refactor(agent-loop): simplify message machine
This commit is contained in:
@@ -19,7 +19,7 @@ function event(active: unknown): SessionEvent {
|
||||
function emitTurnStart(ctx: Context, session: Session): void {
|
||||
ctx.emit('session/event', session, {
|
||||
type: 'turn/start', seq: 0, time: 0,
|
||||
data: { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } },
|
||||
data: { turn: 1 },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('plan-mode stream invariants', () => {
|
||||
expect(() => {
|
||||
ctx.emit('tools/change')
|
||||
ctx.emit('session/event', session, {
|
||||
type: 'turn/start', seq: 0, time: 0, data: { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } },
|
||||
type: 'turn/start', seq: 0, time: 0, data: { turn: 1 },
|
||||
})
|
||||
}).not.toThrow()
|
||||
})
|
||||
@@ -65,7 +65,7 @@ describe('plan-mode stream invariants', () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
const session = ctx.sessions.create()
|
||||
session.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
|
||||
session.append('turn/start', { turn: 1 })
|
||||
session.append('plan/mode', { active: 'plan' as unknown as boolean })
|
||||
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
||||
await ctx.plugin(InvariantService, { enabled: true })
|
||||
@@ -77,7 +77,7 @@ describe('plan-mode stream invariants', () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
const session = ctx.sessions.create()
|
||||
session.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
|
||||
session.append('turn/start', { turn: 1 })
|
||||
session.append('plan/mode', { active: true })
|
||||
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
||||
await ctx.plugin(InvariantService, { enabled: true })
|
||||
|
||||
@@ -75,7 +75,7 @@ async function boundary(ctx: Context, agent: Agent & { session: Session }, type:
|
||||
|
||||
/** Open a turn so a selection queues for the boundary flush (the mid-turn shape). */
|
||||
function openTurn(session: Session, turn = 0): void {
|
||||
session.append('turn/start', { turn, trigger: { kind: 'message', source: { kind: 'user' } } })
|
||||
session.append('turn/start', { turn })
|
||||
}
|
||||
|
||||
/** Close the open turn (the between-turns shape: selections commit immediately). */
|
||||
|
||||
@@ -58,7 +58,7 @@ function runPlanCommand(session: Session, args: string, index: number): void {
|
||||
|
||||
/** Commit one plan/mode flip inside an open turn (the invariant's turn-enclosure rule). */
|
||||
function commitPlanMode(session: Session, active: boolean, turn: number): void {
|
||||
session.append('turn/start', { turn, trigger: { kind: 'message', source: { kind: 'user' } } })
|
||||
session.append('turn/start', { turn })
|
||||
session.append('plan/mode', { active })
|
||||
session.append('turn/end', { turn, reason: { kind: 'completed' } })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user