@miaws/miaw 1.18.5 → 1.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -154
- package/AGENTS.md +0 -131
- package/Dockerfile +0 -18
- package/README.md +0 -15
- package/bunfig.toml +0 -7
- package/git +0 -0
- package/migration/20260511173437_session-metadata/migration.sql +0 -1
- package/migration/20260511173437_session-metadata/snapshot.json +0 -1500
- package/parsers-config.ts +0 -1
- package/script/bench-search.ts +0 -94
- package/script/bench-test-suite.ts +0 -52
- package/script/build.ts +0 -243
- package/script/generate.ts +0 -14
- package/script/httpapi-exercise.ts +0 -1
- package/script/postinstall.mjs +0 -189
- package/script/profile-test-files.ts +0 -42
- package/script/publish.ts +0 -213
- package/script/run-workspace-server +0 -106
- package/script/schema.ts +0 -77
- package/script/time.ts +0 -6
- package/script/trace-imports.ts +0 -153
- package/specs/effect/error-boundaries-plan.md +0 -235
- package/specs/effect/errors.md +0 -207
- package/specs/effect/facades.md +0 -218
- package/specs/effect/guide.md +0 -247
- package/specs/effect/instance-context.md +0 -13
- package/specs/effect/loose-ends.md +0 -30
- package/specs/effect/migration.md +0 -62
- package/specs/effect/routes.md +0 -61
- package/specs/effect/schema.md +0 -88
- package/specs/effect/server-package.md +0 -58
- package/specs/effect/todo.md +0 -241
- package/specs/effect/tools.md +0 -88
- package/specs/openapi-translation-cleanup.md +0 -204
- package/specs/tui-plugins.md +0 -544
- package/specs/v2/api.ts +0 -67
- package/specs/v2/message-shape.md +0 -136
- package/specs/v2/notifications.md +0 -13
- package/specs/v2/tui-command-shim.md +0 -67
- package/src/account/account.ts +0 -463
- package/src/account/repo.ts +0 -173
- package/src/account/schema.ts +0 -99
- package/src/account/url.ts +0 -8
- package/src/acp/agent.ts +0 -95
- package/src/acp/config-option.ts +0 -203
- package/src/acp/content.ts +0 -250
- package/src/acp/directory.ts +0 -210
- package/src/acp/error.ts +0 -90
- package/src/acp/event.ts +0 -336
- package/src/acp/permission.ts +0 -124
- package/src/acp/profile.ts +0 -42
- package/src/acp/service.ts +0 -1048
- package/src/acp/session.ts +0 -231
- package/src/acp/tool.ts +0 -321
- package/src/acp/usage.ts +0 -232
- package/src/agent/agent.ts +0 -467
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -9
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -44
- package/src/agent/subagent-permissions.ts +0 -27
- package/src/audio.d.ts +0 -14
- package/src/auth/index.ts +0 -99
- package/src/background/job.ts +0 -39
- package/src/bus/global.ts +0 -22
- package/src/cli/bootstrap.ts +0 -11
- package/src/cli/cmd/account.ts +0 -264
- package/src/cli/cmd/acp.ts +0 -73
- package/src/cli/cmd/agent.ts +0 -253
- package/src/cli/cmd/attach.ts +0 -97
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/db.ts +0 -62
- package/src/cli/cmd/debug/agent.handler.ts +0 -193
- package/src/cli/cmd/debug/agent.ts +0 -27
- package/src/cli/cmd/debug/config.ts +0 -14
- package/src/cli/cmd/debug/file.ts +0 -73
- package/src/cli/cmd/debug/index.ts +0 -87
- package/src/cli/cmd/debug/lsp.ts +0 -50
- package/src/cli/cmd/debug/ripgrep.ts +0 -79
- package/src/cli/cmd/debug/scrap.ts +0 -15
- package/src/cli/cmd/debug/skill.ts +0 -15
- package/src/cli/cmd/debug/snapshot.ts +0 -50
- package/src/cli/cmd/debug/startup.ts +0 -11
- package/src/cli/cmd/debug/v2.ts +0 -49
- package/src/cli/cmd/export.ts +0 -292
- package/src/cli/cmd/generate.ts +0 -54
- package/src/cli/cmd/github.handler.ts +0 -1593
- package/src/cli/cmd/github.shared.ts +0 -30
- package/src/cli/cmd/github.ts +0 -42
- package/src/cli/cmd/import.ts +0 -224
- package/src/cli/cmd/mcp.ts +0 -849
- package/src/cli/cmd/models.ts +0 -66
- package/src/cli/cmd/plug.ts +0 -230
- package/src/cli/cmd/pr.ts +0 -115
- package/src/cli/cmd/prompt-display.ts +0 -1
- package/src/cli/cmd/providers.ts +0 -534
- package/src/cli/cmd/run/demo.ts +0 -1274
- package/src/cli/cmd/run/entry.body.ts +0 -205
- package/src/cli/cmd/run/footer.command.tsx +0 -1064
- package/src/cli/cmd/run/footer.menu.tsx +0 -351
- package/src/cli/cmd/run/footer.permission.tsx +0 -472
- package/src/cli/cmd/run/footer.prompt.tsx +0 -1306
- package/src/cli/cmd/run/footer.question.tsx +0 -573
- package/src/cli/cmd/run/footer.subagent.tsx +0 -173
- package/src/cli/cmd/run/footer.ts +0 -1129
- package/src/cli/cmd/run/footer.view.tsx +0 -943
- package/src/cli/cmd/run/footer.width.ts +0 -27
- package/src/cli/cmd/run/permission.shared.ts +0 -256
- package/src/cli/cmd/run/prompt.editor.ts +0 -157
- package/src/cli/cmd/run/prompt.shared.ts +0 -153
- package/src/cli/cmd/run/question.shared.ts +0 -340
- package/src/cli/cmd/run/runtime.boot.ts +0 -202
- package/src/cli/cmd/run/runtime.lifecycle.ts +0 -406
- package/src/cli/cmd/run/runtime.queue.ts +0 -349
- package/src/cli/cmd/run/runtime.shared.ts +0 -17
- package/src/cli/cmd/run/runtime.stdin.ts +0 -37
- package/src/cli/cmd/run/runtime.ts +0 -814
- package/src/cli/cmd/run/scrollback.shared.ts +0 -92
- package/src/cli/cmd/run/scrollback.surface.ts +0 -431
- package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
- package/src/cli/cmd/run/session-data.ts +0 -1113
- package/src/cli/cmd/run/session-replay.ts +0 -374
- package/src/cli/cmd/run/session.shared.ts +0 -196
- package/src/cli/cmd/run/splash.ts +0 -280
- package/src/cli/cmd/run/stream.transport.ts +0 -1462
- package/src/cli/cmd/run/stream.ts +0 -175
- package/src/cli/cmd/run/subagent-data.ts +0 -876
- package/src/cli/cmd/run/theme.ts +0 -690
- package/src/cli/cmd/run/tool.ts +0 -1489
- package/src/cli/cmd/run/trace.ts +0 -94
- package/src/cli/cmd/run/turn-summary.ts +0 -47
- package/src/cli/cmd/run/types.ts +0 -350
- package/src/cli/cmd/run/variant.shared.ts +0 -215
- package/src/cli/cmd/run.ts +0 -894
- package/src/cli/cmd/serve.ts +0 -24
- package/src/cli/cmd/session.ts +0 -147
- package/src/cli/cmd/stats.ts +0 -393
- package/src/cli/cmd/tui.ts +0 -224
- package/src/cli/cmd/uninstall.ts +0 -353
- package/src/cli/cmd/upgrade.ts +0 -74
- package/src/cli/cmd/web.ts +0 -84
- package/src/cli/effect/prompt.ts +0 -37
- package/src/cli/effect-cmd.ts +0 -96
- package/src/cli/error.ts +0 -130
- package/src/cli/heap.ts +0 -45
- package/src/cli/logo.ts +0 -1
- package/src/cli/network.ts +0 -64
- package/src/cli/tui/layer.ts +0 -7
- package/src/cli/tui/validate-session.ts +0 -29
- package/src/cli/tui/worker.ts +0 -71
- package/src/cli/ui.ts +0 -132
- package/src/cli/upgrade.ts +0 -53
- package/src/command/index.ts +0 -184
- package/src/command/template/initialize.txt +0 -66
- package/src/command/template/review.txt +0 -101
- package/src/config/agent-preset.ts +0 -175
- package/src/config/agent.ts +0 -59
- package/src/config/command.ts +0 -39
- package/src/config/config.ts +0 -703
- package/src/config/entry-name.ts +0 -19
- package/src/config/managed.ts +0 -69
- package/src/config/markdown.ts +0 -36
- package/src/config/parse.ts +0 -79
- package/src/config/paths.ts +0 -45
- package/src/config/plugin.ts +0 -79
- package/src/config/tui-cwd.ts +0 -5
- package/src/config/tui-host-attention.ts +0 -21
- package/src/config/tui-migrate.ts +0 -132
- package/src/config/tui.ts +0 -274
- package/src/config/variable.ts +0 -91
- package/src/control-plane/adapters/index.ts +0 -41
- package/src/control-plane/adapters/worktree.ts +0 -96
- package/src/control-plane/dev/README.md +0 -19
- package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
- package/src/control-plane/types.ts +0 -59
- package/src/control-plane/util.ts +0 -39
- package/src/control-plane/workspace-adapter-runtime.ts +0 -51
- package/src/control-plane/workspace-context.ts +0 -26
- package/src/control-plane/workspace.ts +0 -989
- package/src/effect/app-runtime.ts +0 -132
- package/src/effect/bootstrap-runtime.ts +0 -23
- package/src/effect/bridge.ts +0 -84
- package/src/effect/config-service.ts +0 -67
- package/src/effect/instance-ref.ts +0 -11
- package/src/effect/instance-registry.ts +0 -12
- package/src/effect/instance-state.ts +0 -69
- package/src/effect/promise.ts +0 -17
- package/src/effect/run-service.ts +0 -47
- package/src/effect/runner.ts +0 -217
- package/src/effect/runtime-flags.ts +0 -79
- package/src/env/index.ts +0 -43
- package/src/event-v2-bridge.ts +0 -79
- package/src/format/formatter.ts +0 -404
- package/src/format/index.ts +0 -205
- package/src/git/index.ts +0 -350
- package/src/id/id.ts +0 -80
- package/src/ide/index.ts +0 -61
- package/src/image/image.ts +0 -174
- package/src/index.ts +0 -142
- package/src/installation/index.ts +0 -350
- package/src/lsp/client.ts +0 -650
- package/src/lsp/diagnostic.ts +0 -29
- package/src/lsp/language.ts +0 -121
- package/src/lsp/launch.ts +0 -21
- package/src/lsp/lsp.ts +0 -511
- package/src/lsp/server.ts +0 -1983
- package/src/markdown.d.ts +0 -4
- package/src/mcp/auth.ts +0 -174
- package/src/mcp/catalog.ts +0 -144
- package/src/mcp/index.ts +0 -953
- package/src/mcp/oauth-callback.ts +0 -221
- package/src/mcp/oauth-provider.ts +0 -206
- package/src/node.ts +0 -4
- package/src/patch/index.ts +0 -686
- package/src/permission/arity.ts +0 -163
- package/src/permission/evaluate.ts +0 -1
- package/src/permission/index.ts +0 -230
- package/src/plugin/azure.ts +0 -26
- package/src/plugin/cloudflare.ts +0 -76
- package/src/plugin/digitalocean.ts +0 -383
- package/src/plugin/github-copilot/copilot.ts +0 -413
- package/src/plugin/github-copilot/models.ts +0 -246
- package/src/plugin/index.ts +0 -315
- package/src/plugin/install.ts +0 -439
- package/src/plugin/loader.ts +0 -237
- package/src/plugin/meta.ts +0 -188
- package/src/plugin/openai/README.md +0 -31
- package/src/plugin/openai/codex.ts +0 -640
- package/src/plugin/openai/ws-pool.ts +0 -270
- package/src/plugin/openai/ws.ts +0 -381
- package/src/plugin/pty-environment.ts +0 -24
- package/src/plugin/shared.ts +0 -323
- package/src/plugin/snowflake-cortex.ts +0 -529
- package/src/plugin/tui/internal.ts +0 -10
- package/src/plugin/tui/runtime.ts +0 -1130
- package/src/plugin/xai.ts +0 -734
- package/src/project/bootstrap-service.ts +0 -9
- package/src/project/bootstrap.ts +0 -76
- package/src/project/instance-context.ts +0 -24
- package/src/project/instance-layer.ts +0 -11
- package/src/project/instance-runtime.ts +0 -16
- package/src/project/instance-store.ts +0 -209
- package/src/project/project.ts +0 -519
- package/src/project/vcs.ts +0 -431
- package/src/provider/auth.ts +0 -233
- package/src/provider/error.ts +0 -188
- package/src/provider/model-status.ts +0 -8
- package/src/provider/provider.ts +0 -1975
- package/src/provider/transform.ts +0 -1426
- package/src/question/index.ts +0 -229
- package/src/question/schema.ts +0 -10
- package/src/server/auth.ts +0 -48
- package/src/server/event.ts +0 -13
- package/src/server/global-lifecycle.ts +0 -28
- package/src/server/init-projectors.ts +0 -3
- package/src/server/mdns.ts +0 -47
- package/src/server/projectors.ts +0 -1
- package/src/server/proxy-util.ts +0 -48
- package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
- package/src/server/routes/instance/httpapi/api.ts +0 -78
- package/src/server/routes/instance/httpapi/errors.ts +0 -193
- package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
- package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
- package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
- package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
- package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -260
- package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
- package/src/server/routes/instance/httpapi/groups/global.ts +0 -138
- package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
- package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
- package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
- package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
- package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
- package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
- package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
- package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
- package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
- package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
- package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
- package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
- package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
- package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
- package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
- package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
- package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
- package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
- package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -187
- package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
- package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
- package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
- package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
- package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
- package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
- package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
- package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
- package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
- package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
- package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
- package/src/server/routes/instance/httpapi/handlers/session.ts +0 -440
- package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
- package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
- package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
- package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
- package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
- package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
- package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
- package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
- package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
- package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
- package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
- package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
- package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
- package/src/server/routes/instance/httpapi/public.ts +0 -535
- package/src/server/routes/instance/httpapi/server.ts +0 -298
- package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -57
- package/src/server/server.ts +0 -217
- package/src/server/shared/fence.ts +0 -60
- package/src/server/shared/pty-ticket.ts +0 -15
- package/src/server/shared/public-ui.ts +0 -12
- package/src/server/shared/tui-control.ts +0 -28
- package/src/server/shared/ui.ts +0 -108
- package/src/server/shared/workspace-routing.ts +0 -38
- package/src/server/tui-event.ts +0 -53
- package/src/session/compaction.ts +0 -620
- package/src/session/instruction.ts +0 -250
- package/src/session/llm/AGENTS.md +0 -90
- package/src/session/llm/ai-sdk.ts +0 -288
- package/src/session/llm/native-request.ts +0 -196
- package/src/session/llm/native-runtime.ts +0 -195
- package/src/session/llm/request.ts +0 -216
- package/src/session/llm.ts +0 -415
- package/src/session/message-error.ts +0 -14
- package/src/session/message-v2.ts +0 -744
- package/src/session/message.ts +0 -148
- package/src/session/overflow.ts +0 -34
- package/src/session/processor.ts +0 -1084
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -79
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/default.txt +0 -95
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/gpt.txt +0 -107
- package/src/session/prompt/kimi.txt +0 -95
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-mode.txt +0 -70
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/trinity.txt +0 -97
- package/src/session/prompt/ultrawork.txt +0 -289
- package/src/session/prompt.ts +0 -1725
- package/src/session/reminders.ts +0 -92
- package/src/session/retry.ts +0 -201
- package/src/session/revert.ts +0 -160
- package/src/session/run-state.ts +0 -156
- package/src/session/schema.ts +0 -26
- package/src/session/session.ts +0 -1119
- package/src/session/status.ts +0 -97
- package/src/session/summary.ts +0 -165
- package/src/session/system.ts +0 -117
- package/src/session/todo.ts +0 -90
- package/src/session/tools.ts +0 -207
- package/src/session/ultrawork.ts +0 -26
- package/src/share/session.ts +0 -61
- package/src/share/share-next.ts +0 -385
- package/src/skill/discovery.ts +0 -109
- package/src/skill/index.ts +0 -366
- package/src/snapshot/index.ts +0 -808
- package/src/sql.d.ts +0 -4
- package/src/storage/schema.ts +0 -5
- package/src/storage/storage.ts +0 -329
- package/src/sync/README.md +0 -179
- package/src/sync/schema.ts +0 -11
- package/src/temporary.ts +0 -31
- package/src/tool/apply_patch.ts +0 -313
- package/src/tool/apply_patch.txt +0 -33
- package/src/tool/edit.ts +0 -737
- package/src/tool/edit.txt +0 -10
- package/src/tool/external-directory.ts +0 -49
- package/src/tool/glob.ts +0 -76
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -112
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -21
- package/src/tool/json-schema.ts +0 -164
- package/src/tool/lsp.ts +0 -113
- package/src/tool/lsp.txt +0 -24
- package/src/tool/mcp-websearch.ts +0 -96
- package/src/tool/plan-enter.txt +0 -14
- package/src/tool/plan-exit.txt +0 -13
- package/src/tool/plan.ts +0 -79
- package/src/tool/question.ts +0 -44
- package/src/tool/question.txt +0 -10
- package/src/tool/read.ts +0 -386
- package/src/tool/read.txt +0 -14
- package/src/tool/registry.ts +0 -440
- package/src/tool/schema.ts +0 -14
- package/src/tool/shell/id.ts +0 -19
- package/src/tool/shell/prompt.ts +0 -307
- package/src/tool/shell/shell.txt +0 -21
- package/src/tool/shell.ts +0 -657
- package/src/tool/skill.ts +0 -71
- package/src/tool/skill.txt +0 -5
- package/src/tool/task.ts +0 -346
- package/src/tool/task.txt +0 -19
- package/src/tool/todo.ts +0 -57
- package/src/tool/todowrite.txt +0 -44
- package/src/tool/tool.ts +0 -183
- package/src/tool/truncate.ts +0 -158
- package/src/tool/truncation-dir.ts +0 -4
- package/src/tool/webfetch.ts +0 -192
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -143
- package/src/tool/websearch.txt +0 -14
- package/src/tool/write.ts +0 -104
- package/src/tool/write.txt +0 -8
- package/src/util/archive.ts +0 -17
- package/src/util/bom.ts +0 -27
- package/src/util/data-url.ts +0 -9
- package/src/util/defer.ts +0 -10
- package/src/util/effect-http-client.ts +0 -11
- package/src/util/error.ts +0 -1
- package/src/util/filesystem.ts +0 -251
- package/src/util/iife.ts +0 -3
- package/src/util/lazy.ts +0 -20
- package/src/util/local-context.ts +0 -25
- package/src/util/locale.ts +0 -2
- package/src/util/media.ts +0 -26
- package/src/util/process.ts +0 -177
- package/src/util/proxy-env.ts +0 -72
- package/src/util/queue.ts +0 -32
- package/src/util/record.ts +0 -1
- package/src/util/repository.ts +0 -232
- package/src/util/rpc.ts +0 -66
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -13
- package/src/util/token.ts +0 -1
- package/src/util/wildcard.ts +0 -59
- package/src/worktree/index.ts +0 -654
- package/sst-env.d.ts +0 -10
- package/test/AGENTS.md +0 -204
- package/test/EFFECT_TEST_MIGRATION.md +0 -169
- package/test/account/repo.test.ts +0 -353
- package/test/account/service.test.ts +0 -453
- package/test/acp/config-option.test.ts +0 -229
- package/test/acp/content.test.ts +0 -201
- package/test/acp/directory.test.ts +0 -186
- package/test/acp/error.test.ts +0 -67
- package/test/acp/event.test.ts +0 -743
- package/test/acp/permission.test.ts +0 -273
- package/test/acp/service-session.test.ts +0 -1174
- package/test/acp/session.test.ts +0 -200
- package/test/acp/tool.test.ts +0 -210
- package/test/acp/usage.test.ts +0 -315
- package/test/agent/agent.test.ts +0 -760
- package/test/agent/plan-mode-subagent-bypass.test.ts +0 -159
- package/test/agent/plugin-agent-regression.test.ts +0 -64
- package/test/auth/auth.test.ts +0 -77
- package/test/background/job.test.ts +0 -243
- package/test/cli/account.test.ts +0 -30
- package/test/cli/acp/acp-test-client.ts +0 -97
- package/test/cli/acp/config-options.test.ts +0 -103
- package/test/cli/acp/helpers.ts +0 -96
- package/test/cli/acp/initialize-auth.test.ts +0 -61
- package/test/cli/acp/lifecycle.test.ts +0 -118
- package/test/cli/acp/prompt-content.test.ts +0 -97
- package/test/cli/acp/skills.test.ts +0 -38
- package/test/cli/cmd/tui/attention.test.ts +0 -484
- package/test/cli/effect-cmd-instance-als.test.ts +0 -39
- package/test/cli/error.test.ts +0 -95
- package/test/cli/github-action.test.ts +0 -199
- package/test/cli/github-remote.test.ts +0 -90
- package/test/cli/help/__snapshots__/help-snapshots.test.ts.snap +0 -631
- package/test/cli/help/help-snapshots.test.ts +0 -137
- package/test/cli/import.test.ts +0 -54
- package/test/cli/mcp-add.test.ts +0 -74
- package/test/cli/plugin-auth-picker.test.ts +0 -120
- package/test/cli/run/entry.body.test.ts +0 -536
- package/test/cli/run/footer.menu.test.ts +0 -43
- package/test/cli/run/footer.view.test.tsx +0 -1375
- package/test/cli/run/footer.width.test.ts +0 -35
- package/test/cli/run/permission.shared.test.ts +0 -144
- package/test/cli/run/prompt.editor.test.ts +0 -101
- package/test/cli/run/prompt.shared.test.ts +0 -101
- package/test/cli/run/question.shared.test.ts +0 -115
- package/test/cli/run/run-process.test.ts +0 -84
- package/test/cli/run/runtime.boot.test.ts +0 -283
- package/test/cli/run/runtime.queue.test.ts +0 -481
- package/test/cli/run/runtime.stdin.test.ts +0 -71
- package/test/cli/run/runtime.test.ts +0 -238
- package/test/cli/run/scrollback.surface.test.ts +0 -1065
- package/test/cli/run/session-data.test.ts +0 -595
- package/test/cli/run/session-replay.test.ts +0 -692
- package/test/cli/run/session.shared.test.ts +0 -247
- package/test/cli/run/stream.test.ts +0 -56
- package/test/cli/run/stream.transport.test.ts +0 -2363
- package/test/cli/run/subagent-data.test.ts +0 -547
- package/test/cli/run/theme.test.ts +0 -177
- package/test/cli/run/variant.shared.test.ts +0 -217
- package/test/cli/serve/serve-process.test.ts +0 -61
- package/test/cli/smokes/read-only.test.ts +0 -115
- package/test/cli/tui/attach.test.ts +0 -11
- package/test/cli/tui/editor-context-zed.test.ts +0 -379
- package/test/cli/tui/editor-context.test.tsx +0 -297
- package/test/cli/tui/plugin-add.test.ts +0 -110
- package/test/cli/tui/plugin-install.test.ts +0 -87
- package/test/cli/tui/plugin-lifecycle.test.ts +0 -224
- package/test/cli/tui/plugin-loader-entrypoint.test.ts +0 -485
- package/test/cli/tui/plugin-loader-pure.test.ts +0 -72
- package/test/cli/tui/plugin-loader.test.ts +0 -1332
- package/test/cli/tui/plugin-toggle.test.ts +0 -264
- package/test/cli/tui/thread.test.ts +0 -36
- package/test/config/agent-color.test.ts +0 -47
- package/test/config/config.test.ts +0 -2041
- package/test/config/entry-name.test.ts +0 -57
- package/test/config/fixtures/empty-frontmatter.md +0 -4
- package/test/config/fixtures/frontmatter.md +0 -28
- package/test/config/fixtures/markdown-header.md +0 -11
- package/test/config/fixtures/no-frontmatter.md +0 -1
- package/test/config/fixtures/weird-model-id.md +0 -13
- package/test/config/lsp.test.ts +0 -69
- package/test/config/markdown.test.ts +0 -228
- package/test/config/plugin.test.ts +0 -0
- package/test/config/tui.test.ts +0 -886
- package/test/control-plane/adapters.test.ts +0 -71
- package/test/control-plane/workspace.test.ts +0 -1703
- package/test/effect/app-graph-types.test.ts +0 -108
- package/test/effect/app-graph.test.ts +0 -204
- package/test/effect/app-runtime-logger.test.ts +0 -99
- package/test/effect/config-service.test.ts +0 -65
- package/test/effect/instance-state.test.ts +0 -391
- package/test/effect/run-service.test.ts +0 -89
- package/test/effect/runner.test.ts +0 -514
- package/test/effect/runtime-flags.test.ts +0 -373
- package/test/fake/account.ts +0 -9
- package/test/fake/auth.ts +0 -8
- package/test/fake/npm.ts +0 -8
- package/test/fake/provider.ts +0 -82
- package/test/fake/skill.ts +0 -8
- package/test/filesystem/filesystem.test.ts +0 -319
- package/test/fixture/agent-plugin.constants.ts +0 -6
- package/test/fixture/agent-plugin.ts +0 -12
- package/test/fixture/config.ts +0 -23
- package/test/fixture/db.ts +0 -11
- package/test/fixture/fixture.test.ts +0 -26
- package/test/fixture/fixture.ts +0 -224
- package/test/fixture/flag.ts +0 -20
- package/test/fixture/flock-worker.ts +0 -72
- package/test/fixture/lsp/fake-lsp-server.js +0 -249
- package/test/fixture/mcp-session-recovery.ts +0 -50
- package/test/fixture/plug-worker.ts +0 -93
- package/test/fixture/plugin-meta-worker.ts +0 -19
- package/test/fixture/plugin.ts +0 -10
- package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
- package/test/fixture/skills/agents-sdk/references/callable.md +0 -92
- package/test/fixture/skills/cloudflare/SKILL.md +0 -211
- package/test/fixture/skills/index.json +0 -6
- package/test/fixture/tui-environment.tsx +0 -32
- package/test/fixture/tui-plugin.ts +0 -355
- package/test/fixture/tui-runtime.ts +0 -56
- package/test/fixture/tui-sdk.ts +0 -82
- package/test/fixture/workspace.ts +0 -30
- package/test/fixtures/recordings/session/native-anthropic-tool-loop.json +0 -49
- package/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json +0 -45
- package/test/fixtures/recordings/session/native-zen-tool-loop.json +0 -49
- package/test/format/format.test.ts +0 -228
- package/test/git/git.test.ts +0 -178
- package/test/ide/ide.test.ts +0 -82
- package/test/image/fixtures/picture-5mb-base64.png +0 -0
- package/test/image/image.test.ts +0 -123
- package/test/installation/installation.test.ts +0 -230
- package/test/lib/cli-process.ts +0 -459
- package/test/lib/effect.ts +0 -177
- package/test/lib/filesystem.ts +0 -10
- package/test/lib/llm-server.ts +0 -779
- package/test/lib/snapshot.ts +0 -73
- package/test/lib/test-provider.ts +0 -37
- package/test/lib/websocket.ts +0 -46
- package/test/lsp/client.test.ts +0 -488
- package/test/lsp/index.test.ts +0 -232
- package/test/lsp/jdtls-root.test.ts +0 -459
- package/test/lsp/launch.test.ts +0 -22
- package/test/lsp/lifecycle.test.ts +0 -160
- package/test/mcp/auth.test.ts +0 -78
- package/test/mcp/headers.test.ts +0 -126
- package/test/mcp/lifecycle.test.ts +0 -1213
- package/test/mcp/oauth-auto-connect.test.ts +0 -276
- package/test/mcp/oauth-browser.test.ts +0 -239
- package/test/mcp/oauth-callback.test.ts +0 -34
- package/test/mcp/oauth-provider.test.ts +0 -61
- package/test/mcp/session-recovery.test.ts +0 -27
- package/test/patch/patch.test.ts +0 -383
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -1176
- package/test/permission-task.test.ts +0 -318
- package/test/plugin/auth-override.test.ts +0 -105
- package/test/plugin/cloudflare.test.ts +0 -68
- package/test/plugin/codex.test.ts +0 -247
- package/test/plugin/github-copilot-models.test.ts +0 -332
- package/test/plugin/install-concurrency.test.ts +0 -140
- package/test/plugin/install.test.ts +0 -570
- package/test/plugin/loader-shared.test.ts +0 -1303
- package/test/plugin/meta.test.ts +0 -137
- package/test/plugin/openai-rollout.test.ts +0 -17
- package/test/plugin/openai-ws.test.ts +0 -877
- package/test/plugin/shared.test.ts +0 -88
- package/test/plugin/snowflake-cortex.test.ts +0 -278
- package/test/plugin/trigger.test.ts +0 -120
- package/test/plugin/workspace-adapter.test.ts +0 -140
- package/test/plugin/xai.test.ts +0 -634
- package/test/preload.ts +0 -92
- package/test/project/instance-bootstrap.test.ts +0 -110
- package/test/project/instance.test.ts +0 -245
- package/test/project/migrate-global.test.ts +0 -167
- package/test/project/project-directory.test.ts +0 -201
- package/test/project/project.test.ts +0 -815
- package/test/project/vcs.test.ts +0 -336
- package/test/project/worktree-remove.test.ts +0 -126
- package/test/project/worktree.test.ts +0 -320
- package/test/provider/amazon-bedrock.test.ts +0 -360
- package/test/provider/cf-ai-gateway-e2e.test.ts +0 -132
- package/test/provider/digitalocean.test.ts +0 -123
- package/test/provider/gitlab-duo.test.ts +0 -412
- package/test/provider/header-timeout.test.ts +0 -233
- package/test/provider/model-status.test.ts +0 -61
- package/test/provider/provider.test.ts +0 -1793
- package/test/provider/transform.test.ts +0 -4207
- package/test/question/question.test.ts +0 -465
- package/test/server/AGENTS.md +0 -15
- package/test/server/auth.test.ts +0 -59
- package/test/server/global-bus.ts +0 -31
- package/test/server/global-session-list.test.ts +0 -104
- package/test/server/httpapi-authorization.test.ts +0 -174
- package/test/server/httpapi-compression.test.ts +0 -151
- package/test/server/httpapi-config.test.ts +0 -110
- package/test/server/httpapi-control-plane.test.ts +0 -63
- package/test/server/httpapi-cors-vary.test.ts +0 -63
- package/test/server/httpapi-cors.test.ts +0 -122
- package/test/server/httpapi-error-middleware.test.ts +0 -101
- package/test/server/httpapi-event.test.ts +0 -94
- package/test/server/httpapi-exercise/assertions.ts +0 -64
- package/test/server/httpapi-exercise/backend.ts +0 -144
- package/test/server/httpapi-exercise/dsl.ts +0 -210
- package/test/server/httpapi-exercise/environment.ts +0 -40
- package/test/server/httpapi-exercise/index.ts +0 -1685
- package/test/server/httpapi-exercise/report.ts +0 -66
- package/test/server/httpapi-exercise/routing.ts +0 -96
- package/test/server/httpapi-exercise/runner.ts +0 -267
- package/test/server/httpapi-exercise/runtime.ts +0 -52
- package/test/server/httpapi-exercise/types.ts +0 -123
- package/test/server/httpapi-experimental.test.ts +0 -297
- package/test/server/httpapi-file.test.ts +0 -73
- package/test/server/httpapi-global.test.ts +0 -66
- package/test/server/httpapi-instance-context.test.ts +0 -348
- package/test/server/httpapi-instance-route-auth.test.ts +0 -81
- package/test/server/httpapi-instance.test.ts +0 -265
- package/test/server/httpapi-layer.ts +0 -33
- package/test/server/httpapi-listen.test.ts +0 -412
- package/test/server/httpapi-mcp-oauth.test.ts +0 -73
- package/test/server/httpapi-mcp.test.ts +0 -223
- package/test/server/httpapi-mdns.test.ts +0 -79
- package/test/server/httpapi-promptasync-context.test.ts +0 -223
- package/test/server/httpapi-provider.test.ts +0 -400
- package/test/server/httpapi-pty.test.ts +0 -299
- package/test/server/httpapi-public-openapi.test.ts +0 -319
- package/test/server/httpapi-query-schema-drift.test.ts +0 -330
- package/test/server/httpapi-reference.test.ts +0 -62
- package/test/server/httpapi-schema-error-body.test.ts +0 -165
- package/test/server/httpapi-sdk.test.ts +0 -909
- package/test/server/httpapi-session.test.ts +0 -1011
- package/test/server/httpapi-sync.test.ts +0 -148
- package/test/server/httpapi-ui.test.ts +0 -453
- package/test/server/httpapi-v2-location.test.ts +0 -82
- package/test/server/httpapi-v2-pty.test.ts +0 -250
- package/test/server/httpapi-workspace-routing.test.ts +0 -555
- package/test/server/httpapi-workspace.test.ts +0 -513
- package/test/server/negative-tokens-regression.test.ts +0 -83
- package/test/server/project-copy.test.ts +0 -121
- package/test/server/project-init-git.test.ts +0 -114
- package/test/server/proxy-util.test.ts +0 -113
- package/test/server/sdk-error-shape.test.ts +0 -81
- package/test/server/sdk-v1-smoke.test.ts +0 -57
- package/test/server/session-actions.test.ts +0 -109
- package/test/server/session-diff-missing-patch.test.ts +0 -96
- package/test/server/session-list.test.ts +0 -312
- package/test/server/session-messages.test.ts +0 -179
- package/test/server/session-select.test.ts +0 -66
- package/test/server/workspace-proxy.test.ts +0 -181
- package/test/server/workspace-routing.test.ts +0 -94
- package/test/server/worktree-endpoint-repro.test.ts +0 -307
- package/test/session/compaction.test.ts +0 -1834
- package/test/session/instruction.test.ts +0 -256
- package/test/session/llm-native-recorded.test.ts +0 -433
- package/test/session/llm-native.test.ts +0 -760
- package/test/session/llm.test.ts +0 -1932
- package/test/session/message-v2.test.ts +0 -1661
- package/test/session/messages-pagination.test.ts +0 -1056
- package/test/session/processor-effect.test.ts +0 -1076
- package/test/session/prompt.test.ts +0 -2326
- package/test/session/retry.test.ts +0 -439
- package/test/session/revert-compact.test.ts +0 -639
- package/test/session/schema-decoding.test.ts +0 -313
- package/test/session/session-schema.test.ts +0 -78
- package/test/session/session.test.ts +0 -248
- package/test/session/snapshot-tool-race.test.ts +0 -190
- package/test/session/structured-output-integration.test.ts +0 -235
- package/test/session/structured-output.test.ts +0 -387
- package/test/session/system.test.ts +0 -86
- package/test/session/ultrawork.test.ts +0 -25
- package/test/share/share-next.test.ts +0 -326
- package/test/skill/discovery.test.ts +0 -139
- package/test/skill/skill.test.ts +0 -571
- package/test/snapshot/snapshot.test.ts +0 -1121
- package/test/storage/storage.test.ts +0 -296
- package/test/tool/__snapshots__/parameters.test.ts.snap +0 -484
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/apply_patch.test.ts +0 -533
- package/test/tool/edit.test.ts +0 -578
- package/test/tool/external-directory.test.ts +0 -155
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +0 -117299
- package/test/tool/glob.test.ts +0 -136
- package/test/tool/grep.test.ts +0 -225
- package/test/tool/lsp.test.ts +0 -181
- package/test/tool/parameters.test.ts +0 -293
- package/test/tool/question.test.ts +0 -138
- package/test/tool/read.test.ts +0 -605
- package/test/tool/registry.test.ts +0 -497
- package/test/tool/shell.test.ts +0 -1238
- package/test/tool/skill.test.ts +0 -136
- package/test/tool/task.test.ts +0 -898
- package/test/tool/tool-define.test.ts +0 -153
- package/test/tool/truncation.test.ts +0 -266
- package/test/tool/webfetch.test.ts +0 -113
- package/test/tool/websearch.test.ts +0 -99
- package/test/tool/write.test.ts +0 -276
- package/test/util/data-url.test.ts +0 -14
- package/test/util/error.test.ts +0 -16
- package/test/util/filesystem.test.ts +0 -656
- package/test/util/glob.test.ts +0 -164
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/module.test.ts +0 -59
- package/test/util/process.test.ts +0 -128
- package/test/util/repository.test.ts +0 -93
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -90
- package/test/v2/session-message-updater.test.ts +0 -269
- package/tsconfig.json +0 -16
|
@@ -1,1834 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, mock, test } from "bun:test"
|
|
2
|
-
import { ConfigV1 } from "@miaw/core/v1/config/config"
|
|
3
|
-
import { SessionV1 } from "@miaw/core/v1/session"
|
|
4
|
-
import { Database } from "@miaw/core/database/database"
|
|
5
|
-
import { EventV2Bridge } from "@/event-v2-bridge"
|
|
6
|
-
import { APICallError } from "ai"
|
|
7
|
-
import { Cause, Deferred, Effect, Exit, Fiber, Layer, Schema } from "effect"
|
|
8
|
-
import * as Stream from "effect/Stream"
|
|
9
|
-
import { Config } from "@/config/config"
|
|
10
|
-
import { Image } from "@/image/image"
|
|
11
|
-
import { Agent } from "../../src/agent/agent"
|
|
12
|
-
import { LLM } from "../../src/session/llm"
|
|
13
|
-
import { SessionCompaction } from "../../src/session/compaction"
|
|
14
|
-
import { Token } from "@/util/token"
|
|
15
|
-
import { Permission } from "../../src/permission"
|
|
16
|
-
import { Plugin } from "../../src/plugin"
|
|
17
|
-
import { provideTmpdirInstance, TestInstance } from "../fixture/fixture"
|
|
18
|
-
import { Session as SessionNs } from "@/session/session"
|
|
19
|
-
import { MessageV2 } from "../../src/session/message-v2"
|
|
20
|
-
import { MessageID, PartID, SessionID } from "../../src/session/schema"
|
|
21
|
-
import { SessionStatus } from "../../src/session/status"
|
|
22
|
-
import { SessionSummary } from "../../src/session/summary"
|
|
23
|
-
import { SessionV2 } from "@miaw/core/session"
|
|
24
|
-
import { SessionExecution } from "@miaw/core/session/execution"
|
|
25
|
-
|
|
26
|
-
import type { Provider } from "@/provider/provider"
|
|
27
|
-
import * as SessionProcessorModule from "../../src/session/processor"
|
|
28
|
-
import { Snapshot } from "../../src/snapshot"
|
|
29
|
-
import { ProviderTest } from "../fake/provider"
|
|
30
|
-
import { testEffect } from "../lib/effect"
|
|
31
|
-
import { CrossSpawnSpawner } from "@miaw/core/cross-spawn-spawner"
|
|
32
|
-
import { TestConfig } from "../fixture/config"
|
|
33
|
-
import { RuntimeFlags } from "@/effect/runtime-flags"
|
|
34
|
-
import { LLMEvent, Usage } from "@miaw/llm"
|
|
35
|
-
import { ProviderV2 } from "@miaw/core/provider"
|
|
36
|
-
import { ModelV2 } from "@miaw/core/model"
|
|
37
|
-
|
|
38
|
-
const summary = Layer.succeed(
|
|
39
|
-
SessionSummary.Service,
|
|
40
|
-
SessionSummary.Service.of({
|
|
41
|
-
summarize: () => Effect.void,
|
|
42
|
-
diff: () => Effect.succeed([]),
|
|
43
|
-
computeDiff: () => Effect.succeed([]),
|
|
44
|
-
}),
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
const ref = {
|
|
48
|
-
providerID: ProviderV2.ID.make("test"),
|
|
49
|
-
modelID: ModelV2.ID.make("test-model"),
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const usage = (input: ConstructorParameters<typeof Usage>[0]) => new Usage(input)
|
|
53
|
-
|
|
54
|
-
const basicUsage = () => usage({ inputTokens: 1, outputTokens: 1, totalTokens: 2 })
|
|
55
|
-
|
|
56
|
-
afterEach(() => {
|
|
57
|
-
mock.restore()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
function createModel(opts: {
|
|
61
|
-
context: number
|
|
62
|
-
output: number
|
|
63
|
-
input?: number
|
|
64
|
-
cost?: Provider.Model["cost"]
|
|
65
|
-
npm?: string
|
|
66
|
-
}): Provider.Model {
|
|
67
|
-
return {
|
|
68
|
-
id: "test-model",
|
|
69
|
-
providerID: "test",
|
|
70
|
-
name: "Test",
|
|
71
|
-
limit: {
|
|
72
|
-
context: opts.context,
|
|
73
|
-
input: opts.input,
|
|
74
|
-
output: opts.output,
|
|
75
|
-
},
|
|
76
|
-
cost: opts.cost ?? { input: 0, output: 0, cache: { read: 0, write: 0 } },
|
|
77
|
-
capabilities: {
|
|
78
|
-
toolcall: true,
|
|
79
|
-
attachment: false,
|
|
80
|
-
reasoning: false,
|
|
81
|
-
temperature: true,
|
|
82
|
-
input: { text: true, image: false, audio: false, video: false },
|
|
83
|
-
output: { text: true, image: false, audio: false, video: false },
|
|
84
|
-
},
|
|
85
|
-
api: { npm: opts.npm ?? "@ai-sdk/anthropic" },
|
|
86
|
-
options: {},
|
|
87
|
-
} as Provider.Model
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const wide = () => ProviderTest.fake({ model: createModel({ context: 100_000, output: 32_000 }) })
|
|
91
|
-
|
|
92
|
-
function createUserMessage(sessionID: SessionID, text: string) {
|
|
93
|
-
return Effect.gen(function* () {
|
|
94
|
-
const ssn = yield* SessionNs.Service
|
|
95
|
-
const msg = yield* ssn.updateMessage({
|
|
96
|
-
id: MessageID.ascending(),
|
|
97
|
-
role: "user",
|
|
98
|
-
sessionID,
|
|
99
|
-
agent: "build",
|
|
100
|
-
model: ref,
|
|
101
|
-
time: { created: Date.now() },
|
|
102
|
-
})
|
|
103
|
-
yield* ssn.updatePart({
|
|
104
|
-
id: PartID.ascending(),
|
|
105
|
-
messageID: msg.id,
|
|
106
|
-
sessionID,
|
|
107
|
-
type: "text",
|
|
108
|
-
text,
|
|
109
|
-
})
|
|
110
|
-
return msg
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function createAssistantMessage(sessionID: SessionID, parentID: MessageID, root: string) {
|
|
115
|
-
return SessionNs.Service.use((ssn) =>
|
|
116
|
-
ssn.updateMessage({
|
|
117
|
-
id: MessageID.ascending(),
|
|
118
|
-
role: "assistant",
|
|
119
|
-
sessionID,
|
|
120
|
-
mode: "build",
|
|
121
|
-
agent: "build",
|
|
122
|
-
path: { cwd: root, root },
|
|
123
|
-
cost: 0,
|
|
124
|
-
tokens: {
|
|
125
|
-
output: 0,
|
|
126
|
-
input: 0,
|
|
127
|
-
reasoning: 0,
|
|
128
|
-
cache: { read: 0, write: 0 },
|
|
129
|
-
},
|
|
130
|
-
modelID: ref.modelID,
|
|
131
|
-
providerID: ref.providerID,
|
|
132
|
-
parentID,
|
|
133
|
-
time: { created: Date.now() },
|
|
134
|
-
finish: "end_turn",
|
|
135
|
-
}),
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function createSummaryAssistantMessage(sessionID: SessionID, parentID: MessageID, root: string, text: string) {
|
|
140
|
-
return SessionNs.Service.use((ssn) =>
|
|
141
|
-
Effect.gen(function* () {
|
|
142
|
-
const msg = yield* ssn.updateMessage({
|
|
143
|
-
id: MessageID.ascending(),
|
|
144
|
-
role: "assistant",
|
|
145
|
-
sessionID,
|
|
146
|
-
mode: "compaction",
|
|
147
|
-
agent: "compaction",
|
|
148
|
-
path: { cwd: root, root },
|
|
149
|
-
cost: 0,
|
|
150
|
-
tokens: {
|
|
151
|
-
output: 0,
|
|
152
|
-
input: 0,
|
|
153
|
-
reasoning: 0,
|
|
154
|
-
cache: { read: 0, write: 0 },
|
|
155
|
-
},
|
|
156
|
-
modelID: ref.modelID,
|
|
157
|
-
providerID: ref.providerID,
|
|
158
|
-
parentID,
|
|
159
|
-
summary: true,
|
|
160
|
-
time: { created: Date.now() },
|
|
161
|
-
finish: "end_turn",
|
|
162
|
-
})
|
|
163
|
-
yield* ssn.updatePart({
|
|
164
|
-
id: PartID.ascending(),
|
|
165
|
-
messageID: msg.id,
|
|
166
|
-
sessionID,
|
|
167
|
-
type: "text",
|
|
168
|
-
text,
|
|
169
|
-
})
|
|
170
|
-
return msg
|
|
171
|
-
}),
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function createCompactionMarker(sessionID: SessionID) {
|
|
176
|
-
return SessionNs.Service.use((ssn) =>
|
|
177
|
-
Effect.gen(function* () {
|
|
178
|
-
const msg = yield* ssn.updateMessage({
|
|
179
|
-
id: MessageID.ascending(),
|
|
180
|
-
role: "user",
|
|
181
|
-
model: ref,
|
|
182
|
-
sessionID,
|
|
183
|
-
agent: "build",
|
|
184
|
-
time: { created: Date.now() },
|
|
185
|
-
})
|
|
186
|
-
yield* ssn.updatePart({
|
|
187
|
-
id: PartID.ascending(),
|
|
188
|
-
messageID: msg.id,
|
|
189
|
-
sessionID: msg.sessionID,
|
|
190
|
-
type: "compaction",
|
|
191
|
-
auto: false,
|
|
192
|
-
})
|
|
193
|
-
}),
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function fake(
|
|
198
|
-
input: Parameters<SessionProcessorModule.SessionProcessor.Interface["create"]>[0],
|
|
199
|
-
result: "continue" | "compact",
|
|
200
|
-
) {
|
|
201
|
-
const msg = input.assistantMessage
|
|
202
|
-
return {
|
|
203
|
-
get message() {
|
|
204
|
-
return msg
|
|
205
|
-
},
|
|
206
|
-
updateToolCall: Effect.fn("TestSessionProcessor.updateToolCall")(() => Effect.succeed(undefined)),
|
|
207
|
-
completeToolCall: Effect.fn("TestSessionProcessor.completeToolCall")(() => Effect.void),
|
|
208
|
-
process: Effect.fn("TestSessionProcessor.process")(() => Effect.succeed(result)),
|
|
209
|
-
} satisfies SessionProcessorModule.SessionProcessor.Handle
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function layer(result: "continue" | "compact") {
|
|
213
|
-
return Layer.succeed(
|
|
214
|
-
SessionProcessorModule.SessionProcessor.Service,
|
|
215
|
-
SessionProcessorModule.SessionProcessor.Service.of({
|
|
216
|
-
create: Effect.fn("TestSessionProcessor.create")((input) => Effect.succeed(fake(input, result))),
|
|
217
|
-
}),
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function cfg(compaction?: ConfigV1.Info["compaction"]) {
|
|
222
|
-
const base = Schema.decodeUnknownSync(ConfigV1.Info)({}) as ConfigV1.Info
|
|
223
|
-
return TestConfig.layer({
|
|
224
|
-
get: () => Effect.succeed({ ...base, compaction }),
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const deps = Layer.mergeAll(
|
|
229
|
-
wide().layer,
|
|
230
|
-
layer("continue"),
|
|
231
|
-
Agent.defaultLayer,
|
|
232
|
-
Plugin.defaultLayer,
|
|
233
|
-
EventV2Bridge.defaultLayer,
|
|
234
|
-
Config.defaultLayer,
|
|
235
|
-
RuntimeFlags.layer({ experimentalEventSystem: true }),
|
|
236
|
-
Database.defaultLayer,
|
|
237
|
-
EventV2Bridge.defaultLayer,
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
const env = Layer.mergeAll(
|
|
241
|
-
SessionNs.defaultLayer,
|
|
242
|
-
Database.defaultLayer,
|
|
243
|
-
EventV2Bridge.defaultLayer,
|
|
244
|
-
CrossSpawnSpawner.defaultLayer,
|
|
245
|
-
SessionCompaction.layer.pipe(Layer.provide(SessionNs.defaultLayer), Layer.provideMerge(deps)),
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
const it = testEffect(env)
|
|
249
|
-
|
|
250
|
-
const compactionEnv = Layer.mergeAll(
|
|
251
|
-
SessionNs.defaultLayer,
|
|
252
|
-
Database.defaultLayer,
|
|
253
|
-
EventV2Bridge.defaultLayer,
|
|
254
|
-
CrossSpawnSpawner.defaultLayer,
|
|
255
|
-
)
|
|
256
|
-
const itCompaction = testEffect(compactionEnv)
|
|
257
|
-
|
|
258
|
-
type CompactionProcessOptions = {
|
|
259
|
-
result?: "continue" | "compact"
|
|
260
|
-
llm?: Layer.Layer<LLM.Service>
|
|
261
|
-
plugin?: Layer.Layer<Plugin.Service>
|
|
262
|
-
provider?: ReturnType<typeof ProviderTest.fake>
|
|
263
|
-
config?: Layer.Layer<Config.Service>
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function withCompaction(options?: CompactionProcessOptions) {
|
|
267
|
-
return Effect.provide(compactionProcessLayer(options))
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function compactionProcessLayer(options?: CompactionProcessOptions) {
|
|
271
|
-
const events = EventV2Bridge.defaultLayer
|
|
272
|
-
const status = SessionStatus.layer.pipe(Layer.provide(events))
|
|
273
|
-
const processor = options?.llm
|
|
274
|
-
? SessionProcessorModule.SessionProcessor.layer.pipe(
|
|
275
|
-
Layer.provide(summary),
|
|
276
|
-
Layer.provide(Image.defaultLayer),
|
|
277
|
-
Layer.provide(RuntimeFlags.layer({ experimentalEventSystem: true })),
|
|
278
|
-
Layer.provide(status),
|
|
279
|
-
)
|
|
280
|
-
: layer(options?.result ?? "continue")
|
|
281
|
-
return Layer.mergeAll(SessionCompaction.layer.pipe(Layer.provide(processor)), processor, events, status).pipe(
|
|
282
|
-
Layer.provide(SessionNs.defaultLayer),
|
|
283
|
-
Layer.provide((options?.provider ?? wide()).layer),
|
|
284
|
-
Layer.provide(Snapshot.defaultLayer),
|
|
285
|
-
Layer.provide(options?.llm ?? LLM.defaultLayer),
|
|
286
|
-
Layer.provide(Permission.defaultLayer),
|
|
287
|
-
Layer.provide(Agent.defaultLayer),
|
|
288
|
-
Layer.provide(options?.plugin ?? Plugin.defaultLayer),
|
|
289
|
-
Layer.provide(status),
|
|
290
|
-
Layer.provide(events),
|
|
291
|
-
Layer.provide(options?.config ?? Config.defaultLayer),
|
|
292
|
-
Layer.provide(RuntimeFlags.layer({ experimentalEventSystem: true })),
|
|
293
|
-
Layer.provide(EventV2Bridge.defaultLayer),
|
|
294
|
-
)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function createSummaryCompaction(sessionID: SessionID) {
|
|
298
|
-
return SessionCompaction.use.create({ sessionID, agent: "build", model: ref, auto: false })
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function readCompactionPart(sessionID: SessionID) {
|
|
302
|
-
return SessionNs.use
|
|
303
|
-
.messages({ sessionID })
|
|
304
|
-
.pipe(
|
|
305
|
-
Effect.map((messages) =>
|
|
306
|
-
messages.at(-2)?.parts.find((item): item is SessionV1.CompactionPart => item.type === "compaction"),
|
|
307
|
-
),
|
|
308
|
-
)
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function llm() {
|
|
312
|
-
const queue: Array<
|
|
313
|
-
Stream.Stream<LLMEvent, unknown> | ((input: LLM.StreamInput) => Stream.Stream<LLMEvent, unknown>)
|
|
314
|
-
> = []
|
|
315
|
-
|
|
316
|
-
return {
|
|
317
|
-
push(stream: Stream.Stream<LLMEvent, unknown> | ((input: LLM.StreamInput) => Stream.Stream<LLMEvent, unknown>)) {
|
|
318
|
-
queue.push(stream)
|
|
319
|
-
},
|
|
320
|
-
layer: Layer.succeed(
|
|
321
|
-
LLM.Service,
|
|
322
|
-
LLM.Service.of({
|
|
323
|
-
stream: (input) => {
|
|
324
|
-
const item = queue.shift() ?? Stream.empty
|
|
325
|
-
const stream = typeof item === "function" ? item(input) : item
|
|
326
|
-
return stream.pipe(Stream.mapEffect((event) => Effect.succeed(event)))
|
|
327
|
-
},
|
|
328
|
-
}),
|
|
329
|
-
),
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function reply(
|
|
334
|
-
text: string,
|
|
335
|
-
capture?: (input: LLM.StreamInput) => void,
|
|
336
|
-
): (input: LLM.StreamInput) => Stream.Stream<LLMEvent, unknown> {
|
|
337
|
-
return (input) => {
|
|
338
|
-
capture?.(input)
|
|
339
|
-
return Stream.make(
|
|
340
|
-
LLMEvent.textStart({ id: "txt-0" }),
|
|
341
|
-
LLMEvent.textDelta({ id: "txt-0", text }),
|
|
342
|
-
LLMEvent.textEnd({ id: "txt-0" }),
|
|
343
|
-
LLMEvent.stepFinish({
|
|
344
|
-
index: 0,
|
|
345
|
-
reason: "stop",
|
|
346
|
-
usage: basicUsage(),
|
|
347
|
-
}),
|
|
348
|
-
LLMEvent.finish({
|
|
349
|
-
reason: "stop",
|
|
350
|
-
usage: basicUsage(),
|
|
351
|
-
}),
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function plugin(ready: Deferred.Deferred<void>) {
|
|
357
|
-
return Layer.mock(Plugin.Service)({
|
|
358
|
-
trigger: <Name extends string, Input, Output>(name: Name, _input: Input, output: Output) => {
|
|
359
|
-
if (name !== "experimental.session.compacting") return Effect.succeed(output)
|
|
360
|
-
return Effect.sync(() => Deferred.doneUnsafe(ready, Effect.void)).pipe(
|
|
361
|
-
Effect.andThen(Effect.never),
|
|
362
|
-
Effect.as(output),
|
|
363
|
-
)
|
|
364
|
-
},
|
|
365
|
-
list: () => Effect.succeed([]),
|
|
366
|
-
init: () => Effect.void,
|
|
367
|
-
})
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function autocontinue(enabled: boolean) {
|
|
371
|
-
return Layer.mock(Plugin.Service)({
|
|
372
|
-
trigger: <Name extends string, Input, Output>(name: Name, _input: Input, output: Output) => {
|
|
373
|
-
if (name !== "experimental.compaction.autocontinue") return Effect.succeed(output)
|
|
374
|
-
return Effect.sync(() => {
|
|
375
|
-
;(output as { enabled: boolean }).enabled = enabled
|
|
376
|
-
return output
|
|
377
|
-
})
|
|
378
|
-
},
|
|
379
|
-
list: () => Effect.succeed([]),
|
|
380
|
-
init: () => Effect.void,
|
|
381
|
-
})
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
describe("session.compaction.isOverflow", () => {
|
|
385
|
-
it.live(
|
|
386
|
-
"returns true when token count exceeds usable context",
|
|
387
|
-
provideTmpdirInstance(() =>
|
|
388
|
-
Effect.gen(function* () {
|
|
389
|
-
const compact = yield* SessionCompaction.Service
|
|
390
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
391
|
-
const tokens = { input: 75_000, output: 5_000, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
392
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(true)
|
|
393
|
-
}),
|
|
394
|
-
),
|
|
395
|
-
)
|
|
396
|
-
|
|
397
|
-
it.live(
|
|
398
|
-
"returns false when token count within usable context",
|
|
399
|
-
provideTmpdirInstance(() =>
|
|
400
|
-
Effect.gen(function* () {
|
|
401
|
-
const compact = yield* SessionCompaction.Service
|
|
402
|
-
const model = createModel({ context: 200_000, output: 32_000 })
|
|
403
|
-
const tokens = { input: 100_000, output: 10_000, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
404
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
|
|
405
|
-
}),
|
|
406
|
-
),
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
it.live(
|
|
410
|
-
"includes cache.read in token count",
|
|
411
|
-
provideTmpdirInstance(() =>
|
|
412
|
-
Effect.gen(function* () {
|
|
413
|
-
const compact = yield* SessionCompaction.Service
|
|
414
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
415
|
-
const tokens = { input: 60_000, output: 10_000, reasoning: 0, cache: { read: 10_000, write: 0 } }
|
|
416
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(true)
|
|
417
|
-
}),
|
|
418
|
-
),
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
it.live(
|
|
422
|
-
"respects input limit for input caps",
|
|
423
|
-
provideTmpdirInstance(() =>
|
|
424
|
-
Effect.gen(function* () {
|
|
425
|
-
const compact = yield* SessionCompaction.Service
|
|
426
|
-
const model = createModel({ context: 400_000, input: 272_000, output: 128_000 })
|
|
427
|
-
const tokens = { input: 271_000, output: 1_000, reasoning: 0, cache: { read: 2_000, write: 0 } }
|
|
428
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(true)
|
|
429
|
-
}),
|
|
430
|
-
),
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
it.live(
|
|
434
|
-
"returns false when input/output are within input caps",
|
|
435
|
-
provideTmpdirInstance(() =>
|
|
436
|
-
Effect.gen(function* () {
|
|
437
|
-
const compact = yield* SessionCompaction.Service
|
|
438
|
-
const model = createModel({ context: 400_000, input: 272_000, output: 128_000 })
|
|
439
|
-
const tokens = { input: 200_000, output: 20_000, reasoning: 0, cache: { read: 10_000, write: 0 } }
|
|
440
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
|
|
441
|
-
}),
|
|
442
|
-
),
|
|
443
|
-
)
|
|
444
|
-
|
|
445
|
-
it.live(
|
|
446
|
-
"returns false when output within limit with input caps",
|
|
447
|
-
provideTmpdirInstance(() =>
|
|
448
|
-
Effect.gen(function* () {
|
|
449
|
-
const compact = yield* SessionCompaction.Service
|
|
450
|
-
const model = createModel({ context: 200_000, input: 120_000, output: 10_000 })
|
|
451
|
-
const tokens = { input: 50_000, output: 9_999, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
452
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
|
|
453
|
-
}),
|
|
454
|
-
),
|
|
455
|
-
)
|
|
456
|
-
|
|
457
|
-
// ─── Bug reproduction tests ───────────────────────────────────────────
|
|
458
|
-
// These tests demonstrate that when limit.input is set, isOverflow()
|
|
459
|
-
// does not subtract any headroom for the next model response. This means
|
|
460
|
-
// compaction only triggers AFTER we've already consumed the full input
|
|
461
|
-
// budget, leaving zero room for the next API call's output tokens.
|
|
462
|
-
//
|
|
463
|
-
// Compare: without limit.input, usable = context - output (reserves space).
|
|
464
|
-
// With limit.input, usable = limit.input (reserves nothing).
|
|
465
|
-
//
|
|
466
|
-
// Related issues: #10634, #8089, #11086, #12621
|
|
467
|
-
// Open PRs: #6875, #12924
|
|
468
|
-
|
|
469
|
-
it.live(
|
|
470
|
-
"BUG: no headroom when limit.input is set — compaction should trigger near boundary but does not",
|
|
471
|
-
provideTmpdirInstance(() =>
|
|
472
|
-
Effect.gen(function* () {
|
|
473
|
-
const compact = yield* SessionCompaction.Service
|
|
474
|
-
// Simulate Claude with prompt caching: input limit = 200K, output limit = 32K
|
|
475
|
-
const model = createModel({ context: 200_000, input: 200_000, output: 32_000 })
|
|
476
|
-
|
|
477
|
-
// We've used 198K tokens total. Only 2K under the input limit.
|
|
478
|
-
// On the next turn, the full conversation (198K) becomes input,
|
|
479
|
-
// plus the model needs room to generate output — this WILL overflow.
|
|
480
|
-
const tokens = { input: 180_000, output: 15_000, reasoning: 0, cache: { read: 3_000, write: 0 } }
|
|
481
|
-
// count = 180K + 3K + 15K = 198K
|
|
482
|
-
// usable = limit.input = 200K (no output subtracted!)
|
|
483
|
-
// 198K > 200K = false → no compaction triggered
|
|
484
|
-
|
|
485
|
-
// WITHOUT limit.input: usable = 200K - 32K = 168K, and 198K > 168K = true ✓
|
|
486
|
-
// WITH limit.input: usable = 200K, and 198K > 200K = false ✗
|
|
487
|
-
|
|
488
|
-
// With 198K used and only 2K headroom, the next turn will overflow.
|
|
489
|
-
// Compaction MUST trigger here.
|
|
490
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(true)
|
|
491
|
-
}),
|
|
492
|
-
),
|
|
493
|
-
)
|
|
494
|
-
|
|
495
|
-
it.live(
|
|
496
|
-
"BUG: without limit.input, same token count correctly triggers compaction",
|
|
497
|
-
provideTmpdirInstance(() =>
|
|
498
|
-
Effect.gen(function* () {
|
|
499
|
-
const compact = yield* SessionCompaction.Service
|
|
500
|
-
// Same model but without limit.input — uses context - output instead
|
|
501
|
-
const model = createModel({ context: 200_000, output: 32_000 })
|
|
502
|
-
|
|
503
|
-
// Same token usage as above
|
|
504
|
-
const tokens = { input: 180_000, output: 15_000, reasoning: 0, cache: { read: 3_000, write: 0 } }
|
|
505
|
-
// count = 198K
|
|
506
|
-
// usable = context - output = 200K - 32K = 168K
|
|
507
|
-
// 198K > 168K = true → compaction correctly triggered
|
|
508
|
-
|
|
509
|
-
const result = yield* compact.isOverflow({ tokens, model })
|
|
510
|
-
expect(result).toBe(true) // ← Correct: headroom is reserved
|
|
511
|
-
}),
|
|
512
|
-
),
|
|
513
|
-
)
|
|
514
|
-
|
|
515
|
-
it.live(
|
|
516
|
-
"BUG: asymmetry — limit.input model allows 30K more usage before compaction than equivalent model without it",
|
|
517
|
-
provideTmpdirInstance(() =>
|
|
518
|
-
Effect.gen(function* () {
|
|
519
|
-
const compact = yield* SessionCompaction.Service
|
|
520
|
-
// Two models with identical context/output limits, differing only in limit.input
|
|
521
|
-
const withInputLimit = createModel({ context: 200_000, input: 200_000, output: 32_000 })
|
|
522
|
-
const withoutInputLimit = createModel({ context: 200_000, output: 32_000 })
|
|
523
|
-
|
|
524
|
-
// 170K total tokens — well above context-output (168K) but below input limit (200K)
|
|
525
|
-
const tokens = { input: 166_000, output: 10_000, reasoning: 0, cache: { read: 5_000, write: 0 } }
|
|
526
|
-
|
|
527
|
-
const withLimit = yield* compact.isOverflow({ tokens, model: withInputLimit })
|
|
528
|
-
const withoutLimit = yield* compact.isOverflow({ tokens, model: withoutInputLimit })
|
|
529
|
-
|
|
530
|
-
// Both models have identical real capacity — they should agree:
|
|
531
|
-
expect(withLimit).toBe(true) // should compact (170K leaves no room for 32K output)
|
|
532
|
-
expect(withoutLimit).toBe(true) // correctly compacts (170K > 168K)
|
|
533
|
-
}),
|
|
534
|
-
),
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
it.live(
|
|
538
|
-
"returns false when model context limit is 0",
|
|
539
|
-
provideTmpdirInstance(() =>
|
|
540
|
-
Effect.gen(function* () {
|
|
541
|
-
const compact = yield* SessionCompaction.Service
|
|
542
|
-
const model = createModel({ context: 0, output: 32_000 })
|
|
543
|
-
const tokens = { input: 100_000, output: 10_000, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
544
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
|
|
545
|
-
}),
|
|
546
|
-
),
|
|
547
|
-
)
|
|
548
|
-
|
|
549
|
-
it.live(
|
|
550
|
-
"returns false when compaction.auto is disabled",
|
|
551
|
-
provideTmpdirInstance(
|
|
552
|
-
() =>
|
|
553
|
-
Effect.gen(function* () {
|
|
554
|
-
const compact = yield* SessionCompaction.Service
|
|
555
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
556
|
-
const tokens = { input: 75_000, output: 5_000, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
557
|
-
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
|
|
558
|
-
}),
|
|
559
|
-
{
|
|
560
|
-
config: {
|
|
561
|
-
compaction: { auto: false },
|
|
562
|
-
},
|
|
563
|
-
},
|
|
564
|
-
),
|
|
565
|
-
)
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
describe("session.compaction.create", () => {
|
|
569
|
-
it.live(
|
|
570
|
-
"creates a compaction user message and part",
|
|
571
|
-
provideTmpdirInstance(() =>
|
|
572
|
-
Effect.gen(function* () {
|
|
573
|
-
const compact = yield* SessionCompaction.Service
|
|
574
|
-
const ssn = yield* SessionNs.Service
|
|
575
|
-
|
|
576
|
-
const info = yield* ssn.create({})
|
|
577
|
-
|
|
578
|
-
yield* compact.create({
|
|
579
|
-
sessionID: info.id,
|
|
580
|
-
agent: "build",
|
|
581
|
-
model: ref,
|
|
582
|
-
auto: true,
|
|
583
|
-
overflow: true,
|
|
584
|
-
})
|
|
585
|
-
|
|
586
|
-
const msgs = yield* ssn.messages({ sessionID: info.id })
|
|
587
|
-
expect(msgs).toHaveLength(1)
|
|
588
|
-
expect(msgs[0].info.role).toBe("user")
|
|
589
|
-
expect(msgs[0].parts).toHaveLength(1)
|
|
590
|
-
expect(msgs[0].parts[0]).toMatchObject({
|
|
591
|
-
type: "compaction",
|
|
592
|
-
auto: true,
|
|
593
|
-
overflow: true,
|
|
594
|
-
})
|
|
595
|
-
}),
|
|
596
|
-
),
|
|
597
|
-
)
|
|
598
|
-
|
|
599
|
-
it.live.skip(
|
|
600
|
-
"projects a compaction message to v2 (v2 projector disabled)",
|
|
601
|
-
provideTmpdirInstance(() =>
|
|
602
|
-
Effect.gen(function* () {
|
|
603
|
-
const compact = yield* SessionCompaction.Service
|
|
604
|
-
const ssn = yield* SessionNs.Service
|
|
605
|
-
const info = yield* ssn.create({})
|
|
606
|
-
|
|
607
|
-
yield* compact.create({
|
|
608
|
-
sessionID: info.id,
|
|
609
|
-
agent: "build",
|
|
610
|
-
model: ref,
|
|
611
|
-
auto: true,
|
|
612
|
-
overflow: true,
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
const v2 = yield* SessionV2.Service.use((svc) => svc.messages({ sessionID: info.id })).pipe(
|
|
616
|
-
Effect.provide(SessionExecution.noopLayer),
|
|
617
|
-
Effect.provide(SessionV2.defaultLayer),
|
|
618
|
-
)
|
|
619
|
-
expect(v2.at(-1)).toMatchObject({
|
|
620
|
-
type: "compaction",
|
|
621
|
-
reason: "auto",
|
|
622
|
-
summary: "",
|
|
623
|
-
})
|
|
624
|
-
}),
|
|
625
|
-
),
|
|
626
|
-
)
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
describe("session.compaction.prune", () => {
|
|
630
|
-
it.live(
|
|
631
|
-
"compacts old completed tool output",
|
|
632
|
-
provideTmpdirInstance(
|
|
633
|
-
(dir) =>
|
|
634
|
-
Effect.gen(function* () {
|
|
635
|
-
const compact = yield* SessionCompaction.Service
|
|
636
|
-
const ssn = yield* SessionNs.Service
|
|
637
|
-
const info = yield* ssn.create({})
|
|
638
|
-
const a = yield* ssn.updateMessage({
|
|
639
|
-
id: MessageID.ascending(),
|
|
640
|
-
role: "user",
|
|
641
|
-
sessionID: info.id,
|
|
642
|
-
agent: "build",
|
|
643
|
-
model: ref,
|
|
644
|
-
time: { created: Date.now() },
|
|
645
|
-
})
|
|
646
|
-
yield* ssn.updatePart({
|
|
647
|
-
id: PartID.ascending(),
|
|
648
|
-
messageID: a.id,
|
|
649
|
-
sessionID: info.id,
|
|
650
|
-
type: "text",
|
|
651
|
-
text: "first",
|
|
652
|
-
})
|
|
653
|
-
const b: SessionV1.Assistant = {
|
|
654
|
-
id: MessageID.ascending(),
|
|
655
|
-
role: "assistant",
|
|
656
|
-
sessionID: info.id,
|
|
657
|
-
mode: "build",
|
|
658
|
-
agent: "build",
|
|
659
|
-
path: { cwd: dir, root: dir },
|
|
660
|
-
cost: 0,
|
|
661
|
-
tokens: {
|
|
662
|
-
output: 0,
|
|
663
|
-
input: 0,
|
|
664
|
-
reasoning: 0,
|
|
665
|
-
cache: { read: 0, write: 0 },
|
|
666
|
-
},
|
|
667
|
-
modelID: ref.modelID,
|
|
668
|
-
providerID: ref.providerID,
|
|
669
|
-
parentID: a.id,
|
|
670
|
-
time: { created: Date.now() },
|
|
671
|
-
finish: "end_turn",
|
|
672
|
-
}
|
|
673
|
-
yield* ssn.updateMessage(b)
|
|
674
|
-
yield* ssn.updatePart({
|
|
675
|
-
id: PartID.ascending(),
|
|
676
|
-
messageID: b.id,
|
|
677
|
-
sessionID: info.id,
|
|
678
|
-
type: "tool",
|
|
679
|
-
callID: crypto.randomUUID(),
|
|
680
|
-
tool: "bash",
|
|
681
|
-
state: {
|
|
682
|
-
status: "completed",
|
|
683
|
-
input: {},
|
|
684
|
-
output: "x".repeat(200_000),
|
|
685
|
-
title: "done",
|
|
686
|
-
metadata: {},
|
|
687
|
-
time: { start: Date.now(), end: Date.now() },
|
|
688
|
-
},
|
|
689
|
-
})
|
|
690
|
-
for (const text of ["second", "third"]) {
|
|
691
|
-
const msg = yield* ssn.updateMessage({
|
|
692
|
-
id: MessageID.ascending(),
|
|
693
|
-
role: "user",
|
|
694
|
-
sessionID: info.id,
|
|
695
|
-
agent: "build",
|
|
696
|
-
model: ref,
|
|
697
|
-
time: { created: Date.now() },
|
|
698
|
-
})
|
|
699
|
-
yield* ssn.updatePart({
|
|
700
|
-
id: PartID.ascending(),
|
|
701
|
-
messageID: msg.id,
|
|
702
|
-
sessionID: info.id,
|
|
703
|
-
type: "text",
|
|
704
|
-
text,
|
|
705
|
-
})
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
yield* compact.prune({ sessionID: info.id })
|
|
709
|
-
|
|
710
|
-
const msgs = yield* ssn.messages({ sessionID: info.id })
|
|
711
|
-
const part = msgs.flatMap((msg) => msg.parts).find((part) => part.type === "tool")
|
|
712
|
-
expect(part?.type).toBe("tool")
|
|
713
|
-
expect(part?.state.status).toBe("completed")
|
|
714
|
-
if (part?.type === "tool" && part.state.status === "completed") {
|
|
715
|
-
expect(part.state.time.compacted).toBeNumber()
|
|
716
|
-
}
|
|
717
|
-
}),
|
|
718
|
-
|
|
719
|
-
{
|
|
720
|
-
config: {
|
|
721
|
-
compaction: { prune: true },
|
|
722
|
-
},
|
|
723
|
-
},
|
|
724
|
-
),
|
|
725
|
-
)
|
|
726
|
-
|
|
727
|
-
it.live(
|
|
728
|
-
"skips protected skill tool output",
|
|
729
|
-
provideTmpdirInstance((dir) =>
|
|
730
|
-
Effect.gen(function* () {
|
|
731
|
-
const compact = yield* SessionCompaction.Service
|
|
732
|
-
const ssn = yield* SessionNs.Service
|
|
733
|
-
const info = yield* ssn.create({})
|
|
734
|
-
const a = yield* ssn.updateMessage({
|
|
735
|
-
id: MessageID.ascending(),
|
|
736
|
-
role: "user",
|
|
737
|
-
sessionID: info.id,
|
|
738
|
-
agent: "build",
|
|
739
|
-
model: ref,
|
|
740
|
-
time: { created: Date.now() },
|
|
741
|
-
})
|
|
742
|
-
yield* ssn.updatePart({
|
|
743
|
-
id: PartID.ascending(),
|
|
744
|
-
messageID: a.id,
|
|
745
|
-
sessionID: info.id,
|
|
746
|
-
type: "text",
|
|
747
|
-
text: "first",
|
|
748
|
-
})
|
|
749
|
-
const b: SessionV1.Assistant = {
|
|
750
|
-
id: MessageID.ascending(),
|
|
751
|
-
role: "assistant",
|
|
752
|
-
sessionID: info.id,
|
|
753
|
-
mode: "build",
|
|
754
|
-
agent: "build",
|
|
755
|
-
path: { cwd: dir, root: dir },
|
|
756
|
-
cost: 0,
|
|
757
|
-
tokens: {
|
|
758
|
-
output: 0,
|
|
759
|
-
input: 0,
|
|
760
|
-
reasoning: 0,
|
|
761
|
-
cache: { read: 0, write: 0 },
|
|
762
|
-
},
|
|
763
|
-
modelID: ref.modelID,
|
|
764
|
-
providerID: ref.providerID,
|
|
765
|
-
parentID: a.id,
|
|
766
|
-
time: { created: Date.now() },
|
|
767
|
-
finish: "end_turn",
|
|
768
|
-
}
|
|
769
|
-
yield* ssn.updateMessage(b)
|
|
770
|
-
yield* ssn.updatePart({
|
|
771
|
-
id: PartID.ascending(),
|
|
772
|
-
messageID: b.id,
|
|
773
|
-
sessionID: info.id,
|
|
774
|
-
type: "tool",
|
|
775
|
-
callID: crypto.randomUUID(),
|
|
776
|
-
tool: "skill",
|
|
777
|
-
state: {
|
|
778
|
-
status: "completed",
|
|
779
|
-
input: {},
|
|
780
|
-
output: "x".repeat(200_000),
|
|
781
|
-
title: "done",
|
|
782
|
-
metadata: {},
|
|
783
|
-
time: { start: Date.now(), end: Date.now() },
|
|
784
|
-
},
|
|
785
|
-
})
|
|
786
|
-
for (const text of ["second", "third"]) {
|
|
787
|
-
const msg = yield* ssn.updateMessage({
|
|
788
|
-
id: MessageID.ascending(),
|
|
789
|
-
role: "user",
|
|
790
|
-
sessionID: info.id,
|
|
791
|
-
agent: "build",
|
|
792
|
-
model: ref,
|
|
793
|
-
time: { created: Date.now() },
|
|
794
|
-
})
|
|
795
|
-
yield* ssn.updatePart({
|
|
796
|
-
id: PartID.ascending(),
|
|
797
|
-
messageID: msg.id,
|
|
798
|
-
sessionID: info.id,
|
|
799
|
-
type: "text",
|
|
800
|
-
text,
|
|
801
|
-
})
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
yield* compact.prune({ sessionID: info.id })
|
|
805
|
-
|
|
806
|
-
const msgs = yield* ssn.messages({ sessionID: info.id })
|
|
807
|
-
const part = msgs.flatMap((msg) => msg.parts).find((part) => part.type === "tool")
|
|
808
|
-
expect(part?.type).toBe("tool")
|
|
809
|
-
if (part?.type === "tool" && part.state.status === "completed") {
|
|
810
|
-
expect(part.state.time.compacted).toBeUndefined()
|
|
811
|
-
}
|
|
812
|
-
}),
|
|
813
|
-
),
|
|
814
|
-
)
|
|
815
|
-
})
|
|
816
|
-
|
|
817
|
-
describe("session.compaction.process", () => {
|
|
818
|
-
it.instance(
|
|
819
|
-
"throws when parent is not a user message",
|
|
820
|
-
Effect.gen(function* () {
|
|
821
|
-
const test = yield* TestInstance
|
|
822
|
-
const ssn = yield* SessionNs.Service
|
|
823
|
-
const session = yield* ssn.create({})
|
|
824
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
825
|
-
const reply = yield* createAssistantMessage(session.id, msg.id, test.directory)
|
|
826
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
827
|
-
|
|
828
|
-
const exit = yield* Effect.exit(
|
|
829
|
-
SessionCompaction.use.process({
|
|
830
|
-
parentID: reply.id,
|
|
831
|
-
messages: msgs,
|
|
832
|
-
sessionID: session.id,
|
|
833
|
-
auto: false,
|
|
834
|
-
}),
|
|
835
|
-
)
|
|
836
|
-
|
|
837
|
-
expect(Exit.isFailure(exit)).toBe(true)
|
|
838
|
-
if (Exit.isFailure(exit)) {
|
|
839
|
-
const error = Cause.squash(exit.cause)
|
|
840
|
-
expect(error).toBeInstanceOf(Error)
|
|
841
|
-
if (error instanceof Error) {
|
|
842
|
-
expect(error.message).toContain(`Compaction parent must be a user message: ${reply.id}`)
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}),
|
|
846
|
-
)
|
|
847
|
-
|
|
848
|
-
it.instance(
|
|
849
|
-
"publishes compacted event on continue",
|
|
850
|
-
Effect.gen(function* () {
|
|
851
|
-
const events = yield* EventV2Bridge.Service
|
|
852
|
-
const ssn = yield* SessionNs.Service
|
|
853
|
-
const session = yield* ssn.create({})
|
|
854
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
855
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
856
|
-
const done = yield* Deferred.make<void, Error>()
|
|
857
|
-
let seen = false
|
|
858
|
-
const unsub = yield* events.listen((evt) => {
|
|
859
|
-
if (evt.type !== SessionCompaction.Event.Compacted.type) return Effect.void
|
|
860
|
-
if ((evt.data as typeof SessionCompaction.Event.Compacted.data.Type).sessionID !== session.id)
|
|
861
|
-
return Effect.void
|
|
862
|
-
seen = true
|
|
863
|
-
Deferred.doneUnsafe(done, Effect.void)
|
|
864
|
-
return Effect.void
|
|
865
|
-
})
|
|
866
|
-
yield* Effect.addFinalizer(() => unsub)
|
|
867
|
-
|
|
868
|
-
const result = yield* SessionCompaction.use.process({
|
|
869
|
-
parentID: msg.id,
|
|
870
|
-
messages: msgs,
|
|
871
|
-
sessionID: session.id,
|
|
872
|
-
auto: false,
|
|
873
|
-
})
|
|
874
|
-
|
|
875
|
-
yield* Deferred.await(done).pipe(Effect.timeout("500 millis"))
|
|
876
|
-
expect(result).toBe("continue")
|
|
877
|
-
expect(seen).toBe(true)
|
|
878
|
-
}),
|
|
879
|
-
)
|
|
880
|
-
|
|
881
|
-
itCompaction.instance(
|
|
882
|
-
"marks summary message as errored on compact result",
|
|
883
|
-
Effect.gen(function* () {
|
|
884
|
-
const ssn = yield* SessionNs.Service
|
|
885
|
-
const session = yield* ssn.create({})
|
|
886
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
887
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
888
|
-
|
|
889
|
-
const result = yield* SessionCompaction.use.process({
|
|
890
|
-
parentID: msg.id,
|
|
891
|
-
messages: msgs,
|
|
892
|
-
sessionID: session.id,
|
|
893
|
-
auto: false,
|
|
894
|
-
})
|
|
895
|
-
|
|
896
|
-
const summary = (yield* ssn.messages({ sessionID: session.id })).find(
|
|
897
|
-
(msg) => msg.info.role === "assistant" && msg.info.summary,
|
|
898
|
-
)
|
|
899
|
-
|
|
900
|
-
expect(result).toBe("stop")
|
|
901
|
-
expect(summary?.info.role).toBe("assistant")
|
|
902
|
-
if (summary?.info.role === "assistant") {
|
|
903
|
-
expect(summary.info.finish).toBe("error")
|
|
904
|
-
expect(JSON.stringify(summary.info.error)).toContain("Session too large to compact")
|
|
905
|
-
}
|
|
906
|
-
}).pipe(withCompaction({ result: "compact" })),
|
|
907
|
-
)
|
|
908
|
-
|
|
909
|
-
it.instance(
|
|
910
|
-
"adds synthetic continue prompt when auto is enabled",
|
|
911
|
-
Effect.gen(function* () {
|
|
912
|
-
const ssn = yield* SessionNs.Service
|
|
913
|
-
const session = yield* ssn.create({})
|
|
914
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
915
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
916
|
-
|
|
917
|
-
const result = yield* SessionCompaction.use.process({
|
|
918
|
-
parentID: msg.id,
|
|
919
|
-
messages: msgs,
|
|
920
|
-
sessionID: session.id,
|
|
921
|
-
auto: true,
|
|
922
|
-
})
|
|
923
|
-
|
|
924
|
-
const all = yield* ssn.messages({ sessionID: session.id })
|
|
925
|
-
const last = all.at(-1)
|
|
926
|
-
|
|
927
|
-
expect(result).toBe("continue")
|
|
928
|
-
expect(last?.info.role).toBe("user")
|
|
929
|
-
expect(last?.parts[0]).toMatchObject({
|
|
930
|
-
type: "text",
|
|
931
|
-
synthetic: true,
|
|
932
|
-
metadata: { compaction_continue: true },
|
|
933
|
-
})
|
|
934
|
-
if (last?.parts[0]?.type === "text") {
|
|
935
|
-
expect(last.parts[0].text).toContain("Continue if you have next steps")
|
|
936
|
-
}
|
|
937
|
-
}),
|
|
938
|
-
)
|
|
939
|
-
|
|
940
|
-
itCompaction.instance(
|
|
941
|
-
"persists tail_start_id for retained recent turns",
|
|
942
|
-
Effect.gen(function* () {
|
|
943
|
-
const ssn = yield* SessionNs.Service
|
|
944
|
-
const session = yield* ssn.create({})
|
|
945
|
-
yield* createUserMessage(session.id, "first")
|
|
946
|
-
const keep = yield* createUserMessage(session.id, "second")
|
|
947
|
-
yield* createUserMessage(session.id, "third")
|
|
948
|
-
yield* createSummaryCompaction(session.id)
|
|
949
|
-
|
|
950
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
951
|
-
const parent = msgs.at(-1)?.info.id
|
|
952
|
-
expect(parent).toBeTruthy()
|
|
953
|
-
yield* SessionCompaction.use.process({
|
|
954
|
-
parentID: parent!,
|
|
955
|
-
messages: msgs,
|
|
956
|
-
sessionID: session.id,
|
|
957
|
-
auto: false,
|
|
958
|
-
})
|
|
959
|
-
|
|
960
|
-
const part = yield* readCompactionPart(session.id)
|
|
961
|
-
expect(part?.type).toBe("compaction")
|
|
962
|
-
expect(part?.tail_start_id).toBe(keep.id)
|
|
963
|
-
}).pipe(withCompaction({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) })),
|
|
964
|
-
)
|
|
965
|
-
|
|
966
|
-
itCompaction.instance(
|
|
967
|
-
"shrinks retained tail to fit preserve token budget",
|
|
968
|
-
Effect.gen(function* () {
|
|
969
|
-
const ssn = yield* SessionNs.Service
|
|
970
|
-
const session = yield* ssn.create({})
|
|
971
|
-
yield* createUserMessage(session.id, "first")
|
|
972
|
-
yield* createUserMessage(session.id, "x".repeat(2_000))
|
|
973
|
-
const keep = yield* createUserMessage(session.id, "tiny")
|
|
974
|
-
yield* createSummaryCompaction(session.id)
|
|
975
|
-
|
|
976
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
977
|
-
const parent = msgs.at(-1)?.info.id
|
|
978
|
-
expect(parent).toBeTruthy()
|
|
979
|
-
yield* SessionCompaction.use.process({
|
|
980
|
-
parentID: parent!,
|
|
981
|
-
messages: msgs,
|
|
982
|
-
sessionID: session.id,
|
|
983
|
-
auto: false,
|
|
984
|
-
})
|
|
985
|
-
|
|
986
|
-
const part = yield* readCompactionPart(session.id)
|
|
987
|
-
expect(part?.type).toBe("compaction")
|
|
988
|
-
expect(part?.tail_start_id).toBe(keep.id)
|
|
989
|
-
}).pipe(withCompaction({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 100 }) })),
|
|
990
|
-
)
|
|
991
|
-
|
|
992
|
-
itCompaction.instance(
|
|
993
|
-
"falls back to full summary when even one recent turn exceeds preserve token budget",
|
|
994
|
-
() => {
|
|
995
|
-
const stub = llm()
|
|
996
|
-
let captured = ""
|
|
997
|
-
stub.push(reply("summary", (input) => (captured = JSON.stringify(input.messages))))
|
|
998
|
-
return Effect.gen(function* () {
|
|
999
|
-
const ssn = yield* SessionNs.Service
|
|
1000
|
-
const session = yield* ssn.create({})
|
|
1001
|
-
yield* createUserMessage(session.id, "first")
|
|
1002
|
-
yield* createUserMessage(session.id, "y".repeat(2_000))
|
|
1003
|
-
yield* createSummaryCompaction(session.id)
|
|
1004
|
-
|
|
1005
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1006
|
-
const parent = msgs.at(-1)?.info.id
|
|
1007
|
-
expect(parent).toBeTruthy()
|
|
1008
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1009
|
-
|
|
1010
|
-
const part = yield* readCompactionPart(session.id)
|
|
1011
|
-
expect(part?.type).toBe("compaction")
|
|
1012
|
-
expect(part?.tail_start_id).toBeUndefined()
|
|
1013
|
-
expect(captured).toContain("yyyy")
|
|
1014
|
-
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 20 }) }))
|
|
1015
|
-
},
|
|
1016
|
-
{ git: true },
|
|
1017
|
-
)
|
|
1018
|
-
|
|
1019
|
-
itCompaction.instance(
|
|
1020
|
-
"falls back to full summary when retained tail media exceeds preserve token budget",
|
|
1021
|
-
() => {
|
|
1022
|
-
const stub = llm()
|
|
1023
|
-
let captured = ""
|
|
1024
|
-
stub.push(reply("summary", (input) => (captured = JSON.stringify(input.messages))))
|
|
1025
|
-
return Effect.gen(function* () {
|
|
1026
|
-
const ssn = yield* SessionNs.Service
|
|
1027
|
-
const session = yield* ssn.create({})
|
|
1028
|
-
yield* createUserMessage(session.id, "older")
|
|
1029
|
-
const recent = yield* createUserMessage(session.id, "recent image turn")
|
|
1030
|
-
yield* ssn.updatePart({
|
|
1031
|
-
id: PartID.ascending(),
|
|
1032
|
-
messageID: recent.id,
|
|
1033
|
-
sessionID: session.id,
|
|
1034
|
-
type: "file",
|
|
1035
|
-
mime: "image/png",
|
|
1036
|
-
filename: "big.png",
|
|
1037
|
-
url: `data:image/png;base64,${"a".repeat(4_000)}`,
|
|
1038
|
-
})
|
|
1039
|
-
yield* createSummaryCompaction(session.id)
|
|
1040
|
-
|
|
1041
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1042
|
-
const parent = msgs.at(-1)?.info.id
|
|
1043
|
-
expect(parent).toBeTruthy()
|
|
1044
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1045
|
-
|
|
1046
|
-
const part = yield* readCompactionPart(session.id)
|
|
1047
|
-
expect(part?.type).toBe("compaction")
|
|
1048
|
-
expect(part?.tail_start_id).toBeUndefined()
|
|
1049
|
-
expect(captured).toContain("recent image turn")
|
|
1050
|
-
expect(captured).toContain("Attached image/png: big.png")
|
|
1051
|
-
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
|
|
1052
|
-
},
|
|
1053
|
-
{ git: true },
|
|
1054
|
-
)
|
|
1055
|
-
|
|
1056
|
-
itCompaction.instance(
|
|
1057
|
-
"retains a split turn suffix when a later message fits the preserve token budget",
|
|
1058
|
-
() => {
|
|
1059
|
-
const stub = llm()
|
|
1060
|
-
let captured = ""
|
|
1061
|
-
stub.push(reply("summary", (input) => (captured = JSON.stringify(input.messages))))
|
|
1062
|
-
return Effect.gen(function* () {
|
|
1063
|
-
const test = yield* TestInstance
|
|
1064
|
-
const ssn = yield* SessionNs.Service
|
|
1065
|
-
const session = yield* ssn.create({})
|
|
1066
|
-
yield* createUserMessage(session.id, "older")
|
|
1067
|
-
const recent = yield* createUserMessage(session.id, "recent turn")
|
|
1068
|
-
const large = yield* createAssistantMessage(session.id, recent.id, test.directory)
|
|
1069
|
-
yield* ssn.updatePart({
|
|
1070
|
-
id: PartID.ascending(),
|
|
1071
|
-
messageID: large.id,
|
|
1072
|
-
sessionID: session.id,
|
|
1073
|
-
type: "text",
|
|
1074
|
-
text: "z".repeat(2_000),
|
|
1075
|
-
})
|
|
1076
|
-
const keep = yield* createAssistantMessage(session.id, recent.id, test.directory)
|
|
1077
|
-
yield* ssn.updatePart({
|
|
1078
|
-
id: PartID.ascending(),
|
|
1079
|
-
messageID: keep.id,
|
|
1080
|
-
sessionID: session.id,
|
|
1081
|
-
type: "text",
|
|
1082
|
-
text: "keep tail",
|
|
1083
|
-
})
|
|
1084
|
-
yield* createSummaryCompaction(session.id)
|
|
1085
|
-
|
|
1086
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1087
|
-
const parent = msgs.at(-1)?.info.id
|
|
1088
|
-
expect(parent).toBeTruthy()
|
|
1089
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1090
|
-
|
|
1091
|
-
const part = yield* readCompactionPart(session.id)
|
|
1092
|
-
expect(part?.type).toBe("compaction")
|
|
1093
|
-
expect(part?.tail_start_id).toBe(keep.id)
|
|
1094
|
-
expect(captured).toContain("zzzz")
|
|
1095
|
-
expect(captured).not.toContain("keep tail")
|
|
1096
|
-
|
|
1097
|
-
const filtered = MessageV2.filterCompacted(yield* MessageV2.stream(session.id))
|
|
1098
|
-
expect(filtered.map((msg) => msg.info.id).slice(0, 3)).toEqual([parent!, expect.any(String), keep.id])
|
|
1099
|
-
expect(filtered[1]?.info.role).toBe("assistant")
|
|
1100
|
-
expect(filtered[1]?.info.role === "assistant" ? filtered[1].info.summary : false).toBe(true)
|
|
1101
|
-
expect(filtered.map((msg) => msg.info.id)).not.toContain(large.id)
|
|
1102
|
-
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
|
|
1103
|
-
},
|
|
1104
|
-
{ git: true },
|
|
1105
|
-
)
|
|
1106
|
-
|
|
1107
|
-
itCompaction.instance(
|
|
1108
|
-
"allows plugins to disable synthetic continue prompt",
|
|
1109
|
-
Effect.gen(function* () {
|
|
1110
|
-
const ssn = yield* SessionNs.Service
|
|
1111
|
-
const session = yield* ssn.create({})
|
|
1112
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
1113
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1114
|
-
|
|
1115
|
-
const result = yield* SessionCompaction.use.process({
|
|
1116
|
-
parentID: msg.id,
|
|
1117
|
-
messages: msgs,
|
|
1118
|
-
sessionID: session.id,
|
|
1119
|
-
auto: true,
|
|
1120
|
-
})
|
|
1121
|
-
|
|
1122
|
-
const all = yield* ssn.messages({ sessionID: session.id })
|
|
1123
|
-
const last = all.at(-1)
|
|
1124
|
-
|
|
1125
|
-
expect(result).toBe("continue")
|
|
1126
|
-
expect(last?.info.role).toBe("assistant")
|
|
1127
|
-
expect(
|
|
1128
|
-
all.some(
|
|
1129
|
-
(msg) =>
|
|
1130
|
-
msg.info.role === "user" &&
|
|
1131
|
-
msg.parts.some(
|
|
1132
|
-
(part) => part.type === "text" && part.synthetic && part.text.includes("Continue if you have next steps"),
|
|
1133
|
-
),
|
|
1134
|
-
),
|
|
1135
|
-
).toBe(false)
|
|
1136
|
-
}).pipe(withCompaction({ plugin: autocontinue(false) })),
|
|
1137
|
-
)
|
|
1138
|
-
|
|
1139
|
-
it.instance(
|
|
1140
|
-
"replays the prior user turn on overflow when earlier context exists",
|
|
1141
|
-
Effect.gen(function* () {
|
|
1142
|
-
const ssn = yield* SessionNs.Service
|
|
1143
|
-
const session = yield* ssn.create({})
|
|
1144
|
-
yield* createUserMessage(session.id, "root")
|
|
1145
|
-
const replay = yield* createUserMessage(session.id, "image")
|
|
1146
|
-
yield* ssn.updatePart({
|
|
1147
|
-
id: PartID.ascending(),
|
|
1148
|
-
messageID: replay.id,
|
|
1149
|
-
sessionID: session.id,
|
|
1150
|
-
type: "file",
|
|
1151
|
-
mime: "image/png",
|
|
1152
|
-
filename: "cat.png",
|
|
1153
|
-
url: "https://example.com/cat.png",
|
|
1154
|
-
})
|
|
1155
|
-
const msg = yield* createUserMessage(session.id, "current")
|
|
1156
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1157
|
-
|
|
1158
|
-
const result = yield* SessionCompaction.use.process({
|
|
1159
|
-
parentID: msg.id,
|
|
1160
|
-
messages: msgs,
|
|
1161
|
-
sessionID: session.id,
|
|
1162
|
-
auto: true,
|
|
1163
|
-
overflow: true,
|
|
1164
|
-
})
|
|
1165
|
-
|
|
1166
|
-
const last = (yield* ssn.messages({ sessionID: session.id })).at(-1)
|
|
1167
|
-
|
|
1168
|
-
expect(result).toBe("continue")
|
|
1169
|
-
expect(last?.info.role).toBe("user")
|
|
1170
|
-
expect(last?.parts.some((part) => part.type === "file")).toBe(false)
|
|
1171
|
-
expect(
|
|
1172
|
-
last?.parts.some((part) => part.type === "text" && part.text.includes("Attached image/png: cat.png")),
|
|
1173
|
-
).toBe(true)
|
|
1174
|
-
}),
|
|
1175
|
-
)
|
|
1176
|
-
|
|
1177
|
-
it.instance(
|
|
1178
|
-
"falls back to overflow guidance when no replayable turn exists",
|
|
1179
|
-
Effect.gen(function* () {
|
|
1180
|
-
const ssn = yield* SessionNs.Service
|
|
1181
|
-
const session = yield* ssn.create({})
|
|
1182
|
-
yield* createUserMessage(session.id, "earlier")
|
|
1183
|
-
const msg = yield* createUserMessage(session.id, "current")
|
|
1184
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1185
|
-
|
|
1186
|
-
const result = yield* SessionCompaction.use.process({
|
|
1187
|
-
parentID: msg.id,
|
|
1188
|
-
messages: msgs,
|
|
1189
|
-
sessionID: session.id,
|
|
1190
|
-
auto: true,
|
|
1191
|
-
overflow: true,
|
|
1192
|
-
})
|
|
1193
|
-
|
|
1194
|
-
const last = (yield* ssn.messages({ sessionID: session.id })).at(-1)
|
|
1195
|
-
|
|
1196
|
-
expect(result).toBe("continue")
|
|
1197
|
-
expect(last?.info.role).toBe("user")
|
|
1198
|
-
if (last?.parts[0]?.type === "text") {
|
|
1199
|
-
expect(last.parts[0].text).toContain("previous request exceeded the provider's size limit")
|
|
1200
|
-
}
|
|
1201
|
-
}),
|
|
1202
|
-
)
|
|
1203
|
-
|
|
1204
|
-
itCompaction.instance(
|
|
1205
|
-
"stops quickly when aborted during retry backoff",
|
|
1206
|
-
() => {
|
|
1207
|
-
const stub = llm()
|
|
1208
|
-
stub.push(
|
|
1209
|
-
Stream.fromAsyncIterable(
|
|
1210
|
-
{
|
|
1211
|
-
async *[Symbol.asyncIterator]() {
|
|
1212
|
-
yield LLMEvent.stepStart({ index: 0 })
|
|
1213
|
-
throw new APICallError({
|
|
1214
|
-
message: "boom",
|
|
1215
|
-
url: "https://example.com/v1/chat/completions",
|
|
1216
|
-
requestBodyValues: {},
|
|
1217
|
-
statusCode: 503,
|
|
1218
|
-
responseHeaders: { "retry-after-ms": "10000" },
|
|
1219
|
-
responseBody: '{"error":"boom"}',
|
|
1220
|
-
isRetryable: true,
|
|
1221
|
-
})
|
|
1222
|
-
},
|
|
1223
|
-
},
|
|
1224
|
-
(err) => err,
|
|
1225
|
-
),
|
|
1226
|
-
)
|
|
1227
|
-
|
|
1228
|
-
return Effect.gen(function* () {
|
|
1229
|
-
const ssn = yield* SessionNs.Service
|
|
1230
|
-
const events = yield* EventV2Bridge.Service
|
|
1231
|
-
const ready = yield* Deferred.make<void>()
|
|
1232
|
-
const session = yield* ssn.create({})
|
|
1233
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
1234
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1235
|
-
const off = yield* events.listen((evt) => {
|
|
1236
|
-
if (evt.type !== SessionStatus.Event.Status.type) return Effect.void
|
|
1237
|
-
const data = evt.data as typeof SessionStatus.Event.Status.data.Type
|
|
1238
|
-
if (data.sessionID !== session.id || data.status.type !== "retry") return Effect.void
|
|
1239
|
-
Deferred.doneUnsafe(ready, Effect.void)
|
|
1240
|
-
return Effect.void
|
|
1241
|
-
})
|
|
1242
|
-
yield* Effect.addFinalizer(() => off)
|
|
1243
|
-
|
|
1244
|
-
const fiber = yield* SessionCompaction.use
|
|
1245
|
-
.process({
|
|
1246
|
-
parentID: msg.id,
|
|
1247
|
-
messages: msgs,
|
|
1248
|
-
sessionID: session.id,
|
|
1249
|
-
auto: false,
|
|
1250
|
-
})
|
|
1251
|
-
.pipe(Effect.forkChild)
|
|
1252
|
-
|
|
1253
|
-
yield* Deferred.await(ready).pipe(Effect.timeout("1 second"))
|
|
1254
|
-
const start = Date.now()
|
|
1255
|
-
yield* Fiber.interrupt(fiber)
|
|
1256
|
-
const exit = yield* Fiber.await(fiber).pipe(Effect.timeout("250 millis"))
|
|
1257
|
-
|
|
1258
|
-
expect(Exit.isFailure(exit)).toBe(true)
|
|
1259
|
-
if (Exit.isFailure(exit)) {
|
|
1260
|
-
expect(Cause.hasInterrupts(exit.cause)).toBe(true)
|
|
1261
|
-
expect(Date.now() - start).toBeLessThan(250)
|
|
1262
|
-
}
|
|
1263
|
-
}).pipe(withCompaction({ llm: stub.layer }))
|
|
1264
|
-
},
|
|
1265
|
-
{ git: true },
|
|
1266
|
-
)
|
|
1267
|
-
|
|
1268
|
-
itCompaction.instance(
|
|
1269
|
-
"does not leave a summary assistant when aborted before processor setup",
|
|
1270
|
-
() =>
|
|
1271
|
-
Effect.gen(function* () {
|
|
1272
|
-
const ready = yield* Deferred.make<void>()
|
|
1273
|
-
return yield* Effect.gen(function* () {
|
|
1274
|
-
const ssn = yield* SessionNs.Service
|
|
1275
|
-
const session = yield* ssn.create({})
|
|
1276
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
1277
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1278
|
-
const fiber = yield* SessionCompaction.use
|
|
1279
|
-
.process({
|
|
1280
|
-
parentID: msg.id,
|
|
1281
|
-
messages: msgs,
|
|
1282
|
-
sessionID: session.id,
|
|
1283
|
-
auto: false,
|
|
1284
|
-
})
|
|
1285
|
-
.pipe(Effect.forkChild)
|
|
1286
|
-
|
|
1287
|
-
yield* Deferred.await(ready).pipe(Effect.timeout("1 second"))
|
|
1288
|
-
yield* Fiber.interrupt(fiber)
|
|
1289
|
-
const exit = yield* Fiber.await(fiber).pipe(Effect.timeout("250 millis"))
|
|
1290
|
-
const all = yield* ssn.messages({ sessionID: session.id })
|
|
1291
|
-
|
|
1292
|
-
expect(Exit.isFailure(exit)).toBe(true)
|
|
1293
|
-
if (Exit.isFailure(exit)) expect(Cause.hasInterrupts(exit.cause)).toBe(true)
|
|
1294
|
-
expect(all.some((msg) => msg.info.role === "assistant" && msg.info.summary)).toBe(false)
|
|
1295
|
-
}).pipe(withCompaction({ plugin: plugin(ready) }))
|
|
1296
|
-
}),
|
|
1297
|
-
{ git: true },
|
|
1298
|
-
)
|
|
1299
|
-
|
|
1300
|
-
itCompaction.instance(
|
|
1301
|
-
"silently drops reasoning-delta arriving without prior reasoning-start",
|
|
1302
|
-
() => {
|
|
1303
|
-
// Regression: PR initially auto-created a reasoning Part for orphan deltas (no preceding
|
|
1304
|
-
// reasoning-start). Reverted to match dev — drop silently. Pinned here so any future
|
|
1305
|
-
// change to processor.ts reasoning-delta handling triggers this test.
|
|
1306
|
-
const stub = llm()
|
|
1307
|
-
stub.push(
|
|
1308
|
-
Stream.make(
|
|
1309
|
-
LLMEvent.reasoningDelta({ id: "orphan-1", text: "stray reasoning" }),
|
|
1310
|
-
LLMEvent.textStart({ id: "txt-0" }),
|
|
1311
|
-
LLMEvent.textDelta({ id: "txt-0", text: "summary" }),
|
|
1312
|
-
LLMEvent.textEnd({ id: "txt-0" }),
|
|
1313
|
-
LLMEvent.stepFinish({ index: 0, reason: "stop", usage: basicUsage() }),
|
|
1314
|
-
LLMEvent.finish({ reason: "stop", usage: basicUsage() }),
|
|
1315
|
-
),
|
|
1316
|
-
)
|
|
1317
|
-
return Effect.gen(function* () {
|
|
1318
|
-
const ssn = yield* SessionNs.Service
|
|
1319
|
-
const session = yield* ssn.create({})
|
|
1320
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
1321
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1322
|
-
yield* SessionCompaction.use.process({
|
|
1323
|
-
parentID: msg.id,
|
|
1324
|
-
messages: msgs,
|
|
1325
|
-
sessionID: session.id,
|
|
1326
|
-
auto: false,
|
|
1327
|
-
})
|
|
1328
|
-
|
|
1329
|
-
const summary = (yield* ssn.messages({ sessionID: session.id })).find(
|
|
1330
|
-
(item) => item.info.role === "assistant" && item.info.summary,
|
|
1331
|
-
)
|
|
1332
|
-
expect(summary?.parts.some((part) => part.type === "reasoning")).toBe(false)
|
|
1333
|
-
// Sanity: the text part still got through.
|
|
1334
|
-
expect(summary?.parts.some((part) => part.type === "text" && part.text === "summary")).toBe(true)
|
|
1335
|
-
}).pipe(withCompaction({ llm: stub.layer }))
|
|
1336
|
-
},
|
|
1337
|
-
{ git: true },
|
|
1338
|
-
)
|
|
1339
|
-
|
|
1340
|
-
itCompaction.instance(
|
|
1341
|
-
"does not allow tool calls while generating the summary",
|
|
1342
|
-
() => {
|
|
1343
|
-
const stub = llm()
|
|
1344
|
-
stub.push(
|
|
1345
|
-
Stream.make(
|
|
1346
|
-
LLMEvent.toolCall({ id: "call-1", name: "_noop", input: {} }),
|
|
1347
|
-
LLMEvent.stepFinish({
|
|
1348
|
-
index: 0,
|
|
1349
|
-
reason: "tool-calls",
|
|
1350
|
-
usage: basicUsage(),
|
|
1351
|
-
}),
|
|
1352
|
-
LLMEvent.finish({
|
|
1353
|
-
reason: "tool-calls",
|
|
1354
|
-
usage: basicUsage(),
|
|
1355
|
-
}),
|
|
1356
|
-
),
|
|
1357
|
-
)
|
|
1358
|
-
return Effect.gen(function* () {
|
|
1359
|
-
const ssn = yield* SessionNs.Service
|
|
1360
|
-
const session = yield* ssn.create({})
|
|
1361
|
-
const msg = yield* createUserMessage(session.id, "hello")
|
|
1362
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1363
|
-
yield* SessionCompaction.use.process({ parentID: msg.id, messages: msgs, sessionID: session.id, auto: false })
|
|
1364
|
-
|
|
1365
|
-
const summary = (yield* ssn.messages({ sessionID: session.id })).find(
|
|
1366
|
-
(item) => item.info.role === "assistant" && item.info.summary,
|
|
1367
|
-
)
|
|
1368
|
-
|
|
1369
|
-
expect(summary?.info.role).toBe("assistant")
|
|
1370
|
-
expect(summary?.parts.some((part) => part.type === "tool")).toBe(false)
|
|
1371
|
-
}).pipe(withCompaction({ llm: stub.layer }))
|
|
1372
|
-
},
|
|
1373
|
-
{ git: true },
|
|
1374
|
-
)
|
|
1375
|
-
|
|
1376
|
-
itCompaction.instance(
|
|
1377
|
-
"summarizes only the head while keeping recent tail out of summary input",
|
|
1378
|
-
() => {
|
|
1379
|
-
const stub = llm()
|
|
1380
|
-
let captured = ""
|
|
1381
|
-
stub.push(
|
|
1382
|
-
reply("summary", (input) => {
|
|
1383
|
-
captured = JSON.stringify(input.messages)
|
|
1384
|
-
}),
|
|
1385
|
-
)
|
|
1386
|
-
return Effect.gen(function* () {
|
|
1387
|
-
const ssn = yield* SessionNs.Service
|
|
1388
|
-
const session = yield* ssn.create({})
|
|
1389
|
-
yield* createUserMessage(session.id, "older context")
|
|
1390
|
-
yield* createUserMessage(session.id, "keep this turn")
|
|
1391
|
-
yield* createUserMessage(session.id, "and this one too")
|
|
1392
|
-
yield* createCompactionMarker(session.id)
|
|
1393
|
-
|
|
1394
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1395
|
-
const parent = msgs.at(-1)?.info.id
|
|
1396
|
-
expect(parent).toBeTruthy()
|
|
1397
|
-
yield* SessionCompaction.use.process({
|
|
1398
|
-
parentID: parent!,
|
|
1399
|
-
messages: msgs,
|
|
1400
|
-
sessionID: session.id,
|
|
1401
|
-
auto: false,
|
|
1402
|
-
})
|
|
1403
|
-
|
|
1404
|
-
expect(captured).toContain("older context")
|
|
1405
|
-
expect(captured).not.toContain("keep this turn")
|
|
1406
|
-
expect(captured).not.toContain("and this one too")
|
|
1407
|
-
expect(captured).not.toContain("What did we do so far?")
|
|
1408
|
-
}).pipe(withCompaction({ llm: stub.layer }))
|
|
1409
|
-
},
|
|
1410
|
-
{ git: true },
|
|
1411
|
-
)
|
|
1412
|
-
|
|
1413
|
-
itCompaction.instance(
|
|
1414
|
-
"anchors repeated compactions with the previous summary",
|
|
1415
|
-
() => {
|
|
1416
|
-
const stub = llm()
|
|
1417
|
-
let captured = ""
|
|
1418
|
-
stub.push(reply("summary one"))
|
|
1419
|
-
stub.push(
|
|
1420
|
-
reply("summary two", (input) => {
|
|
1421
|
-
captured = JSON.stringify(input.messages)
|
|
1422
|
-
}),
|
|
1423
|
-
)
|
|
1424
|
-
|
|
1425
|
-
return Effect.gen(function* () {
|
|
1426
|
-
const ssn = yield* SessionNs.Service
|
|
1427
|
-
const session = yield* ssn.create({})
|
|
1428
|
-
yield* createUserMessage(session.id, "older context")
|
|
1429
|
-
yield* createUserMessage(session.id, "keep this turn")
|
|
1430
|
-
yield* createCompactionMarker(session.id)
|
|
1431
|
-
|
|
1432
|
-
let msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1433
|
-
let parent = msgs.at(-1)?.info.id
|
|
1434
|
-
expect(parent).toBeTruthy()
|
|
1435
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1436
|
-
|
|
1437
|
-
yield* createUserMessage(session.id, "latest turn")
|
|
1438
|
-
yield* createCompactionMarker(session.id)
|
|
1439
|
-
|
|
1440
|
-
msgs = MessageV2.filterCompacted(yield* MessageV2.stream(session.id))
|
|
1441
|
-
parent = msgs.at(-1)?.info.id
|
|
1442
|
-
expect(parent).toBeTruthy()
|
|
1443
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1444
|
-
|
|
1445
|
-
expect(captured).toContain("<previous-summary>")
|
|
1446
|
-
expect(captured).toContain("summary one")
|
|
1447
|
-
expect(captured.match(/summary one/g)?.length).toBe(1)
|
|
1448
|
-
expect(captured).toContain("## Constraints & Preferences")
|
|
1449
|
-
expect(captured).toContain("## Progress")
|
|
1450
|
-
}).pipe(withCompaction({ llm: stub.layer }))
|
|
1451
|
-
},
|
|
1452
|
-
{ git: true },
|
|
1453
|
-
)
|
|
1454
|
-
|
|
1455
|
-
itCompaction.instance("keeps recent pre-compaction turns across repeated compactions", () => {
|
|
1456
|
-
const stub = llm()
|
|
1457
|
-
stub.push(reply("summary one"))
|
|
1458
|
-
stub.push(reply("summary two"))
|
|
1459
|
-
|
|
1460
|
-
return Effect.gen(function* () {
|
|
1461
|
-
const ssn = yield* SessionNs.Service
|
|
1462
|
-
const session = yield* ssn.create({})
|
|
1463
|
-
const u1 = yield* createUserMessage(session.id, "one")
|
|
1464
|
-
const u2 = yield* createUserMessage(session.id, "two")
|
|
1465
|
-
const u3 = yield* createUserMessage(session.id, "three")
|
|
1466
|
-
yield* createCompactionMarker(session.id)
|
|
1467
|
-
|
|
1468
|
-
let msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1469
|
-
let parent = msgs.at(-1)?.info.id
|
|
1470
|
-
expect(parent).toBeTruthy()
|
|
1471
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1472
|
-
|
|
1473
|
-
const u4 = yield* createUserMessage(session.id, "four")
|
|
1474
|
-
yield* createCompactionMarker(session.id)
|
|
1475
|
-
|
|
1476
|
-
msgs = MessageV2.filterCompacted(yield* MessageV2.stream(session.id))
|
|
1477
|
-
parent = msgs.at(-1)?.info.id
|
|
1478
|
-
expect(parent).toBeTruthy()
|
|
1479
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1480
|
-
|
|
1481
|
-
const filtered = MessageV2.filterCompacted(yield* MessageV2.stream(session.id))
|
|
1482
|
-
const ids = filtered.map((msg) => msg.info.id)
|
|
1483
|
-
|
|
1484
|
-
expect(ids).not.toContain(u1.id)
|
|
1485
|
-
expect(ids).not.toContain(u2.id)
|
|
1486
|
-
expect(ids).toContain(u3.id)
|
|
1487
|
-
expect(ids).toContain(u4.id)
|
|
1488
|
-
expect(filtered.some((msg) => msg.info.role === "assistant" && msg.info.summary)).toBe(true)
|
|
1489
|
-
expect(
|
|
1490
|
-
filtered.some((msg) => msg.info.role === "user" && msg.parts.some((part) => part.type === "compaction")),
|
|
1491
|
-
).toBe(true)
|
|
1492
|
-
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))
|
|
1493
|
-
})
|
|
1494
|
-
|
|
1495
|
-
itCompaction.instance(
|
|
1496
|
-
"ignores previous summaries when sizing the retained tail",
|
|
1497
|
-
Effect.gen(function* () {
|
|
1498
|
-
const ssn = yield* SessionNs.Service
|
|
1499
|
-
const test = yield* TestInstance
|
|
1500
|
-
const session = yield* ssn.create({})
|
|
1501
|
-
yield* createUserMessage(session.id, "older")
|
|
1502
|
-
const keep = yield* createUserMessage(session.id, "keep this turn")
|
|
1503
|
-
const keepReply = yield* createAssistantMessage(session.id, keep.id, test.directory)
|
|
1504
|
-
yield* ssn.updatePart({
|
|
1505
|
-
id: PartID.ascending(),
|
|
1506
|
-
messageID: keepReply.id,
|
|
1507
|
-
sessionID: session.id,
|
|
1508
|
-
type: "text",
|
|
1509
|
-
text: "keep reply",
|
|
1510
|
-
})
|
|
1511
|
-
|
|
1512
|
-
yield* createCompactionMarker(session.id)
|
|
1513
|
-
const firstCompaction = (yield* ssn.messages({ sessionID: session.id })).at(-1)?.info.id
|
|
1514
|
-
expect(firstCompaction).toBeTruthy()
|
|
1515
|
-
yield* createSummaryAssistantMessage(session.id, firstCompaction!, test.directory, "summary ".repeat(800))
|
|
1516
|
-
|
|
1517
|
-
const recent = yield* createUserMessage(session.id, "recent turn")
|
|
1518
|
-
const recentReply = yield* createAssistantMessage(session.id, recent.id, test.directory)
|
|
1519
|
-
yield* ssn.updatePart({
|
|
1520
|
-
id: PartID.ascending(),
|
|
1521
|
-
messageID: recentReply.id,
|
|
1522
|
-
sessionID: session.id,
|
|
1523
|
-
type: "text",
|
|
1524
|
-
text: "recent reply",
|
|
1525
|
-
})
|
|
1526
|
-
|
|
1527
|
-
yield* createCompactionMarker(session.id)
|
|
1528
|
-
const msgs = yield* ssn.messages({ sessionID: session.id })
|
|
1529
|
-
const parent = msgs.at(-1)?.info.id
|
|
1530
|
-
expect(parent).toBeTruthy()
|
|
1531
|
-
yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
|
|
1532
|
-
|
|
1533
|
-
const part = yield* readCompactionPart(session.id)
|
|
1534
|
-
expect(part?.type).toBe("compaction")
|
|
1535
|
-
expect(part?.tail_start_id).toBe(keep.id)
|
|
1536
|
-
}).pipe(withCompaction({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 500 }) })),
|
|
1537
|
-
)
|
|
1538
|
-
})
|
|
1539
|
-
|
|
1540
|
-
describe("util.token.estimate", () => {
|
|
1541
|
-
test("estimates tokens from text (4 chars per token)", () => {
|
|
1542
|
-
const text = "x".repeat(4000)
|
|
1543
|
-
expect(Token.estimate(text)).toBe(1000)
|
|
1544
|
-
})
|
|
1545
|
-
|
|
1546
|
-
test("estimates tokens from larger text", () => {
|
|
1547
|
-
const text = "y".repeat(20_000)
|
|
1548
|
-
expect(Token.estimate(text)).toBe(5000)
|
|
1549
|
-
})
|
|
1550
|
-
|
|
1551
|
-
test("returns 0 for empty string", () => {
|
|
1552
|
-
expect(Token.estimate("")).toBe(0)
|
|
1553
|
-
})
|
|
1554
|
-
})
|
|
1555
|
-
|
|
1556
|
-
describe("SessionNs.getUsage", () => {
|
|
1557
|
-
test("normalizes standard usage to token format", () => {
|
|
1558
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1559
|
-
const result = SessionNs.getUsage({
|
|
1560
|
-
model,
|
|
1561
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, totalTokens: 1500 }),
|
|
1562
|
-
})
|
|
1563
|
-
|
|
1564
|
-
expect(result.tokens.input).toBe(1000)
|
|
1565
|
-
expect(result.tokens.output).toBe(500)
|
|
1566
|
-
expect(result.tokens.reasoning).toBe(0)
|
|
1567
|
-
expect(result.tokens.cache.read).toBe(0)
|
|
1568
|
-
expect(result.tokens.cache.write).toBe(0)
|
|
1569
|
-
})
|
|
1570
|
-
|
|
1571
|
-
test("extracts cached tokens to cache.read", () => {
|
|
1572
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1573
|
-
const result = SessionNs.getUsage({
|
|
1574
|
-
model,
|
|
1575
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, totalTokens: 1500, cacheReadInputTokens: 200 }),
|
|
1576
|
-
})
|
|
1577
|
-
|
|
1578
|
-
expect(result.tokens.input).toBe(800)
|
|
1579
|
-
expect(result.tokens.cache.read).toBe(200)
|
|
1580
|
-
})
|
|
1581
|
-
|
|
1582
|
-
test("handles anthropic cache write metadata", () => {
|
|
1583
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1584
|
-
const result = SessionNs.getUsage({
|
|
1585
|
-
model,
|
|
1586
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, totalTokens: 1500 }),
|
|
1587
|
-
metadata: {
|
|
1588
|
-
anthropic: {
|
|
1589
|
-
cacheCreationInputTokens: 300,
|
|
1590
|
-
},
|
|
1591
|
-
},
|
|
1592
|
-
})
|
|
1593
|
-
|
|
1594
|
-
expect(result.tokens.cache.write).toBe(300)
|
|
1595
|
-
})
|
|
1596
|
-
|
|
1597
|
-
test("subtracts cached tokens for anthropic provider", () => {
|
|
1598
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1599
|
-
// AI SDK v6 normalizes inputTokens to include cached tokens for all providers
|
|
1600
|
-
const result = SessionNs.getUsage({
|
|
1601
|
-
model,
|
|
1602
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, totalTokens: 1500, cacheReadInputTokens: 200 }),
|
|
1603
|
-
metadata: {
|
|
1604
|
-
anthropic: {},
|
|
1605
|
-
},
|
|
1606
|
-
})
|
|
1607
|
-
|
|
1608
|
-
expect(result.tokens.input).toBe(800)
|
|
1609
|
-
expect(result.tokens.cache.read).toBe(200)
|
|
1610
|
-
})
|
|
1611
|
-
|
|
1612
|
-
test("separates reasoning tokens from output tokens", () => {
|
|
1613
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1614
|
-
const result = SessionNs.getUsage({
|
|
1615
|
-
model,
|
|
1616
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, reasoningTokens: 100, totalTokens: 1500 }),
|
|
1617
|
-
})
|
|
1618
|
-
|
|
1619
|
-
expect(result.tokens.input).toBe(1000)
|
|
1620
|
-
expect(result.tokens.output).toBe(400)
|
|
1621
|
-
expect(result.tokens.reasoning).toBe(100)
|
|
1622
|
-
expect(result.tokens.total).toBe(1500)
|
|
1623
|
-
})
|
|
1624
|
-
|
|
1625
|
-
test("does not double count reasoning tokens in cost", () => {
|
|
1626
|
-
const model = createModel({
|
|
1627
|
-
context: 100_000,
|
|
1628
|
-
output: 32_000,
|
|
1629
|
-
cost: {
|
|
1630
|
-
input: 0,
|
|
1631
|
-
output: 15,
|
|
1632
|
-
cache: { read: 0, write: 0 },
|
|
1633
|
-
},
|
|
1634
|
-
})
|
|
1635
|
-
const result = SessionNs.getUsage({
|
|
1636
|
-
model,
|
|
1637
|
-
usage: usage({ inputTokens: 0, outputTokens: 1_000_000, reasoningTokens: 250_000, totalTokens: 1_000_000 }),
|
|
1638
|
-
})
|
|
1639
|
-
|
|
1640
|
-
expect(result.tokens.output).toBe(750_000)
|
|
1641
|
-
expect(result.tokens.reasoning).toBe(250_000)
|
|
1642
|
-
expect(result.cost).toBe(15)
|
|
1643
|
-
})
|
|
1644
|
-
|
|
1645
|
-
test("handles undefined optional values gracefully", () => {
|
|
1646
|
-
const model = createModel({ context: 100_000, output: 32_000 })
|
|
1647
|
-
const result = SessionNs.getUsage({
|
|
1648
|
-
model,
|
|
1649
|
-
usage: usage({ inputTokens: 0, outputTokens: 0, totalTokens: 0 }),
|
|
1650
|
-
})
|
|
1651
|
-
|
|
1652
|
-
expect(result.tokens.input).toBe(0)
|
|
1653
|
-
expect(result.tokens.output).toBe(0)
|
|
1654
|
-
expect(result.tokens.reasoning).toBe(0)
|
|
1655
|
-
expect(result.tokens.cache.read).toBe(0)
|
|
1656
|
-
expect(result.tokens.cache.write).toBe(0)
|
|
1657
|
-
expect(Number.isNaN(result.cost)).toBe(false)
|
|
1658
|
-
})
|
|
1659
|
-
|
|
1660
|
-
test("calculates cost correctly", () => {
|
|
1661
|
-
const model = createModel({
|
|
1662
|
-
context: 100_000,
|
|
1663
|
-
output: 32_000,
|
|
1664
|
-
cost: {
|
|
1665
|
-
input: 3,
|
|
1666
|
-
output: 15,
|
|
1667
|
-
cache: { read: 0.3, write: 3.75 },
|
|
1668
|
-
},
|
|
1669
|
-
})
|
|
1670
|
-
const result = SessionNs.getUsage({
|
|
1671
|
-
model,
|
|
1672
|
-
usage: usage({ inputTokens: 1_000_000, outputTokens: 100_000, totalTokens: 1_100_000 }),
|
|
1673
|
-
})
|
|
1674
|
-
|
|
1675
|
-
expect(result.cost).toBe(3 + 1.5)
|
|
1676
|
-
})
|
|
1677
|
-
|
|
1678
|
-
test("uses authoritative Copilot billed cost when provided", () => {
|
|
1679
|
-
const result = SessionNs.getUsage({
|
|
1680
|
-
model: createModel({
|
|
1681
|
-
context: 100_000,
|
|
1682
|
-
output: 32_000,
|
|
1683
|
-
cost: { input: 3, output: 15, cache: { read: 0.3, write: 0.3 } },
|
|
1684
|
-
}),
|
|
1685
|
-
usage: usage({ inputTokens: 11_774, outputTokens: 39, totalTokens: 11_813 }),
|
|
1686
|
-
metadata: { copilot: { totalNanoAiu: 4_473_525_000 } },
|
|
1687
|
-
})
|
|
1688
|
-
|
|
1689
|
-
expect(result.cost).toBe(0.04473525)
|
|
1690
|
-
})
|
|
1691
|
-
|
|
1692
|
-
test("uses matching context cost tier before over-200k fallback", () => {
|
|
1693
|
-
const model = createModel({
|
|
1694
|
-
context: 1_000_000,
|
|
1695
|
-
output: 32_000,
|
|
1696
|
-
cost: {
|
|
1697
|
-
input: 1,
|
|
1698
|
-
output: 2,
|
|
1699
|
-
cache: { read: 0.1, write: 0.5 },
|
|
1700
|
-
tiers: [
|
|
1701
|
-
{
|
|
1702
|
-
input: 3,
|
|
1703
|
-
output: 4,
|
|
1704
|
-
cache: { read: 0.3, write: 1.5 },
|
|
1705
|
-
tier: { type: "context", size: 200_000 },
|
|
1706
|
-
},
|
|
1707
|
-
{
|
|
1708
|
-
input: 5,
|
|
1709
|
-
output: 6,
|
|
1710
|
-
cache: { read: 0.5, write: 2.5 },
|
|
1711
|
-
tier: { type: "context", size: 500_000 },
|
|
1712
|
-
},
|
|
1713
|
-
],
|
|
1714
|
-
experimentalOver200K: {
|
|
1715
|
-
input: 100,
|
|
1716
|
-
output: 100,
|
|
1717
|
-
cache: { read: 100, write: 100 },
|
|
1718
|
-
},
|
|
1719
|
-
},
|
|
1720
|
-
})
|
|
1721
|
-
const result = SessionNs.getUsage({
|
|
1722
|
-
model,
|
|
1723
|
-
usage: usage({
|
|
1724
|
-
inputTokens: 650_000,
|
|
1725
|
-
outputTokens: 100_000,
|
|
1726
|
-
totalTokens: 750_000,
|
|
1727
|
-
cacheReadInputTokens: 100_000,
|
|
1728
|
-
}),
|
|
1729
|
-
})
|
|
1730
|
-
|
|
1731
|
-
expect(result.tokens.input).toBe(550_000)
|
|
1732
|
-
expect(result.cost).toBe(2.75 + 0.6 + 0.05)
|
|
1733
|
-
})
|
|
1734
|
-
|
|
1735
|
-
test("falls back to over-200k pricing when no cost tier matches", () => {
|
|
1736
|
-
const model = createModel({
|
|
1737
|
-
context: 1_000_000,
|
|
1738
|
-
output: 32_000,
|
|
1739
|
-
cost: {
|
|
1740
|
-
input: 1,
|
|
1741
|
-
output: 2,
|
|
1742
|
-
cache: { read: 0.1, write: 0.5 },
|
|
1743
|
-
tiers: [
|
|
1744
|
-
{
|
|
1745
|
-
input: 5,
|
|
1746
|
-
output: 6,
|
|
1747
|
-
cache: { read: 0.5, write: 2.5 },
|
|
1748
|
-
tier: { type: "context", size: 500_000 },
|
|
1749
|
-
},
|
|
1750
|
-
],
|
|
1751
|
-
experimentalOver200K: {
|
|
1752
|
-
input: 3,
|
|
1753
|
-
output: 4,
|
|
1754
|
-
cache: { read: 0.3, write: 1.5 },
|
|
1755
|
-
},
|
|
1756
|
-
},
|
|
1757
|
-
})
|
|
1758
|
-
const result = SessionNs.getUsage({
|
|
1759
|
-
model,
|
|
1760
|
-
usage: usage({ inputTokens: 300_000, outputTokens: 100_000, totalTokens: 400_000 }),
|
|
1761
|
-
})
|
|
1762
|
-
|
|
1763
|
-
expect(result.cost).toBe(0.9 + 0.4)
|
|
1764
|
-
})
|
|
1765
|
-
|
|
1766
|
-
test.each(["@ai-sdk/anthropic", "@ai-sdk/amazon-bedrock", "@ai-sdk/google-vertex/anthropic"])(
|
|
1767
|
-
"computes total from components for %s models",
|
|
1768
|
-
(npm) => {
|
|
1769
|
-
const model = createModel({ context: 100_000, output: 32_000, npm })
|
|
1770
|
-
// AI SDK v6: inputTokens includes cached tokens for all providers
|
|
1771
|
-
const item = usage({
|
|
1772
|
-
inputTokens: 1000,
|
|
1773
|
-
outputTokens: 500,
|
|
1774
|
-
totalTokens: 1500,
|
|
1775
|
-
cacheReadInputTokens: 200,
|
|
1776
|
-
})
|
|
1777
|
-
if (npm === "@ai-sdk/amazon-bedrock") {
|
|
1778
|
-
const result = SessionNs.getUsage({
|
|
1779
|
-
model,
|
|
1780
|
-
usage: item,
|
|
1781
|
-
metadata: {
|
|
1782
|
-
bedrock: {
|
|
1783
|
-
usage: {
|
|
1784
|
-
cacheWriteInputTokens: 300,
|
|
1785
|
-
},
|
|
1786
|
-
},
|
|
1787
|
-
},
|
|
1788
|
-
})
|
|
1789
|
-
|
|
1790
|
-
// inputTokens (1000) includes cache, so adjusted = 1000 - 200 - 300 = 500
|
|
1791
|
-
expect(result.tokens.input).toBe(500)
|
|
1792
|
-
expect(result.tokens.cache.read).toBe(200)
|
|
1793
|
-
expect(result.tokens.cache.write).toBe(300)
|
|
1794
|
-
// total = adjusted (500) + output (500) + cacheRead (200) + cacheWrite (300)
|
|
1795
|
-
expect(result.tokens.total).toBe(1500)
|
|
1796
|
-
return
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
const result = SessionNs.getUsage({
|
|
1800
|
-
model,
|
|
1801
|
-
usage: item,
|
|
1802
|
-
metadata: {
|
|
1803
|
-
anthropic: {
|
|
1804
|
-
cacheCreationInputTokens: 300,
|
|
1805
|
-
},
|
|
1806
|
-
},
|
|
1807
|
-
})
|
|
1808
|
-
|
|
1809
|
-
// inputTokens (1000) includes cache, so adjusted = 1000 - 200 - 300 = 500
|
|
1810
|
-
expect(result.tokens.input).toBe(500)
|
|
1811
|
-
expect(result.tokens.cache.read).toBe(200)
|
|
1812
|
-
expect(result.tokens.cache.write).toBe(300)
|
|
1813
|
-
// total = adjusted (500) + output (500) + cacheRead (200) + cacheWrite (300)
|
|
1814
|
-
expect(result.tokens.total).toBe(1500)
|
|
1815
|
-
},
|
|
1816
|
-
)
|
|
1817
|
-
|
|
1818
|
-
test("extracts cache write tokens from vertex metadata key", () => {
|
|
1819
|
-
const model = createModel({ context: 100_000, output: 32_000, npm: "@ai-sdk/google-vertex/anthropic" })
|
|
1820
|
-
const result = SessionNs.getUsage({
|
|
1821
|
-
model,
|
|
1822
|
-
usage: usage({ inputTokens: 1000, outputTokens: 500, totalTokens: 1500, cacheReadInputTokens: 200 }),
|
|
1823
|
-
metadata: {
|
|
1824
|
-
vertex: {
|
|
1825
|
-
cacheCreationInputTokens: 300,
|
|
1826
|
-
},
|
|
1827
|
-
},
|
|
1828
|
-
})
|
|
1829
|
-
|
|
1830
|
-
expect(result.tokens.input).toBe(500)
|
|
1831
|
-
expect(result.tokens.cache.read).toBe(200)
|
|
1832
|
-
expect(result.tokens.cache.write).toBe(300)
|
|
1833
|
-
})
|
|
1834
|
-
})
|