refactor(agent): unify sourced message delivery

This commit is contained in:
_Kerman
2026-07-24 22:38:50 +08:00
parent 009d113e0e
commit 992cf894af
197 changed files with 1890 additions and 2132 deletions

View File

@@ -213,7 +213,7 @@ export class PlanModeService extends Service {
return { kind: 'success', text: 'Plan mode is already inactive.' }
}
this.set(agent, true)
if (message !== '') agent.steer([{ type: 'text', text: message }])
if (message !== '') agent.steer({ content: [{ type: 'text', text: message }], source: { kind: 'user' } })
return {
kind: 'success',
text: 'Entering plan mode (applies from the next step). Use /plan off to leave.',

View File

@@ -75,7 +75,7 @@ describe('plan mode through the agent loop', () => {
// the first prompt-submit, BEFORE the first assembly.
ctx.planMode.set(agent, true)
agent.followup([{ type: 'text', text: 'explore the repo' }])
agent.followup({ content: [{ type: 'text', text: 'explore the repo' }], source: { kind: 'user' } })
await waitForIdle(ctx, agent)
const log = agent.session.events
@@ -103,14 +103,14 @@ describe('plan mode through the agent loop', () => {
const ctx = await harness(adapter)
const agent = ctx.agentLoop.create(SessionId('it-plan-flip'), { provider: 'mock', model: 'mock' })
agent.followup([{ type: 'text', text: 'hello' }])
agent.followup({ content: [{ type: 'text', text: 'hello' }], source: { kind: 'user' } })
await waitForIdle(ctx, agent)
expect(foldPlanMode(agent.session.events)).toBe(false)
const first = findEvent(agent.session.events, 'request/header')
expect(first.data.header.tools?.map(tool => tool.name)).toEqual(['exit_plan_mode', 'read', 'write'])
ctx.planMode.set(agent, true)
agent.followup([{ type: 'text', text: 'now plan' }])
agent.followup({ content: [{ type: 'text', text: 'now plan' }], source: { kind: 'user' } })
await waitForIdle(ctx, agent)
const log = agent.session.events
@@ -143,7 +143,7 @@ describe('plan mode through the agent loop', () => {
})
const idle = waitForIdle(ctx, agent)
agent.followup([{ type: 'text', text: 'plan after the transient failure' }])
agent.followup({ content: [{ type: 'text', text: 'plan after the transient failure' }], source: { kind: 'user' } })
await idle
expect(adapter.requests).toHaveLength(2)

View File

@@ -516,7 +516,10 @@ describe('/plan', () => {
text: 'Entering plan mode (applies from the next step). Use /plan off to leave.',
})
expect(ctx.planMode.get(messageAgent)).toEqual({ active: false, pending: true })
expect(messageSteer).toHaveBeenCalledExactlyOnceWith([{ type: 'text', text: 'draft the migration' }])
expect(messageSteer).toHaveBeenCalledExactlyOnceWith({
content: [{ type: 'text', text: 'draft the migration' }],
source: { kind: 'user' },
})
})
it('leaves active plan mode, cancels a pending entry, and treats inactive exit as idempotent', async () => {