@bastani/atomic 0.9.38-alpha.5 → 0.9.38-alpha.7
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 +70 -0
- package/README.md +8 -6
- package/dist/builtin/intercom/CHANGELOG.md +9 -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 +78 -33
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +140 -145
- 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 +48 -0
- package/dist/builtin/workflows/builtin/{chunk-q7dx7kh7.js → chunk-85mx6wcf.js} +6 -6
- package/dist/builtin/workflows/builtin/{chunk-xg7kkgf8.js → chunk-8kkv04hz.js} +15 -15
- package/dist/builtin/workflows/builtin/{chunk-na3wpwzh.js → chunk-8x61e0s7.js} +396 -363
- package/dist/builtin/workflows/builtin/{chunk-qrrkfg9v.js → chunk-y45tkftg.js} +7 -7
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/authoring.d.ts +3 -8
- package/dist/builtin/workflows/src/durable/journal/conformance.d.ts +9 -1
- 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/memory-run-journal.d.ts +9 -1
- package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +19 -8
- package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +45 -0
- package/dist/builtin/workflows/src/durable/journal/sqlite-run-journal.d.ts +5 -47
- package/dist/builtin/workflows/src/durable/journal/types.d.ts +9 -114
- package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +6963 -6181
- package/dist/builtin/workflows/src/index.js +9078 -8395
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +8 -8
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +0 -14
- 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/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.js +2 -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 +2 -2
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +75 -59
- 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 +15 -15
- 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 +17 -15
- 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-summary.js +1 -1
- package/dist/core/agent-session-summary.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 +7 -7
- package/dist/core/agent-session-tree.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 +1 -4
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +0 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -1
- package/dist/core/compaction/pi-summary-fallback.js +1 -3
- package/dist/core/compaction/pi-summary-fallback.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 +1 -1
- 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/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 +3 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +20 -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/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 +765 -0
- 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-resolver-defaults.js +1 -1
- package/dist/core/model-resolver-defaults.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/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 +50 -20
- 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 -104
- 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 +547 -307
- 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 +21 -14
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts +3 -13
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +28 -69
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +3 -11
- 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-validation.d.ts.map +1 -1
- package/dist/core/session-manager-validation.js +3 -2
- package/dist/core/session-manager-validation.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -1
- 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 +155 -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 +0 -1
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +0 -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 +74 -8
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +29 -29
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/storage/errors.d.ts +1 -0
- package/dist/core/storage/errors.d.ts.map +1 -1
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/index.d.ts +5 -1
- package/dist/core/storage/index.d.ts.map +1 -1
- package/dist/core/storage/index.js +4 -1
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/node-sqlite.d.ts +2 -0
- package/dist/core/storage/node-sqlite.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite.js +47 -6
- package/dist/core/storage/node-sqlite.js.map +1 -1
- 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/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/jsonl-session-store.d.ts +11 -2
- package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/jsonl-session-store.js +127 -54
- package/dist/core/storage/session/jsonl-session-store.js.map +1 -1
- package/dist/core/storage/session/legacy-format.d.ts +18 -0
- package/dist/core/storage/session/legacy-format.d.ts.map +1 -0
- package/dist/core/storage/session/legacy-format.js +63 -0
- package/dist/core/storage/session/legacy-format.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.d.ts +3 -1
- package/dist/core/storage/session/memory-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/memory-session-store.js +9 -2
- package/dist/core/storage/session/memory-session-store.js.map +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +4 -1
- package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/sql-session-store.js +25 -6
- package/dist/core/storage/session/sql-session-store.js.map +1 -1
- package/dist/core/storage/session/types.d.ts +4 -0
- package/dist/core/storage/session/types.d.ts.map +1 -1
- package/dist/core/storage/session/types.js.map +1 -1
- package/dist/core/storage/session/validation.js +1 -1
- package/dist/core/storage/session/validation.js.map +1 -1
- package/dist/core/storage/testing.d.ts +2 -0
- package/dist/core/storage/testing.d.ts.map +1 -1
- package/dist/core/storage/testing.js +45 -0
- package/dist/core/storage/testing.js.map +1 -1
- 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/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/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.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.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 +148 -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 +16 -7
- 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 +4 -1
- 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 +27 -18
- 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/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-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-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-slash-commands.js +5 -3
- package/dist/modes/interactive/interactive-slash-commands.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/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/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-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 +1 -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 +8 -8
- package/docs/extensions.md +2 -2
- package/docs/getting-started/installation.md +1 -2
- package/docs/models/reference.md +2 -0
- package/docs/models-configuration.md +206 -0
- package/docs/models.md +11 -1
- package/docs/providers.md +4 -4
- package/docs/quickstart.md +2 -1
- package/docs/reference/cli.md +7 -3
- package/docs/rpc/protocol.md +10 -4
- package/docs/sdk/reference.md +15 -13
- package/docs/sdk/web-server.md +5 -6
- package/docs/sdk.md +56 -2
- package/docs/session-format.md +35 -28
- package/docs/sessions.md +50 -17
- package/docs/settings.md +44 -7
- package/docs/storage.md +346 -2
- package/docs/usage.md +3 -2
- package/docs/workflows/api-reference.md +80 -16
- package/docs/workflows/operations.md +6 -4
- package/docs/workflows/reliable-design.md +16 -16
- package/examples/extensions/bookmark.ts +2 -2
- package/examples/extensions/handoff.ts +2 -2
- 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/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 -53
- package/package.json +7 -6
- package/schemas/models.schema.json +62 -29
- package/schemas/settings.schema.json +137 -53
- package/dist/builtin/workflows/builtin/chunk-h5fn47y5.js +0 -8
- package/dist/builtin/workflows/src/durable/journal/node-sqlite.d.ts +0 -20
|
@@ -1,119 +1,138 @@
|
|
|
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 { 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";
|
|
6
7
|
import { classifiedWorkflowMetadata, validSessionWorkflowMetadata } from "./session-manager-classification.js";
|
|
7
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";
|
|
8
10
|
import { buildContextEntries, buildSessionIndex, buildSessionProjection, buildSessionTree, getBranchPath, } from "./session-manager-history.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { ensureDirectory, findMostRecentSession, getSessionHeaderCwd, hasConversationMessage, isInternalHeader, loadEntriesFromFile, persistAppendedEntry, readSessionHeader, sessionCwdMatches, writeSessionEntries, } from "./session-manager-storage.js";
|
|
11
|
+
import { listProjectSessions } from "./session-manager-list.js";
|
|
12
|
+
import { getDefaultSessionDirPath } from "./session-manager-paths.js";
|
|
12
13
|
import { assertValidSessionId, createSessionId, generateId, validateSessionFileEntries, } from "./session-manager-validation.js";
|
|
13
|
-
import {
|
|
14
|
-
|
|
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. */
|
|
15
24
|
export class SessionManager {
|
|
16
25
|
sessionId = "";
|
|
17
26
|
sessionFile;
|
|
18
27
|
sessionDir;
|
|
19
28
|
cwd;
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
store;
|
|
30
|
+
lastSeq = 0;
|
|
31
|
+
mutation = Promise.resolve();
|
|
22
32
|
fileEntries = [];
|
|
23
33
|
byId = new Map();
|
|
24
34
|
labelsById = new Map();
|
|
25
35
|
labelTimestampsById = new Map();
|
|
26
36
|
leafId = null;
|
|
27
|
-
constructor(cwd, sessionDir,
|
|
37
|
+
constructor(store, cwd, sessionDir, options) {
|
|
38
|
+
this.store = store;
|
|
28
39
|
this.cwd = resolvePath(cwd);
|
|
29
40
|
this.sessionDir = normalizePath(sessionDir);
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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();
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.fileEntries = this.fileEntries.concat(entries);
|
|
53
|
-
}
|
|
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;
|
|
54
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;
|
|
55
77
|
}
|
|
56
|
-
/** Switch to a different session file (used for resume and branching) */
|
|
57
78
|
setSessionFile(sessionFile) {
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
const header = validateSessionFileEntries(entries, explicitPath);
|
|
76
|
-
this.sessionFile = explicitPath;
|
|
77
|
-
this.fileEntries = entries;
|
|
78
|
-
this.sessionId = header.id;
|
|
79
|
-
this._buildIndex();
|
|
80
|
-
this.flushed = true;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.newSession();
|
|
84
|
-
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 });
|
|
85
95
|
}
|
|
96
|
+
return this.store;
|
|
86
97
|
}
|
|
87
98
|
newSession(options) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
});
|
|
104
120
|
}
|
|
105
|
-
/** Mark the session as workflow-owned, repairing malformed markers while preserving valid ownership. */
|
|
106
121
|
markSessionInternal(workflow) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
});
|
|
117
136
|
}
|
|
118
137
|
_buildIndex() {
|
|
119
138
|
validateSessionFileEntries(this.fileEntries, this.sessionFile ?? "in-memory session");
|
|
@@ -123,25 +142,8 @@ export class SessionManager {
|
|
|
123
142
|
this.labelTimestampsById = index.labelTimestampsById;
|
|
124
143
|
this.leafId = index.leafId;
|
|
125
144
|
}
|
|
126
|
-
_rewriteFile() {
|
|
127
|
-
if (!this.persist || !this.sessionFile)
|
|
128
|
-
return;
|
|
129
|
-
writeSessionEntries(this.sessionFile, this.fileEntries);
|
|
130
|
-
}
|
|
131
145
|
isPersisted() {
|
|
132
|
-
return this.
|
|
133
|
-
}
|
|
134
|
-
/** Persist the current session tree before an in-process attempt is force-finalized. */
|
|
135
|
-
flush() {
|
|
136
|
-
if (!this.persist || !this.sessionFile)
|
|
137
|
-
return;
|
|
138
|
-
this._rewriteFile();
|
|
139
|
-
this.flushed = true;
|
|
140
|
-
}
|
|
141
|
-
/** Flush only a session whose file has already been started, so closing an unsaved session writes nothing. */
|
|
142
|
-
flushIfStarted() {
|
|
143
|
-
if (this.flushed || hasConversationMessage(this.fileEntries))
|
|
144
|
-
this.flush();
|
|
146
|
+
return !(this.store instanceof MemorySessionStore);
|
|
145
147
|
}
|
|
146
148
|
getCwd() {
|
|
147
149
|
return this.cwd;
|
|
@@ -158,127 +160,203 @@ export class SessionManager {
|
|
|
158
160
|
getSessionFile() {
|
|
159
161
|
return this.sessionFile;
|
|
160
162
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return;
|
|
164
|
-
this.flushed = persistAppendedEntry(this.sessionFile, this.fileEntries, entry, this.flushed);
|
|
163
|
+
getSessionStore() {
|
|
164
|
+
return this.store;
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
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;
|
|
171
186
|
try {
|
|
172
|
-
|
|
187
|
+
snapshot = await store.load(sessionId);
|
|
173
188
|
}
|
|
174
189
|
catch (error) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
await source.close();
|
|
180
224
|
}
|
|
181
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;
|
|
232
|
+
}
|
|
182
233
|
/** Append a message as child of current leaf, then advance leaf. Returns entry id. */
|
|
183
234
|
appendMessage(message) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
235
|
+
return this.runMutation(async () => {
|
|
236
|
+
const entry = createMessageEntry(message, this.byId, this.leafId);
|
|
237
|
+
await this._appendEntry(entry);
|
|
238
|
+
return entry.id;
|
|
239
|
+
});
|
|
187
240
|
}
|
|
188
241
|
/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */
|
|
189
242
|
appendThinkingLevelChange(thinkingLevel) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
243
|
+
return this.runMutation(async () => {
|
|
244
|
+
const entry = createThinkingLevelChangeEntry(thinkingLevel, this.byId, this.leafId);
|
|
245
|
+
await this._appendEntry(entry);
|
|
246
|
+
return entry.id;
|
|
247
|
+
});
|
|
193
248
|
}
|
|
194
249
|
/** Record auxiliary model usage without adding it to the LLM context. */
|
|
195
250
|
appendUsage(kind, provider, model, usage, note) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
+
});
|
|
209
266
|
}
|
|
210
267
|
/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */
|
|
211
268
|
appendModelChange(provider, modelId) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
+
});
|
|
215
274
|
}
|
|
216
275
|
appendCompaction(compactedText, firstKeptEntryId, tokensBefore, details, usage) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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. */
|
|
227
288
|
writeBackupSnapshot(label = "compact") {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
+
});
|
|
231
301
|
}
|
|
232
302
|
/** Append a branch-local edit to an earlier model-visible entry. */
|
|
233
303
|
appendContextEdit(targetId, replacement) {
|
|
234
|
-
|
|
235
|
-
(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
(target.
|
|
249
|
-
target.message.role === "
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
});
|
|
262
334
|
}
|
|
263
335
|
/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */
|
|
264
336
|
appendCustomEntry(customType, data) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
+
});
|
|
268
342
|
}
|
|
269
343
|
/** Append a session info entry (e.g., display name). Returns entry id. */
|
|
270
344
|
appendSessionInfo(name) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
345
|
+
return this.runMutation(async () => {
|
|
346
|
+
const entry = createSessionInfoEntry(name, this.byId, this.leafId);
|
|
347
|
+
await this._appendEntry(entry);
|
|
348
|
+
return entry.id;
|
|
349
|
+
});
|
|
274
350
|
}
|
|
275
351
|
/** Append a generated resume summary anchored to the message it describes. Returns entry id. */
|
|
276
352
|
appendSessionSummary(summary, summarizedThroughId, usage) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
+
});
|
|
282
360
|
}
|
|
283
361
|
/** Get the current session name from the latest session_info entry, if any. */
|
|
284
362
|
getSessionName() {
|
|
@@ -294,9 +372,11 @@ export class SessionManager {
|
|
|
294
372
|
}
|
|
295
373
|
/** Append a custom message entry (for extensions) that participates in LLM context unless excluded. */
|
|
296
374
|
appendCustomMessageEntry(customType, content, display, details, excludeFromContext, protectedReconciliation, stageAdmissionKey) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
});
|
|
300
380
|
}
|
|
301
381
|
getLeafId() {
|
|
302
382
|
return this.leafId;
|
|
@@ -323,20 +403,22 @@ export class SessionManager {
|
|
|
323
403
|
}
|
|
324
404
|
/** Set or clear a label on an entry. */
|
|
325
405
|
appendLabelChange(targetId, label) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
+
});
|
|
340
422
|
}
|
|
341
423
|
/** Walk from entry to root, returning all entries in path order. */
|
|
342
424
|
getBranch(fromId) {
|
|
@@ -374,118 +456,276 @@ export class SessionManager {
|
|
|
374
456
|
}
|
|
375
457
|
/** Start a new branch from an earlier entry. */
|
|
376
458
|
branch(branchFromId) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
459
|
+
return this.runMutation(async () => {
|
|
460
|
+
if (!this.byId.has(branchFromId)) {
|
|
461
|
+
throw new SessionEntryError(branchFromId, "missing");
|
|
462
|
+
}
|
|
463
|
+
this.leafId = branchFromId;
|
|
464
|
+
});
|
|
381
465
|
}
|
|
382
466
|
/** Reset the leaf pointer to null (before any entries). */
|
|
383
467
|
resetLeaf() {
|
|
384
|
-
this.
|
|
468
|
+
return this.runMutation(async () => {
|
|
469
|
+
this.leafId = null;
|
|
470
|
+
});
|
|
385
471
|
}
|
|
386
472
|
/** Start a new branch with a summary of the abandoned path. */
|
|
387
|
-
branchWithSummary(branchFromId, summary, details, fromHook, usage, fromId
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
+
});
|
|
395
482
|
}
|
|
396
|
-
/** Create a new session file containing only the path from root to the specified leaf. */
|
|
397
483
|
createBranchedSession(leafId) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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;
|
|
408
513
|
});
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
this.
|
|
418
|
-
|
|
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;
|
|
419
548
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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));
|
|
611
|
+
}
|
|
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
|
+
}
|
|
444
629
|
static inMemory(cwd = process.cwd(), options, entries) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
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;
|
|
461
645
|
try {
|
|
462
|
-
|
|
463
|
-
if (!file.endsWith(".jsonl"))
|
|
464
|
-
continue;
|
|
465
|
-
const path = join(dir, file);
|
|
466
|
-
const header = readSessionHeader(path);
|
|
467
|
-
if (header?.id !== id || isInternalHeader(header))
|
|
468
|
-
continue;
|
|
469
|
-
if (filterCwd && !sessionCwdMatches(getSessionHeaderCwd(header), resolvedCwd))
|
|
470
|
-
continue;
|
|
471
|
-
return path;
|
|
472
|
-
}
|
|
646
|
+
source = await sourceStore.loadFile(resolvePath(sourcePath));
|
|
473
647
|
}
|
|
474
|
-
|
|
475
|
-
|
|
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;
|
|
681
|
+
}
|
|
682
|
+
finally {
|
|
683
|
+
await store.close();
|
|
476
684
|
}
|
|
477
|
-
return undefined;
|
|
478
685
|
}
|
|
479
|
-
/** List sessions for a directory. Internal (workflow) sessions are excluded unless `includeInternal: true`. */
|
|
480
686
|
static async list(cwd, sessionDir, onProgress, options) {
|
|
481
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
|
+
}
|
|
482
702
|
return listProjectSessions(cwd, sessionDir, onProgress, options !== undefined && "includeInternal" in options && options.includeInternal === true, signal);
|
|
483
703
|
}
|
|
484
|
-
static async listAll(
|
|
485
|
-
|
|
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
|
|
486
727
|
? options
|
|
487
|
-
: (options?.signal ?? (typeof
|
|
488
|
-
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)));
|
|
489
729
|
}
|
|
490
730
|
}
|
|
491
731
|
//# sourceMappingURL=session-manager-core.js.map
|