@bastani/atomic 0.9.74-alpha.1 → 0.9.75-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/agent-browser/SKILL.md +8 -10
- package/dist/builtin/subagents/skills/agent-desktop/SKILL.md +9 -5
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -1
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +48 -0
- package/dist/builtin/workflows/README.md +5 -2
- package/dist/builtin/workflows/builtin/{chunk-m8eg152f.js → chunk-89we7r4p.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-a4fdm2cw.js → chunk-8yfssw01.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-774myqzs.js → chunk-v8mb0005.js} +366 -45
- package/dist/builtin/workflows/builtin/{chunk-d5cxskkp.js → chunk-wh2p4qjg.js} +2 -2
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.d.ts +10 -0
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +12 -0
- package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +3 -2
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +19 -0
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +15 -8
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +2 -0
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +8 -6
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +0 -1
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/engine-checksums.txt +9 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +98 -44
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +101 -34
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +6 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +4 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +444 -144
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +3 -1
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +13 -11
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +10 -8
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_2.md +143 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_haiku_5_5.md +11 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +6 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +7 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5_5.md +3 -3
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +6 -5
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_sol.md +4 -4
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_terra.md +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -3
- package/dist/builtin/workflows/skills/skill-creator/scripts/aggregate_benchmark.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/generate_report.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/improve_description.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/package_skill.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/quick_validate.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +0 -0
- package/dist/builtin/workflows/skills/skill-creator/scripts/run_loop.py +0 -0
- package/dist/builtin/workflows/skills/unslop/SKILL.md +15 -34
- package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +1 -0
- package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +809 -410
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/index.js +685 -295
- package/dist/builtin/workflows/src/local-worker-entry.mjs +695 -305
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +6 -6
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +2 -2
- package/dist/builtin/workflows/src/shared/serializable-error-families.d.ts +2 -0
- package/dist/bun/app-host-modules.d.ts +1 -1
- package/dist/bun/app-host-modules.d.ts.map +1 -1
- package/dist/bun/app-host-modules.js.map +1 -1
- package/dist/bun/internal-workflow-worker.d.ts +2 -0
- package/dist/bun/internal-workflow-worker.d.ts.map +1 -1
- package/dist/bun/internal-workflow-worker.js +2 -1
- package/dist/bun/internal-workflow-worker.js.map +1 -1
- package/dist/codemode-worker.js +2 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +2 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-blueprint-environment.d.ts +10 -0
- package/dist/core/agent-session-blueprint-environment.d.ts.map +1 -0
- package/dist/core/agent-session-blueprint-environment.js +28 -0
- package/dist/core/agent-session-blueprint-environment.js.map +1 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +2 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +1 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +14 -4
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +20 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +55 -6
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +2 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/async-scope.d.ts +13 -0
- package/dist/core/async-scope.d.ts.map +1 -0
- package/dist/core/async-scope.js +20 -0
- package/dist/core/async-scope.js.map +1 -0
- package/dist/core/cache-warmer.d.ts +3 -14
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +8 -60
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/extensions/extension-work.js +2 -2
- package/dist/core/extensions/extension-work.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +3 -1
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +2 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +1 -1
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +4 -2
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts +6 -0
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +10 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/preferred-providers.d.ts +19 -0
- package/dist/core/preferred-providers.d.ts.map +1 -0
- package/dist/core/preferred-providers.js +25 -0
- package/dist/core/preferred-providers.js.map +1 -0
- package/dist/core/provider-alias.d.ts.map +1 -1
- package/dist/core/provider-alias.js +4 -0
- package/dist/core/provider-alias.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +1 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +3 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resume/blueprint/action-expressions.d.ts +32 -0
- package/dist/core/resume/blueprint/action-expressions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/action-expressions.js +389 -0
- package/dist/core/resume/blueprint/action-expressions.js.map +1 -0
- package/dist/core/resume/blueprint/actions.d.ts +90 -0
- package/dist/core/resume/blueprint/actions.d.ts.map +1 -0
- package/dist/core/resume/blueprint/actions.js +818 -0
- package/dist/core/resume/blueprint/actions.js.map +1 -0
- package/dist/core/resume/blueprint/build.d.ts +102 -0
- package/dist/core/resume/blueprint/build.d.ts.map +1 -0
- package/dist/core/resume/blueprint/build.js +535 -0
- package/dist/core/resume/blueprint/build.js.map +1 -0
- package/dist/core/resume/blueprint/context.d.ts +11 -0
- package/dist/core/resume/blueprint/context.d.ts.map +1 -0
- package/dist/core/resume/blueprint/context.js +106 -0
- package/dist/core/resume/blueprint/context.js.map +1 -0
- package/dist/core/resume/blueprint/envrc.d.ts +19 -0
- package/dist/core/resume/blueprint/envrc.d.ts.map +1 -0
- package/dist/core/resume/blueprint/envrc.js +77 -0
- package/dist/core/resume/blueprint/envrc.js.map +1 -0
- package/dist/core/resume/blueprint/errors.d.ts +179 -0
- package/dist/core/resume/blueprint/errors.d.ts.map +1 -0
- package/dist/core/resume/blueprint/errors.js +169 -0
- package/dist/core/resume/blueprint/errors.js.map +1 -0
- package/dist/core/resume/blueprint/ledger.d.ts +51 -0
- package/dist/core/resume/blueprint/ledger.d.ts.map +1 -0
- package/dist/core/resume/blueprint/ledger.js +119 -0
- package/dist/core/resume/blueprint/ledger.js.map +1 -0
- package/dist/core/resume/blueprint/notices.d.ts +14 -0
- package/dist/core/resume/blueprint/notices.d.ts.map +1 -0
- package/dist/core/resume/blueprint/notices.js +44 -0
- package/dist/core/resume/blueprint/notices.js.map +1 -0
- package/dist/core/resume/blueprint/process.d.ts +44 -0
- package/dist/core/resume/blueprint/process.d.ts.map +1 -0
- package/dist/core/resume/blueprint/process.js +142 -0
- package/dist/core/resume/blueprint/process.js.map +1 -0
- package/dist/core/resume/blueprint/resume.d.ts +73 -0
- package/dist/core/resume/blueprint/resume.d.ts.map +1 -0
- package/dist/core/resume/blueprint/resume.js +206 -0
- package/dist/core/resume/blueprint/resume.js.map +1 -0
- package/dist/core/resume/blueprint/schema.d.ts +26 -0
- package/dist/core/resume/blueprint/schema.d.ts.map +1 -0
- package/dist/core/resume/blueprint/schema.js +243 -0
- package/dist/core/resume/blueprint/schema.js.map +1 -0
- package/dist/core/resume/blueprint/steps.d.ts +54 -0
- package/dist/core/resume/blueprint/steps.d.ts.map +1 -0
- package/dist/core/resume/blueprint/steps.js +155 -0
- package/dist/core/resume/blueprint/steps.js.map +1 -0
- package/dist/core/resume/blueprint/types.d.ts +63 -0
- package/dist/core/resume/blueprint/types.d.ts.map +1 -0
- package/dist/core/resume/blueprint/types.js +2 -0
- package/dist/core/resume/blueprint/types.js.map +1 -0
- package/dist/core/resume/errors.d.ts +7 -35
- package/dist/core/resume/errors.d.ts.map +1 -1
- package/dist/core/resume/errors.js +1 -21
- package/dist/core/resume/errors.js.map +1 -1
- package/dist/core/resume/index.d.ts +12 -4
- package/dist/core/resume/index.d.ts.map +1 -1
- package/dist/core/resume/index.js +11 -4
- package/dist/core/resume/index.js.map +1 -1
- package/dist/core/resume/run-setup.d.ts +36 -15
- package/dist/core/resume/run-setup.d.ts.map +1 -1
- package/dist/core/resume/run-setup.js +70 -54
- package/dist/core/resume/run-setup.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +34 -20
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +244 -106
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/retry-policy.d.ts +19 -1
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +26 -1
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +56 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +94 -4
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +10 -5
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-worktree-snapshots.d.ts +11 -0
- package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
- package/dist/core/session-worktree-snapshots.js +10 -4
- package/dist/core/session-worktree-snapshots.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +1 -1
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +1 -1
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +3 -2
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +2 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/storage/write-ahead-log.d.ts +2 -1
- package/dist/core/storage/write-ahead-log.d.ts.map +1 -1
- package/dist/core/storage/write-ahead-log.js +27 -6
- package/dist/core/storage/write-ahead-log.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/file-tool-errors.d.ts +1 -1
- package/dist/core/tools/file-tool-errors.js +1 -1
- package/dist/core/tools/file-tool-errors.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +52 -26
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +10 -2
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/tool-concurrency.d.ts.map +1 -1
- package/dist/core/tools/tool-concurrency.js +2 -2
- package/dist/core/tools/tool-concurrency.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts +12 -4
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +28 -4
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +5 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +6 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +34 -13
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/provider-brand.d.ts +16 -0
- package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -0
- package/dist/modes/interactive/components/provider-brand.js +67 -0
- package/dist/modes/interactive/components/provider-brand.js.map +1 -0
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +8 -6
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.js +4 -3
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +8 -3
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -2
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +59 -21
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +23 -12
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/login-provider-options.d.ts.map +1 -1
- package/dist/modes/interactive/login-provider-options.js +2 -1
- package/dist/modes/interactive/login-provider-options.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +2 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +8 -3
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -1
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +0 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +2 -18
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +8 -2
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-error-decoding.d.ts +7 -0
- package/dist/modes/rpc/rpc-error-decoding.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-error-decoding.js +25 -0
- package/dist/modes/rpc/rpc-error-decoding.js.map +1 -0
- package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-responses.js +12 -0
- package/dist/modes/rpc/rpc-responses.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +11 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +12 -3
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/codemode.md +22 -0
- package/docs/extensions/api-reference.md +27 -1
- package/docs/extensions/authoring.md +1 -1
- package/docs/extensions/ui.md +1 -1
- package/docs/getting-started/first-session.md +1 -1
- package/docs/guides/resume-on-any-machine.md +72 -19
- package/docs/models/evals.md +85 -17
- package/docs/models/reference.md +1 -1
- package/docs/providers.md +38 -5
- package/docs/reference/cli.md +2 -0
- package/docs/rpc/protocol.md +11 -1
- package/docs/sdk/reference.md +36 -4
- package/docs/sdk.md +2 -2
- package/docs/sessions.md +11 -1
- package/docs/settings.md +7 -2
- package/docs/skills.md +3 -3
- package/docs/storage.md +1 -1
- package/docs/tools.md +3 -1
- package/docs/workflows/api-reference.md +14 -12
- package/docs/workflows/authoring.md +29 -1
- package/docs/workflows/builtins.md +9 -1
- package/docs/workflows/operations.md +8 -8
- package/docs/worktree-snapshots.md +3 -2
- package/npm-shrinkwrap.json +83 -67
- package/package.json +7 -7
- package/schemas/settings.schema.json +3 -2
- package/dist/core/resume/setup-hook.d.ts +0 -69
- package/dist/core/resume/setup-hook.d.ts.map +0 -1
- package/dist/core/resume/setup-hook.js +0 -261
- package/dist/core/resume/setup-hook.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EAEnB,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AAkEjC;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACtB,IAAI,GAAuB,gBAAgB,CAAC;I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AC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;KAChH,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import {\n\tfindInCauseChain,\n\trehydrateErrorCause,\n\ttype SerializedErrorCause,\n\tserializeErrorCause,\n} from \"../../error-contract.ts\";\n\nexport type BlueprintErrorFieldValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly BlueprintErrorFieldValue[]\n\t| { readonly [key: string]: BlueprintErrorFieldValue };\nexport type BlueprintErrorFields = { readonly [key: string]: BlueprintErrorFieldValue };\n\n/** Which layer a blueprint belongs to: the global file, a repository root, or an included workspace. */\nexport type BlueprintScope = \"global\" | \"repository\" | \"workspace\";\n/** The sections whose steps a build runs. `knowledge` is never run. */\nexport type BlueprintSection = \"initialize\" | \"maintenance\" | \"post-build\";\n\nexport type BlueprintInvalidErrorCode = \"blueprint-invalid\";\nexport type BlueprintStepFailedErrorCode = \"blueprint-step-failed\";\nexport type BlueprintStepTimedOutErrorCode = \"blueprint-step-timed-out\";\nexport type BlueprintUsesUnsupportedErrorCode = \"blueprint-uses-unsupported\";\nexport type BlueprintBuildFailedErrorCode = \"blueprint-build-failed\";\nexport type BlueprintErrorCode =\n\t| BlueprintInvalidErrorCode\n\t| BlueprintStepFailedErrorCode\n\t| BlueprintStepTimedOutErrorCode\n\t| BlueprintUsesUnsupportedErrorCode\n\t| BlueprintBuildFailedErrorCode;\nexport type BlueprintErrorName =\n\t| \"BlueprintError\"\n\t| \"BlueprintInvalidError\"\n\t| \"BlueprintStepFailedError\"\n\t| \"BlueprintStepTimedOutError\"\n\t| \"BlueprintUsesUnsupportedError\"\n\t| \"BlueprintBuildFailedError\";\n\n/**\n * Why a blueprint file is invalid. `yaml-syntax` is a file that is not YAML; `not-a-mapping` a document that is not a\n * mapping; the rest name the Devin rule that was broken.\n */\nexport type BlueprintInvalidReason =\n\t| \"yaml-syntax\"\n\t| \"not-a-mapping\"\n\t| \"invalid-shell\"\n\t| \"invalid-field\"\n\t| \"uses-in-maintenance\"\n\t| \"run-and-uses\"\n\t| \"missing-run-or-uses\"\n\t| \"with-without-uses\"\n\t| \"invalid-uses-reference\"\n\t| \"duplicate-platform\"\n\t| \"nested-includes\"\n\t| \"include-parent-path\"\n\t| \"duplicate-include\"\n\t| \"post-build-not-global\";\n\n/** Where one step of a blueprint sits, for the errors that name a failing step. */\nexport interface BlueprintStepLocation {\n\treadonly blueprint: string;\n\treadonly scope: BlueprintScope;\n\treadonly section: BlueprintSection;\n\t/** Zero-based position within the section. */\n\treadonly index: number;\n\t/** The step's `name`, or `<section> step <n>` when it has none. */\n\treadonly step: string;\n}\n\n/**\n * Base of every failure a blueprint can cause. Resuming never throws these: a build records them in its outcome so a\n * resume continues with a warning. Branch on `code` or the class, never on `message`. `fields` holds the same\n * JSON-safe facts as the typed properties.\n */\nexport class BlueprintError extends Error {\n\toverride readonly name: BlueprintErrorName = \"BlueprintError\";\n\treadonly code: BlueprintErrorCode;\n\treadonly hint: string;\n\treadonly retryable: boolean = false;\n\treadonly fields: BlueprintErrorFields;\n\n\tconstructor(code: BlueprintErrorCode, summary: string, hint: string, fields: BlueprintErrorFields, cause?: Error) {\n\t\tsuper(`${summary} (${code}). ${hint}`, cause === undefined ? undefined : { cause });\n\t\tthis.code = code;\n\t\tthis.hint = hint;\n\t\tthis.fields = Object.freeze({ ...fields });\n\t\tObject.assign(this, fields);\n\t}\n}\n\nexport interface BlueprintInvalidErrorFields {\n\t/** The blueprint file. */\n\treadonly blueprint: string;\n\treadonly scope: BlueprintScope;\n\treadonly reason: BlueprintInvalidReason;\n\t/** The rule that was broken: Devin's own wording for the rules it words, else a short description. */\n\treadonly rule: string;\n\t/** The section, include entry or field that broke it, when there is one. */\n\treadonly subject: string | null;\n}\n\n/** A blueprint file breaks the schema or a validation rule. The blueprint's setup is skipped; the resume continues. */\nexport class BlueprintInvalidError extends BlueprintError {\n\toverride readonly name = \"BlueprintInvalidError\" as const;\n\tdeclare readonly code: BlueprintInvalidErrorCode;\n\tdeclare readonly blueprint: string;\n\tdeclare readonly scope: BlueprintScope;\n\tdeclare readonly reason: BlueprintInvalidReason;\n\tdeclare readonly rule: string;\n\tdeclare readonly subject: string | null;\n\n\tconstructor(fields: BlueprintInvalidErrorFields, cause?: Error) {\n\t\tsuper(\n\t\t\t\"blueprint-invalid\",\n\t\t\t`The ${fields.scope} blueprint ${fields.blueprint} is invalid: ${fields.rule}${fields.subject === null ? \"\" : ` (${fields.subject})`}`,\n\t\t\t\"Fix the blueprint; the next build picks the change up.\",\n\t\t\t{ ...fields },\n\t\t\tcause,\n\t\t);\n\t}\n}\n\nexport interface BlueprintStepFailedErrorFields extends BlueprintStepLocation {\n\treadonly exitStatus: number | null;\n\treadonly signal: string | null;\n\t/** The step's captured output; null when its log could not be created, so the step was not started. */\n\treadonly logPath: string | null;\n}\n\n/** A step exited non-zero, was stopped by a signal or could not be started. The rest of its blueprint did not run. */\nexport class BlueprintStepFailedError extends BlueprintError {\n\toverride readonly name = \"BlueprintStepFailedError\" as const;\n\tdeclare readonly code: BlueprintStepFailedErrorCode;\n\tdeclare readonly blueprint: string;\n\tdeclare readonly scope: BlueprintScope;\n\tdeclare readonly section: BlueprintSection;\n\tdeclare readonly index: number;\n\tdeclare readonly step: string;\n\tdeclare readonly exitStatus: number | null;\n\tdeclare readonly signal: string | null;\n\tdeclare readonly logPath: string | null;\n\n\tconstructor(fields: BlueprintStepFailedErrorFields, cause?: Error) {\n\t\tconst outcome =\n\t\t\tfields.signal !== null\n\t\t\t\t? `was stopped by ${fields.signal}`\n\t\t\t\t: fields.exitStatus === null\n\t\t\t\t\t? \"could not be started\"\n\t\t\t\t\t: `exited with status ${fields.exitStatus}`;\n\t\tsuper(\n\t\t\t\"blueprint-step-failed\",\n\t\t\t`The ${fields.section} step \"${fields.step}\" of the ${fields.scope} blueprint ${fields.blueprint} ${outcome}`,\n\t\t\tfields.logPath === null\n\t\t\t\t? \"Make the build directory under the agent directory writable, then the next build runs the step again.\"\n\t\t\t\t: `Check the build log ${fields.logPath} for the exact error, then fix the environment and the blueprint; the next build runs it again.`,\n\t\t\t{ ...fields },\n\t\t\tcause,\n\t\t);\n\t}\n}\n\nexport interface BlueprintStepTimedOutErrorFields extends BlueprintStepLocation {\n\treadonly logPath: string;\n\treadonly timeoutMs: number;\n\treadonly elapsedMs: number;\n\t/** The section that was running. */\n\treadonly phase: BlueprintSection;\n}\n\n/** A step did not finish within its timeout (3 hours) and was stopped. The rest of its blueprint did not run. */\nexport class BlueprintStepTimedOutError extends BlueprintError {\n\toverride readonly name = \"BlueprintStepTimedOutError\" as const;\n\tdeclare readonly code: BlueprintStepTimedOutErrorCode;\n\tdeclare readonly blueprint: string;\n\tdeclare readonly scope: BlueprintScope;\n\tdeclare readonly section: BlueprintSection;\n\tdeclare readonly index: number;\n\tdeclare readonly step: string;\n\tdeclare readonly logPath: string;\n\tdeclare readonly timeoutMs: number;\n\tdeclare readonly elapsedMs: number;\n\tdeclare readonly phase: BlueprintSection;\n\n\tconstructor(fields: BlueprintStepTimedOutErrorFields, cause?: Error) {\n\t\tsuper(\n\t\t\t\"blueprint-step-timed-out\",\n\t\t\t`The ${fields.section} step \"${fields.step}\" of the ${fields.scope} blueprint ${fields.blueprint} did not finish within ${fields.timeoutMs} ms`,\n\t\t\t`Check the build log ${fields.logPath}, make the step finish sooner or non-interactive, then fix the blueprint; the next build runs it again.`,\n\t\t\t{ ...fields },\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** Why a `uses` step cannot run here. */\nexport type BlueprintUsesUnsupportedReason =\n\t| \"docker-action\"\n\t| \"unknown-action-type\"\n\t| \"action-not-found\"\n\t| \"action-fetch-failed\"\n\t| \"action-metadata-invalid\"\n\t| \"node-unavailable\"\n\t| \"required-input-missing\"\n\t| \"unsupported-expression\";\n\nexport interface BlueprintUsesUnsupportedErrorFields extends BlueprintStepLocation {\n\t/** The `github.com/<owner>/<repo>[/<subpath>]@<ref>` reference. */\n\treadonly uses: string;\n\treadonly reason: BlueprintUsesUnsupportedReason;\n\t/** A short, credential-free explanation. */\n\treadonly detail: string;\n\treadonly logPath: string;\n}\n\nconst USES_REMEDIATION: Record<BlueprintUsesUnsupportedReason, string> = {\n\t\"docker-action\": \"Replace the action with a `run` step, or use a Node.js or composite action\",\n\t\"unknown-action-type\": \"Replace the action with a `run` step, or use a Node.js or composite action\",\n\t\"required-input-missing\": \"Add the missing input under `with`\",\n\t\"action-not-found\": \"Check the `github.com/<owner>/<repo>@<ref>` reference and that the action has an action.yml\",\n\t\"action-fetch-failed\": \"Check the `github.com/<owner>/<repo>@<ref>` reference and the network access to GitHub\",\n\t\"action-metadata-invalid\": \"Pin a ref whose action.yml is valid\",\n\t\"node-unavailable\": \"Install Node.js and put it on PATH\",\n\t\"unsupported-expression\": \"Pass the value through `with` instead of the unsupported expression, or use a `run` step\",\n};\n\n/** A `uses` step names an action that Atomic cannot run (Docker, or one it cannot fetch or read). */\nexport class BlueprintUsesUnsupportedError extends BlueprintError {\n\toverride readonly name = \"BlueprintUsesUnsupportedError\" as const;\n\tdeclare readonly code: BlueprintUsesUnsupportedErrorCode;\n\tdeclare readonly blueprint: string;\n\tdeclare readonly scope: BlueprintScope;\n\tdeclare readonly section: BlueprintSection;\n\tdeclare readonly index: number;\n\tdeclare readonly step: string;\n\tdeclare readonly uses: string;\n\tdeclare readonly reason: BlueprintUsesUnsupportedReason;\n\tdeclare readonly detail: string;\n\tdeclare readonly logPath: string;\n\n\tconstructor(fields: BlueprintUsesUnsupportedErrorFields, cause?: Error) {\n\t\tsuper(\n\t\t\t\"blueprint-uses-unsupported\",\n\t\t\t`The ${fields.section} step \"${fields.step}\" of the ${fields.scope} blueprint ${fields.blueprint} cannot run ${fields.uses}: ${fields.detail}`,\n\t\t\t`${USES_REMEDIATION[fields.reason]}; details are in ${fields.logPath}.`,\n\t\t\t{ ...fields },\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** What a build was doing when it failed for a reason that is not a step. */\nexport type BlueprintBuildPhase = \"read-blueprint\" | \"ledger\" | \"environment\" | \"unknown\";\n\nexport interface BlueprintBuildFailedErrorFields {\n\treadonly phase: BlueprintBuildPhase;\n\t/** A short, credential-free explanation. */\n\treadonly detail: string;\n}\n\nconst PHASE_ACTIVITY: Record<BlueprintBuildPhase, string> = {\n\t\"read-blueprint\": \"reading a blueprint\",\n\tledger: \"reading or writing the build ledger\",\n\tenvironment: \"preparing the build environment\",\n\tunknown: \"running\",\n};\n\n/**\n * The build machinery itself failed (a blueprint file or the build ledger could not be read or written), not a step.\n * The resume continues without the build.\n */\nexport class BlueprintBuildFailedError extends BlueprintError {\n\toverride readonly name = \"BlueprintBuildFailedError\" as const;\n\tdeclare readonly code: BlueprintBuildFailedErrorCode;\n\tdeclare readonly phase: BlueprintBuildPhase;\n\tdeclare readonly detail: string;\n\n\tconstructor(fields: BlueprintBuildFailedErrorFields, cause?: Error) {\n\t\tsuper(\n\t\t\t\"blueprint-build-failed\",\n\t\t\t`The blueprint build stopped while ${PHASE_ACTIVITY[fields.phase]}: ${fields.detail}`,\n\t\t\t\"Check that the agent directory is readable and writable; the next resume builds again.\",\n\t\t\t{ ...fields },\n\t\t\tcause,\n\t\t);\n\t}\n}\n\nconst CODES: Record<BlueprintErrorName, readonly BlueprintErrorCode[]> = {\n\tBlueprintError: [],\n\tBlueprintInvalidError: [\"blueprint-invalid\"],\n\tBlueprintStepFailedError: [\"blueprint-step-failed\"],\n\tBlueprintStepTimedOutError: [\"blueprint-step-timed-out\"],\n\tBlueprintUsesUnsupportedError: [\"blueprint-uses-unsupported\"],\n\tBlueprintBuildFailedError: [\"blueprint-build-failed\"],\n};\nconst ALL_CODES = new Set(Object.values(CODES).flat());\n\nfunction structurallyIs(value: unknown, name: BlueprintErrorName): boolean {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as { readonly name?: unknown; readonly code?: unknown };\n\tif (name === \"BlueprintError\") {\n\t\treturn (\n\t\t\ttypeof candidate.name === \"string\" &&\n\t\t\tcandidate.name in CODES &&\n\t\t\tALL_CODES.has(candidate.code as BlueprintErrorCode)\n\t\t);\n\t}\n\treturn candidate.name === name && CODES[name].includes(candidate.code as BlueprintErrorCode);\n}\n\nexport function isBlueprintError(value: unknown): value is BlueprintError {\n\treturn value instanceof BlueprintError || structurallyIs(value, \"BlueprintError\");\n}\nexport function isBlueprintInvalidError(value: unknown): value is BlueprintInvalidError {\n\treturn value instanceof BlueprintInvalidError || structurallyIs(value, \"BlueprintInvalidError\");\n}\nexport function isBlueprintStepFailedError(value: unknown): value is BlueprintStepFailedError {\n\treturn value instanceof BlueprintStepFailedError || structurallyIs(value, \"BlueprintStepFailedError\");\n}\nexport function isBlueprintStepTimedOutError(value: unknown): value is BlueprintStepTimedOutError {\n\treturn value instanceof BlueprintStepTimedOutError || structurallyIs(value, \"BlueprintStepTimedOutError\");\n}\nexport function isBlueprintUsesUnsupportedError(value: unknown): value is BlueprintUsesUnsupportedError {\n\treturn value instanceof BlueprintUsesUnsupportedError || structurallyIs(value, \"BlueprintUsesUnsupportedError\");\n}\n\nexport function isBlueprintBuildFailedError(value: unknown): value is BlueprintBuildFailedError {\n\treturn value instanceof BlueprintBuildFailedError || structurallyIs(value, \"BlueprintBuildFailedError\");\n}\n\n/** The first error in `error`'s cause chain, itself included, that `guard` accepts. */\nexport function findBlueprintError<T extends BlueprintError>(\n\terror: unknown,\n\tguard: (value: unknown) => value is T = isBlueprintError as (value: unknown) => value is T,\n): T | undefined {\n\treturn findInCauseChain(error, guard);\n}\n\n/** A {@link BlueprintError} as it crosses a worker, RPC or broker boundary. */\nexport interface SerializedBlueprintError {\n\treadonly name: string;\n\treadonly code: string;\n\treadonly message: string;\n\treadonly hint: string;\n\treadonly retryable: boolean;\n\treadonly fields: BlueprintErrorFields;\n\treadonly cause?: SerializedErrorCause;\n}\n\n/** The JSON form of `error`, with its cause chain bounded and free of stack traces. */\nexport function serializeBlueprintError(error: BlueprintError): SerializedBlueprintError {\n\tconst cause = serializeErrorCause(error.cause);\n\treturn {\n\t\tname: error.name,\n\t\tcode: error.code,\n\t\tmessage: error.message,\n\t\thint: error.hint,\n\t\tretryable: error.retryable,\n\t\tfields: error.fields,\n\t\t...(cause === undefined ? {} : { cause }),\n\t};\n}\n\ntype Rehydrator = (fields: BlueprintErrorFields, cause?: Error) => BlueprintError;\nconst REHYDRATORS: Record<Exclude<BlueprintErrorName, \"BlueprintError\">, Rehydrator> = {\n\tBlueprintInvalidError: (fields, cause) =>\n\t\tnew BlueprintInvalidError(fields as unknown as BlueprintInvalidErrorFields, cause),\n\tBlueprintStepFailedError: (fields, cause) =>\n\t\tnew BlueprintStepFailedError(fields as unknown as BlueprintStepFailedErrorFields, cause),\n\tBlueprintStepTimedOutError: (fields, cause) =>\n\t\tnew BlueprintStepTimedOutError(fields as unknown as BlueprintStepTimedOutErrorFields, cause),\n\tBlueprintUsesUnsupportedError: (fields, cause) =>\n\t\tnew BlueprintUsesUnsupportedError(fields as unknown as BlueprintUsesUnsupportedErrorFields, cause),\n\tBlueprintBuildFailedError: (fields, cause) =>\n\t\tnew BlueprintBuildFailedError(fields as unknown as BlueprintBuildFailedErrorFields, cause),\n};\n\n/**\n * The error {@link serializeBlueprintError} produced, rebuilt after it crossed a process boundary as the same class.\n * An unknown `name` or `code` rebuilds it as a {@link BlueprintError} that keeps the original `name`, `code`,\n * `message`, `hint`, `retryable` and `fields`.\n */\nexport function rehydrateBlueprintError(form: SerializedBlueprintError, cause?: Error): BlueprintError {\n\tconst rebuiltCause = cause ?? rehydrateErrorCause(form.cause);\n\tconst name = form.name as BlueprintErrorName;\n\tif (\n\t\tname !== \"BlueprintError\" &&\n\t\tObject.hasOwn(REHYDRATORS, name) &&\n\t\tCODES[name].includes(form.code as BlueprintErrorCode)\n\t) {\n\t\treturn REHYDRATORS[name as Exclude<BlueprintErrorName, \"BlueprintError\">](form.fields, rebuiltCause);\n\t}\n\tconst error = Object.create(BlueprintError.prototype) as BlueprintError;\n\tObject.defineProperties(error, {\n\t\tname: { value: form.name, enumerable: false, configurable: true },\n\t\tmessage: { value: form.message, enumerable: false, configurable: true },\n\t\tcode: { value: form.code, enumerable: true },\n\t\thint: { value: form.hint, enumerable: true },\n\t\tretryable: { value: form.retryable, enumerable: true },\n\t\tfields: { value: Object.freeze({ ...form.fields }), enumerable: true },\n\t\t...(rebuiltCause === undefined ? {} : { cause: { value: rebuiltCause, enumerable: false, configurable: true } }),\n\t});\n\treturn error;\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** What the last build on this machine left for one workspace: a rebuild is needed unless it succeeded unchanged. */
|
|
2
|
+
export interface WorkspaceLedgerEntry {
|
|
3
|
+
/** Digest of the workspace's blueprint inputs when it was built. */
|
|
4
|
+
readonly digest: string;
|
|
5
|
+
readonly status: "success" | "failed";
|
|
6
|
+
readonly builtAt: string;
|
|
7
|
+
/** The failing step, for a failed build. */
|
|
8
|
+
readonly failedStep?: string;
|
|
9
|
+
readonly logPath?: string;
|
|
10
|
+
}
|
|
11
|
+
/** What the last build on this machine left for the global blueprint. */
|
|
12
|
+
export interface GlobalLedgerEntry {
|
|
13
|
+
/** Digest of the global blueprint and the deprecated `resume.setupCommand` alias. */
|
|
14
|
+
readonly digest: string;
|
|
15
|
+
readonly status: "success" | "failed";
|
|
16
|
+
readonly builtAt: string;
|
|
17
|
+
/** When a full build last succeeded for the global blueprint. */
|
|
18
|
+
readonly lastFullBuildAt?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The last build of one restored worktree: `running` is a build that never finished. */
|
|
21
|
+
export interface RootLedgerEntry {
|
|
22
|
+
readonly state: "running" | "success" | "failed";
|
|
23
|
+
readonly at: string;
|
|
24
|
+
}
|
|
25
|
+
export interface BlueprintLedger {
|
|
26
|
+
readonly version: 1;
|
|
27
|
+
readonly global?: GlobalLedgerEntry;
|
|
28
|
+
readonly workspaces: Readonly<Record<string, WorkspaceLedgerEntry>>;
|
|
29
|
+
readonly roots: Readonly<Record<string, RootLedgerEntry>>;
|
|
30
|
+
}
|
|
31
|
+
/** The digest of a blueprint file's inputs: the file's text and, for a workspace, where it sits. */
|
|
32
|
+
export declare function blueprintDigest(directory: string, source: string, extra?: string): string;
|
|
33
|
+
/** The ledger key of the workspace at `directory` (`.` for the root) of the repository `identity`. */
|
|
34
|
+
export declare function workspaceKey(identity: string, directory: string): string;
|
|
35
|
+
/** The prefix of the ledger keys of every workspace of the repository `identity`. */
|
|
36
|
+
export declare function repositoryKey(identity: string): string;
|
|
37
|
+
/** The ledger key of the restored worktree at `root`. */
|
|
38
|
+
export declare function rootKey(root: string): string;
|
|
39
|
+
export declare function ledgerPath(storeDir: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* The ledger of the builds on this machine. A missing ledger, and one that is not a ledger this version wrote, is an
|
|
42
|
+
* empty one: the next build then has no parent and runs in full, and its write replaces the file.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readLedger(storeDir: string): Promise<BlueprintLedger>;
|
|
45
|
+
/**
|
|
46
|
+
* Applies `update` to the ledger as it is now and writes the result atomically. Updates are serialized, within this
|
|
47
|
+
* process by a queue and across processes by a lock file, so builds that finish at about the same time keep each
|
|
48
|
+
* other's entries. A lock that cannot be taken within its retries rejects with the lock's error.
|
|
49
|
+
*/
|
|
50
|
+
export declare function updateLedger(storeDir: string, update: (ledger: BlueprintLedger) => BlueprintLedger): Promise<BlueprintLedger>;
|
|
51
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/ledger.ts"],"names":[],"mappings":"AAKA,qHAAqH;AACrH,MAAM,WAAW,oBAAoB;IACpC,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,M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AEtD;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAgBD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAgB3E;AA2BD;;;;GAIG;AACH,wBAAsB,YAAY,CACjC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,eAAe,GAClD,OAAO,CAAC,eAAe,CAAC,CAqB1B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import lockfile from "proper-lockfile";
|
|
5
|
+
const DIGEST_VERSION = "atomic-blueprint-v1";
|
|
6
|
+
function sha256(parts) {
|
|
7
|
+
const hash = createHash("sha256");
|
|
8
|
+
for (const part of parts)
|
|
9
|
+
hash.update(`${part.length}:`).update(part);
|
|
10
|
+
return hash.digest("hex");
|
|
11
|
+
}
|
|
12
|
+
/** The digest of a blueprint file's inputs: the file's text and, for a workspace, where it sits. */
|
|
13
|
+
export function blueprintDigest(directory, source, extra = "") {
|
|
14
|
+
return sha256([DIGEST_VERSION, directory, source, extra]);
|
|
15
|
+
}
|
|
16
|
+
/** The ledger key of the workspace at `directory` (`.` for the root) of the repository `identity`. */
|
|
17
|
+
export function workspaceKey(identity, directory) {
|
|
18
|
+
return `${repositoryKey(identity)}:${directory === "" ? "." : directory}`;
|
|
19
|
+
}
|
|
20
|
+
/** The prefix of the ledger keys of every workspace of the repository `identity`. */
|
|
21
|
+
export function repositoryKey(identity) {
|
|
22
|
+
return sha256([identity]).slice(0, 16);
|
|
23
|
+
}
|
|
24
|
+
/** The ledger key of the restored worktree at `root`. */
|
|
25
|
+
export function rootKey(root) {
|
|
26
|
+
return sha256([resolve(root)]).slice(0, 16);
|
|
27
|
+
}
|
|
28
|
+
export function ledgerPath(storeDir) {
|
|
29
|
+
return join(storeDir, "blueprint-builds", "ledger.json");
|
|
30
|
+
}
|
|
31
|
+
const EMPTY_LEDGER = { version: 1, workspaces: {}, roots: {} };
|
|
32
|
+
function isLedger(value) {
|
|
33
|
+
if (typeof value !== "object" || value === null)
|
|
34
|
+
return false;
|
|
35
|
+
const candidate = value;
|
|
36
|
+
return (candidate.version === 1 &&
|
|
37
|
+
typeof candidate.workspaces === "object" &&
|
|
38
|
+
candidate.workspaces !== null &&
|
|
39
|
+
typeof candidate.roots === "object" &&
|
|
40
|
+
candidate.roots !== null);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The ledger of the builds on this machine. A missing ledger, and one that is not a ledger this version wrote, is an
|
|
44
|
+
* empty one: the next build then has no parent and runs in full, and its write replaces the file.
|
|
45
|
+
*/
|
|
46
|
+
export async function readLedger(storeDir) {
|
|
47
|
+
let text;
|
|
48
|
+
try {
|
|
49
|
+
text = await readFile(ledgerPath(storeDir), "utf8");
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code === "ENOENT")
|
|
53
|
+
return EMPTY_LEDGER;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(text);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof SyntaxError)
|
|
62
|
+
return EMPTY_LEDGER;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
return isLedger(parsed) ? parsed : EMPTY_LEDGER;
|
|
66
|
+
}
|
|
67
|
+
const ledgerQueues = new Map();
|
|
68
|
+
/** A lock held by a stopped process is given up after this long; a live holder refreshes it every few seconds. */
|
|
69
|
+
const LEDGER_LOCK_STALE_MS = 15_000;
|
|
70
|
+
const LEDGER_LOCK_UPDATE_MS = 5_000;
|
|
71
|
+
const LEDGER_LOCK_RETRIES = { retries: 40, factor: 1.2, minTimeout: 20, maxTimeout: 250 };
|
|
72
|
+
/** Serializes work on one ledger within this process, in the order it was asked for. */
|
|
73
|
+
async function inProcessTurn(key, work) {
|
|
74
|
+
const previous = ledgerQueues.get(key) ?? Promise.resolve();
|
|
75
|
+
let release;
|
|
76
|
+
const current = new Promise((resolveTurn) => {
|
|
77
|
+
release = resolveTurn;
|
|
78
|
+
});
|
|
79
|
+
const chained = previous.then(() => current);
|
|
80
|
+
ledgerQueues.set(key, chained);
|
|
81
|
+
await previous;
|
|
82
|
+
try {
|
|
83
|
+
return await work();
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
release();
|
|
87
|
+
if (ledgerQueues.get(key) === chained)
|
|
88
|
+
ledgerQueues.delete(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Applies `update` to the ledger as it is now and writes the result atomically. Updates are serialized, within this
|
|
93
|
+
* process by a queue and across processes by a lock file, so builds that finish at about the same time keep each
|
|
94
|
+
* other's entries. A lock that cannot be taken within its retries rejects with the lock's error.
|
|
95
|
+
*/
|
|
96
|
+
export async function updateLedger(storeDir, update) {
|
|
97
|
+
const path = ledgerPath(storeDir);
|
|
98
|
+
return inProcessTurn(path, async () => {
|
|
99
|
+
await mkdir(dirname(path), { recursive: true });
|
|
100
|
+
const release = await lockfile.lock(dirname(path), {
|
|
101
|
+
realpath: false,
|
|
102
|
+
lockfilePath: `${path}.lock`,
|
|
103
|
+
stale: LEDGER_LOCK_STALE_MS,
|
|
104
|
+
update: LEDGER_LOCK_UPDATE_MS,
|
|
105
|
+
retries: LEDGER_LOCK_RETRIES,
|
|
106
|
+
});
|
|
107
|
+
try {
|
|
108
|
+
const next = update(await readLedger(storeDir));
|
|
109
|
+
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
110
|
+
await writeFile(temporary, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
111
|
+
await rename(temporary, path);
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
await release();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAoCvC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAE7C,SAAS,MAAM,CAAC,KAAwB;IACvC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,eAAe,CAAC,SAAiB,EAAE,MAAc,EAAE,KAAK,GAAG,EAAE;IAC5E,OAAO,MAAM,CAAC,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,SAAiB;IAC/D,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,SAAS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EAAE,CAAC;QACjB,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\n\n/** What the last build on this machine left for one workspace: a rebuild is needed unless it succeeded unchanged. */\nexport interface WorkspaceLedgerEntry {\n\t/** Digest of the workspace's blueprint inputs when it was built. */\n\treadonly digest: string;\n\treadonly status: \"success\" | \"failed\";\n\treadonly builtAt: string;\n\t/** The failing step, for a failed build. */\n\treadonly failedStep?: string;\n\treadonly logPath?: string;\n}\n\n/** What the last build on this machine left for the global blueprint. */\nexport interface GlobalLedgerEntry {\n\t/** Digest of the global blueprint and the deprecated `resume.setupCommand` alias. */\n\treadonly digest: string;\n\treadonly status: \"success\" | \"failed\";\n\treadonly builtAt: string;\n\t/** When a full build last succeeded for the global blueprint. */\n\treadonly lastFullBuildAt?: string;\n}\n\n/** The last build of one restored worktree: `running` is a build that never finished. */\nexport interface RootLedgerEntry {\n\treadonly state: \"running\" | \"success\" | \"failed\";\n\treadonly at: string;\n}\n\nexport interface BlueprintLedger {\n\treadonly version: 1;\n\treadonly global?: GlobalLedgerEntry;\n\treadonly workspaces: Readonly<Record<string, WorkspaceLedgerEntry>>;\n\treadonly roots: Readonly<Record<string, RootLedgerEntry>>;\n}\n\nconst DIGEST_VERSION = \"atomic-blueprint-v1\";\n\nfunction sha256(parts: readonly string[]): string {\n\tconst hash = createHash(\"sha256\");\n\tfor (const part of parts) hash.update(`${part.length}:`).update(part);\n\treturn hash.digest(\"hex\");\n}\n\n/** The digest of a blueprint file's inputs: the file's text and, for a workspace, where it sits. */\nexport function blueprintDigest(directory: string, source: string, extra = \"\"): string {\n\treturn sha256([DIGEST_VERSION, directory, source, extra]);\n}\n\n/** The ledger key of the workspace at `directory` (`.` for the root) of the repository `identity`. */\nexport function workspaceKey(identity: string, directory: string): string {\n\treturn `${repositoryKey(identity)}:${directory === \"\" ? \".\" : directory}`;\n}\n\n/** The prefix of the ledger keys of every workspace of the repository `identity`. */\nexport function repositoryKey(identity: string): string {\n\treturn sha256([identity]).slice(0, 16);\n}\n\n/** The ledger key of the restored worktree at `root`. */\nexport function rootKey(root: string): string {\n\treturn sha256([resolve(root)]).slice(0, 16);\n}\n\nexport function ledgerPath(storeDir: string): string {\n\treturn join(storeDir, \"blueprint-builds\", \"ledger.json\");\n}\n\nconst EMPTY_LEDGER: BlueprintLedger = { version: 1, workspaces: {}, roots: {} };\n\nfunction isLedger(value: unknown): value is BlueprintLedger {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as Partial<Record<keyof BlueprintLedger, unknown>>;\n\treturn (\n\t\tcandidate.version === 1 &&\n\t\ttypeof candidate.workspaces === \"object\" &&\n\t\tcandidate.workspaces !== null &&\n\t\ttypeof candidate.roots === \"object\" &&\n\t\tcandidate.roots !== null\n\t);\n}\n\n/**\n * The ledger of the builds on this machine. A missing ledger, and one that is not a ledger this version wrote, is an\n * empty one: the next build then has no parent and runs in full, and its write replaces the file.\n */\nexport async function readLedger(storeDir: string): Promise<BlueprintLedger> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(ledgerPath(storeDir), \"utf8\");\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return EMPTY_LEDGER;\n\t\tthrow error;\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError) return EMPTY_LEDGER;\n\t\tthrow error;\n\t}\n\treturn isLedger(parsed) ? parsed : EMPTY_LEDGER;\n}\n\nconst ledgerQueues = new Map<string, Promise<void>>();\n\n/** A lock held by a stopped process is given up after this long; a live holder refreshes it every few seconds. */\nconst LEDGER_LOCK_STALE_MS = 15_000;\nconst LEDGER_LOCK_UPDATE_MS = 5_000;\nconst LEDGER_LOCK_RETRIES = { retries: 40, factor: 1.2, minTimeout: 20, maxTimeout: 250 } as const;\n\n/** Serializes work on one ledger within this process, in the order it was asked for. */\nasync function inProcessTurn<T>(key: string, work: () => Promise<T>): Promise<T> {\n\tconst previous = ledgerQueues.get(key) ?? Promise.resolve();\n\tlet release!: () => void;\n\tconst current = new Promise<void>((resolveTurn) => {\n\t\trelease = resolveTurn;\n\t});\n\tconst chained = previous.then(() => current);\n\tledgerQueues.set(key, chained);\n\tawait previous;\n\ttry {\n\t\treturn await work();\n\t} finally {\n\t\trelease();\n\t\tif (ledgerQueues.get(key) === chained) ledgerQueues.delete(key);\n\t}\n}\n\n/**\n * Applies `update` to the ledger as it is now and writes the result atomically. Updates are serialized, within this\n * process by a queue and across processes by a lock file, so builds that finish at about the same time keep each\n * other's entries. A lock that cannot be taken within its retries rejects with the lock's error.\n */\nexport async function updateLedger(\n\tstoreDir: string,\n\tupdate: (ledger: BlueprintLedger) => BlueprintLedger,\n): Promise<BlueprintLedger> {\n\tconst path = ledgerPath(storeDir);\n\treturn inProcessTurn(path, async () => {\n\t\tawait mkdir(dirname(path), { recursive: true });\n\t\tconst release = await lockfile.lock(dirname(path), {\n\t\t\trealpath: false,\n\t\t\tlockfilePath: `${path}.lock`,\n\t\t\tstale: LEDGER_LOCK_STALE_MS,\n\t\t\tupdate: LEDGER_LOCK_UPDATE_MS,\n\t\t\tretries: LEDGER_LOCK_RETRIES,\n\t\t});\n\t\ttry {\n\t\t\tconst next = update(await readLedger(storeDir));\n\t\t\tconst temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;\n\t\t\tawait writeFile(temporary, `${JSON.stringify(next, null, 2)}\\n`, { mode: 0o600 });\n\t\t\tawait rename(temporary, path);\n\t\t\treturn next;\n\t\t} finally {\n\t\t\tawait release();\n\t\t}\n\t});\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type BlueprintBuildOutcome } from "./build.ts";
|
|
2
|
+
/** A line a resume shows the user. */
|
|
3
|
+
export interface BlueprintNotice {
|
|
4
|
+
readonly type: "info" | "warning";
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The warnings a build earns: one per blueprint that failed (`Partial build` for a repository or workspace, a
|
|
9
|
+
* prominent `Blueprint build FAILED` for the global blueprint or its post-build), each naming the blueprint and the
|
|
10
|
+
* failing step, plus the deprecation notice when the `resume.setupCommand` alias ran. A build that was skipped or found
|
|
11
|
+
* no blueprint, and one that succeeded, say nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function blueprintNotices(outcome: BlueprintBuildOutcome, aliasConfigured: boolean): BlueprintNotice[];
|
|
14
|
+
//# sourceMappingURL=notices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/notices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAA8C,MAAM,YAAY,CAAC;AAEpG,sCAAsC;AACtC,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAwBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,OAAO,GAAG,eAAe,EAAE,CAgB5G"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SETUP_COMMAND_ALIAS } from "./build.js";
|
|
2
|
+
function repositoryFailure(failure) {
|
|
3
|
+
return `Partial build: ${failure.error.message} The rest of that blueprint did not run; the other blueprints were built.`;
|
|
4
|
+
}
|
|
5
|
+
function repositoryClause(failure) {
|
|
6
|
+
const { section, phase } = failure.error.fields;
|
|
7
|
+
if (section === "post-build")
|
|
8
|
+
return ", and the repositories were set up before it ran";
|
|
9
|
+
if (section === "initialize" ||
|
|
10
|
+
section === "maintenance" ||
|
|
11
|
+
phase === "read-blueprint" ||
|
|
12
|
+
failure.error.code === "blueprint-invalid") {
|
|
13
|
+
return ", but repository setup did not run";
|
|
14
|
+
}
|
|
15
|
+
return ", but repository setup may not have run";
|
|
16
|
+
}
|
|
17
|
+
function globalFailure(failure) {
|
|
18
|
+
return `Blueprint build FAILED: ${failure.error.message} The session resumed anyway${repositoryClause(failure)}.`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The warnings a build earns: one per blueprint that failed (`Partial build` for a repository or workspace, a
|
|
22
|
+
* prominent `Blueprint build FAILED` for the global blueprint or its post-build), each naming the blueprint and the
|
|
23
|
+
* failing step, plus the deprecation notice when the `resume.setupCommand` alias ran. A build that was skipped or found
|
|
24
|
+
* no blueprint, and one that succeeded, say nothing.
|
|
25
|
+
*/
|
|
26
|
+
export function blueprintNotices(outcome, aliasConfigured) {
|
|
27
|
+
if (outcome.kind === undefined && outcome.failures.length === 0)
|
|
28
|
+
return [];
|
|
29
|
+
const notices = outcome.failures.map((failure) => ({
|
|
30
|
+
type: "warning",
|
|
31
|
+
message: failure.scope === "global" ? globalFailure(failure) : repositoryFailure(failure),
|
|
32
|
+
}));
|
|
33
|
+
for (const warning of outcome.warnings) {
|
|
34
|
+
notices.push({ type: "warning", message: `Blueprint ${warning.blueprint}: ${warning.message}.` });
|
|
35
|
+
}
|
|
36
|
+
if (aliasConfigured && outcome.kind !== undefined) {
|
|
37
|
+
notices.push({
|
|
38
|
+
type: "warning",
|
|
39
|
+
message: `Deprecation warning: ${SETUP_COMMAND_ALIAS} is deprecated and will be removed in the next release. Move its command into the maintenance section of .atomic/blueprint.yaml.`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return notices;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=notices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notices.js","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/notices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,mBAAmB,EA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,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,OAAO,CAAC,SAAS,KAAK,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IACnG,CAAC;IACD,IAAI,eAAe,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACnD,OAAO,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,wBAAwB,mBAAmB,kIAAkI;SACtL,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { type BlueprintBuildOutcome, type BlueprintFailure, SETUP_COMMAND_ALIAS } from \"./build.ts\";\n\n/** A line a resume shows the user. */\nexport interface BlueprintNotice {\n\treadonly type: \"info\" | \"warning\";\n\treadonly message: string;\n}\n\nfunction repositoryFailure(failure: BlueprintFailure): string {\n\treturn `Partial build: ${failure.error.message} The rest of that blueprint did not run; the other blueprints were built.`;\n}\n\nfunction repositoryClause(failure: BlueprintFailure): string {\n\tconst { section, phase } = failure.error.fields as { section?: unknown; phase?: unknown };\n\tif (section === \"post-build\") return \", and the repositories were set up before it ran\";\n\tif (\n\t\tsection === \"initialize\" ||\n\t\tsection === \"maintenance\" ||\n\t\tphase === \"read-blueprint\" ||\n\t\tfailure.error.code === \"blueprint-invalid\"\n\t) {\n\t\treturn \", but repository setup did not run\";\n\t}\n\treturn \", but repository setup may not have run\";\n}\n\nfunction globalFailure(failure: BlueprintFailure): string {\n\treturn `Blueprint build FAILED: ${failure.error.message} The session resumed anyway${repositoryClause(failure)}.`;\n}\n\n/**\n * The warnings a build earns: one per blueprint that failed (`Partial build` for a repository or workspace, a\n * prominent `Blueprint build FAILED` for the global blueprint or its post-build), each naming the blueprint and the\n * failing step, plus the deprecation notice when the `resume.setupCommand` alias ran. A build that was skipped or found\n * no blueprint, and one that succeeded, say nothing.\n */\nexport function blueprintNotices(outcome: BlueprintBuildOutcome, aliasConfigured: boolean): BlueprintNotice[] {\n\tif (outcome.kind === undefined && outcome.failures.length === 0) return [];\n\tconst notices: BlueprintNotice[] = outcome.failures.map((failure) => ({\n\t\ttype: \"warning\",\n\t\tmessage: failure.scope === \"global\" ? globalFailure(failure) : repositoryFailure(failure),\n\t}));\n\tfor (const warning of outcome.warnings) {\n\t\tnotices.push({ type: \"warning\", message: `Blueprint ${warning.blueprint}: ${warning.message}.` });\n\t}\n\tif (aliasConfigured && outcome.kind !== undefined) {\n\t\tnotices.push({\n\t\t\ttype: \"warning\",\n\t\t\tmessage: `Deprecation warning: ${SETUP_COMMAND_ALIAS} is deprecated and will be removed in the next release. Move its command into the maintenance section of .atomic/blueprint.yaml.`,\n\t\t});\n\t}\n\treturn notices;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A step's log file, open for appending: the child processes of the step write their output to `fd`. */
|
|
2
|
+
export interface StepLog {
|
|
3
|
+
readonly fd: number;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
}
|
|
6
|
+
/** One process a step starts. */
|
|
7
|
+
export interface LoggedProcess {
|
|
8
|
+
readonly command: string;
|
|
9
|
+
readonly args: readonly string[];
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
readonly env: NodeJS.ProcessEnv;
|
|
12
|
+
/** Written to the process's stdin, for shells that take the command that way; otherwise stdin is closed. */
|
|
13
|
+
readonly stdin?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ProcessExit {
|
|
16
|
+
readonly exitStatus: number | null;
|
|
17
|
+
readonly signal: string | null;
|
|
18
|
+
readonly timedOut: boolean;
|
|
19
|
+
readonly elapsedMs: number;
|
|
20
|
+
/** Why the process could not be started, when it could not. */
|
|
21
|
+
readonly spawnError?: Error;
|
|
22
|
+
}
|
|
23
|
+
export interface LoggedProcessOptions {
|
|
24
|
+
readonly timeoutMs: number;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/** Whether a process started on `platform` leads its own process group, which is how stopping it stops its children. */
|
|
28
|
+
export declare function startsProcessGroup(platform: NodeJS.Platform): boolean;
|
|
29
|
+
export declare function copiesOutputToLog(platform: NodeJS.Platform): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Runs `run` with its output appended to `log`, in its own process group (POSIX) so stopping it stops everything it
|
|
32
|
+
* started. Resolves how it ended: exited, stopped by a signal, timed out after `timeoutMs`, or could not be started
|
|
33
|
+
* (`spawnError`). Rejects with `signal.reason` when `options.signal` aborts, since cancelling is not a failure.
|
|
34
|
+
*/
|
|
35
|
+
export declare function runLoggedProcess(run: LoggedProcess, log: StepLog, options: LoggedProcessOptions): Promise<ProcessExit>;
|
|
36
|
+
/** Opens `path` for appending with owner-only permissions; the caller closes it. */
|
|
37
|
+
export declare function openStepLog(path: string): Promise<StepLog & {
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}>;
|
|
40
|
+
/** How much of a log's end a build outcome keeps. */
|
|
41
|
+
export declare const LOG_TAIL_BYTES = 4096;
|
|
42
|
+
/** The last `bytes` of the file at `path`, or an empty string when it cannot be read. */
|
|
43
|
+
export declare function logTail(path: string, bytes?: number): Promise<string>;
|
|
44
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/process.ts"],"names":[],"mappings":"AAOA,yGAAyG;AACzG,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,iCAAiC;AACjC,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,4GAA4G;IAC5G,QAAQ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readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import { waitForChildProcess } from "../../../utils/child-process.js";
|
|
6
|
+
import { killProcessTree } from "../../../utils/shell.js";
|
|
7
|
+
/** Whether a process started on `platform` leads its own process group, which is how stopping it stops its children. */
|
|
8
|
+
export function startsProcessGroup(platform) {
|
|
9
|
+
return platform !== "win32";
|
|
10
|
+
}
|
|
11
|
+
export function copiesOutputToLog(platform) {
|
|
12
|
+
return platform === "win32";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs `run` with its output appended to `log`, in its own process group (POSIX) so stopping it stops everything it
|
|
16
|
+
* started. Resolves how it ended: exited, stopped by a signal, timed out after `timeoutMs`, or could not be started
|
|
17
|
+
* (`spawnError`). Rejects with `signal.reason` when `options.signal` aborts, since cancelling is not a failure.
|
|
18
|
+
*/
|
|
19
|
+
export async function runLoggedProcess(run, log, options) {
|
|
20
|
+
options.signal?.throwIfAborted();
|
|
21
|
+
const startedAt = Date.now();
|
|
22
|
+
const copiesOutput = copiesOutputToLog(process.platform);
|
|
23
|
+
return new Promise((resolveExit, reject) => {
|
|
24
|
+
const child = spawn(run.command, [...run.args], {
|
|
25
|
+
cwd: run.cwd,
|
|
26
|
+
env: run.env,
|
|
27
|
+
detached: startsProcessGroup(process.platform),
|
|
28
|
+
windowsHide: true,
|
|
29
|
+
stdio: [
|
|
30
|
+
run.stdin === undefined ? "ignore" : "pipe",
|
|
31
|
+
copiesOutput ? "pipe" : log.fd,
|
|
32
|
+
copiesOutput ? "pipe" : log.fd,
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
let timedOut = false;
|
|
36
|
+
let writeError;
|
|
37
|
+
const stop = () => {
|
|
38
|
+
if (child.pid !== undefined)
|
|
39
|
+
killProcessTree(child.pid);
|
|
40
|
+
};
|
|
41
|
+
const timer = setTimeout(() => {
|
|
42
|
+
timedOut = true;
|
|
43
|
+
stop();
|
|
44
|
+
}, options.timeoutMs);
|
|
45
|
+
const onAbort = () => stop();
|
|
46
|
+
if (copiesOutput) {
|
|
47
|
+
const fail = (what, error) => {
|
|
48
|
+
if (writeError !== undefined)
|
|
49
|
+
return;
|
|
50
|
+
writeError = new Error(`The output of ${run.command} could not be ${what} the log ${log.path}`, {
|
|
51
|
+
cause: error,
|
|
52
|
+
});
|
|
53
|
+
stop();
|
|
54
|
+
};
|
|
55
|
+
const copy = (chunk) => {
|
|
56
|
+
if (writeError !== undefined)
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
writeFully(log.fd, chunk);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
fail("written to", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
66
|
+
stream?.on("data", copy);
|
|
67
|
+
stream?.on("error", (error) => {
|
|
68
|
+
if (!timedOut && !options.signal?.aborted)
|
|
69
|
+
fail("read for", error);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const settle = () => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
76
|
+
};
|
|
77
|
+
options.signal?.addEventListener("abort", onAbort);
|
|
78
|
+
const onSpawnError = (error) => {
|
|
79
|
+
settle();
|
|
80
|
+
if (options.signal?.aborted) {
|
|
81
|
+
reject(options.signal.reason);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
resolveExit({
|
|
85
|
+
exitStatus: null,
|
|
86
|
+
signal: null,
|
|
87
|
+
timedOut: false,
|
|
88
|
+
elapsedMs: Date.now() - startedAt,
|
|
89
|
+
spawnError: error,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const ended = (exitStatus, exitSignal) => {
|
|
93
|
+
settle();
|
|
94
|
+
if (options.signal?.aborted) {
|
|
95
|
+
reject(options.signal.reason);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (writeError !== undefined) {
|
|
99
|
+
reject(writeError);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
resolveExit({ exitStatus, signal: exitSignal, timedOut, elapsedMs: Date.now() - startedAt });
|
|
103
|
+
};
|
|
104
|
+
if (copiesOutput) {
|
|
105
|
+
waitForChildProcess(child).then((exitStatus) => ended(exitStatus, child.signalCode), onSpawnError);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
child.once("error", onSpawnError);
|
|
109
|
+
child.once("close", ended);
|
|
110
|
+
}
|
|
111
|
+
if (run.stdin !== undefined)
|
|
112
|
+
child.stdin?.end(run.stdin);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function writeFully(fd, chunk) {
|
|
116
|
+
let written = 0;
|
|
117
|
+
while (written < chunk.length) {
|
|
118
|
+
const count = writeSync(fd, chunk, written);
|
|
119
|
+
if (count <= 0)
|
|
120
|
+
throw new Error("the log accepted no bytes");
|
|
121
|
+
written += count;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Opens `path` for appending with owner-only permissions; the caller closes it. */
|
|
125
|
+
export async function openStepLog(path) {
|
|
126
|
+
await mkdir(dirname(path), { recursive: true });
|
|
127
|
+
const handle = await open(path, "a", 0o600);
|
|
128
|
+
return { fd: handle.fd, path, close: () => handle.close() };
|
|
129
|
+
}
|
|
130
|
+
/** How much of a log's end a build outcome keeps. */
|
|
131
|
+
export const LOG_TAIL_BYTES = 4096;
|
|
132
|
+
/** The last `bytes` of the file at `path`, or an empty string when it cannot be read. */
|
|
133
|
+
export async function logTail(path, bytes = LOG_TAIL_BYTES) {
|
|
134
|
+
try {
|
|
135
|
+
const content = await readFile(path);
|
|
136
|
+
return content.subarray(Math.max(0, content.length - bytes)).toString("utf8");
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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AC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC7C,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;AAC7D,CAAC;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAEnC,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAY,EAAE,KAAK,GAAW,cAAc;IACzE,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { writeSync } from \"node:fs\";\nimport { mkdir, open, readFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { waitForChildProcess } from \"../../../utils/child-process.ts\";\nimport { killProcessTree } from \"../../../utils/shell.ts\";\n\n/** A step's log file, open for appending: the child processes of the step write their output to `fd`. */\nexport interface StepLog {\n\treadonly fd: number;\n\treadonly path: string;\n}\n\n/** One process a step starts. */\nexport interface LoggedProcess {\n\treadonly command: string;\n\treadonly args: readonly string[];\n\treadonly cwd: string;\n\treadonly env: NodeJS.ProcessEnv;\n\t/** Written to the process's stdin, for shells that take the command that way; otherwise stdin is closed. */\n\treadonly stdin?: string;\n}\n\nexport interface ProcessExit {\n\treadonly exitStatus: number | null;\n\treadonly signal: string | null;\n\treadonly timedOut: boolean;\n\treadonly elapsedMs: number;\n\t/** Why the process could not be started, when it could not. */\n\treadonly spawnError?: Error;\n}\n\nexport interface LoggedProcessOptions {\n\treadonly timeoutMs: number;\n\treadonly signal?: AbortSignal;\n}\n\n/** Whether a process started on `platform` leads its own process group, which is how stopping it stops its children. */\nexport function startsProcessGroup(platform: NodeJS.Platform): boolean {\n\treturn platform !== \"win32\";\n}\n\nexport function copiesOutputToLog(platform: NodeJS.Platform): boolean {\n\treturn platform === \"win32\";\n}\n\n/**\n * Runs `run` with its output appended to `log`, in its own process group (POSIX) so stopping it stops everything it\n * started. Resolves how it ended: exited, stopped by a signal, timed out after `timeoutMs`, or could not be started\n * (`spawnError`). Rejects with `signal.reason` when `options.signal` aborts, since cancelling is not a failure.\n */\nexport async function runLoggedProcess(\n\trun: LoggedProcess,\n\tlog: StepLog,\n\toptions: LoggedProcessOptions,\n): Promise<ProcessExit> {\n\toptions.signal?.throwIfAborted();\n\tconst startedAt = Date.now();\n\tconst copiesOutput = copiesOutputToLog(process.platform);\n\treturn new Promise<ProcessExit>((resolveExit, reject) => {\n\t\tconst child = spawn(run.command, [...run.args], {\n\t\t\tcwd: run.cwd,\n\t\t\tenv: run.env,\n\t\t\tdetached: startsProcessGroup(process.platform),\n\t\t\twindowsHide: true,\n\t\t\tstdio: [\n\t\t\t\trun.stdin === undefined ? \"ignore\" : \"pipe\",\n\t\t\t\tcopiesOutput ? \"pipe\" : log.fd,\n\t\t\t\tcopiesOutput ? \"pipe\" : log.fd,\n\t\t\t],\n\t\t});\n\t\tlet timedOut = false;\n\t\tlet writeError: Error | undefined;\n\t\tconst stop = () => {\n\t\t\tif (child.pid !== undefined) killProcessTree(child.pid);\n\t\t};\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tstop();\n\t\t}, options.timeoutMs);\n\t\tconst onAbort = () => stop();\n\t\tif (copiesOutput) {\n\t\t\tconst fail = (what: string, error: Error) => {\n\t\t\t\tif (writeError !== undefined) return;\n\t\t\t\twriteError = new Error(`The output of ${run.command} could not be ${what} the log ${log.path}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t\tstop();\n\t\t\t};\n\t\t\tconst copy = (chunk: Buffer) => {\n\t\t\t\tif (writeError !== undefined) return;\n\t\t\t\ttry {\n\t\t\t\t\twriteFully(log.fd, chunk);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfail(\"written to\", error as Error);\n\t\t\t\t}\n\t\t\t};\n\t\t\tfor (const stream of [child.stdout, child.stderr]) {\n\t\t\t\tstream?.on(\"data\", copy);\n\t\t\t\tstream?.on(\"error\", (error) => {\n\t\t\t\t\tif (!timedOut && !options.signal?.aborted) fail(\"read for\", error);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst settle = () => {\n\t\t\tclearTimeout(timer);\n\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t};\n\t\toptions.signal?.addEventListener(\"abort\", onAbort);\n\t\tconst onSpawnError = (error: Error) => {\n\t\t\tsettle();\n\t\t\tif (options.signal?.aborted) {\n\t\t\t\treject(options.signal.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolveExit({\n\t\t\t\texitStatus: null,\n\t\t\t\tsignal: null,\n\t\t\t\ttimedOut: false,\n\t\t\t\telapsedMs: Date.now() - startedAt,\n\t\t\t\tspawnError: error,\n\t\t\t});\n\t\t};\n\t\tconst ended = (exitStatus: number | null, exitSignal: NodeJS.Signals | null) => {\n\t\t\tsettle();\n\t\t\tif (options.signal?.aborted) {\n\t\t\t\treject(options.signal.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (writeError !== undefined) {\n\t\t\t\treject(writeError);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolveExit({ exitStatus, signal: exitSignal, timedOut, elapsedMs: Date.now() - startedAt });\n\t\t};\n\t\tif (copiesOutput) {\n\t\t\twaitForChildProcess(child).then((exitStatus) => ended(exitStatus, child.signalCode), onSpawnError);\n\t\t} else {\n\t\t\tchild.once(\"error\", onSpawnError);\n\t\t\tchild.once(\"close\", ended);\n\t\t}\n\t\tif (run.stdin !== undefined) child.stdin?.end(run.stdin);\n\t});\n}\n\nfunction writeFully(fd: number, chunk: Buffer): void {\n\tlet written = 0;\n\twhile (written < chunk.length) {\n\t\tconst count = writeSync(fd, chunk, written);\n\t\tif (count <= 0) throw new Error(\"the log accepted no bytes\");\n\t\twritten += count;\n\t}\n}\n\n/** Opens `path` for appending with owner-only permissions; the caller closes it. */\nexport async function openStepLog(path: string): Promise<StepLog & { close(): Promise<void> }> {\n\tawait mkdir(dirname(path), { recursive: true });\n\tconst handle = await open(path, \"a\", 0o600);\n\treturn { fd: handle.fd, path, close: () => handle.close() };\n}\n\n/** How much of a log's end a build outcome keeps. */\nexport const LOG_TAIL_BYTES = 4096;\n\n/** The last `bytes` of the file at `path`, or an empty string when it cannot be read. */\nexport async function logTail(path: string, bytes: number = LOG_TAIL_BYTES): Promise<string> {\n\ttry {\n\t\tconst content = await readFile(path);\n\t\treturn content.subarray(Math.max(0, content.length - bytes)).toString(\"utf8\");\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SessionManager } from "../../session-manager.ts";
|
|
2
|
+
import { type BlueprintBuildConfig, type BlueprintBuildOutcome, type BlueprintLayer, type BlueprintRepository } from "./build.ts";
|
|
3
|
+
import { BlueprintBuildFailedError } from "./errors.ts";
|
|
4
|
+
import { type BlueprintNotice } from "./notices.ts";
|
|
5
|
+
/** A checkout of a session's repository on this node, with the remotes its snapshot recorded. */
|
|
6
|
+
export interface BlueprintCheckout {
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly remotes: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
/** The repository a checkout belongs to for the build ledger: its sorted remotes, else its own root. */
|
|
11
|
+
export declare function blueprintRepository(checkout: BlueprintCheckout): BlueprintRepository;
|
|
12
|
+
/** A restore a session or run recorded: work under `from` continues under `to`. */
|
|
13
|
+
export interface RestoreLink {
|
|
14
|
+
readonly from: string;
|
|
15
|
+
readonly to: string;
|
|
16
|
+
readonly snapshotId: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The remotes that identify the repository of the checkout at `root` for the build ledger. A worktree Atomic restored
|
|
20
|
+
* comes from a store without remotes, so a snapshot captured inside it records none; the repository's remotes are then
|
|
21
|
+
* found by following the recorded restores back, from the worktree to the checkout it replaced, to the first snapshot
|
|
22
|
+
* that has some. `own` are the remotes of the checkout's own latest snapshot. Empty when the chain has none, in which
|
|
23
|
+
* case the repository is identified by its root.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inheritedRemotes(root: string, own: readonly string[], restores: readonly RestoreLink[], snapshots: ReadonlyMap<string, {
|
|
26
|
+
readonly remotes: readonly string[];
|
|
27
|
+
}>): readonly string[];
|
|
28
|
+
/** What a resume does with the blueprints: the outcome of the build, what the user is told, what the agent is told. */
|
|
29
|
+
export interface ResumedBlueprints {
|
|
30
|
+
/** Undefined when no build was attempted. */
|
|
31
|
+
readonly outcome: BlueprintBuildOutcome | undefined;
|
|
32
|
+
readonly notices: readonly BlueprintNotice[];
|
|
33
|
+
readonly layers: readonly BlueprintLayer[];
|
|
34
|
+
/** The first-turn context for the agent; undefined when no blueprint has anything to say. */
|
|
35
|
+
readonly context: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
export interface SetUpBlueprintsOptions {
|
|
38
|
+
/** Worktrees Atomic restored for this resume, or earlier and then failed to build: built now. */
|
|
39
|
+
readonly restored: readonly BlueprintCheckout[];
|
|
40
|
+
/** Checkouts used as they are or restored earlier and built then: only described for the agent. */
|
|
41
|
+
readonly inPlace?: readonly BlueprintCheckout[];
|
|
42
|
+
readonly earlier?: readonly BlueprintCheckout[];
|
|
43
|
+
readonly config: BlueprintBuildConfig;
|
|
44
|
+
readonly signal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds the blueprints of the worktrees a resume restored and describes every checkout the session works in. Never
|
|
48
|
+
* rejects for a blueprint or for the state it keeps: a failure is in the outcome and the notices, and an unexpected
|
|
49
|
+
* one becomes a warning that the session resumed anyway. Only `signal` aborting rejects, with its reason.
|
|
50
|
+
*/
|
|
51
|
+
export declare function setUpResumedBlueprints(options: SetUpBlueprintsOptions): Promise<ResumedBlueprints>;
|
|
52
|
+
/**
|
|
53
|
+
* The restored worktrees of `checkouts` whose last build failed or never finished: they are built again. When the
|
|
54
|
+
* ledger cannot be read, none is known to be built, so all are; the build then reports the ledger as the failure.
|
|
55
|
+
*/
|
|
56
|
+
export declare function checkoutsNeedingRebuild(checkouts: readonly BlueprintCheckout[], storeDir: string): Promise<BlueprintCheckout[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Puts `context` in the session so the agent sees it in its next turn, unless the latest blueprint context in the
|
|
59
|
+
* session already says the same. A session that resumes again before anything changed gets no duplicate.
|
|
60
|
+
*/
|
|
61
|
+
export declare function recordBlueprintContext(sessionManager: SessionManager, context: string | undefined): Promise<void>;
|
|
62
|
+
/** The root of the repository `directory` is in, found by looking for `.git` upward; undefined outside a repository. */
|
|
63
|
+
export declare function enclosingRepositoryRoot(directory: string): string | undefined;
|
|
64
|
+
/** The worktree this machine restored that holds `directory`, under `storeDir`; undefined for any other directory. */
|
|
65
|
+
export declare function restoredWorktreeOf(storeDir: string, directory: string): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Puts the blueprint context of the worktree `directory` is in into a session that starts there without a resume of
|
|
68
|
+
* its own, such as a stage of a resumed workflow run. A directory outside the restored worktrees adds nothing. Never
|
|
69
|
+
* rejects: a kept context that cannot be read is returned as the typed failure, for the caller to report once, and the
|
|
70
|
+
* session starts without it.
|
|
71
|
+
*/
|
|
72
|
+
export declare function recordRestoredWorktreeContext(sessionManager: SessionManager, storeDir: string, directory: string): Promise<BlueprintBuildFailedError | undefined>;
|
|
73
|
+
//# sourceMappingURL=resume.d.ts.map
|