@bastani/atomic 0.10.2-alpha.1 → 0.10.3-alpha.1
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 +112 -0
- package/dist/builtin/intercom/CHANGELOG.md +17 -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 +29 -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 +668 -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 +42 -38
- package/dist/builtin/subagents/skills/skill-creator/scripts/run_eval.py +268 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-task-status.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-task-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoB,KAAK,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AAExG,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,uBAAuB,CAAC;AAG/B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"shell-task-status.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-task-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EAAoB,KAAK,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AAExG,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,uBAAuB,CAAC;AAG/B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAsB/C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAmB/D;AAmBD,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,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IAExB,YAAY,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,MAAM,EAWhE;IAED,8GAA8G;IAC9G,MAAM,IAAI,uBAAuB,CAWhC;CACD;AAED,gHAAgH;AAChH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAQhF;AAED,MAAM,WAAW,qBAAqB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,kHAAkH;AAClH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,GAAG,SAAS,CAS5G"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* One source of truth for two audiences: the model reads compact sentences in the tool result text, and the
|
|
5
5
|
* transcript renders the same facts as a single status line. Structured data stays in the result `details`.
|
|
6
6
|
*/
|
|
7
|
+
import { TASK_MARKS } from "../../modes/interactive/components/task-marks.js";
|
|
7
8
|
import { hasErrorIdentity, serializeErrorCause } from "../error-contract.js";
|
|
8
9
|
import { cancelReasonText } from "../tasks/cancel-reason.js";
|
|
9
10
|
import { TaskEvictedError } from "../tasks/eviction-error.js";
|
|
@@ -29,14 +30,14 @@ export function taskResultStatus(result) {
|
|
|
29
30
|
switch (result.kind) {
|
|
30
31
|
case "completed":
|
|
31
32
|
if (result.exitCode === 0)
|
|
32
|
-
return {
|
|
33
|
+
return { mark: TASK_MARKS.done, tone: "success", label: "completed", detail: "exit 0" };
|
|
33
34
|
if (result.exitCode === undefined)
|
|
34
|
-
return {
|
|
35
|
-
return {
|
|
35
|
+
return { mark: TASK_MARKS.failed, tone: "error", label: "ended without an exit code" };
|
|
36
|
+
return { mark: TASK_MARKS.failed, tone: "error", label: `exited ${result.exitCode}` };
|
|
36
37
|
case "failed":
|
|
37
|
-
return withDetail({
|
|
38
|
+
return withDetail({ mark: TASK_MARKS.failed, tone: "error", label: "failed" }, informativeMessage(result.code, result.message));
|
|
38
39
|
case "cancelled":
|
|
39
|
-
return withDetail({
|
|
40
|
+
return withDetail({ mark: TASK_MARKS.stopped, tone: "dim", label: "cancelled" }, result.cause === "user" ? undefined : cancelReasonText(result));
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
/** What happened to a task, as a verb phrase that follows its subject: `exited with code 1`. */
|
|
@@ -61,7 +62,7 @@ function taskResultPhrase(result) {
|
|
|
61
62
|
export function waitStatus(observation, hasOutput) {
|
|
62
63
|
if (observation.kind === "settled")
|
|
63
64
|
return taskResultStatus(observation.result);
|
|
64
|
-
return withDetail({
|
|
65
|
+
return withDetail({ mark: TASK_MARKS.shell, tone: "warning", label: "still running" }, hasOutput ? "showing output so far" : undefined);
|
|
65
66
|
}
|
|
66
67
|
function waitSentence(observation) {
|
|
67
68
|
if (observation.kind === "yielded")
|
|
@@ -108,9 +109,13 @@ export function cancelReceiptStatus(receipt) {
|
|
|
108
109
|
return receipt.decision === "already-settled" ? { ...status, label: `already ${status.label}` } : status;
|
|
109
110
|
}
|
|
110
111
|
return {
|
|
111
|
-
|
|
112
|
+
mark: execution.kind === "cancelling"
|
|
113
|
+
? TASK_MARKS.stopping
|
|
114
|
+
: execution.kind === "queued"
|
|
115
|
+
? TASK_MARKS.queued
|
|
116
|
+
: TASK_MARKS.shell,
|
|
112
117
|
tone: "warning",
|
|
113
|
-
label: execution.kind === "cancelling" ? "stopping" :
|
|
118
|
+
label: execution.kind === "cancelling" ? "stopping" : `still ${execution.kind}`,
|
|
114
119
|
detail: "cancellation requested",
|
|
115
120
|
};
|
|
116
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-task-status.js","sourceRoot":"","sources":["../../../src/core/tools/shell-task-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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AI,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3E,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC;AACd,CAAC;AAOD,kHAAkH;AAClH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,MAA0B;IACxE,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;IAC7B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/F,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACnC,oGAAoG;IACpG,MAAM,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;AACjE,CAAC","sourcesContent":["/**\n * Plain-language wording for shell task observations (`wait`) and cancellations (`kill`).\n *\n * One source of truth for two audiences: the model reads compact sentences in the tool result text, and the\n * transcript renders the same facts as a single status line. Structured data stays in the result `details`.\n */\n\nimport { hasErrorIdentity, type SerializedTypedError, serializeErrorCause } from \"../error-contract.ts\";\nimport { cancelReasonText } from \"../tasks/cancel-reason.js\";\nimport type {\n\tCancelError,\n\tCancelReceipt,\n\tCleanup,\n\tFailure,\n\tOutputError,\n\tTaskResult,\n\tWaitError,\n\tWaitOutcome,\n\tWatchError,\n} from \"../tasks/contracts.js\";\nimport { TaskEvictedError } from \"../tasks/eviction-error.js\";\n\nexport type TaskStatusTone = \"success\" | \"error\" | \"warning\" | \"dim\";\n\n/** One line of task state: `✓ completed · exit 0`. The glyph and label alone carry the meaning without color. */\nexport interface TaskStatus {\n\tglyph: \"✓\" | \"✗\" | \"●\" | \"○\";\n\ttone: TaskStatusTone;\n\tlabel: string;\n\tdetail?: string;\n}\n\nexport const EMPTY_OUTPUT_TEXT = \"(no output)\";\n\nfunction firstLine(text: string): string {\n\treturn text.trim().split(/\\r?\\n/, 1)[0]?.trim() ?? \"\";\n}\n\nfunction withoutTrailingPeriods(text: string): string {\n\tlet end = text.length;\n\twhile (end > 0 && (text[end - 1] === \".\" || /\\s/.test(text[end - 1] ?? \"\"))) end--;\n\treturn text.slice(0, end);\n}\n\n/** The message of a failure, unless it only repeats the failure code. */\nfunction informativeMessage(code: string, message: string): string | undefined {\n\tconst line = firstLine(message);\n\treturn line && line !== code ? line : undefined;\n}\n\nfunction withDetail(status: Omit<TaskStatus, \"detail\">, detail: string | undefined): TaskStatus {\n\treturn detail === undefined ? status : { ...status, detail };\n}\n\nexport function taskResultStatus(result: TaskResult): TaskStatus {\n\tswitch (result.kind) {\n\t\tcase \"completed\":\n\t\t\tif (result.exitCode === 0) return { glyph: \"✓\", tone: \"success\", label: \"completed\", detail: \"exit 0\" };\n\t\t\tif (result.exitCode === undefined) return { glyph: \"✗\", tone: \"error\", label: \"ended without an exit code\" };\n\t\t\treturn { glyph: \"✗\", tone: \"error\", label: `exited ${result.exitCode}` };\n\t\tcase \"failed\":\n\t\t\treturn withDetail(\n\t\t\t\t{ glyph: \"✗\", tone: \"error\", label: \"failed\" },\n\t\t\t\tinformativeMessage(result.code, result.message),\n\t\t\t);\n\t\tcase \"cancelled\":\n\t\t\treturn withDetail(\n\t\t\t\t{ glyph: \"○\", tone: \"dim\", label: \"cancelled\" },\n\t\t\t\tresult.cause === \"user\" ? undefined : cancelReasonText(result),\n\t\t\t);\n\t}\n}\n\n/** What happened to a task, as a verb phrase that follows its subject: `exited with code 1`. */\nfunction taskResultPhrase(result: TaskResult): string {\n\tswitch (result.kind) {\n\t\tcase \"completed\":\n\t\t\tif (result.exitCode === 0) return \"completed with exit code 0\";\n\t\t\tif (result.exitCode === undefined) return \"ended without an exit code\";\n\t\t\treturn `exited with code ${result.exitCode}`;\n\t\tcase \"failed\": {\n\t\t\tconst message = informativeMessage(result.code, result.message);\n\t\t\tconst reason = message === undefined ? undefined : withoutTrailingPeriods(message);\n\t\t\treturn `failed (${result.code})${reason ? `: ${reason}` : \"\"}${result.exitCode === undefined ? \"\" : ` (exit code ${result.exitCode})`}`;\n\t\t}\n\t\tcase \"cancelled\":\n\t\t\treturn `was cancelled (${cancelReasonText(result)})`;\n\t}\n}\n\n/** Status line for a `wait` result. `hasOutput` says whether any output is shown below it. */\nexport function waitStatus(observation: WaitOutcome, hasOutput: boolean): TaskStatus {\n\tif (observation.kind === \"settled\") return taskResultStatus(observation.result);\n\treturn withDetail(\n\t\t{ glyph: \"●\", tone: \"warning\", label: \"still running\" },\n\t\thasOutput ? \"showing output so far\" : undefined,\n\t);\n}\n\nfunction waitSentence(observation: WaitOutcome): string {\n\tif (observation.kind === \"yielded\")\n\t\treturn `Task ${observation.taskId} is still running (yielded: ${observation.reason}).`;\n\treturn `Task ${observation.taskId} ${taskResultPhrase(observation.result)}.`;\n}\n\nexport interface WaitResultTail {\n\tobservation: WaitOutcome;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n}\n\n/**\n * Everything the model reads after a wait's output: the truncation marker, one sentence with the task's state and\n * exit code, and the path of the full output when it was truncated. The renderer strips the same tail.\n */\nexport function waitResultTail({ observation, truncated, fullOutputPath }: WaitResultTail): string {\n\treturn `${truncated ? \"\\n[Output truncated.]\" : \"\"}\\n\\n${waitSentence(observation)}${fullOutputPath ? `\\nFull output: ${fullOutputPath}` : \"\"}`;\n}\n\nfunction cleanupSentence(cleanup: Cleanup): string {\n\tif (cleanup.kind !== \"failed\" && cleanup.kind !== \"quarantined\") return `Cleanup: ${cleanup.kind}.`;\n\tconst resources = cleanup.resources.map(\n\t\t(entry) => `${entry.resource} (${entry.code}): ${withoutTrailingPeriods(firstLine(entry.message))}`,\n\t);\n\treturn `Cleanup ${cleanup.kind === \"failed\" ? \"failed\" : \"quarantined, still being confirmed\"}: ${resources.join(\"; \")}.`;\n}\n\n/** Model-facing text of a `kill` result. The receipt itself stays in the result details. */\nexport function cancelReceiptSentence(receipt: CancelReceipt): string {\n\tconst { taskId, execution } = receipt;\n\tlet lead: string;\n\tif (execution.kind === \"settled\") {\n\t\tconst phrase = taskResultPhrase(execution.result);\n\t\tlead =\n\t\t\treceipt.decision === \"already-settled\"\n\t\t\t\t? `Task ${taskId} had already finished; nothing to stop. It ${phrase}.`\n\t\t\t\t: `Task ${taskId} ${phrase}.`;\n\t} else if (execution.kind === \"cancelling\") {\n\t\tlead = `Cancellation requested for task ${taskId}; it has not stopped yet.`;\n\t} else {\n\t\tlead = `Cancellation requested for task ${taskId}; it is still ${execution.kind}.`;\n\t}\n\treturn `${lead} ${cleanupSentence(receipt.cleanup)}`;\n}\n\n/** Status line for a `kill` result, describing the task rather than the request. */\nexport function cancelReceiptStatus(receipt: CancelReceipt): TaskStatus {\n\tconst { execution } = receipt;\n\tif (execution.kind === \"settled\") {\n\t\tconst status = taskResultStatus(execution.result);\n\t\treturn receipt.decision === \"already-settled\" ? { ...status, label: `already ${status.label}` } : status;\n\t}\n\treturn {\n\t\tglyph: \"●\",\n\t\ttone: \"warning\",\n\t\tlabel: execution.kind === \"cancelling\" ? \"stopping\" : \"still running\",\n\t\tdetail: \"cancellation requested\",\n\t};\n}\n\n/** The first resource that could not be cleaned up, for a status line; undefined when cleanup did not fail. */\nexport function cleanupFailureSummary(cleanup: Cleanup): string | undefined {\n\tif (cleanup.kind !== \"failed\") return undefined;\n\tconst [first, ...rest] = cleanup.resources;\n\tif (!first) return undefined;\n\tconst message = informativeMessage(first.code, first.message);\n\treturn `${first.resource}${message ? `: ${message}` : \"\"}${rest.length ? ` (+${rest.length} more)` : \"\"}`;\n}\n\nexport type TaskToolFailureCode = WaitError[\"code\"] | CancelError[\"code\"] | OutputError[\"code\"] | WatchError[\"code\"];\n\ninterface TaskErrorCopy {\n\t/** Names the id and what went wrong; `detail` is the supervisor's message when it says more than the code. */\n\theadline: (taskId: string, detail: string | undefined) => string;\n\t/** The next step. Shown in the transcript only, not sent to the model. */\n\thint?: string;\n}\n\nconst TASKS_HINT = \"Run /tasks to check on it.\";\n\nconst TASK_ERROR_COPY: Record<TaskToolFailureCode, TaskErrorCopy> = {\n\tUnknownTask: {\n\t\theadline: (taskId) => `No background task \"${taskId}\" in this session`,\n\t\thint: \"It may have finished and been cleaned up, or belong to another session. Run /tasks to see current tasks.\",\n\t},\n\tScopeMismatch: {\n\t\theadline: (taskId) => `Task \"${taskId}\" belongs to another session`,\n\t\thint: \"Run /tasks to see the tasks in this session.\",\n\t},\n\tTaskEvicted: {\n\t\theadline: (taskId) => `Task \"${taskId}\" finished and is no longer kept in this session`,\n\t\thint: \"Only the most recently finished tasks are kept. Its result is where the conversation reported it.\",\n\t},\n\tOwnerClosed: {\n\t\theadline: () => \"This session's background tasks are closed\",\n\t\thint: \"Run the command again to start a new task.\",\n\t},\n\tEnvironmentClosing: { headline: () => \"Atomic is shutting down\" },\n\tObserverCancelled: { headline: (taskId) => `Stopped waiting for task \"${taskId}\"`, hint: TASKS_HINT },\n\tOutputUnavailable: {\n\t\theadline: (taskId) => `Output for task \"${taskId}\" is no longer available`,\n\t\thint: \"Run /tasks to check on the task.\",\n\t},\n\tCleanupFailed: {\n\t\theadline: (taskId, detail) => `Could not stop task \"${taskId}\"${detail ? `: ${detail}` : \"\"}`,\n\t\thint: \"Run /tasks to check whether it is still running.\",\n\t},\n\tStaleGeneration: { headline: () => \"The task list changed while it was being read\", hint: \"Try again.\" },\n};\n\nfunction isTaskToolFailureCode(code: string): code is TaskToolFailureCode {\n\treturn Object.hasOwn(TASK_ERROR_COPY, code);\n}\n\nconst TASK_TOOL_ERROR_NAME = \"TaskToolError\";\nconst TASK_TOOL_ERROR_NAMES: ReadonlySet<string> = new Set([TASK_TOOL_ERROR_NAME]);\nconst TASK_TOOL_FAILURE_CODES: ReadonlySet<string> = new Set(Object.keys(TASK_ERROR_COPY));\n\n/** The facts a {@link TaskToolError} carries. */\nexport interface TaskToolErrorFields {\n\t/** The id the call named. */\n\treadonly taskId: string;\n}\n\n/** A {@link TaskToolError} as it crosses a process boundary or a detached `wait` reports it in `details.error`. */\nexport interface SerializedTaskToolError extends SerializedTypedError {\n\tcode: TaskToolFailureCode;\n\tfields: { taskId: string };\n}\n\n/**\n * A task failure on the `wait`/`kill` path. The message is `<Code>: <plain-language headline naming the task>`;\n * callers that branch on the failure read `code` instead of parsing it. An evicted task's failure has a\n * {@link TaskEvictedError} as its `cause`. Only `StaleGeneration` is retryable.\n */\nexport class TaskToolError extends Error {\n\toverride readonly name = TASK_TOOL_ERROR_NAME;\n\treadonly code: TaskToolFailureCode;\n\treadonly hint?: string;\n\treadonly retryable: boolean;\n\treadonly fields: TaskToolErrorFields;\n\treadonly taskId: string;\n\n\tconstructor(failure: Failure<TaskToolFailureCode>, taskId: string) {\n\t\tconst copy = TASK_ERROR_COPY[failure.code];\n\t\tsuper(\n\t\t\t`${failure.code}: ${copy.headline(taskId, informativeMessage(failure.code, failure.message))}`,\n\t\t\tfailure.code === \"TaskEvicted\" ? { cause: new TaskEvictedError({ taskId }) } : undefined,\n\t\t);\n\t\tthis.code = failure.code;\n\t\tthis.hint = copy.hint;\n\t\tthis.retryable = failure.code === \"StaleGeneration\";\n\t\tthis.fields = { taskId };\n\t\tthis.taskId = taskId;\n\t}\n\n\t/** The failure as data, for a result that reports it: a detached `wait` of a task that is gone carries it. */\n\ttoJSON(): SerializedTaskToolError {\n\t\tconst cause = serializeErrorCause(this.cause);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\t...(this.hint === undefined ? {} : { hint: this.hint }),\n\t\t\tretryable: this.retryable,\n\t\t\tfields: { taskId: this.taskId },\n\t\t\t...(cause === undefined ? {} : { cause }),\n\t\t};\n\t}\n}\n\n/** True for a {@link TaskToolError}, also one from another realm or process that kept its `name` and `code`. */\nexport function isTaskToolError(error: unknown): error is TaskToolError {\n\treturn error instanceof TaskToolError || hasErrorIdentity(error, TASK_TOOL_ERROR_NAMES, TASK_TOOL_FAILURE_CODES);\n}\n\n/**\n * Rebuilds a {@link TaskToolError} from its serialized form, such as a detached `wait`'s `details.error` read back\n * from a saved session. An evicted task's error gets its {@link TaskEvictedError} cause back. A copy without a known\n * `code` or a string `fields.taskId` gives undefined.\n */\nexport function rehydrateTaskToolError(value: unknown): TaskToolError | undefined {\n\tif (!isTaskToolError(value)) return undefined;\n\tconst { fields, message } = value as { readonly fields?: { readonly taskId?: unknown }; readonly message?: unknown };\n\tconst taskId = fields?.taskId;\n\tif (typeof taskId !== \"string\") return undefined;\n\tconst error = new TaskToolError({ code: value.code, message: \"\" }, taskId);\n\tif (typeof message === \"string\") Object.defineProperty(error, \"message\", { value: message });\n\treturn error;\n}\n\nexport interface TaskErrorPresentation {\n\theadline: string;\n\thint?: string;\n}\n\n/** How the transcript presents the text of a thrown {@link TaskToolError}; undefined for any other error text. */\nexport function presentTaskError(text: string, taskId: string | undefined): TaskErrorPresentation | undefined {\n\tconst match = /^(\\w+): ([^\\n]*)$/.exec(text.trim());\n\tif (!match) return undefined;\n\tconst [, code, rest] = match;\n\tif (code === undefined || rest === undefined || !isTaskToolFailureCode(code)) return undefined;\n\tconst copy = TASK_ERROR_COPY[code];\n\t// Sessions saved before the message was plain language hold only the code, repeated as the message.\n\tconst headline = rest === code && taskId ? copy.headline(taskId, undefined) : rest;\n\treturn copy.hint ? { headline, hint: copy.hint } : { headline };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell-task-status.js","sourceRoot":"","sources":["../../../src/core/tools/shell-task-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAiB,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAA6B,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAY7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAe9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAE/C,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IAC3C,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;IACtB,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAAE,GAAG,EAAE,CAAC;IACnF,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,yEAAyE;AACzE,SAAS,kBAAkB,CAAC,IAAY,EAAE,OAAe;IACxD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,UAAU,CAAC,MAAkC,EAAE,MAA0B;IAC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CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;AACjE,CAAC","sourcesContent":["/**\n * Plain-language wording for shell task observations (`wait`) and cancellations (`kill`).\n *\n * One source of truth for two audiences: the model reads compact sentences in the tool result text, and the\n * transcript renders the same facts as a single status line. Structured data stays in the result `details`.\n */\n\nimport { TASK_MARKS, type TaskMark } from \"../../modes/interactive/components/task-marks.ts\";\nimport { hasErrorIdentity, type SerializedTypedError, serializeErrorCause } from \"../error-contract.ts\";\nimport { cancelReasonText } from \"../tasks/cancel-reason.js\";\nimport type {\n\tCancelError,\n\tCancelReceipt,\n\tCleanup,\n\tFailure,\n\tOutputError,\n\tTaskResult,\n\tWaitError,\n\tWaitOutcome,\n\tWatchError,\n} from \"../tasks/contracts.js\";\nimport { TaskEvictedError } from \"../tasks/eviction-error.js\";\n\nexport type TaskStatusTone = \"success\" | \"error\" | \"warning\" | \"dim\";\n\n/**\n * One line of task state: `● completed · exit 0`. The mark is the one the agent panel and `/tasks` show the task's\n * state with; the mark and label alone carry the meaning without color, and `tone` colours the label.\n */\nexport interface TaskStatus {\n\tmark: TaskMark;\n\ttone: TaskStatusTone;\n\tlabel: string;\n\tdetail?: string;\n}\n\nexport const EMPTY_OUTPUT_TEXT = \"(no output)\";\n\nfunction firstLine(text: string): string {\n\treturn text.trim().split(/\\r?\\n/, 1)[0]?.trim() ?? \"\";\n}\n\nfunction withoutTrailingPeriods(text: string): string {\n\tlet end = text.length;\n\twhile (end > 0 && (text[end - 1] === \".\" || /\\s/.test(text[end - 1] ?? \"\"))) end--;\n\treturn text.slice(0, end);\n}\n\n/** The message of a failure, unless it only repeats the failure code. */\nfunction informativeMessage(code: string, message: string): string | undefined {\n\tconst line = firstLine(message);\n\treturn line && line !== code ? line : undefined;\n}\n\nfunction withDetail(status: Omit<TaskStatus, \"detail\">, detail: string | undefined): TaskStatus {\n\treturn detail === undefined ? status : { ...status, detail };\n}\n\nexport function taskResultStatus(result: TaskResult): TaskStatus {\n\tswitch (result.kind) {\n\t\tcase \"completed\":\n\t\t\tif (result.exitCode === 0)\n\t\t\t\treturn { mark: TASK_MARKS.done, tone: \"success\", label: \"completed\", detail: \"exit 0\" };\n\t\t\tif (result.exitCode === undefined)\n\t\t\t\treturn { mark: TASK_MARKS.failed, tone: \"error\", label: \"ended without an exit code\" };\n\t\t\treturn { mark: TASK_MARKS.failed, tone: \"error\", label: `exited ${result.exitCode}` };\n\t\tcase \"failed\":\n\t\t\treturn withDetail(\n\t\t\t\t{ mark: TASK_MARKS.failed, tone: \"error\", label: \"failed\" },\n\t\t\t\tinformativeMessage(result.code, result.message),\n\t\t\t);\n\t\tcase \"cancelled\":\n\t\t\treturn withDetail(\n\t\t\t\t{ mark: TASK_MARKS.stopped, tone: \"dim\", label: \"cancelled\" },\n\t\t\t\tresult.cause === \"user\" ? undefined : cancelReasonText(result),\n\t\t\t);\n\t}\n}\n\n/** What happened to a task, as a verb phrase that follows its subject: `exited with code 1`. */\nfunction taskResultPhrase(result: TaskResult): string {\n\tswitch (result.kind) {\n\t\tcase \"completed\":\n\t\t\tif (result.exitCode === 0) return \"completed with exit code 0\";\n\t\t\tif (result.exitCode === undefined) return \"ended without an exit code\";\n\t\t\treturn `exited with code ${result.exitCode}`;\n\t\tcase \"failed\": {\n\t\t\tconst message = informativeMessage(result.code, result.message);\n\t\t\tconst reason = message === undefined ? undefined : withoutTrailingPeriods(message);\n\t\t\treturn `failed (${result.code})${reason ? `: ${reason}` : \"\"}${result.exitCode === undefined ? \"\" : ` (exit code ${result.exitCode})`}`;\n\t\t}\n\t\tcase \"cancelled\":\n\t\t\treturn `was cancelled (${cancelReasonText(result)})`;\n\t}\n}\n\n/** Status line for a `wait` result. `hasOutput` says whether any output is shown below it. */\nexport function waitStatus(observation: WaitOutcome, hasOutput: boolean): TaskStatus {\n\tif (observation.kind === \"settled\") return taskResultStatus(observation.result);\n\treturn withDetail(\n\t\t{ mark: TASK_MARKS.shell, tone: \"warning\", label: \"still running\" },\n\t\thasOutput ? \"showing output so far\" : undefined,\n\t);\n}\n\nfunction waitSentence(observation: WaitOutcome): string {\n\tif (observation.kind === \"yielded\")\n\t\treturn `Task ${observation.taskId} is still running (yielded: ${observation.reason}).`;\n\treturn `Task ${observation.taskId} ${taskResultPhrase(observation.result)}.`;\n}\n\nexport interface WaitResultTail {\n\tobservation: WaitOutcome;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n}\n\n/**\n * Everything the model reads after a wait's output: the truncation marker, one sentence with the task's state and\n * exit code, and the path of the full output when it was truncated. The renderer strips the same tail.\n */\nexport function waitResultTail({ observation, truncated, fullOutputPath }: WaitResultTail): string {\n\treturn `${truncated ? \"\\n[Output truncated.]\" : \"\"}\\n\\n${waitSentence(observation)}${fullOutputPath ? `\\nFull output: ${fullOutputPath}` : \"\"}`;\n}\n\nfunction cleanupSentence(cleanup: Cleanup): string {\n\tif (cleanup.kind !== \"failed\" && cleanup.kind !== \"quarantined\") return `Cleanup: ${cleanup.kind}.`;\n\tconst resources = cleanup.resources.map(\n\t\t(entry) => `${entry.resource} (${entry.code}): ${withoutTrailingPeriods(firstLine(entry.message))}`,\n\t);\n\treturn `Cleanup ${cleanup.kind === \"failed\" ? \"failed\" : \"quarantined, still being confirmed\"}: ${resources.join(\"; \")}.`;\n}\n\n/** Model-facing text of a `kill` result. The receipt itself stays in the result details. */\nexport function cancelReceiptSentence(receipt: CancelReceipt): string {\n\tconst { taskId, execution } = receipt;\n\tlet lead: string;\n\tif (execution.kind === \"settled\") {\n\t\tconst phrase = taskResultPhrase(execution.result);\n\t\tlead =\n\t\t\treceipt.decision === \"already-settled\"\n\t\t\t\t? `Task ${taskId} had already finished; nothing to stop. It ${phrase}.`\n\t\t\t\t: `Task ${taskId} ${phrase}.`;\n\t} else if (execution.kind === \"cancelling\") {\n\t\tlead = `Cancellation requested for task ${taskId}; it has not stopped yet.`;\n\t} else {\n\t\tlead = `Cancellation requested for task ${taskId}; it is still ${execution.kind}.`;\n\t}\n\treturn `${lead} ${cleanupSentence(receipt.cleanup)}`;\n}\n\n/** Status line for a `kill` result, describing the task rather than the request. */\nexport function cancelReceiptStatus(receipt: CancelReceipt): TaskStatus {\n\tconst { execution } = receipt;\n\tif (execution.kind === \"settled\") {\n\t\tconst status = taskResultStatus(execution.result);\n\t\treturn receipt.decision === \"already-settled\" ? { ...status, label: `already ${status.label}` } : status;\n\t}\n\treturn {\n\t\tmark:\n\t\t\texecution.kind === \"cancelling\"\n\t\t\t\t? TASK_MARKS.stopping\n\t\t\t\t: execution.kind === \"queued\"\n\t\t\t\t\t? TASK_MARKS.queued\n\t\t\t\t\t: TASK_MARKS.shell,\n\t\ttone: \"warning\",\n\t\tlabel: execution.kind === \"cancelling\" ? \"stopping\" : `still ${execution.kind}`,\n\t\tdetail: \"cancellation requested\",\n\t};\n}\n\n/** The first resource that could not be cleaned up, for a status line; undefined when cleanup did not fail. */\nexport function cleanupFailureSummary(cleanup: Cleanup): string | undefined {\n\tif (cleanup.kind !== \"failed\") return undefined;\n\tconst [first, ...rest] = cleanup.resources;\n\tif (!first) return undefined;\n\tconst message = informativeMessage(first.code, first.message);\n\treturn `${first.resource}${message ? `: ${message}` : \"\"}${rest.length ? ` (+${rest.length} more)` : \"\"}`;\n}\n\nexport type TaskToolFailureCode = WaitError[\"code\"] | CancelError[\"code\"] | OutputError[\"code\"] | WatchError[\"code\"];\n\ninterface TaskErrorCopy {\n\t/** Names the id and what went wrong; `detail` is the supervisor's message when it says more than the code. */\n\theadline: (taskId: string, detail: string | undefined) => string;\n\t/** The next step. Shown in the transcript only, not sent to the model. */\n\thint?: string;\n}\n\nconst TASKS_HINT = \"Run /tasks to check on it.\";\n\nconst TASK_ERROR_COPY: Record<TaskToolFailureCode, TaskErrorCopy> = {\n\tUnknownTask: {\n\t\theadline: (taskId) => `No background task \"${taskId}\" in this session`,\n\t\thint: \"It may have finished and been cleaned up, or belong to another session. Run /tasks to see current tasks.\",\n\t},\n\tScopeMismatch: {\n\t\theadline: (taskId) => `Task \"${taskId}\" belongs to another session`,\n\t\thint: \"Run /tasks to see the tasks in this session.\",\n\t},\n\tTaskEvicted: {\n\t\theadline: (taskId) => `Task \"${taskId}\" finished and is no longer kept in this session`,\n\t\thint: \"Only the most recently finished tasks are kept. Its result is where the conversation reported it.\",\n\t},\n\tOwnerClosed: {\n\t\theadline: () => \"This session's background tasks are closed\",\n\t\thint: \"Run the command again to start a new task.\",\n\t},\n\tEnvironmentClosing: { headline: () => \"Atomic is shutting down\" },\n\tObserverCancelled: { headline: (taskId) => `Stopped waiting for task \"${taskId}\"`, hint: TASKS_HINT },\n\tOutputUnavailable: {\n\t\theadline: (taskId) => `Output for task \"${taskId}\" is no longer available`,\n\t\thint: \"Run /tasks to check on the task.\",\n\t},\n\tCleanupFailed: {\n\t\theadline: (taskId, detail) => `Could not stop task \"${taskId}\"${detail ? `: ${detail}` : \"\"}`,\n\t\thint: \"Run /tasks to check whether it is still running.\",\n\t},\n\tStaleGeneration: { headline: () => \"The task list changed while it was being read\", hint: \"Try again.\" },\n};\n\nfunction isTaskToolFailureCode(code: string): code is TaskToolFailureCode {\n\treturn Object.hasOwn(TASK_ERROR_COPY, code);\n}\n\nconst TASK_TOOL_ERROR_NAME = \"TaskToolError\";\nconst TASK_TOOL_ERROR_NAMES: ReadonlySet<string> = new Set([TASK_TOOL_ERROR_NAME]);\nconst TASK_TOOL_FAILURE_CODES: ReadonlySet<string> = new Set(Object.keys(TASK_ERROR_COPY));\n\n/** The facts a {@link TaskToolError} carries. */\nexport interface TaskToolErrorFields {\n\t/** The id the call named. */\n\treadonly taskId: string;\n}\n\n/** A {@link TaskToolError} as it crosses a process boundary or a detached `wait` reports it in `details.error`. */\nexport interface SerializedTaskToolError extends SerializedTypedError {\n\tcode: TaskToolFailureCode;\n\tfields: { taskId: string };\n}\n\n/**\n * A task failure on the `wait`/`kill` path. The message is `<Code>: <plain-language headline naming the task>`;\n * callers that branch on the failure read `code` instead of parsing it. An evicted task's failure has a\n * {@link TaskEvictedError} as its `cause`. Only `StaleGeneration` is retryable.\n */\nexport class TaskToolError extends Error {\n\toverride readonly name = TASK_TOOL_ERROR_NAME;\n\treadonly code: TaskToolFailureCode;\n\treadonly hint?: string;\n\treadonly retryable: boolean;\n\treadonly fields: TaskToolErrorFields;\n\treadonly taskId: string;\n\n\tconstructor(failure: Failure<TaskToolFailureCode>, taskId: string) {\n\t\tconst copy = TASK_ERROR_COPY[failure.code];\n\t\tsuper(\n\t\t\t`${failure.code}: ${copy.headline(taskId, informativeMessage(failure.code, failure.message))}`,\n\t\t\tfailure.code === \"TaskEvicted\" ? { cause: new TaskEvictedError({ taskId }) } : undefined,\n\t\t);\n\t\tthis.code = failure.code;\n\t\tthis.hint = copy.hint;\n\t\tthis.retryable = failure.code === \"StaleGeneration\";\n\t\tthis.fields = { taskId };\n\t\tthis.taskId = taskId;\n\t}\n\n\t/** The failure as data, for a result that reports it: a detached `wait` of a task that is gone carries it. */\n\ttoJSON(): SerializedTaskToolError {\n\t\tconst cause = serializeErrorCause(this.cause);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\t...(this.hint === undefined ? {} : { hint: this.hint }),\n\t\t\tretryable: this.retryable,\n\t\t\tfields: { taskId: this.taskId },\n\t\t\t...(cause === undefined ? {} : { cause }),\n\t\t};\n\t}\n}\n\n/** True for a {@link TaskToolError}, also one from another realm or process that kept its `name` and `code`. */\nexport function isTaskToolError(error: unknown): error is TaskToolError {\n\treturn error instanceof TaskToolError || hasErrorIdentity(error, TASK_TOOL_ERROR_NAMES, TASK_TOOL_FAILURE_CODES);\n}\n\n/**\n * Rebuilds a {@link TaskToolError} from its serialized form, such as a detached `wait`'s `details.error` read back\n * from a saved session. An evicted task's error gets its {@link TaskEvictedError} cause back. A copy without a known\n * `code` or a string `fields.taskId` gives undefined.\n */\nexport function rehydrateTaskToolError(value: unknown): TaskToolError | undefined {\n\tif (!isTaskToolError(value)) return undefined;\n\tconst { fields, message } = value as { readonly fields?: { readonly taskId?: unknown }; readonly message?: unknown };\n\tconst taskId = fields?.taskId;\n\tif (typeof taskId !== \"string\") return undefined;\n\tconst error = new TaskToolError({ code: value.code, message: \"\" }, taskId);\n\tif (typeof message === \"string\") Object.defineProperty(error, \"message\", { value: message });\n\treturn error;\n}\n\nexport interface TaskErrorPresentation {\n\theadline: string;\n\thint?: string;\n}\n\n/** How the transcript presents the text of a thrown {@link TaskToolError}; undefined for any other error text. */\nexport function presentTaskError(text: string, taskId: string | undefined): TaskErrorPresentation | undefined {\n\tconst match = /^(\\w+): ([^\\n]*)$/.exec(text.trim());\n\tif (!match) return undefined;\n\tconst [, code, rest] = match;\n\tif (code === undefined || rest === undefined || !isTaskToolFailureCode(code)) return undefined;\n\tconst copy = TASK_ERROR_COPY[code];\n\t// Sessions saved before the message was plain language hold only the code, repeated as the message.\n\tconst headline = rest === code && taskId ? copy.headline(taskId, undefined) : rest;\n\treturn copy.hint ? { headline, hint: copy.hint } : { headline };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-selector-connection.d.ts","sourceRoot":"","sources":["../../../src/core/tools/sqlite-selector-connection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AACnE,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite-selector-connection.d.ts","sourceRoot":"","sources":["../../../src/core/tools/sqlite-selector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AC,GAAG;CAKX"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isBuiltin } from "node:module";
|
|
2
2
|
import { Worker } from "node:worker_threads";
|
|
3
|
-
import { evalWorkerExecArgv } from "../../utils/worker-threads.js";
|
|
3
|
+
import { EVAL_WORKER_BUILTIN, evalWorkerExecArgv } from "../../utils/worker-threads.js";
|
|
4
4
|
const MISSING_NODE_SQLITE = "SQLite selectors need node:sqlite (Node >= 22.13 or Bun >= 1.4.2); this runtime does not provide it.";
|
|
5
5
|
const CONNECTION_SOURCE = `
|
|
6
|
-
|
|
6
|
+
${EVAL_WORKER_BUILTIN}
|
|
7
|
+
const { parentPort, workerData } = builtin("node:worker_threads");
|
|
7
8
|
process.emitWarning = () => {};
|
|
8
9
|
let database;
|
|
9
10
|
|
|
@@ -38,7 +39,7 @@ const statements = {
|
|
|
38
39
|
|
|
39
40
|
let DatabaseSync;
|
|
40
41
|
try {
|
|
41
|
-
({ DatabaseSync } =
|
|
42
|
+
({ DatabaseSync } = builtin("node:sqlite"));
|
|
42
43
|
} catch (error) {
|
|
43
44
|
parentPort.postMessage({ id: 0, failure: failure(error, true) });
|
|
44
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-selector-connection.js","sourceRoot":"","sources":["../../../src/core/tools/sqlite-selector-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAMnE,MAAM,mBAAmB,GACxB,sGAAsG,CAAC;AAExG,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDzB,CAAC;AA2BF,SAAS,OAAO,CAAC,OAA0B;IAC1C,IAAI,OAAO,CAAC,aAAa;QAAE,OAAO,IAAI,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GAAG,EAAE,CAAC,SAAS,CAAC,EACnD,KAAK,EAAE,KAAc,EAAE,EAAE;YACxB,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC;QACb,CAAC,CACD,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEO,OAAO,CAAC,OAA0B;QACzC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,GAAG,CAAC,KAAY;QACvB,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;QACrB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACD","sourcesContent":["import { isBuiltin } from \"node:module\";\nimport { Worker } from \"node:worker_threads\";\nimport { evalWorkerExecArgv } from \"../../utils/worker-threads.js\";\nimport type { SqliteRow, SqliteValue } from \"../storage/database.js\";\n\nexport type SqliteSelectorValue = string | number | boolean | null;\nexport type SqliteSelectorRow = Record<string, SqliteSelectorValue>;\n\nconst MISSING_NODE_SQLITE =\n\t\"SQLite selectors need node:sqlite (Node >= 22.13 or Bun >= 1.4.2); this runtime does not provide it.\";\n\nconst CONNECTION_SOURCE = `\nconst { parentPort, workerData } = require(\"node:worker_threads\");\nprocess.emitWarning = () => {};\nlet database;\n\nfunction failure(error, missingModule) {\n\treturn {\n\t\tname: error?.name ?? \"Error\",\n\t\tmessage: String(error?.message ?? error),\n\t\tcode: error?.code,\n\t\terrcode: error?.errcode,\n\t\terrstr: error?.errstr,\n\t\tmissingModule,\n\t};\n}\n\nconst statements = {\n\tall: (request) => database.prepare(request.sql).all(...request.params),\n\trows: (request) => {\n\t\tconst rows = [];\n\t\tif (rows.length >= request.limit) return rows;\n\t\tfor (const row of database.prepare(request.sql).iterate(...request.params)) {\n\t\t\trows.push(row);\n\t\t\tif (rows.length >= request.limit) break;\n\t\t}\n\t\treturn rows;\n\t},\n\trun: (request) => ({ changes: Number(database.prepare(request.sql).run(...request.params).changes ?? 0) }),\n\tclose: () => {\n\t\tdatabase.close();\n\t\tglobalThis.Bun?.gc?.(true);\n\t},\n};\n\nlet DatabaseSync;\ntry {\n\t({ DatabaseSync } = require(\"node:sqlite\"));\n} catch (error) {\n\tparentPort.postMessage({ id: 0, failure: failure(error, true) });\n}\nif (DatabaseSync !== undefined) {\n\ttry {\n\t\tdatabase = workerData.readonly ? new DatabaseSync(workerData.path, { readOnly: true }) : new DatabaseSync(workerData.path);\n\t\tparentPort.postMessage({ id: 0 });\n\t} catch (error) {\n\t\tparentPort.postMessage({ id: 0, failure: failure(error, false) });\n\t}\n}\n\nparentPort.on(\"message\", (request) => {\n\ttry {\n\t\tparentPort.postMessage({ id: request.id, value: statements[request.kind](request) });\n\t} catch (error) {\n\t\tparentPort.postMessage({ id: request.id, failure: failure(error, false) });\n\t}\n});\n`;\n\ninterface ConnectionFailure {\n\treadonly name: string;\n\treadonly message: string;\n\treadonly code?: string;\n\treadonly errcode?: number;\n\treadonly errstr?: string;\n\treadonly missingModule?: boolean;\n}\n\ninterface ConnectionReply {\n\treadonly id: number;\n\treadonly value?: unknown;\n\treadonly failure?: ConnectionFailure;\n}\n\ntype ConnectionRequest =\n\t| { readonly kind: \"all\" | \"run\"; readonly sql: string; readonly params: readonly unknown[] }\n\t| { readonly kind: \"rows\"; readonly sql: string; readonly params: readonly unknown[]; readonly limit: number }\n\t| { readonly kind: \"close\" };\n\ninterface Waiting {\n\treadonly resolve: (value: unknown) => void;\n\treadonly reject: (error: Error) => void;\n}\n\nfunction errorOf(failure: ConnectionFailure): Error {\n\tif (failure.missingModule) return new Error(MISSING_NODE_SQLITE);\n\tconst error = new Error(failure.message);\n\terror.name = failure.name;\n\treturn Object.assign(error, {\n\t\t...(failure.code === undefined ? {} : { code: failure.code }),\n\t\t...(failure.errcode === undefined ? {} : { errcode: failure.errcode }),\n\t\t...(failure.errstr === undefined ? {} : { errstr: failure.errstr }),\n\t});\n}\n\nfunction bindValues(params: readonly SqliteSelectorValue[]): unknown[] {\n\treturn params.map((param) => (typeof param === \"boolean\" ? (param ? 1 : 0) : param));\n}\n\nexport class SqliteSelectorConnection {\n\tprivate readonly waiting = new Map<number, Waiting>();\n\tprivate nextId = 1;\n\tprivate ended: Error | undefined;\n\tprivate closing: Promise<void> | undefined;\n\tprivate readonly worker: Worker;\n\n\tprivate constructor(worker: Worker) {\n\t\tthis.worker = worker;\n\t\tworker.on(\"message\", (reply: ConnectionReply) => {\n\t\t\tconst waiting = this.waiting.get(reply.id);\n\t\t\tif (waiting === undefined) return;\n\t\t\tthis.waiting.delete(reply.id);\n\t\t\tif (reply.failure === undefined) waiting.resolve(reply.value);\n\t\t\telse waiting.reject(errorOf(reply.failure));\n\t\t});\n\t\tworker.on(\"error\", (error) => this.end(error));\n\t\tworker.on(\"exit\", (code) => this.end(new Error(`SQLite selector worker exited with code ${code}`)));\n\t}\n\n\tstatic async open(path: string, options: { readonly readonly?: boolean } = {}): Promise<SqliteSelectorConnection> {\n\t\t// Asked on this thread, without loading the module: the worker starts without the process's flags, so a\n\t\t// `--no-experimental-sqlite` given to the process would not reach it.\n\t\tif (!isBuiltin(\"node:sqlite\")) throw new Error(MISSING_NODE_SQLITE);\n\t\tconst worker = new Worker(CONNECTION_SOURCE, {\n\t\t\teval: true,\n\t\t\texecArgv: evalWorkerExecArgv(),\n\t\t\tworkerData: { path, readonly: options.readonly === true },\n\t\t});\n\t\tconst connection = new SqliteSelectorConnection(worker);\n\t\tconst opened = new Promise<unknown>((resolve, reject) => connection.waiting.set(0, { resolve, reject }));\n\t\ttry {\n\t\t\tawait opened;\n\t\t} catch (error) {\n\t\t\tawait worker.terminate();\n\t\t\tthrow error;\n\t\t}\n\t\treturn connection;\n\t}\n\n\tall(sql: string, params: readonly SqliteSelectorValue[] = []): Promise<SqliteSelectorRow[]> {\n\t\treturn this.request({ kind: \"all\", sql, params: bindValues(params) }) as Promise<SqliteSelectorRow[]>;\n\t}\n\n\t/** Transcript entries can contain binary chunks; preserve their SQLite values across the worker boundary. */\n\tstorageRows<T extends SqliteRow>(sql: string, params: readonly SqliteValue[]): Promise<T[]> {\n\t\treturn this.request({ kind: \"all\", sql, params }) as Promise<T[]>;\n\t}\n\n\trows(sql: string, limit: number): Promise<SqliteSelectorRow[]> {\n\t\treturn this.request({ kind: \"rows\", sql, params: [], limit }) as Promise<SqliteSelectorRow[]>;\n\t}\n\n\trun(sql: string, params: readonly SqliteSelectorValue[] = []): Promise<{ changes: number }> {\n\t\treturn this.request({ kind: \"run\", sql, params: bindValues(params) }) as Promise<{ changes: number }>;\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closing ??= this.request({ kind: \"close\" }).then(\n\t\t\t() => this.worker.terminate().then(() => undefined),\n\t\t\tasync (error: unknown) => {\n\t\t\t\tawait this.worker.terminate();\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn this.closing;\n\t}\n\n\tprivate request(request: ConnectionRequest): Promise<unknown> {\n\t\tif (this.ended !== undefined) return Promise.reject(this.ended);\n\t\tconst id = this.nextId++;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.waiting.set(id, { resolve, reject });\n\t\t\tthis.worker.postMessage({ ...request, id });\n\t\t});\n\t}\n\n\tprivate end(error: Error): void {\n\t\tthis.ended ??= error;\n\t\tfor (const waiting of this.waiting.values()) waiting.reject(this.ended);\n\t\tthis.waiting.clear();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sqlite-selector-connection.js","sourceRoot":"","sources":["../../../src/core/tools/sqlite-selector-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAMxF,MAAM,mBAAmB,GACxB,sGAAsG,CAAC;AAExG,MAAM,iBAAiB,GAAG;EACxB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDpB,CAAC;AA2BF,SAAS,OAAO,CAAC,OAA0B;IAC1C,IAAI,OAAO,CAAC,aAAa;QAAE,OAAO,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QAC3B,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QACtE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,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AAC;YAC1C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,GAAG,CAAC,KAAY;QACvB,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;QACrB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACD","sourcesContent":["import { isBuiltin } from \"node:module\";\nimport { Worker } from \"node:worker_threads\";\nimport { EVAL_WORKER_BUILTIN, evalWorkerExecArgv } from \"../../utils/worker-threads.js\";\nimport type { SqliteRow, SqliteValue } from \"../storage/database.js\";\n\nexport type SqliteSelectorValue = string | number | boolean | null;\nexport type SqliteSelectorRow = Record<string, SqliteSelectorValue>;\n\nconst MISSING_NODE_SQLITE =\n\t\"SQLite selectors need node:sqlite (Node >= 22.13 or Bun >= 1.4.2); this runtime does not provide it.\";\n\nconst CONNECTION_SOURCE = `\n${EVAL_WORKER_BUILTIN}\nconst { parentPort, workerData } = builtin(\"node:worker_threads\");\nprocess.emitWarning = () => {};\nlet database;\n\nfunction failure(error, missingModule) {\n\treturn {\n\t\tname: error?.name ?? \"Error\",\n\t\tmessage: String(error?.message ?? error),\n\t\tcode: error?.code,\n\t\terrcode: error?.errcode,\n\t\terrstr: error?.errstr,\n\t\tmissingModule,\n\t};\n}\n\nconst statements = {\n\tall: (request) => database.prepare(request.sql).all(...request.params),\n\trows: (request) => {\n\t\tconst rows = [];\n\t\tif (rows.length >= request.limit) return rows;\n\t\tfor (const row of database.prepare(request.sql).iterate(...request.params)) {\n\t\t\trows.push(row);\n\t\t\tif (rows.length >= request.limit) break;\n\t\t}\n\t\treturn rows;\n\t},\n\trun: (request) => ({ changes: Number(database.prepare(request.sql).run(...request.params).changes ?? 0) }),\n\tclose: () => {\n\t\tdatabase.close();\n\t\tglobalThis.Bun?.gc?.(true);\n\t},\n};\n\nlet DatabaseSync;\ntry {\n\t({ DatabaseSync } = builtin(\"node:sqlite\"));\n} catch (error) {\n\tparentPort.postMessage({ id: 0, failure: failure(error, true) });\n}\nif (DatabaseSync !== undefined) {\n\ttry {\n\t\tdatabase = workerData.readonly ? new DatabaseSync(workerData.path, { readOnly: true }) : new DatabaseSync(workerData.path);\n\t\tparentPort.postMessage({ id: 0 });\n\t} catch (error) {\n\t\tparentPort.postMessage({ id: 0, failure: failure(error, false) });\n\t}\n}\n\nparentPort.on(\"message\", (request) => {\n\ttry {\n\t\tparentPort.postMessage({ id: request.id, value: statements[request.kind](request) });\n\t} catch (error) {\n\t\tparentPort.postMessage({ id: request.id, failure: failure(error, false) });\n\t}\n});\n`;\n\ninterface ConnectionFailure {\n\treadonly name: string;\n\treadonly message: string;\n\treadonly code?: string;\n\treadonly errcode?: number;\n\treadonly errstr?: string;\n\treadonly missingModule?: boolean;\n}\n\ninterface ConnectionReply {\n\treadonly id: number;\n\treadonly value?: unknown;\n\treadonly failure?: ConnectionFailure;\n}\n\ntype ConnectionRequest =\n\t| { readonly kind: \"all\" | \"run\"; readonly sql: string; readonly params: readonly unknown[] }\n\t| { readonly kind: \"rows\"; readonly sql: string; readonly params: readonly unknown[]; readonly limit: number }\n\t| { readonly kind: \"close\" };\n\ninterface Waiting {\n\treadonly resolve: (value: unknown) => void;\n\treadonly reject: (error: Error) => void;\n}\n\nfunction errorOf(failure: ConnectionFailure): Error {\n\tif (failure.missingModule) return new Error(MISSING_NODE_SQLITE);\n\tconst error = new Error(failure.message);\n\terror.name = failure.name;\n\treturn Object.assign(error, {\n\t\t...(failure.code === undefined ? {} : { code: failure.code }),\n\t\t...(failure.errcode === undefined ? {} : { errcode: failure.errcode }),\n\t\t...(failure.errstr === undefined ? {} : { errstr: failure.errstr }),\n\t});\n}\n\nfunction bindValues(params: readonly SqliteSelectorValue[]): unknown[] {\n\treturn params.map((param) => (typeof param === \"boolean\" ? (param ? 1 : 0) : param));\n}\n\nexport class SqliteSelectorConnection {\n\tprivate readonly waiting = new Map<number, Waiting>();\n\tprivate nextId = 1;\n\tprivate ended: Error | undefined;\n\tprivate closing: Promise<void> | undefined;\n\tprivate readonly worker: Worker;\n\n\tprivate constructor(worker: Worker) {\n\t\tthis.worker = worker;\n\t\tworker.on(\"message\", (reply: ConnectionReply) => {\n\t\t\tconst waiting = this.waiting.get(reply.id);\n\t\t\tif (waiting === undefined) return;\n\t\t\tthis.waiting.delete(reply.id);\n\t\t\tif (reply.failure === undefined) waiting.resolve(reply.value);\n\t\t\telse waiting.reject(errorOf(reply.failure));\n\t\t});\n\t\tworker.on(\"error\", (error) => this.end(error));\n\t\tworker.on(\"exit\", (code) => this.end(new Error(`SQLite selector worker exited with code ${code}`)));\n\t}\n\n\tstatic async open(path: string, options: { readonly readonly?: boolean } = {}): Promise<SqliteSelectorConnection> {\n\t\t// Asked on this thread, without loading the module: the worker starts without the process's flags, so a\n\t\t// `--no-experimental-sqlite` given to the process would not reach it.\n\t\tif (!isBuiltin(\"node:sqlite\")) throw new Error(MISSING_NODE_SQLITE);\n\t\tconst worker = new Worker(CONNECTION_SOURCE, {\n\t\t\teval: true,\n\t\t\texecArgv: evalWorkerExecArgv(),\n\t\t\tworkerData: { path, readonly: options.readonly === true },\n\t\t});\n\t\tconst connection = new SqliteSelectorConnection(worker);\n\t\tconst opened = new Promise<unknown>((resolve, reject) => connection.waiting.set(0, { resolve, reject }));\n\t\ttry {\n\t\t\tawait opened;\n\t\t} catch (error) {\n\t\t\tawait worker.terminate();\n\t\t\tthrow error;\n\t\t}\n\t\treturn connection;\n\t}\n\n\tall(sql: string, params: readonly SqliteSelectorValue[] = []): Promise<SqliteSelectorRow[]> {\n\t\treturn this.request({ kind: \"all\", sql, params: bindValues(params) }) as Promise<SqliteSelectorRow[]>;\n\t}\n\n\t/** Transcript entries can contain binary chunks; preserve their SQLite values across the worker boundary. */\n\tstorageRows<T extends SqliteRow>(sql: string, params: readonly SqliteValue[]): Promise<T[]> {\n\t\treturn this.request({ kind: \"all\", sql, params }) as Promise<T[]>;\n\t}\n\n\trows(sql: string, limit: number): Promise<SqliteSelectorRow[]> {\n\t\treturn this.request({ kind: \"rows\", sql, params: [], limit }) as Promise<SqliteSelectorRow[]>;\n\t}\n\n\trun(sql: string, params: readonly SqliteSelectorValue[] = []): Promise<{ changes: number }> {\n\t\treturn this.request({ kind: \"run\", sql, params: bindValues(params) }) as Promise<{ changes: number }>;\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closing ??= this.request({ kind: \"close\" }).then(\n\t\t\t() => this.worker.terminate().then(() => undefined),\n\t\t\tasync (error: unknown) => {\n\t\t\t\tawait this.worker.terminate();\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn this.closing;\n\t}\n\n\tprivate request(request: ConnectionRequest): Promise<unknown> {\n\t\tif (this.ended !== undefined) return Promise.reject(this.ended);\n\t\tconst id = this.nextId++;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.waiting.set(id, { resolve, reject });\n\t\t\tthis.worker.postMessage({ ...request, id });\n\t\t});\n\t}\n\n\tprivate end(error: Error): void {\n\t\tthis.ended ??= error;\n\t\tfor (const waiting of this.waiting.values()) waiting.reject(this.ended);\n\t\tthis.waiting.clear();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-directory-security.d.ts","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"windows-directory-security.d.ts","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAcH,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IACjC,iEAAiE;I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AE,mCAAwC,GAC/C,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAiB/C;AAqBD,KAAK,cAAc,GAAG,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,mCAAmC,KACxC,wBAAwB,GAAG,SAAS,GAAG,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAC;AAiD1F;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mCAAmC,CAClD,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAyB7B;AAED,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC3C,MAAM,GAAG,SAAS,CAapB;AAED,wBAAsB,8CAA8C,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpF;AAED,gFAAgF;AAChF,wBAAgB,2CAA2C,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,CAEpG;AAED,wGAAwG;AACxG,wBAAgB,4CAA4C,IAAI,IAAI,CAOnE"}
|
|
@@ -30,6 +30,7 @@ import { dirname, resolve } from "node:path";
|
|
|
30
30
|
import { clearTimeout, setTimeout } from "node:timers";
|
|
31
31
|
import { createModuleRequire } from "../../utils/module-require.js";
|
|
32
32
|
import { windowsPowerShellEnvironment } from "../../utils/windows-powershell.js";
|
|
33
|
+
import { asyncScope } from "../async-scope.js";
|
|
33
34
|
/**
|
|
34
35
|
* Principals allowed to own, or hold access-allowed ACEs on, a temp component.
|
|
35
36
|
*
|
|
@@ -184,7 +185,7 @@ async function readNatively(path) {
|
|
|
184
185
|
}
|
|
185
186
|
const outsideAnyCaller = AsyncLocalStorage.snapshot();
|
|
186
187
|
const sharedReads = new Map();
|
|
187
|
-
const currentReadOwner =
|
|
188
|
+
const currentReadOwner = asyncScope();
|
|
188
189
|
const ownedReads = new WeakMap();
|
|
189
190
|
const activeReads = new Set();
|
|
190
191
|
export function trackWindowsDirectorySecurityWork(operation) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-directory-security.js","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AA4BjF;;;;;;;;;;;GAWG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS;IAC3C,UAAU,EAAE,eAAe;IAC3B,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE,gBAAgB;IAC3B,SAAS,EAAE,eAAe;CAC1B,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAAC,QAAkC;IAClF,MAAM,OAAO,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,UAAU,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,OAAO,iCAAiC,CAAC;IAC1C,CAAC;IAC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AO,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;QAClE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/G,CAAC;AACF,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2CAA2C,CAAC,MAAkC;IAC7F,cAAc,GAAG,MAAM,IAAI,iCAAiC,CAAC;AAC9D,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,4CAA4C;IAC3D,eAAe,IAAI,CAAC,CAAC;IACrB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5D,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,eAAe,GAAG,SAAS,CAAC;IAC5B,cAAc,GAAG,iCAAiC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Windows owner-SID and DACL verification for the session temp tree.\n *\n * POSIX proves ownership of an existing temp component with a uid comparison\n * and a mode check. Node exposes neither on Windows — `lstatSync` reports\n * uid/gid 0 — so this module reads the real security descriptor and decides\n * from SIDs alone: the owner must\n * be a trusted principal and every access-allowed ACE must grant only trusted\n * principals. Names are never compared; two accounts can share a display name,\n * but never a SID.\n *\n * The native module reads the descriptor directly. When that binding is\n * unavailable or cannot read the directory, an asynchronous PowerShell\n * subprocess reads it instead. Reads start after the synchronous caller\n * returns, so a synchronous check never reads the descriptor. A successful\n * verification is cached for the life of the process, keyed to the\n * directory's path and identity (its file ID and creation time),\n * and a directory inside a verified one needs no read of its own (see\n * `verifyWindowsDirectorySecurityAsync`). A directory swapped underneath the\n * path is a new file with a new ID and is read again.\n * Failures are not cached: a refusal means \"no spill file this time\", and a\n * transient read failure must not disable persistence for the rest of the\n * process.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { statSync } from \"node:fs\";\nimport { stat as statAsync } from \"node:fs/promises\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { clearTimeout, setTimeout } from \"node:timers\";\nimport { createModuleRequire } from \"../../utils/module-require.js\";\nimport { windowsPowerShellEnvironment } from \"../../utils/windows-powershell.ts\";\n\n/** One DACL entry with its trustee resolved to a literal SID. */\nexport interface WindowsAccessRule {\n\t/** True for an access-allowed entry, false for access-denied. */\n\tallow: boolean;\n\t/** The SID the entry applies to. */\n\tsid: string;\n}\n\n/** What the security read produces: the caller's SID plus the descriptor. */\nexport interface WindowsDirectorySecurity {\n\t/** SID of the current process token's user. */\n\tcurrentSid: string;\n\t/** SID owning the directory. */\n\townerSid: string;\n\t/** The DACL portion of the descriptor in SDDL form (may be empty). */\n\tdacl: string;\n\t/**\n\t * Every DACL entry with its trustee as a literal SID (`GetAccessRules`\n\t * resolves domain-relative SDDL abbreviations such as `LA` that a\n\t * name-side parse cannot). The SDDL string above cross-checks that these\n\t * rules describe the whole DACL: only plain allow/deny ACE types, one\n\t * rule per ACE.\n\t */\n\taccessRules: readonly WindowsAccessRule[];\n}\n\n/**\n * Principals allowed to own, or hold access-allowed ACEs on, a temp component.\n *\n * SYSTEM and Administrators hold both on any per-user Windows temp directory\n * by inheritance, and both can reach any file on the volume regardless, so\n * permitting them grants nothing an attacker did not already have. Elevated\n * processes also create directories owned by the Administrators group rather\n * than the user, which is why the owner check shares this set. CREATOR OWNER\n * is inherit-only plumbing: it materializes as the creating account on\n * descendants, and creation inside the tree is already restricted to the\n * SIDs allowed here.\n */\nconst TRUSTED_STATIC_SIDS = new Set<string>([\n\t\"S-1-5-18\", // Local System\n\t\"S-1-5-32-544\", // Builtin Administrators\n\t\"S-1-3-0\", // Creator Owner\n\t\"S-1-3-4\", // Owner Rights\n]);\n\n/**\n * Decide whether a directory's descriptor is safe to adopt.\n *\n * Returns a refusal reason, or `undefined` when the directory is owned by a\n * trusted principal and its DACL grants access to trusted principals only.\n * Exported as a pure function so the decision table is testable on any host.\n */\nexport function evaluateWindowsDirectorySecurity(security: WindowsDirectorySecurity): string | undefined {\n\tconst trusted = (sid: string): boolean => sid === security.currentSid || TRUSTED_STATIC_SIDS.has(sid);\n\tif (!security.ownerSid.startsWith(\"S-1-\")) {\n\t\treturn \"its owner could not be verified\";\n\t}\n\tif (!trusted(security.ownerSid)) {\n\t\treturn \"it is owned by another account\";\n\t}\n\t// `Get-Acl` renders a null DACL (everyone has full control) as an absent\n\t// `D:` section; an empty DACL (`D:` with no ACEs) grants nobody anything\n\t// and is fine.\n\tconst dacl = security.dacl.trim();\n\tif (!dacl.startsWith(\"D:\")) {\n\t\treturn \"it has no access control list\";\n\t}\n\tlet rest = dacl.slice(2);\n\tconst flagsEnd = rest.indexOf(\"(\");\n\tconst flags = flagsEnd === -1 ? rest : rest.slice(0, flagsEnd);\n\tif (!/^[A-Z]*$/.test(flags)) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\trest = flagsEnd === -1 ? \"\" : rest.slice(flagsEnd);\n\tconst aces = rest.match(/\\([^()]*\\)/g) ?? [];\n\tif (aces.join(\"\") !== rest) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\tfor (const ace of aces) {\n\t\tconst type = ace.slice(1, -1).split(\";\")[0];\n\t\tif (type !== \"A\" && type !== \"D\") {\n\t\t\t// Conditional, object, and callback ACEs are not modeled by the\n\t\t\t// resolved access rules below, so a DACL containing one cannot be\n\t\t\t// proven restrictive.\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t}\n\tif (security.accessRules.length !== aces.length) {\n\t\t// The resolved rules must describe the whole DACL; a mismatch means\n\t\t// part of it was not translated and cannot be checked.\n\t\treturn \"its access control list could not be verified\";\n\t}\n\tfor (const rule of security.accessRules) {\n\t\tif (!rule.allow) {\n\t\t\tcontinue; // A deny entry only ever removes access.\n\t\t}\n\t\tif (!rule.sid.startsWith(\"S-1-\")) {\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t\tif (!trusted(rule.sid)) {\n\t\t\treturn \"it grants access to another account\";\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * One PowerShell round trip: the caller's SID, the owner SID, the DACL in\n * SDDL form, and one `Allow|Deny;SID` line per resolved access rule. The path\n * travels through the environment rather than the command line so no quoting\n * rules apply to it.\n */\nconst READ_SECURITY_SCRIPT = [\n\t\"$ErrorActionPreference = 'Stop'\",\n\t\"$acl = Get-Acl -LiteralPath $env:ATOMIC_SECURITY_QUERY_PATH\",\n\t\"$owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value\",\n\t\"$dacl = $acl.GetSecurityDescriptorSddlForm('Access')\",\n\t\"$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value\",\n\t\"$lines = @($user, $owner, $dacl)\",\n\t\"foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))\" +\n\t\t' { $lines += \"$($rule.AccessControlType);$($rule.IdentityReference.Value)\" }',\n\t'[Console]::Out.Write(($lines -join \"`n\"))',\n].join(\"; \");\n\n/** Bounded wait for the security read; a wedged subprocess must not hang a spill. */\nconst READ_SECURITY_TIMEOUT_MS = 30_000;\n\nexport const VERIFICATION_PENDING_REASON = \"its ownership is still being verified\";\n\n/** PowerShell hosts to try, most specific first: an absolute Windows\n * PowerShell path immune to a stripped `PATH`, then whichever of\n * `powershell.exe`/`pwsh.exe` the environment resolves. */\nexport function powershellCandidates(): string[] {\n\tconst candidates: string[] = [];\n\tcandidates.push(`${windowsDirectory()}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tcandidates.push(\"powershell.exe\", \"pwsh.exe\");\n\treturn candidates;\n}\n\n/** The environment for a PowerShell read: Windows PowerShell's, plus the path the read is for. */\nfunction powershellEnvironment(path: string): NodeJS.ProcessEnv {\n\treturn { ...windowsPowerShellEnvironment(), ATOMIC_SECURITY_QUERY_PATH: path };\n}\n\nfunction windowsDirectory(): string {\n\treturn process.env.SystemRoot ?? process.env.windir ?? \"C:\\\\Windows\";\n}\n\nasync function neutralWorkingDirectory(): Promise<string | undefined> {\n\ttry {\n\t\treturn (await statAsync(windowsDirectory())).isDirectory() ? windowsDirectory() : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet lastReadFailure: string | undefined;\n\n/** Test seam: why the most recent descriptor read returned `undefined`. */\nexport function getLastWindowsSecurityReadFailureForTesting(): string | undefined {\n\treturn lastReadFailure;\n}\n\ntype NativeSecurityReader = (path: string) => Promise<WindowsDirectorySecurity | null | undefined>;\n\nlet nativeReader: NativeSecurityReader | null | undefined;\n\nfunction nativeSecurityReader(): NativeSecurityReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\twindowsDirectorySecurityAsync?: NativeSecurityReader;\n\t\t\t};\n\t\t\tnativeReader = binding.windowsDirectorySecurityAsync ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nasync function readNatively(path: string): Promise<WindowsDirectorySecurity | null> {\n\tconst native = nativeSecurityReader();\n\tif (native === null) {\n\t\treturn null;\n\t}\n\ttry {\n\t\treturn (await native(path)) ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport interface ReadWindowsDirectorySecurityOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tbackground?: boolean;\n\tidentity?: string;\n}\n\ntype SecurityAttempt = { security: WindowsDirectorySecurity } | { failure: string };\n\ntype ChildStream = (Readable & Partial<Pick<Socket, \"ref\" | \"unref\">>) | null;\n\nconst outsideAnyCaller = AsyncLocalStorage.snapshot();\n\nconst sharedReads = new Map<string, SharedSecurityRead>();\nconst currentReadOwner = new AsyncLocalStorage<WeakRef<AbortSignal>>();\nconst ownedReads = new WeakMap<AbortSignal, Set<Promise<void>>>();\nconst activeReads = new Set<Promise<void>>();\n\nexport function trackWindowsDirectorySecurityWork<T>(operation: () => Promise<T>): Promise<T> {\n\tconst owner = currentReadOwner.getStore()?.deref();\n\tconst result = operation();\n\tconst settled = result.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tactiveReads.add(settled);\n\tconst pending = owner ? (ownedReads.get(owner) ?? new Set<Promise<void>>()) : undefined;\n\tif (owner && pending) ownedReads.set(owner, pending);\n\tpending?.add(settled);\n\tvoid settled.then(() => {\n\t\tactiveReads.delete(settled);\n\t\tpending?.delete(settled);\n\t});\n\treturn result;\n}\nconst closingReads = new Set<SharedSecurityRead>();\n\nexport function withWindowsDirectorySecurityOwner<T>(\n\tsignal: AbortSignal,\n\toperation: () => T,\n\toptions: { inherit?: boolean } = {},\n): T {\n\tconst inheritedOwner = options.inherit ? currentReadOwner.getStore()?.deref() : undefined;\n\treturn currentReadOwner.run(new WeakRef(inheritedOwner ?? signal), operation);\n}\n\nexport async function drainWindowsDirectorySecurityReads(signal: AbortSignal): Promise<void> {\n\tconst pending = ownedReads.get(signal);\n\twhile (pending?.size) await Promise.all(pending);\n}\n\nclass SharedSecurityRead {\n\treadonly result: Promise<WindowsDirectorySecurity | undefined>;\n\tprivate readonly controller = new AbortController();\n\tprivate waiters = 0;\n\tprivate foregroundWaiters = 0;\n\tprivate child: ChildProcess | undefined;\n\tprivate finished = false;\n\tprivate readonly path: string;\n\tprivate readonly key: string;\n\n\tconstructor(path: string, key: string) {\n\t\tthis.path = path;\n\t\tthis.key = key;\n\t\tthis.result = outsideAnyCaller(() => Promise.resolve().then(() => this.readCandidates())).finally(() => {\n\t\t\tif (sharedReads.get(key) === this) sharedReads.delete(key);\n\t\t\tthis.finished = true;\n\t\t\tclosingReads.delete(this);\n\t\t});\n\t}\n\n\tjoin(\n\t\ttimeoutMs: number,\n\t\tsignal: AbortSignal | undefined,\n\t\tbackground: boolean,\n\t): Promise<WindowsDirectorySecurity | undefined> {\n\t\tthis.waiters += 1;\n\t\tif (!background) this.foregroundWaiters += 1;\n\t\tthis.applyKeepAlive();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet left = false;\n\t\t\tconst leave = (security: WindowsDirectorySecurity | undefined) => {\n\t\t\t\tif (left) return;\n\t\t\t\tleft = true;\n\t\t\t\tclearTimeout(deadline);\n\t\t\t\tsignal?.removeEventListener(\"abort\", stopWaiting);\n\t\t\t\tthis.waiters -= 1;\n\t\t\t\tif (!background) this.foregroundWaiters -= 1;\n\t\t\t\tif (this.waiters === 0) {\n\t\t\t\t\tthis.cancel();\n\t\t\t\t\tvoid this.result.then(\n\t\t\t\t\t\t() => resolve(security),\n\t\t\t\t\t\t() => resolve(undefined),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.applyKeepAlive();\n\t\t\t\t\tresolve(security);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst stopWaiting = () => leave(undefined);\n\t\t\tconst deadline = setTimeout(stopWaiting, timeoutMs);\n\t\t\tif (background) deadline.unref();\n\t\t\tsignal?.addEventListener(\"abort\", stopWaiting, { once: true });\n\t\t\tvoid this.result.then(leave, () => leave(undefined));\n\t\t});\n\t}\n\n\tcancel(): void {\n\t\tif (sharedReads.get(this.key) === this) sharedReads.delete(this.key);\n\t\tif (!this.finished) closingReads.add(this);\n\t\tthis.controller.abort();\n\t}\n\n\tprivate async readCandidates(): Promise<WindowsDirectorySecurity | undefined> {\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tlastReadFailure = undefined;\n\t\tconst security = await readNatively(this.path);\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tif (security !== null) return security;\n\t\tconst failures: string[] = [];\n\t\tfor (const executable of powershellCandidates()) {\n\t\t\tif (this.controller.signal.aborted) break;\n\t\t\tconst attempt = await this.readWith(executable);\n\t\t\tif (\"security\" in attempt) return attempt.security;\n\t\t\tfailures.push(attempt.failure);\n\t\t}\n\t\tlastReadFailure = failures.join(\" | \");\n\t\treturn undefined;\n\t}\n\n\tprivate async readWith(executable: string): Promise<SecurityAttempt> {\n\t\tconst cwd = await neutralWorkingDirectory();\n\t\tif (this.controller.signal.aborted) return { failure: `${executable}: aborted` };\n\t\treturn new Promise((resolve) => {\n\t\t\tlet child: ChildProcess;\n\t\t\ttry {\n\t\t\t\tchild = spawn(executable, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", READ_SECURITY_SCRIPT], {\n\t\t\t\t\tcwd,\n\t\t\t\t\tenv: powershellEnvironment(this.path),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresolve({ failure: `${executable}: error=${error instanceof Error ? error.message : String(error)}` });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.child = child;\n\t\t\tthis.applyKeepAlive();\n\t\t\tconst stdout: Buffer[] = [];\n\t\t\tconst stderr: Buffer[] = [];\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\t\tlet settled = false;\n\t\t\tconst settle = (attempt: SecurityAttempt) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.child = undefined;\n\t\t\t\tthis.controller.signal.removeEventListener(\"abort\", stop);\n\t\t\t\tresolve(attempt);\n\t\t\t};\n\t\t\tlet failure: string | undefined;\n\t\t\tlet stopping = false;\n\t\t\tconst stop = () => {\n\t\t\t\tfailure ??= `${executable}: aborted`;\n\t\t\t\tif (stopping) return;\n\t\t\t\tstopping = true;\n\t\t\t\tchild.ref();\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t};\n\t\t\tthis.controller.signal.addEventListener(\"abort\", stop, { once: true });\n\t\t\tconst fail = (error: Error) => {\n\t\t\t\tfailure ??= `${executable}: error=${error.message}`;\n\t\t\t\tstop();\n\t\t\t};\n\t\t\tchild.on(\"error\", fail);\n\t\t\tchild.stdout?.on(\"error\", fail);\n\t\t\tchild.stderr?.on(\"error\", fail);\n\t\t\tchild.once(\"close\", (status, signal) => {\n\t\t\t\tif (failure !== undefined) {\n\t\t\t\t\tsettle({ failure });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst output = Buffer.concat(stdout).toString(\"utf8\");\n\t\t\t\tif (status !== 0) {\n\t\t\t\t\tconst detail = Buffer.concat(stderr).toString(\"utf8\").trim().slice(0, 500);\n\t\t\t\t\tsettle({ failure: `${executable}: status=${status} signal=${signal} stderr=${detail}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst security = parseSecurityOutput(output);\n\t\t\t\tsettle(\n\t\t\t\t\tsecurity === undefined\n\t\t\t\t\t\t? { failure: `${executable}: unparseable output ${JSON.stringify(output.slice(0, 500))}` }\n\t\t\t\t\t\t: { security },\n\t\t\t\t);\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate applyKeepAlive(): void {\n\t\tconst child = this.child;\n\t\tif (child === undefined) return;\n\t\tconst keepAlive = this.foregroundWaiters > 0;\n\t\tif (keepAlive) child.ref();\n\t\telse child.unref();\n\t\tconst streams: ChildStream[] = [child.stdout, child.stderr];\n\t\tfor (const stream of streams) {\n\t\t\tif (keepAlive) stream?.ref?.();\n\t\t\telse stream?.unref?.();\n\t\t}\n\t}\n}\n\n/**\n * Read the security descriptor of `path` without blocking the main thread, or\n * `undefined` when it cannot be read (access denied, missing PowerShell, the\n * timeout, an aborted signal). Callers treat `undefined` as unverifiable and\n * refuse the directory.\n */\nexport function readWindowsDirectorySecurityAsync(\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions = {},\n): Promise<WindowsDirectorySecurity | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst owner = currentReadOwner.getStore()?.deref();\n\t\tconst signal = owner && options.signal ? AbortSignal.any([owner, options.signal]) : (owner ?? options.signal);\n\t\tif (signal?.aborted) return undefined;\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = options.identity ?? (await identityOfAsync(resolvedPath));\n\t\tif (identity === undefined || signal?.aborted || generation !== stateGeneration) return undefined;\n\t\tconst key = `${identity}\\0${resolvedPath}`;\n\t\tlet read = sharedReads.get(key);\n\t\tif (read === undefined) {\n\t\t\tread = new SharedSecurityRead(resolvedPath, key);\n\t\t\tsharedReads.set(key, read);\n\t\t}\n\t\treturn read.join(options.timeoutMs ?? READ_SECURITY_TIMEOUT_MS, signal, options.background ?? false);\n\t});\n}\n\nfunction parseSecurityOutput(stdout: string): WindowsDirectorySecurity | undefined {\n\tconst [currentSid, ownerSid, dacl, ...ruleLines] = stdout.split(\"\\n\").map((line) => line.trim());\n\tif (!currentSid || !ownerSid || dacl === undefined) {\n\t\treturn undefined;\n\t}\n\tconst accessRules: WindowsAccessRule[] = [];\n\tfor (const line of ruleLines) {\n\t\tif (line.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [type, sid] = line.split(\";\");\n\t\tif ((type !== \"Allow\" && type !== \"Deny\") || !sid) {\n\t\t\treturn undefined;\n\t\t}\n\t\taccessRules.push({ allow: type === \"Allow\", sid });\n\t}\n\treturn { currentSid, ownerSid, dacl, accessRules };\n}\n\ntype SecurityReader = (\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions,\n) => WindowsDirectorySecurity | undefined | Promise<WindowsDirectorySecurity | undefined>;\n\nlet securityReader: SecurityReader = readWindowsDirectorySecurityAsync;\n\nlet stateGeneration = 0;\n\n/**\n * Verified paths mapped to the identity of the directory verified there: its volume, file ID and creation time. A\n * directory recreated at the path is a new file with a new ID; the creation time alone would not tell, since NTFS gives\n * a name recreated within seconds of its deletion the old creation time back (\"tunneling\").\n */\nconst verifiedPaths = new Map<string, string>();\n\n/** The identity of the directory at `path`, or `undefined` when it cannot be read. */\nfunction identityOf(path: string): string | undefined {\n\ttry {\n\t\tconst stat = statSync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function identityOfAsync(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst stat = await statAsync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** True when `path` was verified in this process and is still the directory verified there. */\nfunction stillVerified(path: string, identity: string | undefined): boolean {\n\treturn identity !== undefined && verifiedPaths.get(path) === identity;\n}\n\nfunction verifiedWithoutReading(path: string, identity: string): boolean {\n\tif (stillVerified(path, identity)) {\n\t\treturn true;\n\t}\n\tconst parent = dirname(path);\n\tif (parent !== path && stillVerified(parent, identityOf(parent))) {\n\t\tverifiedPaths.set(path, identity);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Verify `path` as adoptable, returning the refusal reason when it is not.\n *\n * The descriptor is read natively, with an asynchronous PowerShell fallback, once per private root per process:\n *\n * - A directory verified in this process is trusted for the rest of it while it is the same directory (same file ID and\n * creation time). Only its owner or an administrator can change its DACL (the verified DACL grants nobody else that\n * right), and both can already reach everything below it, so an in-place edit by one of them is not read again. A\n * directory swapped underneath the path is a new file and is read again, and so is one swapped while it was read.\n * - A directory inside a verified one needs no read of its own. The verified DACL lets only trusted principals create\n * entries in it, and grants nobody else access through inheritance either, since an inheritable entry for another\n * account refuses the parent itself; so a directory inside it was made by a trusted principal and starts private.\n *\n * The symlink/directory checks in `session-temp-dir.ts` still run on every use. A failure is never cached, so a\n * transient read error does not permanently disable spills.\n */\nexport function verifyWindowsDirectorySecurityAsync(\n\tpath: string,\n\tsignal?: AbortSignal,\n\toptions: { background?: boolean } = {},\n): Promise<string | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = await identityOfAsync(resolvedPath);\n\t\tif (identity === undefined || generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (stillVerified(resolvedPath, identity)) return undefined;\n\t\tconst parent = dirname(resolvedPath);\n\t\tconst inherited = parent !== resolvedPath && stillVerified(parent, await identityOfAsync(parent));\n\t\tif (generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (!inherited) {\n\t\t\tconst security = await securityReader(resolvedPath, { signal, background: options.background, identity });\n\t\t\tif (security === undefined) return \"its ownership could not be verified\";\n\t\t\tconst refusal = evaluateWindowsDirectorySecurity(security);\n\t\t\tif (generation !== stateGeneration) return refusal ?? \"its ownership could not be verified\";\n\t\t\tif (refusal !== undefined) {\n\t\t\t\tif (verifiedPaths.get(resolvedPath) === identity) verifiedPaths.delete(resolvedPath);\n\t\t\t\treturn refusal;\n\t\t\t}\n\t\t}\n\t\tif ((await identityOfAsync(resolvedPath)) !== identity || generation !== stateGeneration)\n\t\t\treturn \"its ownership could not be verified\";\n\t\tverifiedPaths.set(resolvedPath, identity);\n\t\treturn undefined;\n\t});\n}\n\nexport function verifyWindowsDirectorySecurity(\n\tpath: string,\n\toptions: { startVerification?: boolean } = {},\n): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tconst identity = identityOf(resolvedPath);\n\tif (identity === undefined) {\n\t\treturn \"its ownership could not be verified\";\n\t}\n\tif (verifiedWithoutReading(resolvedPath, identity)) {\n\t\treturn undefined;\n\t}\n\tif (options.startVerification !== false) {\n\t\tverifyWindowsDirectorySecurityAsync(resolvedPath, undefined, { background: true }).catch(() => undefined);\n\t}\n\treturn VERIFICATION_PENDING_REASON;\n}\n\nexport async function waitForWindowsDirectorySecurityReadsForTesting(): Promise<void> {\n\twhile (activeReads.size || sharedReads.size || closingReads.size) {\n\t\tawait Promise.all([...activeReads, ...[...sharedReads.values(), ...closingReads].map((read) => read.result)]);\n\t}\n}\n\n/** Test seam: substitute the descriptor reader; pass `undefined` to restore. */\nexport function setWindowsDirectorySecurityReaderForTesting(reader: SecurityReader | undefined): void {\n\tsecurityReader = reader ?? readWindowsDirectorySecurityAsync;\n}\n\n/** Test seam: forget verified paths and cancel reads in flight so a suite can re-drive verification. */\nexport function resetWindowsDirectorySecurityStateForTesting(): void {\n\tstateGeneration += 1;\n\tverifiedPaths.clear();\n\tfor (const read of [...sharedReads.values()]) read.cancel();\n\tsharedReads.clear();\n\tlastReadFailure = undefined;\n\tsecurityReader = readWindowsDirectorySecurityAsync;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"windows-directory-security.js","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AA4B/C;;;;;;;;;;;GAWG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS;IAC3C,UAAU,EAAE,eAAe;IAC3B,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE,gBAAgB;IAC3B,S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AQ,CAAC,EAAE,CAAC;QACpD,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,iBAAiB,KAAK,KAAK,EAAE,CAAC;QACzC,mCAAmC,CAAC,YAAY,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,2BAA2B,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8CAA8C;IACnE,OAAO,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;QAClE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/G,CAAC;AACF,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2CAA2C,CAAC,MAAkC;IAC7F,cAAc,GAAG,MAAM,IAAI,iCAAiC,CAAC;AAC9D,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,4CAA4C;IAC3D,eAAe,IAAI,CAAC,CAAC;IACrB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5D,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,eAAe,GAAG,SAAS,CAAC;IAC5B,cAAc,GAAG,iCAAiC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Windows owner-SID and DACL verification for the session temp tree.\n *\n * POSIX proves ownership of an existing temp component with a uid comparison\n * and a mode check. Node exposes neither on Windows — `lstatSync` reports\n * uid/gid 0 — so this module reads the real security descriptor and decides\n * from SIDs alone: the owner must\n * be a trusted principal and every access-allowed ACE must grant only trusted\n * principals. Names are never compared; two accounts can share a display name,\n * but never a SID.\n *\n * The native module reads the descriptor directly. When that binding is\n * unavailable or cannot read the directory, an asynchronous PowerShell\n * subprocess reads it instead. Reads start after the synchronous caller\n * returns, so a synchronous check never reads the descriptor. A successful\n * verification is cached for the life of the process, keyed to the\n * directory's path and identity (its file ID and creation time),\n * and a directory inside a verified one needs no read of its own (see\n * `verifyWindowsDirectorySecurityAsync`). A directory swapped underneath the\n * path is a new file with a new ID and is read again.\n * Failures are not cached: a refusal means \"no spill file this time\", and a\n * transient read failure must not disable persistence for the rest of the\n * process.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { statSync } from \"node:fs\";\nimport { stat as statAsync } from \"node:fs/promises\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { clearTimeout, setTimeout } from \"node:timers\";\nimport { createModuleRequire } from \"../../utils/module-require.js\";\nimport { windowsPowerShellEnvironment } from \"../../utils/windows-powershell.ts\";\nimport { asyncScope } from \"../async-scope.ts\";\n\n/** One DACL entry with its trustee resolved to a literal SID. */\nexport interface WindowsAccessRule {\n\t/** True for an access-allowed entry, false for access-denied. */\n\tallow: boolean;\n\t/** The SID the entry applies to. */\n\tsid: string;\n}\n\n/** What the security read produces: the caller's SID plus the descriptor. */\nexport interface WindowsDirectorySecurity {\n\t/** SID of the current process token's user. */\n\tcurrentSid: string;\n\t/** SID owning the directory. */\n\townerSid: string;\n\t/** The DACL portion of the descriptor in SDDL form (may be empty). */\n\tdacl: string;\n\t/**\n\t * Every DACL entry with its trustee as a literal SID (`GetAccessRules`\n\t * resolves domain-relative SDDL abbreviations such as `LA` that a\n\t * name-side parse cannot). The SDDL string above cross-checks that these\n\t * rules describe the whole DACL: only plain allow/deny ACE types, one\n\t * rule per ACE.\n\t */\n\taccessRules: readonly WindowsAccessRule[];\n}\n\n/**\n * Principals allowed to own, or hold access-allowed ACEs on, a temp component.\n *\n * SYSTEM and Administrators hold both on any per-user Windows temp directory\n * by inheritance, and both can reach any file on the volume regardless, so\n * permitting them grants nothing an attacker did not already have. Elevated\n * processes also create directories owned by the Administrators group rather\n * than the user, which is why the owner check shares this set. CREATOR OWNER\n * is inherit-only plumbing: it materializes as the creating account on\n * descendants, and creation inside the tree is already restricted to the\n * SIDs allowed here.\n */\nconst TRUSTED_STATIC_SIDS = new Set<string>([\n\t\"S-1-5-18\", // Local System\n\t\"S-1-5-32-544\", // Builtin Administrators\n\t\"S-1-3-0\", // Creator Owner\n\t\"S-1-3-4\", // Owner Rights\n]);\n\n/**\n * Decide whether a directory's descriptor is safe to adopt.\n *\n * Returns a refusal reason, or `undefined` when the directory is owned by a\n * trusted principal and its DACL grants access to trusted principals only.\n * Exported as a pure function so the decision table is testable on any host.\n */\nexport function evaluateWindowsDirectorySecurity(security: WindowsDirectorySecurity): string | undefined {\n\tconst trusted = (sid: string): boolean => sid === security.currentSid || TRUSTED_STATIC_SIDS.has(sid);\n\tif (!security.ownerSid.startsWith(\"S-1-\")) {\n\t\treturn \"its owner could not be verified\";\n\t}\n\tif (!trusted(security.ownerSid)) {\n\t\treturn \"it is owned by another account\";\n\t}\n\t// `Get-Acl` renders a null DACL (everyone has full control) as an absent\n\t// `D:` section; an empty DACL (`D:` with no ACEs) grants nobody anything\n\t// and is fine.\n\tconst dacl = security.dacl.trim();\n\tif (!dacl.startsWith(\"D:\")) {\n\t\treturn \"it has no access control list\";\n\t}\n\tlet rest = dacl.slice(2);\n\tconst flagsEnd = rest.indexOf(\"(\");\n\tconst flags = flagsEnd === -1 ? rest : rest.slice(0, flagsEnd);\n\tif (!/^[A-Z]*$/.test(flags)) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\trest = flagsEnd === -1 ? \"\" : rest.slice(flagsEnd);\n\tconst aces = rest.match(/\\([^()]*\\)/g) ?? [];\n\tif (aces.join(\"\") !== rest) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\tfor (const ace of aces) {\n\t\tconst type = ace.slice(1, -1).split(\";\")[0];\n\t\tif (type !== \"A\" && type !== \"D\") {\n\t\t\t// Conditional, object, and callback ACEs are not modeled by the\n\t\t\t// resolved access rules below, so a DACL containing one cannot be\n\t\t\t// proven restrictive.\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t}\n\tif (security.accessRules.length !== aces.length) {\n\t\t// The resolved rules must describe the whole DACL; a mismatch means\n\t\t// part of it was not translated and cannot be checked.\n\t\treturn \"its access control list could not be verified\";\n\t}\n\tfor (const rule of security.accessRules) {\n\t\tif (!rule.allow) {\n\t\t\tcontinue; // A deny entry only ever removes access.\n\t\t}\n\t\tif (!rule.sid.startsWith(\"S-1-\")) {\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t\tif (!trusted(rule.sid)) {\n\t\t\treturn \"it grants access to another account\";\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * One PowerShell round trip: the caller's SID, the owner SID, the DACL in\n * SDDL form, and one `Allow|Deny;SID` line per resolved access rule. The path\n * travels through the environment rather than the command line so no quoting\n * rules apply to it.\n */\nconst READ_SECURITY_SCRIPT = [\n\t\"$ErrorActionPreference = 'Stop'\",\n\t\"$acl = Get-Acl -LiteralPath $env:ATOMIC_SECURITY_QUERY_PATH\",\n\t\"$owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value\",\n\t\"$dacl = $acl.GetSecurityDescriptorSddlForm('Access')\",\n\t\"$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value\",\n\t\"$lines = @($user, $owner, $dacl)\",\n\t\"foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))\" +\n\t\t' { $lines += \"$($rule.AccessControlType);$($rule.IdentityReference.Value)\" }',\n\t'[Console]::Out.Write(($lines -join \"`n\"))',\n].join(\"; \");\n\n/** Bounded wait for the security read; a wedged subprocess must not hang a spill. */\nconst READ_SECURITY_TIMEOUT_MS = 30_000;\n\nexport const VERIFICATION_PENDING_REASON = \"its ownership is still being verified\";\n\n/** PowerShell hosts to try, most specific first: an absolute Windows\n * PowerShell path immune to a stripped `PATH`, then whichever of\n * `powershell.exe`/`pwsh.exe` the environment resolves. */\nexport function powershellCandidates(): string[] {\n\tconst candidates: string[] = [];\n\tcandidates.push(`${windowsDirectory()}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tcandidates.push(\"powershell.exe\", \"pwsh.exe\");\n\treturn candidates;\n}\n\n/** The environment for a PowerShell read: Windows PowerShell's, plus the path the read is for. */\nfunction powershellEnvironment(path: string): NodeJS.ProcessEnv {\n\treturn { ...windowsPowerShellEnvironment(), ATOMIC_SECURITY_QUERY_PATH: path };\n}\n\nfunction windowsDirectory(): string {\n\treturn process.env.SystemRoot ?? process.env.windir ?? \"C:\\\\Windows\";\n}\n\nasync function neutralWorkingDirectory(): Promise<string | undefined> {\n\ttry {\n\t\treturn (await statAsync(windowsDirectory())).isDirectory() ? windowsDirectory() : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet lastReadFailure: string | undefined;\n\n/** Test seam: why the most recent descriptor read returned `undefined`. */\nexport function getLastWindowsSecurityReadFailureForTesting(): string | undefined {\n\treturn lastReadFailure;\n}\n\ntype NativeSecurityReader = (path: string) => Promise<WindowsDirectorySecurity | null | undefined>;\n\nlet nativeReader: NativeSecurityReader | null | undefined;\n\nfunction nativeSecurityReader(): NativeSecurityReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\twindowsDirectorySecurityAsync?: NativeSecurityReader;\n\t\t\t};\n\t\t\tnativeReader = binding.windowsDirectorySecurityAsync ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nasync function readNatively(path: string): Promise<WindowsDirectorySecurity | null> {\n\tconst native = nativeSecurityReader();\n\tif (native === null) {\n\t\treturn null;\n\t}\n\ttry {\n\t\treturn (await native(path)) ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport interface ReadWindowsDirectorySecurityOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tbackground?: boolean;\n\tidentity?: string;\n}\n\ntype SecurityAttempt = { security: WindowsDirectorySecurity } | { failure: string };\n\ntype ChildStream = (Readable & Partial<Pick<Socket, \"ref\" | \"unref\">>) | null;\n\nconst outsideAnyCaller = AsyncLocalStorage.snapshot();\n\nconst sharedReads = new Map<string, SharedSecurityRead>();\nconst currentReadOwner = asyncScope<WeakRef<AbortSignal>>();\nconst ownedReads = new WeakMap<AbortSignal, Set<Promise<void>>>();\nconst activeReads = new Set<Promise<void>>();\n\nexport function trackWindowsDirectorySecurityWork<T>(operation: () => Promise<T>): Promise<T> {\n\tconst owner = currentReadOwner.getStore()?.deref();\n\tconst result = operation();\n\tconst settled = result.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tactiveReads.add(settled);\n\tconst pending = owner ? (ownedReads.get(owner) ?? new Set<Promise<void>>()) : undefined;\n\tif (owner && pending) ownedReads.set(owner, pending);\n\tpending?.add(settled);\n\tvoid settled.then(() => {\n\t\tactiveReads.delete(settled);\n\t\tpending?.delete(settled);\n\t});\n\treturn result;\n}\nconst closingReads = new Set<SharedSecurityRead>();\n\nexport function withWindowsDirectorySecurityOwner<T>(\n\tsignal: AbortSignal,\n\toperation: () => T,\n\toptions: { inherit?: boolean } = {},\n): T {\n\tconst inheritedOwner = options.inherit ? currentReadOwner.getStore()?.deref() : undefined;\n\treturn currentReadOwner.run(new WeakRef(inheritedOwner ?? signal), operation);\n}\n\nexport async function drainWindowsDirectorySecurityReads(signal: AbortSignal): Promise<void> {\n\tconst pending = ownedReads.get(signal);\n\twhile (pending?.size) await Promise.all(pending);\n}\n\nclass SharedSecurityRead {\n\treadonly result: Promise<WindowsDirectorySecurity | undefined>;\n\tprivate readonly controller = new AbortController();\n\tprivate waiters = 0;\n\tprivate foregroundWaiters = 0;\n\tprivate child: ChildProcess | undefined;\n\tprivate finished = false;\n\tprivate readonly path: string;\n\tprivate readonly key: string;\n\n\tconstructor(path: string, key: string) {\n\t\tthis.path = path;\n\t\tthis.key = key;\n\t\tthis.result = outsideAnyCaller(() => Promise.resolve().then(() => this.readCandidates())).finally(() => {\n\t\t\tif (sharedReads.get(key) === this) sharedReads.delete(key);\n\t\t\tthis.finished = true;\n\t\t\tclosingReads.delete(this);\n\t\t});\n\t}\n\n\tjoin(\n\t\ttimeoutMs: number,\n\t\tsignal: AbortSignal | undefined,\n\t\tbackground: boolean,\n\t): Promise<WindowsDirectorySecurity | undefined> {\n\t\tthis.waiters += 1;\n\t\tif (!background) this.foregroundWaiters += 1;\n\t\tthis.applyKeepAlive();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet left = false;\n\t\t\tconst leave = (security: WindowsDirectorySecurity | undefined) => {\n\t\t\t\tif (left) return;\n\t\t\t\tleft = true;\n\t\t\t\tclearTimeout(deadline);\n\t\t\t\tsignal?.removeEventListener(\"abort\", stopWaiting);\n\t\t\t\tthis.waiters -= 1;\n\t\t\t\tif (!background) this.foregroundWaiters -= 1;\n\t\t\t\tif (this.waiters === 0) {\n\t\t\t\t\tthis.cancel();\n\t\t\t\t\tvoid this.result.then(\n\t\t\t\t\t\t() => resolve(security),\n\t\t\t\t\t\t() => resolve(undefined),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.applyKeepAlive();\n\t\t\t\t\tresolve(security);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst stopWaiting = () => leave(undefined);\n\t\t\tconst deadline = setTimeout(stopWaiting, timeoutMs);\n\t\t\tif (background) deadline.unref();\n\t\t\tsignal?.addEventListener(\"abort\", stopWaiting, { once: true });\n\t\t\tvoid this.result.then(leave, () => leave(undefined));\n\t\t});\n\t}\n\n\tcancel(): void {\n\t\tif (sharedReads.get(this.key) === this) sharedReads.delete(this.key);\n\t\tif (!this.finished) closingReads.add(this);\n\t\tthis.controller.abort();\n\t}\n\n\tprivate async readCandidates(): Promise<WindowsDirectorySecurity | undefined> {\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tlastReadFailure = undefined;\n\t\tconst security = await readNatively(this.path);\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tif (security !== null) return security;\n\t\tconst failures: string[] = [];\n\t\tfor (const executable of powershellCandidates()) {\n\t\t\tif (this.controller.signal.aborted) break;\n\t\t\tconst attempt = await this.readWith(executable);\n\t\t\tif (\"security\" in attempt) return attempt.security;\n\t\t\tfailures.push(attempt.failure);\n\t\t}\n\t\tlastReadFailure = failures.join(\" | \");\n\t\treturn undefined;\n\t}\n\n\tprivate async readWith(executable: string): Promise<SecurityAttempt> {\n\t\tconst cwd = await neutralWorkingDirectory();\n\t\tif (this.controller.signal.aborted) return { failure: `${executable}: aborted` };\n\t\treturn new Promise((resolve) => {\n\t\t\tlet child: ChildProcess;\n\t\t\ttry {\n\t\t\t\tchild = spawn(executable, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", READ_SECURITY_SCRIPT], {\n\t\t\t\t\tcwd,\n\t\t\t\t\tenv: powershellEnvironment(this.path),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresolve({ failure: `${executable}: error=${error instanceof Error ? error.message : String(error)}` });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.child = child;\n\t\t\tthis.applyKeepAlive();\n\t\t\tconst stdout: Buffer[] = [];\n\t\t\tconst stderr: Buffer[] = [];\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\t\tlet settled = false;\n\t\t\tconst settle = (attempt: SecurityAttempt) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.child = undefined;\n\t\t\t\tthis.controller.signal.removeEventListener(\"abort\", stop);\n\t\t\t\tresolve(attempt);\n\t\t\t};\n\t\t\tlet failure: string | undefined;\n\t\t\tlet stopping = false;\n\t\t\tconst stop = () => {\n\t\t\t\tfailure ??= `${executable}: aborted`;\n\t\t\t\tif (stopping) return;\n\t\t\t\tstopping = true;\n\t\t\t\tchild.ref();\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t};\n\t\t\tthis.controller.signal.addEventListener(\"abort\", stop, { once: true });\n\t\t\tconst fail = (error: Error) => {\n\t\t\t\tfailure ??= `${executable}: error=${error.message}`;\n\t\t\t\tstop();\n\t\t\t};\n\t\t\tchild.on(\"error\", fail);\n\t\t\tchild.stdout?.on(\"error\", fail);\n\t\t\tchild.stderr?.on(\"error\", fail);\n\t\t\tchild.once(\"close\", (status, signal) => {\n\t\t\t\tif (failure !== undefined) {\n\t\t\t\t\tsettle({ failure });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst output = Buffer.concat(stdout).toString(\"utf8\");\n\t\t\t\tif (status !== 0) {\n\t\t\t\t\tconst detail = Buffer.concat(stderr).toString(\"utf8\").trim().slice(0, 500);\n\t\t\t\t\tsettle({ failure: `${executable}: status=${status} signal=${signal} stderr=${detail}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst security = parseSecurityOutput(output);\n\t\t\t\tsettle(\n\t\t\t\t\tsecurity === undefined\n\t\t\t\t\t\t? { failure: `${executable}: unparseable output ${JSON.stringify(output.slice(0, 500))}` }\n\t\t\t\t\t\t: { security },\n\t\t\t\t);\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate applyKeepAlive(): void {\n\t\tconst child = this.child;\n\t\tif (child === undefined) return;\n\t\tconst keepAlive = this.foregroundWaiters > 0;\n\t\tif (keepAlive) child.ref();\n\t\telse child.unref();\n\t\tconst streams: ChildStream[] = [child.stdout, child.stderr];\n\t\tfor (const stream of streams) {\n\t\t\tif (keepAlive) stream?.ref?.();\n\t\t\telse stream?.unref?.();\n\t\t}\n\t}\n}\n\n/**\n * Read the security descriptor of `path` without blocking the main thread, or\n * `undefined` when it cannot be read (access denied, missing PowerShell, the\n * timeout, an aborted signal). Callers treat `undefined` as unverifiable and\n * refuse the directory.\n */\nexport function readWindowsDirectorySecurityAsync(\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions = {},\n): Promise<WindowsDirectorySecurity | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst owner = currentReadOwner.getStore()?.deref();\n\t\tconst signal = owner && options.signal ? AbortSignal.any([owner, options.signal]) : (owner ?? options.signal);\n\t\tif (signal?.aborted) return undefined;\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = options.identity ?? (await identityOfAsync(resolvedPath));\n\t\tif (identity === undefined || signal?.aborted || generation !== stateGeneration) return undefined;\n\t\tconst key = `${identity}\\0${resolvedPath}`;\n\t\tlet read = sharedReads.get(key);\n\t\tif (read === undefined) {\n\t\t\tread = new SharedSecurityRead(resolvedPath, key);\n\t\t\tsharedReads.set(key, read);\n\t\t}\n\t\treturn read.join(options.timeoutMs ?? READ_SECURITY_TIMEOUT_MS, signal, options.background ?? false);\n\t});\n}\n\nfunction parseSecurityOutput(stdout: string): WindowsDirectorySecurity | undefined {\n\tconst [currentSid, ownerSid, dacl, ...ruleLines] = stdout.split(\"\\n\").map((line) => line.trim());\n\tif (!currentSid || !ownerSid || dacl === undefined) {\n\t\treturn undefined;\n\t}\n\tconst accessRules: WindowsAccessRule[] = [];\n\tfor (const line of ruleLines) {\n\t\tif (line.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [type, sid] = line.split(\";\");\n\t\tif ((type !== \"Allow\" && type !== \"Deny\") || !sid) {\n\t\t\treturn undefined;\n\t\t}\n\t\taccessRules.push({ allow: type === \"Allow\", sid });\n\t}\n\treturn { currentSid, ownerSid, dacl, accessRules };\n}\n\ntype SecurityReader = (\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions,\n) => WindowsDirectorySecurity | undefined | Promise<WindowsDirectorySecurity | undefined>;\n\nlet securityReader: SecurityReader = readWindowsDirectorySecurityAsync;\n\nlet stateGeneration = 0;\n\n/**\n * Verified paths mapped to the identity of the directory verified there: its volume, file ID and creation time. A\n * directory recreated at the path is a new file with a new ID; the creation time alone would not tell, since NTFS gives\n * a name recreated within seconds of its deletion the old creation time back (\"tunneling\").\n */\nconst verifiedPaths = new Map<string, string>();\n\n/** The identity of the directory at `path`, or `undefined` when it cannot be read. */\nfunction identityOf(path: string): string | undefined {\n\ttry {\n\t\tconst stat = statSync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function identityOfAsync(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst stat = await statAsync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** True when `path` was verified in this process and is still the directory verified there. */\nfunction stillVerified(path: string, identity: string | undefined): boolean {\n\treturn identity !== undefined && verifiedPaths.get(path) === identity;\n}\n\nfunction verifiedWithoutReading(path: string, identity: string): boolean {\n\tif (stillVerified(path, identity)) {\n\t\treturn true;\n\t}\n\tconst parent = dirname(path);\n\tif (parent !== path && stillVerified(parent, identityOf(parent))) {\n\t\tverifiedPaths.set(path, identity);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Verify `path` as adoptable, returning the refusal reason when it is not.\n *\n * The descriptor is read natively, with an asynchronous PowerShell fallback, once per private root per process:\n *\n * - A directory verified in this process is trusted for the rest of it while it is the same directory (same file ID and\n * creation time). Only its owner or an administrator can change its DACL (the verified DACL grants nobody else that\n * right), and both can already reach everything below it, so an in-place edit by one of them is not read again. A\n * directory swapped underneath the path is a new file and is read again, and so is one swapped while it was read.\n * - A directory inside a verified one needs no read of its own. The verified DACL lets only trusted principals create\n * entries in it, and grants nobody else access through inheritance either, since an inheritable entry for another\n * account refuses the parent itself; so a directory inside it was made by a trusted principal and starts private.\n *\n * The symlink/directory checks in `session-temp-dir.ts` still run on every use. A failure is never cached, so a\n * transient read error does not permanently disable spills.\n */\nexport function verifyWindowsDirectorySecurityAsync(\n\tpath: string,\n\tsignal?: AbortSignal,\n\toptions: { background?: boolean } = {},\n): Promise<string | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = await identityOfAsync(resolvedPath);\n\t\tif (identity === undefined || generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (stillVerified(resolvedPath, identity)) return undefined;\n\t\tconst parent = dirname(resolvedPath);\n\t\tconst inherited = parent !== resolvedPath && stillVerified(parent, await identityOfAsync(parent));\n\t\tif (generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (!inherited) {\n\t\t\tconst security = await securityReader(resolvedPath, { signal, background: options.background, identity });\n\t\t\tif (security === undefined) return \"its ownership could not be verified\";\n\t\t\tconst refusal = evaluateWindowsDirectorySecurity(security);\n\t\t\tif (generation !== stateGeneration) return refusal ?? \"its ownership could not be verified\";\n\t\t\tif (refusal !== undefined) {\n\t\t\t\tif (verifiedPaths.get(resolvedPath) === identity) verifiedPaths.delete(resolvedPath);\n\t\t\t\treturn refusal;\n\t\t\t}\n\t\t}\n\t\tif ((await identityOfAsync(resolvedPath)) !== identity || generation !== stateGeneration)\n\t\t\treturn \"its ownership could not be verified\";\n\t\tverifiedPaths.set(resolvedPath, identity);\n\t\treturn undefined;\n\t});\n}\n\nexport function verifyWindowsDirectorySecurity(\n\tpath: string,\n\toptions: { startVerification?: boolean } = {},\n): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tconst identity = identityOf(resolvedPath);\n\tif (identity === undefined) {\n\t\treturn \"its ownership could not be verified\";\n\t}\n\tif (verifiedWithoutReading(resolvedPath, identity)) {\n\t\treturn undefined;\n\t}\n\tif (options.startVerification !== false) {\n\t\tverifyWindowsDirectorySecurityAsync(resolvedPath, undefined, { background: true }).catch(() => undefined);\n\t}\n\treturn VERIFICATION_PENDING_REASON;\n}\n\nexport async function waitForWindowsDirectorySecurityReadsForTesting(): Promise<void> {\n\twhile (activeReads.size || sharedReads.size || closingReads.size) {\n\t\tawait Promise.all([...activeReads, ...[...sharedReads.values(), ...closingReads].map((read) => read.result)]);\n\t}\n}\n\n/** Test seam: substitute the descriptor reader; pass `undefined` to restore. */\nexport function setWindowsDirectorySecurityReaderForTesting(reader: SecurityReader | undefined): void {\n\tsecurityReader = reader ?? readWindowsDirectorySecurityAsync;\n}\n\n/** Test seam: forget verified paths and cancel reads in flight so a suite can re-drive verification. */\nexport function resetWindowsDirectorySecurityStateForTesting(): void {\n\tstateGeneration += 1;\n\tverifiedPaths.clear();\n\tfor (const read of [...sharedReads.values()]) read.cancel();\n\tsharedReads.clear();\n\tlastReadFailure = undefined;\n\tsecurityReader = readWindowsDirectorySecurityAsync;\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
import { spawn } from "node:child_process";
|
|
3
2
|
import { constants } from "node:fs";
|
|
4
3
|
import { access, stat } from "node:fs/promises";
|
|
@@ -10,6 +9,7 @@ import { createGitEnvironment } from "../../utils/git-env.js";
|
|
|
10
9
|
import { isGitProvisionError } from "../../utils/git-errors.js";
|
|
11
10
|
import { spawnHostProcess } from "../../utils/host-spawn.js";
|
|
12
11
|
import { pathExists } from "../../utils/path-exists.js";
|
|
12
|
+
import { asyncScope } from "../async-scope.js";
|
|
13
13
|
import { redactUrlCredentials } from "../error-contract.js";
|
|
14
14
|
import { containProcessTree } from "../process-tree-containment.js";
|
|
15
15
|
import { GitUnavailableError, gitInstallCommand, isGitUnavailableError, WorkspaceGitError, WorkspaceSnapshotError, } from "./errors.js";
|
|
@@ -21,7 +21,7 @@ const provisionedGit = async (signal) => {
|
|
|
21
21
|
};
|
|
22
22
|
let resolveExecutable = provisionedGit;
|
|
23
23
|
/** The Git every snapshot command of one scope runs instead of the resolver's, such as one restore's. */
|
|
24
|
-
const scopedExecutable =
|
|
24
|
+
const scopedExecutable = asyncScope();
|
|
25
25
|
/**
|
|
26
26
|
* Runs `action` with every snapshot Git command it starts on `executable`, which no resolver is asked for; other
|
|
27
27
|
* operations of this process keep theirs. Undefined: `action` runs as it would without this call.
|