refactor(agent-loop): simplify message machine

This commit is contained in:
_Kerman
2026-07-30 13:49:57 +08:00
parent d554ae3019
commit f2e20c1ef0
212 changed files with 1326 additions and 2382 deletions

View File

@@ -25,7 +25,6 @@ async function appendPersistedTitle(ctx: Context, id: ReturnType<typeof SessionI
const session = ctx.sessions.create(id)
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'Persist this session title' }],

View File

@@ -47,7 +47,7 @@ describe('title projection unit', () => {
const firstSeq = appendTitle(session, 'First title')
const secondSeq = appendTitle(session, 'Second title')
// Unrelated event: same-reference apply, no notification.
session.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
session.append('turn/start', { turn: 1 })
expect(changes).toEqual([
{ key: 'title', value: 'First title', seq: firstSeq },
{ key: 'title', value: 'Second title', seq: secondSeq },

View File

@@ -55,7 +55,6 @@ describe('SessionTitleService provider lifecycle', () => {
const parent = ctx.sessions.create(SessionId('title-parent'))
parent.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const inheritedMessage = appendHumanPrompt(parent, 'Inherited title prompt')
await settle()
@@ -77,7 +76,6 @@ describe('SessionTitleService provider lifecycle', () => {
})
child.append('turn/start', {
turn: 2,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const childMessage = appendHumanPrompt(child, 'Child follow-up prompt')
await settle()
@@ -98,7 +96,6 @@ describe('SessionTitleService provider lifecycle', () => {
})
child.append('turn/start', {
turn: 3,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const latestMessage = appendHumanPrompt(child, 'Retitle the fork now')
await settle()
@@ -136,7 +133,6 @@ describe('SessionTitleService provider lifecycle', () => {
const session = ctx.sessions.create(SessionId('first-provider'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const first = appendHumanPrompt(session, 'Explain asynchronous title generation')
await settle()
@@ -195,7 +191,6 @@ describe('SessionTitleService provider lifecycle', () => {
const session = ctx.sessions.create(SessionId('dispose-provider'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const message = appendHumanPrompt(session, 'Generate this title')
await settle()
@@ -245,7 +240,6 @@ describe('SessionTitleService provider lifecycle', () => {
const session = ctx.sessions.create(SessionId('supersede'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const first = appendHumanPrompt(session, 'First prompt')
await settle()
@@ -286,7 +280,6 @@ describe('SessionTitleService provider lifecycle', () => {
const session = ctx.sessions.create(SessionId('unchanged-route'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const first = appendHumanPrompt(session, 'First routed prompt')
await settle()
@@ -298,7 +291,6 @@ describe('SessionTitleService provider lifecycle', () => {
session.append('turn/start', {
turn: 2,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const second = appendHumanPrompt(session, 'Second prompt on the same route')
await settle()
@@ -345,7 +337,6 @@ describe('SessionTitleService provider lifecycle', () => {
const pending = ctx.sessions.create(SessionId('unmatched-boundary'))
pending.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
appendHumanPrompt(pending, 'Wait for a matching request boundary')
await settle()
@@ -369,7 +360,6 @@ describe('SessionTitleService provider lifecycle', () => {
const session = ctx.sessions.create(SessionId('failure'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
appendHumanPrompt(session, 'Keep a fallback')
await settle()

View File

@@ -37,7 +37,6 @@ function startSession(ctx: Context, id: string): ReturnType<Context['sessions'][
const session = ctx.sessions.create(SessionId(id))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
return session
}
@@ -151,7 +150,6 @@ describe('SessionTitleService configuration and refresh boundaries', () => {
disposeCtx.sessions.announce(disposed)
disposed.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const disposedMessage = appendPrompt(disposed, 'Dispose this session')
await settle()
@@ -168,7 +166,6 @@ describe('SessionTitleService configuration and refresh boundaries', () => {
const seed = new Session(SessionId('fallback-concurrency-seed'))
seed.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const source = appendPrompt(seed, 'Create exactly one fallback title')
seed.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
@@ -337,7 +334,6 @@ describe('SessionTitleService configuration and refresh boundaries', () => {
})
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
appendPrompt(session, 'Detach before the fallback microtask')
await settle()

View File

@@ -43,7 +43,6 @@ describe('SessionTitleService', () => {
const session = ctx.sessions.create(SessionId('fresh'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
const message = session.append('user/message', createUserMessage({
content: [{ type: 'text', text: ' Build\nlog-backed session titles please ' }],
@@ -80,7 +79,6 @@ describe('SessionTitleService', () => {
const session = ctx.sessions.create(SessionId('prefixed-title'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'Explain this referenced session' }],
@@ -99,7 +97,6 @@ describe('SessionTitleService', () => {
const session = ctx.sessions.create(SessionId('eligibility'))
session.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },
})
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'plugin text' }],