@bastani/atomic 0.9.74-alpha.1 → 0.9.75-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 +94 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/agent-browser/SKILL.md +8 -10
- package/dist/builtin/subagents/skills/agent-desktop/SKILL.md +9 -5
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -1
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +48 -0
- package/dist/builtin/workflows/README.md +5 -2
- package/dist/builtin/workflows/builtin/{chunk-m8eg152f.js → chunk-89we7r4p.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-a4fdm2cw.js → chunk-8yfssw01.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-774myqzs.js → chunk-v8mb0005.js} +366 -45
- package/dist/builtin/workflows/builtin/{chunk-d5cxskkp.js → chunk-wh2p4qjg.js} +2 -2
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.d.ts +10 -0
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +12 -0
- package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +3 -2
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +19 -0
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +15 -8
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +2 -0
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +8 -6
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +0 -1
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/engine-checksums.txt +9 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +98 -44
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +101 -34
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +6 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +4 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +444 -144
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +3 -1
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +13 -11
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +10 -8
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_2.md +143 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_haiku_5_5.md +11 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +6 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +7 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5_5.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +6 -5
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_sol.md +4 -4
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_terra.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -3
- package/dist/builtin/workflows/skills/skill-creator/scripts/aggregate_benchmark.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/generate_report.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/improve_description.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/package_skill.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/quick_validate.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_loop.py +0 -0
- package/dist/builtin/workflows/skills/unslop/SKILL.md +15 -34
- package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +1 -0
- package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +809 -410
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/index.js +685 -295
- package/dist/builtin/workflows/src/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +6 -6
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +2 -2
- package/dist/builtin/workflows/src/shared/serializable-error-families.d.ts +2 -0
- package/dist/bun/app-host-modules.d.ts +1 -1
- package/dist/bun/app-host-modules.d.ts.map +1 -1
- package/dist/bun/app-host-modules.js.map +1 -1
- package/dist/bun/internal-workflow-worker.d.ts +2 -0
- package/dist/bun/internal-workflow-worker.d.ts.map +1 -1
- package/dist/bun/internal-workflow-worker.js +2 -1
- package/dist/bun/internal-workflow-worker.js.map +1 -1
- package/dist/codemode-worker.js +2 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +2 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-blueprint-environment.d.ts +10 -0
- package/dist/core/agent-session-blueprint-environment.d.ts.map +1 -0
- package/dist/core/agent-session-blueprint-environment.js +28 -0
- package/dist/core/agent-session-blueprint-environment.js.map +1 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +2 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +1 -0
- 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-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +14 -4
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +20 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +55 -6
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +2 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/async-scope.d.ts +13 -0
- package/dist/core/async-scope.d.ts.map +1 -0
- package/dist/core/async-scope.js +20 -0
- package/dist/core/async-scope.js.map +1 -0
- package/dist/core/cache-warmer.d.ts +3 -14
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +8 -60
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/extensions/extension-work.js +2 -2
- package/dist/core/extensions/extension-work.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +3 -1
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +2 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +1 -1
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +4 -2
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts +6 -0
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +10 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/preferred-providers.d.ts +19 -0
- package/dist/core/preferred-providers.d.ts.map +1 -0
- package/dist/core/preferred-providers.js +25 -0
- package/dist/core/preferred-providers.js.map +1 -0
- package/dist/core/provider-alias.d.ts.map +1 -1
- package/dist/core/provider-alias.js +4 -0
- package/dist/core/provider-alias.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +1 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +3 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resume/blueprint/action-expressions.d.ts +32 -0
- package/dist/core/resume/blueprint/action-expressions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/action-expressions.js +389 -0
- package/dist/core/resume/blueprint/action-expressions.js.map +1 -0
- package/dist/core/resume/blueprint/actions.d.ts +90 -0
- package/dist/core/resume/blueprint/actions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/actions.js +818 -0
- package/dist/core/resume/blueprint/actions.js.map +1 -0
- package/dist/core/resume/blueprint/build.d.ts +102 -0
- package/dist/core/resume/blueprint/build.d.ts.map +1 -0
- package/dist/core/resume/blueprint/build.js +535 -0
- package/dist/core/resume/blueprint/build.js.map +1 -0
- package/dist/core/resume/blueprint/context.d.ts +11 -0
- package/dist/core/resume/blueprint/context.d.ts.map +1 -0
- package/dist/core/resume/blueprint/context.js +106 -0
- package/dist/core/resume/blueprint/context.js.map +1 -0
- package/dist/core/resume/blueprint/envrc.d.ts +19 -0
- package/dist/core/resume/blueprint/envrc.d.ts.map +1 -0
- package/dist/core/resume/blueprint/envrc.js +77 -0
- package/dist/core/resume/blueprint/envrc.js.map +1 -0
- package/dist/core/resume/blueprint/errors.d.ts +179 -0
- package/dist/core/resume/blueprint/errors.d.ts.map +1 -0
- package/dist/core/resume/blueprint/errors.js +169 -0
- package/dist/core/resume/blueprint/errors.js.map +1 -0
- package/dist/core/resume/blueprint/ledger.d.ts +51 -0
- package/dist/core/resume/blueprint/ledger.d.ts.map +1 -0
- package/dist/core/resume/blueprint/ledger.js +119 -0
- package/dist/core/resume/blueprint/ledger.js.map +1 -0
- package/dist/core/resume/blueprint/notices.d.ts +14 -0
- package/dist/core/resume/blueprint/notices.d.ts.map +1 -0
- package/dist/core/resume/blueprint/notices.js +44 -0
- package/dist/core/resume/blueprint/notices.js.map +1 -0
- package/dist/core/resume/blueprint/process.d.ts +44 -0
- package/dist/core/resume/blueprint/process.d.ts.map +1 -0
- package/dist/core/resume/blueprint/process.js +142 -0
- package/dist/core/resume/blueprint/process.js.map +1 -0
- package/dist/core/resume/blueprint/resume.d.ts +73 -0
- package/dist/core/resume/blueprint/resume.d.ts.map +1 -0
- package/dist/core/resume/blueprint/resume.js +206 -0
- package/dist/core/resume/blueprint/resume.js.map +1 -0
- package/dist/core/resume/blueprint/schema.d.ts +26 -0
- package/dist/core/resume/blueprint/schema.d.ts.map +1 -0
- package/dist/core/resume/blueprint/schema.js +243 -0
- package/dist/core/resume/blueprint/schema.js.map +1 -0
- package/dist/core/resume/blueprint/steps.d.ts +54 -0
- package/dist/core/resume/blueprint/steps.d.ts.map +1 -0
- package/dist/core/resume/blueprint/steps.js +155 -0
- package/dist/core/resume/blueprint/steps.js.map +1 -0
- package/dist/core/resume/blueprint/types.d.ts +63 -0
- package/dist/core/resume/blueprint/types.d.ts.map +1 -0
- package/dist/core/resume/blueprint/types.js +2 -0
- package/dist/core/resume/blueprint/types.js.map +1 -0
- package/dist/core/resume/errors.d.ts +7 -35
- package/dist/core/resume/errors.d.ts.map +1 -1
- package/dist/core/resume/errors.js +1 -21
- package/dist/core/resume/errors.js.map +1 -1
- package/dist/core/resume/index.d.ts +12 -4
- package/dist/core/resume/index.d.ts.map +1 -1
- package/dist/core/resume/index.js +11 -4
- package/dist/core/resume/index.js.map +1 -1
- package/dist/core/resume/run-setup.d.ts +36 -15
- package/dist/core/resume/run-setup.d.ts.map +1 -1
- package/dist/core/resume/run-setup.js +70 -54
- package/dist/core/resume/run-setup.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +34 -20
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +244 -106
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/retry-policy.d.ts +19 -1
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +26 -1
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +56 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +94 -4
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +10 -5
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-worktree-snapshots.d.ts +11 -0
- package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
- package/dist/core/session-worktree-snapshots.js +10 -4
- package/dist/core/session-worktree-snapshots.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +1 -1
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +1 -1
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +3 -2
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +2 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/storage/write-ahead-log.d.ts +2 -1
- package/dist/core/storage/write-ahead-log.d.ts.map +1 -1
- package/dist/core/storage/write-ahead-log.js +27 -6
- package/dist/core/storage/write-ahead-log.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/file-tool-errors.d.ts +1 -1
- package/dist/core/tools/file-tool-errors.js +1 -1
- package/dist/core/tools/file-tool-errors.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +52 -26
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +10 -2
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/tool-concurrency.d.ts.map +1 -1
- package/dist/core/tools/tool-concurrency.js +2 -2
- package/dist/core/tools/tool-concurrency.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts +12 -4
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +28 -4
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +5 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +6 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +34 -13
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/provider-brand.d.ts +16 -0
- package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -0
- package/dist/modes/interactive/components/provider-brand.js +67 -0
- package/dist/modes/interactive/components/provider-brand.js.map +1 -0
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +8 -6
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js +4 -3
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +8 -3
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -2
- 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-session-routing.js +59 -21
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +23 -12
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/login-provider-options.d.ts.map +1 -1
- package/dist/modes/interactive/login-provider-options.js +2 -1
- package/dist/modes/interactive/login-provider-options.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +2 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +8 -3
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -1
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +0 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +2 -18
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +8 -2
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-error-decoding.d.ts +7 -0
- package/dist/modes/rpc/rpc-error-decoding.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-error-decoding.js +25 -0
- package/dist/modes/rpc/rpc-error-decoding.js.map +1 -0
- package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-responses.js +12 -0
- package/dist/modes/rpc/rpc-responses.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +11 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +12 -3
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/codemode.md +22 -0
- package/docs/extensions/api-reference.md +27 -1
- package/docs/extensions/authoring.md +1 -1
- package/docs/extensions/ui.md +1 -1
- package/docs/getting-started/first-session.md +1 -1
- package/docs/guides/resume-on-any-machine.md +72 -19
- package/docs/models/evals.md +85 -17
- package/docs/models/reference.md +1 -1
- package/docs/providers.md +38 -5
- package/docs/reference/cli.md +2 -0
- package/docs/rpc/protocol.md +11 -1
- package/docs/sdk/reference.md +36 -4
- package/docs/sdk.md +2 -2
- package/docs/sessions.md +11 -1
- package/docs/settings.md +7 -2
- package/docs/skills.md +3 -3
- package/docs/storage.md +1 -1
- package/docs/tools.md +3 -1
- package/docs/workflows/api-reference.md +14 -12
- package/docs/workflows/authoring.md +29 -1
- package/docs/workflows/builtins.md +9 -1
- package/docs/workflows/operations.md +8 -8
- package/docs/worktree-snapshots.md +3 -2
- package/npm-shrinkwrap.json +83 -67
- package/package.json +7 -7
- package/schemas/settings.schema.json +3 -2
- package/dist/core/resume/setup-hook.d.ts +0 -69
- package/dist/core/resume/setup-hook.d.ts.map +0 -1
- package/dist/core/resume/setup-hook.js +0 -261
- package/dist/core/resume/setup-hook.js.map +0 -1
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
-
import { mkdir, open, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
|
-
import { getShellConfig, killProcessTree } from "../../utils/shell.js";
|
|
7
|
-
import { computeEnvironmentHash, ENVIRONMENT_INPUT_FILES } from "../worktree-snapshot/env-hash.js";
|
|
8
|
-
import { ResumePreconditionError, ResumeSetupHookError, } from "./errors.js";
|
|
9
|
-
/** The repository-provided setup hook, relative to the worktree root. Runs only in a trusted project. */
|
|
10
|
-
export const RESUME_SETUP_HOOK_FILE = ".atomic/setup";
|
|
11
|
-
/** The setting that names a setup command, used when the repository provides no trusted hook. */
|
|
12
|
-
export const RESUME_SETUP_COMMAND_SETTING = "resume.setupCommand";
|
|
13
|
-
/** How long a setup hook may run before it is stopped and the resume fails. */
|
|
14
|
-
export const DEFAULT_RESUME_SETUP_TIMEOUT_MS = 15 * 60_000;
|
|
15
|
-
function ledgerPath(storeDir, worktree) {
|
|
16
|
-
const key = createHash("sha256").update(resolve(worktree)).digest("hex");
|
|
17
|
-
return join(storeDir, "setup-ledger", `${key}.json`);
|
|
18
|
-
}
|
|
19
|
-
/** The setup run recorded for `worktree`, if any. */
|
|
20
|
-
export async function readResumeSetupLedger(storeDir, worktree) {
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(await readFile(ledgerPath(storeDir, worktree), "utf8"));
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (error.code === "ENOENT")
|
|
26
|
-
return undefined;
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function writeLedger(storeDir, entry) {
|
|
31
|
-
const path = ledgerPath(storeDir, entry.worktree);
|
|
32
|
-
await mkdir(dirname(path), { recursive: true });
|
|
33
|
-
const temporary = `${path}.${process.pid}.tmp`;
|
|
34
|
-
await writeFile(temporary, `${JSON.stringify(entry, null, 2)}\n`, { mode: 0o600 });
|
|
35
|
-
await rename(temporary, path);
|
|
36
|
-
}
|
|
37
|
-
async function isFile(path) {
|
|
38
|
-
try {
|
|
39
|
-
return (await stat(path)).isFile();
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
const code = error.code;
|
|
43
|
-
if (code === "ENOENT" || code === "ENOTDIR")
|
|
44
|
-
return false;
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/** Whether `worktree` has any file that decides installed dependencies or toolchains. */
|
|
49
|
-
export async function hasEnvironmentInputs(worktree) {
|
|
50
|
-
for (const path of ENVIRONMENT_INPUT_FILES) {
|
|
51
|
-
if (await isFile(join(worktree, path)))
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
async function resolveHook(worktree, config) {
|
|
57
|
-
const file = join(worktree, RESUME_SETUP_HOOK_FILE);
|
|
58
|
-
const present = await isFile(file);
|
|
59
|
-
if (present && config.trusted(worktree))
|
|
60
|
-
return { kind: "file", name: RESUME_SETUP_HOOK_FILE, path: file };
|
|
61
|
-
const command = config.command?.trim();
|
|
62
|
-
if (command)
|
|
63
|
-
return { kind: "command", name: RESUME_SETUP_COMMAND_SETTING, command };
|
|
64
|
-
return present ? "untrusted" : undefined;
|
|
65
|
-
}
|
|
66
|
-
function missingHookError(options, untrusted) {
|
|
67
|
-
return new ResumePreconditionError({
|
|
68
|
-
entryPoint: options.entryPoint,
|
|
69
|
-
problems: [
|
|
70
|
-
{
|
|
71
|
-
code: "setup-hook-missing",
|
|
72
|
-
subject: untrusted ? `${RESUME_SETUP_HOOK_FILE} (untrusted project)` : "setup hook",
|
|
73
|
-
why: `the worktree restored at ${options.worktree} has dependency inputs (envHash ${options.envHash.slice(0, 12)}) that were never installed on this node, and ${untrusted
|
|
74
|
-
? `${RESUME_SETUP_HOOK_FILE} runs only in a trusted project`
|
|
75
|
-
: `neither ${RESUME_SETUP_HOOK_FILE} nor ${RESUME_SETUP_COMMAND_SETTING} is configured`}`,
|
|
76
|
-
fix: untrusted
|
|
77
|
-
? `Trust the project (start with --approve, or set "defaultProjectTrust": "always"), or set "${RESUME_SETUP_COMMAND_SETTING}" in ~/.atomic/agent/settings.json, then resume again.`
|
|
78
|
-
: `Add an executable ${RESUME_SETUP_HOOK_FILE} to the repository, or set "${RESUME_SETUP_COMMAND_SETTING}" (for example "npm ci") in ~/.atomic/agent/settings.json, then resume again.`,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
let noInputsHash;
|
|
84
|
-
/** The environment fingerprint of a checkout without any dependency input file. */
|
|
85
|
-
function noInputsEnvironmentHash() {
|
|
86
|
-
noInputsHash ??= computeEnvironmentHash(join(tmpdir(), `atomic-no-environment-inputs-${randomUUID()}`));
|
|
87
|
-
return noInputsHash;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* The `setup-hook-missing` problem that restoring a snapshot recorded with `envHash` would hit, when that is known
|
|
91
|
-
* before restoring: the snapshot has dependency inputs, no `resume.setupCommand` is configured, and a worktree restored
|
|
92
|
-
* under `prospectiveWorktree` would not be trusted to run the repository's `.atomic/setup`. Whether the repository has
|
|
93
|
-
* that file is only known after the restore.
|
|
94
|
-
*/
|
|
95
|
-
export async function predictedSetupProblem(envHash, prospectiveWorktree, config) {
|
|
96
|
-
if (config.command?.trim())
|
|
97
|
-
return undefined;
|
|
98
|
-
if (envHash === (await noInputsEnvironmentHash()))
|
|
99
|
-
return undefined;
|
|
100
|
-
if (config.trusted(prospectiveWorktree))
|
|
101
|
-
return undefined;
|
|
102
|
-
return {
|
|
103
|
-
code: "setup-hook-missing",
|
|
104
|
-
subject: "setup hook",
|
|
105
|
-
why: `the snapshot has dependency inputs (envHash ${envHash.slice(0, 12)}) that a restored worktree must install, no ${RESUME_SETUP_COMMAND_SETTING} is configured, and a restored worktree is not trusted to run ${RESUME_SETUP_HOOK_FILE}`,
|
|
106
|
-
fix: `Set "${RESUME_SETUP_COMMAND_SETTING}" (for example "npm ci") in ~/.atomic/agent/settings.json, or trust restored worktrees (start with --approve, or set "defaultProjectTrust": "always") so the repository's ${RESUME_SETUP_HOOK_FILE} can run, then resume again.`,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
async function runHook(hook, worktree, envHash, logPath, timeoutMs, signal) {
|
|
110
|
-
signal?.throwIfAborted();
|
|
111
|
-
await mkdir(dirname(logPath), { recursive: true });
|
|
112
|
-
const log = await open(logPath, "w", 0o600);
|
|
113
|
-
const startedAt = Date.now();
|
|
114
|
-
try {
|
|
115
|
-
return await new Promise((resolveExit, reject) => {
|
|
116
|
-
const child = spawnHook(hook, worktree, log.fd, hookEnv(worktree, envHash));
|
|
117
|
-
let timedOut = false;
|
|
118
|
-
const stop = () => {
|
|
119
|
-
if (child.pid !== undefined)
|
|
120
|
-
killProcessTree(child.pid);
|
|
121
|
-
};
|
|
122
|
-
const timer = setTimeout(() => {
|
|
123
|
-
timedOut = true;
|
|
124
|
-
stop();
|
|
125
|
-
}, timeoutMs);
|
|
126
|
-
const onAbort = () => stop();
|
|
127
|
-
const settle = () => {
|
|
128
|
-
clearTimeout(timer);
|
|
129
|
-
signal?.removeEventListener("abort", onAbort);
|
|
130
|
-
};
|
|
131
|
-
signal?.addEventListener("abort", onAbort);
|
|
132
|
-
child.once("error", (error) => {
|
|
133
|
-
settle();
|
|
134
|
-
reject(error);
|
|
135
|
-
});
|
|
136
|
-
child.once("close", (exitStatus, exitSignal) => {
|
|
137
|
-
settle();
|
|
138
|
-
if (signal?.aborted) {
|
|
139
|
-
reject(signal.reason);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
resolveExit({ exitStatus, signal: exitSignal, timedOut, elapsedMs: Date.now() - startedAt });
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
finally {
|
|
147
|
-
await log.close();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Starts `hook` in `worktree` in its own process group (POSIX), so stopping it stops everything it started: the
|
|
152
|
-
* repository's `.atomic/setup` through the configured shell (bash, or Git Bash on Windows, which runs a script by its
|
|
153
|
-
* shebang, or the legacy WSL launcher, which takes the command on stdin), and `resume.setupCommand` through the
|
|
154
|
-
* platform shell.
|
|
155
|
-
*/
|
|
156
|
-
function spawnHook(hook, worktree, logFd, env) {
|
|
157
|
-
const options = { cwd: worktree, detached: process.platform !== "win32", windowsHide: true, env };
|
|
158
|
-
if (hook.kind === "command")
|
|
159
|
-
return spawn(hook.command, { ...options, shell: true, stdio: ["ignore", logFd, logFd] });
|
|
160
|
-
const { shell, args, commandTransport } = getShellConfig();
|
|
161
|
-
const script = `./${RESUME_SETUP_HOOK_FILE}`;
|
|
162
|
-
if (commandTransport !== "stdin")
|
|
163
|
-
return spawn(shell, [...args, script], { ...options, stdio: ["ignore", logFd, logFd] });
|
|
164
|
-
const child = spawn(shell, args, { ...options, stdio: ["pipe", logFd, logFd] });
|
|
165
|
-
child.stdin?.end(script);
|
|
166
|
-
return child;
|
|
167
|
-
}
|
|
168
|
-
function hookEnv(worktree, envHash) {
|
|
169
|
-
return { ...process.env, ATOMIC_ENV_HASH: envHash, ATOMIC_RESUME_WORKTREE: worktree };
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* The hook a restored worktree needs before work continues in it, or undefined when it needs none: it has no
|
|
173
|
-
* dependency inputs, or the ledger has a successful run for the recorded `envHash`. Throws
|
|
174
|
-
* {@link ResumePreconditionError} (`setup-hook-missing`) when one is needed and none is available.
|
|
175
|
-
*/
|
|
176
|
-
async function neededHook(options) {
|
|
177
|
-
const worktree = resolve(options.worktree);
|
|
178
|
-
const ledger = await readResumeSetupLedger(options.storeDir, worktree);
|
|
179
|
-
if (ledger?.envHash === options.envHash && ledger.exitStatus === 0)
|
|
180
|
-
return undefined;
|
|
181
|
-
if (!(await hasEnvironmentInputs(worktree)))
|
|
182
|
-
return undefined;
|
|
183
|
-
const hook = await resolveHook(worktree, options.config);
|
|
184
|
-
if (hook === undefined || hook === "untrusted")
|
|
185
|
-
throw missingHookError(options, hook === "untrusted");
|
|
186
|
-
return hook;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Checks, before a restored worktree is recorded, that it has the setup hook it needs: throws
|
|
190
|
-
* {@link ResumePreconditionError} (`setup-hook-missing`) exactly when {@link ensureResumeSetup} would. When a hook
|
|
191
|
-
* will run, it is entered in the ledger as not run yet, so a hook that never finishes, because the process stopped or
|
|
192
|
-
* the resume was cancelled, runs again on the next resume.
|
|
193
|
-
*/
|
|
194
|
-
export async function reserveResumeSetup(options) {
|
|
195
|
-
const hook = await neededHook(options);
|
|
196
|
-
if (hook === undefined)
|
|
197
|
-
return;
|
|
198
|
-
await writeLedger(options.storeDir, {
|
|
199
|
-
worktree: resolve(options.worktree),
|
|
200
|
-
envHash: options.envHash,
|
|
201
|
-
hook: hook.name,
|
|
202
|
-
exitStatus: null,
|
|
203
|
-
signal: null,
|
|
204
|
-
ranAt: new Date().toISOString(),
|
|
205
|
-
logPath: "",
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Runs the setup hook a restored worktree needs before work continues in it, and records the result in the host's
|
|
210
|
-
* setup ledger. The hook is needed when the worktree has dependency inputs and the ledger has no successful run for
|
|
211
|
-
* the recorded `envHash`, so a worktree is set up once per environment. Throws {@link ResumePreconditionError}
|
|
212
|
-
* (`setup-hook-missing`) when no hook is available, and {@link ResumeSetupHookError} when it fails or times out.
|
|
213
|
-
*/
|
|
214
|
-
export async function ensureResumeSetup(options) {
|
|
215
|
-
const worktree = resolve(options.worktree);
|
|
216
|
-
const hook = await neededHook(options);
|
|
217
|
-
if (hook === undefined)
|
|
218
|
-
return { status: "not-needed" };
|
|
219
|
-
const timeoutMs = options.config.timeoutMs ?? DEFAULT_RESUME_SETUP_TIMEOUT_MS;
|
|
220
|
-
const logPath = join(options.storeDir, "setup-logs", `${createHash("sha256").update(worktree).digest("hex").slice(0, 12)}-${Date.now()}.log`);
|
|
221
|
-
let exit;
|
|
222
|
-
try {
|
|
223
|
-
exit = await runHook(hook, worktree, options.envHash, logPath, timeoutMs, options.signal);
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
if (options.signal?.aborted)
|
|
227
|
-
throw error;
|
|
228
|
-
throw new ResumeSetupHookError("setup-hook-failed", {
|
|
229
|
-
hook: hook.name,
|
|
230
|
-
worktree,
|
|
231
|
-
envHash: options.envHash,
|
|
232
|
-
exitStatus: null,
|
|
233
|
-
signal: null,
|
|
234
|
-
logPath,
|
|
235
|
-
timeoutMs,
|
|
236
|
-
elapsedMs: 0,
|
|
237
|
-
}, error);
|
|
238
|
-
}
|
|
239
|
-
await writeLedger(options.storeDir, {
|
|
240
|
-
worktree,
|
|
241
|
-
envHash: options.envHash,
|
|
242
|
-
hook: hook.name,
|
|
243
|
-
exitStatus: exit.exitStatus,
|
|
244
|
-
signal: exit.signal,
|
|
245
|
-
ranAt: new Date().toISOString(),
|
|
246
|
-
logPath,
|
|
247
|
-
});
|
|
248
|
-
if (!exit.timedOut && exit.exitStatus === 0)
|
|
249
|
-
return { status: "ran", hook: hook.name, logPath };
|
|
250
|
-
throw new ResumeSetupHookError(exit.timedOut ? "setup-hook-timed-out" : "setup-hook-failed", {
|
|
251
|
-
hook: hook.name,
|
|
252
|
-
worktree,
|
|
253
|
-
envHash: options.envHash,
|
|
254
|
-
exitStatus: exit.exitStatus,
|
|
255
|
-
signal: exit.signal,
|
|
256
|
-
logPath,
|
|
257
|
-
timeoutMs,
|
|
258
|
-
elapsedMs: exit.elapsedMs,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
//# sourceMappingURL=setup-hook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-hook.js","sourceRoot":"","sources":["../../../src/core/resume/setup-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,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AAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC/B,OAAO;KACP,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;IAChG,MAAM,IAAI,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,EAAE;QAC5F,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ;QACR,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,OAAO;QACP,SAAS;QACT,SAAS,EAAE,IAAI,CAAC,SAAS;KACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type ChildProcess, spawn } from \"node:child_process\";\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { mkdir, open, readFile, rename, stat, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { getShellConfig, killProcessTree } from \"../../utils/shell.ts\";\nimport { computeEnvironmentHash, ENVIRONMENT_INPUT_FILES } from \"../worktree-snapshot/env-hash.ts\";\nimport {\n\ttype ResumeEntryPoint,\n\tResumePreconditionError,\n\ttype ResumePreconditionProblem,\n\tResumeSetupHookError,\n} from \"./errors.ts\";\n\n/** The repository-provided setup hook, relative to the worktree root. Runs only in a trusted project. */\nexport const RESUME_SETUP_HOOK_FILE = \".atomic/setup\";\n/** The setting that names a setup command, used when the repository provides no trusted hook. */\nexport const RESUME_SETUP_COMMAND_SETTING = \"resume.setupCommand\";\n/** How long a setup hook may run before it is stopped and the resume fails. */\nexport const DEFAULT_RESUME_SETUP_TIMEOUT_MS = 15 * 60_000;\n\n/** How a restored worktree's dependencies are materialized. */\nexport interface ResumeSetupConfig {\n\t/** `resume.setupCommand`, run through the shell in the worktree. */\n\treadonly command?: string;\n\t/** Whether the project at a worktree is trusted, which `.atomic/setup` requires. */\n\treadonly trusted: (worktree: string) => boolean;\n\treadonly timeoutMs?: number;\n}\n\n/** The last setup run recorded for one worktree on this host. */\nexport interface ResumeSetupLedgerEntry {\n\treadonly worktree: string;\n\treadonly envHash: string;\n\treadonly hook: string;\n\treadonly exitStatus: number | null;\n\treadonly signal: string | null;\n\treadonly ranAt: string;\n\treadonly logPath: string;\n}\n\nexport type ResumeSetupOutcome =\n\t| { readonly status: \"not-needed\" }\n\t| { readonly status: \"ran\"; readonly hook: string; readonly logPath: string };\n\nexport interface EnsureResumeSetupOptions {\n\treadonly entryPoint: ResumeEntryPoint;\n\t/** Root of a worktree Atomic restored on this host. */\n\treadonly worktree: string;\n\t/** The environment fingerprint the restored snapshot recorded. */\n\treadonly envHash: string;\n\t/** Host directory that holds restored worktrees; the setup ledger and logs live under it. */\n\treadonly storeDir: string;\n\treadonly config: ResumeSetupConfig;\n\treadonly signal?: AbortSignal;\n}\n\nfunction ledgerPath(storeDir: string, worktree: string): string {\n\tconst key = createHash(\"sha256\").update(resolve(worktree)).digest(\"hex\");\n\treturn join(storeDir, \"setup-ledger\", `${key}.json`);\n}\n\n/** The setup run recorded for `worktree`, if any. */\nexport async function readResumeSetupLedger(\n\tstoreDir: string,\n\tworktree: string,\n): Promise<ResumeSetupLedgerEntry | undefined> {\n\ttry {\n\t\treturn JSON.parse(await readFile(ledgerPath(storeDir, worktree), \"utf8\")) as ResumeSetupLedgerEntry;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow error;\n\t}\n}\n\nasync function writeLedger(storeDir: string, entry: ResumeSetupLedgerEntry): Promise<void> {\n\tconst path = ledgerPath(storeDir, entry.worktree);\n\tawait mkdir(dirname(path), { recursive: true });\n\tconst temporary = `${path}.${process.pid}.tmp`;\n\tawait writeFile(temporary, `${JSON.stringify(entry, null, 2)}\\n`, { mode: 0o600 });\n\tawait rename(temporary, path);\n}\n\nasync function isFile(path: string): Promise<boolean> {\n\ttry {\n\t\treturn (await stat(path)).isFile();\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\tif (code === \"ENOENT\" || code === \"ENOTDIR\") return false;\n\t\tthrow error;\n\t}\n}\n\n/** Whether `worktree` has any file that decides installed dependencies or toolchains. */\nexport async function hasEnvironmentInputs(worktree: string): Promise<boolean> {\n\tfor (const path of ENVIRONMENT_INPUT_FILES) {\n\t\tif (await isFile(join(worktree, path))) return true;\n\t}\n\treturn false;\n}\n\ntype ResolvedHook =\n\t| { readonly kind: \"file\"; readonly name: string; readonly path: string }\n\t| { readonly kind: \"command\"; readonly name: string; readonly command: string };\n\nasync function resolveHook(\n\tworktree: string,\n\tconfig: ResumeSetupConfig,\n): Promise<ResolvedHook | \"untrusted\" | undefined> {\n\tconst file = join(worktree, RESUME_SETUP_HOOK_FILE);\n\tconst present = await isFile(file);\n\tif (present && config.trusted(worktree)) return { kind: \"file\", name: RESUME_SETUP_HOOK_FILE, path: file };\n\tconst command = config.command?.trim();\n\tif (command) return { kind: \"command\", name: RESUME_SETUP_COMMAND_SETTING, command };\n\treturn present ? \"untrusted\" : undefined;\n}\n\nfunction missingHookError(options: EnsureResumeSetupOptions, untrusted: boolean): ResumePreconditionError {\n\treturn new ResumePreconditionError({\n\t\tentryPoint: options.entryPoint,\n\t\tproblems: [\n\t\t\t{\n\t\t\t\tcode: \"setup-hook-missing\",\n\t\t\t\tsubject: untrusted ? `${RESUME_SETUP_HOOK_FILE} (untrusted project)` : \"setup hook\",\n\t\t\t\twhy: `the worktree restored at ${options.worktree} has dependency inputs (envHash ${options.envHash.slice(0, 12)}) that were never installed on this node, and ${\n\t\t\t\t\tuntrusted\n\t\t\t\t\t\t? `${RESUME_SETUP_HOOK_FILE} runs only in a trusted project`\n\t\t\t\t\t\t: `neither ${RESUME_SETUP_HOOK_FILE} nor ${RESUME_SETUP_COMMAND_SETTING} is configured`\n\t\t\t\t}`,\n\t\t\t\tfix: untrusted\n\t\t\t\t\t? `Trust the project (start with --approve, or set \"defaultProjectTrust\": \"always\"), or set \"${RESUME_SETUP_COMMAND_SETTING}\" in ~/.atomic/agent/settings.json, then resume again.`\n\t\t\t\t\t: `Add an executable ${RESUME_SETUP_HOOK_FILE} to the repository, or set \"${RESUME_SETUP_COMMAND_SETTING}\" (for example \"npm ci\") in ~/.atomic/agent/settings.json, then resume again.`,\n\t\t\t},\n\t\t],\n\t});\n}\n\nlet noInputsHash: Promise<string> | undefined;\n\n/** The environment fingerprint of a checkout without any dependency input file. */\nfunction noInputsEnvironmentHash(): Promise<string> {\n\tnoInputsHash ??= computeEnvironmentHash(join(tmpdir(), `atomic-no-environment-inputs-${randomUUID()}`));\n\treturn noInputsHash;\n}\n\n/**\n * The `setup-hook-missing` problem that restoring a snapshot recorded with `envHash` would hit, when that is known\n * before restoring: the snapshot has dependency inputs, no `resume.setupCommand` is configured, and a worktree restored\n * under `prospectiveWorktree` would not be trusted to run the repository's `.atomic/setup`. Whether the repository has\n * that file is only known after the restore.\n */\nexport async function predictedSetupProblem(\n\tenvHash: string,\n\tprospectiveWorktree: string,\n\tconfig: ResumeSetupConfig,\n): Promise<ResumePreconditionProblem | undefined> {\n\tif (config.command?.trim()) return undefined;\n\tif (envHash === (await noInputsEnvironmentHash())) return undefined;\n\tif (config.trusted(prospectiveWorktree)) return undefined;\n\treturn {\n\t\tcode: \"setup-hook-missing\",\n\t\tsubject: \"setup hook\",\n\t\twhy: `the snapshot has dependency inputs (envHash ${envHash.slice(0, 12)}) that a restored worktree must install, no ${RESUME_SETUP_COMMAND_SETTING} is configured, and a restored worktree is not trusted to run ${RESUME_SETUP_HOOK_FILE}`,\n\t\tfix: `Set \"${RESUME_SETUP_COMMAND_SETTING}\" (for example \"npm ci\") in ~/.atomic/agent/settings.json, or trust restored worktrees (start with --approve, or set \"defaultProjectTrust\": \"always\") so the repository's ${RESUME_SETUP_HOOK_FILE} can run, then resume again.`,\n\t};\n}\n\ninterface HookExit {\n\treadonly exitStatus: number | null;\n\treadonly signal: string | null;\n\treadonly timedOut: boolean;\n\treadonly elapsedMs: number;\n}\n\nasync function runHook(\n\thook: ResolvedHook,\n\tworktree: string,\n\tenvHash: string,\n\tlogPath: string,\n\ttimeoutMs: number,\n\tsignal: AbortSignal | undefined,\n): Promise<HookExit> {\n\tsignal?.throwIfAborted();\n\tawait mkdir(dirname(logPath), { recursive: true });\n\tconst log = await open(logPath, \"w\", 0o600);\n\tconst startedAt = Date.now();\n\ttry {\n\t\treturn await new Promise<HookExit>((resolveExit, reject) => {\n\t\t\tconst child = spawnHook(hook, worktree, log.fd, hookEnv(worktree, envHash));\n\t\t\tlet timedOut = false;\n\t\t\tconst stop = () => {\n\t\t\t\tif (child.pid !== undefined) killProcessTree(child.pid);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tstop();\n\t\t\t}, timeoutMs);\n\t\t\tconst onAbort = () => stop();\n\t\t\tconst settle = () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t};\n\t\t\tsignal?.addEventListener(\"abort\", onAbort);\n\t\t\tchild.once(\"error\", (error) => {\n\t\t\t\tsettle();\n\t\t\t\treject(error);\n\t\t\t});\n\t\t\tchild.once(\"close\", (exitStatus, exitSignal) => {\n\t\t\t\tsettle();\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(signal.reason);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolveExit({ exitStatus, signal: exitSignal, timedOut, elapsedMs: Date.now() - startedAt });\n\t\t\t});\n\t\t});\n\t} finally {\n\t\tawait log.close();\n\t}\n}\n\n/**\n * Starts `hook` in `worktree` in its own process group (POSIX), so stopping it stops everything it started: the\n * repository's `.atomic/setup` through the configured shell (bash, or Git Bash on Windows, which runs a script by its\n * shebang, or the legacy WSL launcher, which takes the command on stdin), and `resume.setupCommand` through the\n * platform shell.\n */\nfunction spawnHook(hook: ResolvedHook, worktree: string, logFd: number, env: NodeJS.ProcessEnv): ChildProcess {\n\tconst options = { cwd: worktree, detached: process.platform !== \"win32\", windowsHide: true, env };\n\tif (hook.kind === \"command\")\n\t\treturn spawn(hook.command, { ...options, shell: true, stdio: [\"ignore\", logFd, logFd] });\n\tconst { shell, args, commandTransport } = getShellConfig();\n\tconst script = `./${RESUME_SETUP_HOOK_FILE}`;\n\tif (commandTransport !== \"stdin\")\n\t\treturn spawn(shell, [...args, script], { ...options, stdio: [\"ignore\", logFd, logFd] });\n\tconst child = spawn(shell, args, { ...options, stdio: [\"pipe\", logFd, logFd] });\n\tchild.stdin?.end(script);\n\treturn child;\n}\n\nfunction hookEnv(worktree: string, envHash: string): NodeJS.ProcessEnv {\n\treturn { ...process.env, ATOMIC_ENV_HASH: envHash, ATOMIC_RESUME_WORKTREE: worktree };\n}\n\n/**\n * The hook a restored worktree needs before work continues in it, or undefined when it needs none: it has no\n * dependency inputs, or the ledger has a successful run for the recorded `envHash`. Throws\n * {@link ResumePreconditionError} (`setup-hook-missing`) when one is needed and none is available.\n */\nasync function neededHook(options: EnsureResumeSetupOptions): Promise<ResolvedHook | undefined> {\n\tconst worktree = resolve(options.worktree);\n\tconst ledger = await readResumeSetupLedger(options.storeDir, worktree);\n\tif (ledger?.envHash === options.envHash && ledger.exitStatus === 0) return undefined;\n\tif (!(await hasEnvironmentInputs(worktree))) return undefined;\n\tconst hook = await resolveHook(worktree, options.config);\n\tif (hook === undefined || hook === \"untrusted\") throw missingHookError(options, hook === \"untrusted\");\n\treturn hook;\n}\n\n/**\n * Checks, before a restored worktree is recorded, that it has the setup hook it needs: throws\n * {@link ResumePreconditionError} (`setup-hook-missing`) exactly when {@link ensureResumeSetup} would. When a hook\n * will run, it is entered in the ledger as not run yet, so a hook that never finishes, because the process stopped or\n * the resume was cancelled, runs again on the next resume.\n */\nexport async function reserveResumeSetup(options: EnsureResumeSetupOptions): Promise<void> {\n\tconst hook = await neededHook(options);\n\tif (hook === undefined) return;\n\tawait writeLedger(options.storeDir, {\n\t\tworktree: resolve(options.worktree),\n\t\tenvHash: options.envHash,\n\t\thook: hook.name,\n\t\texitStatus: null,\n\t\tsignal: null,\n\t\tranAt: new Date().toISOString(),\n\t\tlogPath: \"\",\n\t});\n}\n\n/**\n * Runs the setup hook a restored worktree needs before work continues in it, and records the result in the host's\n * setup ledger. The hook is needed when the worktree has dependency inputs and the ledger has no successful run for\n * the recorded `envHash`, so a worktree is set up once per environment. Throws {@link ResumePreconditionError}\n * (`setup-hook-missing`) when no hook is available, and {@link ResumeSetupHookError} when it fails or times out.\n */\nexport async function ensureResumeSetup(options: EnsureResumeSetupOptions): Promise<ResumeSetupOutcome> {\n\tconst worktree = resolve(options.worktree);\n\tconst hook = await neededHook(options);\n\tif (hook === undefined) return { status: \"not-needed\" };\n\tconst timeoutMs = options.config.timeoutMs ?? DEFAULT_RESUME_SETUP_TIMEOUT_MS;\n\tconst logPath = join(\n\t\toptions.storeDir,\n\t\t\"setup-logs\",\n\t\t`${createHash(\"sha256\").update(worktree).digest(\"hex\").slice(0, 12)}-${Date.now()}.log`,\n\t);\n\tlet exit: HookExit;\n\ttry {\n\t\texit = await runHook(hook, worktree, options.envHash, logPath, timeoutMs, options.signal);\n\t} catch (error) {\n\t\tif (options.signal?.aborted) throw error;\n\t\tthrow new ResumeSetupHookError(\n\t\t\t\"setup-hook-failed\",\n\t\t\t{\n\t\t\t\thook: hook.name,\n\t\t\t\tworktree,\n\t\t\t\tenvHash: options.envHash,\n\t\t\t\texitStatus: null,\n\t\t\t\tsignal: null,\n\t\t\t\tlogPath,\n\t\t\t\ttimeoutMs,\n\t\t\t\telapsedMs: 0,\n\t\t\t},\n\t\t\terror as Error,\n\t\t);\n\t}\n\tawait writeLedger(options.storeDir, {\n\t\tworktree,\n\t\tenvHash: options.envHash,\n\t\thook: hook.name,\n\t\texitStatus: exit.exitStatus,\n\t\tsignal: exit.signal,\n\t\tranAt: new Date().toISOString(),\n\t\tlogPath,\n\t});\n\tif (!exit.timedOut && exit.exitStatus === 0) return { status: \"ran\", hook: hook.name, logPath };\n\tthrow new ResumeSetupHookError(exit.timedOut ? \"setup-hook-timed-out\" : \"setup-hook-failed\", {\n\t\thook: hook.name,\n\t\tworktree,\n\t\tenvHash: options.envHash,\n\t\texitStatus: exit.exitStatus,\n\t\tsignal: exit.signal,\n\t\tlogPath,\n\t\ttimeoutMs,\n\t\telapsedMs: exit.elapsedMs,\n\t});\n}\n"]}
|