refactor(agent): make runtime identity explicit

This commit is contained in:
_Kerman
2026-08-28 17:44:56 +08:00
parent 375af94454
commit ebce3a5f04
61 changed files with 281 additions and 396 deletions
@@ -421,15 +421,12 @@ describe('ApiSession create or adoption', () => {
.rejects.toBeInstanceOf(ApiSessionCwdConflict)
})
it('surfaces directory creation failure and rejects setup without a scoped Agent', async () => {
it('surfaces directory creation failure', async () => {
const { agents } = await harness()
const parent = mkdtempSync(join(tmpdir(), 'dsh-session-controller-file-'))
const file = join(parent, 'file')
writeFileSync(file, 'not a directory')
await expect(agents.ensureSession(SessionId('mkdir-failure'), join(file, 'child'), false))
.rejects.toThrow('failed to ensure project directory')
const composition = await agents.composeAgent(undefined)
expect(() => composition.setup(new Context())).toThrow('Agent setup has no scoped Agent')
})
})
@@ -34,9 +34,9 @@ async function composed(workspaces: readonly Workspace[] = []): Promise<Context>
...options.meta === undefined ? {} : { meta: options.meta },
})
const agent = {} as Agent
const agentCtx = ownerCtx.extend({ agent })
const agentCtx = ownerCtx
Object.assign(agent, { id: session.id, session, status: 'idle', ctx: agentCtx })
await options.setup?.(agentCtx)
await options.setup?.(agentCtx, agent)
ctx.agents.register(agent)
return { agent, dispose: () => Promise.resolve() }
},
@@ -49,9 +49,8 @@ async function harness(presets?: readonly string[]) {
options.meta === undefined ? {} : { meta: options.meta },
)
const agent = stubAgent(session)
const agentCtx = ctx.extend({ agent })
;(agent as { ctx?: Context }).ctx = agentCtx
await options.setup?.(agentCtx)
;(agent as { ctx?: Context }).ctx = ctx
await options.setup?.(ctx, agent)
const unregister = ctx.agents.register(agent)
return { agent, dispose: () => { unregister(); return Promise.resolve() } }
},