chore(session): scope history reader exemptions to tests

This commit is contained in:
_Kerman
2026-09-09 12:55:32 +08:00
parent 37abcb74c5
commit 8f986c8da6
170 changed files with 72 additions and 1070 deletions
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md
2026-09-09-deprecate-synchronous-session-event-reads.md: 0fcbfbc2e21792f67d1bdbe6d32ac3106338ac45
2026-09-09-deprecate-synchronous-session-event-reads.zh.md: d1f22b483380a7a38a5cd1208815c5fc0ae25348
2026-09-09-deprecate-synchronous-session-event-reads.md: 1420227daf9a410e7db6a7a685bcf4433d7d7b0b
2026-09-09-deprecate-synchronous-session-event-reads.zh.md: e546337bcb15cf6682935729de37aab0c579d2a2
@@ -16,6 +16,8 @@ All operations that synchronously read arbitrary positions or ranges of Session
The three methods carry this rule in `@deprecated` JSDoc. This is an API-use decision; the current Session implementation still retains the complete event sequence in memory.
Repository test files may call these three readers to inspect emitted events and exercise Session history behavior. Their existing lint override allows `snapshotEvents`, `eventAt`, and `ownEvents`; all other deprecated names remain errors. This allowance also covers unrelated declarations with the same three names under the current linter. It does not apply to production source or ordinary repository scripts.
### State needed after resume
Design durable event fields and Session projections together so each domain can reconstruct the state its consumers need. Restore that state during resume, then maintain it incrementally from newly committed events. After resume, ordinary logic reads the projection or processes the delivered current event instead of looking back through historical events. Reading already-maintained projection state synchronously does not require arbitrary access to the event log.
@@ -34,13 +36,15 @@ Fork and a small number of operations may genuinely need a complete historical s
**Require every existing caller to migrate immediately.** Existing logic may defer migration under this decision. Preventing new dependencies bounds the remaining work without making every existing consumer part of the same change.
**Disable deprecation lint for these methods or whole files.** Such exemptions also admit new calls. Line-scoped waivers make the existing migration debt explicit while retaining the native type-aware rule for new reads.
**Disable deprecation lint throughout test files or exempt production readers by name.** Tests only need the three reader names; other deprecated APIs must remain errors. Production code retains the prohibition on new synchronous reads.
**Add a separate test-only reader API.** The three existing readers already expose the observations these tests need. Wrapping them adds an API and production-import checks without changing those observations.
## Consequences
New domain behavior must make its event data and projected state sufficient for resumed execution. User-requested history may still load progressively, and genuine full-history operations still have a storage path to design. This decision does not claim that resume or fork already avoids loading the complete log.
Existing calls carry line-scoped `typescript/no-deprecated` waivers with a migration-deferral reason. The rule stays enabled for new calls and unrelated deprecated APIs. Remove a waiver when its call migrates; copying a waiver to a new call violates this policy. The executable lint check exercises all three readers with and without waivers, plus an unrelated deprecated API. Documentation checks verify the source-equivalent API declarations and bilingual records.
Existing calls outside test files carry line-scoped `typescript/no-deprecated` waivers with a migration-deferral reason. Remove a waiver when its call migrates; copying a waiver to a new production call violates this policy. The executable lint check accepts test reads and existing waived reads, rejects unwaived production reads, and rejects unrelated deprecated APIs in tests. Documentation checks verify the source-equivalent API declarations and bilingual records.
## Related decisions
@@ -16,6 +16,8 @@ Status: implemented
这三个方法通过 `@deprecated` JSDoc 声明该规则。这是 API 使用决策;当前 Session 实现仍在内存中保留完整事件序列。
仓库测试文件可以调用这三个读取方法,以检查已发出的事件并验证 Session 历史行为。现有测试 lint override 允许 `snapshotEvents``eventAt``ownEvents`,其他弃用名称仍报错。在当前 linter 下,此豁免也覆盖使用这三个名称的其他声明。它不适用于生产源码或普通仓库脚本。
### 恢复后需要的状态
结合设计持久事件字段与会话投影,使每个领域都能重建其消费方所需的状态。在恢复期间还原这些状态,随后通过新提交的事件增量维护。恢复后,普通逻辑读取投影或处理当前收到的事件,而不是回头查找历史事件。同步读取已经维护好的投影状态,不需要任意访问事件日志。
@@ -34,13 +36,15 @@ fork 等少数操作可能确实需要完整历史序列或继承前缀。它们
**要求立即迁移所有现有调用方。** 本决策允许现有逻辑推迟迁移。禁止新增依赖可以限制剩余工作规模,无需将每个现有消费方都纳入同一次修改。
**为这些方法或整个文件禁用弃用 lint** 这种豁免也会放过新增调用。逐行豁免明确标出已有的迁移负担,同时继续由原生类型感知规则检查新增读取。
**在整个测试文件禁用弃用 lint,或按名称豁免生产代码中的读取方法。** 测试只需要这三个读取方法名;其他弃用 API 必须继续报错。生产代码仍禁止新增同步读取。
**添加单独的测试专用读取 API。** 三个现有读取方法已经提供这些测试所需的观察结果。包装它们会增加一个 API 及生产代码导入检查,却不会改变这些观察结果。
## 后果
新增领域行为必须使其事件数据与投影状态足以支持恢复后的执行。用户请求的历史仍可渐进式加载,确实需要完整历史的操作仍需设计存储读取路径。本决策不表示恢复或 fork 已经能够避免加载完整日志。
现有调用带有逐行的 `typescript/no-deprecated` 豁免,并说明暂缓迁移的理由。该规则对新增调用及其他已弃用 API 继续生效。调用迁移后应删除豁免;将豁免复制到新增调用违反本策略。实际执行 lint 的检查覆盖三个读取方法有无豁免的情况,以及另一个已弃用 API。文档检查校验与源码一致的 API 声明及双语记录。
测试文件之外的现有调用带有逐行的 `typescript/no-deprecated` 豁免,并说明暂缓迁移的理由。调用迁移后应删除豁免;将豁免复制到新增生产调用违反本策略。实际执行 lint 的检查允许测试读取和已有豁免调用,拒绝未豁免的生产读取,并拒绝测试中其他已弃用 API。文档检查校验与源码一致的 API 声明及双语记录。
## 相关决策
+13
View File
@@ -203,6 +203,19 @@
"scripts/**/*.spec.{ts,tsx}"
],
"rules": {
// Session assertions inspect the log; other deprecated APIs remain errors.
"typescript/no-deprecated": [
"error",
{
"allow": [
{
"from": "file",
"name": ["snapshotEvents", "eventAt", "ownEvents"],
"path": "packages/core/session/src/index.ts"
}
]
}
],
"typescript/no-invalid-void-type": "error",
"typescript/no-non-null-assertion": "off", // Assertions commonly follow an expect() that proves presence.
"typescript/no-unnecessary-condition": "off",
@@ -67,7 +67,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('coding task: fix a failing test
await waitForIdle(ctx, agent)
// The agent claims success…
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summary = finalText(agent.session.snapshotEvents()).toLowerCase()
expect(summary.length).toBeGreaterThan(0)
@@ -56,7 +56,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('compaction: a long session compa
}], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
// A compaction ran: the start…end bracket landed in the real log.
@@ -34,7 +34,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('full loop: real model + real bas
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'Run `echo e2e-ok` with the bash tool and tell me its exact output.' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const calls = events.filter(event => event.type === 'tool/call')
expect(calls.length).toBeGreaterThan(0)
@@ -366,7 +366,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('PTC mode: real model writes a pr
+ 'and return only the joined string.',
}], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events: readonly SessionEvent[] = agent.session.snapshotEvents()
// The wire contract: every request this session made offered EXACTLY ONE
@@ -419,12 +418,10 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('PTC mode: real model writes a pr
}], source: { kind: 'user' } }))
await waitForIdle(ctx, handle.agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events: readonly SessionEvent[] = handle.agent.session.snapshotEvents()
const dispatch = events.find(event => event.type === 'tool/ptc-dispatch' && event.data.name === 'read')
const outerResult = events.find(event => event.type === 'tool/result')
const workspaceContext = await vi.waitFor(() => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const splice = handle.agent.session.snapshotEvents().findLast(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.some(message => message.source.kind === 'agent-instructions'))
const inserted = splice?.type === 'agent/inbox/spliced'
@@ -63,7 +63,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('resume: continue a persisted ses
await waitForIdle(ctx, resumed)
// The model recalls it — only possible from the resumed history.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(finalText(resumed.session.snapshotEvents())).toContain(SECRET)
}, 180_000)
})
@@ -37,7 +37,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('todo_write: real model records a
+ 'Send all three in one todo_write call, then reply with the single word DONE.' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
// The model actually called the tool.
@@ -334,7 +334,6 @@ describe('web e2e: continuous conversation grown through the composer', () => {
}
if (sessionId === undefined) throw new Error('continuous conversation completed no turn')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(scaffold.ctx.agents.get(sessionId)?.session.snapshotEvents().filter(event => (
event.type === 'turn/end' && event.data.reason.kind === 'completed'
))).toHaveLength(TURN_COUNT)
@@ -184,17 +184,12 @@ describe('web e2e: long Chat interaction contract', () => {
const toolAssistantMarker = FIXTURE.markers.assistant(TOOL_TURN)
const toolMarker1 = FIXTURE.markers.tool(TOOL_TURN, 1)
const toolMarker2 = FIXTURE.markers.tool(TOOL_TURN, 2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const toolUserEvent = requiredEvent(source.session.snapshotEvents(), 'user/message', toolUserMarker)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const toolAssistantEvent = requiredEvent(source.session.snapshotEvents(), 'assistant/message', toolAssistantMarker)
const branchUserMarker = FIXTURE.markers.user(BRANCH_TURN)
const branchAssistantMarker = FIXTURE.markers.assistant(BRANCH_TURN)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const branchUserEvent = requiredEvent(source.session.snapshotEvents(), 'user/message', branchUserMarker)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const branchAssistantEvent = requiredEvent(source.session.snapshotEvents(), 'assistant/message', branchAssistantMarker)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const boundary = source.session.snapshotEvents().find((event): event is SessionEvent<'turn/end'> => (
event.type === 'turn/end' && event.data.turn === BRANCH_TURN
))
@@ -320,11 +315,8 @@ describe('web e2e: long Chat interaction contract', () => {
.find(agent => agent.session.header.parentSession === SessionId(SESSION_ID))
if (child === undefined) throw new Error('message branch did not create a child session')
expect(child.session.inheritedEventCount).toBe(boundary.seq + 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.session.snapshotEvents().some(event => carries(event, branchAssistantMarker))).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.session.snapshotEvents().some(event => carries(event, FIXTURE.markers.user(BRANCH_TURN + 1)))).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.session.snapshotEvents().some(event => carries(event, FIXTURE.markers.user(FIXTURE.turns)))).toBe(false)
const currentCrumb = page.getByRole('navigation', { name: 'Session hierarchy' })
@@ -342,13 +334,10 @@ describe('web e2e: long Chat interaction contract', () => {
await expect.poll(() => page.locator('[data-streaming="true"]').count(), { timeout: 15_000 }).toBe(0)
expect(await composer.textContent()).toBe('')
expect(await composer.isEnabled()).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(source.session.snapshotEvents().some(event => carries(event, CONTINUE_PROMPT))).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.session.snapshotEvents().filter(event => (
event.type === 'user/message' && carries(event, CONTINUE_PROMPT)
))).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const lastTurnEnd = child.session.snapshotEvents().findLast((event): event is SessionEvent<'turn/end'> => (
event.type === 'turn/end'
))
-1
View File
@@ -178,7 +178,6 @@ function fixtureLog(session: Session): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify(event)),
'',
].join('\n')
@@ -287,7 +287,6 @@ function galleryFixture(imageUrl: string): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
-1
View File
@@ -329,7 +329,6 @@ function fixtureLog(session: Session): string {
}
return [
JSON.stringify(header),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify(event)),
'',
].join('\n')
-1
View File
@@ -275,7 +275,6 @@ describe.each(MODE === 'record' ? ['deepseek-official'] : ['deepseek-official',
expect(captured()).toHaveLength(releasedCount)
await input.press('Enter')
const findHeaderless = () => scaffold.ctx.sessions.list().find(session => session.id !== sessionId
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
&& session.snapshotEvents().some(event => event.type === 'feedback/record'))
// A command-only session keeps the hero view; its durable event confirms submission.
await expect.poll(findHeaderless, { timeout: 10_000 }).toBeDefined()
@@ -124,7 +124,6 @@ describe('web e2e: /goal human transcript presentation', () => {
const sessions = scaffold.ctx.sessions.list()
expect(sessions).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const persisted = sessions[0]?.snapshotEvents() ?? []
expect(persisted.filter(event => event.type === 'command/run' || event.type === 'command/done')
.map(event => event.type)).toEqual(['command/run', 'command/done'])
@@ -79,7 +79,6 @@ function markdownFixture(): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
-1
View File
@@ -144,7 +144,6 @@ function markdownImageFixture(remoteUrl: string, outsidePath: string): string {
// the stats line renders its LLM segment only while the step's measured
// milliseconds exceed zero, so a fixture that leaves the times unset lets
// the replay's own speed decide whether the golden matches.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
@@ -76,7 +76,6 @@ function markdownFixture(linkUrl: string): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
@@ -142,7 +142,6 @@ function wideTableFixture(): string {
return [
JSON.stringify(header),
// Spaced event times, as the sibling markdown fixtures pin them.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
-1
View File
@@ -80,7 +80,6 @@ function mathFixture(): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
@@ -81,7 +81,6 @@ describe('minimal agent preset', () => {
if (requestHeader === undefined) throw new Error('the minimal agent issued no model request')
const systemPrompt = systemPromptText(agentHandle.agent.session)
if (systemPrompt === undefined) throw new Error('the minimal agent issued no system prompt')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agentHandle.agent.session.snapshotEvents().some(event => event.type === 'user/message'
&& event.data.source.kind === 'plugin'
&& event.data.source.plugin === '@deepseek-ai/dsh-system-prompt')).toBe(false)
@@ -45,7 +45,6 @@ describe.skipIf(webSnapshotMode() === 'record')('historical preset restoration t
if ('error' in resolved) throw resolved.error
expect(scaffold.ctx.agentPresets.composedPreset(resolved.agent.ctx)).toBe('ptc')
expect(resolved.agent.session.header.agentPreset).toBe('ptc')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resolved.agent.session.snapshotEvents()
.filter(event => event.type === 'agent-preset/selected')
.map(event => event.data.agentPreset)).toEqual(withSelections ? ['ptc', 'standard', 'ptc'] : [])
@@ -112,7 +112,6 @@ function mentionFixture(): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event,
time: eventTimeOrigin + event.seq * 1_000,
-1
View File
@@ -99,7 +99,6 @@ function producedFixture(): string {
type: 'session', version: SESSION_FORMAT_VERSION, id: '{{sessionId}}',
createdAt: 0, cwd: '{{cwd}}', isSeeded: false, delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify({
...event, time: eventTimeOrigin + event.seq * 1_000,
})),
-2
View File
@@ -73,7 +73,6 @@ function sourceSessionFixture(): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify(event)),
'',
].join('\n')
@@ -123,7 +122,6 @@ function targetSessionFixture(): string {
isSeeded: false,
delegationDepth: 0,
}),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
...session.snapshotEvents().map(event => JSON.stringify(event)),
'',
].join('\n')
-2
View File
@@ -877,7 +877,6 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise<We
* in-memory record-mode harvest, so the on-disk zstd default never matters.
*/
function rawSessionLog(session: Session): string {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const encodedEvents = (session.snapshotEvents() as unknown as readonly SessionFormatEvent[])
.map(event => sessionFormatCatalog.encodeCurrentEvent(event))
const header = sessionFormatCatalog.encodeCurrentHeader({
@@ -1031,7 +1030,6 @@ async function assertReplaySession(
const userPrompts = fixtureUserPrompts(expected)
const candidates = sessions.filter((session) => {
if (session.header.parentSession !== undefined) return false
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const actual = session.snapshotEvents().flatMap((event) => {
if (event.type !== 'user/message' || event.data.source.kind !== 'user') return []
const text = event.data.content.filter(block => block.type === 'text').map(block => block.text).join('')
-8
View File
@@ -205,7 +205,6 @@ async function waitForReply(
): Promise<SessionEvent<'assistant/message'>> {
const deadline = Date.now() + timeoutMs
while (true) {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = handle.agent.session.snapshotEvents().find((candidate): candidate is SessionEvent<'assistant/message'> => (
candidate.type === 'assistant/message' && assistantText(candidate) === text
))
@@ -456,7 +455,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
it('batches one latest occurrence per overdue Every record into an ordinary follow-up', async () => {
onTestFailed(() => saveFailureShot(page, 'web-e2e-schedule-every'))
const ids = new Set(everyRecords.map(record => record.id))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const dispatches = everyHandle.agent.session.snapshotEvents().filter(event => (
event.type === 'schedule/change'
&& event.data.operation === 'dispatch'
@@ -472,7 +470,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
const decision = acceptedAt[0]
if (decision === undefined) throw new Error('missing Every decision time')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const batch = everyHandle.agent.session.snapshotEvents().find(event => (
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -496,7 +493,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
if (reminderRequest === undefined) throw new Error('model did not receive the Every batch')
expect(requestText(reminderRequest)).toContain(batchBlock.text)
expectReminderFraming(reminderRequest)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const active = foldScheduleEvents(everyHandle.agent.session.snapshotEvents()).active
expect(active).toHaveLength(2)
expect(active.every(record => Date.parse(record.scheduledAt) > Date.parse(decision))).toBe(true)
@@ -520,7 +516,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
it('uses request-local browser context to create an explicit local At reminder', async () => {
onTestFailed(() => saveFailureShot(page, 'web-e2e-schedule-at'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const user = atHandle.agent.session.snapshotEvents().find(event => (
event.type === 'user/message'
&& event.data.source.kind === 'user'
@@ -546,13 +541,11 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
}
expect(selectedAt.time_zone).toBe(AT_BROWSER_ZONE)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const toolCall = atHandle.agent.session.snapshotEvents().find(event => (
event.type === 'tool/call' && event.data.name === 'schedule_create'
))
if (toolCall?.type !== 'tool/call') throw new Error('missing schedule_create tool call')
expect(JSON.parse(toolCall.data.arguments)).toEqual({ prompt: AT_PROMPT, at: selectedAt })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const created = atHandle.agent.session.snapshotEvents().find(event => (
event.type === 'schedule/change'
&& event.data.operation === 'create'
@@ -567,7 +560,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => {
prompt: AT_PROMPT,
scheduledAt,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(atHandle.agent.session.snapshotEvents().filter(event => (
event.type === 'schedule/change'
&& event.data.operation === 'dispatch'
-1
View File
@@ -495,7 +495,6 @@ describe('web e2e: seeded history renders through cold resume', () => {
const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
if (agent === undefined) throw new Error('seeded session did not attach an agent')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const done = agent.session.snapshotEvents().filter(event => event.type === 'command/done').at(-1)
if (done?.type !== 'command/done') throw new Error('feedback command did not settle')
const [sessionLine, userLine, extraLine] = done.data.text?.split('\n') ?? []
-4
View File
@@ -144,7 +144,6 @@ describe('web e2e: settings modal and General preferences', () => {
it('stores Permission as the default for future sessions without changing an existing session', async () => {
onTestFailed(() => saveFailureShot(page, 'web-e2e-settings-permission'))
const existing = scaffold.ctx.sessions.create(SessionId('settings-permission-before'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(existing.snapshotEvents().find(event => event.type === 'permission/preset')?.data)
.toEqual({ preset: 'workspace-write' })
@@ -161,12 +160,10 @@ describe('web e2e: settings modal and General preferences', () => {
const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
expect(document).toContain('permission:')
expect(document).toContain('defaultPreset: read-only')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(existing.snapshotEvents().find(event => event.type === 'permission/preset')?.data)
.toEqual({ preset: 'workspace-write' })
const created = scaffold.ctx.sessions.create(SessionId('settings-permission-after'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(created.snapshotEvents().map(event => [event.type, event.data])).toEqual([
['permission/preset', { preset: 'read-only' }],
['sandbox/mode', { mode: 'read-only' }],
@@ -184,7 +181,6 @@ describe('web e2e: settings modal and General preferences', () => {
const confirmedDocument = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
expect(confirmedDocument).toContain('defaultPreset: danger-full-access')
const confirmed = scaffold.ctx.sessions.create(SessionId('settings-permission-confirmed'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(confirmed.snapshotEvents().map(event => [event.type, event.data])).toEqual([
['permission/preset', { preset: 'danger-full-access' }],
['sandbox/mode', { mode: 'danger-full-access' }],
@@ -320,7 +320,6 @@ describe.skipIf(MODE === 'record')('web e2e: composer interrupt for a running co
const child = scaffold.ctx.agents.get(childId)
expect(child).toBeDefined()
expect(child!.inbox.nextTurn).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child!.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(2)
await page.getByRole('button', { name: 'Send message' }).waitFor({ timeout: 15_000 })
-2
View File
@@ -159,9 +159,7 @@ describe.skipIf(MODE === 'record')('web e2e: subagents/interruptByParent over th
expect(child).toBeDefined()
expect(child!.status).toBe('idle')
expect(child!.inbox.nextTurn).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child!.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const lastEnd = child!.session.snapshotEvents().filter(event => event.type === 'turn/end').at(-1)
expect((lastEnd)?.data.reason.kind).toBe('aborted')
-2
View File
@@ -902,7 +902,6 @@ describe('automation-only ACP bridge', () => {
expect(secondImage.attachment.mediaType).toBe('image/jpeg')
expect(secondImage.attachment.bytes).toBe(1)
const agent = harness.ctx.agents.get(SessionId(sessionId))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(JSON.stringify(agent?.session.snapshotEvents())).not.toContain('AQ==')
})
@@ -976,7 +975,6 @@ describe('automation-only ACP bridge', () => {
sessionId,
prompt: [{ type: 'image', data: '', mimeType: 'image/png' }],
})).rejects.toThrow(/inline image prompts were not advertised/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(harness.ctx.agents.get(SessionId(sessionId))?.session.snapshotEvents().some(event => event.type === 'turn/start')).toBe(false)
})
-5
View File
@@ -216,7 +216,6 @@ describe('ACP prompt lifecycle', () => {
const prompt = harness.client.prompt({ sessionId, prompt: [{ type: 'text', text: 'go' }] })
.finally(() => { settled = true })
await vi.waitFor(() => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.length > 0)).toHaveLength(2)
})
@@ -317,7 +316,6 @@ describe('ACP prompt lifecycle', () => {
await expect(first).resolves.toEqual({ stopReason: 'cancelled' })
expect(harness.adapter.requests).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = harness.ctx.agents.get(SessionId(sessionId))?.session.snapshotEvents() ?? []
expect(events.some(event => event.type === 'user/message' || event.type === 'turn/start')).toBe(false)
})
@@ -445,7 +443,6 @@ describe('ACP prompt lifecycle', () => {
await harness.client.cancel({ sessionId })
await expect(prompt).resolves.toEqual({ stopReason: 'cancelled' })
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')?.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
})
@@ -471,14 +468,12 @@ describe('ACP prompt lifecycle', () => {
source: { kind: 'plugin', plugin: 'test' },
}))
await vi.waitFor(() => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'turn/start')).toBe(true)
})
await harness.client.cancel({ sessionId })
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')?.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
})
@@ -41,7 +41,6 @@ async function commandHarness(
// never appends one: the identity folds as continuable, but from the
// inherited prefix rather than this Session's own suffix.
const lineage = childMode === 'seeded-continuable' || childMode === 'seed-only'
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
? ancestor.snapshotEvents()
: undefined
const session = ctx.sessions.create(sessionId, {
@@ -203,7 +203,6 @@ describe('attached updatedAt tracks human prompts', () => {
meta: { cwd: '/proj', createdAt: 500 },
})
ctx.agents.register({ id: resumed.id, session: resumed, status: 'idle', ctx } as Agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const boundary = resumed.snapshotEvents().at(-1)
expect(boundary?.type).toBe('session/end-seed')
expect(boundary?.time).toBeGreaterThan(worked)
@@ -718,7 +717,6 @@ describe('sessions.prompt synchronous rejection', () => {
defaultModelSelection: () => ({ provider: 'p', model: 'm' }),
cwd: '/tmp',
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const initialEvents = session.snapshotEvents()
const rejectedContent: readonly SessionPromptRequest['content'][] = [
[],
@@ -743,7 +741,6 @@ describe('sessions.prompt synchronous rejection', () => {
}
expect(followup).not.toHaveBeenCalled()
expect(steer).not.toHaveBeenCalled()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual(initialEvents)
const queued = await remote.prompt(promptRequest({
@@ -95,7 +95,6 @@ describe('sessions.fork', () => {
expect(response.ok ? null : response.error).toBeNull()
if (!response.ok) return
const child = ctx.sessions.get(response.value.sessionId)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child?.snapshotEvents().map(event => event.type)).toEqual([
'turn/start', 'user/message', 'turn/end', 'session/end-seed',
])
@@ -215,14 +214,12 @@ describe('sessions.fork', () => {
const omitted = await proxy.fork(request({ sessionId: source.id }))
expect(omitted.ok).toBe(true)
if (omitted.ok) {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(ctx.sessions.get(omitted.value.sessionId)?.snapshotEvents().map(event => event.type))
.toEqual(expectedTypes)
}
const pastEnd = await proxy.fork(request({ sessionId: source.id, atSeq: 999 }))
expect(pastEnd.ok).toBe(true)
if (pastEnd.ok) {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(ctx.sessions.get(pastEnd.value.sessionId)?.snapshotEvents().map(event => event.type))
.toEqual(expectedTypes)
}
@@ -246,12 +243,10 @@ describe('sessions.fork', () => {
const source = liveAgent(ctx, 'session-aborted', 1, 'aborted')
// What a stopped message's fork button anchors on: the frozen node sits
// one event before its turn/end, floored client-side to that event's seq.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const anchor = (source.snapshotEvents().at(-1)?.seq ?? 0) - 1
const response = await remote(ctx).fork(request({ sessionId: source.id, atSeq: anchor }))
expect(response.ok).toBe(true)
if (!response.ok) return
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(ctx.sessions.get(response.value.sessionId)?.snapshotEvents().map(event => event.type)).toEqual([
'turn/start', 'user/message', 'turn/end',
'turn/start', 'user/message', 'turn/end',
@@ -263,7 +258,6 @@ describe('sessions.fork', () => {
it('rejects an in-log anchor whose turn is still open', async () => {
const ctx = await composed()
const source = liveAgent(ctx, 'session-open', 1, 'open')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const anchor = source.snapshotEvents().at(-1)?.seq ?? 0
const response = await remote(ctx).fork(request({ sessionId: source.id, atSeq: anchor }))
expect(response).toMatchObject({
@@ -172,7 +172,6 @@ describe('session.history projections block', () => {
parent.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
const inheritedEventCount = parent.seq
const child = ctx.sessions.create(SessionId('wire-seed-child'), {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: parent.snapshotEvents(),
inheritedEventCount,
meta: {
@@ -449,7 +448,6 @@ describe('session.history projections block', () => {
expect('test/last-user' in after.projections.values).toBe(false)
expect(after.projections.values.sessionListMetadata).toEqual({
blank: true,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
lastPromptAt: session.eventAt(SessionSeq(session.seq - 1))?.time,
})
})
@@ -484,7 +482,6 @@ describe('session.list projections column', () => {
expect(row?.projections?.values['test/last-user']).toEqual({ text: 'm0' })
expect(row?.projections?.values.sessionListMetadata).toEqual({
blank: false,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
lastPromptAt: session.eventAt(SessionSeq(session.seq - 1))?.time,
})
expect(row?.projections?.asOfSeq).toBe(session.seq - 1)
@@ -76,7 +76,6 @@ describe('sessions.rename', () => {
expect(renamed.ok).toBe(true)
if (!renamed.ok) return
expect(renamed.value.title).toBe('new name')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = source.snapshotEvents().findLast(item => item.type === 'session/title')
expect(event?.seq).toBe(renamed.value.seq)
expect(event?.data).toMatchObject({ title: 'new name', source: { kind: 'user' } })
@@ -230,7 +230,6 @@ describe('SessionHistoryController', () => {
observed.resolve({
source: 'live',
header: attached.header,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
events: attached.snapshotEvents(),
cursor: attached.seq - 1,
projections: { asOfSeq: attached.seq - 1, values: {} },
@@ -70,7 +70,6 @@ async function executeShell(text: string, nested: boolean, name = 'bash', maxInl
let block: ToolResultNode
if (nested) {
expect(result.value).toMatchObject({ result: true })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const dispatches = session.snapshotEvents().filter(event => event.type === 'tool/ptc-dispatch')
expect(dispatches).toHaveLength(1)
const event = dispatches[0]!
@@ -121,7 +121,6 @@ function expectLastLifecycle(
args: string,
outcome: CommandResult,
): string {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const lifecycle = test.agent.session.snapshotEvents()
.filter(event => event.type === 'command/run' || event.type === 'command/done')
.slice(-2)
@@ -130,7 +130,6 @@ describe('command-compact real Loader composition', () => {
text: 'Compacted 3 history items (~99 tokens).',
sourceEventSeq: RESULT.summarySeq,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().map(event => ({ type: event.type, data: event.data }))).toEqual([
{
type: 'command/run',
@@ -625,7 +625,6 @@ describe('pressure measurement and retention', () => {
await expect(compactIfNeeded(compact, session, 'context-overflow')).resolves.toBeNull()
expect(session.surface.replaceGeneration).toBe(generation)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
})
@@ -647,7 +646,6 @@ describe('pressure measurement and retention', () => {
const compact = service(compactConfig, ctx)
const session = conversation(4, undefined, 'SYSTEM HEAD')
const [head, firstUser] = session.surface.nodes
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.eventAt(head!)?.type).toBe('system/message')
const range = selectCompactableRange(session, ctx.tokenMeter.measure(session), compactConfig.retainTokens!)
@@ -891,11 +889,9 @@ describe('optional model-free tool-result pruning', () => {
expect(await compactIfNeeded(compact, session)).not.toBeNull()
expect(compact.calls).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const original = session.snapshotEvents().find(event => event.type === 'tool/result')
expect(original?.type === 'tool/result' && original.data.message.content[0].content[0])
.toEqual({ type: 'text', text: 'X'.repeat(3_000) })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().filter(event =>
event.type === 'tool/result' && event.surfaceOp !== 'append')).toHaveLength(0)
})
@@ -922,7 +918,6 @@ describe('compaction region transaction', () => {
expect(result.shadowedTokenCount).toBeGreaterThan(0)
expect(compact.calls[0]).toMatchObject({ signal: SIGNAL })
expect(summarizedText(compact.calls[0]!.input)).toContain('fixture user 1')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summary = session.snapshotEvents().findLast(event => event.type === 'compaction/summary')
expect(summary?.data).toMatchObject({
shadowedSeqs: result.shadowedSeqs,
@@ -939,7 +934,6 @@ describe('compaction region transaction', () => {
expect(head.content[0]?.type === 'text' ? head.content[0].text : '').toContain('<compacted-summary>')
expect(head.content.at(-1)).toEqual({ type: 'text', text: '</compacted-summary>' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replay = Session.create(SessionId('replay'), session.snapshotEvents())
expect(replay.deriveMessages()).toEqual(session.deriveMessages())
})
@@ -964,7 +958,6 @@ describe('compaction region transaction', () => {
const compact = service()
const emptyHead = conversation(3, undefined, '')
const emptyNodes = emptyHead.surface.nodes
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(emptyHead.eventAt(emptyNodes[0]!)?.type).toBe('system/message')
await compact.compactRegion(emptyNodes[1]!, emptyNodes[2]!, agent(emptyHead, MODEL), SIGNAL)
expect(compact.calls[0]!.input.messages[0]).toMatchObject({ role: 'user' })
@@ -986,7 +979,6 @@ describe('compaction region transaction', () => {
.rejects.toThrow(/node 0 holds the system prompt/)
expect(session.surface.nodes).toEqual(nodes)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = session.snapshotEvents().findLast(event => event.type === 'compaction/end')
expect(end?.type === 'compaction/end' && end.data.error).toBeDefined()
})
@@ -1100,7 +1092,6 @@ describe('compaction region transaction', () => {
agent(session, MODEL),
)).rejects.toThrow('summary unavailable')
expect(session.surface.nodes).toEqual(before)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().findLast(event => event.type === 'compaction/end')?.data)
.toMatchObject({ error: 'summary unavailable' })
})
@@ -1115,7 +1106,6 @@ describe('compaction region transaction', () => {
nodes[2]!,
agent(session, MODEL),
)).rejects.toBe('plain failure')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().findLast(event => event.type === 'compaction/end')?.data)
.toMatchObject({ error: 'plain failure' })
})
@@ -1136,7 +1126,6 @@ describe('compaction region transaction', () => {
nodes[2]!,
agent(session, MODEL),
)).resolves.toMatchObject({ shadowedSeqs: nodes.slice(0, 3) })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
})
@@ -1156,7 +1145,6 @@ describe('compaction region transaction', () => {
nodes[2]!,
agent(session, MODEL),
)).rejects.toThrow(/session surface changed/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(false)
})
@@ -1174,7 +1162,6 @@ describe('compaction region transaction', () => {
nodes[2]!,
agent(session, MODEL),
)).rejects.toThrow(/summary is not smaller/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(false)
})
@@ -1448,7 +1435,6 @@ describe('default one-shot summarizer', () => {
const session = conversation(3, 'large history '.repeat(500))
const nodes = session.surface.nodes
await compact.compactRegion(nodes[0]!, nodes[3]!, agent(session, MODEL), SIGNAL)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().findLast(event => event.type === 'compaction/summary')?.data).toMatchObject({
summary: [{ type: 'text', text: 'routed summary' }],
llmStreamCall: true,
@@ -1575,7 +1561,6 @@ describe('automatic listener and loader composition', () => {
next: () => Promise<RequestErrorAction> = () => Promise.resolve(undefined),
): Promise<boolean> {
const failure: LlmFailure = { message: error.message, code: error.code ?? 'UNKNOWN' }
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turn = owner.session.snapshotEvents().findLast(event => event.type === 'turn/start')?.data.turn ?? 1
return agentEvents(ctx, owner).waterfall(
'agent/request-error',
@@ -1596,12 +1581,10 @@ describe('automatic listener and loader composition', () => {
})
const pressured = conversation(4)
await preStep(ctx, agent(pressured, 'unconfigured-agent-fallback'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(pressured.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
const small = conversation(1)
await preStep(ctx, agent(small, MODEL))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(small.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
expect(compact.calls).toHaveLength(1)
})
@@ -1619,7 +1602,6 @@ describe('automatic listener and loader composition', () => {
.resolves.toEqual({ kind: 'enter', messages: [] })
expect(compactIfNeeded).not.toHaveBeenCalled()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(pressured.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
})
@@ -1636,7 +1618,6 @@ describe('automatic listener and loader composition', () => {
await expect(preStep(ctx, agent(session, MODEL))).resolves.toEqual({ kind: 'enter', messages: [] })
expect(warnings).toContainEqual(expect.stringContaining('temporary failure'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(false)
})
@@ -1696,7 +1677,6 @@ describe('automatic listener and loader composition', () => {
expect(decision).toBe(true)
expect(session.surface.replaceGeneration).toBe(beforeGeneration + 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
expect(session.surface.nodes).toContain(retainedSeq)
})
@@ -1716,7 +1696,6 @@ describe('automatic listener and loader composition', () => {
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(true)
expect(session.surface.replaceGeneration).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(false)
expect(compact.calls).toHaveLength(0)
})
@@ -1735,7 +1714,6 @@ describe('automatic listener and loader composition', () => {
const session = toolConversation()
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
expect(compact.calls).toHaveLength(1)
expect(summarizedText(compact.calls[0]!.input)).toContain('tool result middle pruned')
@@ -1759,9 +1737,7 @@ describe('automatic listener and loader composition', () => {
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(true)
expect(session.surface.replaceGeneration).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().filter(event => event.type === 'tool/result')).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().findLast(event => event.type === 'compaction/end')?.data)
.toMatchObject({ error: 'summary unavailable after prune' })
expect(warnings).toContainEqual(expect.stringContaining('retrying from the replacement surface'))
@@ -1964,11 +1940,9 @@ describe('automatic listener and loader composition', () => {
})
const session = conversation(4)
await preStep(ctx, agent(session, MODEL))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summaries = session.snapshotEvents().filter(event => event.type === 'compaction/summary').length
expect(summaries).toBe(1)
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().filter(event => event.type === 'compaction/summary')).toHaveLength(summaries)
})
@@ -1981,7 +1955,6 @@ describe('automatic listener and loader composition', () => {
})
const session = conversation(4)
await preStep(ctx, agent(session, MODEL))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(false)
})
@@ -2014,7 +1987,6 @@ describe('automatic listener and loader composition', () => {
const session = conversation(4)
await preStep(ctx, agent(session, MODEL))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
expect(await recover(ctx, agent(session, MODEL), overflow())).toBe(false)
})
@@ -2156,7 +2128,6 @@ describe('route-priced image pressure', () => {
const result = await compact.compactIfNeeded(agent(session), 'pressure', SIGNAL)
expect(result).not.toBeNull()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summaryEvent = session.snapshotEvents().find(event => event.type === 'compaction/summary')
expect(summaryEvent).toBeDefined()
const shadowedHeuristic = before.nodes
@@ -212,7 +212,6 @@ function overflowHistorySeed(): readonly SessionEvent[] {
session.append('step/end', { turn, step: 1 })
session.append('turn/end', { turn, reason: { kind: 'completed' } })
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return session.snapshotEvents()
}
@@ -231,9 +230,7 @@ describe('CBR-001: a real-loop checkpoint is a valid boundary on both sides', ()
await waitForIdle(ctx, agent)
expect(agent.session.requestHeader()?.config.model).toBe('mock')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'completed' } },
@@ -250,7 +247,6 @@ describe('CBR-001: a real-loop checkpoint is a valid boundary on both sides', ()
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'do tool work' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const compactStart = events.find(event => event.type === 'compaction/start')
expect(compactStart).toBeDefined()
@@ -283,7 +279,6 @@ describe('CBR-001: a real-loop checkpoint is a valid boundary on both sides', ()
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'do a long multi-step task' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
// A compaction ran: at least one checkpoint landed on the surface.
const checkpoints = events.filter(
@@ -352,7 +347,6 @@ describe('token pressure after loop-admitted system prompts', () => {
prompt = nextPrompt
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'question' }], source: { kind: 'user' } }))
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end', data: { reason: { kind: 'completed' } },
})
@@ -360,13 +354,11 @@ describe('token pressure after loop-admitted system prompts', () => {
expect(measured.baseline).toEqual({ kind: 'usage', tokens: 1110, usage })
expect(measured.surfaceDeltaTokens).toBe(0)
expect(measured.totalTokens).toBe(1110)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replay = Session.create(SessionId('prompt-pressure-replay'), agent.session.snapshotEvents())
expect(ctx.tokenMeter.measure(replay)).toMatchObject({
baseline: measured.baseline, surfaceDeltaTokens: 0, totalTokens: 1110, nodes: measured.nodes,
})
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const prompts = events.filter(event => event.type === 'system/message')
expect(prompts[0]?.surfaceOp).toBe('append')
@@ -436,7 +428,6 @@ describe('context-overflow recovery across the real loop and compaction-basic',
expect(retry).toContain('RECOVERY CHECKPOINT')
expect(retry).not.toContain('OLD HISTORY SENTINEL')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const stepStart = events.find(event =>
event.type === 'step/start' && event.data.turn === 3 && event.data.step === 1,
@@ -499,13 +490,10 @@ describe('context-overflow recovery across the real loop and compaction-basic',
expect(adapter.conversationRequests).toHaveLength(3)
expect(adapter.summaryRequests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'llm/retry').map(event => event.data))
.toEqual([expect.objectContaining({ turn: 3, step: 1, retry: 1, failure: { message: 'temporary provider outage', code: 'SERVER' } })])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start').slice(-1).map(event => event.data.turn))
.toEqual([3])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'completed' } },
@@ -233,7 +233,6 @@ function detachedService(): { ctx: Context; compact: GatedCompactionEngine; flus
}
function compactEvents(session: Session): SessionEvent[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return session.snapshotEvents().filter(event => event.type.startsWith('compaction/'))
}
@@ -296,16 +295,13 @@ describe('compactNow through the real loop', () => {
const result = await compact.compactNow(agent, SIGNAL)
expect(result).not.toBeNull()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const start = agent.session.snapshotEvents().findLast(event => event.type === 'compaction/start')
const injected = agent.inbox.nextStep.find(message =>
message.source.kind === 'plugin' && message.source.plugin === 'test')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(event => event.type === 'compaction/end')
expect(start).toBeDefined()
expect(injected).toBeDefined()
expect(end).toBeDefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'user/message'
&& event.data.id === injected?.id)).toBe(false)
@@ -340,7 +336,6 @@ describe('compactNow through the real loop', () => {
expect(result).not.toBeNull()
expect(agent.session.deriveMessages()[0]?.role).toBe('system')
expect(derivedText(agent.session)[1]).toContain('checkpoint')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'plugin' && event.data.source.plugin === 'listener')).toHaveLength(0)
const types = compactEvents(agent.session).map(event => event.type)
@@ -361,7 +356,6 @@ describe('compactNow through the real loop', () => {
await agent.whenIdle()
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'compaction/start')).toBe(false)
})
@@ -412,18 +406,13 @@ describe('compactNow transaction and failure classification', () => {
expect(result).not.toBeNull()
expect(result?.sourceCommandId).toBe(commandId)
expect(flushes()).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().filter(event => event.type === 'turn/start').at(-1)?.data.turn).toBe(7)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const start = session.snapshotEvents().findLast(event => event.type === 'compaction/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summaryEvent = session.snapshotEvents().findLast(event => event.type === 'compaction/summary')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const checkpoint = session.snapshotEvents().findLast(
(event): event is SessionEvent<'user/message'> => event.type === 'user/message'
&& isCompactCheckpointSource(event.data.source),
)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = session.snapshotEvents().findLast(event => event.type === 'compaction/end')
const correlated = { compactionId: result?.compactionId, sourceCommandId: commandId }
expect(start?.data).toEqual({ ...correlated, turn: null })
@@ -454,11 +443,8 @@ describe('compactNow transaction and failure classification', () => {
compactionId: CompactionId('stale-manual-compaction'),
turn: null,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reloaded = Session.create(SessionId('stale-orphan'), original.snapshotEvents())
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const boundary = reloaded.snapshotEvents().findLast(event => event.type === 'session/end-seed')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const orphan = reloaded.snapshotEvents().find(event => event.type === 'compaction/start')
const agent = fakeAgent(reloaded, () => () => undefined)
@@ -476,7 +462,6 @@ describe('compactNow transaction and failure classification', () => {
})
original.append('turn/start', { turn: 3 })
original.append('turn/end', { turn: 3, reason: { kind: 'interrupted' } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reloaded = Session.create(SessionId('reloaded-orphan'), original.snapshotEvents())
const agent = fakeAgent(reloaded, () => () => undefined)
@@ -580,7 +565,6 @@ describe('compactNow transaction and failure classification', () => {
expect(session.surface.replaceGeneration).toBe(generation + 1)
expect(session.surface.nodes).not.toContain(head)
expect(compactEvents(session).map(event => event.type)).toEqual(['compaction/start', 'compaction/end'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'user/message'
&& isCompactCheckpointSource(event.data.source))).toBe(false)
})
@@ -600,7 +584,6 @@ describe('compactNow transaction and failure classification', () => {
expect(causeOf(error).message).toBe('boundary rejected')
vi.restoreAllMocks()
expect(flushes()).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().findLast(event => event.type.startsWith('compaction/'))?.type)
.toBe('compaction/summary')
expect(compactEvents(session).filter(event => event.type === 'compaction/start')).toHaveLength(1)
@@ -667,7 +650,6 @@ describe('compactNow transaction and failure classification', () => {
vi.restoreAllMocks()
expect(error.code).toBe('commit')
expect(released).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = session.snapshotEvents().findLast(event => event.type === 'compaction/end')
expect(end?.type === 'compaction/end' && end.data.error).toContain('summary record rejected')
expect(end?.type === 'compaction/end' && end.data.turn).toBeNull()
@@ -704,9 +686,7 @@ describe('compactNow transaction and failure classification', () => {
const result = await compact.compactNow(agent, SIGNAL)
expect(result).not.toBeNull()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'turn/start')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().find(event => event.type === 'compaction/start')?.data)
.toEqual({ compactionId: result?.compactionId, turn: null })
})
@@ -719,11 +699,8 @@ describe('compactNow transaction and failure classification', () => {
expect((await rejection(compact.compactNow(agent, SIGNAL))).code).toBe('persistence')
vi.restoreAllMocks()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const start = session.snapshotEvents().findLast(event => event.type === 'compaction/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = session.snapshotEvents().findLast(event => event.type === 'compaction/end')
expect(end?.data).toEqual({ compactionId: start?.data.compactionId, turn: null })
})
@@ -740,7 +717,6 @@ describe('compactNow transaction and failure classification', () => {
const reserve = vi.fn(() => testCase.release)
const measure = vi.spyOn(ctx.tokenMeter, 'measure')
const agent = fakeAgent(testCase.session, reserve)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const before = testCase.session.snapshotEvents()
const reason = Object.freeze({ kind: 'cancelled', case: testCase.name })
const controller = new AbortController()
@@ -756,7 +732,6 @@ describe('compactNow transaction and failure classification', () => {
expect(reserve).not.toHaveBeenCalled()
expect(measure).not.toHaveBeenCalled()
expect(compact.calls).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(testCase.session.snapshotEvents()).toEqual(before)
vi.restoreAllMocks()
}
@@ -806,7 +781,6 @@ describe('compactNow transaction and failure classification', () => {
await expect(compact.compactNow(agent, controller.signal)).rejects.toBe(reason)
expect(compactEvents(session).map(event => event.type)).toEqual(['compaction/start', 'compaction/end'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'compaction/summary')).toBe(false)
})
@@ -851,7 +825,6 @@ describe('compactNow transaction and failure classification', () => {
await compact.compactNow(agent, SIGNAL)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const summary = session.snapshotEvents().find(event => event.type === 'compaction/summary')
expect(summary?.type === 'compaction/summary' && summary.data.rawOutput).toEqual(compact.rawOutput)
expect(summary?.type === 'compaction/summary' && summary.data.usage).toEqual(compact.usage)
@@ -867,9 +840,7 @@ describe('compactNow transaction and failure classification', () => {
await compact.compactNow(agent, SIGNAL)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const start = session.snapshotEvents().findLast(event => event.type === 'compaction/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = session.snapshotEvents().findLast(event => event.type === 'compaction/end')
expect(start).toBeDefined()
expect(end).toBeDefined()
@@ -186,9 +186,7 @@ describe('ToolResultPruner session transaction', () => {
expect(entry).toMatchObject({ originalSeq, callId: ToolCallId('one'), charsBefore: 100 })
expect(entry.charsAfter).toBeLessThanOrEqual(50)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const original = session.snapshotEvents()[originalSeq]!
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replacement = session.snapshotEvents()[entry.replacementSeq]! as SurfaceEvent
expect(original).toMatchObject({
type: 'tool/result',
@@ -223,7 +221,6 @@ describe('ToolResultPruner session transaction', () => {
// Shadow-price protocol: the metering event sits directly before the
// replacement and prices the shadowed node with the shared estimator.
if (original.type !== 'tool/result') throw new Error('original is not a tool/result')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()[entry.replacementSeq - 1]).toMatchObject({
type: 'compaction/prune',
data: {
@@ -259,7 +256,6 @@ describe('ToolResultPruner session transaction', () => {
turn: 2,
})
service().pruneSession(session)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replay = Session.create(session.id, session.snapshotEvents())
expect(replay.deriveMessages()).toEqual(session.deriveMessages())
expect(replay.surface.replaceGeneration).toBe(session.surface.replaceGeneration)
@@ -131,7 +131,6 @@ describe('CompactionEngine seam', () => {
const result = await svc.compactRegion(original.seq, original.seq, stubAgent(session, 'm'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const startEvent = session.snapshotEvents().find(e => e.type === 'compaction/start')
expect(startEvent).toBeDefined()
// Log-only: the compiler rejects surfaceOp on compaction/* (not a SurfaceEventType);
@@ -143,14 +142,12 @@ describe('CompactionEngine seam', () => {
expect(result.endSeq).toBeGreaterThan(result.summarySeq)
expect(result.shadowedRange).toEqual({ start: original.seq, end: original.seq })
expect(result.shadowedSeqs).toEqual([original.seq])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const checkpoint = session.snapshotEvents().find(event => event.type === 'user/message'
&& isCompactCheckpointSource(event.data.source))
expect(checkpoint?.type === 'user/message' && checkpoint.data.source)
.toEqual(compactCheckpointSource(result.compactionId))
expect(isCompactCheckpointSource({ kind: 'plugin', plugin: 'other' })).toBe(false)
expect(isCompactCheckpointSource({ kind: 'user' })).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().filter(e => e.type.startsWith('compaction/')).map(e => e.type))
.toEqual(['compaction/start', 'compaction/summary', 'compaction/end'])
})
@@ -134,10 +134,8 @@ describe('compaction invariants', () => {
const source = Session.create(SessionId('stale-compaction-source'))
source.append('compaction/start', { compactionId: TEST_COMPACTION_ID, turn: null })
const replayed = ctx.sessions.create(SessionId('stale-compaction-replay'), {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: source.snapshotEvents(),
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().map(event => event.type))
.toEqual(['compaction/start', 'session/end-seed'])
@@ -157,10 +155,8 @@ describe('compaction invariants', () => {
startTurn(source)
source.append('compaction/start', { compactionId: TEST_COMPACTION_ID, turn: 1 })
const replayed = ctx.sessions.create(SessionId('stale-numbered-compaction-replay'), {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: source.snapshotEvents(),
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().map(event => event.type))
.toEqual(['turn/start', 'compaction/start', 'session/end-seed'])
@@ -181,10 +177,8 @@ describe('compaction invariants', () => {
startTurn(source)
source.append('turn/end', { turn: 1, reason: { kind: 'interrupted' } })
const replayed = ctx.sessions.create(SessionId('stale-repaired-compaction-replay'), {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: source.snapshotEvents(),
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().map(event => event.type)).toEqual([
'compaction/start',
'turn/start',
@@ -210,10 +204,8 @@ describe('compaction invariants', () => {
source.append('turn/end', { turn: 1, reason: { kind: 'interrupted' } })
source.append('compaction/end', { compactionId: TEST_COMPACTION_ID, turn: null, error: 'failed after crossing turn' })
const replayed = ctx.sessions.create(SessionId('closed-nested-compaction-replay'), {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: source.snapshotEvents(),
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().at(-1)?.type).toBe('session/end-seed')
await ctx.plugin(InvariantRegistry)
@@ -7,7 +7,6 @@ import type { SessionEvent, SessionSeq as SessionSeqType } from '@deepseek-ai/ds
const SURFACE = { surfaceOp: 'append' as const }
function seqOf(session: Session, type: SessionEvent['type'], nth = 0): SessionSeqType {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return session.snapshotEvents().filter(event => event.type === type)[nth]!.seq
}
@@ -77,7 +77,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('workspace context e2e: real mode
live.agent.followup(createUserMessage({ content: [{ type: 'text', text: 'Workspace context handshake?' }], source: { kind: 'user' } }))
await waitForIdle(live.ctx, live.agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(finalText(live.agent.session.snapshotEvents())).toContain(PROBE)
}, 120_000)
@@ -90,7 +89,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('workspace context e2e: real mode
live.agent.followup(createUserMessage({ content: [{ type: 'text', text: 'Use the read tool to inspect pkg/deep/file.txt. After reading it, answer: nested instruction handshake?' }], source: { kind: 'user' } }))
await waitForIdle(live.ctx, live.agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(finalText(live.agent.session.snapshotEvents())).toContain(NESTED_PROBE)
}, 120_000)
@@ -104,7 +102,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('workspace context e2e: real mode
live.agent.followup(createUserMessage({ content: [{ type: 'text', text: 'You must use the read tool to inspect trigger.txt. After reading it, answer: updated workspace context handshake?' }], source: { kind: 'user' } }))
await waitForIdle(live.ctx, live.agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = live.agent.session.snapshotEvents()
const update = events.find(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions'
@@ -277,7 +277,6 @@ async function syncedWorkspaceContext(ctx: Context, agent: Agent): Promise<UserM
}
function baselineEvents(agent: Agent): SessionEvent[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents().filter(event =>
event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions'
@@ -1128,7 +1127,6 @@ describe('workspace context request injection', () => {
const second = await composeBaselinePrefix(ctx, agent)
expect(second).toEqual(first)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'user/message' && event.data.source.kind !== 'user')).toHaveLength(1)
expect(derivedText(agent)).toContain('repo rule')
} finally {
@@ -1148,16 +1146,13 @@ describe('workspace context request injection', () => {
const original = await stubAgent(root)
await composeBaselinePrefix(ctx, original)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const firstResume = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(ctx, firstResume)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const secondResume = await stubAgent(root, firstResume.session.snapshotEvents())
await composeBaselinePrefix(ctx, secondResume)
expect(baselineEvents(firstResume)).toHaveLength(1)
expect(baselineEvents(secondResume)).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(secondResume.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions')).toHaveLength(1)
} finally {
@@ -1180,12 +1175,10 @@ describe('workspace context request injection', () => {
await composeBaselinePrefix(ctx, original)
fs.throwOnStat.add(join(root, 'AGENTS.md'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(ctx, resumed)
expect(baselineEvents(resumed)).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions')).toHaveLength(1)
} finally {
@@ -1208,15 +1201,12 @@ describe('workspace context request injection', () => {
const original = await stubAgent(cwd)
await composeBaselinePrefix(ctx, original)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const firstResume = await stubAgent(cwd, original.session.snapshotEvents())
await composeBaselinePrefix(ctx, firstResume)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const secondResume = await stubAgent(cwd, firstResume.session.snapshotEvents())
await composeBaselinePrefix(ctx, secondResume)
expect(baselineEvents(secondResume)).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(secondResume.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions')).toHaveLength(1)
expect(blocksText(secondResume.session.deriveMessages()[0]?.content)).toContain('omitted AGENTS.md')
@@ -1241,12 +1231,10 @@ describe('workspace context request injection', () => {
await composeBaselinePrefix(ctx, original)
await write(join(cwd, 'AGENTS.md'), 'package rule')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(cwd, original.session.snapshotEvents())
await composeBaselinePrefix(ctx, resumed)
expect(baselineEvents(resumed)).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const update = resumed.session.snapshotEvents().findLast(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions'
&& event.data.source.baseline !== true)
@@ -1280,7 +1268,6 @@ describe('workspace context request injection', () => {
maxBytes: 65536,
instructionFileCandidates: ['CLAUDE.md', 'AGENTS.md'],
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(resumedCtx, resumed)
@@ -1300,7 +1287,6 @@ describe('workspace context request injection', () => {
: [])
expect(new Set(baselineIdentities).size).toBe(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const repeated = await stubAgent(root, resumed.session.snapshotEvents())
await composeBaselinePrefix(resumedCtx, repeated)
expect(baselineEvents(repeated)).toHaveLength(2)
@@ -1335,7 +1321,6 @@ describe('workspace context request injection', () => {
maxBytes: 65536,
instructionFileCandidates: ['CLAUDE.md'],
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const claudeResume = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(claudeCtx, claudeResume)
const claudeBaseline = baselineEvents(claudeResume).at(-1)
@@ -1351,7 +1336,6 @@ describe('workspace context request injection', () => {
maxBytes: 65536,
instructionFileCandidates: ['AGENTS.md'],
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const restored = await stubAgent(root, claudeResume.session.snapshotEvents())
await composeBaselinePrefix(restoredCtx, restored)
const restoredBaseline = baselineEvents(restored).at(-1)
@@ -1387,7 +1371,6 @@ describe('workspace context request injection', () => {
maxBytes: 65536,
instructionFileCandidates: ['POLICY.md'],
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(resumedCtx, resumed)
@@ -1402,7 +1385,6 @@ describe('workspace context request injection', () => {
{ action: 'remove', scope: sk('.', 'AGENTS.md'), path: 'AGENTS.md' },
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const repeated = await stubAgent(root, resumed.session.snapshotEvents())
await composeBaselinePrefix(resumedCtx, repeated)
expect(baselineEvents(repeated)).toHaveLength(2)
@@ -1433,7 +1415,6 @@ describe('workspace context request injection', () => {
await fiber.dispose()
await mountWorkspaceContextPlugin(ctx, { dshHome: home, maxBytes: 65536 })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
agentEvents(ctx, resumed).emit('agent/session-start', { source: 'resume' })
const claimed = claimInbox(resumed, 'next-step')
@@ -1450,7 +1431,6 @@ describe('workspace context request injection', () => {
expect(decision.messages.map(message => message.id)).toEqual([inserted?.id])
expect(resumed.inbox.nextStep).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.session.snapshotEvents().filter(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.some(message => message.source.kind === 'agent-instructions'
&& message.source.baseline === true))).toHaveLength(1)
@@ -1481,7 +1461,6 @@ describe('workspace context request injection', () => {
await write(join(root, 'AGENTS.md'), 'new repo rule')
await fiber.dispose()
await mountWorkspaceContextPlugin(ctx, { dshHome: home, maxBytes: 65536 })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
agentEvents(ctx, resumed).emit('agent/session-start', { source: 'resume' })
const staleClaim = claimInbox(resumed, 'next-step')
@@ -1535,7 +1514,6 @@ describe('workspace context request injection', () => {
await originalCtx.fiber.dispose()
if (provideFs) await resumedCtx.plugin(LocalFileSystem, { cwd: '/' })
await mountWorkspaceContextPlugin(resumedCtx, { dshHome: home, maxBytes })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
agentEvents(resumedCtx, resumed).emit('agent/session-start', { source: 'resume' })
const claimed = claimInbox(resumed, 'next-step')
@@ -1577,7 +1555,6 @@ describe('workspace context request injection', () => {
await composeBaselinePrefix(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const removal = agent.session.snapshotEvents().find(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions'
&& event.data.source.changes.some(change => change.action === 'remove'))
@@ -1612,7 +1589,6 @@ describe('workspace context request injection', () => {
await composeBaselinePrefix(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const workspaceEvents = agent.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions')
expect(workspaceEvents).toHaveLength(2)
@@ -1622,7 +1598,6 @@ describe('workspace context request injection', () => {
expect(baselineEvents(agent)).toHaveLength(1)
await composeBaselinePrefix(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'agent-instructions')).toHaveLength(2)
} finally {
@@ -1846,7 +1821,6 @@ describe('workspace context request injection', () => {
// The first resumed pre-step retains the compatible visible baseline and
// appends only the offline file transition needed to reach current state.
await write(join(root, 'AGENTS.md'), 'new root rule after offline edit')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
// Resume announces its lifecycle start before the first step.
@@ -1855,7 +1829,6 @@ describe('workspace context request injection', () => {
const baselines = baselineEvents(resumed)
expect(baselines).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const latest = resumed.session.snapshotEvents().findLast(event =>
event.type === 'user/message' && event.data.source.kind === 'agent-instructions')
expect(latest?.type === 'user/message' ? latest.data.source : undefined).toMatchObject({
@@ -2037,7 +2010,6 @@ describe('workspace context request injection', () => {
await composeBaselinePrefix(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contexts = agent.session.snapshotEvents().filter(event =>
event.type === 'user/message' && event.data.source.kind !== 'user',
)
@@ -2679,7 +2651,6 @@ describe('dynamic nested workspace context injection', () => {
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'read and abort' }], source: { kind: 'user' } }))
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event =>
event.type === 'user/message' && event.data.source.kind !== 'user',
)).toHaveLength(0)
@@ -2687,7 +2658,6 @@ describe('dynamic nested workspace context injection', () => {
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'retry the read' }], source: { kind: 'user' } }))
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contexts = agent.session.snapshotEvents().filter(event => event.type === 'user/message' && event.data.source.kind !== 'user')
expect(contexts).toHaveLength(1)
expect(adapter.requests).toHaveLength(3)
@@ -3663,7 +3633,6 @@ describe('dynamic nested workspace context injection', () => {
agent,
})
await appendAdditionalContexts(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, agent.session.snapshotEvents())
const afterResume = await ctx.tools.execute({
@@ -3698,12 +3667,10 @@ describe('dynamic nested workspace context injection', () => {
})
await appendAdditionalContexts(ctx, original)
await write(join(root, 'pkg/AGENTS.md'), 'new nested rule after resume')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
await composeBaselinePrefix(ctx, resumed)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const update = resumed.session.snapshotEvents().findLast(event => event.type === 'user/message' && event.data.source.kind !== 'user')
expect(update?.type === 'user/message' && update.data.source).toMatchObject({
changes: [{ action: 'replace', scope: sk('pkg', 'AGENTS.md'), path: join('pkg', 'AGENTS.md') }],
@@ -4734,7 +4701,6 @@ describe('workspace context inbox synchronization', () => {
callId: ToolCallId('recover-pending-a'), name: 'read', arguments: { file_path: join('a', 'file.txt') }, agent: original,
})
await syncWorkspaceContext(ctx, original)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = await stubAgent(root, original.session.snapshotEvents())
await ctx.tools.execute({
@@ -134,7 +134,6 @@ describe('session-reference real Loader composition', () => {
ctx.sessions.get(SessionId('reference-source'))!.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'LATER_SOURCE_MUTATION' }], source: { kind: 'user' },
}), { surfaceOp: 'append' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(SessionId('replayed-target'), target.snapshotEvents()).deriveMessages()).toEqual(captured)
expect(await readFile(notice.fullSnapshot.locator, 'utf8')).toBe(transcript)
})
@@ -322,7 +322,6 @@ describe('session reference spill outcomes', () => {
const target = ctx.sessions.create(SessionId('target'))
const source = ctx.sessions.create(SessionId('source'))
for (const text of texts) appendText(source, text)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const captured = source.snapshotEvents().at(-1)?.seq
const read = vi.spyOn(ctx.sessionQuery, 'readSurface')
const store = ctx.spillStore as RecordingSpill
@@ -372,7 +371,6 @@ describe('session reference spill outcomes', () => {
const context = result.additionalContext!
target.append('user/message', context, { surfaceOp: 'append' })
for (const detach of detachSources) detach()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = Session.create(SessionId('replayed'), target.snapshotEvents()).deriveMessages()
expect(replayed).toEqual(target.deriveMessages())
expect(JSON.stringify(replayed)).toContain('memory:session-reference-1.txt')
@@ -453,7 +451,6 @@ describe('session reference spill outcomes', () => {
finish.resolve(undefined)
await rejected
await settled.promise
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(target.snapshotEvents().filter(event => event.type === 'user/message')).toEqual([])
} finally { finish.resolve(undefined); await ctx.fiber.dispose() }
})
@@ -1201,7 +1198,6 @@ describe('session reference discovery and preparation', () => {
expect(JSON.stringify(before)).toContain('durable referenced fact')
expect(JSON.stringify(before)).toContain('use @source')
expect(JSON.stringify(before)).not.toContain('later source mutation')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(SessionId('replayed-target'), target.snapshotEvents()).deriveMessages()).toEqual(before)
})
@@ -68,7 +68,6 @@ function openMessageTurn(session: Session, turn: number, clientTimeZone?: string
function contextTexts(session: Session): string[] {
const texts: string[] = []
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of session.snapshotEvents()) {
if (event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -169,7 +168,6 @@ describe('durable step context', () => {
+ 'Browser time zone for this request: Asia/Shanghai. Interpret otherwise-unqualified dates and times in this zone.\n'
+ 'Elapsed since the preceding model-visible message: 1d 1h 1m 1s.',
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = session.snapshotEvents().at(-1)
expect(event?.type).toBe('user/message')
if (event?.type !== 'user/message') throw new Error('missing time context')
@@ -293,9 +291,7 @@ describe('durable step context', () => {
const original = Session.create(SessionId('seed-source'))
openMessageTurn(original, 1)
await fire(ctx, sessionAgent(original), 1, 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const user = original.snapshotEvents().find(event => event.type === 'user/message' && event.data.source.kind === 'user')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reading = original.snapshotEvents().find(event => event.type === 'user/message' && event.data.source.kind === 'plugin')
if (user === undefined || reading === undefined) throw new Error('missing source surface events')
original.append('user/message', createUserMessage({
@@ -308,17 +304,14 @@ describe('durable step context', () => {
original.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
expect(JSON.stringify(original.deriveMessages())).not.toContain('Time sampled while preparing')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumed = Session.create(SessionId('resumed'), original.snapshotEvents())
const resumedAgent = sessionAgent(resumed)
vi.setSystemTime(BASE + 999)
openMessageTurn(resumed, 2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const beforeSkip = resumed.snapshotEvents().length
await fire(ctx, resumedAgent, 2, 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.snapshotEvents()).toHaveLength(beforeSkip)
expect(contextTexts(resumed)).toHaveLength(1)
@@ -341,7 +334,6 @@ describe('durable step context', () => {
vi.setSystemTime(BASE + 500)
openMessageTurn(first, 2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const beforeSkip = first.snapshotEvents().length
await fire(ctx, firstAgent, 2, 1)
@@ -349,7 +341,6 @@ describe('durable step context', () => {
openMessageTurn(independent, 1)
await fire(ctx, sessionAgent(independent, 'independent-agent'), 1, 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(first.snapshotEvents()).toHaveLength(beforeSkip)
expect(contextTexts(first)).toHaveLength(1)
expect(contextTexts(independent)).toHaveLength(1)
@@ -469,7 +460,6 @@ describe('real agent-loop request history', () => {
expect(contextTexts(agent.session)).toHaveLength(0)
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'step/start')).toBe(false)
await ctx.fiber.dispose()
})
@@ -492,10 +482,8 @@ describe('real agent-loop request history', () => {
await agent.whenIdle()
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contexts = agent.session.snapshotEvents().filter(
(event): event is SessionEvent<'user/message'> => event.type === 'user/message' && event.data.source.kind === 'plugin')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const starts = agent.session.snapshotEvents().filter(event => event.type === 'step/start')
expect(contexts).toHaveLength(adapter.requests.length)
expect(starts).toHaveLength(adapter.requests.length)
@@ -520,7 +508,6 @@ describe('real agent-loop request history', () => {
expect(request.messages[0]?.role).toBe('system')
expect(JSON.stringify(request.messages[0])).not.toContain('Time sampled while preparing')
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const systemNodes = agent.session.snapshotEvents().filter(event => event.type === 'system/message')
expect(JSON.stringify(systemNodes)).not.toContain('Time sampled while preparing')
await ctx.fiber.dispose()
@@ -123,7 +123,6 @@ function openMessageTurn(session: Session, turn: number): void {
function contextTexts(session: Session): string[] {
const texts: string[] = []
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of session.snapshotEvents()) {
if (event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -172,7 +171,6 @@ describe('tmux-context injection', () => {
+ 'window active=1, pane active=0, '
+ 'layout d517,270x71,0,0{135x71,0,0,87,134x71,136,0[134x35,136,0,90,134x35,136,36,93]}',
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = session.snapshotEvents().at(-1)
if (event?.type !== 'user/message') throw new Error('missing tmux context')
// `snapshot` form: one named contribution carrying exactly the reading the
@@ -335,7 +335,6 @@ describe('AgentLoop initiator scope', () => {
}])
const schema = adapter.requests[0]?.tools?.find(tool => tool.name === 'capability-request')
expect(JSON.stringify(schema?.parameters)).not.toMatch(/session|harness/i)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const call = handle.agent.session.snapshotEvents().find(event => event.type === 'tool/call')
expect(call?.type === 'tool/call' ? call.data.arguments : undefined)
.toBe(JSON.stringify({ path: '/v1/capability' }))
@@ -35,7 +35,6 @@ describe('Agent', () => {
agent.inject(createUserMessage({ content: [{ type: 'text', text: 'context' }], source: { kind: 'plugin', plugin: 'p' } }))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().map(event => event.type)).toEqual(['agent/inbox/spliced'])
expect(agent.status).toBe('idle')
expect(adapter.requests).toHaveLength(0)
@@ -48,7 +47,6 @@ describe('Agent', () => {
agent.inject(createUserMessage({ content: [{ type: 'text', text: 'empty plugin source' }], source: { kind: 'plugin', plugin: '' } }))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const injected = agent.session.snapshotEvents().at(-1)
expect(injected?.type === 'agent/inbox/spliced' && injected.data.inserted[0]?.source)
.toEqual({ kind: 'plugin', plugin: '' })
@@ -99,7 +97,6 @@ describe('Agent', () => {
expect(() => {
agent.inject(createUserMessage({ content: [{ type: 'text', text: 'x', bad: 1n } as never], source: { kind: 'plugin', plugin: 'p' } }))
}).toThrow(/non-JSON-serializable/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()).toHaveLength(0)
})
@@ -111,7 +108,6 @@ describe('Agent', () => {
agent.steer(createUserMessage({ content: [{ type: 'text', text: 'steer idle' }], source: { kind: 'plugin', plugin: 'test' } }))
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'user/message')).toBe(true)
expect(adapter.requests).toHaveLength(1)
})
@@ -50,7 +50,6 @@ function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
/** All user-message texts recorded in the log (to assert what actually ran). */
function userTexts(agent: Agent): string[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
.filter(e => e.type === 'user/message')
.flatMap(e => e.type === 'user/message' ? e.data.content : [])
@@ -72,7 +71,6 @@ describe('Agent.cancel()', () => {
// The prompt ran: its user message is in the log and one turn completed.
expect(userTexts(agent)).toEqual(['real prompt'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'turn/end')).toBe(true)
})
@@ -88,14 +86,12 @@ describe('Agent.cancel()', () => {
// A waking send starts and claims synchronously, so keepInbox has no
// pending item to preserve by the time this cancellation runs.
agent.cancel({ kind: 'user' }, { keepInbox: true })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event =>
event.type === 'agent/inbox/spliced' && event.data.outcome === 'canceled')).toBe(false)
await agent.whenIdle()
expect(agent.inbox.nextTurn).toHaveLength(0)
expect(userTexts(agent)).toEqual([])
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')?.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
@@ -150,7 +146,6 @@ describe('Agent.cancel()', () => {
expect(userTexts(agent)).toEqual(['active', 'B'])
expect(adapter.requests).toHaveLength(2)
expect(agent.inbox.nextTurn).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(e => e.type === 'turn/end').map(e =>
e.type === 'turn/end' ? e.data.reason : null)).toEqual([
{ kind: 'aborted', reason: { kind: 'user' } },
@@ -201,7 +196,6 @@ describe('Agent.cancel()', () => {
expect(agent.status).toBe('idle')
// No replay with nothing to run: the latched message is gone, so no
// empty follow-up turn is recorded.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(e => e.type === 'turn/start')).toHaveLength(1)
})
@@ -261,11 +255,8 @@ describe('Agent.cancel()', () => {
await new Promise(r => setTimeout(r, 30))
expect(userTexts(agent)).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'step/start')).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')?.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
expect(agent.status).toBe('idle')
@@ -295,7 +286,6 @@ describe('Agent.cancel()', () => {
await driverDone(agent)
expect(agent.status).toBe('idle')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'turn/start')).toBe(false)
expect(userTexts(agent)).toEqual([])
expect(adapter.requests).toHaveLength(0)
@@ -333,7 +323,6 @@ describe('Agent.cancel()', () => {
replacementObservation = agent.whenIdle().then(() => ({
status: agent.status,
requests: adapter.requests.length,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
turns: agent.session.snapshotEvents().filter(event => event.type === 'turn/start').length,
}))
agent.cancel({ kind: 'user' })
@@ -411,7 +400,6 @@ describe('Agent.cancel()', () => {
expect(reasons).toEqual([{ kind: 'aborted', reason: { kind: 'user' } }])
expect(userTexts(agent)).toEqual(['go'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
expect(adapter.requests).toHaveLength(1)
})
@@ -448,9 +436,7 @@ describe('Agent.cancel()', () => {
expect(executions).toBe(0)
expect(reasons).toEqual([{ kind: 'aborted', reason: { kind: 'user' } }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const call = agent.session.snapshotEvents().find(event => event.type === 'tool/call')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const result = agent.session.snapshotEvents().find(event => event.type === 'tool/result')
expect(call?.type === 'tool/call' ? call.data.callId : undefined).toBe('c1')
expect(result?.type === 'tool/result' ? result.data : undefined).toMatchObject({
@@ -491,7 +477,6 @@ describe('Agent.cancel()', () => {
expect(userTexts(agent)).toContain('second')
// The second turn completed (its reply was streamed).
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reasons = agent.session.snapshotEvents().filter(e => e.type === 'turn/end')
expect(reasons.length).toBe(2)
})
@@ -508,7 +493,6 @@ describe('Agent.cancel()', () => {
// The prefix the user watched stream is committed as the step's message,
// carrying the truncation marker and exact embedded stream that delivered it.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
expect(message?.type === 'assistant/message' ? message.data.message.content : undefined)
.toEqual([{ type: 'text', text: 'partial' }])
@@ -519,7 +503,6 @@ describe('Agent.cancel()', () => {
))
: false).toBe(true)
expect(message?.sourceEventSeqs).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types.indexOf('assistant/message')).toBeLessThan(types.indexOf('step/end'))
expect(types.indexOf('step/end')).toBeLessThan(types.indexOf('turn/end'))
@@ -554,14 +537,12 @@ describe('Agent.cancel()', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().find(event => event.type === 'assistant/message')
expect(message?.type === 'assistant/message' ? message.data.message.source.replayState : undefined)
.toEqual(replayState)
expect(message?.type === 'assistant/message' ? message.data.interrupted : undefined).toBe(true)
expect(() => Session.fromRestore(
agent.session.id,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
structuredClone([...agent.session.snapshotEvents()]),
structuredClone(agent.session.header),
SessionLogOffset(0),
@@ -585,7 +566,6 @@ describe('Agent.cancel()', () => {
agent.cancel({ kind: 'user' })
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
expect(message?.type === 'assistant/message' ? message.data.message.content : undefined)
.toEqual([{ type: 'reasoning', text: 'thinking about it' }])
@@ -613,11 +593,9 @@ describe('Agent.cancel()', () => {
await waitForIdle(ctx, agent)
// The undispatched call is dropped whole — no dangling tool_use to pair.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
expect(message?.type === 'assistant/message' ? message.data.message.content : undefined)
.toEqual([{ type: 'text', text: 'reading the file' }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/call')).toBe(false)
})
@@ -640,9 +618,7 @@ describe('Agent.cancel()', () => {
// The failed stream's prefix stays off the surface: clients reset it on
// retry, and provider failures commit nothing.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'assistant/message')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' ? end.data.reason.kind : undefined).toBe('aborted')
})
@@ -663,14 +639,12 @@ describe('Agent.cancel()', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const messages = agent.session.snapshotEvents().filter(e => e.type === 'assistant/message')
expect(messages).toHaveLength(1)
const message = messages[0]!
expect(message.type === 'assistant/message' ? message.data.message.content : undefined)
.toEqual([{ type: 'text', text: 'recovered' }])
expect(message.type === 'assistant/message' ? message.data.interrupted : undefined).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const failed = agent.session.snapshotEvents().find(e => e.type === 'assistant/attempt')
expect(failed?.type === 'assistant/attempt'
? expandAssistantStream(failed.data.stream).some(member => (
@@ -702,12 +676,10 @@ describe('Agent.cancel()', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const attempt = agent.session.snapshotEvents().find(event => event.type === 'assistant/attempt')
expect(attempt?.type === 'assistant/attempt'
? expandAssistantStream(attempt.data.stream).map(member => member.chunk)
: []).toContainEqual({ type: 'text-delta', index: 0, text: 'partial before failure' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().find(event => event.type === 'turn/end')).toMatchObject({
type: 'turn/end', data: { reason: { kind: 'error', error: { message: failure.message } } },
})
@@ -728,7 +700,6 @@ describe('Agent.cancel()', () => {
agent.cancel({ kind: 'user' })
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'assistant/message')).toBe(false)
})
@@ -758,7 +729,6 @@ describe('Agent.cancel()', () => {
// log is balanced (the open step was closed by the cancel branch).
expect(streamed).toBe(false)
expect(reasons).toEqual([{ kind: 'aborted', reason: { kind: 'user' } }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types.filter(t => t === 'step/start').length).toBe(types.filter(t => t === 'step/end').length)
})
@@ -794,9 +764,7 @@ describe('Agent.cancel()', () => {
expect(streamed).toBe(false)
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'turn/end')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types.filter(t => t === 'step/start').length).toBe(types.filter(t => t === 'step/end').length)
})
@@ -850,7 +818,6 @@ describe('Agent.cancel()', () => {
// No turn opened, no step streamed, and a later prompt still runs (the marker
// was reset).
expect(streamed).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'turn/start')).toBe(false)
})
@@ -882,7 +849,6 @@ describe('Agent.cancel()', () => {
await replacementIdle
expect(userTexts(agent)).toEqual(['B', 'C'])
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/end')).toHaveLength(2)
})
@@ -906,7 +872,6 @@ describe('Agent.cancel()', () => {
await replacementIdle
expect(userTexts(agent)).toEqual(['B', 'C'])
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/end')).toHaveLength(3)
})
@@ -928,11 +893,9 @@ describe('Agent.cancel()', () => {
// started from the dropped steering.
await new Promise(r => setTimeout(r, 30))
expect(agent.status).toBe('idle')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnStarts = agent.session.snapshotEvents().filter(e => e.type === 'turn/start')
expect(turnStarts.length).toBe(1) // only the original (cancelled) turn
// The steering text was dropped — it never reached the log.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const flat = agent.session.snapshotEvents()
.filter(e => e.type === 'user/message')
.flatMap(e => e.data.content)
@@ -964,7 +927,6 @@ describe('Agent.cancel()', () => {
status: agent.status,
requests: adapter.requests.length,
users: userTexts(agent),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
events: agent.session.snapshotEvents().map(event => event.type),
})}`))
}, 1000)
@@ -976,7 +938,6 @@ describe('Agent.cancel()', () => {
expect(adapter.requests).toHaveLength(2)
expect(userTexts(agent)).toEqual(['original', 'replacement'])
expect(agent.inbox.nextTurn).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reasons = agent.session.snapshotEvents()
.filter(event => event.type === 'turn/end')
.map(event => event.type === 'turn/end' ? event.data.reason : undefined)
@@ -1004,7 +965,6 @@ describe('Agent.cancel()', () => {
const runtimeReason: unknown = adapter.requests[0]?.signal?.reason
expect(runtimeReason).toEqual({ kind: 'parent' })
expect(runtimeReason).toBe(supplied)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason).toEqual({
kind: 'aborted',
@@ -1026,7 +986,6 @@ describe('Agent.cancel()', () => {
agent.cancel({ kind: 'user' })
await handle.dispose()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason).toEqual({ kind: 'aborted', reason: { kind: 'user' } })
})
@@ -1098,7 +1057,6 @@ describe('Agent.cancel()', () => {
const idle = agent.whenIdle()
agent.cancel({ kind: 'user' })
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
@@ -72,7 +72,6 @@ describe('assistant replay provider and model fields', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const recorded = agent.session.snapshotEvents().find(event => event.type === 'assistant/message')
expect(recorded?.type === 'assistant/message' && recorded.data.message.source).toEqual({
kind: 'model', provider: 'mock', model: 'next-model', replayState,
@@ -112,7 +111,6 @@ describe('abort during tool execution ends the turn', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.filter(event => event.type === 'tool/result'
|| (event.type === 'user/message' && event.data.source.kind === 'plugin')
@@ -126,7 +124,6 @@ describe('abort during tool execution ends the turn', () => {
send(agent, 'wake')
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.flatMap(event => event.type === 'user/message' && event.data.source.kind === 'plugin'
? [event.data.content]
@@ -177,7 +174,6 @@ describe('abort during tool execution ends the turn', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
expect(events
.filter(event => event.type === 'tool/result'
@@ -203,11 +199,9 @@ describe('abort during tool execution ends the turn', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start'
|| event.type === 'step/start' || event.type === 'turn/end').map(event => event.type))
.toEqual(['turn/start', 'turn/end'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().find(event => event.type === 'turn/end')?.data)
.toEqual({ turn: 1, reason: { kind: 'completed' } })
expect(agent.inbox.nextTurn).toHaveLength(0)
@@ -249,23 +243,19 @@ describe('abort during tool execution ends the turn', () => {
await started.promise
await fiber.dispose()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.flatMap(event => event.type === 'user/message' && event.data.source.kind === 'plugin'
? [event.data.content]
: []))
.toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.flatMap(event => event.type === 'agent/inbox/spliced' && event.data.target === 'next-step'
? [event.data.inserted.map(inboxText)]
: [])
.at(-1))
.toEqual(['accepted result context during disposal'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start'))
.toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().find(event => event.type === 'turn/end')?.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'disposed' } })
})
@@ -320,7 +310,6 @@ describe('abort during tool execution ends the turn', () => {
send(agent, 'start a text-only turn')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'user/message' && event.data.source.kind === 'plugin'
? [event.data.content]
@@ -373,7 +362,6 @@ describe('plugin exceptions are contained', () => {
send(agent, 'first')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')).toMatchObject({
data: { reason: { kind: 'error', error: { message: 'broken continuation plugin', code: 'UNKNOWN' } } },
})
@@ -410,9 +398,7 @@ describe('disposal leaves the two-state status contract balanced', () => {
expect(statuses).toEqual(['running', 'idle'])
expect(reasons).toEqual([{ kind: 'aborted', reason: { kind: 'disposed' } }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const messages = agent.session.snapshotEvents()
.filter(event => event.type === 'user/message')
.flatMap(event => event.data.content)
@@ -462,7 +448,6 @@ describe('adapter registration, routing, and accepted-input ownership', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error'
? turnEnd.data.reason.error.message
@@ -525,7 +510,6 @@ describe('adapter registration, routing, and accepted-input ownership', () => {
['content', 'id', 'role', 'source'],
])
expect(targets).toEqual(['next-turn', 'next-step'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const steeringSources = agent.session.snapshotEvents().flatMap(e =>
e.type === 'user/message' && e.data.source.kind === 'plugin' ? [e.data.source] : [])
expect(steeringSources).toEqual([{ kind: 'plugin', plugin: 'goal' }])
@@ -559,7 +543,6 @@ describe('adapter registration, routing, and accepted-input ownership', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const claims = events.flatMap(event => event.type === 'agent/inbox/spliced'
&& event.data.target === 'next-step'
@@ -605,7 +588,6 @@ describe('turn numbering continues across seeded sessions', () => {
const { agent: forked } = await ctx2.agents.create({
sessionId: SessionId('forked'),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: agent.session.snapshotEvents(),
agentOptions: { provider: 'mock', model: 'mock' },
})
@@ -674,7 +656,6 @@ describe('a finish-error stream chunk ends the turn as error, not completed', ()
expect(errors[0]).toBeInstanceOf(LlmError)
expect((errors[0] as LlmError).failure).toEqual(failure)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const turnEnd = events.find(event => event.type === 'turn/end')
expect(turnEnd).toMatchObject({ data: { reason: { kind: 'error', error: failure } } })
@@ -697,7 +678,6 @@ describe('a finish-error stream chunk ends the turn as error, not completed', ()
await waitForIdle(ctx, agent)
expect(reasons).toEqual([{ kind: 'error', error: { message: 'model stream aborted', code: 'ABORTED' } }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'assistant/message')).toBe(false)
})
@@ -728,7 +708,6 @@ describe('step boundary publication order', () => {
const observed: { turn: number; step: number; lastEventType: string | undefined; sawStepStart: boolean }[] = []
ctx.on('session/event', (subject, event) => {
if (subject !== agent.session || event.type !== 'step/start') return
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = subject.snapshotEvents()
const last = events.at(-1)
observed.push({
@@ -765,7 +744,6 @@ describe('turn and step boundary recovery', () => {
/** Count turn/step boundary events for balance assertions. */
function boundaryCounts(agent: Agent) {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
return {
turnStart: e.filter(x => x.type === 'turn/start').length,
@@ -796,7 +774,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
const c = boundaryCounts(agent)
expect(c).toMatchObject({ turnStart: 1, turnEnd: 1, stepStart: 1, stepEnd: 1, errors: 0 })
@@ -830,7 +807,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'rejected')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'turn/start'
|| event.type === 'user/message')).toBe(false)
expect(agent.inbox.nextTurn).toHaveLength(1)
@@ -862,7 +838,6 @@ describe('turn and step boundary recovery', () => {
stepEnd: 0,
errors: 1,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')).toMatchObject({
data: { reason: { kind: 'error', error: { message: 'reject step-start before commit', code: 'UNKNOWN' } } },
})
@@ -956,7 +931,6 @@ describe('turn and step boundary recovery', () => {
await fiber.dispose() // dispose during the hanging step
await driverDone(agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
const turnStarts = e.filter(x => x.type === 'turn/start').length
const turnEnds = e.filter(x => x.type === 'turn/end').length
@@ -990,7 +964,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'go')
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -1020,14 +993,11 @@ describe('turn and step boundary recovery', () => {
expect(errors).toEqual([])
// Session contains the observer failure per listener, so the committed turn
// remains visible to later observers and executes normally.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types.filter(t => t === 'turn/start')).toHaveLength(1)
expect(types.filter(t => t === 'turn/end')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const lastBoundary = agent.session.snapshotEvents().findLast(e => e.type === 'turn/start' || e.type === 'turn/end')
expect(lastBoundary?.type).toBe('turn/end')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)?.type).toBe('turn/end')
// loop survives: a second turn runs normally.
@@ -1060,7 +1030,6 @@ describe('turn and step boundary recovery', () => {
.toEqual({ kind: 'completed' })
// step/end precedes turn/end (ordering contract)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
const stepEndIdx = e.findIndex(x => x.type === 'step/end')
const turnEndIdx = e.findIndex(x => x.type === 'turn/end')
@@ -1095,7 +1064,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
// Both step/end and turn/end are present — finalization ran to completion.
expect(e.some(x => x.type === 'step/end')).toBe(true)
@@ -1126,7 +1094,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// turn 1 is balanced despite the throwing turn/end listener.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e1 = agent.session.snapshotEvents()
expect(e1.filter(x => x.type === 'turn/start')).toHaveLength(1)
expect(e1.filter(x => x.type === 'turn/end')).toHaveLength(1)
@@ -1136,7 +1103,6 @@ describe('turn and step boundary recovery', () => {
send(agent, 'again')
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(x => x.type === 'turn/end')).toHaveLength(2)
})
})
@@ -1169,7 +1135,6 @@ describe('tool result call identity', () => {
await waitForIdle(ctx, agent)
// The logged tool/result.callId is the originating call.id.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resultEvent = agent.session.snapshotEvents().find(e => e.type === 'tool/result')
expect(resultEvent?.type).toBe('tool/result')
if (resultEvent?.type === 'tool/result') {
@@ -1234,7 +1199,6 @@ describe('disposal and cancellation during pre-step assembly', () => {
await driverDone(agent)
unlisten()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -1283,7 +1247,6 @@ describe('disposal and cancellation during pre-step assembly', () => {
await driverDone(agent)
unlisten()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -1334,7 +1297,6 @@ describe('disposal and cancellation during pre-step assembly', () => {
await driverDone(agent)
// The post-listener cancellation check catches disposal before any step or LLM call.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -1382,7 +1344,6 @@ describe('disposal and cancellation during pre-step assembly', () => {
await fiber.dispose()
await driverDone(agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -1428,7 +1389,6 @@ describe('disposal and cancellation during pre-step assembly', () => {
await disposalDone
await driverDone(agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const e = agent.session.snapshotEvents()
expect(e.filter(x => x.type === 'turn/start' || x.type === 'turn/end').map(x => x.type))
.toEqual(['turn/start', 'turn/end'])
@@ -69,14 +69,12 @@ describe('tool JSON parse', () => {
await waitForIdle(ctx, agent)
// tool/call event should have recorded the raw arguments string
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const callEvent = agent.session.snapshotEvents().find(e => e.type === 'tool/call')
expect(callEvent).toBeDefined()
if (callEvent!.type === 'tool/call') {
expect(callEvent!.data.arguments).toBe('not json')
}
// the loop did not crash — a result was produced
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/result')).toBe(true)
})
@@ -103,7 +101,6 @@ describe('tool JSON parse', () => {
send(agent, 'use tool')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/result')).toBe(true)
})
})
@@ -133,11 +130,8 @@ describe('thrown-value propagation', () => {
expect(errors).toHaveLength(1)
expect(errors[0]).toBe('naked string error')
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const starts = agent.session.snapshotEvents().filter(event => event.type === 'turn/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const ends = agent.session.snapshotEvents().filter(event => event.type === 'turn/end')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const messages = agent.session.snapshotEvents().filter(event => event.type === 'user/message')
expect(starts).toHaveLength(0)
expect(ends).toHaveLength(0)
@@ -161,7 +155,6 @@ describe('thrown-value propagation', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error'
? turnEnd.data.reason.error.message
@@ -187,7 +180,6 @@ describe('durable error rendering', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
expect(turnEnd).toBeDefined()
if (turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error') {
@@ -244,7 +236,6 @@ describe('structured tool error propagation (the runtime-validation Agent Note,
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const toolResult = agent.session.snapshotEvents().find(e => e.type === 'tool/result')
expect(toolResult?.type === 'tool/result' && toolResult.data.message.content[0].isError).toBe(true)
expect(toolResult?.type === 'tool/result' && toolResult.data.error)
@@ -271,7 +262,6 @@ describe('request-error action edges', () => {
// One failed request, no retry turn.
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const ends = agent.session.snapshotEvents().filter(e => e.type === 'turn/end')
expect(ends).toHaveLength(1)
})
@@ -294,7 +284,6 @@ describe('request-error action edges', () => {
await agent.whenIdle()
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('aborted')
})
@@ -324,7 +313,6 @@ describe('stream failure edges', () => {
// No facts -> not offered to recovery; the turn fails through settle().
expect(recoveries).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
})
@@ -400,7 +388,6 @@ describe('tool result meta persistence', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const result = agent.session.snapshotEvents().find(e => e.type === 'tool/result')
expect(result?.type === 'tool/result' && result.data.meta).toEqual({ presentation: 'diff-card' })
})
@@ -449,7 +436,6 @@ describe('recovery without a retry action', () => {
expect(recoveries).toBe(1)
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
})
@@ -475,7 +461,6 @@ describe('unrenderable failure settlement', () => {
send(agent, 'go')
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
if (end?.type === 'turn/end' && end.data.reason.kind === 'error') {
@@ -517,7 +502,6 @@ describe('driver bookkeeping edges', () => {
expect(proposals).toBe(2)
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason).toEqual({ kind: 'blocked' })
})
@@ -540,10 +524,8 @@ describe('driver bookkeeping edges', () => {
send(agent, 'go')
await agent.whenIdle()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types.filter(t => t === 'step/end')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const end = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(end?.type === 'turn/end' && end.data.reason.kind).toBe('error')
})
@@ -142,7 +142,6 @@ describe('ReactLoopInbox', () => {
const childAgent = stubAgent('inbox-fork-child', { ctx, session: child })
const childInbox = new ReactLoopInbox(ctx.sessionProjections, child, agentEvents(ctx, childAgent))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.inheritedEventCount).toBe(parent.snapshotEvents().length)
expect(childInbox.nextTurn).toEqual([inherited])
@@ -247,7 +246,6 @@ describe('ReactLoopInbox', () => {
const nextStep = createUserMessage({ content: [{ type: 'text', text: 'step' }], source: { kind: 'user' } })
agent.inbox.append('next-turn', nextTurn)
agent.inbox.append('next-step', nextStep)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const beforeClear = session.snapshotEvents().length
agent.inbox.clear()
@@ -255,7 +253,6 @@ describe('ReactLoopInbox', () => {
expect(agent.inbox.nextTurn).toEqual([])
expect(agent.inbox.nextStep).toEqual([])
expect(discarded).toEqual([nextStep, nextTurn])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().slice(beforeClear).map(event => event.type === 'agent/inbox/spliced'
? event.data
: event.type)).toEqual([
@@ -264,7 +261,6 @@ describe('ReactLoopInbox', () => {
])
agent.inbox.clear()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(beforeClear + 2)
})
})
@@ -57,7 +57,6 @@ function send(agent: Agent, text: string) {
}
function events(agent: Agent): readonly SessionEvent[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
}
@@ -53,7 +53,6 @@ function systemOf(request: GenerateOptions | undefined): string | undefined {
/** All user-message texts recorded in the log (to assert what actually ran). */
function userTexts(agent: Agent): string[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
.filter(e => e.type === 'user/message')
.flatMap(e => e.type === 'user/message' ? e.data.content : [])
@@ -73,7 +72,6 @@ describe('agent loop', () => {
if (subject !== agent) return
frames.push(frame)
if (frame.type === 'end' && frame.outcome.kind === 'committed') {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
committedAfterMessage = agent.session.snapshotEvents().at(-1)?.type === 'assistant/message'
}
})
@@ -93,9 +91,7 @@ describe('agent loop', () => {
(frame): frame is Extract<AssistantStreamFrame, { type: 'chunk' }> => frame.type === 'chunk',
)
expect(chunks.map(frame => frame.index)).toEqual(chunks.map((_frame, index) => index))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => (event.type as string) === 'assistant/chunk')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().findLast(event => event.type === 'assistant/message')
expect(message?.type === 'assistant/message'
? expandAssistantStream(message.data.stream).map(member => member.chunk)
@@ -137,7 +133,6 @@ describe('agent loop', () => {
type: 'end',
outcome: { kind: 'abandoned' },
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'assistant/message')).toBe(false)
})
@@ -165,11 +160,9 @@ describe('agent loop', () => {
index: 2,
outcome: { kind: 'abandoned' },
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => (
event.type === 'assistant/message' || event.type === 'assistant/attempt'
))).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error' } },
@@ -225,7 +218,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(frames).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error' } },
@@ -441,7 +433,6 @@ describe('agent loop', () => {
expect(userTexts(agent)).toEqual([])
expect(adapter.requests).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(e => e.type === 'turn/start')).toHaveLength(0)
})
@@ -465,14 +456,12 @@ describe('agent loop', () => {
expect(order).toEqual(['turn/start', 'step/start', 'step/end', 'turn/end'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
// Durable inbox receipt precedes the turn-owned transcript.
expect(types[0]).toBe('agent/inbox/spliced')
expect(types).toContain('turn/start')
expect(types).toContain('user/message')
expect(types).toContain('assistant/message')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const assistantMessage = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
expect(assistantMessage?.type === 'assistant/message' && assistantMessage.data.usage).toEqual({ inputTokens: 10, outputTokens: 'hello there'.length })
expect(types.at(-1)).toBe('turn/end')
@@ -515,7 +504,6 @@ describe('agent loop', () => {
expect((block).content).toEqual([{ type: 'text', text: 'echo: ping' }])
// session log records call + result
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = agent.session.snapshotEvents().map(e => e.type)
expect(types).toContain('tool/call')
expect(types).toContain('tool/result')
@@ -578,7 +566,6 @@ describe('agent loop', () => {
expect(errors.map(error => error.message)).toEqual([
'prompt variable "{{cwd}}" has no value for this assembly (section "deployment:persona-prefix")',
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind).toBe('error')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind === 'error'
@@ -596,7 +583,6 @@ describe('agent loop', () => {
expect(adapter.requests).toHaveLength(1)
expect(systemOf(adapter.requests[0])).toBe('You are an AI agent powered by DeepSeek Harness.\n\nIn /rescued.')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnds = agent.session.snapshotEvents().filter(e => e.type === 'turn/end')
expect(turnEnds).toHaveLength(2)
expect(turnEnds[1]?.type === 'turn/end' && turnEnds[1].data.reason.kind).toBe('completed')
@@ -644,7 +630,6 @@ describe('agent loop', () => {
expect(adapter.requests).toHaveLength(1)
expect('system' in adapter.requests[0]!).toBe(false)
expect(adapter.requests[0]!.messages.map(message => message.role)).toEqual(['user'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'system/message')).toMatchObject([
{ data: { message: { role: 'system', content: [] } }, surfaceOp: 'append' },
])
@@ -659,7 +644,6 @@ describe('agent loop', () => {
const firstIdle = waitForIdle(ctx, agent)
send(agent, 'first')
await firstIdle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const head = agent.session.snapshotEvents().find(event => event.type === 'system/message')
expect(adapter.requests[0]?.messages.map(message => message.role)).toEqual(['user'])
expect(head).toMatchObject({ data: { message: { content: [] } }, surfaceOp: 'append' })
@@ -672,14 +656,12 @@ describe('agent loop', () => {
expect(adapter.requests).toHaveLength(2)
expect(systemOf(adapter.requests[1])).toBe('You are an AI agent powered by DeepSeek Harness.')
expect(adapter.requests[1]?.messages.map(message => message.role)).toEqual(['system', 'user', 'assistant', 'user'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replacement = agent.session.snapshotEvents().findLast(event => event.type === 'system/message')
expect(replacement).toMatchObject({
surfaceOp: { op: 'replace', startSeq: head?.seq, endSeq: head?.seq },
sourceEventSeqs: [head?.seq],
})
expect(agent.session.surface.nodes[0]).toBe(replacement?.seq)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
} finally {
@@ -699,7 +681,6 @@ describe('agent loop', () => {
let mode = 'read-only'
const dispose = ctx.systemPrompt.context({ name: 'policy', order: 0, text: () => `Mode: ${mode}.` })
const agent = await ctx.agentLoop.create(SessionId('a-runtime-context'), { provider: 'mock', model: 'mock' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contextEvents = () => agent.session.snapshotEvents().flatMap(event =>
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -741,9 +722,7 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(contextEvents()).toHaveLength(3)
expect(adapter.requests.map(systemOf)).toEqual(Array(5).fill(systemOf(adapter.requests[0])))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'system/message')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
})
@@ -756,7 +735,6 @@ describe('agent loop', () => {
send(agent, 'first')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contextEvent = agent.session.snapshotEvents().find(event =>
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -772,7 +750,6 @@ describe('agent loop', () => {
send(agent, 'after compaction')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const runtimeContexts = agent.session.snapshotEvents().flatMap(event =>
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -793,7 +770,6 @@ describe('agent loop', () => {
send(agent, 'first')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contextEvent = agent.session.snapshotEvents().find(event =>
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -856,7 +832,6 @@ describe('agent loop', () => {
send(agent, 'repair context')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const runtimeContexts = agent.session.snapshotEvents().flatMap(event =>
event.type === 'user/message'
&& event.data.source.kind === 'plugin'
@@ -878,7 +853,6 @@ describe('agent loop', () => {
send(agent, 'hi')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const message = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
const chunks = message?.type === 'assistant/message' ? expandAssistantStream(message.data.stream) : []
// textResponse('abc') = block-start + 3 deltas + block-end + usage + finish = 7
@@ -913,14 +887,12 @@ describe('agent loop', () => {
send(agent, 'start')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const steering = agent.session.snapshotEvents().find(e =>
e.type === 'user/message' && JSON.stringify(e.data.content).includes('change of plans'))
expect(steering).toBeDefined()
// The entered batch is appended after the second step opens and before its
// request derives history.
const steeringSeq = steering!.seq
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const secondStepStart = agent.session.snapshotEvents().filter(e => e.type === 'step/start')[1]
expect(secondStepStart).toBeDefined()
expect(steeringSeq).toBeGreaterThan(secondStepStart!.seq)
@@ -939,14 +911,11 @@ describe('agent loop', () => {
const idle = waitForIdle(ctx, agent)
agent.steer(createUserMessage({ content: [{ type: 'text', text: 'first idle steer' }], source: { kind: 'user' } }))
expect(agent.status).toBe('running')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
agent.steer(createUserMessage({ content: [{ type: 'text', text: 'second idle steer' }], source: { kind: 'user' } }))
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.filter(event => event.type === 'user/message')
.map(event => event.data.content)).toEqual([
@@ -975,9 +944,7 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/end')).toHaveLength(1)
expect(agent.inbox.nextStep).toHaveLength(1)
@@ -985,7 +952,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(2)
expect(JSON.stringify(adapter.requests[0]?.messages)).toContain('pending steering')
})
@@ -998,9 +964,7 @@ describe('agent loop', () => {
agent.inject(createUserMessage({ content: [{ type: 'text', text: 'file changed: a.ts' }], source: { kind: 'plugin', plugin: 'watcher' } }))
expect(agent.status).toBe('idle')
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'agent/inbox/spliced',
data: {
@@ -1015,7 +979,6 @@ describe('agent loop', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
const flat = JSON.stringify(adapter.requests[0]!.messages)
expect(flat).toContain('file changed: a.ts')
@@ -1031,7 +994,6 @@ describe('agent loop', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contextEvent = agent.session.snapshotEvents().find(event => event.type === 'user/message' && event.data.source.kind === 'plugin')
expect(contextEvent?.type === 'user/message' && contextEvent.data.source)
.toEqual({ kind: 'plugin', plugin: 'agent-instructions' })
@@ -1058,7 +1020,6 @@ describe('agent loop', () => {
agent.inject(createUserMessage({ content: [first], source: { kind: 'plugin', plugin: 'x' } }))
first.text = 'mutated after inject'
agent.inject(createUserMessage({ content: [{ type: 'text', text: 'second notice' }], source: { kind: 'plugin', plugin: 'x' } }))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
visibleDuringTool = agent.session.snapshotEvents().some(e => e.type === 'user/message' && e.data.source.kind === 'plugin')
return [{ type: 'text', text: 'ok' }]
},
@@ -1071,12 +1032,9 @@ describe('agent loop', () => {
// The injection stays in the open turn, but its user-role context cannot
// split the assistant tool call from the provider's tool-result message.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnStarts = agent.session.snapshotEvents().filter(e => e.type === 'turn/start')
expect(turnStarts).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const result = agent.session.snapshotEvents().find(e => e.type === 'tool/result')!
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const contexts = agent.session.snapshotEvents().filter(e => e.type === 'user/message' && e.data.source.kind === 'plugin')
expect(contexts).toHaveLength(2)
expect(result.seq).toBeLessThan(contexts[0]!.seq)
@@ -1121,7 +1079,6 @@ describe('agent loop', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'user/message' && event.data.source.kind === 'plugin')).toBe(false)
})
@@ -1167,7 +1124,6 @@ describe('agent loop', () => {
// only one model call despite the tool call requesting a follow-up
expect(adapter.requests).toHaveLength(1)
// The tool still executes and durably records its result.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/result')).toBe(true)
})
@@ -1194,7 +1150,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents().map(event => event.type)
expect(events.filter(type => type === 'turn/end')).toHaveLength(1)
expect(JSON.stringify(adapter.requests[1]?.messages)).toContain('late steering')
@@ -1224,7 +1179,6 @@ describe('agent loop', () => {
expect(adapter.requests[0]!.model).toBe('other-model')
// The header event records what the request ACTUALLY used — the switch is
// a reconstructable fact, not silent drift.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headerEvent = agent.session.snapshotEvents().find(e => e.type === 'request/header')
expect(headerEvent?.type === 'request/header' && headerEvent.data.header.config.model).toBe('other-model')
})
@@ -1264,7 +1218,6 @@ describe('agent loop', () => {
let boundaryOpen = true
ctx.on('agent/pre-step', ({ agent: subject }, next) => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
if (subject === agent) boundaryOpen = subject.session.snapshotEvents().at(-1)?.type === 'step/start'
return next()
})
@@ -1297,16 +1250,13 @@ describe('agent loop', () => {
// The first proposal failed inside a balanced turn without calling the model.
expect(errors.map(error => error.message)).toEqual(['boom in pre-step'])
expect(adapter.requests.length).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'turn/start')).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(event => event.type === 'turn/end')).toBe(true)
// The loop survived: a second prompt runs a normal completed turn.
send(agent, 'second')
await waitForIdle(ctx, agent)
expect(adapter.requests.length).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const lastTurnEnd = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(lastTurnEnd?.type === 'turn/end' && lastTurnEnd.data.reason).toEqual({ kind: 'completed' })
})
@@ -1353,7 +1303,6 @@ describe('agent loop', () => {
expect(adapter.requests).toHaveLength(1)
expect(reasons).toEqual([{ kind: 'max-tokens' }])
// Assert the durable row, not only the live listener.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(turnEnd!.data.reason).toEqual({ kind: 'max-tokens' })
})
@@ -1458,7 +1407,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(executions).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/call')).toBe(false)
expect(agent.session.deriveMessages().slice(1)).toEqual([{
id: expect.any(String) as unknown,
@@ -1469,7 +1417,6 @@ describe('agent loop', () => {
expect(reasons).toEqual([{ kind: 'max-tokens' }])
// Empty content still needs an assistant/message to carry usage; derivation
// skips that host so it does not create a spurious assistant turn.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const assistantMessage = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')
expect(assistantMessage?.type === 'assistant/message' && assistantMessage.data).toMatchObject({
turn: 1,
@@ -1510,7 +1457,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(reasons).toEqual([{ kind: 'max-tokens' }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const assistant = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')!
expect(assistant.type === 'assistant/message' && assistant.data).toMatchObject({
turn: 1,
@@ -1546,7 +1492,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(reasons).toEqual([{ kind: 'completed' }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const assistant = agent.session.snapshotEvents().find(e => e.type === 'assistant/message')!
expect(assistant.type === 'assistant/message' && assistant.data).toMatchObject({
turn: 1,
@@ -1590,7 +1535,6 @@ describe('agent loop', () => {
send(agent, 'continue')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'tool/call')).toBe(false)
// The follow-up request replays the truncated message with its replay
// metadata pruned in step with the dropped tool call.
@@ -1659,7 +1603,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(e => e.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason.kind).toBe('completed')
})
@@ -1681,9 +1624,7 @@ describe('agent loop', () => {
send(agent, 'outer message')
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turns = agent.session.snapshotEvents().filter(event => event.type === 'turn/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const messages = agent.session.snapshotEvents()
.filter(event => event.type === 'user/message')
.map(event => event.data.content)
@@ -1702,9 +1643,7 @@ describe('agent loop', () => {
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'plugin message' }], source: { kind: 'plugin', plugin: 'test' } }))
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turns = agent.session.snapshotEvents().filter(event => event.type === 'turn/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const sources = agent.session.snapshotEvents()
.filter(event => event.type === 'user/message')
.map(event => event.data.source)
@@ -1760,11 +1699,9 @@ describe('agent loop', () => {
send(agent, 'outer message')
await idle
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const messages = agent.session.snapshotEvents()
.filter(event => event.type === 'user/message')
.map(event => event.data.content)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(2)
expect(messages).toEqual([
[{ type: 'text', text: 'outer message' }],
@@ -1795,7 +1732,6 @@ describe('agent loop', () => {
})
expect(reasons[0]).toMatchObject({ kind: 'error' })
// The durable failure and live relay describe the same failed turn.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().find(e => e.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason).toMatchObject({ kind: 'error' })
})
@@ -1849,7 +1785,6 @@ describe('agent loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(1)
expect(adapter.requests[0]?.reasoningEffort).toBe(effort)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const header = agent.session.snapshotEvents().find(event => event.type === 'request/header')
expect(header?.type === 'request/header' && header.data.header.config.reasoningEffort).toBe(effort)
})
@@ -1888,15 +1823,11 @@ describe('agent loop', () => {
send(agent, 'run')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = ctx.sessions.create(SessionId('replayed'), { seed: [...agent.session.snapshotEvents()] })
expect(replayed.deriveMessages()).toEqual(agent.session.deriveMessages())
// event-by-event identity of types over the inherited prefix
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().slice(0, agent.session.seq).map(e => e.type)).toEqual(
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
agent.session.snapshotEvents().map(e => e.type))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().at(-1)?.type).toBe('session/end-seed')
})
})
@@ -72,21 +72,18 @@ function recordStatus(ctx: Context, agent: Agent): { seen: string[]; dispose: ()
}
function userMessageTexts(agent: Agent): string[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
.filter(e => e.type === 'user/message')
.map(e => (e.data as { content: { type: string; text?: string }[] }).content.map(b => b.text ?? '').join(''))
}
function turnNumbers(agent: Agent): number[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
.filter(e => e.type === 'turn/start')
.map(e => e.data.turn)
}
function turnEndNumbers(agent: Agent): number[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
.filter(e => e.type === 'turn/end')
.map(e => (e.data as { turn: number }).turn)
@@ -94,7 +91,6 @@ function turnEndNumbers(agent: Agent): number[] {
function userMessageCountsByTurn(agent: Agent): number[] {
const counts: number[] = []
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of agent.session.snapshotEvents()) {
if (event.type === 'turn/start') counts.push(0)
if (event.type === 'user/message') counts[counts.length - 1]! += 1
@@ -82,7 +82,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('log-derived request cache hits (
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'Thanks. Repeat that value one more time.' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const usages = agent.session.snapshotEvents()
.filter(e => e.type === 'assistant/message')
.map(e => e.data.usage)
@@ -92,14 +92,12 @@ describe('agent/request-error', () => {
code: 'SERVICE_UNAVAILABLE',
},
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
expect(seen.map(item => item.retryPolicy)).toEqual([
expect.objectContaining({ mode: 'normal' }),
expect.objectContaining({ mode: 'normal' }),
])
expect(statuses).toEqual(['running', 'idle'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
})
@@ -117,9 +115,7 @@ describe('agent/request-error', () => {
await agent.whenIdle()
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().find(event => event.type === 'turn/end')).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'aborted', reason: { kind: 'user' } } },
@@ -141,9 +137,7 @@ describe('agent/request-error', () => {
await agent.whenIdle()
expect(adapter.requests).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'turn/start')).toHaveLength(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().find(event => event.type === 'turn/end')).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error' } },
@@ -58,7 +58,6 @@ describe('loop-owned request freezing', () => {
}),
stream: [],
}, { surfaceOp: 'append' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = structuredClone(seed.snapshotEvents())
const userEvent = events.find(event => event.type === 'user/message')!
const assistantEvent = events.find(event => event.type === 'assistant/message')!
@@ -199,7 +198,6 @@ describe('loop-owned request freezing', () => {
expect(() => request.stop!.push('mutate')).toThrow(TypeError)
if (!registered) expect(request.stop).toBe(stops[index])
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(event => event.type === 'request/header')).toHaveLength(1)
expect(agent.session.requestHeader()!.tools).not.toBe(requests[0]!.tools)
expect(agent.session.requestHeader()!.config.stop).not.toBe(requests[0]!.stop)
@@ -223,7 +221,6 @@ describe('loop-owned request freezing', () => {
await agent.whenIdle()
expect(request.signal!.aborted).toBe(true)
expect(request.signal!.reason).toEqual({ kind: 'user' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().at(-1)).toMatchObject({
type: 'turn/end', data: { reason: { kind: 'aborted', reason: { kind: 'user' } } },
})
@@ -94,7 +94,6 @@ describe('request stability across the loop', () => {
expect(Object.isFrozen(request.messages)).toBe(true)
}
// One anchoring header snapshot; no further header events (nothing changed).
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headerEvents = agent.session.snapshotEvents().filter(e => e.type === 'request/header')
expect(headerEvents).toHaveLength(1)
expect(headerEvents[0]?.type === 'request/header' && headerEvents[0].data.reason).toBe('initial')
@@ -112,7 +111,6 @@ describe('request stability across the loop', () => {
expect(adapter.requests).toHaveLength(2)
expectPrefixExtension(adapter.requests[0]!, adapter.requests[1]!)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
})
@@ -134,7 +132,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
expectPrefixExtension(adapter.requests[0]!, adapter.requests[1]!)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
})
@@ -160,7 +157,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
expectPrefixExtension(adapter.requests[0]!, adapter.requests[1]!)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event => event.type === 'request/header'
? [{ reason: event.data.reason, startsSeries: event.data.startsSeries }]
: [])).toEqual([
@@ -198,7 +194,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
expectPrefixExtension(adapter.requests[0]!, adapter.requests[1]!)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
})
@@ -228,7 +223,6 @@ describe('request stability across the loop', () => {
ReasoningEffortId('high'),
ReasoningEffortId('max'),
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headers = agent.session.snapshotEvents().filter(event => event.type === 'request/header')
expect(headers.map(event => event.data.header.config.reasoningEffort)).toEqual([
ReasoningEffortId('high'),
@@ -248,7 +242,6 @@ describe('request stability across the loop', () => {
const resumedCtx = await harness(resumedAdapter)
const resumedHandle = await resumedCtx.agents.create({
sessionId: SessionId(`effort-${model}`),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: structuredClone(agent.session.snapshotEvents()),
agentOptions: { provider: 'mock', model },
})
@@ -257,7 +250,6 @@ describe('request stability across the loop', () => {
expect(resumedAdapter.requests[0]?.model).toBe(model)
expect(resumedAdapter.requests[0]?.reasoningEffort).toBe(effort)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const resumedHeaders = resumedHandle.agent.session.snapshotEvents().filter(event => event.type === 'request/header')
expect(resumedHeaders.at(-1)?.data.header.config.reasoningEffort).toBe(effort)
expect(resumedHeaders.at(-1)?.data.reason).toBe('resume')
@@ -276,7 +268,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests[0]?.maxTokens).toBe(256_000)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const header = agent.session.snapshotEvents().find(event => event.type === 'request/header')
expect(header?.type === 'request/header' && header.data.header.config.maxTokens).toBe(256_000)
expect(header?.type === 'request/header' && header.data.header.adapterDefaults)
@@ -308,7 +299,6 @@ describe('request stability across the loop', () => {
expect(deepseek.requests[0]?.maxTokens).toBe(256_000)
expect(other.requests[0]?.maxTokens).toBe(8_192)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headers = agent.session.snapshotEvents().filter(event => event.type === 'request/header')
expect(headers.map(event => event.data.header.config.maxTokens)).toEqual([256_000, 8_192])
expect(headers.map(event => event.data.header.adapterDefaults)).toEqual([
@@ -343,7 +333,6 @@ describe('request stability across the loop', () => {
expect(deepseek.requests[0]?.maxTokens).toBe(4_096)
expect(other.requests[0]?.maxTokens).toBe(4_096)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headers = agent.session.snapshotEvents().filter(event => event.type === 'request/header')
expect(headers.map(event => event.data.header.config.maxTokens)).toEqual([4_096, 4_096])
expect(headers.map(event => event.data.header.adapterDefaults)).toEqual([undefined, undefined])
@@ -396,7 +385,6 @@ describe('request stability across the loop', () => {
ReasoningEffortId('high'),
])
expect(second.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headers = agent.session.snapshotEvents().filter(event => event.type === 'request/header')
expect(headers.at(-1)?.data.header.config.reasoningEffort).toBe(ReasoningEffortId('high'))
})
@@ -435,7 +423,6 @@ describe('request stability across the loop', () => {
expect(signal.aborted).toBe(true)
expect(handle.agent.status).toBe('idle')
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(handle.agent.session.snapshotEvents().some(event => event.type === 'request/header')).toBe(false)
})
@@ -459,7 +446,6 @@ describe('request stability across the loop', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')).toMatchObject({
data: {
reason: failure instanceof LlmError
@@ -535,7 +521,6 @@ describe('request stability across the loop', () => {
// The rewritten history: summary replaces turn 1's user+assistant pair behind the system prompt.
expect(second.messages[0]!.role).toBe('system')
expect(second.messages[1]!.content.some(b => b.type === 'text' && b.text.includes('[summary of turn 1]'))).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event => event.type === 'request/header'
? [{ reason: event.data.reason, startsSeries: event.data.startsSeries }]
: [])).toEqual([
@@ -574,7 +559,6 @@ describe('request stability across the loop', () => {
expect(adapter.requests[1]?.messages[1]?.content).toContainEqual({
type: 'text', text: '[summary for retry]',
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
})
@@ -588,7 +572,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
@@ -596,10 +579,8 @@ describe('request stability across the loop', () => {
send(agent, 'third')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const snapshots = agent.session.snapshotEvents().filter(e => e.type === 'request/header')
expect(snapshots.map(event => event.data.reason)).toEqual(['initial', 'series'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(2)
expect(systemNodes[1]?.surfaceOp).toEqual({ op: 'replace', startSeq: systemNodes[0]?.seq, endSeq: systemNodes[0]?.seq })
@@ -629,10 +610,8 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
// No new series: the header stays, node 0 stays, and the prompt update follows the cached prefix.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(2)
expect(systemNodes[1]?.surfaceOp).toBe('append')
@@ -646,7 +625,6 @@ describe('request stability across the loop', () => {
// An unchanged prompt adds nothing on the next step.
send(agent, 'fourth')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().filter(e => e.type === 'system/message')).toHaveLength(2)
expectPrefixExtension(adapter.requests[2]!, adapter.requests[3]!)
})
@@ -670,11 +648,9 @@ describe('request stability across the loop', () => {
startSeries = true
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
let systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(2)
expect(systemNodes[1]?.surfaceOp).toEqual({ op: 'replace', startSeq: systemNodes[0]?.seq, endSeq: systemNodes[0]?.seq })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
@@ -684,7 +660,6 @@ describe('request stability across the loop', () => {
disposeSection = ctx.systemPrompt.section({ name: 'extra', order: 2, text: 'newer guidance' })
send(agent, 'third')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(3)
expect(systemNodes[2]?.surfaceOp).toBe('append')
@@ -695,7 +670,6 @@ describe('request stability across the loop', () => {
ctx.systemPrompt.section({ name: 'extra', order: 2, text: 'newest guidance' })
send(agent, 'fourth')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(5)
expect(systemNodes[3]?.data.message.content).toEqual([])
@@ -729,12 +703,10 @@ describe('request stability across the loop', () => {
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(2)
expect(systemNodes[1]?.surfaceOp).toEqual({ op: 'replace', startSeq: systemNodes[0]?.seq, endSeq: systemNodes[0]?.seq })
expect(adapter.requests[1]!.messages.map(message => message.role)).toEqual(['system', 'user', 'user'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial', 'series'])
})
@@ -753,10 +725,8 @@ describe('request stability across the loop', () => {
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const headers = agent.session.snapshotEvents().filter(e => e.type === 'request/header')
expect(headers.map(event => [event.data.reason, event.data.startsSeries])).toEqual([['initial', undefined], ['change', true]])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const systemNodes = agent.session.snapshotEvents().filter(e => e.type === 'system/message')
expect(systemNodes).toHaveLength(2)
expect(systemNodes[1]?.surfaceOp).toEqual({ op: 'replace', startSeq: systemNodes[0]?.seq, endSeq: systemNodes[0]?.seq })
@@ -782,7 +752,6 @@ describe('request stability across the loop', () => {
const first = adapter.requests[0]!
// The inject landed in the log after the boundary: not in THIS request…
expect(first.messages.some(m => m.content.some(b => b.type === 'text' && b.text.includes('[late context]')))).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'user/message' && e.data.source.kind === 'plugin')).toBe(true)
send(agent, 'second')
@@ -810,7 +779,6 @@ describe('request stability across the loop', () => {
send(agent, 'go')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd).toMatchObject({ data: { reason: { kind: 'error' } } })
if (turnEnd?.type !== 'turn/end' || turnEnd.data.reason.kind !== 'error') throw new Error()
@@ -830,7 +798,6 @@ describe('request stability across the loop', () => {
const ctx2 = await harness(adapter2)
const handle = await ctx2.agents.create({
sessionId: SessionId('gen2-session'),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: agent.session.snapshotEvents(),
agentOptions: { provider: 'mock', model: 'mock' },
})
@@ -838,13 +805,11 @@ describe('request stability across the loop', () => {
send(agent2, 'second')
await waitForIdle(ctx2, agent2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const snapshots = agent2.session.snapshotEvents().filter(e => e.type === 'request/header')
expect(snapshots).toHaveLength(2)
expect(snapshots[1]?.data.reason).toBe('resume')
// Identical header and an unchanged system node across the restart: byte-identical continuation.
expect(adapter2.requests[0]!.messages[0]).toEqual(adapter.requests[0]!.messages[0])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent2.session.snapshotEvents().filter(event => event.type === 'system/message')).toHaveLength(1)
expectPrefixExtension(adapter.requests[0]!, adapter2.requests[0]!)
})
@@ -873,7 +838,6 @@ describe('request stability across the loop', () => {
// The second turn reuses the same series and header; the session's own
// fold remains immutable state.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().flatMap(event =>
event.type === 'request/header' ? [event.data.reason] : [])).toEqual(['initial'])
expect(Object.isFrozen(agent.session.requestHeader())).toBe(true)
@@ -900,7 +864,6 @@ describe('request stability across the loop', () => {
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(3)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = agent.session.snapshotEvents()
const stepStarts = events.filter(e => e.type === 'step/start')
expect(stepStarts).toHaveLength(3)
@@ -957,7 +920,6 @@ describe('request/context capacity records', () => {
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const records = agent.session.snapshotEvents().filter(event => event.type === 'request/context')
expect(records).toHaveLength(1)
expect(records[0]?.data).toEqual({ provider: 'mock', model: 'mock', contextWindow: 128_000 })
@@ -983,7 +945,6 @@ describe('request/context capacity records', () => {
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.filter(event => event.type === 'request/context')
.map(event => event.data.contextWindow)).toEqual([64_000, 256_000])
@@ -996,7 +957,6 @@ describe('request/context capacity records', () => {
await waitForIdle(ctx, agent)
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.filter(event => event.type === 'request/context')
.map(event => event.data)).toEqual([{ provider: 'mock', model: 'mock' }])
@@ -1017,7 +977,6 @@ describe('request/context capacity records', () => {
send(agent, 'second')
await waitForIdle(ctx, agent)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()
.filter(event => event.type === 'request/context')
.map(event => event.data)).toEqual([
@@ -484,7 +484,6 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
// Lifecycle 2: resume repairs the tail and stores the repair durably.
const ctx2 = await mountPersistentHarness(root, new MockAdapter([]))
const handle = await ctx2.agents.resume({ resumeSessionId: sessionId })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(handle.agent.session.snapshotEvents().map(event => event.type))
.toEqual(['turn/start', 'turn/end', 'session/end-seed'])
await handle.dispose()
@@ -553,7 +552,6 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
// closers immediately after the committed prefix — no gap, no fragment.
const ctx2 = await mountPersistentHarness(root, new MockAdapter([]), 'none')
const handle = await ctx2.agents.resume({ resumeSessionId: sessionId })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(handle.agent.session.snapshotEvents().map(event => event.type))
.toEqual(['turn/start', 'turn/end', 'session/end-seed'])
await handle.dispose()
@@ -641,7 +639,6 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
setup: async (agentCtx, agent) => {
expect(agent.id).toBe(sessionId)
// The two persisted events plus the end-seed marker.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents()).toHaveLength(3)
agentCtx.on('session/created', () => void order.push('setup-listener:session/created'))
agentCtx.on('agent/created', () => void order.push('setup-listener:agent/created'))
@@ -694,7 +691,6 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
expect(stored.map(event => event.type)).toEqual(['turn/start', 'turn/end', 'session/end-seed'])
const second = await ctx.agents.resume({ resumeSessionId: sessionId })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(second.agent.session.snapshotEvents().map(event => event.type))
.toEqual(['turn/start', 'turn/end', 'session/end-seed'])
await second.dispose()
@@ -987,7 +983,6 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
const a1 = h1.agent
a1.followup(createUserMessage({ content: [{ type: 'text', text: 'first question' }], source: { kind: 'user' } }))
await waitForIdle(ctx1, a1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events1 = a1.session.snapshotEvents()
const seqs1 = events1.map(e => e.seq)
expect(seqs1).toEqual([...seqs1].sort((x, y) => x - y)) // contiguous
@@ -1001,10 +996,8 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
// The resumed session carries the prior history…
expect(a2.session.id).toBe('sess-resume')
// …followed by one end-seed event marking the constructor seed.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(a2.session.snapshotEvents().length).toBe(events1.length + 1)
expect(a2.session.firstLiveSeq).toBe(events1.length)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(a2.session.snapshotEvents().at(-1)?.type).toBe('session/end-seed')
const replay = Session.create(SessionId('replay'), events1)
expect(a2.session.deriveMessages()).toEqual(replay.deriveMessages())
@@ -1012,10 +1005,8 @@ describe('the session-persistence Agent Note: AgentLoop factory create/resume',
// …and a new turn continues numbering (turn 2) with contiguous seqs.
a2.followup(createUserMessage({ content: [{ type: 'text', text: 'second question' }], source: { kind: 'user' } }))
await waitForIdle(ctx2, a2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const allSeqs = a2.session.snapshotEvents().map(e => e.seq)
expect(allSeqs).toEqual(allSeqs.map((_, i) => i)) // 0..N contiguous, no duplicates
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnStarts = a2.session.snapshotEvents().filter(e => e.type === 'turn/start')
expect(turnStarts.map(e => e.type === 'turn/start' && e.data.turn)).toEqual([1, 2])
await ctx2.fiber.dispose()
@@ -809,7 +809,6 @@ describe('agent scope lifecycle', () => {
expect(statuses).toEqual([])
expect(observerSawLive).toBe(true)
expect(scopeDisposed).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(announced.session.snapshotEvents()).toEqual([])
expect(ctx.agents.get(SessionId('session-start-dispose-s'))).toBeUndefined()
expect(ctx.sessions.get(SessionId('session-start-dispose-s'))).toBeUndefined()
@@ -1115,10 +1114,8 @@ describe('agent scope lifecycle', () => {
// are empty and nothing still drives the detached session.
expect(ctx.agents.get(agent.id)).toBeUndefined()
expect(ctx.sessions.get(agent.id)).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const eventsAfter = agent.session.snapshotEvents().length
await new Promise(resolve => setTimeout(resolve, 30))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().length).toBe(eventsAfter)
await ctx.fiber.dispose()
})
@@ -39,7 +39,6 @@ async function harness(capable = new MockAdapter(Array.from({ length: 8 }, () =>
ctx.on('llm/stream', (request, next) => {
// Rebuild from copied source events, not the live projection's cached state.
const subject = ctx.agents.get(request.sessionId!)!
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replay = Session.create(subject.id, subject.session.snapshotEvents())
expect(request.messages).toEqual(replay.deriveMessages())
expect(request.system).toBeUndefined()
@@ -84,26 +83,21 @@ describe('prepared-route prompt admission', () => {
expect(systemTexts(cleared)).toEqual([])
expect(toPiContext(cleared).systemPrompt).toBeUndefined()
expect(JSON.stringify(toPiContext(cleared))).not.toContain('prompt ')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const clearEvents = h.agent.session.snapshotEvents().filter(event => event.type === 'system/message').filter(event => event.data.turn === 4)
expect(clearEvents).toHaveLength(3)
for (const event of clearEvents) {
expect(event.data.message.content).toEqual([])
expect(event.surfaceOp).toEqual({ op: 'replace', startSeq: event.sourceEventSeqs?.[0], endSeq: event.sourceEventSeqs?.[0] })
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const count = h.agent.session.snapshotEvents().filter(event => event.type === 'system/message').length
await send(h.agent, 'still clear')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(h.agent.session.snapshotEvents().filter(event => event.type === 'system/message')).toHaveLength(count)
expect(systemTexts(adapter.requests.at(-1)!)).toEqual([])
const { agent: resumed } = await h.ctx.agents.create({
sessionId: SessionId('cleared-resume'), agentOptions: { provider, model: 'model' },
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: [...h.agent.session.snapshotEvents()],
})
await send(resumed, 'resume clear')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.session.snapshotEvents().filter(event => event.type === 'system/message')).toHaveLength(count)
expect(systemTexts(adapter.requests.at(-1)!)).toEqual([])
h.setPrompt('restored instruction')
@@ -130,7 +124,6 @@ describe('prepared-route prompt admission', () => {
}
await send(h.agent, 'third')
expectPlain(h.capable.requests[2]!, 'prompt two')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const header = h.agent.session.snapshotEvents().filter(event => event.type === 'request/header').at(-1)
expect(header?.data.reason).toBe(reason === 'explicit' ? 'series' : 'change')
if (reason === 'tools') expect(header?.data.startsSeries).toBe(true)
@@ -154,7 +147,6 @@ describe('prepared-route prompt admission', () => {
expect(failure.code).toBe('CONTEXT_LENGTH')
if (attempts++ === 0) {
const nodes = h.agent.session.surface.nodes
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const latest = nodes.findLast(seq => h.agent.session.eventAt(seq)?.type === 'system/message')!
const start = retainOlder ? latest : nodes[1]!
const replaced = nodes.slice(nodes.indexOf(start), nodes.indexOf(latest) + 1)
@@ -174,7 +166,6 @@ describe('prepared-route prompt admission', () => {
expectPlain(adapter.requests[3]!, 'prompt three')
expect(adapter.requests[4]!.messages).toEqual(adapter.requests[3]!.messages)
expect(adapter.requests[3]!.messages.at(-1)?.content).toEqual([{ type: 'text', text: 'third' }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = h.agent.session.snapshotEvents()
expect(events.filter(event => event.type === 'step/start')).toHaveLength(3)
expect(events.filter(event => event.type === 'user/message' && event.data.source.kind === 'user')).toHaveLength(3)
@@ -192,7 +183,6 @@ describe('prepared-route prompt admission', () => {
if (changed) h.setPrompt('prompt three')
await send(h.agent, 'third')
expectPlain(h.plain.requests[0]!, changed ? 'prompt three' : 'prompt two')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = h.agent.session.snapshotEvents()
const replacements = events.filter(event => event.type === 'system/message').filter(event => event.surfaceOp !== 'append')
expect(replacements).toHaveLength(2)
@@ -201,7 +191,6 @@ describe('prepared-route prompt admission', () => {
expect(event.surfaceOp).toEqual({ op: 'replace', startSeq: event.sourceEventSeqs?.[0], endSeq: event.sourceEventSeqs?.[0] })
}
await send(h.agent, 'fourth')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(h.agent.session.snapshotEvents().filter(event => event.type === 'system/message')).toHaveLength(4)
expectPlain(h.plain.requests[1]!, changed ? 'prompt three' : 'prompt two')
})
@@ -225,7 +214,6 @@ describe('prepared-route prompt admission', () => {
expect(messages.slice(-2).map(message => message.content)).toEqual([
[{ type: 'text', text: 'second' }], notice,
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const notices = h.agent.session.snapshotEvents().filter(event => event.type === 'user/message'
&& event.data.source.kind === 'plugin' && event.data.source.plugin === 'model-selection')
expect(notices).toHaveLength(1)
@@ -242,12 +230,10 @@ describe('prepared-route prompt admission', () => {
await send(h.agent, 'second')
const { agent: resumed } = await h.ctx.agents.create({
sessionId: SessionId('resumed-capable'), agentOptions: { provider: 'capable', model: 'model' },
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: [...h.agent.session.snapshotEvents()],
})
h.ctx.on('agent/pre-step', ({ agent }, next) => {
if (agent === resumed && replace) {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const seq = agent.session.surface.nodes.find(seq => agent.session.eventAt(seq)?.type === 'user/message')!
agent.session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'compacted history' }], source: { kind: 'plugin', plugin: 'test-compaction' },
@@ -259,7 +245,6 @@ describe('prepared-route prompt admission', () => {
expect(systemTexts(h.capable.requests[2]!)).toEqual(replace
? [[{ type: 'text', text: 'prompt two' }]]
: [[{ type: 'text', text: 'prompt one' }], [{ type: 'text', text: 'prompt two' }]])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.session.snapshotEvents().filter(event => event.type === 'request/header').map(event => event.data.reason))
.toEqual(['initial', 'resume'])
})
@@ -269,12 +254,10 @@ describe('prepared-route prompt admission', () => {
await send(h.agent, 'first')
h.setPrompt('prompt two')
await send(h.agent, 'second')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const seed = h.agent.session.snapshotEvents()
const { agent: resumed } = await h.ctx.agents.create({ sessionId: SessionId('resumed'), agentOptions: { provider: 'plain', model: 'model' }, seed: [...seed] })
await send(resumed, 'resume')
expectPlain(h.plain.requests[0]!, 'prompt two')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.session.snapshotEvents().filter(event => event.type === 'request/header').at(-1)?.data.reason).toBe('resume')
})
@@ -283,7 +266,6 @@ describe('prepared-route prompt admission', () => {
const entered = Promise.withResolvers<undefined>()
const release = Promise.withResolvers<undefined>()
const observe = async () => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = h.agent.session.snapshotEvents().map(event => event.type)
expect(types).toContain('step/start')
expect(types).not.toContain('system/message')
@@ -303,7 +285,6 @@ describe('prepared-route prompt admission', () => {
release.resolve(undefined)
await h.agent.whenIdle()
expect(h.capable.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const types = h.agent.session.snapshotEvents().map(event => event.type)
expect(types.filter(type => type === 'step/start' || type === 'step/end')).toEqual(['step/start', 'step/end'])
expect(types.filter(type => ['system/message', 'user/message', 'request/header'].includes(type))).toEqual([])
@@ -322,7 +303,6 @@ describe('prepared-route prompt admission', () => {
expect(h.plain.requests).toHaveLength(0)
expect(h.capable.requests[1]).toMatchObject({ provider: 'capable', temperature: 0.5, maxTokens: 100 })
expect(systemTexts(h.capable.requests[1]!)).toHaveLength(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(h.agent.session.snapshotEvents().filter(event => event.type === 'user/message')).toHaveLength(2)
})
})
@@ -42,7 +42,6 @@ function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
}
function events(agent: Agent): readonly SessionEvent[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return agent.session.snapshotEvents()
}
@@ -69,7 +69,6 @@ async function runTurn(registrationOrder: string[], toolOrder?: SystemPromptConf
describe('loop-level canonical tool order', () => {
it('logs the request/header with tools in canonical order, not registration order', async () => {
const { agent, adapter } = await runTurn(['zulu', 'alpha', 'mike'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const header = foldRequestHeader(agent.session.snapshotEvents())
expect(header?.tools?.map(tool => tool.name)).toEqual(['alpha', 'mike', 'zulu'])
// The dispatched request is built FROM the logged header (whose tools the
@@ -83,7 +82,6 @@ describe('loop-level canonical tool order', () => {
it('produces the same header order for any registration order', async () => {
const first = await runTurn(['alpha', 'mike', 'zulu'])
const second = await runTurn(['zulu', 'mike', 'alpha'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const names = (run: typeof first) => foldRequestHeader(run.agent.session.snapshotEvents())?.tools?.map(tool => tool.name)
expect(names(first)).toEqual(['alpha', 'mike', 'zulu'])
expect(names(second)).toEqual(names(first))
@@ -91,7 +89,6 @@ describe('loop-level canonical tool order', () => {
it('honors a configured toolOrder in the logged header and the dispatched request', async () => {
const { agent, adapter } = await runTurn(['alpha', 'zulu', 'mike'], ['zulu', TOOL_ORDER_REST])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const header = foldRequestHeader(agent.session.snapshotEvents())
expect(header?.tools?.map(tool => tool.name)).toEqual(['zulu', 'alpha', 'mike'])
expect(adapter.requests[0]?.tools?.map(tool => tool.name)).toEqual(['zulu', 'alpha', 'mike'])
@@ -106,15 +103,10 @@ describe('loop-level canonical tool order', () => {
agent.followup(createUserMessage({ content: [{ type: 'text', text: 'go' }], source: { kind: 'user' } }))
await waitForIdle(ctx, agent)
expect(adapter.requests).toHaveLength(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldRequestHeader(agent.session.snapshotEvents())).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'turn/start')).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'turn/end')).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'step/start')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(agent.session.snapshotEvents().some(e => e.type === 'step/end')).toBe(false)
})
})
@@ -40,7 +40,6 @@ describe('foldConsumedWork', () => {
const session = Session.create(SessionId('empty'))
accept(session, 'queued')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents())).toEqual({ droppedUnrun: false })
})
@@ -49,7 +48,6 @@ describe('foldConsumedWork', () => {
steppedTurn(session, 1, { kind: 'completed' })
steppedTurn(session, 2, { kind: 'max-tokens' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data)
.toEqual({ turn: 2, reason: { kind: 'max-tokens' } })
})
@@ -63,7 +61,6 @@ describe('foldConsumedWork', () => {
claim(session)
session.append('turn/end', { turn: 2, reason: { kind: 'error', error: { message: 'ENOSPC', code: 'UNKNOWN' } } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(2)
})
@@ -74,7 +71,6 @@ describe('foldConsumedWork', () => {
claim(session)
session.append('turn/end', { turn: 2, reason: { kind: 'aborted', reason: { kind: 'user' } } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(2)
})
@@ -89,7 +85,6 @@ describe('foldConsumedWork', () => {
session.append('turn/end', { turn: 4, reason: { kind: 'blocked' } })
// None of these turns describes work: they opened, found nothing of their own, and closed.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(1)
})
@@ -102,7 +97,6 @@ describe('foldConsumedWork', () => {
// Rejection does not retain the claimed messages, so the `blocked` end is
// the only account of input that will never run.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(2)
})
@@ -115,7 +109,6 @@ describe('foldConsumedWork', () => {
// An emptied claim ran nothing and dropped nothing: a listener rewrote the
// batch away, which is not this log's account of the work.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(1)
})
@@ -127,7 +120,6 @@ describe('foldConsumedWork', () => {
claim(session)
session.append('turn/end', { turn: 2, reason: { kind: 'aborted', reason: { kind: 'user' } } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).end?.data.turn).toBe(1)
})
@@ -138,9 +130,7 @@ describe('foldConsumedWork', () => {
cancelPending(session)
// No turn opened over it, so only the cancellation says the work was cut short.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents())).toEqual({
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
end: session.snapshotEvents().find(event => event.type === 'turn/end'),
droppedUnrun: true,
})
@@ -153,7 +143,6 @@ describe('foldConsumedWork', () => {
target: 'next-turn', start: 0, removedCount: 1, inserted: [message('rewritten')], outcome: 'canceled',
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents()).droppedUnrun).toBe(false)
})
@@ -163,9 +152,7 @@ describe('foldConsumedWork', () => {
cancelPending(session)
steppedTurn(session, 2, { kind: 'completed' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldConsumedWork(session.snapshotEvents())).toEqual({
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
end: session.snapshotEvents().findLast(event => event.type === 'turn/end'),
droppedUnrun: false,
})
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/core/session/README.md
README.md: ebe4c1c29992b29b07ad38d7368ca5cef2253ee0
README.zh.md: f5d0ac59f1276e4fe59c1cc449dcf6ce5a082aba
README.md: e61481d1f5b62e24499b0db676a9ae62cce8f0c0
README.zh.md: 9350a98c57261a4fc78487578717707a9393b502
+1 -1
View File
@@ -55,7 +55,7 @@ Append, seed/restore, and event adoption/snapshot reject any `header.system` and
### Read the log
`session.seq` reads the current log length without materializing an array, and `session.eventAt(seq)` reads one accepted, deeply frozen event by sequence number. `session.snapshotEvents(fromSeq?, toSeqExclusive?)` materializes a frozen, stable snapshot of a half-open range; a complete current snapshot is cached until the next append. `eventAt()`, `snapshotEvents()`, and `ownEvents()` are deprecated: existing logic may remain unmigrated for now, but new calls are prohibited ([rationale](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md)). Callers that only need a length use `seq`.
`session.seq` reads the current log length without materializing an array, and `session.eventAt(seq)` reads one accepted, deeply frozen event by sequence number. `session.snapshotEvents(fromSeq?, toSeqExclusive?)` materializes a frozen, stable snapshot of a half-open range; a complete current snapshot is cached until the next append. `eventAt()`, `snapshotEvents()`, and `ownEvents()` are deprecated: existing logic may remain unmigrated for now, but new production calls are prohibited. Repository test files may use these three readers under their scoped lint allowance ([policy](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md)). Callers that only need a length use `seq`.
Session log positions use two numeric types. `SessionSeq` identifies an existing event or inclusive event watermark; `SessionLogOffset` identifies a gap, prefix length, or read boundary and may equal the event count. `SessionSeqCursor` adds the `-1` “no event yet” value, while `OptionalSessionSeq` uses `null` when absence is data. The constructors validate non-negative safe integers, and the brands disappear at runtime, so durable JSON and wire values remain ordinary numbers.
+1 -1
View File
@@ -55,7 +55,7 @@ session.deriveMessages() // the derived model history
### 读取日志
`session.seq` 无需物化数组即可读取当前日志长度,`session.eventAt(seq)` 按序列号读取单个已接受且深度冻结的事件。`session.snapshotEvents(fromSeq?, toSeqExclusive?)` 会物化半开区间的冻结稳定快照;当前完整快照会缓存到下一次追加。`eventAt()``snapshotEvents()``ownEvents()` 已弃用:现有逻辑可以暂不迁移,但禁止新增调用[理由](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.zh.md))。只需要长度的调用方使用 `seq`
`session.seq` 无需物化数组即可读取当前日志长度,`session.eventAt(seq)` 按序列号读取单个已接受且深度冻结的事件。`session.snapshotEvents(fromSeq?, toSeqExclusive?)` 会物化半开区间的冻结稳定快照;当前完整快照会缓存到下一次追加。`eventAt()``snapshotEvents()``ownEvents()` 已弃用:现有逻辑可以暂不迁移,但禁止新增生产调用。仓库测试文件可以在限定范围的 lint 豁免下使用这三个读取方法[策略](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.zh.md))。只需要长度的调用方使用 `seq`
会话日志位置使用两种数字类型。`SessionSeq` 标识已有事件或包含端点的事件水位;`SessionLogOffset` 标识间隙、前缀长度或读取边界,并且可以等于事件数量。`SessionSeqCursor` 添加 `-1` 这个“尚无事件”值,`OptionalSessionSeq` 则在缺失本身属于数据时使用 `null`。构造函数会校验非负安全整数,品牌在运行时会被擦除,因此持久 JSON 与 wire 值仍是普通数字。
@@ -121,7 +121,6 @@ describe('canonical event payload acceptance', () => {
expect(copy).toEqual(event)
if (path === 'adopt' || path === 'snapshot') expect(accept(copy)).toEqual(event)
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(id, [event]).eventAt(SessionSeq(0))).toEqual(event)
}
})
@@ -179,7 +178,6 @@ describe('canonical event payload acceptance', () => {
const prepared = ctx.sessions.prepare(id, {
seed: [event], meta: { ...header }, inheritedEventCount: SessionLogOffset(0), eventState,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(prepared.eventAt(SessionSeq(0))).toBe(event)
expect(prepared.requestHeader()).toEqual({ config })
expect(ctx.sessions.get(id)).toBeUndefined()
@@ -205,7 +203,6 @@ describe('canonical event payload acceptance', () => {
const published = vi.fn()
ctx.on('session/created', created)
ctx.on('session/event', published)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = session.snapshotEvents()
const messages = session.deriveMessages()
for (const { event } of invalidData) {
@@ -213,7 +210,6 @@ describe('canonical event payload acceptance', () => {
expect(() => ctx.sessions.create(SessionId('invalid-seed'), { seed: [event] })).toThrow()
expect(ctx.sessions.get(SessionId('invalid-seed'))).toBeUndefined()
expect(session.seq).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toBe(events)
expect(session.surface.nodes).toEqual([])
expect(session.surface.replaceGeneration).toBe(0)
@@ -283,7 +279,6 @@ describe('canonical event-local surface metadata', () => {
expect(() => accept(structuredClone(event))).not.toThrow()
}
const session = Session.create(id, [event])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.eventAt(SessionSeq(0))).toEqual(event)
expect(session.surface.nodes).toEqual([])
expect(session.deriveMessages()).toEqual([])
@@ -16,7 +16,6 @@ function userText(session: Session, text: string): void {
/** From-scratch oracle: replay the log into a fresh session and derive. */
function scratch(session: Session): unknown {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return Session.create(SessionId(`${session.id}-scratch-${session.seq}`), session.snapshotEvents()).deriveMessages()
}
-13
View File
@@ -47,7 +47,6 @@ function firstUserMessage(events: readonly SessionEvent[]): SessionEvent<'user/m
}
function lastSeq(session: Session): SessionSeq {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = session.snapshotEvents().at(-1)
if (event === undefined) throw new Error('missing last event')
return event.seq
@@ -55,7 +54,6 @@ function lastSeq(session: Session): SessionSeq {
/** A seeded child's fork-inherited prefix. */
function inherited(session: Session): readonly SessionEvent[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return session.snapshotEvents(SessionLogOffset(0), session.inheritedEventCount)
}
@@ -83,19 +81,13 @@ describe('SessionStore.fork', () => {
const child = sessions.fork(SessionId('parent'), undefined, SessionId('child'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(inherited(child)).toEqual(source.snapshotEvents())
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.snapshotEvents()).not.toBe(source.snapshotEvents())
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.snapshotEvents()[1]).not.toBe(source.snapshotEvents()[1])
expect(() => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
firstUserMessage(child.snapshotEvents()).data.content[0] = { type: 'text', text: 'child mutation' }
}).toThrow(TypeError)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(firstUserMessage(source.snapshotEvents()).data.content).toEqual([{ type: 'text', text: 'hello' }])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(firstUserMessage(child.snapshotEvents()).data.content).toEqual([{ type: 'text', text: 'hello' }])
expect(child.header).toMatchObject({
id: SessionId('child'),
@@ -114,7 +106,6 @@ describe('SessionStore.fork', () => {
const child = sessions.fork(source, undefined, SessionId('log-only-child'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(inherited(child)).toEqual(source.snapshotEvents())
expect(inherited(child).at(-1)).toMatchObject({
type: 'test/log-only',
@@ -132,7 +123,6 @@ describe('SessionStore.fork', () => {
const child = sessions.fork(source, firstBoundary, SessionId('child-from-first'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(inherited(child)).toEqual(source.snapshotEvents().slice(0, firstBoundary + 1))
expect(child.inheritedEventCount).toBe(firstBoundary + 1)
expect(child.deriveMessages()).toEqual([{
@@ -176,12 +166,9 @@ describe('SessionStore.fork', () => {
const child = sessions.fork(parent, undefined, SessionId('bracket-child'))
// Parent: no end-seed event follows the bracket, so its owner treats it as live.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(parent.snapshotEvents().at(-1)).toBe(open)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(parent.snapshotEvents().some(event => event.type === 'session/end-seed')).toBe(false)
// Child: the same bracket is before end-seed, so it belongs to the seed.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const boundary = child.snapshotEvents().at(-1)
expect(boundary).toMatchObject({ type: 'session/end-seed' })
expect(boundary!.seq).toBeGreaterThan(open.seq)
@@ -83,7 +83,6 @@ describe('session-log invariants', () => {
expect(() => session.append('turn/start', {
turn: 1,
})).toThrow('later dispatch veto')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
expect(() => {
session.append('turn/start', { turn: 1 })
@@ -429,7 +428,6 @@ describe('session-log invariants', () => {
const open = ctx.sessions.create(SessionId('inherited-inside-open-turn'), { seed: [
{ type: 'turn/start', seq: SessionSeq(0), time: 1, data: { turn: 1 } },
] })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(open.snapshotEvents().map(event => event.type)).toEqual(['turn/start', 'session/end-seed'])
// Still open afterwards: the boundary moves no cursor.
expect(() => open.append('turn/start', { turn: 2 }))
@@ -107,7 +107,6 @@ describe('Session properties', () => {
it('seq is strictly monotonic and zero-based contiguous', () => {
fc.assert(fc.property(logArb, (events) => {
const session = build(events)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
session.snapshotEvents().forEach((event, i) => { expect(event.seq).toBe(i) })
expect(session.seq).toBe(events.length)
}))
@@ -116,11 +115,9 @@ describe('Session properties', () => {
it('replay-from-seed reproduces the derivation identically', () => {
fc.assert(fc.property(logArb, (events) => {
const original = build(events)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = Session.create(SessionId(`replay-${counter++}`), original.snapshotEvents())
expect(replayed.deriveMessages()).toEqual(original.deriveMessages())
// Every explicit replay grows by exactly one log-only boundary.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().slice(0, original.seq)).toEqual(original.snapshotEvents())
expect(replayed.seq).toBe(original.seq + 1)
}))
@@ -129,12 +126,9 @@ describe('Session properties', () => {
it('replaying a log that already ends in end-seed adds no further marker', () => {
fc.assert(fc.property(logArb, (events) => {
const original = build(events)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const once = Session.create(SessionId(`idem-a-${counter++}`), original.snapshotEvents())
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const twice = Session.create(SessionId(`idem-b-${counter++}`), once.snapshotEvents())
// Lazy resume makes browsing a pickup, so this must not grow per open.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(twice.snapshotEvents()).toEqual(once.snapshotEvents())
}))
})
@@ -168,7 +162,6 @@ describe('Session properties', () => {
fc.assert(fc.property(logArb, (events) => {
const session = build(events)
const messages = session.deriveMessages()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const before = structuredClone(session.snapshotEvents())
for (const m of messages) {
expect(['user', 'assistant', 'system']).toContain(m.role)
@@ -177,7 +170,6 @@ describe('Session properties', () => {
expect(Object.isFrozen(m)).toBe(true)
expect(() => { m.content.push({ type: 'text', text: 'mutation' }) }).toThrow(TypeError)
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual(before)
}))
})
@@ -80,7 +80,6 @@ describe('foldRequestHeader', () => {
content: [{ type: 'text', text: 'hi' }], source: { kind: 'user' },
}), { surfaceOp: 'append' })
session.append('request/header', { header: { config: { provider: 'mock', model: 'other' } }, reason: 'change' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldRequestHeader(session.snapshotEvents())).toEqual({ config: { provider: 'mock', model: 'other' } })
})
})
@@ -69,13 +69,11 @@ describe('Session log positions', () => {
isSeeded: true,
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const child = Session.create(id, source.snapshotEvents(), header, source.seq)
expect(child.header.isSeeded).toBe(true)
expect('seedLength' in child.header).toBe(false)
expect(child.inheritedEventCount).toBe(2)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.ownEvents().map(event => event.type)).toEqual(['session/end-seed'])
expect(child.isOwnSeq(SessionSeq(1))).toBe(false)
expect(child.isOwnSeq(SessionSeq(2))).toBe(true)
@@ -92,7 +90,6 @@ describe('Session log positions', () => {
parent.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
const id = SessionId('suffix-child')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const child = Session.create(id, parent.snapshotEvents(), {
version: SESSION_FORMAT_VERSION,
id,
@@ -101,7 +98,6 @@ describe('Session log positions', () => {
}, parent.seq)
child.append('request/context', { provider: 'provider', model: 'model' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(child.ownEvents().map(event => event.type)).toEqual([
'session/end-seed',
'request/context',
@@ -71,7 +71,6 @@ describe('Session', () => {
session.append('turn/start', { turn: 1 })
session.append('turn/end', { turn: 1, reason: { kind: 'max-tokens' } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = session.snapshotEvents().findLast(e => e.type === 'turn/end')!
expect(turnEnd.data.reason).toEqual({ kind: 'max-tokens' })
// survives a structuredClone (the persistence-serialization boundary)
@@ -82,11 +81,8 @@ describe('Session', () => {
const session = Session.create(SessionId('aborted'))
session.append('turn/start', { turn: 1 })
session.append('turn/end', { turn: 1, reason: { kind: 'aborted', reason: { kind: 'user' } } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = Session.create(SessionId('aborted-replay'), structuredClone(session.snapshotEvents()))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().slice(0, -1)).toEqual(session.snapshotEvents())
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnEnd = replayed.snapshotEvents().findLast(event => event.type === 'turn/end')
expect(turnEnd?.type === 'turn/end' && turnEnd.data.reason)
.toEqual({ kind: 'aborted', reason: { kind: 'user' } })
@@ -119,7 +115,6 @@ describe('Session', () => {
session.append('user/message', message, { surfaceOp: 'append' })
expect(session.deriveMessages()).toEqual([message])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = session.snapshotEvents()[0]
expect(event?.type === 'user/message' && event.data.source).toEqual({ kind: 'plugin', plugin: 'agent-instructions' })
})
@@ -144,11 +139,9 @@ describe('Session', () => {
}, { surfaceOp: 'append' })
original.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = Session.create(SessionId('s3-replay'), original.snapshotEvents())
expect(replayed.deriveMessages()).toEqual(original.deriveMessages())
// The seed verbatim, plus the end-seed event the constructor appends.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(replayed.snapshotEvents().slice(0, original.seq)).toEqual(original.snapshotEvents())
expect(replayed.seq).toBe(original.seq + 1)
expect(replayed.firstLiveSeq).toBe(original.seq)
@@ -156,20 +149,16 @@ describe('Session', () => {
it('marks an explicitly empty seed without marking a fresh session', () => {
const fresh = Session.create(SessionId('fresh-empty'))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(fresh.snapshotEvents()).toEqual([])
const resumed = Session.create(SessionId('resumed-empty'), [])
expect(resumed.firstLiveSeq).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(resumed.snapshotEvents()).toMatchObject([
{ type: 'session/end-seed', seq: 0, data: {} },
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const reopened = Session.create(SessionId('reopened-empty'), resumed.snapshotEvents())
expect(reopened.firstLiveSeq).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(reopened.snapshotEvents()).toEqual(resumed.snapshotEvents())
})
@@ -199,7 +188,6 @@ describe('Session', () => {
const unrelatedPrimitiveData = {
type: 'plugin/event', seq: 0, time: 1, data: null,
} as unknown as SessionEvent
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(SessionId('primitive-plugin-data'), [unrelatedPrimitiveData]).snapshotEvents().slice(0, 1))
.toEqual([unrelatedPrimitiveData])
})
@@ -262,7 +250,6 @@ describe('Session', () => {
SessionLogOffset(0),
'detached',
)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(restored.eventAt(SessionSeq(0))).toBe(mismatchedMessage)
expect(Object.isFrozen(mismatchedMessage)).toBe(false)
})
@@ -532,7 +519,6 @@ describe('Session', () => {
reason: 'initial',
},
} as const
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(SessionId('reasoning-effort'), [valid]).snapshotEvents()[0])
.toEqual(valid)
@@ -563,7 +549,6 @@ describe('Session', () => {
reason: 'initial',
},
} as const
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(Session.create(SessionId('adapter-defaults'), [valid]).snapshotEvents()[0]).toEqual(valid)
for (const adapterDefaults of [
@@ -594,7 +579,6 @@ describe('Session', () => {
isError: false,
}),
}, { surfaceOp: 'append' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const before = structuredClone(session.snapshotEvents())
// A misbehaving consumer tries to mutate the messages it was handed.
@@ -611,7 +595,6 @@ describe('Session', () => {
messages.reverse()
// The log is unchanged: deep-equal to the snapshot taken before mutation.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual(before)
// And a fresh derivation still reflects the original content and order.
expect(session.deriveMessages()[0]!.content).toEqual([{ type: 'text', text: 'original' }])
@@ -641,7 +624,6 @@ describe('Session', () => {
cyclic['self'] = cyclic
expect(bad(cyclic)).toThrow(/non-JSON-serializable/)
// The rejected appends never entered the log.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(0)
})
@@ -656,14 +638,12 @@ describe('Session', () => {
})))
.toThrow(/surface-eligible and requires a surfaceOp marker/)
// The rejected append never entered the log (only turn/start is present).
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(1)
})
it('accepts dense arrays and nested plain objects', () => {
const session = Session.create(SessionId('s6'))
expect(() => session.append('user/message', { content: [{ type: 'text', text: 'x' }], source: { kind: 'user' }, extra: [1, 2, [3, { a: null, b: true }]] } as never, { surfaceOp: 'append' })).not.toThrow()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(1)
})
@@ -708,7 +688,6 @@ describe('Session', () => {
{ type: 'turn/end' as const, seq: 2, time: 3, data: { turn: 1, reason: { kind: 'completed' as const } } },
] as SessionEvent[]
const session = Session.create(SessionId('seed-ok'), goodSeed)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().slice(0, 3)).toEqual(goodSeed)
expect(session.firstLiveSeq).toBe(3)
})
@@ -734,7 +713,6 @@ describe('Session', () => {
const session = Session.create(SessionId('seed-entry-snapshot'), seed)
expect(reads).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().slice(0, 1)).toEqual([accepted])
})
@@ -752,7 +730,6 @@ describe('Session', () => {
const session = Session.create(SessionId('seed-nested-drift'), seed)
expect(reads).toBe(1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()[0]!.data).toEqual({ value: 'accepted' })
})
@@ -814,7 +791,6 @@ describe('Session', () => {
const session = Session.create(SessionId('seed-null-prototype'), [event])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().slice(0, 1)).toEqual([{ ...event }])
})
@@ -847,7 +823,6 @@ describe('Session', () => {
}] as unknown as SessionEvent[]
const session = Session.create(SessionId('seed-unstable-metadata'), seed)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const event = session.snapshotEvents()[1]!
if (event.type !== 'user/message') throw new Error('test fixture must remain a user/message')
@@ -908,7 +883,6 @@ describe('Session', () => {
const um = seed[1]!
;(um.data as { content: { type: 'text'; text: string }[] }).content[0]!.text = 'HACKED'
;(um.data as Record<string, unknown>)['injected'] = 1n // would have failed validation
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const logged = session.snapshotEvents()[1]!
expect(logged.type === 'user/message' && (logged.data.content[0] as { text: string }).text).toBe('original')
expect((logged.data as Record<string, unknown>)['injected']).toBeUndefined()
@@ -927,7 +901,6 @@ describe('Session', () => {
// make session.snapshotEvents() diverge from the value that passed validation.
data.content[0]!.text = 'HACKED'
;(data as Record<string, unknown>)['injected'] = 1n
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const logged = session.snapshotEvents()[0]!
expect(logged.type === 'user/message' && (logged.data.content[0] as { text: string }).text).toBe('original')
expect((logged.data as Record<string, unknown>)['injected']).toBeUndefined()
@@ -950,7 +923,6 @@ describe('Session', () => {
expect(reads).toBe(1)
expect(event.data).toEqual({ value: 'accepted' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([event])
})
@@ -964,7 +936,6 @@ describe('Session', () => {
}),
{ surfaceOp: { op: 'replace', startSeq: 1n, endSeq: 2 } } as never,
)).toThrow(/non-JSON-serializable surface metadata/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
})
@@ -983,7 +954,6 @@ describe('Session', () => {
}),
{ surfaceOp: new ReplaceOp() },
)).toThrow(/non-JSON-serializable surface metadata/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
})
@@ -1015,7 +985,6 @@ describe('Session', () => {
expect(reads).toBe(1)
expect(event.surfaceOp).toEqual({ op: 'replace', startSeq: 0, endSeq: 0 })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([source, event])
})
@@ -1037,7 +1006,6 @@ describe('Session', () => {
surfaceOp: 'append',
sourceEventSeqs: [0, -1],
})).toThrow(/non-negative safe integers/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
})
@@ -1061,7 +1029,6 @@ describe('Session', () => {
data: { turn: 1 },
surfaceOp: 'append',
} as unknown as SessionEvent])).toThrow(/invalid seed event.*not surface-eligible/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
})
@@ -1072,7 +1039,6 @@ describe('Session', () => {
time: 1,
data: { turn: 1 },
}])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const seededEvent = seeded.snapshotEvents()[0]!
if (seededEvent.type !== 'turn/start') throw new Error('test fixture must remain a turn/start')
expect(Object.isFrozen(seededEvent)).toBe(true)
@@ -1093,24 +1059,20 @@ describe('Session', () => {
it('returns cached frozen event-array snapshots that do not grow after append', () => {
const session = Session.create(SessionId('events-snapshot'))
session.append('turn/start', { turn: 1 })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const before = session.snapshotEvents()
const beforeEvent = before[0]!
if (beforeEvent.type !== 'turn/start') throw new Error('test fixture must remain a turn/start')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toBe(before)
expect(Object.isFrozen(before)).toBe(true)
expect(() => { (before as SessionEvent[]).push(beforeEvent) }).toThrow(TypeError)
expect(() => { beforeEvent.data.turn = 99 }).toThrow(TypeError)
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const after = session.snapshotEvents()
expect(before).toHaveLength(1)
expect(after).toHaveLength(2)
expect(after).not.toBe(before)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toBe(after)
})
@@ -1119,14 +1081,10 @@ describe('Session', () => {
const start = session.append('turn/start', { turn: 1 })
const end = session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.eventAt(SessionSeq(0))).toBe(start)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.eventAt(SessionSeq(1))).toBe(end)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.eventAt(SessionSeq(2))).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const range = session.snapshotEvents(SessionLogOffset(1), SessionLogOffset(2))
expect(range).toEqual([end])
expect(Object.isFrozen(range)).toBe(true)
@@ -1272,7 +1230,6 @@ describe('Session', () => {
const marked = Session.create(SessionId('ignorable-envelope'), [
{ ...base, ignorable: true } as SessionEvent,
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(marked.snapshotEvents()[0]?.ignorable).toBe(true)
})
})
@@ -1317,7 +1274,6 @@ describe('SessionStore', () => {
a.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'q' }], source: { kind: 'user' },
}), { surfaceOp: 'append' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const forked = ctx.sessions.create(SessionId('fork'), { seed: a.snapshotEvents() })
expect(forked.deriveMessages()).toEqual(a.deriveMessages())
})
@@ -1581,7 +1537,6 @@ describe('SessionStore', () => {
const heard: SessionEvent[] = []
let committedBeforeNotify = false
ctx.on('session/event', (observedSession, event) => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
committedBeforeNotify = observedSession.snapshotEvents().at(-1) === event
throw new Error('sync event observer')
})
@@ -1595,7 +1550,6 @@ describe('SessionStore', () => {
})
}).not.toThrow()
expect(committedBeforeNotify).toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([appended])
expect(heard).toEqual([appended])
await Promise.resolve()
@@ -1619,7 +1573,6 @@ describe('SessionStore', () => {
const [observedSession, event] = args as [Session, SessionEvent]
validations.push({
event,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
logLength: observedSession.snapshotEvents().length,
frozen: Object.isFrozen(event) && Object.isFrozen(event.data),
})
@@ -1633,7 +1586,6 @@ describe('SessionStore', () => {
expect(() => session.append('turn/start', {
turn: 1,
})).toThrow('reject first candidate')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
expect(observed).toEqual([])
@@ -1646,7 +1598,6 @@ describe('SessionStore', () => {
])
expect(validations.map(({ event }) => event.seq)).toEqual([0, 0])
expect(validations[1]!.event).toBe(appended)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([appended])
expect(observed).toEqual([appended])
})
@@ -1678,7 +1629,6 @@ describe('SessionStore', () => {
sourceEventSeqs: [SessionSeq(2)],
})).toThrow('reject surface candidate')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(3)
expect(surface.nodes).toEqual([2])
expect(surface.replaceGeneration).toBe(0)
@@ -1704,7 +1654,6 @@ describe('SessionStore', () => {
expect(() => session.append('turn/start', {
turn: 1,
})).toThrow('dispatch instrumentation rejected the carrier')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
expect(observed).toEqual([])
})
@@ -1724,7 +1673,6 @@ describe('SessionStore', () => {
const appended = session.append('turn/start', {
turn: 1,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([appended])
expect(heard).toEqual([appended])
expect(warnings).toEqual([
@@ -1756,7 +1704,6 @@ describe('SessionStore', () => {
turn: 1,
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([appended])
expect(order).toEqual(['resolve:live', 'observe:live', 'dispose:detached'])
expect(ctx.sessions.get(session.id)).toBeUndefined()
@@ -328,7 +328,6 @@ describe('SurfaceManager', () => {
sourceEventSeqs: sourceSeqs(2, 1),
})
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const folded = foldSurface(s.snapshotEvents())
expect(folded.nodes).toEqual(s.surface.nodes)
expect(folded.replacements).toEqual([
@@ -338,9 +337,7 @@ describe('SurfaceManager', () => {
folded.nodes[0] = SessionSeq(99)
folded.replacements[0]!.shadowedSeqs.push(SessionSeq(99))
expect(s.surface.nodes).toEqual([3])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldSurface(s.snapshotEvents()).nodes).toEqual([3])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldSurface(s.snapshotEvents()).replacements[0]!.shadowedSeqs).toEqual([0])
})
@@ -357,7 +354,6 @@ describe('SurfaceManager', () => {
expect(s.surface.nodes).toEqual([1])
const manager = s.surface as unknown as { _state: object }
expect(Object.hasOwn(manager._state, 'replacements')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldSurface(s.snapshotEvents()).replacements).toEqual([
{ seq: 1, start: 0, end: 0, shadowedSeqs: [0] },
])
@@ -392,7 +388,6 @@ describe('SurfaceManager', () => {
const surface = s.surface
const nodes = surface.nodes
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(nodes).toEqual(foldSurface(s.snapshotEvents()).nodes)
expect(surface.replaceGeneration).toBe(0)
@@ -413,12 +408,10 @@ describe('SurfaceManager', () => {
{ surfaceOp: surfaceOp({ op: 'replace', startSeq: 0, endSeq: 0 }) },
)).toThrow(/missing 0/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(s.snapshotEvents()).toHaveLength(1)
expect(s.surface).toBe(surface)
expect(surface.nodes).toEqual([0])
expect(surface.replaceGeneration).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(surface.nodes).toEqual(foldSurface(s.snapshotEvents()).nodes)
s.append('user/message', createUserMessage({
@@ -427,7 +420,6 @@ describe('SurfaceManager', () => {
expect(surface.nodes).toBe(nodes)
expect(surface.nodes).toEqual([0, 1])
expect(surface.replaceGeneration).toBe(0)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(surface.nodes).toEqual(foldSurface(s.snapshotEvents()).nodes)
})
@@ -501,7 +493,6 @@ describe('SurfaceManager', () => {
isError: false,
}),
}, { surfaceOp: 'append' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replayed = Session.create(SessionId('replay'), original.snapshotEvents())
expect(replayed.surface.nodes).toEqual([1, 2, 4])
expect(replayed.deriveMessages()).toEqual(original.deriveMessages())
@@ -603,7 +594,6 @@ describe('SurfaceManager', () => {
// Mutate caller's array after append.
sources.push(SessionSeq(1))
sources[0] = SessionSeq(99)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const logged = s.snapshotEvents()[1]! as SurfaceEvent
expect(logged.sourceEventSeqs).toEqual([0])
})
@@ -639,7 +629,6 @@ describe('SurfaceManager', () => {
})
// Mutate caller's object after append.
op.startSeq = SessionSeq(99)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const logged = s.snapshotEvents()[1]! as SurfaceEvent
expect(logged.surfaceOp).toEqual({ op: 'replace', startSeq: 0, endSeq: 0 })
})
@@ -730,9 +719,7 @@ describe('Session.append surface opts', () => {
expect(event.sourceEventSeqs).toEqual([0, 1])
expect(event.surfaceOp).toBe('append')
// The logged event matches the returned event.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect((s.snapshotEvents()[2]! as SurfaceEvent).sourceEventSeqs).toEqual([0, 1])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect((s.snapshotEvents()[2]! as SurfaceEvent).surfaceOp).toBe('append')
})
@@ -766,9 +753,7 @@ describe('Session.append surface opts', () => {
it('a non-surface event carries no surface fields', () => {
const s = Session.create(SessionId('noopts'))
s.append('turn/start', { turn: 1 })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect((s.snapshotEvents()[0] as SessionEvent<SurfaceEventType>).sourceEventSeqs).toBeUndefined()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect((s.snapshotEvents()[0] as SessionEvent<SurfaceEventType>).surfaceOp).toBeUndefined()
})
@@ -821,14 +806,12 @@ describe('surface type guards', () => {
it('isSurfaceEvent narrows a fully-formed surface event', () => {
const s = surfaceSession()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const userMessage = s.snapshotEvents().find(e => e.type === 'user/message')!
expect(isSurfaceEvent(userMessage)).toBe(true)
})
it('isSurfaceEvent rejects a non-surface-eligible type', () => {
const s = surfaceSession()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnStart = s.snapshotEvents().find(e => e.type === 'turn/start')!
expect(isSurfaceEvent(turnStart)).toBe(false)
})
@@ -852,9 +835,7 @@ describe('surface type guards', () => {
s.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'checkpoint' }], source: { kind: 'plugin', plugin: 'compact' },
}), { surfaceOp: surfaceOp({ op: 'replace', startSeq: 1, endSeq: 2 }), sourceEventSeqs: sourceSeqs(1, 2) })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const appended = s.snapshotEvents().find(e => e.type === 'user/message')!
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const replacement = s.snapshotEvents().at(-1)!
expect(isAppendSurfaceEvent(appended)).toBe(true)
@@ -865,7 +846,6 @@ describe('surface type guards', () => {
it('rejects log-only and markerless events from both marker guards', () => {
const s = surfaceSession()
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const turnStart = s.snapshotEvents().find(e => e.type === 'turn/start')!
// A surface-eligible type whose mandatory marker is absent has no origin at
// all: it never entered the surface.
@@ -152,7 +152,6 @@ describe('tool-pipeline invariants', () => {
name: 'echo',
arguments: {},
})).toThrow(/parentCallId child does not belong to rootCallId another-root/)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents().some(event => event.type === 'tool/ptc-dispatch-start'
&& String(event.data.subCallId) === 'invalid-grandchild')).toBe(false)
})
-1
View File
@@ -1484,7 +1484,6 @@ describe('the run_code dispatch bridge', () => {
expect(result.isError).toBe(false)
expect(result.isError ? undefined : result.value).toEqual({ logs: [], result: depth })
expect({ observedDepth, observedLeaf }).toEqual({ observedDepth: depth, observedLeaf: 'leaf' })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const dispatch = session.snapshotEvents().find(event => event.type === 'tool/ptc-dispatch')
if (dispatch === undefined) throw new Error('expected a durable tool/ptc-dispatch event')
const logged = dispatch.data.arguments as { nested: JsonValue }
@@ -44,7 +44,6 @@ describe('Agent Teams stream invariant', () => {
code: 'INVARIANT',
packageName: '@deepseek-ai/dsh-experimental-agent-team',
}))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(invalid.snapshotEvents()).toEqual([])
})
@@ -70,7 +69,6 @@ describe('Agent Teams stream invariant', () => {
code: 'INVARIANT',
packageName: '@deepseek-ai/dsh-experimental-agent-team',
}))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toEqual([])
})
})
@@ -31,7 +31,6 @@ function durable(agent: Agent): {
pendingMessages: TeamMessageSnapshot[]
} {
let projected = teamProjectionDefinition.init(agent.session.header)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of agent.session.snapshotEvents()) projected = teamProjectionDefinition.apply(projected, event)
if (projected.failure !== undefined) throw new Error(projected.failure)
const state = projected
@@ -159,7 +158,6 @@ async function persistedChild(
// Live sessions persist only through an attached agent-loop writer; this
// bare fixture session seeds its durable log directly for the cold restart.
const handle = await ctx.sessionPersistence.create(child.header)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
await handle.append(child.snapshotEvents())
await handle.close()
return child
@@ -395,7 +393,6 @@ for (const backend of backends) {
const checkpointEntered = Promise.withResolvers<undefined>()
const releaseCheckpoint = Promise.withResolvers<undefined>()
const delayedCheckpoint = vi.spyOn(second.ctx.sessions, 'flush').mockImplementation(async (session) => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
if (session.id === rootId && session.snapshotEvents().some(event =>
event.type === 'team/message/delivered' && event.data.messageId === messageId)) {
checkpointEntered.resolve(undefined)
@@ -35,7 +35,6 @@ function durable(agent: Agent): {
pendingMessages: TeamMessageSnapshot[]
} {
let projected = teamProjectionDefinition.init(agent.session.header)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of agent.session.snapshotEvents()) projected = teamProjectionDefinition.apply(projected, event)
if (projected.failure !== undefined) throw new Error(projected.failure)
const state = projected
@@ -271,7 +270,6 @@ describe('Team identity and provisioning', () => {
// Live sessions persist only through an attached agent-loop writer; this
// bare fixture session seeds its durable log directly for the cold reread.
const persisted = await ctx.sessionPersistence.create(liveSession.header)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
await persisted.append(liveSession.snapshotEvents())
await persisted.close()
await liveFiber.dispose()
@@ -471,7 +469,6 @@ describe('Team identity and provisioning', () => {
await ctx.agentTeams.createTask(lead, { subject: 'parent task', description: 'belongs to parent' })
const handle = await ctx.agents.create({
sessionId: SessionId('ordinary-fork'),
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
seed: lead.session.snapshotEvents(),
meta: { parentSession: lead.id, isSeeded: true },
inheritedEventCount: SessionLogOffset(lead.session.seq),
@@ -954,7 +951,6 @@ describe('Team mailbox and waiting', () => {
})
await expect(teamInternals(ctx).mailbox.tryDispatch(lead, message, SIGNAL)).resolves.toBe(true)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(lead.session.snapshotEvents().some(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.some(input => input.source.kind === 'team-message'
&& input.source.messageId === message.id))).toBe(true)
@@ -999,14 +995,12 @@ describe('Team mailbox and waiting', () => {
'team/message/delivered',
])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const receiptCount = lead.session.snapshotEvents().filter(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.some(message => message.source.kind === 'team-message'
&& messageIds.has(message.source.messageId))).length
await teamFiber.dispose()
await ctx.plugin(TeamService, { maxPendingMessagesPerMember: 1 })
await vi.waitFor(() => { expect(durable(lead).pendingMessages).toEqual([]) })
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(lead.session.snapshotEvents().filter(event => event.type === 'agent/inbox/spliced'
&& event.data.inserted.some(message => message.source.kind === 'team-message'
&& messageIds.has(message.source.messageId)))).toHaveLength(receiptCount)
@@ -1208,7 +1202,6 @@ describe('Team mailbox and waiting', () => {
expect(later.status).toBe('accepted')
const target = await waitRunning(ctx, started.member.id)
await vi.waitFor(() => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const accepted = target.session.snapshotEvents().flatMap(event => event.type === 'agent/inbox/spliced'
? event.data.inserted.flatMap(message => message.source.kind === 'team-message'
? [message.source.messageId]
@@ -33,7 +33,6 @@ export class TestSessionQuery extends SessionQueryEngine {
options: SessionObservationOptions = {},
): Promise<SessionObservation> {
const live = this.ctx.sessions.get(sessionId)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
if (live !== undefined) return cut('live', live.header, live.snapshotEvents())
const handle = await this.ctx.sessionPersistence.open(
sessionId,
@@ -148,7 +148,6 @@ describe('dsh-tool-team', () => {
expect(childAssembly.tools.map(schema => schema.name).filter(name => TOOL_NAMES.includes(name)).sort())
.toEqual(TOOL_NAMES)
expect(renderPrompt(childAssembly)).toContain('Your Team role is teammate; your Team name is tool-worker')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const initialPrompt = child.session.snapshotEvents().find(event => event.type === 'user/message'
&& event.data.source.kind === 'user')
expect(initialPrompt?.type === 'user/message'
@@ -73,7 +73,6 @@ async function run(test: Harness, suffix = ''): Promise<{ kind: string; text?: s
/** Authoritative feedback payloads in log order. */
function feedbackTexts(session: Session): string[] {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
return session.snapshotEvents()
.filter(event => event.type === 'feedback/record')
.map(event => event.data.text)
@@ -108,17 +107,14 @@ describe('/feedback human command', () => {
text: `Feedback recorded for session ${test.session.id}\nAnonymous user: ${USER_ID}.`,
})
expect(feedbackTexts(test.session)).toEqual(['the diff view is unreadable'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const commandRun = test.session.snapshotEvents().find(event => event.type === 'command/run')
expect(commandRun?.type === 'command/run' && Object.hasOwn(commandRun.data, 'args')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(JSON.stringify(test.session.snapshotEvents()).match(/the diff view is unreadable/gu)).toHaveLength(1)
})
it('exports a command-independent feedback producer', async () => {
const test = await harness()
commandFeedback.recordFeedback(test.session, ' recorded outside a command ')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(test.session.snapshotEvents().map(event => event.type)).toEqual(['feedback/record'])
expect(feedbackTexts(test.session)).toEqual(['recorded outside a command'])
expect(() => { commandFeedback.recordFeedback(test.session, ' \n\t ') })
@@ -129,7 +125,6 @@ describe('/feedback human command', () => {
it('keeps command bookkeeping around the authoritative feedback event', async () => {
const test = await harness()
await run(test, ' nothing else happens')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(test.session.snapshotEvents().map(event => event.type)).toEqual([
'command/run', 'feedback/record', 'command/done',
])
@@ -166,12 +161,10 @@ describe('/feedback human command', () => {
it('keeps every recorded event out of model context and derived history', async () => {
const test = await harness()
await run(test, ' invisible to the model')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of test.session.snapshotEvents()) {
expect('surfaceOp' in event).toBe(false)
expect(test.session.deriveEventMessage(event)).toBeNull()
}
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(foldSurface(test.session.snapshotEvents()).nodes).toEqual([])
expect(test.session.surface.nodes).toEqual([])
expect(test.session.deriveMessages()).toEqual([])
@@ -187,10 +180,8 @@ describe('/feedback human command', () => {
await expect(run(test, ' \n\t ')).resolves.toEqual(expected)
expect(getOrCreateAnonymousUserId).not.toHaveBeenCalled()
expect(feedbackTexts(test.session)).toEqual([])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const done = test.session.snapshotEvents().filter(event => event.type === 'command/done')
expect(done.map(event => event.data.kind)).toEqual(['error', 'error'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
for (const event of test.session.snapshotEvents()) {
if (event.type === 'command/run') expect(Object.hasOwn(event.data, 'args')).toBe(false)
}
@@ -202,7 +193,6 @@ describe('/feedback human command', () => {
controller.abort(new Error('user cancelled the command'))
await expect(test.ctx.commands.execute(test.agent, '/feedback too late', [], controller.signal))
.rejects.toThrow('user cancelled the command')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(test.session.snapshotEvents()).toEqual([])
})
})
@@ -102,16 +102,12 @@ describe('/feedback real Loader composition through cordis.yml', () => {
})
// The domain event owns the payload; generic command bookkeeping omits it.
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(owner.session.snapshotEvents().map(event => event.type))
.toEqual(['command/run', 'feedback/record', 'command/done', 'command/run', 'command/done'])
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const run = owner.session.snapshotEvents().find(event => event.type === 'command/run')
expect(run?.type === 'command/run' && Object.hasOwn(run.data, 'args')).toBe(false)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const feedback = owner.session.snapshotEvents().find(event => event.type === 'feedback/record')
expect(feedback?.type === 'feedback/record' && feedback.data.text).toBe('the diff view is unreadable')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(JSON.stringify(owner.session.snapshotEvents()).match(/the diff view is unreadable/gu)).toHaveLength(1)
// Nothing reached the model.
@@ -186,7 +186,6 @@ class TestPersistence extends SessionPersistence {
}
persist(session: Session): void {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
this.durable.set(session.id, { meta: session.header, events: [...session.snapshotEvents()] })
}
@@ -62,7 +62,6 @@ describe('MessageFeedbackService public contract', () => {
})
const fixture = messageFixture('corrupt-session')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
persistence.setDurable({ meta: fixture.session.header, events: fixture.session.snapshotEvents() })
const corruption = new Error('stored log checksum mismatch')
persistence.readFailure = corruption
@@ -415,7 +414,6 @@ describe('MessageFeedbackService item concurrency', () => {
const replacement = Session.create(
old.session.id,
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
old.session.snapshotEvents(),
{ ...old.session.header, createdAt: 20, cwd: '/new' },
)
@@ -495,7 +493,6 @@ describe('canonical message feedback history', () => {
const sessionId = fixture.session.id
const messageId = fixture.assistantMessageIds[0]
persistence.persist(fixture.session)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const prefix = fixture.session.snapshotEvents()
const lifecycle: string[] = []
ctx.on('session/created', () => { lifecycle.push('created') })
@@ -541,7 +538,6 @@ describe('canonical message feedback history', () => {
const { ctx, persistence } = await harness()
const session = ctx.sessions.create(SessionId('live-log'))
const fixture = appendMessageFixture(session)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const before = session.snapshotEvents().length
const failure = new Error('disk unavailable')
let fail = true
@@ -556,9 +552,7 @@ describe('canonical message feedback history', () => {
const item = listed.value.items[0]!
fail = false
expectItem(await ctx.messageFeedback.put({ ...request, ifVersion: item.version }))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(session.snapshotEvents()).toHaveLength(before + 1)
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(persistence.durable.get(session.id)?.events).toEqual(session.snapshotEvents())
expect(persistence.openCalls).toEqual(['read'])
})
@@ -569,7 +563,6 @@ describe('canonical message feedback history', () => {
const session = ctx.sessions.create(SessionId('mismatched-checkpoint'))
const fixture = appendMessageFixture(session)
ctx.on('session/flush', () => {
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = [...session.snapshotEvents()]
if (kind === 'missing-tail') events.pop()
if (kind === 'different-tail') events[events.length - 1] = { ...events.at(-1)!, time: 0 }
@@ -594,7 +587,6 @@ describe('canonical message feedback history', () => {
expectItem(await ctx.messageFeedback.put({
sessionId: session.id, messageId: fixture.assistantMessageIds[0], rating: 'positive', ifVersion: null,
}))
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
expect(persistence.durable.get(session.id)!.events.length).toBe(session.snapshotEvents().length - 1)
})
@@ -632,7 +624,6 @@ describe('canonical message feedback history', () => {
])('rejects malformed durable feedback payload %#', async (record) => {
const { ctx, persistence } = await harness()
const fixture = messageFixture('invalid-feedback')
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const events = fixture.session.snapshotEvents()
persistence.setDurable({ meta: fixture.session.header, events: [...events, {
...record, seq: SessionSeq(events.length), time: 1,
@@ -43,7 +43,6 @@ describe.skipIf(!process.env.DEEPSEEK_API_KEY)('fs tools with-key smoke', () =>
expect(content).not.toContain('draft')
// The log records real read/write/edit tool calls (not bash).
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
const calls = agent.session.snapshotEvents().filter(e => e.type === 'tool/call').map(e => e.data.name)
expect(calls).toContain('write')
expect(calls).toContain('read')

Some files were not shown because too many files have changed in this diff Show More