A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep the computer view and live state apart and read optional services safely
Fei2411535c6d700946
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex f710846a..a5c44a41 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -24725,11 +24725,11 @@ function apply(ctx) {work.set(value.work);}}- if (value.computer !== void 0) {- const nextComputer = JSON.stringify(value.computer);+ if (value.computerLive !== void 0) {+ const nextComputer = JSON.stringify(value.computerLive);if (nextComputer !== computerKey) {computerKey = nextComputer;- computer.set(value.computer);+ computer.set(value.computerLive);}}if (value.memoryNews !== void 0) noteMemoryNews(value.memoryNews);diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex 7c553a71..d67957ce 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -180,9 +180,9 @@ export function apply(ctx) {const nextWork = JSON.stringify(value.work)if (nextWork !== workKey) { workKey = nextWork; work.set(value.work) }}- if (value.computer !== undefined) {- const nextComputer = JSON.stringify(value.computer)- if (nextComputer !== computerKey) { computerKey = nextComputer; computer.set(value.computer) }+ if (value.computerLive !== undefined) {+ const nextComputer = JSON.stringify(value.computerLive)+ if (nextComputer !== computerKey) { computerKey = nextComputer; computer.set(value.computerLive) }}if (value.memoryNews !== undefined) noteMemoryNews(value.memoryNews)const current = roster.getSnapshot()diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.jsindex 130b6818..a832e690 100644--- a/ds-bot/src/host/channel.js+++ b/ds-bot/src/host/channel.js@@ -105,7 +105,9 @@ export function install(rt) {imStatus: rt.imStatusView?.() ?? {},imVia: rt.imViaView?.() ?? {},// Computer use live state: per-Bot control, leases, pending app cards and holds.- computer: rt.computerLive?.() ?? {},+ // Named apart from the state view's `computer`: the live answer merges into the+ // same object and would wipe its `enabled` and `provider` fields.+ computerLive: rt.computerLive?.() ?? {},})// The live fields' sources are spread across the host with no single change// counter, so the serialized answer itself is the detector: a poll whose `live`diff --git a/ds-bot/src/host/computer/index.js b/ds-bot/src/host/computer/index.jsindex 7b2eed67..8c3ba181 100644--- a/ds-bot/src/host/computer/index.js+++ b/ds-bot/src/host/computer/index.js@@ -112,7 +112,10 @@ export function install(rt) {}// ---- Provider mount ----- const loaderOf = () => ctx.get?.('loader')+ // Optional services resolve through reflect: ctx.get throws on an+ // uninjected name, but these services mount only when enabled.+ const service = name => ctx.reflect?.get(name)+ const loaderOf = () => service('loader')const importPackage = async (name) => {const loader = loaderOf()if (typeof loader?.import !== 'function') throw Object.assign(new Error('This DSH cannot load packages.'), { code: 'bot/no-loader' })@@ -136,13 +139,13 @@ export function install(rt) {}providerStatus = { state: 'loading' }try {- if (ctx.get?.('computerUse') === undefined) {+ if (service('computerUse') === undefined) {const registry = await importPackage(REGISTRY_PACKAGE).catch(error => { throw missing(error, REGISTRY_PACKAGE) })registryFiber = ctx.plugin(registry)await registryFiber.await?.()}if (stopped || !enabled()) return- const existing = ctx.computerUse.providerName+ const existing = service('computerUse').providerNameif (existing !== undefined && !mountedByUs) {providerStatus = { state: 'occupied', name: String(existing) }return@@ -154,7 +157,7 @@ export function install(rt) {await providerFiber.await?.()if (stopped || !enabled()) returnmountedByUs = true- providerStatus = { state: 'ready', name: ctx.computerUse.providerName ?? 'dsh-cua' }+ providerStatus = { state: 'ready', name: service('computerUse').providerName ?? 'dsh-cua' }refreshComputer()} catch (error) {await unmountProvider().catch(() => {})@@ -170,7 +173,7 @@ export function install(rt) {providerFiber = undefinedmountedByUs = falseif (fiber) await Promise.resolve().then(() => fiber.dispose()).catch(() => {})- if (ctx.get?.('computerUse') !== undefined && ctx.computerUse.providerName === undefined && registryFiber === undefined) {+ if (service('computerUse')?.providerName === undefined && registryFiber === undefined) {// The registry stays; another provider may still want it.}leases.releaseAll()@@ -244,7 +247,7 @@ export function install(rt) {}}function refreshComputer() {- for (const agent of ctx.get?.('agents')?.list?.() ?? []) {+ for (const agent of service('agents')?.list?.() ?? []) {try { applyComputer(agent) } catch (error) { rt.warn('ds-bot: computer-use masking on %s failed: %s', agent?.session?.id, error) }}}@@ -713,7 +716,7 @@ export function install(rt) {leases.releaseBot(bot.id)settleControl(bot.id)}- for (const agent of ctx.get?.('agents')?.list?.() ?? []) applyComputer(agent)+ for (const agent of service('agents')?.list?.() ?? []) applyComputer(agent)return true}const revokeApp = async (botId, appKey) => {@@ -735,7 +738,7 @@ export function install(rt) {// DSH's "Allow for this session" outlives the grant, so a revoke must deny// the provider's decision too or the Bot keeps using the app. Other Bots'// grants are unaffected: their next getApp is answered by DS Bot again.- const access = ctx.get?.('cuaAccess')+ const access = service('cuaAccess')const recorded = [...sessionApps.values()].flatMap(map => [...map.values()]).find(app => app.key === appKey || app.id === appKey || normName(app.name) === normName(grant?.name ?? appKey))const wanted = normName(grant?.name ?? recorded?.name ?? appKey)@@ -778,12 +781,12 @@ export function install(rt) {await ensureProvider()return rt.computerView()case 'system-status': {- const access = ctx.get?.('cuaAccess')+ const access = service('cuaAccess')if (access === undefined || typeof access.systemStatus !== 'function') return nullreturn access.systemStatus().catch(() => null)}case 'permission': {- const access = ctx.get?.('cuaAccess')+ const access = service('cuaAccess')if (access === undefined || typeof access.requestPermission !== 'function') throw new Error('System permissions are not available here')const permission = ['accessibility', 'screenRecording'].includes(body.permission) ? body.permission : 'accessibility'return access.requestPermission(permission, rt.uiLanguage?.() ?? 'en').catch((error) => { throw new Error(String(error?.message ?? error)) })@@ -827,7 +830,7 @@ export function install(rt) {return true}case 'shot': {- const attachments = ctx.get?.('attachments')+ const attachments = service('attachments')const id = String(body.attachmentId ?? '')if (attachments === undefined || id === '') return nullconst chunks = []diff --git a/ds-bot/test/computer.test.js b/ds-bot/test/computer.test.jsindex 9494721b..350fd2a1 100644--- a/ds-bot/test/computer.test.js+++ b/ds-bot/test/computer.test.js@@ -243,19 +243,21 @@ test('macOS consent answerer: grants allow, the card answers, Always records, DS})// A fake Cordis plugin mount + the registry the provider registers on.-function withProvider(ctx, { providerName } = {}) {+function withProvider(ctx, services, { providerName } = {}) {const fibers = []ctx.plugin = (module, config) => {const entry = { module, config }fibers.push(entry)- // Only the provider mount registers a provider name, not the registry's.- if (ctx.computerUse !== undefined && String(module?.name ?? '').includes('experimental')) ctx.computerUse.providerName = providerName ?? 'fake-provider'+ // The registry mount brings the service up; only the provider mount names a provider.+ if (String(module?.name ?? '').includes('experimental')) {+ services.computerUse ??= { providerName: undefined }+ services.computerUse.providerName = providerName ?? 'fake-provider'+ } else services.computerUse ??= { providerName: undefined }return {await: async () => {},dispose: async () => { const index = fibers.indexOf(entry); if (index >= 0) fibers.splice(index, 1) },}}- ctx.computerUse = { providerName: undefined }return fibers}@@ -266,7 +268,7 @@ test('the provider mounts when the switch comes on and reports its status', asynctx.get = name => services[name]services.loader = { import: async name => ({ name }) }services.agents = { list: () => [] }- const fibers = withProvider(ctx)+ const fibers = withProvider(ctx, services)await rt.load()assert.deepEqual(rt.computerStatus().state, 'off')await rt.computerEndpoint('set-enabled', { enabled: true })@@ -289,17 +291,18 @@ test('provider status: occupied, missing, unsupported, error and retry', async (ctx.get = name => services[name]services.loader = { import: async name => { if (name.includes('missing')) throw new Error('Cannot find package') ; return { name } } }services.agents = { list: () => [] }- withProvider(ctx)+ withProvider(ctx, services)// occupied: another provider is already registered- ctx.computerUse.providerName = 'other-provider'+ services.computerUse = { providerName: 'other-provider' }await rt.load()await rt.computerEndpoint('set-enabled', { enabled: true })await rt.computerEndpoint('provider-retry', {})assert.deepEqual(rt.computerStatus(), { state: 'occupied', name: 'other-provider' })- ctx.computerUse.providerName = undefined+ services.computerUse.providerName = undefinedawait rt.computerEndpoint('provider-retry', {})assert.equal(rt.computerStatus().state, 'ready')- // missing: the package cannot be imported+ // missing: the package cannot be imported; the fake registry keeps its name field+ services.computerUse.providerName = undefinedservices.loader = { import: async () => { throw Object.assign(new Error('Cannot find package'), { code: 'ERR_MODULE_NOT_FOUND' }) } }await rt.computerEndpoint('provider-retry', {})assert.equal(rt.computerStatus().state, 'missing')@@ -324,7 +327,7 @@ test('masking: non-Bot agents and off Bots lose the tools and the sections', asy})const services = { loader: { import: async name => ({ name }) }, agents: { list: () => [] } }ctx.get = name => services[name]- withProvider(ctx)+ withProvider(ctx, services)await rt.load()await rt.computerEndpoint('set-enabled', { enabled: true })await rt.computerEndpoint('provider-retry', {})@@ -347,7 +350,7 @@ test('the ds-bot section is empty for a non-Bot, off, or provider-not-ready agent.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const services = { loader: { import: async name => ({ name }) }, agents: { list: () => [] } }ctx.get = name => services[name]- withProvider(ctx)+ withProvider(ctx, services)await rt.load()const section = ctx.sections.get('computer-use:ds-bot')const text = agent => section.text({ agent: { id: agent } })@@ -366,7 +369,7 @@ test('a revoke removes the grant, aborts the call, revokes in the provider and tconst revoked = []const services = { loader: { import: async name => ({ name }) }, agents: { list: () => [] }, cuaAccess: { revoke: async id => revoked.push(id) } }ctx.get = name => services[name]- withProvider(ctx)+ withProvider(ctx, services)await rt.load()await rt.computerEndpoint('set-enabled', { enabled: true })await rt.computerEndpoint('set-level', { botId: 'w1', level: 'background' })@@ -404,7 +407,7 @@ test('grants hold in a later part and in a group Session of the same Bot', asynct.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const services = { loader: { import: async name => ({ name }) }, agents: { list: () => [] } }ctx.get = name => services[name]- withProvider(ctx)+ withProvider(ctx, services)await rt.load()await rt.computerEndpoint('set-enabled', { enabled: true })await rt.computerEndpoint('set-level', { botId: 'w1', level: 'background' })@@ -551,7 +554,7 @@ test('computer_handoff: the hold answers done, skip and takeover', async (t) =>t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const services = { loader: { import: async name => ({ name }) }, agents: { list: () => [] } }ctx.get = name => services[name]- withProvider(ctx)+ withProvider(ctx, services)await rt.load()await rt.computerEndpoint('set-enabled', { enabled: true })await rt.computerEndpoint('provider-retry', {})diff --git a/ds-bot/test/fake-ctx.js b/ds-bot/test/fake-ctx.jsindex 9e9a995f..fdb7a577 100644--- a/ds-bot/test/fake-ctx.js+++ b/ds-bot/test/fake-ctx.js@@ -46,6 +46,8 @@ export function fakeContext({ services = {} } = {}) {sections,logger: { warn() {}, info() {} },get: name => services[name],+ // The real ctx guards plain access with `inject`; service() reads this.+ reflect: { get: name => ctx.get(name) },on(name, listener, options) {calls.push(`on ${name}${options?.prepend ? ' (prepend)' : ''}`)listeners.set(name, [...(listeners.get(name) ?? []), listener])