fix: commit step context before request dispatch

This commit is contained in:
_Kerman
2026-07-30 18:18:04 +08:00
parent a31331cb0e
commit a4ae0b4126
17 changed files with 132 additions and 228 deletions

View File

@@ -116,20 +116,20 @@ export function apply(ctx: Context, config: Config): void {
{ includeBaselineScopes: false, signal },
)
if (update !== undefined) {
agent.inject(update.context)
agent.session.append('user/message', update.context, { surfaceOp: 'append' })
applyInstructionVersionUpdates(agent.session, update.versionUpdates, instructionVersions)
}
const keepVisibleBaseline = !lifecycleWitnessed.has(agent.session) && hasVisibleBaseline(agent)
if (!keepVisibleBaseline && instructions !== undefined && instructions.rendered.text.length > 0) {
const baselineMessage = workspaceContextMessage(instructions.rendered.text)
agent.inject(createUserMessage({
agent.session.append('user/message', createUserMessage({
content: baselineMessage.content,
source: {
kind: 'workspace-instructions',
baseline: true,
changes: [...baseline.changes.values()],
},
}))
}), { surfaceOp: 'append' })
}
baselineLoaded.add(agent.session)
})

View File

@@ -180,9 +180,7 @@ function stubAgent(cwd?: string, seed: SessionEvent[] = []): Agent {
status: 'idle',
followup: () => {},
steer: () => {},
inject(input) {
session.append('user/message', input, { surfaceOp: 'append' })
},
inject: () => { throw new Error('workspace-context must append directly to the open step') },
cancel() {},
whenIdle: () => Promise.resolve(),
}
@@ -1164,7 +1162,7 @@ describe('workspace context request injection', () => {
const ctx = new Context()
await mountWorkspaceContext(ctx, { dshHome: home, maxBytes: 65536 })
ctx.on('agent/step', (agent) => {
agent.inject(createUserMessage({ content: [{ type: 'text', text: '<system-reminder>Available skills</system-reminder>' }], source: { kind: 'plugin', plugin: 'test-skills' } }))
agent.session.append('user/message', createUserMessage({ content: [{ type: 'text', text: '<system-reminder>Available skills</system-reminder>' }], source: { kind: 'plugin', plugin: 'test-skills' } }), { surfaceOp: 'append' })
})
const prefix = await composeBaselinePrefix(ctx, stubAgent(root))