@bastani/atomic 0.9.20-alpha.4 → 0.9.20-alpha.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/CHANGELOG.md +60 -0
- package/README.md +37 -0
- package/dist/builtin/intercom/CHANGELOG.md +16 -0
- package/dist/builtin/intercom/broker/broker.ts +110 -39
- package/dist/builtin/intercom/broker/client.ts +8 -1
- package/dist/builtin/intercom/index.bundle.mjs +61 -2
- package/dist/builtin/intercom/live-route-refusal.ts +69 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/recoverable-disconnect.ts +16 -4
- package/dist/builtin/intercom/skills/intercom/SKILL.md +43 -12
- package/dist/builtin/intercom/types.ts +3 -1
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +18 -0
- package/dist/builtin/subagents/README.md +2 -0
- package/dist/builtin/subagents/agents/code-simplifier.md +1 -1
- package/dist/builtin/subagents/agents/codebase-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +3 -3
- package/dist/builtin/subagents/agents/debugger.md +7 -5
- package/dist/builtin/subagents/agents/worker.md +4 -2
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/agent-browser/SKILL.md +56 -0
- package/dist/builtin/subagents/skills/cua-driver/BROWSER.md +494 -0
- package/dist/builtin/subagents/skills/cua-driver/EMBEDDING.md +578 -0
- package/dist/builtin/subagents/skills/cua-driver/LINUX.md +364 -0
- package/dist/builtin/subagents/skills/cua-driver/MACOS.md +509 -0
- package/dist/builtin/subagents/skills/cua-driver/README.md +113 -0
- package/dist/builtin/subagents/skills/cua-driver/RECORDING.md +162 -0
- package/dist/builtin/subagents/skills/cua-driver/SKILL.md +1105 -0
- package/dist/builtin/subagents/skills/cua-driver/WINDOWS.md +866 -0
- package/dist/builtin/subagents/skills/subagent/SKILL.md +32 -8
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -4
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +43 -0
- package/dist/builtin/workflows/README.md +4 -2
- package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
- package/dist/builtin/workflows/builtin/{chunk-1dydq7w3.js → chunk-2hzrv5y8.js} +202 -45
- package/dist/builtin/workflows/builtin/{chunk-n4yxrsm9.js → chunk-3tx8ry44.js} +3 -2
- package/dist/builtin/workflows/builtin/{chunk-n8g2da69.js → chunk-5724b0cf.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-scgprmdj.js → chunk-7n51c5gh.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-9y0f90rd.js → chunk-9z3ztr2a.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-vt9zgr9d.js → chunk-deq63d9p.js} +4 -4
- package/dist/builtin/workflows/builtin/{chunk-k18g9me8.js → chunk-dxjxtgmp.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-kf5xpbkz.js → chunk-ffdrv23t.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-119kxb28.js → chunk-hmt5w62g.js} +72 -45
- package/dist/builtin/workflows/builtin/{chunk-hnbbb5r0.js → chunk-jngsbbpm.js} +4 -4
- package/dist/builtin/workflows/builtin/{chunk-d1xqh1rd.js → chunk-njmf5ze7.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-sn5mchnx.js → chunk-vn0wb31x.js} +1 -1
- package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
- package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
- package/dist/builtin/workflows/builtin/goal.js +4 -4
- package/dist/builtin/workflows/builtin/index.d.ts +1 -1
- package/dist/builtin/workflows/builtin/index.js +12 -12
- package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +1 -1
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +4 -4
- package/dist/builtin/workflows/builtin/steering-context.js +1 -1
- package/dist/builtin/workflows/builtin/tournament.js +3 -3
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +18 -11
- package/dist/builtin/workflows/skills/impeccable/reference/adapt.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/adapt.native.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/animate.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +5 -5
- package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +6 -6
- package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +0 -6
- package/dist/builtin/workflows/skills/impeccable/reference/critique.md +19 -41
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +11 -65
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/delight.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/extract.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +21 -21
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +8 -8
- package/dist/builtin/workflows/skills/impeccable/reference/layout.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/live-setup.md +10 -8
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +39 -38
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +48 -21
- package/dist/builtin/workflows/skills/impeccable/reference/onboard.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/polish.md +11 -3
- package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/routing.md +13 -7
- package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +13 -19
- package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index-failures.json +121 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index.json +1 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +212 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +218 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-dom.js +21 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +242 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +25 -4
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +666 -197
- package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +352 -117
- package/dist/builtin/workflows/src/index.js +1403 -1218
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +15 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +40 -12
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +9 -8
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-boundaries.d.ts +68 -0
- package/dist/core/agent-session-boundaries.d.ts.map +1 -0
- package/dist/core/agent-session-boundaries.js +334 -0
- package/dist/core/agent-session-boundaries.js.map +1 -0
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +27 -13
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +16 -20
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +3 -2
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +30 -4
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +2 -1
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +93 -25
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +4 -9
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +15 -5
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +2 -3
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +6 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +15 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +17 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
- package/dist/core/compaction/compaction-boundary.js +11 -6
- package/dist/core/compaction/compaction-boundary.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +3 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +37 -0
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/crash-log.d.ts +6 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +69 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/execution-model-router.d.ts +3 -0
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +45 -16
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/export-html/template-js/tree-filter-render.js +6 -1
- package/dist/core/export-html/template.js +6 -1
- package/dist/core/extensions/agent-events.d.ts +69 -3
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +5 -3
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/event-results.d.ts +3 -0
- package/dist/core/extensions/event-results.d.ts.map +1 -1
- package/dist/core/extensions/event-results.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -2
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +2 -0
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runner-events.d.ts +16 -2
- package/dist/core/extensions/runner-events.d.ts.map +1 -1
- package/dist/core/extensions/runner-events.js +98 -5
- package/dist/core/extensions/runner-events.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/messages.d.ts +10 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +57 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +52 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +16 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver-defaults.d.ts.map +1 -1
- package/dist/core/model-resolver-defaults.js +2 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/model-routing-task.d.ts +1 -1
- package/dist/core/model-routing-task.d.ts.map +1 -1
- package/dist/core/model-routing-task.js +4 -3
- package/dist/core/model-routing-task.js.map +1 -1
- package/dist/core/prompt-templates-async.d.ts +2 -2
- package/dist/core/prompt-templates-async.d.ts.map +1 -1
- package/dist/core/prompt-templates-async.js +57 -29
- package/dist/core/prompt-templates-async.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +6 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +61 -35
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +1 -0
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +19 -0
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/resource-loader-assets.d.ts.map +1 -1
- package/dist/core/resource-loader-assets.js +6 -6
- package/dist/core/resource-loader-assets.js.map +1 -1
- package/dist/core/sdk.js +3 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +10 -3
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +65 -7
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +4 -1
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +8 -0
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +16 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +105 -42
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +30 -3
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/structured-output/index.d.ts +0 -1
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +3 -15
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/jev-client.d.ts +4 -8
- package/dist/core/structured-output/jev-client.d.ts.map +1 -1
- package/dist/core/structured-output/jev-client.js +36 -32
- package/dist/core/structured-output/jev-client.js.map +1 -1
- package/dist/core/structured-output/jev.d.ts.map +1 -1
- package/dist/core/structured-output/jev.js +4 -12
- package/dist/core/structured-output/jev.js.map +1 -1
- package/dist/core/structured-output/types.d.ts +0 -2
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +2 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +5 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/main-app-mode.d.ts +1 -1
- package/dist/main-app-mode.d.ts.map +1 -1
- package/dist/main-app-mode.js +3 -2
- package/dist/main-app-mode.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +4 -0
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +6 -0
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-model.js +1 -0
- package/dist/modes/interactive/components/tree-selector-model.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +17 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.js +16 -0
- package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +13 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +5 -1
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/utils/mime.js +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +3 -1
- package/dist/utils/tool-result-images.d.ts.map +1 -1
- package/dist/utils/tool-result-images.js +4 -1
- package/dist/utils/tool-result-images.js.map +1 -1
- package/docs/compaction.md +5 -1
- package/docs/computer-use.md +123 -73
- package/docs/extensions/events.md +75 -7
- package/docs/extensions.md +6 -2
- package/docs/getting-started/first-session.md +3 -2
- package/docs/getting-started/installation.md +6 -2
- package/docs/intercom/operations.md +13 -1
- package/docs/intercom.md +7 -2
- package/docs/models/evals.md +68 -82
- package/docs/models/model-selection.md +11 -7
- package/docs/models/reference.md +30 -2
- package/docs/packages.md +2 -0
- package/docs/prompt-templates.md +1 -0
- package/docs/providers.md +8 -2
- package/docs/quickstart.md +1 -1
- package/docs/sdk/reference.md +1 -2
- package/docs/sdk/structured-decisions.md +10 -9
- package/docs/sdk.md +13 -2
- package/docs/session-format.md +17 -2
- package/docs/settings.md +1 -1
- package/docs/skills.md +3 -1
- package/docs/subagents/reference.md +6 -6
- package/docs/subagents.md +8 -2
- package/docs/usage.md +2 -0
- package/docs/windows.md +1 -1
- package/docs/workflows/api-reference.md +5 -4
- package/docs/workflows/authoring.md +191 -0
- package/docs/workflows/builtins.md +2 -2
- package/docs/workflows/operations.md +10 -4
- package/docs/workflows/reliable-design.md +12 -1
- package/docs/workflows/verification.md +27 -14
- package/npm-shrinkwrap.json +69 -69
- package/package.json +8 -8
- package/dist/builtin/subagents/skills/playwright-cli/SKILL.md +0 -420
- package/dist/builtin/subagents/skills/playwright-cli/references/element-attributes.md +0 -23
- package/dist/builtin/subagents/skills/playwright-cli/references/playwright-tests.md +0 -39
- package/dist/builtin/subagents/skills/playwright-cli/references/request-mocking.md +0 -87
- package/dist/builtin/subagents/skills/playwright-cli/references/running-code.md +0 -241
- package/dist/builtin/subagents/skills/playwright-cli/references/session-management.md +0 -225
- package/dist/builtin/subagents/skills/playwright-cli/references/storage-state.md +0 -275
- package/dist/builtin/subagents/skills/playwright-cli/references/test-generation.md +0 -433
- package/dist/builtin/subagents/skills/playwright-cli/references/tracing.md +0 -139
- package/dist/builtin/subagents/skills/playwright-cli/references/video-recording.md +0 -143
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +0 -94
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +0 -27
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +0 -41
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_manual_edit_applier.toml +0 -95
- package/dist/builtin/workflows/skills/impeccable/agents/openai.yaml +0 -4
- package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +0 -695
- package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +0 -325
- package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +0 -1503
- package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +0 -222
- package/dist/builtin/workflows/skills/impeccable/scripts/detect-csp.mjs +0 -198
- package/dist/builtin/workflows/skills/impeccable/scripts/detect.mjs +0 -21
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +0 -2073
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +0 -432
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +0 -1121
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -8746
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns.mjs +0 -51
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -376
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -1168
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1192
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -290
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +0 -18
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +0 -213
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/profile/profiler.mjs +0 -166
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +0 -617
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +0 -5534
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/color.mjs +0 -588
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +0 -112
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/fonts.mjs +0 -30
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +0 -35
- package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +0 -338
- package/dist/builtin/workflows/skills/impeccable/scripts/embed-prompt.mjs +0 -270
- package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +0 -277
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +0 -783
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +0 -2305
- package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +0 -78
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +0 -93
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +0 -200
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +0 -395
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/design-parser.mjs +0 -925
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +0 -640
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +0 -137
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/is-generated.mjs +0 -72
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/open-system-browser.mjs +0 -57
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +0 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/roll-selection.mjs +0 -369
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +0 -483
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +0 -169
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +0 -528
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +0 -151
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-args.mjs +0 -42
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +0 -33
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +0 -146
- package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-css.mjs +0 -617
- package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-verify.mjs +0 -71
- package/dist/builtin/workflows/skills/impeccable/scripts/live/browser-script-parts.mjs +0 -77
- package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +0 -28
- package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +0 -199
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/astro.mjs +0 -47
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/detect-utils.mjs +0 -157
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/index.mjs +0 -143
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/journal.mjs +0 -205
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nextjs.mjs +0 -49
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nuxt.mjs +0 -170
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/script-src.mjs +0 -26
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/static-html.mjs +0 -26
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/sveltekit.mjs +0 -71
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tag-strategy.mjs +0 -247
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tanstack-start.mjs +0 -70
- package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/vite-generic.mjs +0 -42
- package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +0 -149
- package/dist/builtin/workflows/skills/impeccable/scripts/live/insert-ui.mjs +0 -458
- package/dist/builtin/workflows/skills/impeccable/scripts/live/instructions.mjs +0 -169
- package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-apply.mjs +0 -939
- package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
- package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
- package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +0 -14
- package/dist/builtin/workflows/skills/impeccable/scripts/live/roots.mjs +0 -670
- package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +0 -563
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +0 -105
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +0 -105
- package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-ast.mjs +0 -969
- package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-component.mjs +0 -1401
- package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +0 -314
- package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +0 -280
- package/dist/builtin/workflows/skills/impeccable/scripts/live/ui-surfaces.mjs +0 -75
- package/dist/builtin/workflows/skills/impeccable/scripts/live/vocabulary.mjs +0 -171
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +0 -961
- package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +0 -1244
- package/dist/builtin/workflows/skills/impeccable/scripts/live-complete.mjs +0 -107
- package/dist/builtin/workflows/skills/impeccable/scripts/live-copy-edit-agent.mjs +0 -800
- package/dist/builtin/workflows/skills/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
- package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +0 -515
- package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +0 -292
- package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +0 -371
- package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +0 -427
- package/dist/builtin/workflows/skills/impeccable/scripts/live-resume.mjs +0 -123
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +0 -1675
- package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +0 -71
- package/dist/builtin/workflows/skills/impeccable/scripts/live-target.mjs +0 -30
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +0 -927
- package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +0 -365
- package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +0 -628
- package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +0 -224
- package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +0 -1540
- package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +0 -74
|
@@ -23,17 +23,72 @@ function contextMessageFromEntry(entry) {
|
|
|
23
23
|
* tool results keep their full text and images stay as image blocks, because the tail
|
|
24
24
|
* is exactly the span `preserve_recent` promised to keep.
|
|
25
25
|
*/
|
|
26
|
-
function serializeKeptTail(entries) {
|
|
26
|
+
function serializeKeptTail(entries, edits) {
|
|
27
27
|
const messages = [];
|
|
28
28
|
for (const entry of entries) {
|
|
29
29
|
const message = contextMessageFromEntry(entry);
|
|
30
|
-
if (message)
|
|
30
|
+
if (!message)
|
|
31
|
+
continue;
|
|
32
|
+
const edit = edits?.get(entry.id);
|
|
33
|
+
if (edit)
|
|
34
|
+
messages.push(...applyContextEdit([message], edit));
|
|
35
|
+
else
|
|
31
36
|
messages.push(message);
|
|
32
37
|
}
|
|
33
38
|
if (messages.length === 0)
|
|
34
39
|
return [];
|
|
35
40
|
return serializeRetainedTranscript(convertToLlm(messages));
|
|
36
41
|
}
|
|
42
|
+
/** Index the latest context edit per target among the given entries. */
|
|
43
|
+
export function collectContextEdits(entries) {
|
|
44
|
+
const edits = new Map();
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (entry.type === "context_edit")
|
|
47
|
+
edits.set(entry.targetId, entry);
|
|
48
|
+
}
|
|
49
|
+
return edits;
|
|
50
|
+
}
|
|
51
|
+
/** Apply one append-only context edit to the messages an entry contributes. */
|
|
52
|
+
export function applyContextEdit(messages, edit) {
|
|
53
|
+
const replacement = edit.replacement;
|
|
54
|
+
if (replacement === null)
|
|
55
|
+
return [];
|
|
56
|
+
return messages.map((message) => {
|
|
57
|
+
if (message.role !== "user" &&
|
|
58
|
+
message.role !== "assistant" &&
|
|
59
|
+
message.role !== "toolResult" &&
|
|
60
|
+
message.role !== "custom") {
|
|
61
|
+
return message;
|
|
62
|
+
}
|
|
63
|
+
const content = (message.role === "assistant" || message.role === "toolResult") && typeof replacement.content === "string"
|
|
64
|
+
? [{ type: "text", text: replacement.content }]
|
|
65
|
+
: replacement.content;
|
|
66
|
+
return { ...message, content };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function projectContextEntry(entry, edit) {
|
|
70
|
+
const messages = sessionEntryToContextMessages(entry);
|
|
71
|
+
if (!edit)
|
|
72
|
+
return messages;
|
|
73
|
+
return applyContextEdit(messages, edit);
|
|
74
|
+
}
|
|
75
|
+
/** Extract the settings (thinking level and model) recorded along a branch path. */
|
|
76
|
+
function getSessionContextSettings(path) {
|
|
77
|
+
let thinkingLevel = "off";
|
|
78
|
+
let model = null;
|
|
79
|
+
for (const entry of path) {
|
|
80
|
+
if (entry.type === "thinking_level_change") {
|
|
81
|
+
thinkingLevel = entry.thinkingLevel;
|
|
82
|
+
}
|
|
83
|
+
else if (entry.type === "model_change") {
|
|
84
|
+
model = { provider: entry.provider, modelId: entry.modelId };
|
|
85
|
+
}
|
|
86
|
+
else if (entry.type === "message" && entry.message.role === "assistant") {
|
|
87
|
+
model = { provider: entry.message.provider, modelId: entry.message.model };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { thinkingLevel, model };
|
|
91
|
+
}
|
|
37
92
|
export function getLatestCompactionBoundaryEntry(entries) {
|
|
38
93
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
39
94
|
const entry = entries[i];
|
|
@@ -88,13 +143,16 @@ export function buildContextEntries(entries, leafId, byId = new Map(entries.map(
|
|
|
88
143
|
];
|
|
89
144
|
}
|
|
90
145
|
/**
|
|
91
|
-
* Build
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
146
|
+
* Build provenance-preserving, compaction-aware model context.
|
|
147
|
+
*
|
|
148
|
+
* Every entry on the active branch after the latest compaction boundary is projected
|
|
149
|
+
* to the messages it contributes after context edits. The latest verbatim compaction
|
|
150
|
+
* boundary is emitted as one custom-role text message: the compacted string with the
|
|
151
|
+
* kept tail (edits applied) serialized and appended to its end, rather than the tail
|
|
152
|
+
* being replayed as separate structured messages. Kept-tail entries therefore project
|
|
153
|
+
* to no standalone messages of their own.
|
|
96
154
|
*/
|
|
97
|
-
export function
|
|
155
|
+
export function buildSessionProjection(entries, leafId, byId) {
|
|
98
156
|
// Build uuid index if not available
|
|
99
157
|
if (!byId) {
|
|
100
158
|
byId = new Map();
|
|
@@ -106,7 +164,7 @@ export function buildSessionContext(entries, leafId, byId) {
|
|
|
106
164
|
let leaf;
|
|
107
165
|
if (leafId === null) {
|
|
108
166
|
// Explicitly null - return no messages (navigated to before first entry)
|
|
109
|
-
return { messages: [], thinkingLevel: "off", model: null };
|
|
167
|
+
return { entries: [], messages: [], thinkingLevel: "off", model: null };
|
|
110
168
|
}
|
|
111
169
|
if (leafId) {
|
|
112
170
|
leaf = byId.get(leafId);
|
|
@@ -116,48 +174,53 @@ export function buildSessionContext(entries, leafId, byId) {
|
|
|
116
174
|
leaf = entries[entries.length - 1];
|
|
117
175
|
}
|
|
118
176
|
if (!leaf) {
|
|
119
|
-
return { messages: [], thinkingLevel: "off", model: null };
|
|
177
|
+
return { entries: [], messages: [], thinkingLevel: "off", model: null };
|
|
120
178
|
}
|
|
121
179
|
// Walk from leaf to root, collecting path
|
|
122
180
|
const path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const entry of path) {
|
|
127
|
-
if (entry.type === "thinking_level_change") {
|
|
128
|
-
thinkingLevel = entry.thinkingLevel;
|
|
129
|
-
}
|
|
130
|
-
else if (entry.type === "model_change") {
|
|
131
|
-
model = { provider: entry.provider, modelId: entry.modelId };
|
|
132
|
-
}
|
|
133
|
-
else if (entry.type === "message" && entry.message.role === "assistant") {
|
|
134
|
-
model = { provider: entry.message.provider, modelId: entry.message.model };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const messages = [];
|
|
138
|
-
const appendMessage = (entry) => {
|
|
139
|
-
const message = contextMessageFromEntry(entry);
|
|
140
|
-
if (message)
|
|
141
|
-
messages.push(message);
|
|
142
|
-
};
|
|
181
|
+
const { thinkingLevel, model } = getSessionContextSettings(path);
|
|
182
|
+
const contextEntries = buildContextEntries(entries, leaf.id, byId);
|
|
183
|
+
const edits = collectContextEdits(contextEntries);
|
|
143
184
|
const boundary = getLatestCompactionBoundaryEntry(path);
|
|
144
185
|
if (!boundary) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
186
|
+
const projected = contextEntries.map((sourceEntry) => ({
|
|
187
|
+
sourceEntry,
|
|
188
|
+
messages: projectContextEntry(sourceEntry, edits.get(sourceEntry.id)),
|
|
189
|
+
}));
|
|
190
|
+
return { entries: projected, messages: projected.flatMap((entry) => entry.messages), thinkingLevel, model };
|
|
148
191
|
}
|
|
149
192
|
const boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);
|
|
150
193
|
const firstKeptIndex = path.findIndex((entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId);
|
|
151
|
-
const
|
|
194
|
+
const keptTailEntries = firstKeptIndex >= 0 ? path.slice(firstKeptIndex, boundaryIndex) : [];
|
|
195
|
+
const keptTailIds = new Set(keptTailEntries.map((entry) => entry.id));
|
|
196
|
+
const keptTail = serializeKeptTail(keptTailEntries, edits);
|
|
152
197
|
const separator = keptTail.length > 0 && boundary.summary.length > 0 ? [{ type: "text", text: "\n\n" }] : [];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
198
|
+
const boundaryMessages = [
|
|
199
|
+
...(boundary.systemMessage ? [boundary.systemMessage] : []),
|
|
200
|
+
createVerbatimCompactionMessage(boundary.summary, boundary.tokensBefore, boundary.timestamp, boundary.details, [
|
|
201
|
+
...separator,
|
|
202
|
+
...keptTail,
|
|
203
|
+
]),
|
|
204
|
+
];
|
|
205
|
+
const projected = contextEntries.map((sourceEntry) => ({
|
|
206
|
+
sourceEntry,
|
|
207
|
+
messages: sourceEntry.id === boundary.id
|
|
208
|
+
? boundaryMessages
|
|
209
|
+
: keptTailIds.has(sourceEntry.id)
|
|
210
|
+
? []
|
|
211
|
+
: projectContextEntry(sourceEntry, edits.get(sourceEntry.id)),
|
|
212
|
+
}));
|
|
213
|
+
return { entries: projected, messages: projected.flatMap((entry) => entry.messages), thinkingLevel, model };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Build the session context from entries using tree traversal.
|
|
217
|
+
* If leafId is provided, walks from that entry to root.
|
|
218
|
+
* Emits the latest verbatim compaction boundary as one custom-role text message: the
|
|
219
|
+
* compacted string with the kept tail serialized and appended to its end, rather than
|
|
220
|
+
* the tail being replayed as separate structured messages.
|
|
221
|
+
*/
|
|
222
|
+
export function buildSessionContext(entries, leafId, byId) {
|
|
223
|
+
const { messages, thinkingLevel, model } = buildSessionProjection(entries, leafId, byId);
|
|
161
224
|
return { messages, thinkingLevel, model };
|
|
162
225
|
}
|
|
163
226
|
export function buildSessionIndex(fileEntries) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-history.js","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAwB,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EACN,YAAY,EACZ,0BAA0B,EAC1B,mBAAmB,EACnB,+BAA+B,EAC/B,uBAAuB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AASlF,4EAA4E;AAC5E,SAAS,uBAAuB,CAAC,KAAmB;IACnD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5E,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACrC,OAAO,mBAAmB,CACzB,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,iBAAiB,CACvB,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtG,OAAO,0BAA0B,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAA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OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nimport { serializeRetainedTranscript, type TranscriptChunk } from \"./compaction/transcript-serialization.js\";\nimport {\n\tconvertToLlm,\n\tcreateBranchSummaryMessage,\n\tcreateCustomMessage,\n\tcreateVerbatimCompactionMessage,\n\tnormalizeMessageContent,\n} from \"./messages.ts\";\nimport { normalizeDerivedSessionEntries } from \"./session-entry-normalization.ts\";\nimport type {\n\tCompactionEntry,\n\tFileEntry,\n\tSessionContext,\n\tSessionEntry,\n\tSessionTreeNode,\n} from \"./session-manager-types.ts\";\n\n/** Build the single context message a durable entry contributes, if any. */\nfunction contextMessageFromEntry(entry: SessionEntry): AgentMessage | undefined {\n\tif (entry.type === \"message\") return normalizeMessageContent(entry.message);\n\tif (entry.type === \"custom_message\") {\n\t\treturn createCustomMessage(\n\t\t\tentry.customType,\n\t\t\tentry.content,\n\t\t\tentry.display,\n\t\t\tentry.details,\n\t\t\tentry.timestamp,\n\t\t\tentry.excludeFromContext,\n\t\t\tentry.stageAdmissionKey,\n\t\t);\n\t}\n\tif (entry.type === \"branch_summary\" && typeof entry.summary === \"string\" && entry.summary.length > 0) {\n\t\treturn createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\t}\n\treturn undefined;\n}\n\n/**\n * Serialize the kept tail into the compaction boundary's transcript grammar.\n *\n * The tail is concatenated onto the end of the boundary string instead of being\n * replayed as structured messages. A tail that starts mid-turn (a tool result whose\n * tool call was compacted away, or a trailing unanswered tool call) would otherwise\n * emit ill-ordered provider blocks and fail the request. Serialization is lossless:\n * tool results keep their full text and images stay as image blocks, because the tail\n * is exactly the span `preserve_recent` promised to keep.\n */\nfunction serializeKeptTail(entries: SessionEntry[]): TranscriptChunk[] {\n\tconst messages: AgentMessage[] = [];\n\tfor (const entry of entries) {\n\t\tconst message = contextMessageFromEntry(entry);\n\t\tif (message) messages.push(message);\n\t}\n\tif (messages.length === 0) return [];\n\treturn serializeRetainedTranscript(convertToLlm(messages));\n}\n\nexport function getLatestCompactionBoundaryEntry(\n\tentries: SessionEntry[],\n): CompactionEntry<VerbatimCompactionDetails> | null {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type !== \"compaction\") continue;\n\t\tconst details = (entry as CompactionEntry<{ strategy?: string }>).details;\n\t\tif (details?.strategy === \"verbatim-lines\") return entry as CompactionEntry<VerbatimCompactionDetails>;\n\t}\n\treturn null;\n}\n\n/** Convert one durable session entry into the messages it contributes to model context. */\nexport function sessionEntryToContextMessages(entry: SessionEntry): AgentMessage[] {\n\tif (entry.type === \"message\") return [normalizeMessageContent(entry.message)];\n\tif (entry.type === \"custom_message\") {\n\t\treturn [\n\t\t\tcreateCustomMessage(\n\t\t\t\tentry.customType,\n\t\t\t\tentry.content,\n\t\t\t\tentry.display,\n\t\t\t\tentry.details,\n\t\t\t\tentry.timestamp,\n\t\t\t\tentry.excludeFromContext,\n\t\t\t\tentry.stageAdmissionKey,\n\t\t\t),\n\t\t];\n\t}\n\tif (entry.type === \"branch_summary\" && entry.summary.length > 0) {\n\t\treturn [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)];\n\t}\n\tif (entry.type === \"compaction\") {\n\t\tconst details = (entry as CompactionEntry<{ strategy?: string }>).details;\n\t\tif (details?.strategy === \"verbatim-lines\") {\n\t\t\treturn [\n\t\t\t\t...(entry.systemMessage ? [entry.systemMessage] : []),\n\t\t\t\tcreateVerbatimCompactionMessage(\n\t\t\t\t\tentry.summary,\n\t\t\t\t\tentry.tokensBefore,\n\t\t\t\t\tentry.timestamp,\n\t\t\t\t\tentry.details as VerbatimCompactionDetails,\n\t\t\t\t),\n\t\t\t];\n\t\t}\n\t}\n\treturn [];\n}\n\n/** Return the active branch entries after applying the latest compaction boundary. */\nexport function buildContextEntries(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId = new Map(entries.map((entry) => [entry.id, entry])),\n): SessionEntry[] {\n\tif (leafId === null) return [];\n\tconst leaf = leafId ? byId.get(leafId) : entries[entries.length - 1];\n\tif (!leaf) return [];\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\tconst boundary = getLatestCompactionBoundaryEntry(path);\n\tif (!boundary) return path;\n\tconst boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);\n\tconst firstKeptIndex = path.findIndex(\n\t\t(entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId,\n\t);\n\treturn [\n\t\tboundary,\n\t\t...(firstKeptIndex >= 0 ? path.slice(firstKeptIndex, boundaryIndex) : []),\n\t\t...path.slice(boundaryIndex + 1),\n\t];\n}\n\n/**\n * Build the session context from entries using tree traversal.\n * If leafId is provided, walks from that entry to root.\n * Emits the latest verbatim compaction boundary as one custom-role text message: the\n * compacted string with the kept tail serialized and appended to its end, rather than\n * the tail being replayed as separate structured messages.\n */\nexport function buildSessionContext(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionContext {\n\t// Build uuid index if not available\n\tif (!byId) {\n\t\tbyId = new Map<string, SessionEntry>();\n\t\tfor (const entry of entries) {\n\t\t\tbyId.set(entry.id, entry);\n\t\t}\n\t}\n\n\t// Find leaf\n\tlet leaf: SessionEntry | undefined;\n\tif (leafId === null) {\n\t\t// Explicitly null - return no messages (navigated to before first entry)\n\t\treturn { messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\tif (leafId) {\n\t\tleaf = byId.get(leafId);\n\t}\n\tif (!leaf) {\n\t\t// Fallback to last entry (when leafId is undefined)\n\t\tleaf = entries[entries.length - 1];\n\t}\n\n\tif (!leaf) {\n\t\treturn { messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\n\t// Walk from leaf to root, collecting path\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\n\t// Extract settings\n\tlet thinkingLevel = \"off\";\n\tlet model: { provider: string; modelId: string } | null = null;\n\n\tfor (const entry of path) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t}\n\t}\n\n\tconst messages: AgentMessage[] = [];\n\tconst appendMessage = (entry: SessionEntry): void => {\n\t\tconst message = contextMessageFromEntry(entry);\n\t\tif (message) messages.push(message);\n\t};\n\n\tconst boundary = getLatestCompactionBoundaryEntry(path);\n\tif (!boundary) {\n\t\tfor (const entry of path) appendMessage(entry);\n\t\treturn { messages, thinkingLevel, model };\n\t}\n\n\tconst boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);\n\tconst firstKeptIndex = path.findIndex(\n\t\t(entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId,\n\t);\n\tconst keptTail = firstKeptIndex >= 0 ? serializeKeptTail(path.slice(firstKeptIndex, boundaryIndex)) : [];\n\tconst separator: TranscriptChunk[] =\n\t\tkeptTail.length > 0 && boundary.summary.length > 0 ? [{ type: \"text\", text: \"\\n\\n\" }] : [];\n\tif (boundary.systemMessage) messages.push(boundary.systemMessage);\n\tmessages.push(\n\t\tcreateVerbatimCompactionMessage(boundary.summary, boundary.tokensBefore, boundary.timestamp, boundary.details, [\n\t\t\t...separator,\n\t\t\t...keptTail,\n\t\t]),\n\t);\n\tfor (let i = boundaryIndex + 1; i < path.length; i++) appendMessage(path[i]);\n\n\treturn { messages, thinkingLevel, model };\n}\n\nexport interface SessionIndex {\n\tbyId: Map<string, SessionEntry>;\n\tlabelsById: Map<string, string>;\n\tlabelTimestampsById: Map<string, string>;\n\tleafId: string | null;\n}\n\nexport function buildSessionIndex(fileEntries: FileEntry[]): SessionIndex {\n\tconst byId = new Map<string, SessionEntry>();\n\tconst labelsById = new Map<string, string>();\n\tconst labelTimestampsById = new Map<string, string>();\n\tlet leafId: string | null = null;\n\n\tfor (const entry of fileEntries) {\n\t\tif (entry.type === \"session\") continue;\n\t\tbyId.set(entry.id, entry);\n\t\tleafId = entry.id;\n\t\tif (entry.type === \"label\") {\n\t\t\tif (entry.label) {\n\t\t\t\tlabelsById.set(entry.targetId, entry.label);\n\t\t\t\tlabelTimestampsById.set(entry.targetId, entry.timestamp);\n\t\t\t} else {\n\t\t\t\tlabelsById.delete(entry.targetId);\n\t\t\t\tlabelTimestampsById.delete(entry.targetId);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { byId, labelsById, labelTimestampsById, leafId };\n}\n\nexport function getBranchPath(fromId: string | null | undefined, byId: Map<string, SessionEntry>): SessionEntry[] {\n\tconst path: SessionEntry[] = [];\n\tlet current = fromId ? byId.get(fromId) : undefined;\n\twhile (current) {\n\t\tpath.push(current);\n\t\tcurrent = current.parentId ? byId.get(current.parentId) : undefined;\n\t}\n\tpath.reverse();\n\treturn path;\n}\n\nexport function buildSessionTree(\n\tentries: SessionEntry[],\n\tlabelsById: ReadonlyMap<string, string>,\n\tlabelTimestampsById: ReadonlyMap<string, string>,\n): SessionTreeNode[] {\n\tconst nodeMap = new Map<string, SessionTreeNode>();\n\tconst roots: SessionTreeNode[] = [];\n\n\t// Create nodes with resolved labels\n\tfor (const entry of entries) {\n\t\tconst label = labelsById.get(entry.id);\n\t\tconst labelTimestamp = labelTimestampsById.get(entry.id);\n\t\tnodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });\n\t}\n\n\t// Build tree\n\tfor (const entry of entries) {\n\t\tconst node = nodeMap.get(entry.id)!;\n\t\tif (entry.parentId === null || entry.parentId === entry.id) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\tif (parent) {\n\t\t\t\tparent.children.push(node);\n\t\t\t} else {\n\t\t\t\t// Orphan - treat as root\n\t\t\t\troots.push(node);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Sort children by timestamp (oldest first, newest at bottom)\n\t// Use iterative approach to avoid stack overflow on deep trees\n\tconst stack: SessionTreeNode[] = [...roots];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop()!;\n\t\tnode.children.sort((a, b) => new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime());\n\t\tstack.push(...node.children);\n\t}\n\n\treturn roots;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-manager-history.js","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAwB,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EACN,YAAY,EACZ,0BAA0B,EAC1B,mBAAmB,EACnB,+BAA+B,EAC/B,uBAAuB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAYlF,4EAA4E;AAC5E,SAAS,uBAAuB,CAAC,KAAmB;IACnD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5E,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACrC,OAAO,mBAAmB,CACzB,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,iBAAiB,CACvB,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtG,OAAO,0BAA0B,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAA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I,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5G,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nimport { serializeRetainedTranscript, type TranscriptChunk } from \"./compaction/transcript-serialization.js\";\nimport {\n\tconvertToLlm,\n\tcreateBranchSummaryMessage,\n\tcreateCustomMessage,\n\tcreateVerbatimCompactionMessage,\n\tnormalizeMessageContent,\n} from \"./messages.ts\";\nimport { normalizeDerivedSessionEntries } from \"./session-entry-normalization.ts\";\nimport type {\n\tCompactionEntry,\n\tContextEditEntry,\n\tFileEntry,\n\tProjectedSessionEntry,\n\tSessionContext,\n\tSessionEntry,\n\tSessionProjection,\n\tSessionTreeNode,\n} from \"./session-manager-types.ts\";\n\n/** Build the single context message a durable entry contributes, if any. */\nfunction contextMessageFromEntry(entry: SessionEntry): AgentMessage | undefined {\n\tif (entry.type === \"message\") return normalizeMessageContent(entry.message);\n\tif (entry.type === \"custom_message\") {\n\t\treturn createCustomMessage(\n\t\t\tentry.customType,\n\t\t\tentry.content,\n\t\t\tentry.display,\n\t\t\tentry.details,\n\t\t\tentry.timestamp,\n\t\t\tentry.excludeFromContext,\n\t\t\tentry.stageAdmissionKey,\n\t\t);\n\t}\n\tif (entry.type === \"branch_summary\" && typeof entry.summary === \"string\" && entry.summary.length > 0) {\n\t\treturn createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\t}\n\treturn undefined;\n}\n\n/**\n * Serialize the kept tail into the compaction boundary's transcript grammar.\n *\n * The tail is concatenated onto the end of the boundary string instead of being\n * replayed as structured messages. A tail that starts mid-turn (a tool result whose\n * tool call was compacted away, or a trailing unanswered tool call) would otherwise\n * emit ill-ordered provider blocks and fail the request. Serialization is lossless:\n * tool results keep their full text and images stay as image blocks, because the tail\n * is exactly the span `preserve_recent` promised to keep.\n */\nfunction serializeKeptTail(entries: SessionEntry[], edits?: Map<string, ContextEditEntry>): TranscriptChunk[] {\n\tconst messages: AgentMessage[] = [];\n\tfor (const entry of entries) {\n\t\tconst message = contextMessageFromEntry(entry);\n\t\tif (!message) continue;\n\t\tconst edit = edits?.get(entry.id);\n\t\tif (edit) messages.push(...applyContextEdit([message], edit));\n\t\telse messages.push(message);\n\t}\n\tif (messages.length === 0) return [];\n\treturn serializeRetainedTranscript(convertToLlm(messages));\n}\n\n/** Index the latest context edit per target among the given entries. */\nexport function collectContextEdits(entries: readonly SessionEntry[]): Map<string, ContextEditEntry> {\n\tconst edits = new Map<string, ContextEditEntry>();\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"context_edit\") edits.set(entry.targetId, entry);\n\t}\n\treturn edits;\n}\n\n/** Apply one append-only context edit to the messages an entry contributes. */\nexport function applyContextEdit(messages: AgentMessage[], edit: ContextEditEntry): AgentMessage[] {\n\tconst replacement = edit.replacement;\n\tif (replacement === null) return [];\n\n\treturn messages.map((message) => {\n\t\tif (\n\t\t\tmessage.role !== \"user\" &&\n\t\t\tmessage.role !== \"assistant\" &&\n\t\t\tmessage.role !== \"toolResult\" &&\n\t\t\tmessage.role !== \"custom\"\n\t\t) {\n\t\t\treturn message;\n\t\t}\n\t\tconst content =\n\t\t\t(message.role === \"assistant\" || message.role === \"toolResult\") && typeof replacement.content === \"string\"\n\t\t\t\t? [{ type: \"text\" as const, text: replacement.content }]\n\t\t\t\t: replacement.content;\n\t\treturn { ...message, content } as AgentMessage;\n\t});\n}\n\nfunction projectContextEntry(entry: SessionEntry, edit: ContextEditEntry | undefined): AgentMessage[] {\n\tconst messages = sessionEntryToContextMessages(entry);\n\tif (!edit) return messages;\n\treturn applyContextEdit(messages, edit);\n}\n\n/** Extract the settings (thinking level and model) recorded along a branch path. */\nfunction getSessionContextSettings(path: SessionEntry[]): {\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n} {\n\tlet thinkingLevel = \"off\";\n\tlet model: { provider: string; modelId: string } | null = null;\n\tfor (const entry of path) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t}\n\t}\n\treturn { thinkingLevel, model };\n}\n\nexport function getLatestCompactionBoundaryEntry(\n\tentries: SessionEntry[],\n): CompactionEntry<VerbatimCompactionDetails> | null {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type !== \"compaction\") continue;\n\t\tconst details = (entry as CompactionEntry<{ strategy?: string }>).details;\n\t\tif (details?.strategy === \"verbatim-lines\") return entry as CompactionEntry<VerbatimCompactionDetails>;\n\t}\n\treturn null;\n}\n\n/** Convert one durable session entry into the messages it contributes to model context. */\nexport function sessionEntryToContextMessages(entry: SessionEntry): AgentMessage[] {\n\tif (entry.type === \"message\") return [normalizeMessageContent(entry.message)];\n\tif (entry.type === \"custom_message\") {\n\t\treturn [\n\t\t\tcreateCustomMessage(\n\t\t\t\tentry.customType,\n\t\t\t\tentry.content,\n\t\t\t\tentry.display,\n\t\t\t\tentry.details,\n\t\t\t\tentry.timestamp,\n\t\t\t\tentry.excludeFromContext,\n\t\t\t\tentry.stageAdmissionKey,\n\t\t\t),\n\t\t];\n\t}\n\tif (entry.type === \"branch_summary\" && entry.summary.length > 0) {\n\t\treturn [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)];\n\t}\n\tif (entry.type === \"compaction\") {\n\t\tconst details = (entry as CompactionEntry<{ strategy?: string }>).details;\n\t\tif (details?.strategy === \"verbatim-lines\") {\n\t\t\treturn [\n\t\t\t\t...(entry.systemMessage ? [entry.systemMessage] : []),\n\t\t\t\tcreateVerbatimCompactionMessage(\n\t\t\t\t\tentry.summary,\n\t\t\t\t\tentry.tokensBefore,\n\t\t\t\t\tentry.timestamp,\n\t\t\t\t\tentry.details as VerbatimCompactionDetails,\n\t\t\t\t),\n\t\t\t];\n\t\t}\n\t}\n\treturn [];\n}\n\n/** Return the active branch entries after applying the latest compaction boundary. */\nexport function buildContextEntries(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId = new Map(entries.map((entry) => [entry.id, entry])),\n): SessionEntry[] {\n\tif (leafId === null) return [];\n\tconst leaf = leafId ? byId.get(leafId) : entries[entries.length - 1];\n\tif (!leaf) return [];\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\tconst boundary = getLatestCompactionBoundaryEntry(path);\n\tif (!boundary) return path;\n\tconst boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);\n\tconst firstKeptIndex = path.findIndex(\n\t\t(entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId,\n\t);\n\treturn [\n\t\tboundary,\n\t\t...(firstKeptIndex >= 0 ? path.slice(firstKeptIndex, boundaryIndex) : []),\n\t\t...path.slice(boundaryIndex + 1),\n\t];\n}\n\n/**\n * Build provenance-preserving, compaction-aware model context.\n *\n * Every entry on the active branch after the latest compaction boundary is projected\n * to the messages it contributes after context edits. The latest verbatim compaction\n * boundary is emitted as one custom-role text message: the compacted string with the\n * kept tail (edits applied) serialized and appended to its end, rather than the tail\n * being replayed as separate structured messages. Kept-tail entries therefore project\n * to no standalone messages of their own.\n */\nexport function buildSessionProjection(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionProjection {\n\t// Build uuid index if not available\n\tif (!byId) {\n\t\tbyId = new Map<string, SessionEntry>();\n\t\tfor (const entry of entries) {\n\t\t\tbyId.set(entry.id, entry);\n\t\t}\n\t}\n\n\t// Find leaf\n\tlet leaf: SessionEntry | undefined;\n\tif (leafId === null) {\n\t\t// Explicitly null - return no messages (navigated to before first entry)\n\t\treturn { entries: [], messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\tif (leafId) {\n\t\tleaf = byId.get(leafId);\n\t}\n\tif (!leaf) {\n\t\t// Fallback to last entry (when leafId is undefined)\n\t\tleaf = entries[entries.length - 1];\n\t}\n\n\tif (!leaf) {\n\t\treturn { entries: [], messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\n\t// Walk from leaf to root, collecting path\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\tconst { thinkingLevel, model } = getSessionContextSettings(path);\n\tconst contextEntries = buildContextEntries(entries, leaf.id, byId);\n\tconst edits = collectContextEdits(contextEntries);\n\n\tconst boundary = getLatestCompactionBoundaryEntry(path);\n\tif (!boundary) {\n\t\tconst projected = contextEntries.map(\n\t\t\t(sourceEntry): ProjectedSessionEntry => ({\n\t\t\t\tsourceEntry,\n\t\t\t\tmessages: projectContextEntry(sourceEntry, edits.get(sourceEntry.id)),\n\t\t\t}),\n\t\t);\n\t\treturn { entries: projected, messages: projected.flatMap((entry) => entry.messages), thinkingLevel, model };\n\t}\n\n\tconst boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);\n\tconst firstKeptIndex = path.findIndex(\n\t\t(entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId,\n\t);\n\tconst keptTailEntries = firstKeptIndex >= 0 ? path.slice(firstKeptIndex, boundaryIndex) : [];\n\tconst keptTailIds = new Set(keptTailEntries.map((entry) => entry.id));\n\tconst keptTail = serializeKeptTail(keptTailEntries, edits);\n\tconst separator: TranscriptChunk[] =\n\t\tkeptTail.length > 0 && boundary.summary.length > 0 ? [{ type: \"text\", text: \"\\n\\n\" }] : [];\n\tconst boundaryMessages: AgentMessage[] = [\n\t\t...(boundary.systemMessage ? [boundary.systemMessage] : []),\n\t\tcreateVerbatimCompactionMessage(boundary.summary, boundary.tokensBefore, boundary.timestamp, boundary.details, [\n\t\t\t...separator,\n\t\t\t...keptTail,\n\t\t]),\n\t];\n\tconst projected = contextEntries.map(\n\t\t(sourceEntry): ProjectedSessionEntry => ({\n\t\t\tsourceEntry,\n\t\t\tmessages:\n\t\t\t\tsourceEntry.id === boundary.id\n\t\t\t\t\t? boundaryMessages\n\t\t\t\t\t: keptTailIds.has(sourceEntry.id)\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: projectContextEntry(sourceEntry, edits.get(sourceEntry.id)),\n\t\t}),\n\t);\n\treturn { entries: projected, messages: projected.flatMap((entry) => entry.messages), thinkingLevel, model };\n}\n\n/**\n * Build the session context from entries using tree traversal.\n * If leafId is provided, walks from that entry to root.\n * Emits the latest verbatim compaction boundary as one custom-role text message: the\n * compacted string with the kept tail serialized and appended to its end, rather than\n * the tail being replayed as separate structured messages.\n */\nexport function buildSessionContext(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionContext {\n\tconst { messages, thinkingLevel, model } = buildSessionProjection(entries, leafId, byId);\n\treturn { messages, thinkingLevel, model };\n}\n\nexport interface SessionIndex {\n\tbyId: Map<string, SessionEntry>;\n\tlabelsById: Map<string, string>;\n\tlabelTimestampsById: Map<string, string>;\n\tleafId: string | null;\n}\n\nexport function buildSessionIndex(fileEntries: FileEntry[]): SessionIndex {\n\tconst byId = new Map<string, SessionEntry>();\n\tconst labelsById = new Map<string, string>();\n\tconst labelTimestampsById = new Map<string, string>();\n\tlet leafId: string | null = null;\n\n\tfor (const entry of fileEntries) {\n\t\tif (entry.type === \"session\") continue;\n\t\tbyId.set(entry.id, entry);\n\t\tleafId = entry.id;\n\t\tif (entry.type === \"label\") {\n\t\t\tif (entry.label) {\n\t\t\t\tlabelsById.set(entry.targetId, entry.label);\n\t\t\t\tlabelTimestampsById.set(entry.targetId, entry.timestamp);\n\t\t\t} else {\n\t\t\t\tlabelsById.delete(entry.targetId);\n\t\t\t\tlabelTimestampsById.delete(entry.targetId);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { byId, labelsById, labelTimestampsById, leafId };\n}\n\nexport function getBranchPath(fromId: string | null | undefined, byId: Map<string, SessionEntry>): SessionEntry[] {\n\tconst path: SessionEntry[] = [];\n\tlet current = fromId ? byId.get(fromId) : undefined;\n\twhile (current) {\n\t\tpath.push(current);\n\t\tcurrent = current.parentId ? byId.get(current.parentId) : undefined;\n\t}\n\tpath.reverse();\n\treturn path;\n}\n\nexport function buildSessionTree(\n\tentries: SessionEntry[],\n\tlabelsById: ReadonlyMap<string, string>,\n\tlabelTimestampsById: ReadonlyMap<string, string>,\n): SessionTreeNode[] {\n\tconst nodeMap = new Map<string, SessionTreeNode>();\n\tconst roots: SessionTreeNode[] = [];\n\n\t// Create nodes with resolved labels\n\tfor (const entry of entries) {\n\t\tconst label = labelsById.get(entry.id);\n\t\tconst labelTimestamp = labelTimestampsById.get(entry.id);\n\t\tnodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });\n\t}\n\n\t// Build tree\n\tfor (const entry of entries) {\n\t\tconst node = nodeMap.get(entry.id)!;\n\t\tif (entry.parentId === null || entry.parentId === entry.id) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\tif (parent) {\n\t\t\t\tparent.children.push(node);\n\t\t\t} else {\n\t\t\t\t// Orphan - treat as root\n\t\t\t\troots.push(node);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Sort children by timestamp (oldest first, newest at bottom)\n\t// Use iterative approach to avoid stack overflow on deep trees\n\tconst stack: SessionTreeNode[] = [...roots];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop()!;\n\t\tnode.children.sort((a, b) => new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime());\n\t\tstack.push(...node.children);\n\t}\n\n\treturn roots;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ImageContent, SystemMessage, TextContent, Usage } from "@bastani/pi-ai/compat";
|
|
1
|
+
import type { AssistantMessage, ImageContent, SystemMessage, TextContent, ToolResultMessage, Usage, UserMessage } from "@bastani/pi-ai/compat";
|
|
2
2
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import type { CustomMessage } from "./messages.ts";
|
|
3
4
|
import type { SessionManager } from "./session-manager-core.ts";
|
|
4
5
|
export declare const CURRENT_SESSION_VERSION = 3;
|
|
5
6
|
/**
|
|
@@ -189,8 +190,19 @@ export interface CustomMessageEntry<T = unknown> extends SessionEntryBase {
|
|
|
189
190
|
/** Internal crash-recovery marker for a model-facing protected turn. */
|
|
190
191
|
protectedReconciliation?: ProtectedReconciliationMarker;
|
|
191
192
|
}
|
|
193
|
+
/** Content that an append-only context edit may replace without changing message metadata. */
|
|
194
|
+
export type ContextEditableContent = UserMessage["content"] | AssistantMessage["content"] | ToolResultMessage["content"] | CustomMessage["content"];
|
|
195
|
+
/** Append-only change to one earlier entry's contribution to model context. */
|
|
196
|
+
export interface ContextEditEntry extends SessionEntryBase {
|
|
197
|
+
type: "context_edit";
|
|
198
|
+
targetId: string;
|
|
199
|
+
/** Null omits the target from model context. A value replaces only its content. */
|
|
200
|
+
replacement: {
|
|
201
|
+
content: ContextEditableContent;
|
|
202
|
+
} | null;
|
|
203
|
+
}
|
|
192
204
|
/** Session entry - has id/parentId for tree structure (returned by "read" methods in SessionManager) */
|
|
193
|
-
export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | UsageEntry | CompactionEntry | ContextCompactionEntry | BranchSummaryEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry | SessionSummaryEntry;
|
|
205
|
+
export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | UsageEntry | CompactionEntry | ContextCompactionEntry | BranchSummaryEntry | CustomEntry | CustomMessageEntry | ContextEditEntry | LabelEntry | SessionInfoEntry | SessionSummaryEntry;
|
|
194
206
|
/** Raw file entry (includes header) */
|
|
195
207
|
export type FileEntry = SessionHeader | SessionEntry;
|
|
196
208
|
/** Tree node for getTree() - defensive copy of session structure */
|
|
@@ -202,6 +214,21 @@ export interface SessionTreeNode {
|
|
|
202
214
|
/** Timestamp of the latest label change for this entry, if any */
|
|
203
215
|
labelTimestamp?: string;
|
|
204
216
|
}
|
|
217
|
+
export interface ProjectedSessionEntry {
|
|
218
|
+
/** Raw append-only entry that owns this projected contribution. */
|
|
219
|
+
sourceEntry: SessionEntry;
|
|
220
|
+
/** Model-visible messages after context edits. Empty for state-only entries and omissions. */
|
|
221
|
+
messages: AgentMessage[];
|
|
222
|
+
}
|
|
223
|
+
export interface SessionProjection {
|
|
224
|
+
entries: ProjectedSessionEntry[];
|
|
225
|
+
messages: AgentMessage[];
|
|
226
|
+
thinkingLevel: string;
|
|
227
|
+
model: {
|
|
228
|
+
provider: string;
|
|
229
|
+
modelId: string;
|
|
230
|
+
} | null;
|
|
231
|
+
}
|
|
205
232
|
export interface SessionContext {
|
|
206
233
|
messages: AgentMessage[];
|
|
207
234
|
thinkingLevel: string;
|
|
@@ -239,5 +266,5 @@ export interface SessionInfo {
|
|
|
239
266
|
messageColor?: "success" | "warning" | "accent" | "error";
|
|
240
267
|
}
|
|
241
268
|
export type SessionListProgress = (loaded: number, total: number, partialSessions?: readonly SessionInfo[]) => void;
|
|
242
|
-
export type ReadonlySessionManager = Pick<SessionManager, "getCwd" | "getSessionDir" | "usesDefaultSessionDir" | "getSessionId" | "getSessionFile" | "getLeafId" | "getLeafEntry" | "getEntry" | "getLabel" | "getBranch" | "getHeader" | "getEntries" | "getTree" | "getSessionName" | "getSessionNameState">;
|
|
269
|
+
export type ReadonlySessionManager = Pick<SessionManager, "getCwd" | "getSessionDir" | "usesDefaultSessionDir" | "getSessionId" | "getSessionFile" | "getLeafId" | "getLeafEntry" | "getEntry" | "getLabel" | "getBranch" | "buildContextEntries" | "buildSessionProjection" | "getHeader" | "getEntries" | "getTree" | "getSessionName" | "getSessionNameState">;
|
|
243
270
|
//# sourceMappingURL=session-manager-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-types.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"session-manager-types.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,KAAK,EACL,WAAW,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iIAAiI;IACjI,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,uBAAuB,CAAC;CACnC;AAED,MAAM,WAA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,GACV,UAAU,GACV,WAAW,GACX,qBAAqB,GACrB,wBAAwB,GACxB,WAAW,GACX,YAAY,GACZ,SAAS,GACT,gBAAgB,GAChB,qBAAqB,CACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-types.js","sourceRoot":"","sources":["../../src/core/session-manager-types.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC","sourcesContent":["import type { ImageContent, SystemMessage, TextContent, Usage } from \"@bastani/pi-ai/compat\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { SessionManager } from \"./session-manager-core.ts\";\n\nexport const CURRENT_SESSION_VERSION = 3;\n\n/**\n * Workflow linkage persisted on internal (workflow-created) session headers.\n * Used to exclude workflow stage sessions from the standard `/resume` history\n * while keeping them resumable through the workflow-specific resume path.\n */\nexport interface SessionWorkflowMetadata {\n\trunId: string;\n\tstageId: string;\n\tstageName: string;\n}\n\nexport interface SessionHeader {\n\ttype: \"session\";\n\tversion?: number; // v1 sessions don't have this\n\tid: string;\n\ttimestamp: string;\n\tcwd: string;\n\tparentSession?: string;\n\t/** Marks sessions created by automated machinery (e.g. workflow stages) so they can be excluded from standard resume history. */\n\tinternal?: boolean;\n\t/** When internal, links the session to its owning workflow run/stage. */\n\tworkflow?: SessionWorkflowMetadata;\n}\n\nexport interface NewSessionOptions {\n\tid?: string;\n\tparentSession?: string;\n\t/** Mark the new session as internal (e.g. a workflow stage session). */\n\tinternal?: boolean;\n\t/** Workflow run/stage linkage for internal workflow sessions. */\n\tworkflow?: SessionWorkflowMetadata;\n}\n\nexport interface SessionEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface SessionMessageEntry extends SessionEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface UsageEntry extends SessionEntryBase {\n\ttype: \"usage\";\n\tkind: string;\n\tprovider: string;\n\tmodel: string;\n\tusage: Usage;\n\tnote?: string;\n}\n\n/** Durable compaction boundary. Active entries carry `details.strategy === \"verbatim-lines\"`. */\nexport interface CompactionEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\t/** First context-visible tail entry, or null when the durable summary replaces the entire pre-boundary transcript. */\n\tfirstKeptEntryId: string | null;\n\ttokensBefore: number;\n\tdetails?: T;\n\t/** Aggregate usage from model calls that produced this boundary. */\n\tusage?: Usage;\n\t/** True when the compacted text was supplied by an extension hook. */\n\tfromHook?: boolean;\n\t/** Replayed system instructions and tool state at this boundary. */\n\tsystemMessage?: SystemMessage;\n}\n\n/** @deprecated Legacy archival statistics; never produced or applied. */\nexport interface ContextCompactionStats {\n\tobjectsBefore: number;\n\tobjectsAfter: number;\n\tobjectsDeleted: number;\n\ttokensBefore: number;\n\ttokensAfter: number;\n\tpercentReduction: number;\n}\n\n/** @deprecated Legacy archival record; never produced or applied. */\nexport interface ContextCompactionEntry extends SessionEntryBase {\n\ttype: \"context_compaction\";\n\tpromptVersion: 1;\n\tdeletedTargets: Array<\n\t\t{ kind: \"entry\"; entryId: string } | { kind: \"content_block\"; entryId: string; blockIndex: number }\n\t>;\n\tprotectedEntryIds: string[];\n\tstats: ContextCompactionStats;\n\tbackupPath?: string;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\t/** Extension-specific data (not sent to LLM) */\n\tdetails?: T;\n\t/** Usage from the model call that generated this summary. */\n\tusage?: Usage;\n\t/** True if generated by an extension, false if generated by Atomic. */\n\tfromHook?: boolean;\n}\n\n/**\n * Custom entry for extensions to store extension-specific data in the session.\n * Use customType to identify your extension's entries.\n *\n * Purpose: Persist extension state across session reloads. On reload, extensions can\n * scan entries for their customType and reconstruct internal state.\n *\n * Does NOT participate in LLM context (ignored by buildSessionContext).\n * For injecting content into context, see CustomMessageEntry.\n */\nexport interface CustomEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\n/** Label entry for user-defined bookmarks/markers on entries. */\nexport interface LabelEntry extends SessionEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\n/** Session metadata entry (e.g., user-defined display name). */\nexport interface SessionInfoEntry extends SessionEntryBase {\n\ttype: \"session_info\";\n\tname?: string;\n}\n\n/**\n * Session name read state, mirroring pi's has_session_name / session_name pair\n * (upstream 7bdb16c2): the fact that a session was ever named is separate from the\n * name it currently holds. The distinction is already durable in the JSONL — a clear\n * appends a `session_info` entry with an empty name, a never-named session has none —\n * so this is a read-side shape, not a storage change.\n *\n * - `{ hasName: false }` — no `session_info` entry exists; the session was never named.\n * - `{ hasName: true }` — the latest `session_info` entry has an empty name; the session\n * was named and then cleared.\n * - `{ hasName: true, name: \"…\" }` — the session currently holds this name.\n */\nexport interface SessionNameState {\n\t/** True when a `session_info` entry exists, even if its latest name is empty (cleared). */\n\thasName: boolean;\n\t/** Current name. Undefined for both a cleared and a never-named session. */\n\tname?: string;\n}\n\n/** Session summary metadata entry. */\nexport interface SessionSummaryEntry extends SessionEntryBase {\n\ttype: \"session_summary\";\n\tsummary: string;\n\tsummarizedThroughId: string;\n\tusage?: Usage;\n}\n\n/**\n * Custom message entry for extensions to inject messages into LLM context.\n * Use customType to identify your extension's entries.\n *\n * Unlike CustomEntry, this usually participates in LLM context.\n * The content is converted to a user message in buildSessionContext() unless\n * excludeFromContext is true. Use details for extension-specific metadata (not sent to LLM).\n *\n * display controls TUI rendering:\n * - false: hidden entirely\n * - true: rendered with distinct styling (different from user messages)\n */\nexport interface ProtectedReconciliationMarker {\n\tdelivery: \"steer\" | \"followUp\";\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n\texcludeFromContext?: boolean;\n\t/** Stable producer identity used by workflow stages to de-nominate admitted external turns. */\n\tstageAdmissionKey?: string;\n\t/** Runtime provenance used to distinguish stage continuation from an externally triggered response. */\n\t/** Internal crash-recovery marker for a model-facing protected turn. */\n\tprotectedReconciliation?: ProtectedReconciliationMarker;\n}\n\n/** Session entry - has id/parentId for tree structure (returned by \"read\" methods in SessionManager) */\nexport type SessionEntry =\n\t| SessionMessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| UsageEntry\n\t| CompactionEntry\n\t| ContextCompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry\n\t| SessionSummaryEntry;\n\n/** Raw file entry (includes header) */\nexport type FileEntry = SessionHeader | SessionEntry;\n\n/** Tree node for getTree() - defensive copy of session structure */\nexport interface SessionTreeNode {\n\tentry: SessionEntry;\n\tchildren: SessionTreeNode[];\n\t/** Resolved label for this entry, if any */\n\tlabel?: string;\n\t/** Timestamp of the latest label change for this entry, if any */\n\tlabelTimestamp?: string;\n}\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionInfo {\n\tpath: string;\n\tid: string;\n\t/** Working directory where the session was started. Empty string for old sessions. */\n\tcwd: string;\n\t/**\n\t * User-defined display name from session_info entries. Undefined both for a\n\t * never-named session and for one whose name was cleared; `hasName` separates them.\n\t */\n\tname?: string;\n\t/** True when a session_info entry exists, even if the name was later cleared. */\n\thasName?: boolean;\n\t/** Path to the parent session (if this session was forked). */\n\tparentSessionPath?: string;\n\t/** True when this session was created by automated machinery (e.g. a workflow stage). */\n\tinternal?: boolean;\n\t/** Workflow run/stage linkage when the session is an internal workflow session. */\n\tworkflow?: SessionWorkflowMetadata;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\t/** Generated resume summary. Absent when never generated, or stale against the latest message. */\n\tsummary?: string;\n\tallMessagesText: string;\n\t/** Optional semantic color for synthetic selector rows. */\n\tmessageColor?: \"success\" | \"warning\" | \"accent\" | \"error\";\n}\n\nexport type SessionListProgress = (loaded: number, total: number, partialSessions?: readonly SessionInfo[]) => void;\n\nexport type ReadonlySessionManager = Pick<\n\tSessionManager,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"usesDefaultSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionFile\"\n\t| \"getLeafId\"\n\t| \"getLeafEntry\"\n\t| \"getEntry\"\n\t| \"getLabel\"\n\t| \"getBranch\"\n\t| \"getHeader\"\n\t| \"getEntries\"\n\t| \"getTree\"\n\t| \"getSessionName\"\n\t| \"getSessionNameState\"\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"session-manager-types.js","sourceRoot":"","sources":["../../src/core/session-manager-types.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tImageContent,\n\tSystemMessage,\n\tTextContent,\n\tToolResultMessage,\n\tUsage,\n\tUserMessage,\n} from \"@bastani/pi-ai/compat\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { CustomMessage } from \"./messages.ts\";\nimport type { SessionManager } from \"./session-manager-core.ts\";\n\nexport const CURRENT_SESSION_VERSION = 3;\n\n/**\n * Workflow linkage persisted on internal (workflow-created) session headers.\n * Used to exclude workflow stage sessions from the standard `/resume` history\n * while keeping them resumable through the workflow-specific resume path.\n */\nexport interface SessionWorkflowMetadata {\n\trunId: string;\n\tstageId: string;\n\tstageName: string;\n}\n\nexport interface SessionHeader {\n\ttype: \"session\";\n\tversion?: number; // v1 sessions don't have this\n\tid: string;\n\ttimestamp: string;\n\tcwd: string;\n\tparentSession?: string;\n\t/** Marks sessions created by automated machinery (e.g. workflow stages) so they can be excluded from standard resume history. */\n\tinternal?: boolean;\n\t/** When internal, links the session to its owning workflow run/stage. */\n\tworkflow?: SessionWorkflowMetadata;\n}\n\nexport interface NewSessionOptions {\n\tid?: string;\n\tparentSession?: string;\n\t/** Mark the new session as internal (e.g. a workflow stage session). */\n\tinternal?: boolean;\n\t/** Workflow run/stage linkage for internal workflow sessions. */\n\tworkflow?: SessionWorkflowMetadata;\n}\n\nexport interface SessionEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface SessionMessageEntry extends SessionEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface UsageEntry extends SessionEntryBase {\n\ttype: \"usage\";\n\tkind: string;\n\tprovider: string;\n\tmodel: string;\n\tusage: Usage;\n\tnote?: string;\n}\n\n/** Durable compaction boundary. Active entries carry `details.strategy === \"verbatim-lines\"`. */\nexport interface CompactionEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\t/** First context-visible tail entry, or null when the durable summary replaces the entire pre-boundary transcript. */\n\tfirstKeptEntryId: string | null;\n\ttokensBefore: number;\n\tdetails?: T;\n\t/** Aggregate usage from model calls that produced this boundary. */\n\tusage?: Usage;\n\t/** True when the compacted text was supplied by an extension hook. */\n\tfromHook?: boolean;\n\t/** Replayed system instructions and tool state at this boundary. */\n\tsystemMessage?: SystemMessage;\n}\n\n/** @deprecated Legacy archival statistics; never produced or applied. */\nexport interface ContextCompactionStats {\n\tobjectsBefore: number;\n\tobjectsAfter: number;\n\tobjectsDeleted: number;\n\ttokensBefore: number;\n\ttokensAfter: number;\n\tpercentReduction: number;\n}\n\n/** @deprecated Legacy archival record; never produced or applied. */\nexport interface ContextCompactionEntry extends SessionEntryBase {\n\ttype: \"context_compaction\";\n\tpromptVersion: 1;\n\tdeletedTargets: Array<\n\t\t{ kind: \"entry\"; entryId: string } | { kind: \"content_block\"; entryId: string; blockIndex: number }\n\t>;\n\tprotectedEntryIds: string[];\n\tstats: ContextCompactionStats;\n\tbackupPath?: string;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\t/** Extension-specific data (not sent to LLM) */\n\tdetails?: T;\n\t/** Usage from the model call that generated this summary. */\n\tusage?: Usage;\n\t/** True if generated by an extension, false if generated by Atomic. */\n\tfromHook?: boolean;\n}\n\n/**\n * Custom entry for extensions to store extension-specific data in the session.\n * Use customType to identify your extension's entries.\n *\n * Purpose: Persist extension state across session reloads. On reload, extensions can\n * scan entries for their customType and reconstruct internal state.\n *\n * Does NOT participate in LLM context (ignored by buildSessionContext).\n * For injecting content into context, see CustomMessageEntry.\n */\nexport interface CustomEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\n/** Label entry for user-defined bookmarks/markers on entries. */\nexport interface LabelEntry extends SessionEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\n/** Session metadata entry (e.g., user-defined display name). */\nexport interface SessionInfoEntry extends SessionEntryBase {\n\ttype: \"session_info\";\n\tname?: string;\n}\n\n/**\n * Session name read state, mirroring pi's has_session_name / session_name pair\n * (upstream 7bdb16c2): the fact that a session was ever named is separate from the\n * name it currently holds. The distinction is already durable in the JSONL — a clear\n * appends a `session_info` entry with an empty name, a never-named session has none —\n * so this is a read-side shape, not a storage change.\n *\n * - `{ hasName: false }` — no `session_info` entry exists; the session was never named.\n * - `{ hasName: true }` — the latest `session_info` entry has an empty name; the session\n * was named and then cleared.\n * - `{ hasName: true, name: \"…\" }` — the session currently holds this name.\n */\nexport interface SessionNameState {\n\t/** True when a `session_info` entry exists, even if its latest name is empty (cleared). */\n\thasName: boolean;\n\t/** Current name. Undefined for both a cleared and a never-named session. */\n\tname?: string;\n}\n\n/** Session summary metadata entry. */\nexport interface SessionSummaryEntry extends SessionEntryBase {\n\ttype: \"session_summary\";\n\tsummary: string;\n\tsummarizedThroughId: string;\n\tusage?: Usage;\n}\n\n/**\n * Custom message entry for extensions to inject messages into LLM context.\n * Use customType to identify your extension's entries.\n *\n * Unlike CustomEntry, this usually participates in LLM context.\n * The content is converted to a user message in buildSessionContext() unless\n * excludeFromContext is true. Use details for extension-specific metadata (not sent to LLM).\n *\n * display controls TUI rendering:\n * - false: hidden entirely\n * - true: rendered with distinct styling (different from user messages)\n */\nexport interface ProtectedReconciliationMarker {\n\tdelivery: \"steer\" | \"followUp\";\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n\texcludeFromContext?: boolean;\n\t/** Stable producer identity used by workflow stages to de-nominate admitted external turns. */\n\tstageAdmissionKey?: string;\n\t/** Runtime provenance used to distinguish stage continuation from an externally triggered response. */\n\t/** Internal crash-recovery marker for a model-facing protected turn. */\n\tprotectedReconciliation?: ProtectedReconciliationMarker;\n}\n\n/** Content that an append-only context edit may replace without changing message metadata. */\nexport type ContextEditableContent =\n\t| UserMessage[\"content\"]\n\t| AssistantMessage[\"content\"]\n\t| ToolResultMessage[\"content\"]\n\t| CustomMessage[\"content\"];\n\n/** Append-only change to one earlier entry's contribution to model context. */\nexport interface ContextEditEntry extends SessionEntryBase {\n\ttype: \"context_edit\";\n\ttargetId: string;\n\t/** Null omits the target from model context. A value replaces only its content. */\n\treplacement: { content: ContextEditableContent } | null;\n}\n\n/** Session entry - has id/parentId for tree structure (returned by \"read\" methods in SessionManager) */\nexport type SessionEntry =\n\t| SessionMessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| UsageEntry\n\t| CompactionEntry\n\t| ContextCompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| ContextEditEntry\n\t| LabelEntry\n\t| SessionInfoEntry\n\t| SessionSummaryEntry;\n\n/** Raw file entry (includes header) */\nexport type FileEntry = SessionHeader | SessionEntry;\n\n/** Tree node for getTree() - defensive copy of session structure */\nexport interface SessionTreeNode {\n\tentry: SessionEntry;\n\tchildren: SessionTreeNode[];\n\t/** Resolved label for this entry, if any */\n\tlabel?: string;\n\t/** Timestamp of the latest label change for this entry, if any */\n\tlabelTimestamp?: string;\n}\n\nexport interface ProjectedSessionEntry {\n\t/** Raw append-only entry that owns this projected contribution. */\n\tsourceEntry: SessionEntry;\n\t/** Model-visible messages after context edits. Empty for state-only entries and omissions. */\n\tmessages: AgentMessage[];\n}\n\nexport interface SessionProjection {\n\tentries: ProjectedSessionEntry[];\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionInfo {\n\tpath: string;\n\tid: string;\n\t/** Working directory where the session was started. Empty string for old sessions. */\n\tcwd: string;\n\t/**\n\t * User-defined display name from session_info entries. Undefined both for a\n\t * never-named session and for one whose name was cleared; `hasName` separates them.\n\t */\n\tname?: string;\n\t/** True when a session_info entry exists, even if the name was later cleared. */\n\thasName?: boolean;\n\t/** Path to the parent session (if this session was forked). */\n\tparentSessionPath?: string;\n\t/** True when this session was created by automated machinery (e.g. a workflow stage). */\n\tinternal?: boolean;\n\t/** Workflow run/stage linkage when the session is an internal workflow session. */\n\tworkflow?: SessionWorkflowMetadata;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\t/** Generated resume summary. Absent when never generated, or stale against the latest message. */\n\tsummary?: string;\n\tallMessagesText: string;\n\t/** Optional semantic color for synthetic selector rows. */\n\tmessageColor?: \"success\" | \"warning\" | \"accent\" | \"error\";\n}\n\nexport type SessionListProgress = (loaded: number, total: number, partialSessions?: readonly SessionInfo[]) => void;\n\nexport type ReadonlySessionManager = Pick<\n\tSessionManager,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"usesDefaultSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionFile\"\n\t| \"getLeafId\"\n\t| \"getLeafEntry\"\n\t| \"getEntry\"\n\t| \"getLabel\"\n\t| \"getBranch\"\n\t| \"buildContextEntries\"\n\t| \"buildSessionProjection\"\n\t| \"getHeader\"\n\t| \"getEntries\"\n\t| \"getTree\"\n\t| \"getSessionName\"\n\t| \"getSessionNameState\"\n>;\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { VerbatimCompactionDetails } from "./compaction/compaction-types.js";
|
|
2
2
|
export { SessionManager } from "./session-manager-core.ts";
|
|
3
|
-
export { buildContextEntries, buildSessionContext, getLatestCompactionBoundaryEntry, sessionEntryToContextMessages, } from "./session-manager-history.ts";
|
|
3
|
+
export { buildContextEntries, buildSessionContext, buildSessionProjection, getLatestCompactionBoundaryEntry, sessionEntryToContextMessages, } from "./session-manager-history.ts";
|
|
4
4
|
export { migrateSessionEntries, parseSessionEntries } from "./session-manager-migrations.ts";
|
|
5
5
|
export { getDefaultSessionDir } from "./session-manager-paths.ts";
|
|
6
6
|
export { findMostRecentSession, isInternalHeader, loadEntriesFromFile } from "./session-manager-storage.ts";
|
|
7
|
-
export type { BranchSummaryEntry, CompactionEntry, ContextCompactionEntry, ContextCompactionStats, CustomEntry, CustomMessageEntry, FileEntry, LabelEntry, ModelChangeEntry, NewSessionOptions, ReadonlySessionManager, SessionContext, SessionEntry, SessionEntryBase, SessionHeader, SessionInfo, SessionInfoEntry, SessionListProgress, SessionMessageEntry, SessionNameState, SessionTreeNode, SessionWorkflowMetadata, ThinkingLevelChangeEntry, UsageEntry, } from "./session-manager-types.ts";
|
|
7
|
+
export type { BranchSummaryEntry, CompactionEntry, ContextCompactionEntry, ContextCompactionStats, ContextEditableContent, ContextEditEntry, CustomEntry, CustomMessageEntry, FileEntry, LabelEntry, ModelChangeEntry, NewSessionOptions, ProjectedSessionEntry, ReadonlySessionManager, SessionContext, SessionEntry, SessionEntryBase, SessionHeader, SessionInfo, SessionInfoEntry, SessionListProgress, SessionMessageEntry, SessionNameState, SessionProjection, SessionTreeNode, SessionWorkflowMetadata, ThinkingLevelChangeEntry, UsageEntry, } from "./session-manager-types.ts";
|
|
8
8
|
export { CURRENT_SESSION_VERSION } from "./session-manager-types.ts";
|
|
9
9
|
export { assertValidSessionId } from "./session-manager-validation.ts";
|
|
10
10
|
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/core/session-manager.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,EAChC,6BAA6B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC5G,YAAY,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,UAAU,GACV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/core/session-manager.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,gCAAgC,EAChC,6BAA6B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC5G,YAAY,EACX,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,UAAU,GACV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SessionManager } from "./session-manager-core.js";
|
|
2
|
-
export { buildContextEntries, buildSessionContext, getLatestCompactionBoundaryEntry, sessionEntryToContextMessages, } from "./session-manager-history.js";
|
|
2
|
+
export { buildContextEntries, buildSessionContext, buildSessionProjection, getLatestCompactionBoundaryEntry, sessionEntryToContextMessages, } from "./session-manager-history.js";
|
|
3
3
|
export { migrateSessionEntries, parseSessionEntries } from "./session-manager-migrations.js";
|
|
4
4
|
export { getDefaultSessionDir } from "./session-manager-paths.js";
|
|
5
5
|
export { findMostRecentSession, isInternalHeader, loadEntriesFromFile } from "./session-manager-storage.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.js","sourceRoot":"","sources":["../../src/core/session-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,EAChC,6BAA6B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-manager.js","sourceRoot":"","sources":["../../src/core/session-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,gCAAgC,EAChC,6BAA6B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AA+B5G,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nexport { SessionManager } from \"./session-manager-core.ts\";\nexport {\n\tbuildContextEntries,\n\tbuildSessionContext,\n\tbuildSessionProjection,\n\tgetLatestCompactionBoundaryEntry,\n\tsessionEntryToContextMessages,\n} from \"./session-manager-history.ts\";\nexport { migrateSessionEntries, parseSessionEntries } from \"./session-manager-migrations.ts\";\nexport { getDefaultSessionDir } from \"./session-manager-paths.ts\";\nexport { findMostRecentSession, isInternalHeader, loadEntriesFromFile } from \"./session-manager-storage.ts\";\nexport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tContextCompactionEntry,\n\tContextCompactionStats,\n\tContextEditableContent,\n\tContextEditEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tFileEntry,\n\tLabelEntry,\n\tModelChangeEntry,\n\tNewSessionOptions,\n\tProjectedSessionEntry,\n\tReadonlySessionManager,\n\tSessionContext,\n\tSessionEntry,\n\tSessionEntryBase,\n\tSessionHeader,\n\tSessionInfo,\n\tSessionInfoEntry,\n\tSessionListProgress,\n\tSessionMessageEntry,\n\tSessionNameState,\n\tSessionProjection,\n\tSessionTreeNode,\n\tSessionWorkflowMetadata,\n\tThinkingLevelChangeEntry,\n\tUsageEntry,\n} from \"./session-manager-types.ts\";\nexport { CURRENT_SESSION_VERSION } from \"./session-manager-types.ts\";\nexport { assertValidSessionId } from \"./session-manager-validation.ts\";\n"]}
|
|
@@ -2,7 +2,6 @@ import type { Static, TSchema } from "typebox";
|
|
|
2
2
|
import type { RouterDecisionRequest, StructuredOutputRequest, StructuredOutputResult } from "./types.js";
|
|
3
3
|
export { getStructuredOutputProviders, JEV_STRUCTURED_OUTPUT_PROVIDER, resolveRouterModel, } from "./resolver.js";
|
|
4
4
|
export type { RouterDecisionRequest, RouterModelSelectionOptions, StructuredChoiceQuestion, StructuredOutputModel, StructuredOutputRequest, StructuredOutputResult, } from "./types.js";
|
|
5
|
-
export declare const DEFAULT_STRUCTURED_OUTPUT_TIMEOUT_MS = 30000;
|
|
6
5
|
/** General structured inference remains one-shot. */
|
|
7
6
|
export declare function inferStructuredOutput<T extends TSchema>(request: StructuredOutputRequest<T>): Promise<StructuredOutputResult<Static<T>>>;
|
|
8
7
|
/** Resolve only prerequisite routing inference. Does not execute the selected action or alter chat/tools. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/structured-output/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAY/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzG,OAAO,EACN,4BAA4B,EAC5B,8BAA8B,EAC9B,kBAAkB,GAClB,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/structured-output/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAY/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzG,OAAO,EACN,4BAA4B,EAC5B,8BAA8B,EAC9B,kBAAkB,GAClB,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,YAAY,CAAC;AAyHpB,qDAAqD;AACrD,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,OAAO,EACtD,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAE5C;AAoID,6GAA6G;AAC7G,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,OAAO,EAC1D,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC;AACjC,iGAAiG;AACjG,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,GAC9C,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAe5C"}
|
|
@@ -6,7 +6,6 @@ import { inferJev, STRUCTURED_DECISION_POLICY } from "./jev.js";
|
|
|
6
6
|
import { JevRequestError } from "./jev-client.js";
|
|
7
7
|
import { resolveRouterModel } from "./resolver.js";
|
|
8
8
|
export { getStructuredOutputProviders, JEV_STRUCTURED_OUTPUT_PROVIDER, resolveRouterModel, } from "./resolver.js";
|
|
9
|
-
export const DEFAULT_STRUCTURED_OUTPUT_TIMEOUT_MS = 30_000;
|
|
10
9
|
const DEFAULT_MAX_TOKENS = 4096;
|
|
11
10
|
function positiveInteger(value, name) {
|
|
12
11
|
if (!Number.isSafeInteger(value) || value <= 0 || value > 2_147_483_647) {
|
|
@@ -40,7 +39,7 @@ function validateState(state) {
|
|
|
40
39
|
throw new Error("Structured output requires a nonempty named state object containing the task and relevant context text.");
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
async function inferChat(request, model, signal,
|
|
42
|
+
async function inferChat(request, model, signal, assertActive) {
|
|
44
43
|
// Anthropic catalog configuration may opt into server-side fallback. A decision must not.
|
|
45
44
|
const decisionModel = model.api === "anthropic-messages"
|
|
46
45
|
? { ...model, compat: { ...model.compat, allowedFallbackModels: [] } }
|
|
@@ -69,7 +68,6 @@ async function inferChat(request, model, signal, timeoutMs, assertActive) {
|
|
|
69
68
|
],
|
|
70
69
|
}, {
|
|
71
70
|
signal,
|
|
72
|
-
timeoutMs,
|
|
73
71
|
maxRetries: 0,
|
|
74
72
|
transport: "sse",
|
|
75
73
|
toolChoice: "auto",
|
|
@@ -112,8 +110,6 @@ export function inferStructuredOutput(request) {
|
|
|
112
110
|
}
|
|
113
111
|
async function inferDecision(request, repairs, validateDecision, fallbackModel) {
|
|
114
112
|
request.signal?.throwIfAborted();
|
|
115
|
-
const timeoutMs = request.timeoutMs ?? DEFAULT_STRUCTURED_OUTPUT_TIMEOUT_MS;
|
|
116
|
-
positiveInteger(timeoutMs, "timeoutMs");
|
|
117
113
|
positiveInteger(request.maxTokens ?? DEFAULT_MAX_TOKENS, "maxTokens");
|
|
118
114
|
validateState(request.state);
|
|
119
115
|
if (!request.instructions?.trim())
|
|
@@ -155,14 +151,7 @@ async function inferDecision(request, repairs, validateDecision, fallbackModel)
|
|
|
155
151
|
const controller = new AbortController();
|
|
156
152
|
const abort = () => controller.abort(new Error("Structured output cancelled; no decision was accepted."));
|
|
157
153
|
request.signal?.addEventListener("abort", abort, { once: true });
|
|
158
|
-
const
|
|
159
|
-
const expire = () => controller.abort(new Error("Structured output timed out; no decision was accepted. Retry explicitly or select another inference model."));
|
|
160
|
-
const assertActive = () => {
|
|
161
|
-
if (performance.now() >= deadline && !controller.signal.aborted)
|
|
162
|
-
expire();
|
|
163
|
-
controller.signal.throwIfAborted();
|
|
164
|
-
};
|
|
165
|
-
const timer = setTimeout(expire, timeoutMs);
|
|
154
|
+
const assertActive = () => controller.signal.throwIfAborted();
|
|
166
155
|
try {
|
|
167
156
|
if (request.signal?.aborted)
|
|
168
157
|
abort();
|
|
@@ -179,7 +168,7 @@ async function inferDecision(request, repairs, validateDecision, fallbackModel)
|
|
|
179
168
|
try {
|
|
180
169
|
const result = await raceWithAbortSignal(selected.kind === "jev"
|
|
181
170
|
? inferJev(current, controller.signal, assertActive)
|
|
182
|
-
: inferChat(current, selected.model, controller.signal,
|
|
171
|
+
: inferChat(current, selected.model, controller.signal, assertActive), controller.signal);
|
|
183
172
|
assertActive();
|
|
184
173
|
usage.inputTokens += result.usage.inputTokens;
|
|
185
174
|
usage.outputTokens += result.usage.outputTokens;
|
|
@@ -226,7 +215,6 @@ async function inferDecision(request, repairs, validateDecision, fallbackModel)
|
|
|
226
215
|
}
|
|
227
216
|
}
|
|
228
217
|
finally {
|
|
229
|
-
clearTimeout(timer);
|
|
230
218
|
request.signal?.removeEventListener("abort", abort);
|
|
231
219
|
}
|
|
232
220
|
}
|