@bastani/atomic 0.9.74 → 0.9.75
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 +136 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +21 -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 +64 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-resume.js","sourceRoot":"","sources":["../../../src/core/resume/session-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAA4B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CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,sBAAsB,EAAE,KAAK,QAAQ,CAAC;AACjG,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC9C,OAAO,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,UAA4B,EAC5B,SAAiB,EACjB,QAAgB,EAChB,eAA+F,EAC/F,OAAsC;IAEtC,OAAO;QACN,UAAU;QACV,SAAS;QACT,QAAQ,EAAE,eAAe,CAAC,2BAA2B,EAAE;QACvD,KAAK,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE;QACpE,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;KAClC,CAAC;AACH,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { stat } from \"node:fs/promises\";\nimport { join, relative, resolve } from \"node:path\";\nimport { type GitUnavailableError, isGitUnavailableError } from \"../../utils/git-errors.ts\";\nimport type { SessionManager } from \"../session-manager.ts\";\nimport { currentWorktreeSnapshots, mapRestoredPath, openSessionInWorktree } from \"../session-worktree-snapshots.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport { ProjectTrustStore } from \"../trust-manager.ts\";\nimport { locateCheckout, readRepositoryConfig } from \"../worktree-snapshot/capture.ts\";\nimport { isWorkspaceDriftError, isWorkspaceSnapshotError } from \"../worktree-snapshot/errors.ts\";\nimport { gitText, runGit } from \"../worktree-snapshot/git.ts\";\nimport { isHeadOnlyAdvance } from \"../worktree-snapshot/head-advance.ts\";\nimport {\n\tdefaultWorktreeSnapshotStoreDir,\n\ttype VerifyWorktreeOptions,\n\tverifyWorktree,\n} from \"../worktree-snapshot/restore.ts\";\nimport type { WorktreeRootMapping, WorktreeSnapshot, WorktreeSnapshotSettings } from \"../worktree-snapshot/types.ts\";\nimport type { ResumeEntryPoint, ResumePreconditionProblem } from \"./errors.ts\";\nimport { isInside } from \"./path-mapping.ts\";\nimport {\n\tassertResumePreconditions,\n\tdefaultResumePreflightIo,\n\tgitUnavailableProblem,\n\ttype ResumePreflightIo,\n} from \"./preflight.ts\";\nimport {\n\tensureResumeSetup,\n\tpredictedSetupProblem,\n\ttype ResumeSetupConfig,\n\treadResumeSetupLedger,\n\treserveResumeSetup,\n} from \"./setup-hook.ts\";\n\n/** What to do when the checkout a resume was started in belongs to the session's repository but differs from it. */\nexport type DirtyCheckoutChoice = \"restore\" | \"use\" | \"cancel\";\n\nexport interface DirtyCheckoutPrompt {\n\t/** Root of the user's checkout the resume was started in. */\n\treadonly checkout: string;\n\t/** Root the session recorded, on the node that recorded it. */\n\treadonly recordedRoot: string;\n\treadonly snapshotId: string;\n}\n\nexport interface ResumeNotice {\n\treadonly type: \"info\" | \"warning\";\n\treadonly message: string;\n}\n\nexport interface PrepareSessionResumeOptions {\n\treadonly entryPoint: ResumeEntryPoint;\n\t/** Where the resume was started: the requested target when it is a checkout of the session's repository. */\n\treadonly launchCwd: string;\n\treadonly settings: WorktreeSnapshotSettings;\n\treadonly setup: ResumeSetupConfig;\n\t/** Host directory for restored worktrees. Default ~/.atomic/agent/worktree-snapshots. */\n\treadonly storeDir?: string;\n\t/** Asks the user about a dirty checkout. Without it a fresh worktree is restored, which overwrites nothing. */\n\treadonly chooseDirtyCheckout?: (prompt: DirtyCheckoutPrompt) => Promise<DirtyCheckoutChoice>;\n\treadonly io?: ResumePreflightIo;\n\t/** Session directory to reopen a moved session in, for stores that keep sessions per directory. */\n\treadonly sessionDirectory?: string;\n\treadonly signal?: AbortSignal;\n\t/**\n\t * Checkouts the session continues in as they are, by the root its recorded restores put them at: never verified and\n\t * never restored, as for checkouts it worked in on this node and changed since.\n\t */\n\treadonly keepInPlace?: ReadonlySet<string>;\n}\n\nexport type PreparedSessionResume =\n\t| { readonly status: \"cancelled\" }\n\t| {\n\t\t\treadonly status: \"ready\";\n\t\t\t/** The session opened where it continues: the one passed in when its cwd did not change. */\n\t\t\treadonly sessionManager: SessionManager;\n\t\t\treadonly notices: readonly ResumeNotice[];\n\t };\n\nasync function isDirectory(path: string): Promise<boolean> {\n\ttry {\n\t\treturn (await stat(path)).isDirectory();\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\nexport interface SessionSnapshotMatch {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\t/** The session cwd after the session's recorded restores. */\n\treadonly cwd: string;\n}\n\n/** The latest snapshot of the checkout the session works in, the same one #4245's resume verifies. */\nexport function latestSessionSnapshot(\n\tsessionManager: Pick<SessionManager, \"getCwd\" | \"getWorktreeRootMappings\" | \"getLatestWorktreeSnapshots\">,\n): SessionSnapshotMatch | undefined {\n\tconst cwd = mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());\n\tlet match: SessionSnapshotMatch | undefined;\n\tfor (const [root, snapshot] of sessionManager.getLatestWorktreeSnapshots()) {\n\t\tif (isInside(root, cwd) && (!match || root.length > match.root.length)) match = { root, snapshot, cwd };\n\t}\n\treturn match;\n}\n\n/** Continue in the launch checkout, or stop because the user cancelled; undefined restores a fresh worktree. */\ntype CheckoutReuse =\n\t| {\n\t\t\treadonly kind: \"reused\";\n\t\t\treadonly cwd: string;\n\t\t\t/** Whether the checkout matched the snapshot, rather than being used as it is by the user's choice. */\n\t\t\treadonly matches: boolean;\n\t\t\treadonly notice: ResumeNotice;\n\t\t\t/** The recorded root mapped onto the checkout, recorded once nothing else stops the resume. */\n\t\t\treadonly mapping: WorktreeRootMapping;\n\t }\n\t| { readonly kind: \"cancelled\" }\n\t| undefined;\n\n/**\n * Continues in the checkout the resume started in when it is a checkout of the session's repository: as-is when its\n * tree matches the snapshot (or only its HEAD moved forward over it); when it differs and has local changes, only if\n * the user says so. A clean checkout that differs is left alone and a fresh worktree is restored instead. Returns the\n * mapping that makes paths follow, for the caller to record.\n */\nasync function reuseLaunchCheckout(\n\tmatch: SessionSnapshotMatch,\n\toptions: PrepareSessionResumeOptions,\n): Promise<CheckoutReuse> {\n\tconst checkout = await locateCheckout(options.launchCwd, options.signal).catch((error: unknown) => {\n\t\tif (isWorkspaceSnapshotError(error)) return error;\n\t\tthrow error;\n\t});\n\tif (checkout instanceof Error) return undefined;\n\tconst root = resolve(checkout.root);\n\tconst { remotes } = await readRepositoryConfig(root, options.signal);\n\tif (!remotes.some((remote) => match.snapshot.remotes.includes(remote))) return undefined;\n\tlet matches = true;\n\ttry {\n\t\tawait verifyWorktree(match.snapshot, root, { settings: options.settings, signal: options.signal });\n\t} catch (error) {\n\t\tif (!isWorkspaceDriftError(error)) throw error;\n\t\tmatches = await isHeadOnlyAdvance(error, options.signal);\n\t}\n\tif (!matches) {\n\t\tif (!(await hasLocalChanges(root, options.signal))) return undefined;\n\t\tconst choice = options.chooseDirtyCheckout\n\t\t\t? await options.chooseDirtyCheckout({\n\t\t\t\t\tcheckout: root,\n\t\t\t\t\trecordedRoot: match.root,\n\t\t\t\t\tsnapshotId: match.snapshot.id,\n\t\t\t\t})\n\t\t\t: \"restore\";\n\t\tif (choice === \"cancel\") return { kind: \"cancelled\" };\n\t\tif (choice === \"restore\") return undefined;\n\t}\n\tconst mapping: WorktreeRootMapping = {\n\t\tfrom: match.root,\n\t\tto: root,\n\t\tsnapshotId: match.snapshot.id,\n\t\ttree: match.snapshot.tree,\n\t\trestoredAt: new Date().toISOString(),\n\t};\n\treturn {\n\t\tkind: \"reused\",\n\t\tcwd: resolve(root, relative(match.root, match.cwd)),\n\t\tmatches,\n\t\tmapping,\n\t\tnotice: matches\n\t\t\t? {\n\t\t\t\t\ttype: \"info\",\n\t\t\t\t\tmessage: `Resuming in ${root}, which matches snapshot ${match.snapshot.id.slice(0, 12)} of ${match.root}`,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tmessage: `Resuming in ${root}, which differs from snapshot ${match.snapshot.id.slice(0, 12)} of ${match.root}`,\n\t\t\t\t},\n\t};\n}\n\n/** Whether the checkout at `root` has uncommitted or untracked changes, which a resume must not overwrite unasked. */\nasync function hasLocalChanges(root: string, signal: AbortSignal | undefined): Promise<boolean> {\n\treturn (await gitText([\"status\", \"--porcelain\"], { cwd: root, signal })).length > 0;\n}\n\n/**\n * Gets a resumed session's checkouts ready on this node before its runtime starts, and returns the session opened\n * where it continues. When the checkout the session works in is missing or changed here, a checkout of the same\n * repository the resume started in is used as-is if it matches (and, if it differs, only when the user chooses it).\n * Every other checkout the session recorded that is gone or changed here, except those in `keepInPlace`, is restored:\n * every precondition of those restores is checked in one pass first (Git, and a setup hook for each snapshot with\n * dependency inputs), then #4245's {@link openSessionInWorktree} restores them into fresh worktrees. A restored\n * worktree that turns out to have no setup hook it needs is removed again before its restore is recorded. Each\n * worktree Atomic restored gets its setup hook once per environment. The session's tools resolve paths under every\n * root it recorded into the place that root was restored.\n */\nexport async function prepareSessionResume(\n\tsessionManager: SessionManager,\n\toptions: PrepareSessionResumeOptions,\n): Promise<PreparedSessionResume> {\n\tconst io = options.io ?? defaultResumePreflightIo;\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\tif (!options.settings.enabled || sessionManager.getLatestWorktreeSnapshots().size === 0) {\n\t\treturn { status: \"ready\", sessionManager, notices: [] };\n\t}\n\tconst notices: ResumeNotice[] = [];\n\tconst match = latestSessionSnapshot(sessionManager);\n\tlet git: GitProbe | undefined;\n\tlet reused: WorktreeRootMapping | undefined;\n\tif (\n\t\tmatch !== undefined &&\n\t\t!options.keepInPlace?.has(match.root) &&\n\t\t(await worktreeNeedsRestore(match.snapshot, match.root, options))\n\t) {\n\t\tgit = { unavailable: await io.probeGit(options.signal) };\n\t\tconst reuse = git.unavailable === undefined ? await reuseLaunchCheckout(match, options) : undefined;\n\t\tif (reuse?.kind === \"cancelled\") return { status: \"cancelled\" };\n\t\tif (reuse?.kind === \"reused\" && !reuse.matches) {\n\t\t\tawait recordReuse(sessionManager, reuse.mapping);\n\t\t\treturn continueInChosenCheckout(sessionManager, reuse, options);\n\t\t}\n\t\tif (reuse?.kind === \"reused\") {\n\t\t\treused = reuse.mapping;\n\t\t\tnotices.push(reuse.notice);\n\t\t}\n\t}\n\tconst restoring = await checkoutsToRestore(withMapping(sessionManager, reused), options);\n\tif (restoring.length > 0) {\n\t\tgit ??= { unavailable: await io.probeGit(options.signal) };\n\t\tawait assertRestorePreconditions(sessionManager, restoring, storeDir, options, git.unavailable);\n\t}\n\tconst snapshots = sessionManager.getWorktreeSnapshotRecords();\n\tconst recordedBefore = sessionManager.getWorktreeRootMappings().length;\n\tconst opened = await openSessionInWorktree(sessionManager, {\n\t\tsettings: options.settings,\n\t\tstoreDir,\n\t\tsignal: options.signal,\n\t\tsessionDirectory: options.sessionDirectory,\n\t\tbeforeRecord: (restored) => reserveRestoredSetup(restored, snapshots, storeDir, options),\n\t\tpendingMappings: reused === undefined ? [] : [reused],\n\t\tkeepInPlace: options.keepInPlace,\n\t});\n\tconst mappings = opened.sessionManager.getWorktreeRootMappings();\n\tnotices.push(...opened.notices);\n\tconst restoredNow = new Set(mappings.slice(recordedBefore).map((mapping) => resolve(mapping.to)));\n\tnotices.push(...(await setUpRestoredCheckouts(opened.sessionManager, restoredNow, storeDir, options)));\n\treturn { status: \"ready\", sessionManager: opened.sessionManager, notices };\n}\n\n/**\n * Continues in the launch checkout the user chose although it differs from the snapshot. #4245's resume would restore\n * a fresh worktree over that choice, so no other checkout is restored either; the notice names those left out.\n */\nasync function continueInChosenCheckout(\n\tsessionManager: SessionManager,\n\treuse: Extract<CheckoutReuse, { kind: \"reused\" }>,\n\toptions: PrepareSessionResumeOptions,\n): Promise<PreparedSessionResume> {\n\tconst notices: ResumeNotice[] = [reuse.notice];\n\tfor (const root of currentWorktreeSnapshots(sessionManager).keys()) {\n\t\tif (!(await isDirectory(root))) {\n\t\t\tnotices.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `Continuing without restoring ${root}, which this session also recorded`,\n\t\t\t});\n\t\t}\n\t}\n\tconst reopened = await sessionManager.openSessionById(\n\t\tsessionManager.getSessionId(),\n\t\treuse.cwd,\n\t\toptions.sessionDirectory,\n\t);\n\treturn { status: \"ready\", sessionManager: reopened, notices };\n}\n\n/** A recorded checkout a resume restores, and whether it is missing here or only changed. */\ninterface RestoreTarget {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\treadonly absent: boolean;\n}\n\n/** Records that the session continues in a checkout already here, so paths follow it. */\nasync function recordReuse(sessionManager: SessionManager, mapping: WorktreeRootMapping): Promise<void> {\n\tawait sessionManager.appendWorktreeSnapshot(mapping.to, mapping.snapshotId, undefined, mapping);\n}\n\ntype SessionCheckouts = Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">;\n\n/** The session's checkouts as they are once `mapping`, not yet recorded, is. */\nfunction withMapping(sessionManager: SessionManager, mapping: WorktreeRootMapping | undefined): SessionCheckouts {\n\tif (mapping === undefined) return sessionManager;\n\treturn {\n\t\tgetBranch: () => sessionManager.getBranch(),\n\t\tgetWorktreeSnapshotRecords: () => sessionManager.getWorktreeSnapshotRecords(),\n\t\tgetWorktreeRootMappings: () => [...sessionManager.getWorktreeRootMappings(), mapping],\n\t};\n}\n\n/**\n * The recorded checkouts that are gone or changed here, which #4245's resume restores into fresh worktrees, except\n * those the session continues in as they are.\n */\nasync function checkoutsToRestore(\n\tsessionManager: SessionCheckouts,\n\toptions: PrepareSessionResumeOptions,\n): Promise<RestoreTarget[]> {\n\tconst targets: RestoreTarget[] = [];\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tif (!options.keepInPlace?.has(root) && (await worktreeNeedsRestore(snapshot, root, options))) {\n\t\t\ttargets.push({ root, snapshot, absent: !(await isDirectory(root)) });\n\t\t}\n\t}\n\treturn targets;\n}\n\n/**\n * Checks that each worktree #4245's resume just restored has the setup hook it needs, before that resume records any\n * of them, so a missing hook leaves no record of a worktree that is removed again, and enters each hook that will run\n * in the ledger as not run yet.\n */\nasync function reserveRestoredSetup(\n\trestored: readonly WorktreeRootMapping[],\n\tsnapshots: ReadonlyMap<string, WorktreeSnapshot>,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<void> {\n\tfor (const mapping of restored) {\n\t\tawait reserveResumeSetup({\n\t\t\tentryPoint: options.entryPoint,\n\t\t\tworktree: mapping.to,\n\t\t\tenvHash: snapshots.get(mapping.snapshotId)!.envHash,\n\t\t\tstoreDir,\n\t\t\tconfig: options.setup,\n\t\t\tsignal: options.signal,\n\t\t});\n\t}\n}\n\n/**\n * Runs the setup hook of the worktrees Atomic restored for the session: once per environment in each worktree this\n * resume restored (`restoredNow`), and again in a worktree restored earlier only when its last hook failed. Later\n * changes to an earlier worktree's lockfiles are the session's own work.\n */\nasync function setUpRestoredCheckouts(\n\tsessionManager: SessionManager,\n\trestoredNow: ReadonlySet<string>,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<ResumeNotice[]> {\n\tconst notices: ResumeNotice[] = [];\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tif (!isInside(storeDir, root)) continue;\n\t\tif (!restoredNow.has(root)) {\n\t\t\tconst last = await readResumeSetupLedger(storeDir, root);\n\t\t\tif (last === undefined || last.exitStatus === 0) continue;\n\t\t}\n\t\tconst setup = await ensureResumeSetup({\n\t\t\tentryPoint: options.entryPoint,\n\t\t\tworktree: root,\n\t\t\tenvHash: snapshot.envHash,\n\t\t\tstoreDir,\n\t\t\tconfig: options.setup,\n\t\t\tsignal: options.signal,\n\t\t});\n\t\tif (setup.status === \"ran\") {\n\t\t\tnotices.push({ type: \"info\", message: `Ran setup hook ${setup.hook} in ${root} (output: ${setup.logPath})` });\n\t\t}\n\t}\n\treturn notices;\n}\n\n/**\n * Whether the repository of the checkout at `root` holds the commit that records `snapshot`. That commit is\n * content-addressed and written only where Atomic captured exactly that state, so it tells the checkout a session\n * worked in, even after it changed, from another checkout of the same repository at the same path on another node,\n * unless Atomic captured the same state there too. A checkout that is not a repository, or a node without Git, does\n * not hold it.\n */\nexport async function holdsSnapshotCommit(\n\tsnapshot: WorktreeSnapshot,\n\troot: string,\n\tsignal?: AbortSignal,\n): Promise<boolean> {\n\ttry {\n\t\tconst { exitCode } = await runGit([\"cat-file\", \"-e\", `${snapshot.snapshot}^{commit}`], {\n\t\t\tcwd: root,\n\t\t\tsignal,\n\t\t\tallowExitCodes: [1, 128],\n\t\t});\n\t\treturn exitCode === 0;\n\t} catch (error) {\n\t\tif (isGitUnavailableError(error)) return false;\n\t\tthrow error;\n\t}\n}\n\n/**\n * Where a woken session continues. Each checkout it recorded that it worked in on this node stays as it is, since work\n * done in it after the release belongs to the session, and a setup hook that did not finish in a worktree this node\n * restored for it runs again. Every other checkout, as when it is missing or another clone sits at its path on another\n * node, is prepared as `/resume` prepares it. When every checkout stays, it continues in the directory it last worked\n * in, after the restores it recorded, which `reopen` opens it in.\n */\nexport async function continueSessionWhereItWorked(\n\topened: SessionManager,\n\toptions: PrepareSessionResumeOptions,\n\treopen: (cwd: string) => Promise<SessionManager> = (cwd) => opened.openSessionById(opened.getSessionId(), cwd),\n): Promise<SessionManager> {\n\tconst cwd = mapRestoredPath(opened.getCwd(), opened.getWorktreeRootMappings());\n\tconst checkouts = currentWorktreeSnapshots(opened);\n\tconst own = await checkoutsWorkedHere(checkouts, cwd, options);\n\tif (own.size < checkouts.size) {\n\t\tconst prepared = await prepareSessionResume(opened, { ...options, keepInPlace: own });\n\t\treturn prepared.status === \"ready\" ? prepared.sessionManager : opened;\n\t}\n\tawait retryFailedSessionSetup(opened, options);\n\treturn cwd === resolve(opened.getCwd()) ? opened : reopen(cwd);\n}\n\n/**\n * The roots of the `checkouts` a session recorded that are here as checkouts it worked in on this node, as it left them\n * or changed since: a worktree this node restored for it, or a checkout whose repository holds the commit of its latest\n * snapshot. The checkout the session works in counts only while its working directory `cwd` is here too.\n */\nasync function checkoutsWorkedHere(\n\tcheckouts: ReadonlyMap<string, WorktreeSnapshot>,\n\tcwd: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<Set<string>> {\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\tconst own = new Set<string>();\n\tfor (const [root, snapshot] of checkouts) {\n\t\tif (!existsSync(isInside(root, cwd) ? cwd : root)) continue;\n\t\tif (isInside(storeDir, root) || (await holdsSnapshotCommit(snapshot, root, options.signal))) own.add(root);\n\t}\n\treturn own;\n}\n\n/**\n * Runs the setup hook again in each worktree Atomic restored for the session whose last hook there failed, as a resume\n * that restores nothing does.\n */\nexport async function retryFailedSessionSetup(\n\tsessionManager: SessionManager,\n\toptions: PrepareSessionResumeOptions,\n): Promise<ResumeNotice[]> {\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\treturn setUpRestoredCheckouts(sessionManager, new Set(), storeDir, options);\n}\n\n/**\n * Whether resuming in `root` restores `snapshot` into a fresh worktree: the checkout is gone, is not a repository of\n * the recorded tree, or no longer matches it. A path that cannot be read fails with its typed `unreadable-path` error\n * instead, since restoring would hide it. A checkout whose HEAD only moved forward over the recorded tree, as after\n * committing the recorded edits, continues in place, as #4245's resume decides. Read-only.\n */\nexport async function worktreeNeedsRestore(\n\tsnapshot: WorktreeSnapshot,\n\troot: string,\n\toptions: VerifyWorktreeOptions,\n): Promise<boolean> {\n\ttry {\n\t\tawait verifyWorktree(snapshot, root, options);\n\t\treturn false;\n\t} catch (error) {\n\t\tif (isWorkspaceDriftError(error)) return !(await isHeadOnlyAdvance(error, options.signal));\n\t\tif (isWorkspaceSnapshotError(error) && error.code !== \"unreadable-path\") return true;\n\t\tthrow error;\n\t}\n}\n\n/** The outcome of starting or provisioning Git once for a resume: the typed reason it cannot run, or undefined. */\ninterface GitProbe {\n\treadonly unavailable: GitUnavailableError | undefined;\n}\n\n/**\n * Every precondition of restoring `targets` on this node, checked before anything is written: Git can be started or\n * provisioned (`git`, the probe's typed failure), and a setup hook can run in each restored worktree whose snapshot has\n * dependency inputs.\n */\nasync function assertRestorePreconditions(\n\tsessionManager: SessionManager,\n\ttargets: readonly RestoreTarget[],\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n\tgit: GitUnavailableError | undefined,\n): Promise<void> {\n\tconst problems: ResumePreconditionProblem[] = [];\n\tif (git) {\n\t\tconst reasons = targets.map(\n\t\t\t(target) =>\n\t\t\t\t`snapshot ${target.snapshot.id.slice(0, 12)} because ${target.root} ${target.absent ? \"does not exist on this node\" : \"no longer matches it\"}`,\n\t\t);\n\t\tproblems.push(\n\t\t\tgitUnavailableProblem(\n\t\t\t\tgit,\n\t\t\t\t`session ${sessionManager.getSessionId()} must be restored from ${reasons.join(\", and from \")}`,\n\t\t\t),\n\t\t);\n\t}\n\tfor (const target of targets) {\n\t\tconst setup = await predictedSetupProblem(target.snapshot.envHash, join(storeDir, \"worktrees\"), options.setup);\n\t\tif (setup) {\n\t\t\tproblems.push(setup);\n\t\t\tbreak;\n\t\t}\n\t}\n\tassertResumePreconditions(options.entryPoint, problems, git);\n}\n\n/**\n * Whether a restored worktree is trusted to run its repository's `.atomic/setup` outside the CLI: the decision saved\n * in `agentDir` for that path, else the default trust setting.\n */\nexport function savedProjectTrust(\n\tagentDir: string,\n\tsettings: Pick<SettingsManager, \"getDefaultProjectTrust\">,\n): (worktree: string) => boolean {\n\tconst trustStore = new ProjectTrustStore(agentDir);\n\treturn (worktree) => trustStore.get(worktree) ?? settings.getDefaultProjectTrust() === \"always\";\n}\n\n/** Where restored worktrees, the setup ledger and setup logs live for the agent directory `agentDir`. */\nexport function resumeStoreDir(agentDir: string): string {\n\treturn join(agentDir, \"worktree-snapshots\");\n}\n\n/**\n * The options a resume from `launchCwd` needs: snapshot settings and the setup hook configuration from\n * `settingsManager`, and the worktree store of `agentDir`.\n */\nexport function sessionResumeOptions(\n\tentryPoint: ResumeEntryPoint,\n\tlaunchCwd: string,\n\tagentDir: string,\n\tsettingsManager: Pick<SettingsManager, \"getWorktreeSnapshotSettings\" | \"getResumeSetupCommand\">,\n\ttrusted: (worktree: string) => boolean,\n): PrepareSessionResumeOptions {\n\treturn {\n\t\tentryPoint,\n\t\tlaunchCwd,\n\t\tsettings: settingsManager.getWorktreeSnapshotSettings(),\n\t\tsetup: { command: settingsManager.getResumeSetupCommand(), trusted },\n\t\tstoreDir: resumeStoreDir(agentDir),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-resume.js","sourceRoot":"","sources":["../../../src/core/resume/session-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAA4B,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAE5F,OAAO,EACN,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,GACrB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EACN,+BAA+B,EAE/B,cAAc,GACd,MAAM,iCAAiC,CAAC;AAG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,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,sBAAsB,EAAE,KAAK,QAAQ,CAAC;AACjG,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC9C,OAAO,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,eAAe,CAAC,OAAsD;IAC9E,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,+BAA+B,EAAE,CAAC,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,UAA4B,EAC5B,SAAiB,EACjB,QAAgB,EAChB,eAA+F,EAC/F,OAAsC;IAEtC,OAAO;QACN,UAAU;QACV,SAAS;QACT,QAAQ,EAAE,eAAe,CAAC,2BAA2B,EAAE;QACvD,SAAS,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE;QACvF,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;KAClC,CAAC;AACH,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { stat } from \"node:fs/promises\";\nimport { join, relative, resolve } from \"node:path\";\nimport { type GitUnavailableError, isGitUnavailableError } from \"../../utils/git-errors.ts\";\nimport type { SessionManager } from \"../session-manager.ts\";\nimport {\n\tcurrentWorktreeSnapshots,\n\tmapRestoredPath,\n\topenResumedSession,\n\tresumeSessionWorktree,\n} from \"../session-worktree-snapshots.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport { ProjectTrustStore } from \"../trust-manager.ts\";\nimport { locateCheckout, readRepositoryConfig } from \"../worktree-snapshot/capture.ts\";\nimport {\n\tisWorkspaceConfigError,\n\tisWorkspaceDriftError,\n\tisWorkspaceSnapshotError,\n} from \"../worktree-snapshot/errors.ts\";\nimport { gitText, runGit } from \"../worktree-snapshot/git.ts\";\nimport { isHeadOnlyAdvance } from \"../worktree-snapshot/head-advance.ts\";\nimport {\n\tdefaultWorktreeSnapshotStoreDir,\n\ttype VerifyWorktreeOptions,\n\tverifyWorktree,\n} from \"../worktree-snapshot/restore.ts\";\nimport type { WorktreeRootMapping, WorktreeSnapshot, WorktreeSnapshotSettings } from \"../worktree-snapshot/types.ts\";\nimport type { BlueprintBuildConfig } from \"./blueprint/build.ts\";\nimport {\n\ttype BlueprintCheckout,\n\tcheckoutsNeedingRebuild,\n\tenclosingRepositoryRoot,\n\tinheritedRemotes,\n\ttype ResumedBlueprints,\n\trecordBlueprintContext,\n\tsetUpResumedBlueprints,\n} from \"./blueprint/resume.ts\";\nimport { isResumePreconditionError, type ResumeEntryPoint, ResumePreconditionError } from \"./errors.ts\";\nimport { isResumeFailure } from \"./failure.ts\";\nimport { isInside } from \"./path-mapping.ts\";\nimport { defaultResumePreflightIo, gitUnavailableProblem, type ResumePreflightIo } from \"./preflight.ts\";\n\n/** What to do when the checkout a resume was started in belongs to the session's repository but differs from it. */\nexport type DirtyCheckoutChoice = \"restore\" | \"use\" | \"cancel\";\n\nexport interface DirtyCheckoutPrompt {\n\t/** Root of the user's checkout the resume was started in. */\n\treadonly checkout: string;\n\t/** Root the session recorded, on the node that recorded it. */\n\treadonly recordedRoot: string;\n\treadonly snapshotId: string;\n}\n\nexport interface ResumeNotice {\n\treadonly type: \"info\" | \"warning\";\n\treadonly message: string;\n}\n\nexport interface PrepareSessionResumeOptions {\n\treadonly entryPoint: ResumeEntryPoint;\n\t/** Where the resume was started: the requested target when it is a checkout of the session's repository. */\n\treadonly launchCwd: string;\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** How the blueprints of worktrees this resume restores are built; the store directory is `storeDir`. */\n\treadonly blueprint: Omit<BlueprintBuildConfig, \"storeDir\">;\n\t/** Host directory for restored worktrees. Default ~/.atomic/agent/worktree-snapshots. */\n\treadonly storeDir?: string;\n\t/** Asks the user about a dirty checkout. Without it a fresh worktree is restored, which overwrites nothing. */\n\treadonly chooseDirtyCheckout?: (prompt: DirtyCheckoutPrompt) => Promise<DirtyCheckoutChoice>;\n\treadonly io?: ResumePreflightIo;\n\t/** Session directory to reopen a moved session in, for stores that keep sessions per directory. */\n\treadonly sessionDirectory?: string;\n\treadonly signal?: AbortSignal;\n\t/**\n\t * Checkouts the session continues in as they are, by the root its recorded restores put them at: never verified and\n\t * never restored, as for checkouts it worked in on this node and changed since.\n\t */\n\treadonly keepInPlace?: ReadonlySet<string>;\n\t/**\n\t * `\"skip\"` restores checkouts but builds and describes no blueprint and records no blueprint context: for a process\n\t * that serves a resume another process of the same user-level action already prepared and built, so one resume\n\t * builds once. Default `\"build\"`.\n\t */\n\treadonly blueprints?: \"build\" | \"skip\";\n\t/**\n\t * Told the warnings of the blueprint builds a resume ran when its caller gets only a session back, as when a\n\t * released session is woken ({@link continueSessionWhereItWorked}).\n\t */\n\treadonly onNotices?: (notices: readonly ResumeNotice[]) => void;\n}\n\nexport type PreparedSessionResume =\n\t| { readonly status: \"cancelled\" }\n\t| {\n\t\t\treadonly status: \"ready\";\n\t\t\t/** The session opened where it continues: the one passed in when its cwd did not change. */\n\t\t\treadonly sessionManager: SessionManager;\n\t\t\treadonly notices: readonly ResumeNotice[];\n\t\t\t/** The warnings of the blueprint builds this resume ran, also in `notices`. */\n\t\t\treadonly blueprintNotices: readonly ResumeNotice[];\n\t\t\t/** The blueprint context the session's next turn carries, already recorded in it; undefined when none. */\n\t\t\treadonly blueprintContext: string | undefined;\n\t };\n\nasync function isDirectory(path: string): Promise<boolean> {\n\ttry {\n\t\treturn (await stat(path)).isDirectory();\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\nexport interface SessionSnapshotMatch {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\t/** The session cwd after the session's recorded restores. */\n\treadonly cwd: string;\n}\n\n/** The latest snapshot of the checkout the session works in, the same one #4245's resume verifies. */\nexport function latestSessionSnapshot(\n\tsessionManager: Pick<SessionManager, \"getCwd\" | \"getWorktreeRootMappings\" | \"getLatestWorktreeSnapshots\">,\n): SessionSnapshotMatch | undefined {\n\tconst cwd = mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());\n\tlet match: SessionSnapshotMatch | undefined;\n\tfor (const [root, snapshot] of sessionManager.getLatestWorktreeSnapshots()) {\n\t\tif (isInside(root, cwd) && (!match || root.length > match.root.length)) match = { root, snapshot, cwd };\n\t}\n\treturn match;\n}\n\n/** Continue in the launch checkout, or stop because the user cancelled; undefined restores a fresh worktree. */\ntype CheckoutReuse =\n\t| {\n\t\t\treadonly kind: \"reused\";\n\t\t\treadonly cwd: string;\n\t\t\t/** Whether the checkout matched the snapshot, rather than being used as it is by the user's choice. */\n\t\t\treadonly matches: boolean;\n\t\t\treadonly notice: ResumeNotice;\n\t\t\t/** The recorded root mapped onto the checkout, recorded once nothing else stops the resume. */\n\t\t\treadonly mapping: WorktreeRootMapping;\n\t }\n\t| { readonly kind: \"cancelled\" }\n\t| undefined;\n\n/**\n * Continues in the checkout the resume started in when it is a checkout of the session's repository: as-is when its\n * tree matches the snapshot (or only its HEAD moved forward over it); when it differs and has local changes, only if\n * the user says so. A clean checkout that differs is left alone and a fresh worktree is restored instead. Returns the\n * mapping that makes paths follow, for the caller to record.\n */\nasync function reuseLaunchCheckout(\n\tmatch: SessionSnapshotMatch,\n\toptions: PrepareSessionResumeOptions,\n): Promise<CheckoutReuse> {\n\tconst checkout = await locateCheckout(options.launchCwd, options.signal).catch((error: unknown) => {\n\t\tif (isWorkspaceSnapshotError(error)) return error;\n\t\tthrow error;\n\t});\n\tif (checkout instanceof Error) return undefined;\n\tconst root = resolve(checkout.root);\n\tconst { remotes } = await readRepositoryConfig(root, options.signal);\n\tif (!remotes.some((remote) => match.snapshot.remotes.includes(remote))) return undefined;\n\tlet matches = true;\n\ttry {\n\t\tawait verifyWorktree(match.snapshot, root, { settings: options.settings, signal: options.signal });\n\t} catch (error) {\n\t\tif (!isWorkspaceDriftError(error)) throw error;\n\t\tmatches = await isHeadOnlyAdvance(error, options.signal);\n\t}\n\tif (!matches) {\n\t\tif (!(await hasLocalChanges(root, options.signal))) return undefined;\n\t\tconst choice = options.chooseDirtyCheckout\n\t\t\t? await options.chooseDirtyCheckout({\n\t\t\t\t\tcheckout: root,\n\t\t\t\t\trecordedRoot: match.root,\n\t\t\t\t\tsnapshotId: match.snapshot.id,\n\t\t\t\t})\n\t\t\t: \"restore\";\n\t\tif (choice === \"cancel\") return { kind: \"cancelled\" };\n\t\tif (choice === \"restore\") return undefined;\n\t}\n\tconst mapping: WorktreeRootMapping = {\n\t\tfrom: match.root,\n\t\tto: root,\n\t\tsnapshotId: match.snapshot.id,\n\t\ttree: match.snapshot.tree,\n\t\trestoredAt: new Date().toISOString(),\n\t};\n\treturn {\n\t\tkind: \"reused\",\n\t\tcwd: resolve(root, relative(match.root, match.cwd)),\n\t\tmatches,\n\t\tmapping,\n\t\tnotice: matches\n\t\t\t? {\n\t\t\t\t\ttype: \"info\",\n\t\t\t\t\tmessage: `Resuming in ${root}, which matches snapshot ${match.snapshot.id.slice(0, 12)} of ${match.root}`,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tmessage: `Resuming in ${root}, which differs from snapshot ${match.snapshot.id.slice(0, 12)} of ${match.root}`,\n\t\t\t\t},\n\t};\n}\n\n/** Whether the checkout at `root` has uncommitted or untracked changes, which a resume must not overwrite unasked. */\nasync function hasLocalChanges(root: string, signal: AbortSignal | undefined): Promise<boolean> {\n\treturn (await gitText([\"status\", \"--porcelain\"], { cwd: root, signal })).length > 0;\n}\n\n/**\n * Gets a resumed session's checkouts ready on this node before its runtime starts, and returns the session opened\n * where it continues. When the checkout the session works in is missing or changed here, a checkout of the same\n * repository the resume started in is used as-is if it matches (and, if it differs, only when the user chooses it).\n * The checkout the session works in is the only one the resume cannot go without: when it must be restored, the\n * precondition of restoring the recorded checkouts, that Git can run, is checked first, and an unmet one refuses the\n * resume before anything is written. Every other checkout the session recorded that is gone or changed here, except\n * those in `keepInPlace`, never blocks the resume: one the session worked in on this node, changed since, continues as\n * it is; the rest are restored into fresh worktrees one by one by #4245's {@link resumeSessionWorktree}, and one that\n * cannot be (Git is unavailable, or its restore fails) is left out with a warning that names its path and why. Each\n * worktree Atomic restored then gets its blueprints built (#4588): a failing step is a warning in `notices` and never\n * stops the resume. The agent gets the blueprints' maintenance and knowledge in the session's next turn. The session's\n * tools resolve paths under every root it recorded into the place that root was restored.\n */\nexport async function prepareSessionResume(\n\tsessionManager: SessionManager,\n\toptions: PrepareSessionResumeOptions,\n): Promise<PreparedSessionResume> {\n\tconst io = options.io ?? defaultResumePreflightIo;\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\tif (!options.settings.enabled || sessionManager.getLatestWorktreeSnapshots().size === 0) {\n\t\tconst unchanged = await describeBlueprintsInPlace(sessionManager, storeDir, options);\n\t\treturn { status: \"ready\", sessionManager, notices: [], blueprintNotices: [], blueprintContext: unchanged };\n\t}\n\tconst notices: ResumeNotice[] = [];\n\tconst match = latestSessionSnapshot(sessionManager);\n\tlet git: GitProbe | undefined;\n\tlet reused: WorktreeRootMapping | undefined;\n\tif (\n\t\tmatch !== undefined &&\n\t\t!options.keepInPlace?.has(match.root) &&\n\t\t(await worktreeNeedsRestore(match.snapshot, match.root, options))\n\t) {\n\t\tgit = { unavailable: await io.probeGit(options.signal) };\n\t\tconst reuse = git.unavailable === undefined ? await reuseLaunchCheckout(match, options) : undefined;\n\t\tif (reuse?.kind === \"cancelled\") return { status: \"cancelled\" };\n\t\tif (reuse?.kind === \"reused\" && !reuse.matches) {\n\t\t\tawait recordReuse(sessionManager, reuse.mapping);\n\t\t\treturn continueInChosenCheckout(sessionManager, reuse, storeDir, options);\n\t\t}\n\t\tif (reuse?.kind === \"reused\") {\n\t\t\treused = reuse.mapping;\n\t\t\tnotices.push(reuse.notice);\n\t\t}\n\t}\n\tconst checkouts = withMapping(sessionManager, reused);\n\tconst candidates = await restoreCandidates(\n\t\tcheckouts,\n\t\tmapRestoredPath(sessionManager.getCwd(), checkouts.getWorktreeRootMappings()),\n\t\toptions,\n\t);\n\tif (candidates.targets.length > 0) git ??= { unavailable: await io.probeGit(options.signal) };\n\tconst plan = planRestores(sessionManager, candidates, options, git?.unavailable);\n\tnotices.push(...plan.left.values());\n\tconst recordedBefore = sessionManager.getWorktreeRootMappings().length;\n\tconst resumed = await restorePlanned(sessionManager, plan, reused, storeDir, options);\n\tconst cwd = mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());\n\tconst opened = await openResumedSession(sessionManager, cwd, resumed.restored, options.sessionDirectory);\n\tnotices.push(...opened.notices, ...resumed.failed);\n\tconst restoredNow = new Set(\n\t\topened.sessionManager\n\t\t\t.getWorktreeRootMappings()\n\t\t\t.slice(recordedBefore)\n\t\t\t.map((mapping) => resolve(mapping.to))\n\t\t\t.filter((root) => isInside(storeDir, root)),\n\t);\n\tconst blueprints = await setUpCheckoutBlueprints(opened.sessionManager, restoredNow, storeDir, options);\n\tnotices.push(...blueprints.notices);\n\tawait recordBlueprintContext(opened.sessionManager, blueprints.context);\n\treturn {\n\t\tstatus: \"ready\",\n\t\tsessionManager: opened.sessionManager,\n\t\tnotices,\n\t\tblueprintNotices: blueprints.notices,\n\t\tblueprintContext: blueprints.context,\n\t};\n}\n\nconst SKIPPED_BLUEPRINTS: ResumedBlueprints = { outcome: undefined, notices: [], layers: [], context: undefined };\n\n/**\n * The blueprint context of a session that has no worktree snapshots to restore: what its working directory's\n * repository and the global blueprint say, recorded in the session. No build runs and no Git command is started.\n */\nasync function describeBlueprintsInPlace(\n\tsessionManager: SessionManager,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<string | undefined> {\n\tif (options.blueprints === \"skip\") return undefined;\n\tconst root = enclosingRepositoryRoot(resolve(sessionManager.getCwd()));\n\tconst blueprints = await setUpResumedBlueprints({\n\t\trestored: [],\n\t\tinPlace: root === undefined ? [] : [{ root, remotes: [] }],\n\t\tconfig: { ...options.blueprint, storeDir },\n\t\tsignal: options.signal,\n\t});\n\tawait recordBlueprintContext(sessionManager, blueprints.context);\n\treturn blueprints.context;\n}\n\n/**\n * Continues in the launch checkout the user chose although it differs from the snapshot. #4245's resume would restore\n * a fresh worktree over that choice, so no other checkout is restored either; the notice names those left out.\n */\nasync function continueInChosenCheckout(\n\tsessionManager: SessionManager,\n\treuse: Extract<CheckoutReuse, { kind: \"reused\" }>,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<PreparedSessionResume> {\n\tconst notices: ResumeNotice[] = [reuse.notice];\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tif (!(await isDirectory(root))) {\n\t\t\tnotices.push(\n\t\t\t\tnotRestored(\n\t\t\t\t\troot,\n\t\t\t\t\tsnapshot,\n\t\t\t\t\t\"it does not exist on this node, and the session continues in the checkout you chose, which restores nothing else\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\tconst reopened = await sessionManager.openSessionById(\n\t\tsessionManager.getSessionId(),\n\t\treuse.cwd,\n\t\toptions.sessionDirectory,\n\t);\n\tconst blueprints =\n\t\toptions.blueprints === \"skip\"\n\t\t\t? SKIPPED_BLUEPRINTS\n\t\t\t: await setUpResumedBlueprints({\n\t\t\t\t\trestored: [],\n\t\t\t\t\tinPlace: await existingCheckouts(reopened),\n\t\t\t\t\tconfig: { ...options.blueprint, storeDir },\n\t\t\t\t\tsignal: options.signal,\n\t\t\t\t});\n\tawait recordBlueprintContext(reopened, blueprints.context);\n\treturn {\n\t\tstatus: \"ready\",\n\t\tsessionManager: reopened,\n\t\tnotices,\n\t\tblueprintNotices: [],\n\t\tblueprintContext: blueprints.context,\n\t};\n}\n\n/** The session's current checkouts that exist on this node, with the remotes their snapshots recorded. */\nasync function existingCheckouts(sessionManager: SessionCheckouts): Promise<BlueprintCheckout[]> {\n\tconst checkouts: BlueprintCheckout[] = [];\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tif (await isDirectory(root)) checkouts.push(checkoutOf(sessionManager, root, snapshot));\n\t}\n\treturn checkouts;\n}\n\n/** The checkout at `root` for the blueprint build, identified by its repository's remotes as the session's restores trace them. */\nfunction checkoutOf(sessionManager: SessionCheckouts, root: string, snapshot: WorktreeSnapshot): BlueprintCheckout {\n\treturn {\n\t\troot,\n\t\tremotes: inheritedRemotes(\n\t\t\troot,\n\t\t\tsnapshot.remotes,\n\t\t\tsessionManager.getWorktreeRootMappings(),\n\t\t\tsessionManager.getWorktreeSnapshotRecords(),\n\t\t),\n\t};\n}\n\n/** A recorded checkout a resume restores, and whether it is missing here or only changed. */\ninterface RestoreTarget {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\treadonly absent: boolean;\n\t/** Whether the session's working directory is inside it, so the session cannot continue without it. */\n\treadonly runsHere: boolean;\n}\n\n/** What a resume does about the recorded checkouts that are gone or changed here. */\ninterface RestorePlan {\n\t/** Checkouts the session works in, which the resume restores together or not at all. */\n\treadonly required: readonly RestoreTarget[];\n\t/** Every other checkout the resume restores, each on its own, so that one that cannot be restored is left out. */\n\treadonly optional: readonly RestoreTarget[];\n\t/** The warning for each other checkout the resume continues without restoring, by its root. */\n\treadonly left: ReadonlyMap<string, ResumeNotice>;\n}\n\n/** Records that the session continues in a checkout already here, so paths follow it. */\nasync function recordReuse(sessionManager: SessionManager, mapping: WorktreeRootMapping): Promise<void> {\n\tawait sessionManager.appendWorktreeSnapshot(mapping.to, mapping.snapshotId, undefined, mapping);\n}\n\ntype SessionCheckouts = Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">;\n\n/** The session's checkouts as they are once `mapping`, not yet recorded, is. */\nfunction withMapping(sessionManager: SessionManager, mapping: WorktreeRootMapping | undefined): SessionCheckouts {\n\tif (mapping === undefined) return sessionManager;\n\treturn {\n\t\tgetBranch: () => sessionManager.getBranch(),\n\t\tgetWorktreeSnapshotRecords: () => sessionManager.getWorktreeSnapshotRecords(),\n\t\tgetWorktreeRootMappings: () => [...sessionManager.getWorktreeRootMappings(), mapping],\n\t};\n}\n\n/** The warning that the resume continues without restoring the checkout recorded at `root`, with the reason. */\nfunction notRestored(root: string, snapshot: WorktreeSnapshot, reason: string): ResumeNotice {\n\treturn {\n\t\ttype: \"warning\",\n\t\tmessage: `Continuing without restoring ${root} (snapshot ${snapshot.id.slice(0, 12)}): ${reason}`,\n\t};\n}\n\nfunction absentOrChanged(target: Pick<RestoreTarget, \"absent\">): string {\n\treturn target.absent ? \"it does not exist on this node\" : \"it no longer matches the snapshot\";\n}\n\n/**\n * A failure of one checkout alone, which leaves the session's other checkouts restorable: a typed resume, workspace or\n * Git failure, but not a setting that is wrong for every checkout.\n */\nfunction isCheckoutFailure(error: unknown): error is Error {\n\treturn isResumeFailure(error) && !isWorkspaceConfigError(error);\n}\n\n/** What went wrong in `error`, for a warning: the unmet preconditions' reasons, or its own message, and any failed cleanup. */\nfunction describeFailure(error: Error): string {\n\tconst detail = isResumePreconditionError(error)\n\t\t? error.problems.map((problem) => problem.why).join(\"; \")\n\t\t: error.message;\n\tconst cleanup = (error as Error & { readonly cleanupCause?: unknown }).cleanupCause;\n\treturn cleanup instanceof Error ? `${detail}; removing what it restored also failed: ${cleanup.message}` : detail;\n}\n\n/**\n * The recorded checkouts that are gone or changed here, which #4245's resume restores into fresh worktrees, except\n * those the session continues in as they are. Another checkout than the one the session works in is also left alone,\n * with a warning, when it cannot be compared with its snapshot, or when it is here and the session worked in it on this\n * node, so it continues as it is.\n */\nasync function restoreCandidates(\n\tsessionManager: SessionCheckouts,\n\tcwd: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<{ readonly targets: RestoreTarget[]; readonly left: Map<string, ResumeNotice> }> {\n\tconst targets: RestoreTarget[] = [];\n\tconst left = new Map<string, ResumeNotice>();\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tif (options.keepInPlace?.has(root)) continue;\n\t\tconst runsHere = isInside(root, cwd);\n\t\ttry {\n\t\t\tif (!(await worktreeNeedsRestore(snapshot, root, options))) continue;\n\t\t} catch (error) {\n\t\t\tif (runsHere || options.signal?.aborted || !isCheckoutFailure(error)) throw error;\n\t\t\tleft.set(root, notRestored(root, snapshot, `it could not be compared with the snapshot: ${error.message}`));\n\t\t\tcontinue;\n\t\t}\n\t\tconst absent = !(await isDirectory(root));\n\t\tif (!runsHere && !absent && (await checkoutsWorkedHere(new Map([[root, snapshot]]), cwd, options)).has(root)) {\n\t\t\tleft.set(\n\t\t\t\troot,\n\t\t\t\tnotRestored(\n\t\t\t\t\troot,\n\t\t\t\t\tsnapshot,\n\t\t\t\t\t\"it changed since the snapshot, and the session worked in it on this node, so it stays as it is\",\n\t\t\t\t),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\ttargets.push({ root, snapshot, absent, runsHere });\n\t}\n\treturn { targets, left };\n}\n\n/**\n * Restores what `plan` says into fresh worktrees with #4245's {@link resumeSessionWorktree}, recording each restore on\n * `sessionManager`, and returns the mappings it recorded. The checkouts the session works in are restored together,\n * with the mapping to the launch checkout `reused`, and any failure refuses the resume. Every other checkout is\n * restored on its own, and one whose restore fails is reported in `failed` and left out.\n */\nasync function restorePlanned(\n\tsessionManager: SessionManager,\n\tplan: RestorePlan,\n\treused: WorktreeRootMapping | undefined,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<{ restored: WorktreeRootMapping[]; failed: ResumeNotice[] }> {\n\tconst outcome = { restored: [] as WorktreeRootMapping[], failed: [] as ResumeNotice[] };\n\tconst restore = async (targets: readonly RestoreTarget[], pending: WorktreeRootMapping | undefined) => {\n\t\tconst restoring = new Set(targets.map((target) => target.root));\n\t\tconst resumed = await resumeSessionWorktree(sessionManager, {\n\t\t\tsettings: options.settings,\n\t\t\tstoreDir,\n\t\t\tsignal: options.signal,\n\t\t\tpendingMappings: pending === undefined ? [] : [pending],\n\t\t\tkeepInPlace: new Set(\n\t\t\t\t[...currentWorktreeSnapshots(withMapping(sessionManager, pending)).keys()].filter(\n\t\t\t\t\t(root) => !restoring.has(root),\n\t\t\t\t),\n\t\t\t),\n\t\t});\n\t\tif (resumed.status === \"restored\") outcome.restored.push(...resumed.mappings);\n\t};\n\tawait restore(plan.required, reused);\n\tfor (const target of plan.optional) {\n\t\ttry {\n\t\t\tawait restore([target], undefined);\n\t\t} catch (error) {\n\t\t\tif (options.signal?.aborted || !isCheckoutFailure(error)) throw error;\n\t\t\toutcome.failed.push(\n\t\t\t\tnotRestored(\n\t\t\t\t\ttarget.root,\n\t\t\t\t\ttarget.snapshot,\n\t\t\t\t\t`${absentOrChanged(target)}, and restoring it failed: ${describeFailure(error)}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn outcome;\n}\n\n/**\n * Builds the blueprints of the worktrees Atomic restored for the session: each worktree this resume restored\n * (`restoredNow`), and again each worktree restored earlier whose last build failed or never finished. Later changes\n * to an earlier worktree's files are the session's own work. Every other checkout the session works in is only\n * described to the agent.\n */\nasync function setUpCheckoutBlueprints(\n\tsessionManager: SessionManager,\n\trestoredNow: ReadonlySet<string>,\n\tstoreDir: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<ResumedBlueprints> {\n\tif (options.blueprints === \"skip\") return SKIPPED_BLUEPRINTS;\n\tconst restoredHere: BlueprintCheckout[] = [];\n\tconst earlier: BlueprintCheckout[] = [];\n\tconst inPlace: BlueprintCheckout[] = [];\n\tfor (const [root, snapshot] of currentWorktreeSnapshots(sessionManager)) {\n\t\tconst checkout = checkoutOf(sessionManager, root, snapshot);\n\t\tif (restoredNow.has(root)) restoredHere.push(checkout);\n\t\telse if (isInside(storeDir, root)) earlier.push(checkout);\n\t\telse if (await isDirectory(root)) inPlace.push(checkout);\n\t}\n\tconst retried = await checkoutsNeedingRebuild(earlier, storeDir);\n\treturn setUpResumedBlueprints({\n\t\trestored: [...restoredHere, ...retried],\n\t\tinPlace,\n\t\tearlier: earlier.filter((checkout) => !retried.includes(checkout)),\n\t\tconfig: { ...options.blueprint, storeDir },\n\t\tsignal: options.signal,\n\t});\n}\n\n/**\n * Whether the repository of the checkout at `root` holds the commit that records `snapshot`. That commit is\n * content-addressed and written only where Atomic captured exactly that state, so it tells the checkout a session\n * worked in, even after it changed, from another checkout of the same repository at the same path on another node,\n * unless Atomic captured the same state there too. A checkout that is not a repository, or a node without Git, does\n * not hold it.\n */\nexport async function holdsSnapshotCommit(\n\tsnapshot: WorktreeSnapshot,\n\troot: string,\n\tsignal?: AbortSignal,\n): Promise<boolean> {\n\ttry {\n\t\tconst { exitCode } = await runGit([\"cat-file\", \"-e\", `${snapshot.snapshot}^{commit}`], {\n\t\t\tcwd: root,\n\t\t\tsignal,\n\t\t\tallowExitCodes: [1, 128],\n\t\t});\n\t\treturn exitCode === 0;\n\t} catch (error) {\n\t\tif (isGitUnavailableError(error)) return false;\n\t\tthrow error;\n\t}\n}\n\n/**\n * Where a woken session continues. Each checkout it recorded that it worked in on this node stays as it is, since work\n * done in it after the release belongs to the session, and a blueprint build that failed or did not finish in a worktree\n * this node restored for it runs again. Every other checkout, as when it is missing or another clone sits at its path on another\n * node, is prepared as `/resume` prepares it. When every checkout stays, it continues in the directory it last worked\n * in, after the restores it recorded, which `reopen` opens it in.\n */\nexport async function continueSessionWhereItWorked(\n\topened: SessionManager,\n\toptions: PrepareSessionResumeOptions,\n\treopen: (cwd: string) => Promise<SessionManager> = (cwd) => opened.openSessionById(opened.getSessionId(), cwd),\n): Promise<SessionManager> {\n\tconst cwd = mapRestoredPath(opened.getCwd(), opened.getWorktreeRootMappings());\n\tconst checkouts = currentWorktreeSnapshots(opened);\n\tconst own = await checkoutsWorkedHere(checkouts, cwd, options);\n\tif (own.size < checkouts.size) {\n\t\tconst prepared = await prepareSessionResume(opened, { ...options, keepInPlace: own });\n\t\tif (prepared.status !== \"ready\") return opened;\n\t\tif (prepared.blueprintNotices.length > 0) options.onNotices?.(prepared.blueprintNotices);\n\t\treturn prepared.sessionManager;\n\t}\n\tconst storeDir = resolveStoreDir(options);\n\tif (checkouts.size === 0) {\n\t\tawait describeBlueprintsInPlace(opened, storeDir, options);\n\t} else {\n\t\tconst blueprints = await setUpCheckoutBlueprints(opened, new Set(), storeDir, options);\n\t\tawait recordBlueprintContext(opened, blueprints.context);\n\t\tif (blueprints.notices.length > 0) options.onNotices?.(blueprints.notices);\n\t}\n\treturn cwd === resolve(opened.getCwd()) ? opened : reopen(cwd);\n}\n\n/**\n * The roots of the `checkouts` a session recorded that are here as checkouts it worked in on this node, as it left them\n * or changed since: a worktree this node restored for it, or a checkout whose repository holds the commit of its latest\n * snapshot. The checkout the session works in counts only while its working directory `cwd` is here too.\n */\nasync function checkoutsWorkedHere(\n\tcheckouts: ReadonlyMap<string, WorktreeSnapshot>,\n\tcwd: string,\n\toptions: PrepareSessionResumeOptions,\n): Promise<Set<string>> {\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\tconst own = new Set<string>();\n\tfor (const [root, snapshot] of checkouts) {\n\t\tif (!existsSync(isInside(root, cwd) ? cwd : root)) continue;\n\t\tif (isInside(storeDir, root) || (await holdsSnapshotCommit(snapshot, root, options.signal))) own.add(root);\n\t}\n\treturn own;\n}\n\n/**\n * Whether resuming in `root` restores `snapshot` into a fresh worktree: the checkout is gone, is not a repository of\n * the recorded tree, or no longer matches it. A path that cannot be read fails with its typed `unreadable-path` error\n * instead, since restoring would hide it. A checkout whose HEAD only moved forward over the recorded tree, as after\n * committing the recorded edits, continues in place, as #4245's resume decides. Read-only.\n */\nexport async function worktreeNeedsRestore(\n\tsnapshot: WorktreeSnapshot,\n\troot: string,\n\toptions: VerifyWorktreeOptions,\n): Promise<boolean> {\n\ttry {\n\t\tawait verifyWorktree(snapshot, root, options);\n\t\treturn false;\n\t} catch (error) {\n\t\tif (isWorkspaceDriftError(error)) return !(await isHeadOnlyAdvance(error, options.signal));\n\t\tif (isWorkspaceSnapshotError(error) && error.code !== \"unreadable-path\") return true;\n\t\tthrow error;\n\t}\n}\n\n/** The outcome of starting or provisioning Git once for a resume: the typed reason it cannot run, or undefined. */\ninterface GitProbe {\n\treadonly unavailable: GitUnavailableError | undefined;\n}\n\n/**\n * Decides what the resume does about the `candidates` that are gone or changed here, before anything is written. The\n * precondition of restoring them on this node is that Git can be started or provisioned (`git`, the probe's typed\n * failure). When it is unmet and the session works in a checkout that must be restored, the resume is refused; for any\n * other checkout it leaves that checkout out, with a warning. A blueprint is never a precondition.\n */\nfunction planRestores(\n\tsessionManager: SessionManager,\n\tcandidates: { readonly targets: readonly RestoreTarget[]; readonly left: ReadonlyMap<string, ResumeNotice> },\n\toptions: PrepareSessionResumeOptions,\n\tgit: GitUnavailableError | undefined,\n): RestorePlan {\n\tconst required = candidates.targets.filter((target) => target.runsHere);\n\tconst others = candidates.targets.filter((target) => !target.runsHere);\n\tif (required.length > 0 && git !== undefined) {\n\t\tthrow preconditionFailure(sessionManager, [...required, ...others], options, git);\n\t}\n\tconst left = new Map(candidates.left);\n\tconst optional: RestoreTarget[] = [];\n\tfor (const target of others) {\n\t\tif (git) {\n\t\t\tleft.set(\n\t\t\t\ttarget.root,\n\t\t\t\tnotRestored(\n\t\t\t\t\ttarget.root,\n\t\t\t\t\ttarget.snapshot,\n\t\t\t\t\t`${absentOrChanged(target)}, and Git is unavailable here (${git.code}), which restoring it needs`,\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\toptional.push(target);\n\t\t}\n\t}\n\treturn { required, optional, left };\n}\n\n/** The refusal to resume because `targets` cannot be restored here: Git cannot be started or provisioned. */\nfunction preconditionFailure(\n\tsessionManager: SessionManager,\n\ttargets: readonly RestoreTarget[],\n\toptions: PrepareSessionResumeOptions,\n\tgit: GitUnavailableError,\n): ResumePreconditionError {\n\tconst reasons = targets.map(\n\t\t(target) =>\n\t\t\t`snapshot ${target.snapshot.id.slice(0, 12)} because ${target.root} ${target.absent ? \"does not exist on this node\" : \"no longer matches it\"}`,\n\t);\n\tconst problems = [\n\t\tgitUnavailableProblem(\n\t\t\tgit,\n\t\t\t`session ${sessionManager.getSessionId()} must be restored from ${reasons.join(\", and from \")}`,\n\t\t),\n\t];\n\treturn new ResumePreconditionError({ entryPoint: options.entryPoint, problems }, git);\n}\n\n/**\n * Whether a restored worktree is trusted to run its blueprints outside the CLI: the decision saved in `agentDir` for\n * that path, else the default trust setting.\n */\nexport function savedProjectTrust(\n\tagentDir: string,\n\tsettings: Pick<SettingsManager, \"getDefaultProjectTrust\">,\n): (worktree: string) => boolean {\n\tconst trustStore = new ProjectTrustStore(agentDir);\n\treturn (worktree) => trustStore.get(worktree) ?? settings.getDefaultProjectTrust() === \"always\";\n}\n\n/** Where restored worktrees, the blueprint build ledger and logs live for the agent directory `agentDir`. */\nexport function resumeStoreDir(agentDir: string): string {\n\treturn join(agentDir, \"worktree-snapshots\");\n}\n\nfunction resolveStoreDir(options: Pick<PrepareSessionResumeOptions, \"storeDir\">): string {\n\treturn resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n}\n\n/**\n * The options a resume from `launchCwd` needs: snapshot settings and the blueprint build configuration from\n * `settingsManager`, and the worktree store of `agentDir`.\n */\nexport function sessionResumeOptions(\n\tentryPoint: ResumeEntryPoint,\n\tlaunchCwd: string,\n\tagentDir: string,\n\tsettingsManager: Pick<SettingsManager, \"getWorktreeSnapshotSettings\" | \"getResumeSetupCommand\">,\n\ttrusted: (worktree: string) => boolean,\n): PrepareSessionResumeOptions {\n\treturn {\n\t\tentryPoint,\n\t\tlaunchCwd,\n\t\tsettings: settingsManager.getWorktreeSnapshotSettings(),\n\t\tblueprint: { agentDir, setupCommand: settingsManager.getResumeSetupCommand(), trusted },\n\t\tstoreDir: resumeStoreDir(agentDir),\n\t};\n}\n"]}
|
|
@@ -22,6 +22,22 @@ export interface RetryDecision {
|
|
|
22
22
|
/** Server retry hint, capped by `maxRetryDelayMs`, or else the exponential backoff to wait before that retry. */
|
|
23
23
|
readonly delayMs: number;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* An attempt whose response stream ended early after at least this long ran long enough that a repeat is likely to be
|
|
27
|
+
* cut again (#4626). A stream cut sooner keeps the ordinary retry budget.
|
|
28
|
+
*/
|
|
29
|
+
export declare const LONG_STREAM_CUT_MS = 300000;
|
|
30
|
+
/** Same-model retries allowed after an attempt whose stream was cut after `LONG_STREAM_CUT_MS`. */
|
|
31
|
+
export declare const MAX_LONG_STREAM_CUT_RETRIES = 1;
|
|
32
|
+
/** Whether the failure is a stream that ended early after an attempt that ran at least `LONG_STREAM_CUT_MS`. */
|
|
33
|
+
export declare function isLongStreamCut(failure: unknown): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the failure is a long stream cut after the model's long stream cuts have already been retried
|
|
36
|
+
* `MAX_LONG_STREAM_CUT_RETRIES` times: another attempt is likely to be cut again, so the same model is not retried.
|
|
37
|
+
*/
|
|
38
|
+
export declare function repeatsLongStreamCut(failure: unknown, longStreamCutRetriesSpent: number): boolean;
|
|
39
|
+
/** What to do when the same model keeps being cut after long attempts and is no longer retried. */
|
|
40
|
+
export declare const LONG_STREAM_CUT_ADVICE = "Atomic stopped retrying this model after its stream was cut again after 5 minutes or more, because another attempt is likely to be cut too. Split the work into smaller steps, lower the thinking effort, or switch to another model; the fallbackModels setting switches models automatically.";
|
|
25
41
|
/**
|
|
26
42
|
* Decide whether one more attempt against the same target is allowed.
|
|
27
43
|
*
|
|
@@ -29,6 +45,8 @@ export interface RetryDecision {
|
|
|
29
45
|
* @param retriesSpent retries already made for this failure
|
|
30
46
|
* @param eligible whether this failure can be repaired by requesting again
|
|
31
47
|
* @param failure the failed message, whose server retry hint replaces the backoff
|
|
48
|
+
* @param longStreamCutRetriesSpent retries already made after an attempt whose stream was cut after
|
|
49
|
+
* `LONG_STREAM_CUT_MS`; a caller that does not track them gets no limit on long stream cuts
|
|
32
50
|
*/
|
|
33
|
-
export declare function nextRetryDecision(settings: RetryPolicySettings | undefined, retriesSpent: number, eligible: boolean, failure?: Pick<AssistantMessage, "retryAfterMs"
|
|
51
|
+
export declare function nextRetryDecision(settings: RetryPolicySettings | undefined, retriesSpent: number, eligible: boolean, failure?: Pick<AssistantMessage, "retryAfterMs" | "diagnostics">, longStreamCutRetriesSpent?: number): RetryDecision | undefined;
|
|
34
52
|
//# sourceMappingURL=retry-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-policy.d.ts","sourceRoot":"","sources":["../../src/core/retry-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"retry-policy.d.ts","sourceRoot":"","sources":["../../src/core/retry-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;AAG5E,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iHAAiH;IACjH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,SAAU,CAAC;AAE1C,mGAAmG;AACnG,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,gHAAgH;AAChH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,GAAG,OAAO,CAEjG;AAED,mGAAmG;AACnG,eAAO,MAAM,sBAAsB,oSAAiU,CAAC;AAErW;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,EACzC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,cAAc,GAAG,aAAa,CAAM,EACpE,yBAAyB,SAAI,GAC3B,aAAa,GAAG,SAAS,CAO3B"}
|
|
@@ -9,6 +9,27 @@
|
|
|
9
9
|
* handling, sleeping, and whether the chain may advance afterwards.
|
|
10
10
|
*/
|
|
11
11
|
import { failureRetryDelayMs } from "@bastani/pi-ai";
|
|
12
|
+
import { streamCutDurationMs } from "./model-fallback-failures.js";
|
|
13
|
+
/**
|
|
14
|
+
* An attempt whose response stream ended early after at least this long ran long enough that a repeat is likely to be
|
|
15
|
+
* cut again (#4626). A stream cut sooner keeps the ordinary retry budget.
|
|
16
|
+
*/
|
|
17
|
+
export const LONG_STREAM_CUT_MS = 300_000;
|
|
18
|
+
/** Same-model retries allowed after an attempt whose stream was cut after `LONG_STREAM_CUT_MS`. */
|
|
19
|
+
export const MAX_LONG_STREAM_CUT_RETRIES = 1;
|
|
20
|
+
/** Whether the failure is a stream that ended early after an attempt that ran at least `LONG_STREAM_CUT_MS`. */
|
|
21
|
+
export function isLongStreamCut(failure) {
|
|
22
|
+
return (streamCutDurationMs(failure) ?? 0) >= LONG_STREAM_CUT_MS;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether the failure is a long stream cut after the model's long stream cuts have already been retried
|
|
26
|
+
* `MAX_LONG_STREAM_CUT_RETRIES` times: another attempt is likely to be cut again, so the same model is not retried.
|
|
27
|
+
*/
|
|
28
|
+
export function repeatsLongStreamCut(failure, longStreamCutRetriesSpent) {
|
|
29
|
+
return longStreamCutRetriesSpent >= MAX_LONG_STREAM_CUT_RETRIES && isLongStreamCut(failure);
|
|
30
|
+
}
|
|
31
|
+
/** What to do when the same model keeps being cut after long attempts and is no longer retried. */
|
|
32
|
+
export const LONG_STREAM_CUT_ADVICE = `Atomic stopped retrying this model after its stream was cut again after ${LONG_STREAM_CUT_MS / 60_000} minutes or more, because another attempt is likely to be cut too. Split the work into smaller steps, lower the thinking effort, or switch to another model; the fallbackModels setting switches models automatically.`;
|
|
12
33
|
/**
|
|
13
34
|
* Decide whether one more attempt against the same target is allowed.
|
|
14
35
|
*
|
|
@@ -16,11 +37,15 @@ import { failureRetryDelayMs } from "@bastani/pi-ai";
|
|
|
16
37
|
* @param retriesSpent retries already made for this failure
|
|
17
38
|
* @param eligible whether this failure can be repaired by requesting again
|
|
18
39
|
* @param failure the failed message, whose server retry hint replaces the backoff
|
|
40
|
+
* @param longStreamCutRetriesSpent retries already made after an attempt whose stream was cut after
|
|
41
|
+
* `LONG_STREAM_CUT_MS`; a caller that does not track them gets no limit on long stream cuts
|
|
19
42
|
*/
|
|
20
|
-
export function nextRetryDecision(settings, retriesSpent, eligible, failure = {}) {
|
|
43
|
+
export function nextRetryDecision(settings, retriesSpent, eligible, failure = {}, longStreamCutRetriesSpent = 0) {
|
|
21
44
|
if (settings === undefined || !settings.enabled || !eligible || retriesSpent >= settings.maxRetries) {
|
|
22
45
|
return undefined;
|
|
23
46
|
}
|
|
47
|
+
if (repeatsLongStreamCut(failure, longStreamCutRetriesSpent))
|
|
48
|
+
return undefined;
|
|
24
49
|
const attempt = retriesSpent + 1;
|
|
25
50
|
return { attempt, delayMs: failureRetryDelayMs(settings, attempt, failure) };
|
|
26
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-policy.js","sourceRoot":"","sources":["../../src/core/retry-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAyB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"retry-policy.js","sourceRoot":"","sources":["../../src/core/retry-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAyB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAiBnE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C,mGAAmG;AACnG,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C,gHAAgH;AAChH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC/C,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,kBAAkB,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,yBAAiC;IACvF,OAAO,yBAAyB,IAAI,2BAA2B,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AAC7F,CAAC;AAED,mGAAmG;AACnG,MAAM,CAAC,MAAM,sBAAsB,GAAG,2EAA2E,kBAAkB,GAAG,MAAM,wNAAwN,CAAC;AAErW;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAChC,QAAyC,EACzC,YAAoB,EACpB,QAAiB,EACjB,OAAO,GAA2D,EAAE,EACpE,yBAAyB,GAAG,CAAC;IAE7B,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,IAAI,YAAY,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;QACrG,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,oBAAoB,CAAC,OAAO,EAAE,yBAAyB,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/E,MAAM,OAAO,GAAG,YAAY,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["/**\n * The one bounded same-target retry policy.\n *\n * Main chat and workflow stages both retry a failing model before spending a\n * fallback candidate. Keeping the gate and the backoff curve here means the two\n * cannot drift into different budgets for the same `settings.retry` values.\n *\n * Callers keep their own concerns: attempt state, lifecycle events, abort\n * handling, sleeping, and whether the chain may advance afterwards.\n */\n\nimport { type AssistantMessage, failureRetryDelayMs } from \"@bastani/pi-ai\";\nimport { streamCutDurationMs } from \"./model-fallback-failures.ts\";\n\nexport interface RetryPolicySettings {\n\treadonly enabled: boolean;\n\treadonly maxRetries: number;\n\treadonly baseDelayMs: number;\n\treadonly maxAgentDelayMs?: number;\n\treadonly maxRetryDelayMs?: number;\n}\n\nexport interface RetryDecision {\n\t/** 1-based number of the retry this decision authorizes. */\n\treadonly attempt: number;\n\t/** Server retry hint, capped by `maxRetryDelayMs`, or else the exponential backoff to wait before that retry. */\n\treadonly delayMs: number;\n}\n\n/**\n * An attempt whose response stream ended early after at least this long ran long enough that a repeat is likely to be\n * cut again (#4626). A stream cut sooner keeps the ordinary retry budget.\n */\nexport const LONG_STREAM_CUT_MS = 300_000;\n\n/** Same-model retries allowed after an attempt whose stream was cut after `LONG_STREAM_CUT_MS`. */\nexport const MAX_LONG_STREAM_CUT_RETRIES = 1;\n\n/** Whether the failure is a stream that ended early after an attempt that ran at least `LONG_STREAM_CUT_MS`. */\nexport function isLongStreamCut(failure: unknown): boolean {\n\treturn (streamCutDurationMs(failure) ?? 0) >= LONG_STREAM_CUT_MS;\n}\n\n/**\n * Whether the failure is a long stream cut after the model's long stream cuts have already been retried\n * `MAX_LONG_STREAM_CUT_RETRIES` times: another attempt is likely to be cut again, so the same model is not retried.\n */\nexport function repeatsLongStreamCut(failure: unknown, longStreamCutRetriesSpent: number): boolean {\n\treturn longStreamCutRetriesSpent >= MAX_LONG_STREAM_CUT_RETRIES && isLongStreamCut(failure);\n}\n\n/** What to do when the same model keeps being cut after long attempts and is no longer retried. */\nexport const LONG_STREAM_CUT_ADVICE = `Atomic stopped retrying this model after its stream was cut again after ${LONG_STREAM_CUT_MS / 60_000} minutes or more, because another attempt is likely to be cut too. Split the work into smaller steps, lower the thinking effort, or switch to another model; the fallbackModels setting switches models automatically.`;\n\n/**\n * Decide whether one more attempt against the same target is allowed.\n *\n * @param settings retry settings, or `undefined` when the caller has none\n * @param retriesSpent retries already made for this failure\n * @param eligible whether this failure can be repaired by requesting again\n * @param failure the failed message, whose server retry hint replaces the backoff\n * @param longStreamCutRetriesSpent retries already made after an attempt whose stream was cut after\n * `LONG_STREAM_CUT_MS`; a caller that does not track them gets no limit on long stream cuts\n */\nexport function nextRetryDecision(\n\tsettings: RetryPolicySettings | undefined,\n\tretriesSpent: number,\n\teligible: boolean,\n\tfailure: Pick<AssistantMessage, \"retryAfterMs\" | \"diagnostics\"> = {},\n\tlongStreamCutRetriesSpent = 0,\n): RetryDecision | undefined {\n\tif (settings === undefined || !settings.enabled || !eligible || retriesSpent >= settings.maxRetries) {\n\t\treturn undefined;\n\t}\n\tif (repeatsLongStreamCut(failure, longStreamCutRetriesSpent)) return undefined;\n\tconst attempt = retriesSpent + 1;\n\treturn { attempt, delayMs: failureRetryDelayMs(settings, attempt, failure) };\n}\n"]}
|
package/dist/core/sdk.js
CHANGED
|
@@ -186,7 +186,7 @@ async function acquireSessionPermit(admission, options) {
|
|
|
186
186
|
/**
|
|
187
187
|
* A supplied session that recorded worktree snapshots, prepared the way `atomic --session` prepares it: continued in
|
|
188
188
|
* its recorded checkout when that still matches, in a matching checkout, or in a worktree restored from its snapshot,
|
|
189
|
-
* with
|
|
189
|
+
* with its blueprints built. The checkout is compared under the `snapshots` the session itself records with. A session
|
|
190
190
|
* without snapshots is returned unchanged, so creating it costs no Git call.
|
|
191
191
|
*/
|
|
192
192
|
async function sessionResumedOnThisNode(sessionManager, agentDir, settingsManager, snapshots) {
|