@bastani/atomic 0.10.2 → 0.10.3
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 +120 -0
- package/dist/builtin/intercom/CHANGELOG.md +22 -0
- package/dist/builtin/intercom/broker/broker-instance.ts +2 -13
- package/dist/builtin/intercom/broker/broker.ts +158 -73
- package/dist/builtin/intercom/broker/durable-ended-queue.ts +14 -2
- package/dist/builtin/intercom/broker/host-command-environment.ts +13 -0
- package/dist/builtin/intercom/broker/hosted-session-errors.ts +1 -0
- package/dist/builtin/intercom/broker/multinode-router.ts +111 -16
- package/dist/builtin/intercom/broker/multinode-state-store.ts +50 -4
- package/dist/builtin/intercom/broker/open-broker-state.ts +5 -4
- package/dist/builtin/intercom/broker/spawn.ts +144 -25
- package/dist/builtin/intercom/broker/sql-add-column.ts +33 -0
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +120 -36
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +75 -13
- package/dist/builtin/intercom/broker/start-announcement.ts +55 -10
- package/dist/builtin/intercom/broker/watchdog.ts +10 -7
- package/dist/builtin/intercom/index.bundle.mjs +111 -27
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +26 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/skill-creator/SKILL.md +30 -52
- package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +34 -40
- package/dist/builtin/subagents/skills/skill-creator/eval-viewer/viewer.html +2 -2
- package/dist/builtin/subagents/skills/skill-creator/scripts/atomic_cli.py +731 -0
- package/dist/builtin/subagents/skills/skill-creator/scripts/generate_report.py +3 -3
- package/dist/builtin/subagents/skills/skill-creator/scripts/improve_description.py +41 -38
- package/dist/builtin/subagents/skills/skill-creator/scripts/run_eval.py +276 -176
- package/dist/builtin/subagents/skills/skill-creator/scripts/run_loop.py +20 -11
- package/dist/builtin/subagents/skills/skill-creator/scripts/utils.py +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +163 -97
- package/dist/builtin/web-access/CHANGELOG.md +14 -0
- package/dist/builtin/web-access/index.bundle.mjs +5 -4
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts +10 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +54 -2
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts +4 -0
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +17 -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 +3 -1
- package/dist/core/agent-session-custom-message-commit.js.map +1 -1
- package/dist/core/agent-session-events.d.ts +2 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +34 -13
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +3 -0
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +27 -0
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +213 -30
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +6 -1
- 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-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +35 -3
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -2
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +6 -1
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +15 -2
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-typed-queue.d.ts +14 -1
- package/dist/core/agent-session-typed-queue.d.ts.map +1 -1
- package/dist/core/agent-session-typed-queue.js +26 -1
- package/dist/core/agent-session-typed-queue.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +5 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/async-scope.d.ts +9 -4
- package/dist/core/async-scope.d.ts.map +1 -1
- package/dist/core/async-scope.js +13 -5
- package/dist/core/async-scope.js.map +1 -1
- package/dist/core/builtin-diagnostics.js +2 -2
- package/dist/core/builtin-diagnostics.js.map +1 -1
- package/dist/core/chat-admission-order.d.ts.map +1 -1
- package/dist/core/chat-admission-order.js +2 -1
- package/dist/core/chat-admission-order.js.map +1 -1
- package/dist/core/chat-record-saves.d.ts +4 -0
- package/dist/core/chat-record-saves.d.ts.map +1 -0
- package/dist/core/chat-record-saves.js +25 -0
- package/dist/core/chat-record-saves.js.map +1 -0
- package/dist/core/command-deliveries.d.ts +62 -0
- package/dist/core/command-deliveries.d.ts.map +1 -0
- package/dist/core/command-deliveries.js +139 -0
- package/dist/core/command-deliveries.js.map +1 -0
- package/dist/core/diagnostic-writer.d.ts.map +1 -1
- package/dist/core/diagnostic-writer.js +5 -4
- package/dist/core/diagnostic-writer.js.map +1 -1
- package/dist/core/extension-startup-close.d.ts +1 -2
- package/dist/core/extension-startup-close.d.ts.map +1 -1
- package/dist/core/extension-startup-close.js +2 -2
- package/dist/core/extension-startup-close.js.map +1 -1
- package/dist/core/extensions/jiti-aliases.d.ts +11 -0
- package/dist/core/extensions/jiti-aliases.d.ts.map +1 -0
- package/dist/core/extensions/jiti-aliases.js +28 -0
- package/dist/core/extensions/jiti-aliases.js.map +1 -0
- package/dist/core/extensions/loader-api.js +3 -3
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-bindings.js +2 -2
- package/dist/core/extensions/loader-bindings.js.map +1 -1
- package/dist/core/extensions/loader-rollback.d.ts +1 -2
- package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
- package/dist/core/extensions/loader-rollback.js +2 -2
- 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 +53 -9
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/native-builtin-entries.d.ts +5 -0
- package/dist/core/extensions/native-builtin-entries.d.ts.map +1 -1
- package/dist/core/extensions/native-builtin-entries.js +8 -1
- package/dist/core/extensions/native-builtin-entries.js.map +1 -1
- package/dist/core/extensions/reloadable-scripts.d.ts +21 -2
- package/dist/core/extensions/reloadable-scripts.d.ts.map +1 -1
- package/dist/core/extensions/reloadable-scripts.js +11 -3
- package/dist/core/extensions/reloadable-scripts.js.map +1 -1
- package/dist/core/extensions/source-builtin-imports.d.ts +40 -0
- package/dist/core/extensions/source-builtin-imports.d.ts.map +1 -0
- package/dist/core/extensions/source-builtin-imports.js +142 -0
- package/dist/core/extensions/source-builtin-imports.js.map +1 -0
- package/dist/core/extensions/transform-graph.d.ts +15 -0
- package/dist/core/extensions/transform-graph.d.ts.map +1 -0
- package/dist/core/extensions/transform-graph.js +85 -0
- package/dist/core/extensions/transform-graph.js.map +1 -0
- package/dist/core/extensions/ts-source-specifiers.d.ts +2 -0
- package/dist/core/extensions/ts-source-specifiers.d.ts.map +1 -1
- package/dist/core/extensions/ts-source-specifiers.js +7 -0
- package/dist/core/extensions/ts-source-specifiers.js.map +1 -1
- package/dist/core/extensions/ts-transform-worker.d.ts +2 -0
- package/dist/core/extensions/ts-transform-worker.d.ts.map +1 -0
- package/dist/core/extensions/ts-transform-worker.js +43 -0
- package/dist/core/extensions/ts-transform-worker.js.map +1 -0
- package/dist/core/message-admission.d.ts.map +1 -1
- package/dist/core/message-admission.js +4 -4
- package/dist/core/message-admission.js.map +1 -1
- package/dist/core/messages.d.ts +5 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +35 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts +1 -1
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +18 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/process-start-token.d.ts +7 -0
- package/dist/core/process-start-token.d.ts.map +1 -1
- package/dist/core/process-start-token.js +14 -0
- package/dist/core/process-start-token.js.map +1 -1
- package/dist/core/project-trust-electorate.d.ts +24 -0
- package/dist/core/project-trust-electorate.d.ts.map +1 -0
- package/dist/core/project-trust-electorate.js +52 -0
- package/dist/core/project-trust-electorate.js.map +1 -0
- package/dist/core/project-trust-state.d.ts +15 -0
- package/dist/core/project-trust-state.d.ts.map +1 -1
- package/dist/core/project-trust-state.js +15 -0
- package/dist/core/project-trust-state.js.map +1 -1
- package/dist/core/provider-request-admission.d.ts.map +1 -1
- package/dist/core/provider-request-admission.js +2 -2
- package/dist/core/provider-request-admission.js.map +1 -1
- package/dist/core/queued-input-admission.js +2 -2
- package/dist/core/queued-input-admission.js.map +1 -1
- package/dist/core/queued-message-delivery.d.ts +2 -2
- package/dist/core/queued-message-delivery.d.ts.map +1 -1
- package/dist/core/queued-message-delivery.js +6 -3
- package/dist/core/queued-message-delivery.js.map +1 -1
- package/dist/core/resource-admission-scope.js +2 -2
- package/dist/core/resource-admission-scope.js.map +1 -1
- package/dist/core/resume/blueprint/process.d.ts +3 -4
- package/dist/core/resume/blueprint/process.d.ts.map +1 -1
- package/dist/core/resume/blueprint/process.js +33 -17
- package/dist/core/resume/blueprint/process.js.map +1 -1
- package/dist/core/resume/path-mapping.js +4 -4
- package/dist/core/resume/path-mapping.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +9 -0
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +27 -2
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/resume-cache-checkpoint.d.ts +27 -1
- package/dist/core/resume-cache-checkpoint.d.ts.map +1 -1
- package/dist/core/resume-cache-checkpoint.js +45 -0
- package/dist/core/resume-cache-checkpoint.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -31
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-lifecycle-scope.d.ts +1 -2
- package/dist/core/session-lifecycle-scope.d.ts.map +1 -1
- package/dist/core/session-lifecycle-scope.js +2 -2
- package/dist/core/session-lifecycle-scope.js.map +1 -1
- package/dist/core/session-lifecycle-work.js +2 -2
- package/dist/core/session-lifecycle-work.js.map +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +3 -0
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-storage.d.ts +12 -0
- package/dist/core/session-storage.d.ts.map +1 -1
- package/dist/core/session-storage.js +68 -1
- package/dist/core/session-storage.js.map +1 -1
- package/dist/core/settings-lock-directory.d.ts.map +1 -1
- package/dist/core/settings-lock-directory.js +4 -3
- package/dist/core/settings-lock-directory.js.map +1 -1
- package/dist/core/settings-write-ownership.d.ts +1 -2
- package/dist/core/settings-write-ownership.d.ts.map +1 -1
- package/dist/core/settings-write-ownership.js +2 -2
- package/dist/core/settings-write-ownership.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +6 -4
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite.js +22 -8
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/system-prompt.d.ts +16 -2
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +33 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
- package/dist/core/tasks/agent-adapter.js +2 -1
- package/dist/core/tasks/agent-adapter.js.map +1 -1
- package/dist/core/tasks/completion.d.ts +3 -2
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tasks/execution-scope.js +2 -2
- package/dist/core/tasks/execution-scope.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +2 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
- package/dist/core/tools/history-regex-worker.js +3 -2
- package/dist/core/tools/history-regex-worker.js.map +1 -1
- package/dist/core/tools/shell-task-render.d.ts +3 -2
- package/dist/core/tools/shell-task-render.d.ts.map +1 -1
- package/dist/core/tools/shell-task-render.js +7 -5
- package/dist/core/tools/shell-task-render.js.map +1 -1
- package/dist/core/tools/shell-task-status.d.ts +6 -2
- package/dist/core/tools/shell-task-status.d.ts.map +1 -1
- package/dist/core/tools/shell-task-status.js +13 -8
- package/dist/core/tools/shell-task-status.js.map +1 -1
- package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
- package/dist/core/tools/sqlite-selector-connection.js +4 -3
- package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
- package/dist/core/tools/windows-directory-security.d.ts.map +1 -1
- package/dist/core/tools/windows-directory-security.js +2 -1
- package/dist/core/tools/windows-directory-security.js.map +1 -1
- package/dist/core/worktree-snapshot/git.js +2 -2
- package/dist/core/worktree-snapshot/git.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts +6 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +150 -18
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/tool-records.d.ts +44 -9
- package/dist/extensions/mcp/tool-records.d.ts.map +1 -1
- package/dist/extensions/mcp/tool-records.js +58 -16
- package/dist/extensions/mcp/tool-records.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts +3 -1
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +1 -0
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +230 -96
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts +5 -0
- package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/agent-view-bridge.js.map +1 -1
- package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts +5 -2
- package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/agent-view-switcher.js +3 -3
- package/dist/modes/interactive/agent-view/agent-view-switcher.js.map +1 -1
- package/dist/modes/interactive/agent-view/contracts.d.ts +6 -0
- package/dist/modes/interactive/agent-view/contracts.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/contracts.js.map +1 -1
- package/dist/modes/interactive/agent-view/install.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/install.js +2 -1
- package/dist/modes/interactive/agent-view/install.js.map +1 -1
- package/dist/modes/interactive/agent-view/open-port.d.ts +4 -2
- package/dist/modes/interactive/agent-view/open-port.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/open-port.js +4 -3
- package/dist/modes/interactive/agent-view/open-port.js.map +1 -1
- package/dist/modes/interactive/agent-view/prompt-retarget.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/prompt-retarget.js +18 -5
- package/dist/modes/interactive/agent-view/prompt-retarget.js.map +1 -1
- package/dist/modes/interactive/agent-view/remote-port.d.ts +10 -1
- package/dist/modes/interactive/agent-view/remote-port.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/remote-port.js +36 -4
- package/dist/modes/interactive/agent-view/remote-port.js.map +1 -1
- package/dist/modes/interactive/agent-view/viewed-keys.d.ts +56 -0
- package/dist/modes/interactive/agent-view/viewed-keys.d.ts.map +1 -0
- package/dist/modes/interactive/agent-view/viewed-keys.js +63 -0
- package/dist/modes/interactive/agent-view/viewed-keys.js.map +1 -0
- package/dist/modes/interactive/agent-view/viewed-submit.d.ts +14 -4
- package/dist/modes/interactive/agent-view/viewed-submit.d.ts.map +1 -1
- package/dist/modes/interactive/agent-view/viewed-submit.js +51 -17
- package/dist/modes/interactive/agent-view/viewed-submit.js.map +1 -1
- package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/agent-panel.js +8 -21
- package/dist/modes/interactive/components/agent-panel.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +18 -5
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +6 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +2 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.d.ts +5 -0
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +33 -2
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +58 -2
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/host-session-picker.js +2 -2
- package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
- package/dist/modes/interactive/components/main-composer-keys.d.ts +16 -5
- package/dist/modes/interactive/components/main-composer-keys.d.ts.map +1 -1
- package/dist/modes/interactive/components/main-composer-keys.js +27 -8
- package/dist/modes/interactive/components/main-composer-keys.js.map +1 -1
- package/dist/modes/interactive/components/notice-line.d.ts +8 -25
- package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
- package/dist/modes/interactive/components/notice-line.js +18 -17
- package/dist/modes/interactive/components/notice-line.js.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.d.ts +20 -3
- package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.js +82 -32
- package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
- package/dist/modes/interactive/components/queued-messages-view.d.ts +5 -2
- package/dist/modes/interactive/components/queued-messages-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/queued-messages-view.js +12 -5
- package/dist/modes/interactive/components/queued-messages-view.js.map +1 -1
- package/dist/modes/interactive/components/task-board.d.ts +5 -8
- package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-board.js +5 -49
- package/dist/modes/interactive/components/task-board.js.map +1 -1
- package/dist/modes/interactive/components/task-completion-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-completion-message.js +9 -2
- package/dist/modes/interactive/components/task-completion-message.js.map +1 -1
- package/dist/modes/interactive/components/task-marks.d.ts +19 -0
- package/dist/modes/interactive/components/task-marks.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-marks.js +25 -0
- package/dist/modes/interactive/components/task-marks.js.map +1 -0
- package/dist/modes/interactive/components/task-row.d.ts +10 -2
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-row.js +39 -32
- package/dist/modes/interactive/components/task-row.js.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.d.ts +7 -0
- package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.js +106 -10
- package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
- package/dist/modes/interactive/components/tool-block-families.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-block-families.js +8 -9
- package/dist/modes/interactive/components/tool-block-families.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +5 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -1
- package/dist/modes/interactive/extension-command-hold.js +5 -7
- package/dist/modes/interactive/extension-command-hold.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js +6 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +21 -7
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-initial-session-binding.d.ts +1 -2
- package/dist/modes/interactive/interactive-initial-session-binding.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-initial-session-binding.js +2 -2
- package/dist/modes/interactive/interactive-initial-session-binding.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +13 -4
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +2 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +6 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +4 -2
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.js +6 -0
- package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +96 -17
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +5 -0
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +37 -5
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +45 -4
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-resource-disclosure.d.ts +4 -1
- package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-resource-disclosure.js +20 -1
- package/dist/modes/interactive/interactive-resource-disclosure.js.map +1 -1
- package/dist/modes/interactive/interactive-resource-rendering.js +3 -0
- package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +43 -5
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.d.ts +6 -3
- package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.js +3 -2
- package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
- package/dist/modes/interactive-engine/engine-health.d.ts +2 -0
- package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-health.js.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts +10 -0
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.js +33 -0
- package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +7 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js +15 -2
- package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
- package/dist/modes/interactive-engine/host-listener-failures.d.ts +24 -0
- package/dist/modes/interactive-engine/host-listener-failures.d.ts.map +1 -0
- package/dist/modes/interactive-engine/host-listener-failures.js +98 -0
- package/dist/modes/interactive-engine/host-listener-failures.js.map +1 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +16 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +74 -7
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +5 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +8 -2
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/interactive-engine/remote-component.d.ts +13 -0
- package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-component.js +69 -4
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +34 -6
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.d.ts +7 -0
- package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.js +11 -1
- package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
- package/dist/modes/rpc/agent-view-rpc-panel.d.ts.map +1 -1
- package/dist/modes/rpc/agent-view-rpc-panel.js +11 -5
- package/dist/modes/rpc/agent-view-rpc-panel.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +8 -1
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +89 -65
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +21 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +77 -33
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.d.ts +5 -0
- package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.js +8 -2
- package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +9 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/shell.d.ts +5 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +14 -7
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/worker-threads.d.ts +10 -4
- package/dist/utils/worker-threads.d.ts.map +1 -1
- package/dist/utils/worker-threads.js +10 -4
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/background-tasks.md +10 -10
- package/docs/compaction.md +1 -0
- package/docs/development.md +1 -1
- package/docs/environment-variables.md +4 -0
- package/docs/extensions/api-reference.md +2 -0
- package/docs/extensions/events.md +1 -1
- package/docs/getting-started/installation.md +1 -0
- package/docs/guides/non-interactive.md +2 -0
- package/docs/guides/resume-on-any-machine.md +3 -1
- package/docs/intercom/reference.md +1 -1
- package/docs/keybindings.md +6 -5
- package/docs/libraries/ai.md +2 -1
- package/docs/mcp-servers.md +1 -1
- package/docs/sdk/reference.md +1 -1
- package/docs/sdk.md +6 -0
- package/docs/security.md +4 -2
- package/docs/settings.md +2 -1
- package/docs/storage.md +2 -0
- package/docs/subagents.md +2 -2
- package/docs/tui/reference.md +3 -1
- package/npm-shrinkwrap.json +49 -49
- package/package.json +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dialectOf, type SqliteRow, validateStoragePrefix } from "@bastani/atomic/storage";
|
|
2
|
-
import { addMissingColumns } from "./sql-add-column.js";
|
|
1
|
+
import { dialectOf, type SqliteExecutor, type SqliteRow, validateStoragePrefix } from "@bastani/atomic/storage";
|
|
2
|
+
import { addMissingColumns, addOptionalColumn } from "./sql-add-column.js";
|
|
3
3
|
import type {
|
|
4
4
|
IntercomBrokerStateOptions,
|
|
5
5
|
KnownSessionBindingResult,
|
|
@@ -8,11 +8,21 @@ import type {
|
|
|
8
8
|
KnownSessionRecordResult,
|
|
9
9
|
KnownSessionState,
|
|
10
10
|
KnownSessionStore,
|
|
11
|
+
SessionIdReclaim,
|
|
12
|
+
SessionIdReclaimResult,
|
|
11
13
|
} from "./multinode-state-store.js";
|
|
12
14
|
import { ensureBrokerSchema } from "./sql-schema.js";
|
|
13
15
|
|
|
14
16
|
type BindingRow = SqliteRow & { return_address: string };
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The start every delivery identity of a session with `returnAddress` shares, whatever its group (`deliveryTargetIdentity`
|
|
20
|
+
* writes `["return", returnAddress, group]`).
|
|
21
|
+
*/
|
|
22
|
+
function returnIdentityPrefix(returnAddress: string): string {
|
|
23
|
+
return `${JSON.stringify(["return", returnAddress]).slice(0, -1)},`;
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
type KnownRow = SqliteRow & {
|
|
17
27
|
target_identity: string;
|
|
18
28
|
intercom_session_id: string;
|
|
@@ -55,6 +65,8 @@ export async function openSqlKnownSessionStore({
|
|
|
55
65
|
}: IntercomBrokerStateOptions): Promise<KnownSessionStore> {
|
|
56
66
|
const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_known_sessions`;
|
|
57
67
|
const bindings = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_session_bindings`;
|
|
68
|
+
// The lease store's table, which the broker opens first: `reclaim` reads its presence leases.
|
|
69
|
+
const leases = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_leases`;
|
|
58
70
|
const { types, nowMs, greatest } = dialectOf(database);
|
|
59
71
|
const age = greatest("0", `${nowMs} - recorded_at`);
|
|
60
72
|
/** `age` at the statement's one reading of the clock, from `WITH clock`. */
|
|
@@ -89,10 +101,112 @@ export async function openSqlKnownSessionStore({
|
|
|
89
101
|
// #5154: added later: set, by store clock, once the session's broker was retired before it recorded the session
|
|
90
102
|
// leaving. An older broker ignores it, and its `record` leaves it set.
|
|
91
103
|
await addMissingColumns(database, table, { lost_at: types.int });
|
|
104
|
+
// #5607: added later: the claim of the registration that last bound the id, written by `bind` when it is given one.
|
|
105
|
+
// An older broker's `bind` leaves it as it is. Without it (a role that may not add it) there is no `reclaim`.
|
|
106
|
+
const claims = await addOptionalColumn(database, bindings, "latest_claim", "TEXT");
|
|
92
107
|
const columns = `target_identity, intercom_session_id, name_json, atomic_session_id, group_name, groups_json,
|
|
93
108
|
recipient_purpose, reply_capability, ${age} AS age_ms`;
|
|
94
109
|
|
|
110
|
+
/** `bind`'s statements, in the caller's serial transaction on `bindings`. */
|
|
111
|
+
const bindIn = async (
|
|
112
|
+
tx: SqliteExecutor,
|
|
113
|
+
intercomSessionId: string,
|
|
114
|
+
returnAddress: string,
|
|
115
|
+
retentionMs: number,
|
|
116
|
+
claim: string | undefined,
|
|
117
|
+
): Promise<KnownSessionBindResult> => {
|
|
118
|
+
await tx.run(
|
|
119
|
+
`DELETE FROM ${bindings} WHERE intercom_session_id = ? AND ${nowMs} - recorded_at > ?`,
|
|
120
|
+
intercomSessionId,
|
|
121
|
+
retentionMs,
|
|
122
|
+
);
|
|
123
|
+
// A known-session record kept from before bindings existed holds the id for its return address.
|
|
124
|
+
await tx.run(
|
|
125
|
+
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at)
|
|
126
|
+
SELECT intercom_session_id, COALESCE(atomic_session_id, ''), ${nowMs} FROM ${table}
|
|
127
|
+
WHERE intercom_session_id = ? AND ${age} <= ?
|
|
128
|
+
ORDER BY record_order LIMIT 1
|
|
129
|
+
ON CONFLICT(intercom_session_id) DO NOTHING`,
|
|
130
|
+
intercomSessionId,
|
|
131
|
+
retentionMs,
|
|
132
|
+
);
|
|
133
|
+
// One conditional write: a binding held by another return address is left as it is.
|
|
134
|
+
if (claims) {
|
|
135
|
+
await tx.run(
|
|
136
|
+
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at, latest_claim) VALUES (?, ?, ${nowMs}, ?)
|
|
137
|
+
ON CONFLICT(intercom_session_id) DO UPDATE SET recorded_at = excluded.recorded_at, latest_claim = excluded.latest_claim
|
|
138
|
+
WHERE ${bindings}.return_address = excluded.return_address`,
|
|
139
|
+
intercomSessionId,
|
|
140
|
+
returnAddress,
|
|
141
|
+
claim ?? null,
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
await tx.run(
|
|
145
|
+
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at) VALUES (?, ?, ${nowMs})
|
|
146
|
+
ON CONFLICT(intercom_session_id) DO UPDATE SET recorded_at = excluded.recorded_at
|
|
147
|
+
WHERE ${bindings}.return_address = excluded.return_address`,
|
|
148
|
+
intercomSessionId,
|
|
149
|
+
returnAddress,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const bound = await tx.get<BindingRow>(
|
|
153
|
+
`SELECT return_address FROM ${bindings} WHERE intercom_session_id = ?`,
|
|
154
|
+
intercomSessionId,
|
|
155
|
+
);
|
|
156
|
+
if (bound === undefined || bound.return_address === returnAddress) return { status: "bound" };
|
|
157
|
+
return { status: "refused", returnAddress: bound.return_address };
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const reclaim = async (request: SessionIdReclaim): Promise<SessionIdReclaimResult> => {
|
|
161
|
+
if (request.intercomSessionId.length === 0 || request.freshId.length === 0)
|
|
162
|
+
return { status: "invalid", reason: "empty-session-id" };
|
|
163
|
+
return database.transaction(
|
|
164
|
+
async (tx) => {
|
|
165
|
+
// A session of this return address that another broker presents, in any group, holds the id there.
|
|
166
|
+
const identities = returnIdentityPrefix(request.returnAddress);
|
|
167
|
+
const { changes } = await tx.run(
|
|
168
|
+
`UPDATE ${bindings} SET recorded_at = ${nowMs}
|
|
169
|
+
WHERE intercom_session_id = ? AND return_address = ? AND latest_claim = ? AND ${nowMs} - recorded_at <= ?
|
|
170
|
+
AND NOT EXISTS (
|
|
171
|
+
SELECT 1 FROM ${leases} presence
|
|
172
|
+
WHERE presence.kind = 'presence' AND substr(presence.key, 1, length(?)) = ? AND presence.holder_id IS NOT NULL
|
|
173
|
+
AND presence.holder_id <> ? AND ${greatest("0", `${nowMs} - presence.renewed_at`)} <= ?
|
|
174
|
+
)`,
|
|
175
|
+
request.intercomSessionId,
|
|
176
|
+
request.returnAddress,
|
|
177
|
+
request.claim,
|
|
178
|
+
request.retentionMs,
|
|
179
|
+
// The database measures the prefix itself, in its own characters.
|
|
180
|
+
identities,
|
|
181
|
+
identities,
|
|
182
|
+
request.brokerId,
|
|
183
|
+
request.presenceStaleAfterMs,
|
|
184
|
+
);
|
|
185
|
+
if (changes === 1) return { status: "kept" } as const;
|
|
186
|
+
// A fresh id, made at random for this registration, has no binding or record yet: one write binds it, and only an
|
|
187
|
+
// id already there, bound or recorded, takes `bind`'s whole way.
|
|
188
|
+
const inserted = await tx.run(
|
|
189
|
+
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at)
|
|
190
|
+
SELECT ?, ?, ${nowMs}
|
|
191
|
+
WHERE NOT EXISTS (SELECT 1 FROM ${table} WHERE intercom_session_id = ? AND ${age} <= ?)
|
|
192
|
+
ON CONFLICT(intercom_session_id) DO NOTHING`,
|
|
193
|
+
request.freshId,
|
|
194
|
+
request.returnAddress,
|
|
195
|
+
request.freshId,
|
|
196
|
+
request.retentionMs,
|
|
197
|
+
);
|
|
198
|
+
const binding =
|
|
199
|
+
inserted.changes === 1
|
|
200
|
+
? ({ status: "bound" } as const)
|
|
201
|
+
: await bindIn(tx, request.freshId, request.returnAddress, request.retentionMs, undefined);
|
|
202
|
+
return { status: "fresh", binding } as const;
|
|
203
|
+
},
|
|
204
|
+
{ concurrency: { kind: "serial", domain: bindings } },
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
|
|
95
208
|
return {
|
|
209
|
+
...(claims ? { reclaim } : {}),
|
|
96
210
|
async record(session): Promise<KnownSessionRecordResult> {
|
|
97
211
|
if (session.targetIdentity.length === 0) return { status: "invalid", reason: "empty-target-identity" };
|
|
98
212
|
if (session.intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
@@ -142,41 +256,11 @@ export async function openSqlKnownSessionStore({
|
|
|
142
256
|
);
|
|
143
257
|
return { status: "found", sessions: rows.map(stateFromRow) };
|
|
144
258
|
},
|
|
145
|
-
async bind(intercomSessionId, returnAddress, retentionMs): Promise<KnownSessionBindResult> {
|
|
259
|
+
async bind(intercomSessionId, returnAddress, retentionMs, claim): Promise<KnownSessionBindResult> {
|
|
146
260
|
if (intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
`DELETE FROM ${bindings} WHERE intercom_session_id = ? AND ${nowMs} - recorded_at > ?`,
|
|
151
|
-
intercomSessionId,
|
|
152
|
-
retentionMs,
|
|
153
|
-
);
|
|
154
|
-
// A known-session record kept from before bindings existed holds the id for its return address.
|
|
155
|
-
await tx.run(
|
|
156
|
-
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at)
|
|
157
|
-
SELECT intercom_session_id, COALESCE(atomic_session_id, ''), ${nowMs} FROM ${table}
|
|
158
|
-
WHERE intercom_session_id = ? AND ${age} <= ?
|
|
159
|
-
ORDER BY record_order LIMIT 1
|
|
160
|
-
ON CONFLICT(intercom_session_id) DO NOTHING`,
|
|
161
|
-
intercomSessionId,
|
|
162
|
-
retentionMs,
|
|
163
|
-
);
|
|
164
|
-
await tx.run(
|
|
165
|
-
`INSERT INTO ${bindings}(intercom_session_id, return_address, recorded_at) VALUES (?, ?, ${nowMs})
|
|
166
|
-
ON CONFLICT(intercom_session_id) DO UPDATE SET recorded_at = excluded.recorded_at
|
|
167
|
-
WHERE ${bindings}.return_address = excluded.return_address`,
|
|
168
|
-
intercomSessionId,
|
|
169
|
-
returnAddress,
|
|
170
|
-
);
|
|
171
|
-
return tx.get<BindingRow>(
|
|
172
|
-
`SELECT return_address FROM ${bindings} WHERE intercom_session_id = ?`,
|
|
173
|
-
intercomSessionId,
|
|
174
|
-
);
|
|
175
|
-
},
|
|
176
|
-
{ concurrency: { kind: "serial", domain: bindings } },
|
|
177
|
-
);
|
|
178
|
-
if (bound === undefined || bound.return_address === returnAddress) return { status: "bound" };
|
|
179
|
-
return { status: "refused", returnAddress: bound.return_address };
|
|
261
|
+
return database.transaction((tx) => bindIn(tx, intercomSessionId, returnAddress, retentionMs, claim), {
|
|
262
|
+
concurrency: { kind: "serial", domain: bindings },
|
|
263
|
+
});
|
|
180
264
|
},
|
|
181
265
|
async binding(intercomSessionId, retentionMs): Promise<KnownSessionBindingResult> {
|
|
182
266
|
if (intercomSessionId.length === 0) return { status: "invalid", reason: "empty-session-id" };
|
|
@@ -69,12 +69,42 @@ function toRow(record: OutboxRecord): OutboxRow {
|
|
|
69
69
|
|
|
70
70
|
const isSettled = (record: OutboxRecord): boolean => record.state === "delivered" || record.state === "failed";
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* #5607: the wake-up hint written with an offline recipient's row failed, so neither was written. The hint is only a
|
|
74
|
+
* hint: the caller writes the row again without it (`withoutFailedWake`).
|
|
75
|
+
*/
|
|
76
|
+
export class OutboxWakeFailedError extends Error {
|
|
77
|
+
constructor(cause: unknown) {
|
|
78
|
+
super("The wake-up hint for a queued message could not be written", { cause });
|
|
79
|
+
this.name = "OutboxWakeFailedError";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
/** The SQL outbox, which can also enqueue inside a transaction the caller holds. */
|
|
73
84
|
export interface SqlOutboxStore extends OutboxStore {
|
|
74
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* `enqueue`, as part of `executor`'s transaction: the row is written only when that transaction commits. It throws
|
|
87
|
+
* `OutboxWakeFailedError` when only the optional wake-up hint failed; run the transaction again without it then.
|
|
88
|
+
*/
|
|
75
89
|
enqueueIn(executor: SqliteExecutor, request: OutboxEnqueueRequest): Promise<OutboxEnqueueResult>;
|
|
76
90
|
}
|
|
77
91
|
|
|
92
|
+
/**
|
|
93
|
+
* #5607: runs `write` for `request`, and once more for it without its wake-up hint when only that hint failed it.
|
|
94
|
+
*/
|
|
95
|
+
export async function withoutFailedWake<T>(
|
|
96
|
+
request: OutboxEnqueueRequest,
|
|
97
|
+
write: (request: OutboxEnqueueRequest) => Promise<T>,
|
|
98
|
+
): Promise<T> {
|
|
99
|
+
try {
|
|
100
|
+
return await write(request);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!(error instanceof OutboxWakeFailedError)) throw error;
|
|
103
|
+
const { wakeHostWithinMs: _hint, ...withoutHint } = request;
|
|
104
|
+
return write(withoutHint);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
78
108
|
/**
|
|
79
109
|
* S2 outbox on the shared storage adapter's database, in `<prefix>intercom_outbox`. Every read-modify-write runs in
|
|
80
110
|
* one `BEGIN IMMEDIATE` transaction, and every age is measured on the database clock.
|
|
@@ -82,7 +112,7 @@ export interface SqlOutboxStore extends OutboxStore {
|
|
|
82
112
|
export async function openSqlOutboxStore(options: IntercomBrokerStateOptions): Promise<SqlOutboxStore> {
|
|
83
113
|
const { database } = options;
|
|
84
114
|
const table = `${validateStoragePrefix(options.prefix, dialectOf(database).name)}intercom_outbox`;
|
|
85
|
-
const { types, nowMs, greatest } = dialectOf(database);
|
|
115
|
+
const { types, nowMs, greatest, name: dialect } = dialectOf(database);
|
|
86
116
|
const ageSince = (column: string) => greatest("0", `${nowMs} - ${column}`);
|
|
87
117
|
// In a serial transaction, so brokers opening a new store at once take turns creating it (#5054).
|
|
88
118
|
const schema = `
|
|
@@ -120,6 +150,10 @@ export async function openSqlOutboxStore(options: IntercomBrokerStateOptions): P
|
|
|
120
150
|
CASE WHEN saving_at IS NULL THEN NULL ELSE ${ageSince("saving_at")} END AS saving_age`;
|
|
121
151
|
const select = (executor: SqliteExecutor, messageId: string) =>
|
|
122
152
|
executor.get<OutboxRecord>(`SELECT ${columns} FROM ${table} WHERE message_id = ?`, messageId);
|
|
153
|
+
// #5607: the lease store's table, whose presence leases name the broker hosting a recipient, and the wake-up bus's
|
|
154
|
+
// hint log. The broker opens both before it enqueues anything.
|
|
155
|
+
const leases = `${validateStoragePrefix(options.prefix, dialectOf(database).name)}intercom_leases`;
|
|
156
|
+
const wakeups = `${validateStoragePrefix(options.prefix, dialectOf(database).name)}intercom_wakeups`;
|
|
123
157
|
const undelivered = (executor: SqliteExecutor, targetIdentity: string, limit?: number) =>
|
|
124
158
|
limit === undefined
|
|
125
159
|
? executor.all<OutboxRecord>(
|
|
@@ -212,18 +246,44 @@ export async function openSqlOutboxStore(options: IntercomBrokerStateOptions): P
|
|
|
212
246
|
) {
|
|
213
247
|
return { status: "full", limit: OUTBOX_TARGET_MAX_ROWS, byteLimit: OUTBOX_TARGET_MAX_BYTES } as const;
|
|
214
248
|
}
|
|
215
|
-
|
|
216
|
-
`INSERT INTO ${table}(message_id, target_identity, origin_broker_id, digest, frame_json, state, queued_at,
|
|
249
|
+
const insert = `INSERT INTO ${table}(message_id, target_identity, origin_broker_id, digest, frame_json, state, queued_at,
|
|
217
250
|
frame_bytes)
|
|
218
|
-
VALUES (?, ?, ?, ?, ?, 'queued', ${nowMs}, ?)
|
|
219
|
-
|
|
251
|
+
VALUES (?, ?, ?, ?, ?, 'queued', ${nowMs}, ?)`;
|
|
252
|
+
const values = [messageId, request.targetIdentity, request.originBrokerId, request.digest, frameJson, frameBytes];
|
|
253
|
+
if (request.wakeHostWithinMs === undefined) {
|
|
254
|
+
await executor.run(insert, ...values);
|
|
255
|
+
return { status: "inserted", row: toRow((await select(executor, messageId))!) } as const;
|
|
256
|
+
}
|
|
257
|
+
// #5607: the row comes back from its insert, with the broker holding the recipient's live presence, read in this
|
|
258
|
+
// transaction: a presence lease committed before it is seen here; one committed after it was written after this row,
|
|
259
|
+
// and the registration that wrote it looks for the row next. Only when there is one does a second statement write
|
|
260
|
+
// its wake-up hint, in this transaction too.
|
|
261
|
+
const inserted = (await executor.get<OutboxRecord & { readonly presence_holder: string | null }>(
|
|
262
|
+
`${insert} RETURNING ${columns}, (
|
|
263
|
+
SELECT presence.holder_id FROM ${leases} presence
|
|
264
|
+
WHERE presence.kind = 'presence' AND presence.key = ? AND presence.holder_id IS NOT NULL
|
|
265
|
+
AND ${greatest("0", `${nowMs} - presence.renewed_at`)} <= ?
|
|
266
|
+
) AS presence_holder`,
|
|
267
|
+
...values,
|
|
220
268
|
request.targetIdentity,
|
|
221
|
-
request.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
269
|
+
request.wakeHostWithinMs,
|
|
270
|
+
))!;
|
|
271
|
+
const host = inserted.presence_holder;
|
|
272
|
+
if (host !== null) {
|
|
273
|
+
const hint = async () => {
|
|
274
|
+
// PostgreSQL: never wait behind another session's lock on the hint log; such a hint goes without.
|
|
275
|
+
if (dialect === "postgres") await executor.run(`LOCK TABLE ${wakeups} IN ROW EXCLUSIVE MODE NOWAIT`);
|
|
276
|
+
await executor.run(
|
|
277
|
+
`INSERT INTO ${wakeups}(broker_id, reason, version, created_at) VALUES (?, 'outbox', ?, ${nowMs})`,
|
|
278
|
+
host,
|
|
279
|
+
Number(inserted.sequence),
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
await hint().catch((cause: unknown) => {
|
|
283
|
+
throw new OutboxWakeFailedError(cause);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return { status: "inserted", row: toRow(inserted), ...(host === null ? {} : { woke: host }) } as const;
|
|
227
287
|
};
|
|
228
288
|
|
|
229
289
|
return {
|
|
@@ -232,7 +292,9 @@ export async function openSqlOutboxStore(options: IntercomBrokerStateOptions): P
|
|
|
232
292
|
if (request.targetIdentity.length === 0) return invalid("empty-target-identity");
|
|
233
293
|
if (request.originBrokerId.length === 0) return invalid("empty-broker-id");
|
|
234
294
|
if (request.frame.message.id.length === 0) return invalid("empty-message-id");
|
|
235
|
-
return
|
|
295
|
+
return withoutFailedWake(request, (attempt) =>
|
|
296
|
+
database.transaction((executor) => enqueueIn(executor, attempt)),
|
|
297
|
+
);
|
|
236
298
|
},
|
|
237
299
|
|
|
238
300
|
async claim(request) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A spawned broker announces its real pid, so a parent that cannot watch the process it spawned can tell a broker that
|
|
@@ -16,9 +17,14 @@ import { readFile } from "node:fs/promises";
|
|
|
16
17
|
* The parent hands the broker the file and token through the environment, so a broker started any other way (a test,
|
|
17
18
|
* an older parent) announces nothing. The token ties a file to the spawn that asked for it: a broker that is retiring
|
|
18
19
|
* and a replacement that is starting never read each other's announcement as their own.
|
|
20
|
+
*
|
|
21
|
+
* #6133: a parent that asks for it (`BROKER_ANNOUNCE_START_ENV`) also gets when the broker process was created, as
|
|
22
|
+
* Windows records it, so that it can tell the broker apart from a later process Windows gives the same pid to. Without
|
|
23
|
+
* the request the file holds exactly what earlier versions wrote, so an older parent still reads it.
|
|
19
24
|
*/
|
|
20
25
|
export const BROKER_ANNOUNCE_PATH_ENV = "ATOMIC_INTERCOM_BROKER_ANNOUNCE_PATH";
|
|
21
26
|
export const BROKER_ANNOUNCE_TOKEN_ENV = "ATOMIC_INTERCOM_BROKER_ANNOUNCE_TOKEN";
|
|
27
|
+
export const BROKER_ANNOUNCE_START_ENV = "ATOMIC_INTERCOM_BROKER_ANNOUNCE_START";
|
|
22
28
|
|
|
23
29
|
/** The file and token one spawn asks its broker to announce itself with. */
|
|
24
30
|
export interface BrokerStartAnnouncement {
|
|
@@ -26,8 +32,16 @@ export interface BrokerStartAnnouncement {
|
|
|
26
32
|
readonly token: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
/** What a broker announced: its pid, and when it was created where it could read that and was asked to. */
|
|
36
|
+
export interface AnnouncedBroker {
|
|
37
|
+
readonly pid: number;
|
|
38
|
+
/** The process's creation time, as the decimal count of 100-nanosecond intervals since 1601-01-01 UTC. */
|
|
39
|
+
readonly started?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
/** Tokens go in the file and the environment unquoted, so only plain characters are accepted. */
|
|
30
43
|
const TOKEN_PATTERN = /^[A-Za-z0-9-]+$/u;
|
|
44
|
+
const CREATION_TIME_PATTERN = /^[1-9]\d*$/u;
|
|
31
45
|
|
|
32
46
|
/** The announcement the environment asks this process for, or undefined when it asks for none. */
|
|
33
47
|
function requested(env: NodeJS.ProcessEnv): BrokerStartAnnouncement | undefined {
|
|
@@ -37,12 +51,38 @@ function requested(env: NodeJS.ProcessEnv): BrokerStartAnnouncement | undefined
|
|
|
37
51
|
return { path, token };
|
|
38
52
|
}
|
|
39
53
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
54
|
+
/**
|
|
55
|
+
* When this process was created, as Windows records it, read by Atomic's native module; undefined elsewhere, or where
|
|
56
|
+
* that module cannot be loaded. Read synchronously: the broker announces itself before it loads anything else.
|
|
57
|
+
*/
|
|
58
|
+
function ownCreationTime(): string | undefined {
|
|
59
|
+
if (process.platform !== "win32") return undefined;
|
|
60
|
+
try {
|
|
61
|
+
const native = createRequire(import.meta.url)("@bastani/atomic-natives") as {
|
|
62
|
+
processCreationTime?: (pid: number) => string | null;
|
|
63
|
+
};
|
|
64
|
+
const created = native.processCreationTime?.(process.pid);
|
|
65
|
+
return typeof created === "string" && CREATION_TIME_PATTERN.test(created) ? created : undefined;
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Broker side: write `<token> <pid>` where the parent asked, followed by ` <creation time>` when the parent asked for it
|
|
73
|
+
* too and it can be read. A failure to write must never keep the broker from starting.
|
|
74
|
+
*/
|
|
75
|
+
export function announceBrokerStart(
|
|
76
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
77
|
+
pid: number = process.pid,
|
|
78
|
+
readStart: () => string | undefined = ownCreationTime,
|
|
79
|
+
): void {
|
|
42
80
|
const announcement = requested(env);
|
|
43
81
|
if (announcement === undefined) return;
|
|
82
|
+
const started = env[BROKER_ANNOUNCE_START_ENV] === "1" ? readStart() : undefined;
|
|
83
|
+
const witness = started !== undefined && CREATION_TIME_PATTERN.test(started) ? ` ${started}` : "";
|
|
44
84
|
try {
|
|
45
|
-
writeFileSync(announcement.path, `${announcement.token} ${pid}\n`, { mode: 0o600 });
|
|
85
|
+
writeFileSync(announcement.path, `${announcement.token} ${pid}${witness}\n`, { mode: 0o600 });
|
|
46
86
|
} catch {
|
|
47
87
|
// The parent then waits out its start-up budget, as it did before broker announcements existed.
|
|
48
88
|
}
|
|
@@ -53,7 +93,7 @@ export function retractBrokerStartAnnouncement(env: NodeJS.ProcessEnv = process.
|
|
|
53
93
|
const announcement = requested(env);
|
|
54
94
|
if (announcement === undefined) return;
|
|
55
95
|
// Only the broker's own announcement: a stale file from another broker is the parent's to replace.
|
|
56
|
-
if (readBrokerStartAnnouncement(announcement) !== pid) return;
|
|
96
|
+
if (readBrokerStartAnnouncement(announcement)?.pid !== pid) return;
|
|
57
97
|
try {
|
|
58
98
|
unlinkSync(announcement.path);
|
|
59
99
|
} catch {
|
|
@@ -61,17 +101,22 @@ export function retractBrokerStartAnnouncement(env: NodeJS.ProcessEnv = process.
|
|
|
61
101
|
}
|
|
62
102
|
}
|
|
63
103
|
|
|
64
|
-
function parseBrokerStartAnnouncement(
|
|
104
|
+
function parseBrokerStartAnnouncement(
|
|
105
|
+
text: string,
|
|
106
|
+
announcement: BrokerStartAnnouncement,
|
|
107
|
+
): AnnouncedBroker | undefined {
|
|
65
108
|
// A complete line only: a write still in progress is read as nothing yet.
|
|
66
109
|
if (!text.endsWith("\n")) return undefined;
|
|
67
|
-
const [token, pid, ...rest] = text.trim().split(/\s+/u);
|
|
110
|
+
const [token, pid, started, ...rest] = text.trim().split(/\s+/u);
|
|
68
111
|
if (token !== announcement.token || rest.length > 0) return undefined;
|
|
112
|
+
if (started !== undefined && !CREATION_TIME_PATTERN.test(started)) return undefined;
|
|
69
113
|
const parsed = Number(pid);
|
|
70
|
-
|
|
114
|
+
if (!Number.isInteger(parsed) || parsed <= 0) return undefined;
|
|
115
|
+
return started === undefined ? { pid: parsed } : { pid: parsed, started };
|
|
71
116
|
}
|
|
72
117
|
|
|
73
|
-
/** Parent side:
|
|
74
|
-
export function readBrokerStartAnnouncement(announcement: BrokerStartAnnouncement):
|
|
118
|
+
/** Parent side: what this spawn's broker announced, or undefined until it has, or when the file is another spawn's. */
|
|
119
|
+
export function readBrokerStartAnnouncement(announcement: BrokerStartAnnouncement): AnnouncedBroker | undefined {
|
|
75
120
|
let text: string;
|
|
76
121
|
try {
|
|
77
122
|
text = readFileSync(announcement.path, "utf-8");
|
|
@@ -83,7 +128,7 @@ export function readBrokerStartAnnouncement(announcement: BrokerStartAnnouncemen
|
|
|
83
128
|
|
|
84
129
|
export async function readBrokerStartAnnouncementAsync(
|
|
85
130
|
announcement: BrokerStartAnnouncement,
|
|
86
|
-
): Promise<
|
|
131
|
+
): Promise<AnnouncedBroker | undefined> {
|
|
87
132
|
let text: string;
|
|
88
133
|
try {
|
|
89
134
|
text = await readFile(announcement.path, "utf-8");
|
|
@@ -4,11 +4,14 @@ export const BROKER_WATCHDOG_INTERVAL_MS = 2_000;
|
|
|
4
4
|
export const BROKER_WATCHDOG_PROBE_TIMEOUT_MS = 10_000;
|
|
5
5
|
export const BROKER_WATCHDOG_SILENCE_MS = 60_000;
|
|
6
6
|
|
|
7
|
+
// Node evaluates this source as an ES module, which has no require, when --input-type=module reaches the worker (from
|
|
8
|
+
// NODE_OPTIONS, or the process's flags under the permission model) (#6110); `builtin` loads Node's modules either way.
|
|
7
9
|
const WATCHDOG_SOURCE = `
|
|
8
|
-
const
|
|
9
|
-
const {
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
10
|
+
const builtin = typeof require === "function" ? require : (id) => process.getBuiltinModule(id);
|
|
11
|
+
const { workerData } = builtin("node:worker_threads");
|
|
12
|
+
const { connect } = builtin("node:net");
|
|
13
|
+
const { randomUUID } = builtin("node:crypto");
|
|
14
|
+
const { writeFileSync } = builtin("node:fs");
|
|
12
15
|
let lastHealthyAt = performance.now();
|
|
13
16
|
let consecutiveFailures = 0;
|
|
14
17
|
|
|
@@ -87,9 +90,9 @@ export function startBrokerWatchdog(socketPath: string, instanceId: string, logP
|
|
|
87
90
|
try {
|
|
88
91
|
const worker = new Worker(WATCHDOG_SOURCE, {
|
|
89
92
|
eval: true,
|
|
90
|
-
// None of the process's flags:
|
|
91
|
-
//
|
|
92
|
-
// only by the flags it starts with, so there it keeps them.
|
|
93
|
+
// None of the process's flags: the process's preloads would run again in the watchdog, and its
|
|
94
|
+
// `--input-type=module` would make the source a module. Under Node's permission model a worker is
|
|
95
|
+
// restricted only by the flags it starts with, so there it keeps them.
|
|
93
96
|
execArgv: process.permission === undefined ? [] : undefined,
|
|
94
97
|
workerData: {
|
|
95
98
|
socketPath,
|