@bastani/atomic 0.9.37 → 0.9.38-alpha.10
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 +151 -0
- package/README.md +8 -6
- package/dist/builtin/intercom/CHANGELOG.md +15 -0
- package/dist/builtin/intercom/broker/broker.ts +6 -4
- package/dist/builtin/intercom/broker/delivered-message-cache.ts +50 -4
- package/dist/builtin/intercom/broker/send-handler.ts +6 -4
- package/dist/builtin/intercom/index.bundle.mjs +89 -40
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/README.md +9 -4
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +163 -158
- package/dist/builtin/web-access/CHANGELOG.md +7 -0
- package/dist/builtin/web-access/index.bundle.mjs +53 -15
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +91 -0
- package/dist/builtin/workflows/README.md +5 -10
- package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
- package/dist/builtin/workflows/builtin/{chunk-94f8zfz1.js → chunk-454hz1qt.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-wf876n16.js → chunk-4bwtzyjq.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-kb7s3gx2.js → chunk-5eh0brtd.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-nkj4qhj6.js → chunk-85mx6wcf.js} +7 -7
- package/dist/builtin/workflows/builtin/{chunk-rhkg3d8e.js → chunk-8kkv04hz.js} +16 -16
- package/dist/builtin/workflows/builtin/chunk-8x61e0s7.js +3148 -0
- package/dist/builtin/workflows/builtin/{chunk-r97ndfvt.js → chunk-bjva9j5k.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-a1ar035d.js → chunk-qdd897wm.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-gyjck9z8.js → chunk-qjqn389g.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-632fxeb8.js → chunk-x0vvjyzg.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-3xffzzbg.js → chunk-y45tkftg.js} +11 -18
- package/dist/builtin/workflows/builtin/classify-and-act.js +2 -2
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +2 -2
- package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
- package/dist/builtin/workflows/builtin/goal.js +3 -3
- package/dist/builtin/workflows/builtin/index.js +11 -11
- package/dist/builtin/workflows/builtin/loop-until-done.js +2 -2
- package/dist/builtin/workflows/builtin/open-claude-design.js +2 -2
- package/dist/builtin/workflows/builtin/ralph.js +3 -3
- package/dist/builtin/workflows/builtin/tournament.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/authoring.d.ts +9 -12
- package/dist/builtin/workflows/src/durable/journal/conformance.d.ts +12 -0
- package/dist/builtin/workflows/src/durable/journal/internal.d.ts +1 -0
- package/dist/builtin/workflows/src/durable/journal/lease-expiry.d.ts +2 -0
- package/dist/builtin/workflows/src/durable/journal/legacy-journal-tables.d.ts +42 -0
- package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +35 -0
- package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +32 -0
- package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +48 -0
- package/dist/builtin/workflows/src/durable/journal/sqlite-run-journal.d.ts +7 -0
- package/dist/builtin/workflows/src/durable/journal/types.d.ts +95 -0
- package/dist/builtin/workflows/src/durable/journal/values.d.ts +5 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +29510 -64819
- package/dist/builtin/workflows/src/index.js +10767 -45878
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +8 -14
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +4 -20
- package/dist/bun/split-loader.js +0 -13
- package/dist/bun/split-loader.js.map +1 -1
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +35 -5
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/session-picker.d.ts +2 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +5 -5
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +2 -2
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +2 -3
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +18 -10
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-boundaries.d.ts +6 -6
- package/dist/core/agent-session-boundaries.d.ts.map +1 -1
- package/dist/core/agent-session-boundaries.js +22 -22
- package/dist/core/agent-session-boundaries.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +3 -2
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
- package/dist/core/agent-session-custom-message-commit.js +10 -12
- package/dist/core/agent-session-custom-message-commit.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +26 -14
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.js +1 -1
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +3 -3
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +98 -64
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +2 -2
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +17 -8
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +17 -17
- 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-models.d.ts +2 -2
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-models.js +59 -42
- package/dist/core/agent-session-models.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts +4 -4
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +16 -17
- 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 +6 -8
- 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 +18 -16
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +7 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +88 -100
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +4 -6
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +13 -8
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-summary.js +1 -1
- package/dist/core/agent-session-summary.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +3 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +8 -7
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -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.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +2 -0
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +12 -0
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/auth-storage.d.ts +5 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +46 -12
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/cache-warmer.js +1 -1
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -5
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +6 -10
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction-runner.d.ts +1 -0
- package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/compaction-runner.js +4 -1
- package/dist/core/compaction/compaction-runner.js.map +1 -1
- package/dist/core/compaction/pi-summary-fallback.d.ts +2 -1
- package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -1
- package/dist/core/compaction/pi-summary-fallback.js +6 -8
- package/dist/core/compaction/pi-summary-fallback.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +2 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +32 -7
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/export-html/index.js +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template-js/entries-navigation.js +1 -1
- package/dist/core/export-html/template-js/message-tools.js +20 -7
- package/dist/core/export-html/template-js/tree-filter-render.js +1 -9
- package/dist/core/export-html/template.js +22 -17
- package/dist/core/extensions/api-types.d.ts +12 -12
- 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/context-types.d.ts +4 -2
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/extension-work.d.ts +1 -0
- package/dist/core/extensions/extension-work.d.ts.map +1 -1
- package/dist/core/extensions/extension-work.js +5 -1
- package/dist/core/extensions/extension-work.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 +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +40 -42
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +6 -2
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
- package/dist/core/extensions/loader-rollback.js +1 -0
- package/dist/core/extensions/loader-rollback.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +1 -0
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +1 -0
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +10 -3
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner-handlers.d.ts +1 -1
- package/dist/core/extensions/runner-handlers.d.ts.map +1 -1
- package/dist/core/extensions/runner-handlers.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +5 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +28 -12
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +7 -7
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/session-events.d.ts +5 -5
- package/dist/core/extensions/session-events.d.ts.map +1 -1
- package/dist/core/extensions/session-events.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +2 -0
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +3 -3
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js +4 -4
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/fast-model-routing.d.ts.map +1 -1
- package/dist/core/fast-model-routing.js +1 -0
- package/dist/core/fast-model-routing.js.map +1 -1
- package/dist/core/intercom-runtime-group.js +1 -1
- package/dist/core/intercom-runtime-group.js.map +1 -1
- package/dist/core/model-config.d.ts +774 -9
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +46 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +3 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts +2 -0
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.js +47 -143
- package/dist/core/model-resolver-cli.js.map +1 -1
- package/dist/core/model-resolver-defaults.js +5 -5
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/model-resolver-patterns.d.ts +48 -22
- package/dist/core/model-resolver-patterns.d.ts.map +1 -1
- package/dist/core/model-resolver-patterns.js +154 -105
- package/dist/core/model-resolver-patterns.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +6 -9
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +51 -53
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-resolver-types.d.ts +0 -6
- package/dist/core/model-resolver-types.d.ts.map +1 -1
- package/dist/core/model-resolver-types.js.map +1 -1
- package/dist/core/model-resolver.d.ts +3 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime-streaming.d.ts +9 -2
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +121 -10
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime.d.ts +6 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +103 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +6 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-attribution.js +1 -1
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/resource-loader-reload.js +1 -1
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/resource-loader-types.d.ts +1 -1
- package/dist/core/resource-loader-types.d.ts.map +1 -1
- package/dist/core/resource-loader-types.js.map +1 -1
- package/dist/core/retry-policy.d.ts +5 -2
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +4 -3
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +1 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +3 -0
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk-types.d.ts +4 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +145 -94
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-lifecycle-work.d.ts +3 -0
- package/dist/core/session-lifecycle-work.d.ts.map +1 -1
- package/dist/core/session-lifecycle-work.js +2 -0
- package/dist/core/session-lifecycle-work.js.map +1 -1
- package/dist/core/session-manager-archive.d.ts +2 -16
- package/dist/core/session-manager-archive.d.ts.map +1 -1
- package/dist/core/session-manager-archive.js +8 -109
- package/dist/core/session-manager-archive.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +53 -51
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +549 -315
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +5 -10
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-errors.d.ts +10 -0
- package/dist/core/session-manager-errors.d.ts.map +1 -0
- package/dist/core/session-manager-errors.js +27 -0
- package/dist/core/session-manager-errors.js.map +1 -0
- package/dist/core/session-manager-list.d.ts +1 -0
- package/dist/core/session-manager-list.d.ts.map +1 -1
- package/dist/core/session-manager-list.js +23 -25
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts +3 -12
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +60 -77
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +4 -12
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js +2 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager-validation.d.ts +3 -0
- package/dist/core/session-manager-validation.d.ts.map +1 -1
- package/dist/core/session-manager-validation.js +18 -1
- package/dist/core/session-manager-validation.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -3
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-mutation-queue.d.ts +3 -0
- package/dist/core/session-mutation-queue.d.ts.map +1 -0
- package/dist/core/session-mutation-queue.js +14 -0
- package/dist/core/session-mutation-queue.js.map +1 -0
- package/dist/core/session-resume-args.d.ts +4 -0
- package/dist/core/session-resume-args.d.ts.map +1 -0
- package/dist/core/session-resume-args.js +9 -0
- package/dist/core/session-resume-args.js.map +1 -0
- package/dist/core/session-storage.d.ts +26 -0
- package/dist/core/session-storage.d.ts.map +1 -0
- package/dist/core/session-storage.js +171 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-store-list.d.ts +4 -0
- package/dist/core/session-store-list.d.ts.map +1 -0
- package/dist/core/session-store-list.js +28 -0
- package/dist/core/session-store-list.js.map +1 -0
- package/dist/core/settings-manager-basic-accessors.d.ts +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +1 -5
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-merge.d.ts.map +1 -1
- package/dist/core/settings-merge.js +8 -2
- package/dist/core/settings-merge.js.map +1 -1
- package/dist/core/settings-schema.d.ts +76 -6
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +29 -20
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/storage/database.d.ts +21 -0
- package/dist/core/storage/database.d.ts.map +1 -0
- package/dist/core/storage/database.js +2 -0
- package/dist/core/storage/database.js.map +1 -0
- package/dist/core/storage/errors.d.ts +64 -0
- package/dist/core/storage/errors.d.ts.map +1 -0
- package/dist/core/storage/errors.js +103 -0
- package/dist/core/storage/errors.js.map +1 -0
- package/dist/core/storage/index.d.ts +10 -0
- package/dist/core/storage/index.d.ts.map +1 -0
- package/dist/core/storage/index.js +8 -0
- package/dist/core/storage/index.js.map +1 -0
- package/dist/core/storage/node-sqlite.d.ts +7 -0
- package/dist/core/storage/node-sqlite.d.ts.map +1 -0
- package/dist/core/storage/node-sqlite.js +202 -0
- package/dist/core/storage/node-sqlite.js.map +1 -0
- package/dist/core/storage/prefix.d.ts +5 -0
- package/dist/core/storage/prefix.d.ts.map +1 -0
- package/dist/core/storage/prefix.js +15 -0
- package/dist/core/storage/prefix.js.map +1 -0
- package/dist/core/storage/provider.d.ts +58 -0
- package/dist/core/storage/provider.d.ts.map +1 -0
- package/dist/core/storage/provider.js +243 -0
- package/dist/core/storage/provider.js.map +1 -0
- package/dist/core/storage/run-journal.d.ts +93 -0
- package/dist/core/storage/run-journal.d.ts.map +1 -0
- package/dist/core/storage/run-journal.js +15 -0
- package/dist/core/storage/run-journal.js.map +1 -0
- package/dist/core/storage/schema.d.ts +3 -0
- package/dist/core/storage/schema.d.ts.map +1 -0
- package/dist/core/storage/schema.js +6 -0
- package/dist/core/storage/schema.js.map +1 -0
- package/dist/core/storage/selection.d.ts +16 -0
- package/dist/core/storage/selection.d.ts.map +1 -0
- package/dist/core/storage/selection.js +87 -0
- package/dist/core/storage/selection.js.map +1 -0
- package/dist/core/storage/session/conformance.d.ts +12 -0
- package/dist/core/storage/session/conformance.d.ts.map +1 -0
- package/dist/core/storage/session/conformance.js +674 -0
- package/dist/core/storage/session/conformance.js.map +1 -0
- package/dist/core/storage/session/entry-structure.d.ts +4 -0
- package/dist/core/storage/session/entry-structure.d.ts.map +1 -0
- package/dist/core/storage/session/entry-structure.js +83 -0
- package/dist/core/storage/session/entry-structure.js.map +1 -0
- package/dist/core/storage/session/errors.d.ts +54 -0
- package/dist/core/storage/session/errors.d.ts.map +1 -0
- package/dist/core/storage/session/errors.js +95 -0
- package/dist/core/storage/session/errors.js.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts +72 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.js +564 -0
- package/dist/core/storage/session/jsonl-session-store.js.map +1 -0
- package/dist/core/storage/session/legacy-format.d.ts +20 -0
- package/dist/core/storage/session/legacy-format.d.ts.map +1 -0
- package/dist/core/storage/session/legacy-format.js +89 -0
- package/dist/core/storage/session/legacy-format.js.map +1 -0
- package/dist/core/storage/session/legacy-session-store.d.ts +63 -0
- package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -0
- package/dist/core/storage/session/legacy-session-store.js +239 -0
- package/dist/core/storage/session/legacy-session-store.js.map +1 -0
- package/dist/core/storage/session/legacy-session-summary.d.ts +11 -0
- package/dist/core/storage/session/legacy-session-summary.d.ts.map +1 -0
- package/dist/core/storage/session/legacy-session-summary.js +103 -0
- package/dist/core/storage/session/legacy-session-summary.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.d.ts +33 -0
- package/dist/core/storage/session/memory-session-store.d.ts.map +1 -0
- package/dist/core/storage/session/memory-session-store.js +120 -0
- package/dist/core/storage/session/memory-session-store.js.map +1 -0
- package/dist/core/storage/session/scratch-directory.d.ts +2 -0
- package/dist/core/storage/session/scratch-directory.d.ts.map +1 -0
- package/dist/core/storage/session/scratch-directory.js +5 -0
- package/dist/core/storage/session/scratch-directory.js.map +1 -0
- package/dist/core/storage/session/session-summary.d.ts +24 -0
- package/dist/core/storage/session/session-summary.d.ts.map +1 -0
- package/dist/core/storage/session/session-summary.js +79 -0
- package/dist/core/storage/session/session-summary.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.d.ts +49 -0
- package/dist/core/storage/session/sql-session-store.d.ts.map +1 -0
- package/dist/core/storage/session/sql-session-store.js +246 -0
- package/dist/core/storage/session/sql-session-store.js.map +1 -0
- package/dist/core/storage/session/types.d.ts +72 -0
- package/dist/core/storage/session/types.d.ts.map +1 -0
- package/dist/core/storage/session/types.js +2 -0
- package/dist/core/storage/session/types.js.map +1 -0
- package/dist/core/storage/session/validation.d.ts +7 -0
- package/dist/core/storage/session/validation.d.ts.map +1 -0
- package/dist/core/storage/session/validation.js +47 -0
- package/dist/core/storage/session/validation.js.map +1 -0
- package/dist/core/storage/testing.d.ts +15 -0
- package/dist/core/storage/testing.d.ts.map +1 -0
- package/dist/core/storage/testing.js +309 -0
- package/dist/core/storage/testing.js.map +1 -0
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js +2 -4
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tools/bash-session-environment.d.ts.map +1 -1
- package/dist/core/tools/bash-session-environment.js +0 -2
- package/dist/core/tools/bash-session-environment.js.map +1 -1
- package/dist/core/tools/malformed-tool-arguments.d.ts +3 -0
- package/dist/core/tools/malformed-tool-arguments.d.ts.map +1 -0
- package/dist/core/tools/malformed-tool-arguments.js +23 -0
- package/dist/core/tools/malformed-tool-arguments.js.map +1 -0
- package/dist/core/tools/read-url.d.ts.map +1 -1
- package/dist/core/tools/read-url.js +6 -1
- package/dist/core/tools/read-url.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +2 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +19 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/todos-model.js +3 -3
- package/dist/core/tools/todos-model.js.map +1 -1
- package/dist/core/tools/todos-mutations.js +2 -2
- package/dist/core/tools/todos-mutations.js.map +1 -1
- package/dist/core/tools/todos-render.js +1 -1
- package/dist/core/tools/todos-render.js.map +1 -1
- package/dist/core/tools/todos-storage.js +2 -2
- package/dist/core/tools/todos-storage.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +14 -1
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +1 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/herdr/index.d.ts.map +1 -1
- package/dist/extensions/herdr/index.js +6 -8
- package/dist/extensions/herdr/index.js.map +1 -1
- package/dist/extensions/mcp/index.js +1 -1
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +6 -1
- package/dist/extensions/mcp/tools.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 +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main-session-options.d.ts.map +1 -1
- package/dist/main-session-options.js +1 -0
- package/dist/main-session-options.js.map +1 -1
- package/dist/main-session.d.ts +12 -2
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +151 -53
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +97 -42
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +3 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +18 -5
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +2 -2
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/host-session-picker.js +1 -1
- package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +9 -5
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-delete.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-delete.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.d.ts +12 -9
- package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.js +27 -25
- package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +8 -4
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +31 -21
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-component.d.ts +5 -1
- package/dist/modes/interactive/components/tree-selector-component.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-component.js +20 -3
- package/dist/modes/interactive/components/tree-selector-component.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 +2 -9
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/interactive-bash-compact.js +1 -1
- package/dist/modes/interactive/interactive-bash-compact.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +2 -2
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-editor-actions.js +2 -2
- package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +2 -0
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +6 -4
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +2 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.js +7 -3
- package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -5
- 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-model-routing.js +12 -7
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +8 -5
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +2 -2
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +38 -14
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +6 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +5 -3
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-tui.d.ts +1 -0
- package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-tui.js +9 -2
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive/program-status-reporter.d.ts +4 -0
- package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -1
- package/dist/modes/interactive/program-status-reporter.js +45 -6
- package/dist/modes/interactive/program-status-reporter.js.map +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.js +8 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/engine-args.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-args.js +11 -4
- package/dist/modes/interactive-engine/engine-args.js.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +2 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js +9 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +99 -74
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +4 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +39 -1
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/rpc/rpc-bash-request-owners.js +1 -1
- package/dist/modes/rpc/rpc-bash-request-owners.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js +2 -2
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +2 -2
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +20 -7
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +4 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +6 -2
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +12 -9
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +2 -2
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +10 -0
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/modes/rpc/rpc-terminal-drain.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-terminal-drain.js +11 -2
- package/dist/modes/rpc/rpc-terminal-drain.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +6 -2
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/canonical-path.d.ts +5 -0
- package/dist/utils/canonical-path.d.ts.map +1 -0
- package/dist/utils/canonical-path.js +26 -0
- package/dist/utils/canonical-path.js.map +1 -0
- package/dist/utils/paths.d.ts +1 -7
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +1 -15
- package/dist/utils/paths.js.map +1 -1
- package/docs/codemode.md +2 -0
- package/docs/compaction.md +2 -2
- package/docs/custom-provider/oauth.md +2 -2
- package/docs/custom-provider/override.md +3 -3
- package/docs/custom-provider/registration.md +7 -7
- package/docs/custom-provider/streaming.md +1 -1
- package/docs/custom-provider.md +5 -5
- package/docs/docs.json +6 -0
- package/docs/environment-variables.md +10 -2
- package/docs/extensions/api-reference.md +40 -19
- package/docs/extensions/authoring.md +1 -1
- package/docs/extensions/events.md +12 -8
- package/docs/extensions/ui.md +10 -0
- package/docs/extensions.md +2 -2
- package/docs/getting-started/installation.md +2 -4
- package/docs/json.md +1 -1
- package/docs/llama-cpp.md +95 -0
- package/docs/models/reference.md +9 -0
- package/docs/models-configuration.md +206 -0
- package/docs/models.md +11 -1
- package/docs/packages/authoring.md +1 -1
- package/docs/prompt-templates.md +2 -0
- package/docs/providers.md +13 -5
- package/docs/quickstart.md +2 -1
- package/docs/reference/cli.md +10 -6
- package/docs/rpc/protocol.md +10 -4
- package/docs/sdk/reference.md +16 -14
- package/docs/sdk/web-server.md +6 -7
- package/docs/sdk.md +67 -27
- package/docs/session-format.md +35 -34
- package/docs/sessions.md +56 -17
- package/docs/settings.md +38 -25
- package/docs/storage.md +387 -0
- package/docs/subagents.md +19 -6
- package/docs/tools.md +2 -0
- package/docs/usage.md +3 -2
- package/docs/workflows/api-reference.md +88 -60
- package/docs/workflows/authoring.md +2 -1
- package/docs/workflows/operations.md +32 -174
- package/docs/workflows/reliable-design.md +17 -17
- package/examples/extensions/bookmark.ts +2 -2
- package/examples/extensions/handoff.ts +2 -2
- package/examples/extensions/minimal-mode.ts +1 -8
- package/examples/extensions/plan-mode/index.ts +15 -13
- package/examples/extensions/preset.ts +8 -8
- package/examples/extensions/session-name.ts +1 -1
- package/examples/extensions/snake.ts +3 -1
- package/examples/extensions/space-invaders.ts +3 -1
- package/examples/extensions/subagent/display.ts +4 -6
- package/examples/extensions/tic-tac-toe.ts +80 -80
- package/examples/sdk/11-sessions.ts +5 -5
- package/examples/sdk/13-session-runtime.ts +7 -7
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +53 -469
- package/package.json +17 -9
- package/schemas/models.schema.json +67 -34
- package/schemas/settings.schema.json +138 -27
- package/dist/builtin/workflows/builtin/chunk-7fvrnzhb.js +0 -8
- package/dist/builtin/workflows/builtin/chunk-8c3ae7tt.js +0 -11609
- package/dist/core/session-manager-migrations.d.ts +0 -11
- package/dist/core/session-manager-migrations.d.ts.map +0 -1
- package/dist/core/session-manager-migrations.js +0 -80
- package/dist/core/session-manager-migrations.js.map +0 -1
|
@@ -1,153 +1,149 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
1
3
|
import { getCurrentSystemMessage } from "@bastani/pi-ai";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { normalizePath, resolvePath } from "../utils/paths.js";
|
|
6
|
-
import { createBackupSnapshot, createBranchedSessionState, forkSessionFromFile, forkSessionFromFileAsync, } from "./session-manager-archive.js";
|
|
4
|
+
import { getAgentDir } from "../config.js";
|
|
5
|
+
import { createSessionCwdMatcher, normalizePath, resolvePath } from "../utils/paths.js";
|
|
6
|
+
import { createBranchedSessionState } from "./session-manager-archive.js";
|
|
7
7
|
import { classifiedWorkflowMetadata, validSessionWorkflowMetadata } from "./session-manager-classification.js";
|
|
8
8
|
import { createBranchSummaryEntry, createCompactionEntry, createContextEditEntry, createCustomEntry, createCustomMessageEntry, createLabelEntry, createMessageEntry, createModelChangeEntry, createSessionFilePath, createSessionHeader, createSessionInfoEntry, createSessionSummaryEntry, createThinkingLevelChangeEntry, getEntriesWithoutHeader, getLatestSessionName, } from "./session-manager-entries.js";
|
|
9
|
+
import { SessionEntryError } from "./session-manager-errors.js";
|
|
9
10
|
import { buildContextEntries, buildSessionIndex, buildSessionProjection, buildSessionTree, getBranchPath, } from "./session-manager-history.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
11
|
+
import { listProjectSessions } from "./session-manager-list.js";
|
|
12
|
+
import { getDefaultSessionDirPath } from "./session-manager-paths.js";
|
|
13
|
+
import { assertValidSessionId, createSessionId, generateId, validateSessionFileEntries, } from "./session-manager-validation.js";
|
|
14
|
+
import { listSessionStore } from "./session-store-list.js";
|
|
15
|
+
import { StorageRollbackError } from "./storage/errors.js";
|
|
16
|
+
import { SessionFormatVersionError, SessionIdMismatchError, SessionNotFoundError, StorageUnavailableError, } from "./storage/session/errors.js";
|
|
17
|
+
import { JsonlSessionStore } from "./storage/session/jsonl-session-store.js";
|
|
18
|
+
import { MemorySessionStore } from "./storage/session/memory-session-store.js";
|
|
19
|
+
async function resolveSessionStore(cwd) {
|
|
20
|
+
// Selection loads settings and tools, which depend on the completed session module.
|
|
21
|
+
return (await import("./session-storage.js")).resolveSessionStore(cwd);
|
|
22
|
+
}
|
|
23
|
+
/** An in-memory session tree whose mutations await the backing store. */
|
|
16
24
|
export class SessionManager {
|
|
17
25
|
sessionId = "";
|
|
18
26
|
sessionFile;
|
|
19
27
|
sessionDir;
|
|
20
28
|
cwd;
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
store;
|
|
30
|
+
lastSeq = 0;
|
|
31
|
+
mutation = Promise.resolve();
|
|
23
32
|
fileEntries = [];
|
|
24
33
|
byId = new Map();
|
|
25
34
|
labelsById = new Map();
|
|
26
35
|
labelTimestampsById = new Map();
|
|
27
36
|
leafId = null;
|
|
28
|
-
constructor(cwd, sessionDir,
|
|
37
|
+
constructor(store, cwd, sessionDir, options) {
|
|
38
|
+
this.store = store;
|
|
29
39
|
this.cwd = resolvePath(cwd);
|
|
30
40
|
this.sessionDir = normalizePath(sessionDir);
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
this.start(options);
|
|
42
|
+
}
|
|
43
|
+
runMutation(operation) {
|
|
44
|
+
const result = this.mutation.then(operation);
|
|
45
|
+
this.mutation = result.then(() => { }, () => { });
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
recordHeader(header = this.getHeader()) {
|
|
49
|
+
const { type: _type, ...record } = header;
|
|
50
|
+
return record;
|
|
51
|
+
}
|
|
52
|
+
restore(snapshot, location) {
|
|
53
|
+
const header = snapshot.header;
|
|
54
|
+
this.fileEntries = [{ type: "session", ...header }, ...snapshot.entries];
|
|
55
|
+
this.sessionId = header.id;
|
|
56
|
+
this.lastSeq = snapshot.lastSeq;
|
|
57
|
+
this.sessionFile =
|
|
58
|
+
location ?? (this.store instanceof JsonlSessionStore ? this.store.locationFor(header) : undefined);
|
|
59
|
+
this._buildIndex();
|
|
44
60
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
this.newSession(options);
|
|
56
|
-
this.fileEntries = this.fileEntries.concat(entries);
|
|
57
|
-
}
|
|
61
|
+
start(options) {
|
|
62
|
+
if (options?.id !== undefined)
|
|
63
|
+
assertValidSessionId(options.id);
|
|
64
|
+
this.sessionId = options?.id ?? createSessionId();
|
|
65
|
+
this.fileEntries = [
|
|
66
|
+
createSessionHeader(this.sessionId, this.cwd, new Date().toISOString(), options?.parentSession, options?.internal, options?.workflow),
|
|
67
|
+
];
|
|
68
|
+
this.lastSeq = 0;
|
|
58
69
|
this._buildIndex();
|
|
70
|
+
this.sessionFile =
|
|
71
|
+
this.store instanceof JsonlSessionStore
|
|
72
|
+
? this.sessionDir
|
|
73
|
+
? createSessionFilePath(this.sessionDir, this.getHeader().createdAt, this.sessionId)
|
|
74
|
+
: this.store.locationFor(this.recordHeader())
|
|
75
|
+
: undefined;
|
|
76
|
+
return this.sessionFile;
|
|
59
77
|
}
|
|
60
|
-
/** Switch to a different session file (used for resume and branching) */
|
|
61
78
|
setSessionFile(sessionFile) {
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const header = this.fileEntries.find((entry) => entry.type === "session");
|
|
81
|
-
this.sessionId = header?.id ?? createSessionId();
|
|
82
|
-
if (migrateToCurrentVersion(this.fileEntries)) {
|
|
83
|
-
this._rewriteFile();
|
|
84
|
-
}
|
|
85
|
-
this._buildIndex();
|
|
86
|
-
this.flushed = true;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const explicitPath = this.sessionFile;
|
|
90
|
-
this.newSession();
|
|
91
|
-
this.sessionFile = explicitPath; // preserve explicit path from --session flag
|
|
79
|
+
return this.runMutation(async () => {
|
|
80
|
+
const opened = await SessionManager.open(sessionFile, this.sessionDir, this.cwd);
|
|
81
|
+
this.store = opened.store;
|
|
82
|
+
this.restore({ header: opened.recordHeader(), entries: opened.getEntries(), lastSeq: opened.lastSeq }, opened.sessionFile);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async initialize() {
|
|
86
|
+
this.lastSeq = (await (this.store instanceof JsonlSessionStore
|
|
87
|
+
? this.store.create(this.recordHeader(), this.getEntries(), this.sessionFile)
|
|
88
|
+
: this.store.create(this.recordHeader(), this.getEntries()))).lastSeq;
|
|
89
|
+
}
|
|
90
|
+
async storeForNewSession() {
|
|
91
|
+
if (this.store instanceof JsonlSessionStore &&
|
|
92
|
+
this.sessionDir &&
|
|
93
|
+
this.store.descriptor.location !== resolvePath(this.sessionDir)) {
|
|
94
|
+
return JsonlSessionStore.open(this.sessionDir, { exactDirectory: true, scanExisting: false });
|
|
92
95
|
}
|
|
96
|
+
return this.store;
|
|
93
97
|
}
|
|
94
98
|
newSession(options) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
return this.runMutation(async () => {
|
|
100
|
+
if (options?.id !== undefined)
|
|
101
|
+
assertValidSessionId(options.id);
|
|
102
|
+
const header = createSessionHeader(options?.id ?? createSessionId(), this.cwd, new Date().toISOString(), options?.parentSession, options?.internal, options?.workflow);
|
|
103
|
+
const record = this.recordHeader(header);
|
|
104
|
+
const store = await this.storeForNewSession();
|
|
105
|
+
const location = store instanceof JsonlSessionStore
|
|
106
|
+
? this.sessionDir
|
|
107
|
+
? createSessionFilePath(this.sessionDir, record.createdAt, record.id)
|
|
108
|
+
: store.locationFor(record)
|
|
109
|
+
: undefined;
|
|
110
|
+
const result = await (store instanceof JsonlSessionStore
|
|
111
|
+
? store.create(record, [], location)
|
|
112
|
+
: store.create(record, []));
|
|
113
|
+
this.store = store;
|
|
114
|
+
this.byId.clear();
|
|
115
|
+
this.labelsById.clear();
|
|
116
|
+
this.labelTimestampsById.clear();
|
|
117
|
+
this.restore({ header: record, entries: [], lastSeq: result.lastSeq }, location);
|
|
118
|
+
return this.sessionFile;
|
|
119
|
+
});
|
|
111
120
|
}
|
|
112
|
-
/** Mark the session as workflow-owned, repairing malformed markers while preserving valid ownership. */
|
|
113
121
|
markSessionInternal(workflow) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
return this.runMutation(async () => {
|
|
123
|
+
const previous = this.getHeader();
|
|
124
|
+
if (classifiedWorkflowMetadata(previous))
|
|
125
|
+
return;
|
|
126
|
+
const validWorkflow = validSessionWorkflowMetadata(workflow);
|
|
127
|
+
if (!validWorkflow)
|
|
128
|
+
return;
|
|
129
|
+
const header = { ...previous, internal: true, workflow: validWorkflow };
|
|
130
|
+
const result = await this.store.replace(this.sessionId, this.recordHeader(header), this.getEntries(), {
|
|
131
|
+
expectSeq: this.lastSeq,
|
|
132
|
+
});
|
|
133
|
+
this.lastSeq = result.lastSeq;
|
|
134
|
+
this.fileEntries[0] = header;
|
|
135
|
+
});
|
|
124
136
|
}
|
|
125
137
|
_buildIndex() {
|
|
138
|
+
validateSessionFileEntries(this.fileEntries, this.sessionFile ?? "in-memory session");
|
|
126
139
|
const index = buildSessionIndex(this.fileEntries);
|
|
127
140
|
this.byId = index.byId;
|
|
128
141
|
this.labelsById = index.labelsById;
|
|
129
142
|
this.labelTimestampsById = index.labelTimestampsById;
|
|
130
143
|
this.leafId = index.leafId;
|
|
131
144
|
}
|
|
132
|
-
_rewriteFile() {
|
|
133
|
-
if (!this.persist || !this.sessionFile)
|
|
134
|
-
return;
|
|
135
|
-
writeSessionEntries(this.sessionFile, this.fileEntries);
|
|
136
|
-
}
|
|
137
145
|
isPersisted() {
|
|
138
|
-
return this.
|
|
139
|
-
}
|
|
140
|
-
/** Persist the current session tree before an in-process attempt is force-finalized. */
|
|
141
|
-
flush() {
|
|
142
|
-
if (!this.persist || !this.sessionFile)
|
|
143
|
-
return;
|
|
144
|
-
this._rewriteFile();
|
|
145
|
-
this.flushed = true;
|
|
146
|
-
}
|
|
147
|
-
/** Flush only a session whose file has already been started, so closing an unsaved session writes nothing. */
|
|
148
|
-
flushIfStarted() {
|
|
149
|
-
if (this.flushed || hasConversationMessage(this.fileEntries))
|
|
150
|
-
this.flush();
|
|
146
|
+
return !(this.store instanceof MemorySessionStore);
|
|
151
147
|
}
|
|
152
148
|
getCwd() {
|
|
153
149
|
return this.cwd;
|
|
@@ -164,127 +160,203 @@ export class SessionManager {
|
|
|
164
160
|
getSessionFile() {
|
|
165
161
|
return this.sessionFile;
|
|
166
162
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return;
|
|
170
|
-
this.flushed = persistAppendedEntry(this.sessionFile, this.fileEntries, entry, this.flushed);
|
|
163
|
+
getSessionStore() {
|
|
164
|
+
return this.store;
|
|
171
165
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
/** @internal Finalize provisional startup storage after project trust resolves. */
|
|
167
|
+
rebindStore(store, removeProvisionalRecord) {
|
|
168
|
+
return this.runMutation(async () => {
|
|
169
|
+
if (store === this.store)
|
|
170
|
+
return;
|
|
171
|
+
const header = this.recordHeader();
|
|
172
|
+
const entries = this.getEntries();
|
|
173
|
+
const result = await store.create(header, entries);
|
|
174
|
+
if (removeProvisionalRecord)
|
|
175
|
+
await this.store.delete(this.sessionId);
|
|
176
|
+
this.store = store;
|
|
177
|
+
this.sessionDir = store instanceof JsonlSessionStore ? store.descriptor.location : "";
|
|
178
|
+
this.restore({ header, entries, lastSeq: result.lastSeq });
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async openSessionById(sessionId, cwdOverride, sessionDirectory) {
|
|
182
|
+
let store = sessionDirectory === undefined
|
|
183
|
+
? this.store
|
|
184
|
+
: await JsonlSessionStore.open(sessionDirectory, { exactDirectory: true, scanExisting: false });
|
|
185
|
+
let snapshot;
|
|
177
186
|
try {
|
|
178
|
-
|
|
187
|
+
snapshot = await store.load(sessionId);
|
|
179
188
|
}
|
|
180
189
|
catch (error) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
if (!(error instanceof SessionNotFoundError) ||
|
|
191
|
+
sessionDirectory !== undefined ||
|
|
192
|
+
!this.usesDefaultSessionDir())
|
|
193
|
+
throw error;
|
|
194
|
+
store = await JsonlSessionStore.open(join(getAgentDir(), "sessions"), { scanExisting: false });
|
|
195
|
+
snapshot = await store.load(sessionId);
|
|
196
|
+
}
|
|
197
|
+
const location = store instanceof JsonlSessionStore ? await store.findFile(sessionId) : undefined;
|
|
198
|
+
if (location !== undefined) {
|
|
199
|
+
store = await JsonlSessionStore.open(dirname(location), { exactDirectory: true, scanExisting: false });
|
|
200
|
+
snapshot = await store.load(sessionId);
|
|
201
|
+
}
|
|
202
|
+
if (snapshot.header.id !== sessionId)
|
|
203
|
+
throw new SessionIdMismatchError(sessionId, snapshot.header.id);
|
|
204
|
+
const manager = new SessionManager(store, cwdOverride ?? snapshot.header.cwd, this.sessionDir);
|
|
205
|
+
manager.restore(snapshot, location);
|
|
206
|
+
if (location !== undefined)
|
|
207
|
+
manager.sessionDir = dirname(location);
|
|
208
|
+
return manager;
|
|
209
|
+
}
|
|
210
|
+
async importFromJsonl(inputPath, cwdOverride) {
|
|
211
|
+
const source = await JsonlSessionStore.open(dirname(resolvePath(inputPath)), {
|
|
212
|
+
exactDirectory: true,
|
|
213
|
+
scanExisting: false,
|
|
214
|
+
});
|
|
215
|
+
try {
|
|
216
|
+
const snapshot = await source.loadFile(inputPath);
|
|
217
|
+
const manager = new SessionManager(this.store, cwdOverride ?? snapshot.header.cwd, this.sessionDir);
|
|
218
|
+
manager.restore(snapshot);
|
|
219
|
+
await manager.initialize();
|
|
220
|
+
return manager;
|
|
186
221
|
}
|
|
222
|
+
finally {
|
|
223
|
+
await source.close();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async _appendEntry(entry) {
|
|
227
|
+
const result = await this.store.append(this.sessionId, [entry], { expectSeq: this.lastSeq });
|
|
228
|
+
this.lastSeq = result.lastSeq;
|
|
229
|
+
this.fileEntries.push(entry);
|
|
230
|
+
this.byId.set(entry.id, entry);
|
|
231
|
+
this.leafId = entry.id;
|
|
187
232
|
}
|
|
188
233
|
/** Append a message as child of current leaf, then advance leaf. Returns entry id. */
|
|
189
234
|
appendMessage(message) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
235
|
+
return this.runMutation(async () => {
|
|
236
|
+
const entry = createMessageEntry(message, this.byId, this.leafId);
|
|
237
|
+
await this._appendEntry(entry);
|
|
238
|
+
return entry.id;
|
|
239
|
+
});
|
|
193
240
|
}
|
|
194
241
|
/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */
|
|
195
242
|
appendThinkingLevelChange(thinkingLevel) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
243
|
+
return this.runMutation(async () => {
|
|
244
|
+
const entry = createThinkingLevelChangeEntry(thinkingLevel, this.byId, this.leafId);
|
|
245
|
+
await this._appendEntry(entry);
|
|
246
|
+
return entry.id;
|
|
247
|
+
});
|
|
199
248
|
}
|
|
200
249
|
/** Record auxiliary model usage without adding it to the LLM context. */
|
|
201
250
|
appendUsage(kind, provider, model, usage, note) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
251
|
+
return this.runMutation(async () => {
|
|
252
|
+
const entry = {
|
|
253
|
+
type: "usage",
|
|
254
|
+
id: generateId(this.byId),
|
|
255
|
+
parentId: this.leafId,
|
|
256
|
+
timestamp: new Date().toISOString(),
|
|
257
|
+
kind,
|
|
258
|
+
provider,
|
|
259
|
+
model,
|
|
260
|
+
usage,
|
|
261
|
+
...(note === undefined ? {} : { note }),
|
|
262
|
+
};
|
|
263
|
+
await this._appendEntry(entry);
|
|
264
|
+
return entry;
|
|
265
|
+
});
|
|
215
266
|
}
|
|
216
267
|
/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */
|
|
217
268
|
appendModelChange(provider, modelId) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
269
|
+
return this.runMutation(async () => {
|
|
270
|
+
const entry = createModelChangeEntry(provider, modelId, this.byId, this.leafId);
|
|
271
|
+
await this._appendEntry(entry);
|
|
272
|
+
return entry.id;
|
|
273
|
+
});
|
|
221
274
|
}
|
|
222
275
|
appendCompaction(compactedText, firstKeptEntryId, tokensBefore, details, usage) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
276
|
+
return this.runMutation(async () => {
|
|
277
|
+
if (firstKeptEntryId !== null && !this.byId.has(firstKeptEntryId))
|
|
278
|
+
throw new SessionEntryError(firstKeptEntryId, "missing");
|
|
279
|
+
const entry = createCompactionEntry(compactedText, firstKeptEntryId, tokensBefore, details, usage, this.byId, this.leafId);
|
|
280
|
+
const systemMessage = getCurrentSystemMessage(this.buildSessionProjection().messages);
|
|
281
|
+
if (systemMessage)
|
|
282
|
+
entry.systemMessage = { ...systemMessage, timestamp: new Date(entry.timestamp).getTime() };
|
|
283
|
+
await this._appendEntry(entry);
|
|
284
|
+
return entry.id;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/** Save a JSONL backup; database-backed sessions have no file snapshot. */
|
|
233
288
|
writeBackupSnapshot(label = "compact") {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
289
|
+
return this.runMutation(async () => {
|
|
290
|
+
if (!(this.store instanceof JsonlSessionStore) || !this.sessionFile)
|
|
291
|
+
return undefined;
|
|
292
|
+
const path = `${this.sessionFile}.${new Date().toISOString().replace(/[:.]/g, "-")}.${label.replace(/[^a-z0-9_-]/gi, "-") || "backup"}.bak`;
|
|
293
|
+
try {
|
|
294
|
+
await writeFile(path, `${[JSON.stringify({ type: "session", ...this.recordHeader() }), ...this.getEntries().map((entry) => JSON.stringify(entry))].join("\n")}\n`);
|
|
295
|
+
}
|
|
296
|
+
catch (cause) {
|
|
297
|
+
throw new StorageUnavailableError(this.store.descriptor, cause);
|
|
298
|
+
}
|
|
299
|
+
return path;
|
|
300
|
+
});
|
|
237
301
|
}
|
|
238
302
|
/** Append a branch-local edit to an earlier model-visible entry. */
|
|
239
303
|
appendContextEdit(targetId, replacement) {
|
|
240
|
-
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
(target.
|
|
255
|
-
target.message.role === "
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
304
|
+
return this.runMutation(async () => {
|
|
305
|
+
if (replacement !== null &&
|
|
306
|
+
(typeof replacement !== "object" ||
|
|
307
|
+
!("content" in replacement) ||
|
|
308
|
+
(typeof replacement.content !== "string" && !Array.isArray(replacement.content)))) {
|
|
309
|
+
throw new SessionEntryError(targetId, "invalid-replacement");
|
|
310
|
+
}
|
|
311
|
+
const target = this.byId.get(targetId);
|
|
312
|
+
if (!target)
|
|
313
|
+
throw new SessionEntryError(targetId, "missing");
|
|
314
|
+
if (!this.getBranch().some((entry) => entry.id === targetId)) {
|
|
315
|
+
throw new SessionEntryError(targetId, "inactive");
|
|
316
|
+
}
|
|
317
|
+
const editable = target.type === "custom_message" ||
|
|
318
|
+
(target.type === "message" &&
|
|
319
|
+
(target.message.role === "user" ||
|
|
320
|
+
target.message.role === "assistant" ||
|
|
321
|
+
target.message.role === "toolResult"));
|
|
322
|
+
if (!editable)
|
|
323
|
+
throw new SessionEntryError(targetId, "not-editable");
|
|
324
|
+
const targetRole = target.type === "message" ? target.message.role : "custom";
|
|
325
|
+
const normalizedReplacement = replacement !== null &&
|
|
326
|
+
(targetRole === "assistant" || targetRole === "toolResult") &&
|
|
327
|
+
typeof replacement.content === "string"
|
|
328
|
+
? { content: [{ type: "text", text: replacement.content }] }
|
|
329
|
+
: replacement;
|
|
330
|
+
const entry = createContextEditEntry(targetId, normalizedReplacement, this.byId, this.leafId);
|
|
331
|
+
await this._appendEntry(entry);
|
|
332
|
+
return entry.id;
|
|
333
|
+
});
|
|
268
334
|
}
|
|
269
335
|
/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */
|
|
270
336
|
appendCustomEntry(customType, data) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
337
|
+
return this.runMutation(async () => {
|
|
338
|
+
const entry = createCustomEntry(customType, data, this.byId, this.leafId);
|
|
339
|
+
await this._appendEntry(entry);
|
|
340
|
+
return entry.id;
|
|
341
|
+
});
|
|
274
342
|
}
|
|
275
343
|
/** Append a session info entry (e.g., display name). Returns entry id. */
|
|
276
344
|
appendSessionInfo(name) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
345
|
+
return this.runMutation(async () => {
|
|
346
|
+
const entry = createSessionInfoEntry(name, this.byId, this.leafId);
|
|
347
|
+
await this._appendEntry(entry);
|
|
348
|
+
return entry.id;
|
|
349
|
+
});
|
|
280
350
|
}
|
|
281
351
|
/** Append a generated resume summary anchored to the message it describes. Returns entry id. */
|
|
282
352
|
appendSessionSummary(summary, summarizedThroughId, usage) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
353
|
+
return this.runMutation(async () => {
|
|
354
|
+
if (!this.byId.has(summarizedThroughId))
|
|
355
|
+
throw new SessionEntryError(summarizedThroughId, "missing");
|
|
356
|
+
const entry = createSessionSummaryEntry(summary, summarizedThroughId, usage, this.byId, this.leafId);
|
|
357
|
+
await this._appendEntry(entry);
|
|
358
|
+
return entry.id;
|
|
359
|
+
});
|
|
288
360
|
}
|
|
289
361
|
/** Get the current session name from the latest session_info entry, if any. */
|
|
290
362
|
getSessionName() {
|
|
@@ -300,9 +372,11 @@ export class SessionManager {
|
|
|
300
372
|
}
|
|
301
373
|
/** Append a custom message entry (for extensions) that participates in LLM context unless excluded. */
|
|
302
374
|
appendCustomMessageEntry(customType, content, display, details, excludeFromContext, protectedReconciliation, stageAdmissionKey) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
375
|
+
return this.runMutation(async () => {
|
|
376
|
+
const entry = createCustomMessageEntry(customType, content, display, details, excludeFromContext, protectedReconciliation, this.byId, this.leafId, stageAdmissionKey);
|
|
377
|
+
await this._appendEntry(entry);
|
|
378
|
+
return entry.id;
|
|
379
|
+
});
|
|
306
380
|
}
|
|
307
381
|
getLeafId() {
|
|
308
382
|
return this.leafId;
|
|
@@ -329,20 +403,22 @@ export class SessionManager {
|
|
|
329
403
|
}
|
|
330
404
|
/** Set or clear a label on an entry. */
|
|
331
405
|
appendLabelChange(targetId, label) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
406
|
+
return this.runMutation(async () => {
|
|
407
|
+
if (!this.byId.has(targetId)) {
|
|
408
|
+
throw new SessionEntryError(targetId, "missing");
|
|
409
|
+
}
|
|
410
|
+
const entry = createLabelEntry(targetId, label, this.byId, this.leafId);
|
|
411
|
+
await this._appendEntry(entry);
|
|
412
|
+
if (label) {
|
|
413
|
+
this.labelsById.set(targetId, label);
|
|
414
|
+
this.labelTimestampsById.set(targetId, entry.timestamp);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
this.labelsById.delete(targetId);
|
|
418
|
+
this.labelTimestampsById.delete(targetId);
|
|
419
|
+
}
|
|
420
|
+
return entry.id;
|
|
421
|
+
});
|
|
346
422
|
}
|
|
347
423
|
/** Walk from entry to root, returning all entries in path order. */
|
|
348
424
|
getBranch(fromId) {
|
|
@@ -380,118 +456,276 @@ export class SessionManager {
|
|
|
380
456
|
}
|
|
381
457
|
/** Start a new branch from an earlier entry. */
|
|
382
458
|
branch(branchFromId) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
459
|
+
return this.runMutation(async () => {
|
|
460
|
+
if (!this.byId.has(branchFromId)) {
|
|
461
|
+
throw new SessionEntryError(branchFromId, "missing");
|
|
462
|
+
}
|
|
463
|
+
this.leafId = branchFromId;
|
|
464
|
+
});
|
|
387
465
|
}
|
|
388
466
|
/** Reset the leaf pointer to null (before any entries). */
|
|
389
467
|
resetLeaf() {
|
|
390
|
-
this.
|
|
468
|
+
return this.runMutation(async () => {
|
|
469
|
+
this.leafId = null;
|
|
470
|
+
});
|
|
391
471
|
}
|
|
392
472
|
/** Start a new branch with a summary of the abandoned path. */
|
|
393
|
-
branchWithSummary(branchFromId, summary, details, fromHook, usage, fromId
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
473
|
+
branchWithSummary(branchFromId, summary, details, fromHook, usage, fromId) {
|
|
474
|
+
return this.runMutation(async () => {
|
|
475
|
+
if (branchFromId !== null && !this.byId.has(branchFromId)) {
|
|
476
|
+
throw new SessionEntryError(branchFromId, "missing");
|
|
477
|
+
}
|
|
478
|
+
const entry = createBranchSummaryEntry(branchFromId, fromId ?? this.leafId ?? "root", summary, details, usage, fromHook, this.byId);
|
|
479
|
+
await this._appendEntry(entry);
|
|
480
|
+
return entry.id;
|
|
481
|
+
});
|
|
401
482
|
}
|
|
402
|
-
/** Create a new session file containing only the path from root to the specified leaf. */
|
|
403
483
|
createBranchedSession(leafId) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
484
|
+
return this.runMutation(async () => {
|
|
485
|
+
const result = createBranchedSessionState({
|
|
486
|
+
leafId,
|
|
487
|
+
cwd: this.cwd,
|
|
488
|
+
parentSessionId: this.sessionId,
|
|
489
|
+
workflow: classifiedWorkflowMetadata(this.getHeader()),
|
|
490
|
+
path: this.getBranch(leafId),
|
|
491
|
+
labelsById: this.labelsById,
|
|
492
|
+
labelTimestampsById: this.labelTimestampsById,
|
|
493
|
+
});
|
|
494
|
+
const header = result.fileEntries[0];
|
|
495
|
+
const entries = getEntriesWithoutHeader(result.fileEntries);
|
|
496
|
+
const record = this.recordHeader(header);
|
|
497
|
+
const store = await this.storeForNewSession();
|
|
498
|
+
const location = store instanceof JsonlSessionStore
|
|
499
|
+
? this.sessionDir
|
|
500
|
+
? createSessionFilePath(this.sessionDir, record.createdAt, record.id)
|
|
501
|
+
: store.locationFor(record)
|
|
502
|
+
: undefined;
|
|
503
|
+
const lastSeq = (await (store instanceof JsonlSessionStore
|
|
504
|
+
? store.create(record, entries, location)
|
|
505
|
+
: store.create(record, entries))).lastSeq;
|
|
506
|
+
this.store = store;
|
|
507
|
+
this.fileEntries = result.fileEntries;
|
|
508
|
+
this.sessionId = header.id;
|
|
509
|
+
this.lastSeq = lastSeq;
|
|
510
|
+
this.sessionFile = location;
|
|
511
|
+
this._buildIndex();
|
|
512
|
+
return this.sessionFile;
|
|
414
513
|
});
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.
|
|
424
|
-
|
|
514
|
+
}
|
|
515
|
+
async forkTo(cwd, sessionDir, options) {
|
|
516
|
+
const store = typeof sessionDir === "string"
|
|
517
|
+
? await JsonlSessionStore.open(sessionDir, { exactDirectory: true, scanExisting: false })
|
|
518
|
+
: (sessionDir ?? (await resolveSessionStore(cwd)));
|
|
519
|
+
const directory = store instanceof JsonlSessionStore ? store.descriptor.location : "";
|
|
520
|
+
return SessionManager.constructWithStore(store, store !== sessionDir, async () => {
|
|
521
|
+
const manager = new SessionManager(store, cwd, directory, { ...options, parentSession: this.sessionId });
|
|
522
|
+
manager.fileEntries.push(...this.getEntries());
|
|
523
|
+
await manager.initialize();
|
|
524
|
+
manager._buildIndex();
|
|
525
|
+
return manager;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
static async importFromJsonl(inputPath, cwd, sessionDir) {
|
|
529
|
+
const store = typeof sessionDir === "string"
|
|
530
|
+
? await JsonlSessionStore.open(sessionDir, { exactDirectory: true, scanExisting: false })
|
|
531
|
+
: (sessionDir ?? (await resolveSessionStore(cwd)));
|
|
532
|
+
return SessionManager.constructWithStore(store, store !== sessionDir, () => new SessionManager(store, cwd, store instanceof JsonlSessionStore ? store.descriptor.location : "").importFromJsonl(inputPath));
|
|
533
|
+
}
|
|
534
|
+
static async constructWithStore(store, owned, construct) {
|
|
535
|
+
try {
|
|
536
|
+
return await construct();
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
if (owned) {
|
|
540
|
+
try {
|
|
541
|
+
await store.close();
|
|
542
|
+
}
|
|
543
|
+
catch (cause) {
|
|
544
|
+
throw new StorageRollbackError(error, cause);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
static async create(cwdOrStore, directoryOrCwd, options) {
|
|
551
|
+
const cwd = typeof cwdOrStore === "string" ? cwdOrStore : (directoryOrCwd ?? process.cwd());
|
|
552
|
+
if (typeof cwdOrStore === "string" && directoryOrCwd === undefined) {
|
|
553
|
+
const store = await resolveSessionStore(cwd);
|
|
554
|
+
return SessionManager.constructWithStore(store, true, () => SessionManager.create(store, cwd, options));
|
|
555
|
+
}
|
|
556
|
+
const directory = typeof cwdOrStore === "string"
|
|
557
|
+
? directoryOrCwd
|
|
558
|
+
? normalizePath(directoryOrCwd)
|
|
559
|
+
: getDefaultSessionDirPath(cwd)
|
|
560
|
+
: cwdOrStore instanceof JsonlSessionStore
|
|
561
|
+
? cwdOrStore.descriptor.location
|
|
562
|
+
: "";
|
|
563
|
+
const store = typeof cwdOrStore === "string"
|
|
564
|
+
? await JsonlSessionStore.open(directory, { exactDirectory: true, scanExisting: false })
|
|
565
|
+
: cwdOrStore;
|
|
566
|
+
return SessionManager.constructWithStore(store, store !== cwdOrStore, async () => {
|
|
567
|
+
const manager = new SessionManager(store, cwd, directory, options);
|
|
568
|
+
if (typeof cwdOrStore !== "string" && store instanceof JsonlSessionStore) {
|
|
569
|
+
manager.sessionFile = store.locationFor(manager.recordHeader());
|
|
570
|
+
manager.sessionDir = dirname(manager.sessionFile);
|
|
571
|
+
}
|
|
572
|
+
await manager.initialize();
|
|
573
|
+
return manager;
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
static async open(pathOrStore, directoryOrId, cwdOverride) {
|
|
577
|
+
if (typeof pathOrStore !== "string") {
|
|
578
|
+
const snapshot = await pathOrStore.load(directoryOrId);
|
|
579
|
+
if (snapshot.header.id !== directoryOrId)
|
|
580
|
+
throw new SessionIdMismatchError(directoryOrId, snapshot.header.id);
|
|
581
|
+
const manager = new SessionManager(pathOrStore, cwdOverride ?? snapshot.header.cwd, pathOrStore instanceof JsonlSessionStore ? pathOrStore.descriptor.location : "");
|
|
582
|
+
manager.restore(snapshot, pathOrStore instanceof JsonlSessionStore ? await pathOrStore.findFile(directoryOrId) : undefined);
|
|
583
|
+
if (manager.sessionFile)
|
|
584
|
+
manager.sessionDir = dirname(manager.sessionFile);
|
|
585
|
+
return manager;
|
|
586
|
+
}
|
|
587
|
+
const path = resolvePath(pathOrStore);
|
|
588
|
+
const directory = directoryOrId ?? dirname(path);
|
|
589
|
+
const store = await JsonlSessionStore.open(dirname(path), { exactDirectory: true, scanExisting: false });
|
|
590
|
+
let snapshot;
|
|
591
|
+
try {
|
|
592
|
+
snapshot = await store.loadFile(path);
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
if (!(error instanceof StorageUnavailableError) || error.cause.code !== "ENOENT")
|
|
596
|
+
throw error;
|
|
597
|
+
const manager = new SessionManager(store, cwdOverride ?? process.cwd(), directory);
|
|
598
|
+
manager.lastSeq = (await store.create(manager.recordHeader(), [], path)).lastSeq;
|
|
599
|
+
manager.sessionFile = path;
|
|
600
|
+
return manager;
|
|
601
|
+
}
|
|
602
|
+
const manager = new SessionManager(store, cwdOverride ?? snapshot.header.cwd, directory);
|
|
603
|
+
manager.restore(snapshot, path);
|
|
604
|
+
return manager;
|
|
605
|
+
}
|
|
606
|
+
static async continueRecent(cwdOrStore, directoryOrCwd, options) {
|
|
607
|
+
const cwd = typeof cwdOrStore === "string" ? cwdOrStore : directoryOrCwd;
|
|
608
|
+
if (typeof cwdOrStore === "string" && directoryOrCwd === undefined) {
|
|
609
|
+
const store = await resolveSessionStore(cwd);
|
|
610
|
+
return SessionManager.constructWithStore(store, true, () => SessionManager.continueRecent(store, cwd, options));
|
|
425
611
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
static continueRecent(cwd, sessionDir, options) {
|
|
444
|
-
const dir = sessionDir ? normalizePath(sessionDir) : getDefaultSessionDir(cwd);
|
|
445
|
-
const filterCwd = sessionDir !== undefined && dir !== getDefaultSessionDirPath(cwd);
|
|
446
|
-
const mostRecent = findMostRecentSession(dir, filterCwd ? cwd : undefined, options?.includeInternal === true);
|
|
447
|
-
return new SessionManager(cwd, dir, mostRecent ?? undefined, true);
|
|
448
|
-
}
|
|
449
|
-
/** Create an in-memory session (no file persistence), optionally preloaded with entries. */
|
|
612
|
+
const directory = typeof cwdOrStore === "string" ? (directoryOrCwd ?? getDefaultSessionDirPath(cwd)) : "";
|
|
613
|
+
const store = typeof cwdOrStore === "string"
|
|
614
|
+
? await JsonlSessionStore.open(directory, { exactDirectory: true, scanExisting: false })
|
|
615
|
+
: cwdOrStore;
|
|
616
|
+
return SessionManager.constructWithStore(store, store !== cwdOrStore, async () => {
|
|
617
|
+
const recent = await store.findMostRecent({
|
|
618
|
+
cwd: resolvePath(cwd),
|
|
619
|
+
includeInternal: options?.includeInternal,
|
|
620
|
+
});
|
|
621
|
+
const manager = new SessionManager(store, cwd, directory);
|
|
622
|
+
if (recent)
|
|
623
|
+
manager.restore(await store.load(recent.id), recent.location);
|
|
624
|
+
else
|
|
625
|
+
await manager.initialize();
|
|
626
|
+
return manager;
|
|
627
|
+
});
|
|
628
|
+
}
|
|
450
629
|
static inMemory(cwd = process.cwd(), options, entries) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const resolvedCwd = resolvePath(cwd);
|
|
630
|
+
const manager = new SessionManager(new MemorySessionStore(createSessionCwdMatcher), cwd, "", options);
|
|
631
|
+
if (entries?.length) {
|
|
632
|
+
manager.fileEntries = entries[0].type === "session" ? entries : [...manager.fileEntries, ...entries];
|
|
633
|
+
manager.sessionId = manager.getHeader().id;
|
|
634
|
+
manager._buildIndex();
|
|
635
|
+
}
|
|
636
|
+
manager.mutation = manager.initialize();
|
|
637
|
+
return manager;
|
|
638
|
+
}
|
|
639
|
+
static async forkFrom(sourcePath, targetCwd, sessionDir, options) {
|
|
640
|
+
const sourceStore = await JsonlSessionStore.open(dirname(resolvePath(sourcePath)), {
|
|
641
|
+
exactDirectory: true,
|
|
642
|
+
scanExisting: false,
|
|
643
|
+
});
|
|
644
|
+
let source;
|
|
467
645
|
try {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
646
|
+
source = await sourceStore.loadFile(resolvePath(sourcePath));
|
|
647
|
+
}
|
|
648
|
+
finally {
|
|
649
|
+
await sourceStore.close();
|
|
650
|
+
}
|
|
651
|
+
const store = sessionDir === undefined
|
|
652
|
+
? await resolveSessionStore(targetCwd)
|
|
653
|
+
: await JsonlSessionStore.open(sessionDir, { exactDirectory: true, scanExisting: false });
|
|
654
|
+
return SessionManager.constructWithStore(store, true, async () => {
|
|
655
|
+
const manager = new SessionManager(store, targetCwd, sessionDir ?? "", {
|
|
656
|
+
...options,
|
|
657
|
+
parentSession: source.header.id,
|
|
658
|
+
});
|
|
659
|
+
manager.fileEntries.push(...source.entries);
|
|
660
|
+
await manager.initialize();
|
|
661
|
+
manager._buildIndex();
|
|
662
|
+
return manager;
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
static async findById(cwd, id, sessionDir) {
|
|
666
|
+
const store = sessionDir === undefined
|
|
667
|
+
? await resolveSessionStore(cwd)
|
|
668
|
+
: await JsonlSessionStore.open(sessionDir, { exactDirectory: true, scanExisting: false });
|
|
669
|
+
try {
|
|
670
|
+
const header = await store.readHeader(id);
|
|
671
|
+
if (!header ||
|
|
672
|
+
classifiedWorkflowMetadata(header) ||
|
|
673
|
+
!createSessionCwdMatcher(resolvePath(cwd))(resolvePath(header.cwd)))
|
|
674
|
+
return undefined;
|
|
675
|
+
return store instanceof JsonlSessionStore ? await store.findFile(id) : id;
|
|
676
|
+
}
|
|
677
|
+
catch (error) {
|
|
678
|
+
if (error instanceof SessionFormatVersionError)
|
|
679
|
+
return undefined;
|
|
680
|
+
throw error;
|
|
479
681
|
}
|
|
480
|
-
|
|
481
|
-
|
|
682
|
+
finally {
|
|
683
|
+
await store.close();
|
|
482
684
|
}
|
|
483
|
-
return undefined;
|
|
484
685
|
}
|
|
485
|
-
/** List sessions for a directory. Internal (workflow) sessions are excluded unless `includeInternal: true`. */
|
|
486
686
|
static async list(cwd, sessionDir, onProgress, options) {
|
|
487
687
|
const signal = options && "aborted" in options ? options : options?.signal;
|
|
688
|
+
if (typeof sessionDir !== "string") {
|
|
689
|
+
const store = sessionDir ?? (await resolveSessionStore(cwd));
|
|
690
|
+
try {
|
|
691
|
+
return await listSessionStore(store, {
|
|
692
|
+
cwd: resolvePath(cwd),
|
|
693
|
+
signal,
|
|
694
|
+
includeInternal: options !== undefined && "includeInternal" in options && options.includeInternal === true,
|
|
695
|
+
}, onProgress);
|
|
696
|
+
}
|
|
697
|
+
finally {
|
|
698
|
+
if (sessionDir === undefined)
|
|
699
|
+
await store.close();
|
|
700
|
+
}
|
|
701
|
+
}
|
|
488
702
|
return listProjectSessions(cwd, sessionDir, onProgress, options !== undefined && "includeInternal" in options && options.includeInternal === true, signal);
|
|
489
703
|
}
|
|
490
|
-
static async listAll(
|
|
491
|
-
|
|
704
|
+
static async listAll(directoryOrProgress, progressOrSignal, options) {
|
|
705
|
+
if (typeof directoryOrProgress !== "string") {
|
|
706
|
+
const supplied = typeof directoryOrProgress === "object" ? directoryOrProgress : undefined;
|
|
707
|
+
const store = supplied ?? (await resolveSessionStore(process.cwd()));
|
|
708
|
+
try {
|
|
709
|
+
return await listSessionStore(store, {
|
|
710
|
+
includeInternal: options !== undefined && "includeInternal" in options && options.includeInternal === true,
|
|
711
|
+
signal: options && "aborted" in options
|
|
712
|
+
? options
|
|
713
|
+
: (options?.signal ?? (typeof progressOrSignal === "object" ? progressOrSignal : undefined)),
|
|
714
|
+
}, typeof directoryOrProgress === "function"
|
|
715
|
+
? directoryOrProgress
|
|
716
|
+
: typeof progressOrSignal === "function"
|
|
717
|
+
? progressOrSignal
|
|
718
|
+
: undefined);
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
if (!supplied)
|
|
722
|
+
await store.close();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const { listAllSessions } = await import("./session-manager-list.js");
|
|
726
|
+
return listAllSessions(directoryOrProgress, typeof progressOrSignal === "function" ? progressOrSignal : undefined, options !== undefined && "includeInternal" in options && options.includeInternal === true, options && "aborted" in options
|
|
492
727
|
? options
|
|
493
|
-
: (options?.signal ?? (typeof
|
|
494
|
-
return listAllSessions(sessionDirOrOnProgress, typeof onProgress === "function" ? onProgress : undefined, options !== undefined && "includeInternal" in options && options.includeInternal === true, signal);
|
|
728
|
+
: (options?.signal ?? (typeof progressOrSignal === "object" ? progressOrSignal : undefined)));
|
|
495
729
|
}
|
|
496
730
|
}
|
|
497
731
|
//# sourceMappingURL=session-manager-core.js.map
|