@bastani/atomic 0.9.20-alpha.5 → 0.9.20-alpha.7
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 +73 -0
- package/README.md +37 -0
- package/dist/builtin/intercom/CHANGELOG.md +10 -0
- package/dist/builtin/intercom/broker/broker.ts +110 -39
- package/dist/builtin/intercom/broker/client.ts +8 -1
- package/dist/builtin/intercom/index.bundle.mjs +61 -2
- package/dist/builtin/intercom/live-route-refusal.ts +69 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/recoverable-disconnect.ts +16 -4
- package/dist/builtin/intercom/skills/intercom/SKILL.md +11 -11
- package/dist/builtin/intercom/types.ts +3 -1
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/cua-driver/BROWSER.md +494 -0
- package/dist/builtin/subagents/skills/cua-driver/EMBEDDING.md +578 -0
- package/dist/builtin/subagents/skills/cua-driver/LINUX.md +364 -0
- package/dist/builtin/subagents/skills/cua-driver/MACOS.md +509 -0
- package/dist/builtin/subagents/skills/cua-driver/README.md +113 -0
- package/dist/builtin/subagents/skills/cua-driver/RECORDING.md +162 -0
- package/dist/builtin/subagents/skills/cua-driver/SKILL.md +1105 -0
- package/dist/builtin/subagents/skills/cua-driver/WINDOWS.md +866 -0
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +18 -8
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +34 -0
- package/dist/builtin/workflows/README.md +5 -19
- package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
- package/dist/builtin/workflows/builtin/{chunk-7f381xnq.js → chunk-2hzrv5y8.js} +140 -21
- package/dist/builtin/workflows/builtin/{chunk-e83tc6nr.js → chunk-3tx8ry44.js} +3 -2
- package/dist/builtin/workflows/builtin/{chunk-00ywx588.js → chunk-5724b0cf.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-zj5162bh.js → chunk-7bzcersz.js} +33 -22
- package/dist/builtin/workflows/builtin/{chunk-ne6vh5ct.js → chunk-7n51c5gh.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-x2nftpgj.js → chunk-9z3ztr2a.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-7h7s5xdj.js → chunk-dxjxtgmp.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-tvcydq13.js → chunk-ffdrv23t.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-pfm1kgqz.js → chunk-hmt5w62g.js} +12 -4
- package/dist/builtin/workflows/builtin/{chunk-tdqvdrg1.js → chunk-jngsbbpm.js} +3 -3
- package/dist/builtin/workflows/builtin/{chunk-55p5dxjk.js → chunk-njmf5ze7.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-evfb0312.js → chunk-vn0wb31x.js} +1 -1
- package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
- package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
- package/dist/builtin/workflows/builtin/goal.js +4 -4
- package/dist/builtin/workflows/builtin/index.js +12 -12
- package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +4 -4
- package/dist/builtin/workflows/builtin/steering-context.js +1 -1
- package/dist/builtin/workflows/builtin/tournament.js +3 -3
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +10 -9
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +4 -4
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +96 -23
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +75 -27
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +72 -26
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +58 -22
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +118 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +70 -29
- package/dist/builtin/workflows/skills/prompt-engineer/references/core_prompting.md +1 -1
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +95 -32
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +79 -30
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +139 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -4
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +446 -639
- package/dist/builtin/workflows/src/index.js +1434 -1277
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +15 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +40 -12
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +9 -8
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-boundaries.d.ts +68 -0
- package/dist/core/agent-session-boundaries.d.ts.map +1 -0
- package/dist/core/agent-session-boundaries.js +334 -0
- package/dist/core/agent-session-boundaries.js.map +1 -0
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +27 -13
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +16 -20
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +6 -3
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +33 -4
- 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-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +2 -1
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +93 -25
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +4 -9
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +4 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +7 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts +9 -0
- package/dist/core/agent-session-tasks.d.ts.map +1 -1
- package/dist/core/agent-session-tasks.js +68 -16
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +15 -5
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +9 -21
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +2 -3
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +8 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +18 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +22 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
- package/dist/core/compaction/compaction-boundary.js +11 -6
- package/dist/core/compaction/compaction-boundary.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +3 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +37 -0
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/crash-log.d.ts +6 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +69 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/execution-model-router.d.ts +15 -0
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +82 -33
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/export-html/template-js/tree-filter-render.js +6 -1
- package/dist/core/export-html/template.js +6 -1
- package/dist/core/extensions/agent-events.d.ts +69 -3
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +5 -3
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/event-results.d.ts +3 -0
- package/dist/core/extensions/event-results.d.ts.map +1 -1
- package/dist/core/extensions/event-results.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -2
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +2 -0
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runner-events.d.ts +16 -2
- package/dist/core/extensions/runner-events.d.ts.map +1 -1
- package/dist/core/extensions/runner-events.js +98 -5
- package/dist/core/extensions/runner-events.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/fast-model-variants.d.ts +16 -0
- package/dist/core/fast-model-variants.d.ts.map +1 -1
- package/dist/core/fast-model-variants.js +27 -0
- package/dist/core/fast-model-variants.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/messages.d.ts +10 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +57 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +52 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +16 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver-defaults.d.ts.map +1 -1
- package/dist/core/model-resolver-defaults.js +2 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/model-runtime.d.ts +13 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +16 -1
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/prompt-templates-async.d.ts +2 -2
- package/dist/core/prompt-templates-async.d.ts.map +1 -1
- package/dist/core/prompt-templates-async.js +57 -29
- package/dist/core/prompt-templates-async.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +6 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +61 -35
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +1 -0
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +19 -0
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/resource-loader-assets.d.ts.map +1 -1
- package/dist/core/resource-loader-assets.js +6 -6
- package/dist/core/resource-loader-assets.js.map +1 -1
- package/dist/core/sdk-types.d.ts +5 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +10 -3
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +65 -7
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +4 -1
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +8 -0
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +16 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +105 -42
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +30 -3
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/structured-output/index.d.ts +1 -1
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +37 -41
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/jev-client.d.ts +13 -8
- package/dist/core/structured-output/jev-client.d.ts.map +1 -1
- package/dist/core/structured-output/jev-client.js +90 -32
- package/dist/core/structured-output/jev-client.js.map +1 -1
- package/dist/core/structured-output/jev.d.ts.map +1 -1
- package/dist/core/structured-output/jev.js +38 -64
- package/dist/core/structured-output/jev.js.map +1 -1
- package/dist/core/structured-output/resolver.d.ts +32 -24
- package/dist/core/structured-output/resolver.d.ts.map +1 -1
- package/dist/core/structured-output/resolver.js +57 -9
- package/dist/core/structured-output/resolver.js.map +1 -1
- package/dist/core/structured-output/types.d.ts +8 -6
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/child-command-owner.d.ts +34 -0
- package/dist/core/tasks/child-command-owner.d.ts.map +1 -0
- package/dist/core/tasks/child-command-owner.js +70 -0
- package/dist/core/tasks/child-command-owner.js.map +1 -0
- package/dist/core/tools/bash-pty-native.d.ts +5 -1
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +15 -7
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/kill.d.ts +2 -2
- package/dist/core/tools/kill.d.ts.map +1 -1
- package/dist/core/tools/kill.js +3 -4
- package/dist/core/tools/kill.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +5 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/main-app-mode.d.ts +1 -1
- package/dist/main-app-mode.d.ts.map +1 -1
- package/dist/main-app-mode.js +3 -2
- package/dist/main-app-mode.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +6 -0
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-model.js +1 -0
- package/dist/modes/interactive/components/tree-selector-model.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +17 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +2 -4
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.js +16 -0
- package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +13 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +5 -1
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.d.ts +16 -0
- package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js +27 -0
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +4 -1
- 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 +7 -2
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +3 -1
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +2 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +2 -2
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/mime.js +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +3 -1
- package/dist/utils/tool-result-images.d.ts.map +1 -1
- package/dist/utils/tool-result-images.js +4 -1
- package/dist/utils/tool-result-images.js.map +1 -1
- package/docs/background-tasks.md +11 -2
- package/docs/compaction.md +5 -1
- package/docs/computer-use.md +105 -56
- package/docs/environment-variables.md +1 -1
- package/docs/extensions/events.md +75 -7
- package/docs/extensions.md +6 -2
- package/docs/getting-started/first-session.md +3 -2
- package/docs/intercom/operations.md +13 -1
- package/docs/intercom.md +1 -1
- package/docs/llama-cpp.md +2 -2
- package/docs/models/evals.md +108 -118
- package/docs/models/reference.md +31 -3
- package/docs/packages.md +2 -0
- package/docs/prompt-templates.md +1 -0
- package/docs/providers.md +19 -6
- package/docs/reference/cli.md +2 -2
- package/docs/rpc/examples.md +2 -0
- package/docs/sdk/reference.md +2 -3
- package/docs/sdk/structured-decisions.md +25 -18
- package/docs/sdk.md +13 -2
- package/docs/session-format.md +17 -2
- package/docs/settings.md +8 -8
- package/docs/skills.md +8 -2
- package/docs/subagents/reference.md +4 -4
- package/docs/subagents.md +2 -2
- package/docs/workflows/api-reference.md +7 -34
- package/docs/workflows/authoring.md +191 -0
- package/docs/workflows/builtins.md +1 -1
- package/docs/workflows/operations.md +18 -78
- package/docs/workflows/reliable-design.md +14 -29
- package/docs/workflows/verification.md +21 -8
- package/docs/workflows.md +8 -7
- package/examples/rpc-client.ts +38 -0
- package/examples/rpc-extension-ui.ts +19 -5
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +69 -69
- package/package.json +8 -8
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_astra.md +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,CAAU,CAAC;AA4DvH,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AACxD,gGAAgG;AAChG,MAAM,UAAU,iCAAiC,CAAC,KAA+B;IAChF,OAAO;QACN,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,aAAa,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,IAAI,oBAAoB,CAAC,CAAC;QACjE,YAAY,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE;QAC/C,cAAc,EAAE,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAC/F;QACD,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QACrD,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,IAAI,EAAE;QAClD,QAAQ,EAAE,EAAE,GAAG,CAAC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ACjD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getSystemMessageText } from \"@bastani/pi-ai\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\", \"find\", \"search\", \"ask_user_question\", \"todo\"] as const;\n\nexport interface SystemPromptModel {\n\t/** Provider identifier for the selected model. */\n\tprovider: string;\n\t/** Stable provider-specific model identifier. */\n\tid: string;\n\t/** Human-readable model name, when available. */\n\tname?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default prefix). */\n\tcustomPrompt?: string;\n\t/** Exact full prompt replacement set by a before_agent_start handler. */\n\tforceSystemPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write, find, search, ask_user_question, todo] */\n\tselectedTools?: string[];\n\t/** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n\texcludedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Guideline bullets contributed by each tool, keyed by tool name. */\n\ttoolGuidelines?: Record<string, string[]>;\n\t/** Additional guideline bullets appended to the default system prompt rules. */\n\tpromptGuidelines?: string[];\n\t/** Text appended from user configuration before project context, skills, and cwd. */\n\tappendSystemPrompt?: string;\n\t/** Additional XML-wrapped prompt sections keyed by tag name. */\n\tsections?: Record<string, string>;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Currently selected model, used for model-aware prompt metadata. */\n\tselectedModel?: SystemPromptModel;\n\t/** Current reasoning/thinking level for the selected model. */\n\tselectedThinkingLevel?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\nexport type NormalizedBuildSystemPromptOptions = BuildSystemPromptOptions & {\n\tselectedTools: string[];\n\ttoolSnippets: Record<string, string>;\n\ttoolGuidelines: Record<string, string[]>;\n\tpromptGuidelines: string[];\n\tappendSystemPrompt: string;\n\tsections: Record<string, string>;\n\tcontextFiles: Array<{ path: string; content: string }>;\n\tskills: Skill[];\n};\n\n/**\n * Ordered system prompt sections, keyed by name. `preamble` is untagged text; every other\n * section is wrapped in a tag of the same name so the model can match later updates to it.\n * These become `SystemMessage.sections` in the transcript.\n */\nexport type SystemPromptSections = Record<string, string>;\n\nconst SYSTEM_PROMPT_SECTION_NAME = /^[a-z][a-z0-9_-]*$/;\n/** Normalize prompt input into the mutable, collection-complete shape exposed to extensions. */\nexport function normalizeBuildSystemPromptOptions(input: BuildSystemPromptOptions): NormalizedBuildSystemPromptOptions {\n\treturn {\n\t\tcustomPrompt: input.customPrompt,\n\t\tforceSystemPrompt: input.forceSystemPrompt,\n\t\tselectedTools: [...(input.selectedTools ?? DEFAULT_PROMPT_TOOLS)],\n\t\ttoolSnippets: { ...(input.toolSnippets ?? {}) },\n\t\ttoolGuidelines: Object.fromEntries(\n\t\t\tObject.entries(input.toolGuidelines ?? {}).map(([name, guidelines]) => [name, [...guidelines]]),\n\t\t),\n\t\tpromptGuidelines: [...(input.promptGuidelines ?? [])],\n\t\tappendSystemPrompt: input.appendSystemPrompt ?? \"\",\n\t\tsections: { ...(input.sections ?? {}) },\n\t\tcwd: input.cwd,\n\t\t...(input.excludedTools === undefined ? {} : { excludedTools: [...input.excludedTools] }),\n\t\t...(input.selectedModel === undefined ? {} : { selectedModel: { ...input.selectedModel } }),\n\t\t...(input.selectedThinkingLevel === undefined ? {} : { selectedThinkingLevel: input.selectedThinkingLevel }),\n\t\tcontextFiles: (input.contextFiles ?? []).map((file) => ({ ...file })),\n\t\tskills: (input.skills ?? []).map((skill) => ({ ...skill })),\n\t};\n}\n\nfunction renderProjectContext(contextFiles: Array<{ path: string; content: string }>): string {\n\treturn [\n\t\t\"Project-specific instructions and guidelines:\",\n\t\t...contextFiles.map(\n\t\t\t({ path, content }) => `<project_instructions path=\"${path}\">\\n${content}\\n</project_instructions>`,\n\t\t),\n\t].join(\"\\n\\n\");\n}\n\nfunction buildRules(\n\tselectedTools: string[],\n\ttoolGuidelines: Record<string, string[]>,\n\tpromptGuidelines: string[],\n): string {\n\tconst rules: string[] = [];\n\tconst seen = new Set<string>();\n\tconst addRule = (rule: string): void => {\n\t\tconst normalized = rule.trim();\n\t\tif (!normalized || seen.has(normalized)) return;\n\t\tseen.add(normalized);\n\t\trules.push(normalized);\n\t};\n\n\tconst tools = selectedTools;\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasPowerShell = tools.includes(\"powershell\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst shouldIncludeAskUserFallbackGuidance = tools.length > 0 && !tools.includes(\"ask_user_question\");\n\tconst addGuideline = addRule;\n\tif ((hasBash || hasPowerShell) && !hasFind && !hasLs) {\n\t\tif (hasBash && hasPowerShell) {\n\t\t\taddRule(\"Use bash or PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else if (hasPowerShell) {\n\t\t\taddRule(\"Use PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else {\n\t\t\taddRule(\"Use bash for file operations like ls, rg, find\");\n\t\t}\n\t}\n\tif (shouldIncludeAskUserFallbackGuidance) {\n\t\taddGuideline(\n\t\t\t\"If an equivalent user-question tool is available, use it for all questions to the user instead of plain text, including confirmations and approvals, following its supported schema. When no usable question tool or human-input channel exists, do not stall on a question: choose the interpretation best supported by the repository and the stated objective, state the assumption in your response, and continue fully autonomously on best judgment. Tool unavailability alone is not a blocker. Preserve safety and authorization constraints.\",\n\t\t);\n\t}\n\tif (hasBash || hasPowerShell) {\n\t\taddGuideline(\n\t\t\t\"**Repository intent**: When working in a repository, infer how its maintainers actually work before imposing defaults: review recent commits, open and merged PRs, issues and their comments, and project/board status when tooling allows (for example `git log` and the `gh` CLI) to learn conventions, priorities, and scope norms. Better, identify the requesting user (`git config user.name`/`user.email`, `gh api user`) and study their own commits, PRs, reviews, and issue comments so you interpret ambiguous requests the way they would, aligning style, scope, and process with their patterns.\",\n\t\t);\n\t}\n\n\tfor (const name of selectedTools) {\n\t\tfor (const rule of toolGuidelines[name] ?? []) addRule(rule);\n\t}\n\tfor (const rule of promptGuidelines) addRule(rule);\n\taddRule(\n\t\t\"Write self-describing code and do not add comments unless the user explicitly asks for them or the task instructions call for them. Code that needs a comment to be understood is a smell: restructure it with clearer names, smaller units, or explicit types instead\",\n\t);\n\taddRule(\"Be concise in your responses\");\n\taddRule(\"Show file paths clearly when working with files\");\n\treturn rules.map((rule) => `- ${rule}`).join(\"\\n\");\n}\n\n/** Build the ordered, independently replaceable sections of the structured system prompt. */\nexport function buildSystemPromptSections(input: BuildSystemPromptOptions): SystemPromptSections {\n\tconst options = normalizeBuildSystemPromptOptions(input);\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\ttoolGuidelines,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tsections: customSections,\n\t\tcwd,\n\t\tcontextFiles,\n\t\tskills,\n\t} = options;\n\tconst explicitlyExcludedTools = new Set(options.excludedTools ?? []);\n\tconst tools = selectedTools.filter((name) => !explicitlyExcludedTools.has(name));\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\tconst modelName = options.selectedModel?.name?.trim() || options.selectedModel?.id || \"unknown\";\n\tconst modelReasoningLevel = options.selectedThinkingLevel?.trim() || \"off\";\n\tconst now = new Date();\n\tconst date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}`;\n\n\tfor (const name of Object.keys(customSections)) {\n\t\tif (!SYSTEM_PROMPT_SECTION_NAME.test(name) || name === \"preamble\") {\n\t\t\tthrow new Error(`Invalid system prompt section name: ${name}`);\n\t\t}\n\t}\n\n\tconst promptSections: Record<string, string> = {};\n\tif (customPrompt) {\n\t\tpromptSections.preamble = customPrompt;\n\t} else {\n\t\tpromptSections.preamble =\n\t\t\t\"You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\";\n\t\tconst visibleTools = tools.filter((name) => !!toolSnippets[name]);\n\t\tconst toolsList =\n\t\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join(\"\\n\") : \"(none)\";\n\t\tpromptSections.tools = `Available tools:\\n${toolsList}\\n\\nIn addition to the tools above, you may have access to other custom tools depending on the project.`;\n\t\tpromptSections.rules = `Guidelines:\\n${buildRules(tools, toolGuidelines, promptGuidelines)}`;\n\t\tpromptSections.docs = `\nAtomic documentation (read when the user asks about model choice, computer use or automation, MCP, web access, intercom, subagents, or customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- Bundled integrations use the same docs root in npm and binary installations: MCP servers (docs/mcp-servers.md), web access (docs/web-access.md), intercom (docs/intercom.md), subagents (docs/subagents.md), workflows (docs/workflows.md). Read these guides rather than guessing paths inside builtin packages.\n- When the user asks which model to choose for a task, read ${docsPath}/models/model-selection.md and ${docsPath}/models/evals.md, then consult https://artificialanalysis.ai/ for the relevant benchmark charts and methodology. Match the task to individual evaluations rather than an aggregate winner. Cite the benchmark, source date, exact model/effort and cost or latency tradeoff; distinguish measured results from recommendations. If live evidence is unavailable, label the dated docs snapshot instead of claiming a refresh. Check the configured catalog before giving an exact provider/model or thinking setting; catalog presence is not proof of live access.\n- For computer use (CUA), use PyAutoGUI for desktop mouse, keyboard and screenshot automation; for browser automation use the agent-browser skill. For terminal automation/testing, prefer herdr on macOS, Linux and Windows; install it if missing when network access and permissions permit, and fall back to tmux or native Windows psmux if installation or use is not possible. Load the matching skill and ${docsPath}/workflows/verification.md. Preserve the pinned herdr skill's explicit-request and HERDR_ENV=1 requirements; never control a focused session from outside Herdr. Check installed capabilities, use dedicated sessions, preserve desktop failsafes and permissions, and release held input on interruption. These CLIs are not interchangeable, and skills do not grant tools or authorization.\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\t}\n\n\tif (appendSystemPrompt) promptSections.addendum = appendSystemPrompt;\n\tif (contextFiles.length > 0) promptSections.project_context = renderProjectContext(contextFiles);\n\tconst skillFileReadTool = ([\"read\", \"bash\"] as const).find((tool) => tools.includes(tool));\n\tif (skillFileReadTool && skills.length > 0) {\n\t\tconst skillsPrompt = formatSkillsForPrompt(skills, skillFileReadTool).trim();\n\t\tif (skillsPrompt) promptSections.skills = skillsPrompt;\n\t}\n\tpromptSections.model = `Model name (used for commit attribution): ${modelName}\\nModel reasoning level: ${modelReasoningLevel}`;\n\tpromptSections.date = `Current date: ${date}`;\n\tpromptSections.cwd = `Current working directory: ${cwd.replace(/\\\\/g, \"/\")}`;\n\tfor (const [name, content] of Object.entries(customSections)) {\n\t\tif (content) promptSections[name] = content;\n\t}\n\n\tconst sections: SystemPromptSections = { preamble: promptSections.preamble };\n\tfor (const [name, content] of Object.entries(promptSections)) {\n\t\tif (name !== \"preamble\") sections[name] = `<${name}>\\n${content}\\n</${name}>`;\n\t}\n\treturn sections;\n}\n\n/**\n * The complete prompt state for `input`. A forced prompt is opaque and lives in `content`\n * with no sections; otherwise `content` is empty and the structured sections carry the prompt.\n */\nexport function buildSystemPromptState(input: BuildSystemPromptOptions): {\n\tcontent: string;\n\tsections?: SystemPromptSections;\n} {\n\tif (input.forceSystemPrompt !== undefined) return { content: input.forceSystemPrompt };\n\treturn { content: \"\", sections: buildSystemPromptSections(input) };\n}\n\n/** Build the system prompt text, rendered exactly as the transcript's system message replays it. */\nexport function buildSystemPrompt(input: BuildSystemPromptOptions): string {\n\treturn getSystemMessageText({ role: \"system\", ...buildSystemPromptState(input), timestamp: 0 });\n}\n\n/**\n * Diff the sections the model currently has (replayed from the transcript, so never null)\n * against the desired ones. Returns a `SystemMessage.sections` patch, or undefined when\n * nothing changed.\n */\nexport function diffSystemPromptSections(\n\tprevious: Record<string, string | null>,\n\tcurrent: SystemPromptSections,\n): Record<string, string | null> | undefined {\n\tconst patch: Record<string, string | null> = {};\n\tfor (const [name, text] of Object.entries(current)) {\n\t\tif (previous[name] !== text) patch[name] = text;\n\t}\n\tfor (const name of Object.keys(previous)) {\n\t\tif (current[name] === undefined) patch[name] = null;\n\t}\n\treturn Object.keys(patch).length > 0 ? patch : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,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D,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getSystemMessageText } from \"@bastani/pi-ai\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\", \"find\", \"search\", \"ask_user_question\", \"todo\"] as const;\n\nexport interface SystemPromptModel {\n\t/** Provider identifier for the selected model. */\n\tprovider: string;\n\t/** Stable provider-specific model identifier. */\n\tid: string;\n\t/** Human-readable model name, when available. */\n\tname?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default prefix). */\n\tcustomPrompt?: string;\n\t/** Exact full prompt replacement set by a before_agent_start handler. */\n\tforceSystemPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write, find, search, ask_user_question, todo] */\n\tselectedTools?: string[];\n\t/** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n\texcludedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Guideline bullets contributed by each tool, keyed by tool name. */\n\ttoolGuidelines?: Record<string, string[]>;\n\t/** Additional guideline bullets appended to the default system prompt rules. */\n\tpromptGuidelines?: string[];\n\t/** Text appended from user configuration before project context, skills, and cwd. */\n\tappendSystemPrompt?: string;\n\t/** Additional XML-wrapped prompt sections keyed by tag name. */\n\tsections?: Record<string, string>;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Currently selected model, used for model-aware prompt metadata. */\n\tselectedModel?: SystemPromptModel;\n\t/** Current reasoning/thinking level for the selected model. */\n\tselectedThinkingLevel?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\nexport type NormalizedBuildSystemPromptOptions = BuildSystemPromptOptions & {\n\tselectedTools: string[];\n\ttoolSnippets: Record<string, string>;\n\ttoolGuidelines: Record<string, string[]>;\n\tpromptGuidelines: string[];\n\tappendSystemPrompt: string;\n\tsections: Record<string, string>;\n\tcontextFiles: Array<{ path: string; content: string }>;\n\tskills: Skill[];\n};\n\n/**\n * Ordered system prompt sections, keyed by name. `preamble` is untagged text; every other\n * section is wrapped in a tag of the same name so the model can match later updates to it.\n * These become `SystemMessage.sections` in the transcript.\n */\nexport type SystemPromptSections = Record<string, string>;\n\nconst SYSTEM_PROMPT_SECTION_NAME = /^[a-z][a-z0-9_-]*$/;\n/** Normalize prompt input into the mutable, collection-complete shape exposed to extensions. */\nexport function normalizeBuildSystemPromptOptions(input: BuildSystemPromptOptions): NormalizedBuildSystemPromptOptions {\n\treturn {\n\t\tcustomPrompt: input.customPrompt,\n\t\tforceSystemPrompt: input.forceSystemPrompt,\n\t\tselectedTools: [...(input.selectedTools ?? DEFAULT_PROMPT_TOOLS)],\n\t\ttoolSnippets: { ...(input.toolSnippets ?? {}) },\n\t\ttoolGuidelines: Object.fromEntries(\n\t\t\tObject.entries(input.toolGuidelines ?? {}).map(([name, guidelines]) => [name, [...guidelines]]),\n\t\t),\n\t\tpromptGuidelines: [...(input.promptGuidelines ?? [])],\n\t\tappendSystemPrompt: input.appendSystemPrompt ?? \"\",\n\t\tsections: { ...(input.sections ?? {}) },\n\t\tcwd: input.cwd,\n\t\t...(input.excludedTools === undefined ? {} : { excludedTools: [...input.excludedTools] }),\n\t\t...(input.selectedModel === undefined ? {} : { selectedModel: { ...input.selectedModel } }),\n\t\t...(input.selectedThinkingLevel === undefined ? {} : { selectedThinkingLevel: input.selectedThinkingLevel }),\n\t\tcontextFiles: (input.contextFiles ?? []).map((file) => ({ ...file })),\n\t\tskills: (input.skills ?? []).map((skill) => ({ ...skill })),\n\t};\n}\n\nfunction renderProjectContext(contextFiles: Array<{ path: string; content: string }>): string {\n\treturn [\n\t\t\"Project-specific instructions and guidelines:\",\n\t\t...contextFiles.map(\n\t\t\t({ path, content }) => `<project_instructions path=\"${path}\">\\n${content}\\n</project_instructions>`,\n\t\t),\n\t].join(\"\\n\\n\");\n}\n\nfunction buildRules(\n\tselectedTools: string[],\n\ttoolGuidelines: Record<string, string[]>,\n\tpromptGuidelines: string[],\n): string {\n\tconst rules: string[] = [];\n\tconst seen = new Set<string>();\n\tconst addRule = (rule: string): void => {\n\t\tconst normalized = rule.trim();\n\t\tif (!normalized || seen.has(normalized)) return;\n\t\tseen.add(normalized);\n\t\trules.push(normalized);\n\t};\n\n\tconst tools = selectedTools;\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasPowerShell = tools.includes(\"powershell\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst shouldIncludeAskUserFallbackGuidance = tools.length > 0 && !tools.includes(\"ask_user_question\");\n\tconst addGuideline = addRule;\n\tif ((hasBash || hasPowerShell) && !hasFind && !hasLs) {\n\t\tif (hasBash && hasPowerShell) {\n\t\t\taddRule(\"Use bash or PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else if (hasPowerShell) {\n\t\t\taddRule(\"Use PowerShell for file operations like listing, searching, and finding files\");\n\t\t} else {\n\t\t\taddRule(\"Use bash for file operations like ls, rg, find\");\n\t\t}\n\t}\n\tif (shouldIncludeAskUserFallbackGuidance) {\n\t\taddGuideline(\n\t\t\t\"If an equivalent user-question tool is available, use it for all questions to the user instead of plain text, including confirmations and approvals, following its supported schema. When no usable question tool or human-input channel exists, do not stall on a question: choose the interpretation best supported by the repository and the stated objective, state the assumption in your response, and continue fully autonomously on best judgment. Tool unavailability alone is not a blocker. Preserve safety and authorization constraints.\",\n\t\t);\n\t}\n\tif (hasBash || hasPowerShell) {\n\t\taddGuideline(\n\t\t\t\"**Repository intent**: When working in a repository, infer how its maintainers actually work before imposing defaults: review recent commits, open and merged PRs, issues and their comments, and project/board status when tooling allows (for example `git log` and the `gh` CLI) to learn conventions, priorities, and scope norms. Better, identify the requesting user (`git config user.name`/`user.email`, `gh api user`) and study their own commits, PRs, reviews, and issue comments so you interpret ambiguous requests the way they would, aligning style, scope, and process with their patterns.\",\n\t\t);\n\t}\n\n\tfor (const name of selectedTools) {\n\t\tfor (const rule of toolGuidelines[name] ?? []) addRule(rule);\n\t}\n\tfor (const rule of promptGuidelines) addRule(rule);\n\taddRule(\n\t\t\"Write self-describing code and do not add comments unless the user explicitly asks for them or the task instructions call for them. Code that needs a comment to be understood is a smell: restructure it with clearer names, smaller units, or explicit types instead\",\n\t);\n\taddRule(\"Be concise in your responses\");\n\taddRule(\"Show file paths clearly when working with files\");\n\treturn rules.map((rule) => `- ${rule}`).join(\"\\n\");\n}\n\n/** Build the ordered, independently replaceable sections of the structured system prompt. */\nexport function buildSystemPromptSections(input: BuildSystemPromptOptions): SystemPromptSections {\n\tconst options = normalizeBuildSystemPromptOptions(input);\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\ttoolGuidelines,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tsections: customSections,\n\t\tcwd,\n\t\tcontextFiles,\n\t\tskills,\n\t} = options;\n\tconst explicitlyExcludedTools = new Set(options.excludedTools ?? []);\n\tconst tools = selectedTools.filter((name) => !explicitlyExcludedTools.has(name));\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\tconst modelName = options.selectedModel?.name?.trim() || options.selectedModel?.id || \"unknown\";\n\tconst modelReasoningLevel = options.selectedThinkingLevel?.trim() || \"off\";\n\tconst now = new Date();\n\tconst date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}`;\n\n\tfor (const name of Object.keys(customSections)) {\n\t\tif (!SYSTEM_PROMPT_SECTION_NAME.test(name) || name === \"preamble\") {\n\t\t\tthrow new Error(`Invalid system prompt section name: ${name}`);\n\t\t}\n\t}\n\n\tconst promptSections: Record<string, string> = {};\n\tif (customPrompt) {\n\t\tpromptSections.preamble = customPrompt;\n\t} else {\n\t\tpromptSections.preamble =\n\t\t\t\"You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\";\n\t\tconst visibleTools = tools.filter((name) => !!toolSnippets[name]);\n\t\tconst toolsList =\n\t\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join(\"\\n\") : \"(none)\";\n\t\tpromptSections.tools = `Available tools:\\n${toolsList}\\n\\nIn addition to the tools above, you may have access to other custom tools depending on the project.`;\n\t\tpromptSections.rules = `Guidelines:\\n${buildRules(tools, toolGuidelines, promptGuidelines)}`;\n\t\tpromptSections.docs = `\nAtomic documentation (read when the user asks about model choice, computer use or automation, MCP, web access, intercom, subagents, or customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- Bundled integrations use the same docs root in npm and binary installations: MCP servers (docs/mcp-servers.md), web access (docs/web-access.md), intercom (docs/intercom.md), subagents (docs/subagents.md), workflows (docs/workflows.md). Read these guides rather than guessing paths inside builtin packages.\n- When the user asks which model to choose for a task, read ${docsPath}/models/model-selection.md and ${docsPath}/models/evals.md, then consult https://artificialanalysis.ai/ for the relevant benchmark charts and methodology. Match the task to individual evaluations rather than an aggregate winner. Cite the benchmark, source date, exact model/effort and cost or latency tradeoff; distinguish measured results from recommendations. If live evidence is unavailable, label the dated docs snapshot instead of claiming a refresh. Check the configured catalog before giving an exact provider/model or thinking setting; catalog presence is not proof of live access.\n- For computer use (CUA) on desktop apps, simulators and emulators, use Cua Driver through the cua-driver skill and one-shot \\`cua-driver call <tool>\\` commands: when a model chooses the next action (interactive sessions or any workflow stage acting outside ctx.tool), use the CLI; when workflow TypeScript code owns the sequence and postcondition, use the @trycua/cua-driver TypeScript SDK inside ctx.tool. If \\`cua-driver --version\\` fails, make one bounded attempt with upstream's one-line installer and report its side effects; never run \\`cua-driver skills install\\`. Run every cua-driver command with CUA_DRIVER_RS_TELEMETRY_ENABLED=false and follow ${docsPath}/computer-use.md for install, readiness and permissions. Prefer the agent-browser skill for what it covers: websites and web apps in Chrome/Chromium, Electron desktop apps such as VS Code, Slack, Discord, Figma, Notion and Spotify, Slack workspaces, and cloud browsers. Use cua-driver for everything else (native desktop apps, iOS simulators, Android emulators, OS dialogs and permission prompts, non-Chromium browsers) and whenever agent-browser hits a limitation. For terminal automation/testing, prefer herdr on macOS, Linux and Windows; install it if missing when network access and permissions permit, and fall back to tmux or native Windows psmux if installation or use is not possible. Load the matching skill and ${docsPath}/workflows/verification.md. Preserve the pinned herdr skill's explicit-request and HERDR_ENV=1 requirements; never control a focused session from outside Herdr. Check installed capabilities, use dedicated sessions, respect desktop permissions, and stop before destructive actions. These CLIs are not interchangeable, and skills do not grant tools or authorization.\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\t}\n\n\tif (appendSystemPrompt) promptSections.addendum = appendSystemPrompt;\n\tif (contextFiles.length > 0) promptSections.project_context = renderProjectContext(contextFiles);\n\tconst skillFileReadTool = ([\"read\", \"bash\"] as const).find((tool) => tools.includes(tool));\n\tif (skillFileReadTool && skills.length > 0) {\n\t\tconst skillsPrompt = formatSkillsForPrompt(skills, skillFileReadTool).trim();\n\t\tif (skillsPrompt) promptSections.skills = skillsPrompt;\n\t}\n\tpromptSections.model = `Model name (used for commit attribution): ${modelName}\\nModel reasoning level: ${modelReasoningLevel}`;\n\tpromptSections.date = `Current date: ${date}`;\n\tpromptSections.cwd = `Current working directory: ${cwd.replace(/\\\\/g, \"/\")}`;\n\tfor (const [name, content] of Object.entries(customSections)) {\n\t\tif (content) promptSections[name] = content;\n\t}\n\n\tconst sections: SystemPromptSections = { preamble: promptSections.preamble };\n\tfor (const [name, content] of Object.entries(promptSections)) {\n\t\tif (name !== \"preamble\") sections[name] = `<${name}>\\n${content}\\n</${name}>`;\n\t}\n\treturn sections;\n}\n\n/**\n * The complete prompt state for `input`. A forced prompt is opaque and lives in `content`\n * with no sections; otherwise `content` is empty and the structured sections carry the prompt.\n */\nexport function buildSystemPromptState(input: BuildSystemPromptOptions): {\n\tcontent: string;\n\tsections?: SystemPromptSections;\n} {\n\tif (input.forceSystemPrompt !== undefined) return { content: input.forceSystemPrompt };\n\treturn { content: \"\", sections: buildSystemPromptSections(input) };\n}\n\n/** Build the system prompt text, rendered exactly as the transcript's system message replays it. */\nexport function buildSystemPrompt(input: BuildSystemPromptOptions): string {\n\treturn getSystemMessageText({ role: \"system\", ...buildSystemPromptState(input), timestamp: 0 });\n}\n\n/**\n * Diff the sections the model currently has (replayed from the transcript, so never null)\n * against the desired ones. Returns a `SystemMessage.sections` patch, or undefined when\n * nothing changed.\n */\nexport function diffSystemPromptSections(\n\tprevious: Record<string, string | null>,\n\tcurrent: SystemPromptSections,\n): Record<string, string | null> | undefined {\n\tconst patch: Record<string, string | null> = {};\n\tfor (const [name, text] of Object.entries(current)) {\n\t\tif (previous[name] !== text) patch[name] = text;\n\t}\n\tfor (const name of Object.keys(previous)) {\n\t\tif (current[name] === undefined) patch[name] = null;\n\t}\n\treturn Object.keys(patch).length > 0 ? patch : undefined;\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SupervisedCommandOwner } from "../tools/bash-pty-native.js";
|
|
2
|
+
import type { AgentTaskHost } from "./agent-adapter.js";
|
|
3
|
+
import type { TaskId, YieldReason } from "./contracts.js";
|
|
4
|
+
import type { TaskSupervisor, WaitLease } from "./supervisor.js";
|
|
5
|
+
export type TaskCompletionMessage = {
|
|
6
|
+
customType: string;
|
|
7
|
+
content: string;
|
|
8
|
+
details: object;
|
|
9
|
+
display: true;
|
|
10
|
+
};
|
|
11
|
+
/** Live delivery into the child that launched a shell task, while that child still runs. */
|
|
12
|
+
export interface ChildTaskCompletionRoute {
|
|
13
|
+
isOpen(): boolean;
|
|
14
|
+
deliver(message: TaskCompletionMessage): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parent-issued capability that lets an in-process subagent child run shell tasks
|
|
18
|
+
* in the parent's task owner, so they appear in the parent's `/tasks` and outlive
|
|
19
|
+
* the child. It never authorizes agent launches.
|
|
20
|
+
*/
|
|
21
|
+
export interface ChildCommandTaskOwner {
|
|
22
|
+
bind(childId: string, route: ChildTaskCompletionRoute, waits: ChildTaskWaits): SupervisedCommandOwner;
|
|
23
|
+
}
|
|
24
|
+
/** Completion route for a task a child launched in this owner, only while that child accepts messages. */
|
|
25
|
+
export declare function childTaskCompletionRoute(host: AgentTaskHost, taskId: TaskId): ChildTaskCompletionRoute | undefined;
|
|
26
|
+
/** Resolve the parent's live owner per call so session replacement is followed like the parent's own shells. */
|
|
27
|
+
export declare function createChildCommandTaskOwner(resolveHost: () => AgentTaskHost): ChildCommandTaskOwner;
|
|
28
|
+
/** Child-side waits on parent-owned tasks; inbound child messages release observation, never execution. */
|
|
29
|
+
export declare class ChildTaskWaits {
|
|
30
|
+
private readonly waits;
|
|
31
|
+
track(supervisor: TaskSupervisor, wait: WaitLease): void;
|
|
32
|
+
yieldAll(reason: YieldReason): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=child-command-owner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-command-owner.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/child-command-owner.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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launchedBy = new Map();
|
|
4
|
+
this.routes = new Map();
|
|
5
|
+
}
|
|
6
|
+
bind(childId, route) {
|
|
7
|
+
this.routes.set(childId, route);
|
|
8
|
+
}
|
|
9
|
+
recordLaunch(taskId, childId) {
|
|
10
|
+
this.launchedBy.set(taskId, childId);
|
|
11
|
+
}
|
|
12
|
+
launchedByChild(taskId, childId) {
|
|
13
|
+
return this.launchedBy.get(taskId) === childId;
|
|
14
|
+
}
|
|
15
|
+
openRoute(taskId) {
|
|
16
|
+
const childId = this.launchedBy.get(taskId);
|
|
17
|
+
const route = childId === undefined ? undefined : this.routes.get(childId);
|
|
18
|
+
return route?.isOpen() ? route : undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const routesByHost = new WeakMap();
|
|
22
|
+
function routesFor(host) {
|
|
23
|
+
let routes = routesByHost.get(host);
|
|
24
|
+
if (!routes) {
|
|
25
|
+
routes = new ChildCommandTaskRoutes();
|
|
26
|
+
routesByHost.set(host, routes);
|
|
27
|
+
}
|
|
28
|
+
return routes;
|
|
29
|
+
}
|
|
30
|
+
/** Completion route for a task a child launched in this owner, only while that child accepts messages. */
|
|
31
|
+
export function childTaskCompletionRoute(host, taskId) {
|
|
32
|
+
return routesByHost.get(host)?.openRoute(taskId);
|
|
33
|
+
}
|
|
34
|
+
/** Resolve the parent's live owner per call so session replacement is followed like the parent's own shells. */
|
|
35
|
+
export function createChildCommandTaskOwner(resolveHost) {
|
|
36
|
+
return {
|
|
37
|
+
bind(childId, route, waits) {
|
|
38
|
+
const host = resolveHost();
|
|
39
|
+
const routes = routesFor(host);
|
|
40
|
+
routes.bind(childId, route);
|
|
41
|
+
const { supervisor, owner } = host.ownerBinding;
|
|
42
|
+
return {
|
|
43
|
+
supervisor,
|
|
44
|
+
owner,
|
|
45
|
+
ownsTask: (taskId) => routes.launchedByChild(taskId, childId),
|
|
46
|
+
onCommandStarted: (taskId) => routes.recordLaunch(taskId, childId),
|
|
47
|
+
waitForTask: (taskId, budgetMs, onRegistered) => supervisor.waitForTaskId(owner, taskId, budgetMs, (wait) => {
|
|
48
|
+
waits.track(supervisor, wait);
|
|
49
|
+
onRegistered?.(wait);
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Child-side waits on parent-owned tasks; inbound child messages release observation, never execution. */
|
|
56
|
+
export class ChildTaskWaits {
|
|
57
|
+
constructor() {
|
|
58
|
+
this.waits = new Map();
|
|
59
|
+
}
|
|
60
|
+
track(supervisor, wait) {
|
|
61
|
+
this.waits.set(wait, supervisor);
|
|
62
|
+
const remove = () => this.waits.delete(wait);
|
|
63
|
+
void supervisor.observeTaskWait(wait).then(remove, remove);
|
|
64
|
+
}
|
|
65
|
+
yieldAll(reason) {
|
|
66
|
+
for (const [wait, supervisor] of this.waits)
|
|
67
|
+
supervisor.yieldTaskWait(wait, reason);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=child-command-owner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-command-owner.js","sourceRoot":"","sources":["../../../src/core/tasks/child-command-owner.ts"],"names":[],"mappings":"AA2BA,MAAM,sBAAsB;IAA5B;QACkB,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QACvC,WAAM,GAAG,IAAI,GAAG,EAAoC,CAAC;IAmBvE,CAAC;IAjBA,IAAI,CAAC,OAAe,EAAE,KAA+B;QACpD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,OAAe;QAC3C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,eAAe,CAAC,MAAc,EAAE,OAAe;QAC9C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,OAAO,CAA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ACV,KAAK;gBACL,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC;gBAC7D,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC;gBAClE,WAAW,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,CAC/C,UAAU,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;oBAC1D,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;oBAC9B,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC,CAAC;aACH,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC;AAED,2GAA2G;AAC3G,MAAM,OAAO,cAAc;IAA3B;QACkB,UAAK,GAAG,IAAI,GAAG,EAA6B,CAAC;IAW/D,CAAC;IATA,KAAK,CAAC,UAA0B,EAAE,IAAe;QAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7C,KAAK,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED,QAAQ,CAAC,MAAmB;QAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,KAAK;YAAE,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrF,CAAC;CACD","sourcesContent":["import type { SupervisedCommandOwner } from \"../tools/bash-pty-native.js\";\nimport type { AgentTaskHost } from \"./agent-adapter.js\";\nimport type { TaskId, YieldReason } from \"./contracts.js\";\nimport type { TaskSupervisor, WaitLease } from \"./supervisor.js\";\n\nexport type TaskCompletionMessage = {\n\tcustomType: string;\n\tcontent: string;\n\tdetails: object;\n\tdisplay: true;\n};\n\n/** Live delivery into the child that launched a shell task, while that child still runs. */\nexport interface ChildTaskCompletionRoute {\n\tisOpen(): boolean;\n\tdeliver(message: TaskCompletionMessage): Promise<void>;\n}\n\n/**\n * Parent-issued capability that lets an in-process subagent child run shell tasks\n * in the parent's task owner, so they appear in the parent's `/tasks` and outlive\n * the child. It never authorizes agent launches.\n */\nexport interface ChildCommandTaskOwner {\n\tbind(childId: string, route: ChildTaskCompletionRoute, waits: ChildTaskWaits): SupervisedCommandOwner;\n}\n\nclass ChildCommandTaskRoutes {\n\tprivate readonly launchedBy = new Map<TaskId, string>();\n\tprivate readonly routes = new Map<string, ChildTaskCompletionRoute>();\n\n\tbind(childId: string, route: ChildTaskCompletionRoute): void {\n\t\tthis.routes.set(childId, route);\n\t}\n\n\trecordLaunch(taskId: TaskId, childId: string): void {\n\t\tthis.launchedBy.set(taskId, childId);\n\t}\n\n\tlaunchedByChild(taskId: TaskId, childId: string): boolean {\n\t\treturn this.launchedBy.get(taskId) === childId;\n\t}\n\n\topenRoute(taskId: TaskId): ChildTaskCompletionRoute | undefined {\n\t\tconst childId = this.launchedBy.get(taskId);\n\t\tconst route = childId === undefined ? undefined : this.routes.get(childId);\n\t\treturn route?.isOpen() ? route : undefined;\n\t}\n}\n\nconst routesByHost = new WeakMap<AgentTaskHost, ChildCommandTaskRoutes>();\n\nfunction routesFor(host: AgentTaskHost): ChildCommandTaskRoutes {\n\tlet routes = routesByHost.get(host);\n\tif (!routes) {\n\t\troutes = new ChildCommandTaskRoutes();\n\t\troutesByHost.set(host, routes);\n\t}\n\treturn routes;\n}\n\n/** Completion route for a task a child launched in this owner, only while that child accepts messages. */\nexport function childTaskCompletionRoute(host: AgentTaskHost, taskId: TaskId): ChildTaskCompletionRoute | undefined {\n\treturn routesByHost.get(host)?.openRoute(taskId);\n}\n\n/** Resolve the parent's live owner per call so session replacement is followed like the parent's own shells. */\nexport function createChildCommandTaskOwner(resolveHost: () => AgentTaskHost): ChildCommandTaskOwner {\n\treturn {\n\t\tbind(childId, route, waits) {\n\t\t\tconst host = resolveHost();\n\t\t\tconst routes = routesFor(host);\n\t\t\troutes.bind(childId, route);\n\t\t\tconst { supervisor, owner } = host.ownerBinding;\n\t\t\treturn {\n\t\t\t\tsupervisor,\n\t\t\t\towner,\n\t\t\t\townsTask: (taskId) => routes.launchedByChild(taskId, childId),\n\t\t\t\tonCommandStarted: (taskId) => routes.recordLaunch(taskId, childId),\n\t\t\t\twaitForTask: (taskId, budgetMs, onRegistered) =>\n\t\t\t\t\tsupervisor.waitForTaskId(owner, taskId, budgetMs, (wait) => {\n\t\t\t\t\t\twaits.track(supervisor, wait);\n\t\t\t\t\t\tonRegistered?.(wait);\n\t\t\t\t\t}),\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** Child-side waits on parent-owned tasks; inbound child messages release observation, never execution. */\nexport class ChildTaskWaits {\n\tprivate readonly waits = new Map<WaitLease, TaskSupervisor>();\n\n\ttrack(supervisor: TaskSupervisor, wait: WaitLease): void {\n\t\tthis.waits.set(wait, supervisor);\n\t\tconst remove = () => this.waits.delete(wait);\n\t\tvoid supervisor.observeTaskWait(wait).then(remove, remove);\n\t}\n\n\tyieldAll(reason: YieldReason): void {\n\t\tfor (const [wait, supervisor] of this.waits) supervisor.yieldTaskWait(wait, reason);\n\t}\n}\n"]}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { type ShellConfig } from "../../utils/shell.ts";
|
|
2
2
|
import type { TaskId, WaitOutcome, WaitPolicy } from "../tasks/contracts.js";
|
|
3
|
-
import type { OwnerLease, TaskSupervisor, WaitLease } from "../tasks/supervisor.js";
|
|
3
|
+
import type { OwnerLease, TaskLease, TaskSupervisor, WaitLease } from "../tasks/supervisor.js";
|
|
4
4
|
import { type OutputAccumulatorOptions } from "./output-accumulator.ts";
|
|
5
5
|
export declare function resetNativePtyBindingCache(): void;
|
|
6
6
|
export interface SupervisedCommandOwner {
|
|
7
7
|
supervisor: TaskSupervisor;
|
|
8
8
|
owner: OwnerLease;
|
|
9
9
|
waitForTask?: (taskId: TaskId, budgetMs?: number, onRegistered?: (wait: WaitLease) => void) => ReturnType<TaskSupervisor["waitForTaskId"]>;
|
|
10
|
+
/** Narrow a shared owner to the tasks this binding launched. */
|
|
11
|
+
ownsTask?: (taskId: TaskId) => boolean;
|
|
12
|
+
onCommandStarted?: (taskId: TaskId) => void;
|
|
10
13
|
}
|
|
14
|
+
export declare function lookupOwnedTask(context: SupervisedCommandOwner, id: string): TaskLease;
|
|
11
15
|
export interface SupervisedCommandResult {
|
|
12
16
|
exitCode: number | null;
|
|
13
17
|
observation?: WaitOutcome;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAe,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAe,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AA0C3F,wBAAgB,0BAA0B,IAAI,IAAI,C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AAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACnC;AAED,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,uBAAuB,CAAC,CA6ClC"}
|
|
@@ -29,6 +29,15 @@ function loadNativePtyBinding() {
|
|
|
29
29
|
return cachedLoadResult;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
export function lookupOwnedTask(context, id) {
|
|
33
|
+
const taskId = id;
|
|
34
|
+
const task = context.supervisor.lookupTask(context.owner, taskId);
|
|
35
|
+
if (!task.ok)
|
|
36
|
+
throw new Error(`${task.error.code}: ${task.error.message}`);
|
|
37
|
+
if (context.ownsTask && !context.ownsTask(taskId))
|
|
38
|
+
throw new Error("UnknownTask: task was not launched here");
|
|
39
|
+
return task.value;
|
|
40
|
+
}
|
|
32
41
|
// Bind progress to the task capability, not a tool instance or replaceable session binding.
|
|
33
42
|
const yieldedOutputOffsets = new WeakMap();
|
|
34
43
|
export async function waitForSupervisedCommand(context, id, budgetMs, signal, outputOptions) {
|
|
@@ -36,9 +45,7 @@ export async function waitForSupervisedCommand(context, id, budgetMs, signal, ou
|
|
|
36
45
|
throw new Error("Shell task wait requires a supported task owner");
|
|
37
46
|
if (signal?.aborted)
|
|
38
47
|
throw new Error("aborted");
|
|
39
|
-
const task =
|
|
40
|
-
if (!task.ok)
|
|
41
|
-
throw new Error(`${task.error.code}: ${task.error.message}`);
|
|
48
|
+
const task = lookupOwnedTask(context, id);
|
|
42
49
|
let lease;
|
|
43
50
|
const abort = () => {
|
|
44
51
|
if (lease)
|
|
@@ -59,10 +66,10 @@ export async function waitForSupervisedCommand(context, id, budgetMs, signal, ou
|
|
|
59
66
|
throw new Error("aborted");
|
|
60
67
|
if (!observed.ok)
|
|
61
68
|
throw new Error(`${observed.error.code}: ${observed.error.message}`);
|
|
62
|
-
let offset = observed.value.kind === "yielded" ? (yieldedOutputOffsets.get(task
|
|
69
|
+
let offset = observed.value.kind === "yielded" ? (yieldedOutputOffsets.get(task) ?? "0") : "0";
|
|
63
70
|
let nextOffset;
|
|
64
71
|
do {
|
|
65
|
-
const page = await context.supervisor.readTaskOutput(task
|
|
72
|
+
const page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });
|
|
66
73
|
if (!page.ok)
|
|
67
74
|
throw new Error(`${page.error.code}: ${page.error.message}`);
|
|
68
75
|
const segments = [
|
|
@@ -85,8 +92,8 @@ export async function waitForSupervisedCommand(context, id, budgetMs, signal, ou
|
|
|
85
92
|
output.finish();
|
|
86
93
|
const snapshot = output.snapshot({ persistIfTruncated: true });
|
|
87
94
|
await output.closeTempFile();
|
|
88
|
-
if (observed.value.kind === "yielded" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task
|
|
89
|
-
yieldedOutputOffsets.set(task
|
|
95
|
+
if (observed.value.kind === "yielded" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task) ?? "0"))
|
|
96
|
+
yieldedOutputOffsets.set(task, nextOffset);
|
|
90
97
|
const terminal = observed.value.kind === "settled" ? observed.value.result : undefined;
|
|
91
98
|
return {
|
|
92
99
|
content: [
|
|
@@ -164,6 +171,7 @@ export async function executeSupervisedCommand(command, cwd, options, pty) {
|
|
|
164
171
|
if (!started.ok)
|
|
165
172
|
throw new Error(`${started.error.code}: ${started.error.message}`);
|
|
166
173
|
const task = started.value;
|
|
174
|
+
context.onCommandStarted?.(context.supervisor.taskReference(task).taskId);
|
|
167
175
|
const abort = () => {
|
|
168
176
|
void context.supervisor.cancelTask(task, "user");
|
|
169
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-pty-native.js","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAE,iBAAiB,EAAiC,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAqCjD,IAAI,gBAA8C,CAAC;AAEnD,MAAM,UAAU,0BAA0B;IACzC,gBAAgB,GAAG,SAAS,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB;IAC5B,IAAI,gBAAgB;QAAE,OAAO,gBAAgB,CAAC;IAC9C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,cAAc,CAA8B,CAAC;QACjG,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAC7C,gBAAgB,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,kBAAkB,cAAc,yBAAyB,CAAC,EAAE,CAAC;YAC9G,OAAO,gBAAgB,CAAC;QACzB,CAAC;QACD,gBAAgB,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAA0B,EAAE,CAAC;QACrE,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAAC,OAAO,KAA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AAE,WAAW,CAAC,gBAAgB,KAAK,OAAO;SAChE,EACD,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjB,IAAI,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC,CACD,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5E,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;IAClE,CAAC;YAAS,CAAC;QACV,IAAI,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;AACF,CAAC","sourcesContent":["import { setTimeout as poll } from \"node:timers/promises\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createModuleRequire } from \"../../utils/module-require.ts\";\nimport { getShellConfig, getShellEnv, type ShellConfig } from \"../../utils/shell.ts\";\nimport type { OperationId, TaskId, WaitOutcome, WaitPolicy } from \"../tasks/contracts.js\";\nimport type { OwnerLease, TaskLease, TaskSupervisor, WaitLease } from \"../tasks/supervisor.js\";\nimport { OutputAccumulator, type OutputAccumulatorOptions } from \"./output-accumulator.ts\";\nimport { completeUtf8PrefixLength } from \"./persisted-output-file.ts\";\n\nconst NATIVE_PACKAGE = \"@bastani/atomic-natives\";\n\ninterface NativePtyRunResult {\n\texitCode?: number;\n\texit_code?: number;\n\tcancelled?: boolean;\n\ttimedOut?: boolean;\n\ttimed_out?: boolean;\n}\n\ninterface NativePtySession {\n\tstart(\n\t\toptions: {\n\t\t\tcommand: string;\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeoutMs?: number;\n\t\t\tcols?: number;\n\t\t\trows?: number;\n\t\t\tshell?: string;\n\t\t\tshellArgs?: string[];\n\t\t\tcommandTransport?: \"argv\" | \"stdin\";\n\t\t\tcloseStdinAfterCommand?: boolean;\n\t\t},\n\t\tonChunk?: (error: Error | null, chunk: string) => void,\n\t): Promise<NativePtyRunResult>;\n\twrite(data: string): void;\n\tresize(cols: number, rows: number): void;\n\tkill(): void;\n}\n\ninterface NativePtyBinding {\n\tPtySession: new () => NativePtySession;\n}\n\ntype NativeLoadResult = { ok: true; binding: NativePtyBinding } | { ok: false; error: Error };\n\nlet cachedLoadResult: NativeLoadResult | undefined;\n\nexport function resetNativePtyBindingCache(): void {\n\tcachedLoadResult = undefined;\n}\n\nfunction loadNativePtyBinding(): NativeLoadResult {\n\tif (cachedLoadResult) return cachedLoadResult;\n\ttry {\n\t\tconst loaded = createModuleRequire(import.meta.url)(NATIVE_PACKAGE) as Partial<NativePtyBinding>;\n\t\tif (typeof loaded.PtySession !== \"function\") {\n\t\t\tcachedLoadResult = { ok: false, error: new Error(`Native package ${NATIVE_PACKAGE} is missing PtySession.`) };\n\t\t\treturn cachedLoadResult;\n\t\t}\n\t\tcachedLoadResult = { ok: true, binding: loaded as NativePtyBinding };\n\t\treturn cachedLoadResult;\n\t} catch (error) {\n\t\tcachedLoadResult = {\n\t\t\tok: false,\n\t\t\terror: new Error(\n\t\t\t\t`Native PTY package ${NATIVE_PACKAGE} is unavailable for ${process.platform}-${process.arch}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t),\n\t\t};\n\t\treturn cachedLoadResult;\n\t}\n}\n\nexport interface SupervisedCommandOwner {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n\twaitForTask?: (\n\t\ttaskId: TaskId,\n\t\tbudgetMs?: number,\n\t\tonRegistered?: (wait: WaitLease) => void,\n\t) => ReturnType<TaskSupervisor[\"waitForTaskId\"]>;\n}\nexport interface SupervisedCommandResult {\n\texitCode: number | null;\n\tobservation?: WaitOutcome;\n}\n\n// Bind progress to the task capability, not a tool instance or replaceable session binding.\nconst yieldedOutputOffsets = new WeakMap<TaskLease, string>();\n\nexport async function waitForSupervisedCommand(\n\tcontext: SupervisedCommandOwner | undefined,\n\tid: string,\n\tbudgetMs?: number,\n\tsignal?: AbortSignal,\n\toutputOptions?: OutputAccumulatorOptions,\n) {\n\tif (!context) throw new Error(\"Shell task wait requires a supported task owner\");\n\tif (signal?.aborted) throw new Error(\"aborted\");\n\tconst task = context.supervisor.lookupTask(context.owner, id as TaskId);\n\tif (!task.ok) throw new Error(`${task.error.code}: ${task.error.message}`);\n\tlet lease: WaitLease | undefined;\n\tconst abort = () => {\n\t\tif (lease) context.supervisor.disposeTaskWait(lease);\n\t};\n\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\tconst output = new OutputAccumulator(outputOptions);\n\ttry {\n\t\tconst registered = (wait: WaitLease) => {\n\t\t\tlease = wait;\n\t\t\tif (signal?.aborted) abort();\n\t\t};\n\t\tconst observed = await (context.waitForTask\n\t\t\t? context.waitForTask(id as TaskId, budgetMs, registered)\n\t\t\t: context.supervisor.waitForTaskId(context.owner, id as TaskId, budgetMs, registered));\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\tif (!observed.ok) throw new Error(`${observed.error.code}: ${observed.error.message}`);\n\t\tlet offset: string | undefined =\n\t\t\tobserved.value.kind === \"yielded\" ? (yieldedOutputOffsets.get(task.value) ?? \"0\") : \"0\";\n\t\tlet nextOffset: string;\n\t\tdo {\n\t\t\tconst page = await context.supervisor.readTaskOutput(task.value, { start: offset, maximumBytes: 8192 });\n\t\t\tif (!page.ok) throw new Error(`${page.error.code}: ${page.error.message}`);\n\t\t\tconst segments = [\n\t\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\t\toffsets,\n\t\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t\t})),\n\t\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\t\tconst bytes = Buffer.concat(segments.map((segment) => segment.bytes));\n\t\t\tconst completeBytes = observed.value.kind === \"yielded\" ? completeUtf8PrefixLength(bytes) : bytes.length;\n\t\t\toutput.append(bytes.subarray(0, completeBytes));\n\t\t\t// Re-read an incomplete UTF-8 suffix next time, including at the current live tail.\n\t\t\tnextOffset = page.value.nextOffset ?? segments.at(-1)?.offsets.end ?? offset;\n\t\t\tnextOffset = (BigInt(nextOffset) - BigInt(bytes.length - completeBytes)).toString();\n\t\t\tif (page.value.nextOffset !== undefined && observed.value.kind === \"yielded\")\n\t\t\t\toutput.append(Buffer.from(\"\\n[Additional output not shown; wait again to retrieve retained output.]\\n\"));\n\t\t\toffset = observed.value.kind === \"yielded\" ? undefined : page.value.nextOffset;\n\t\t} while (offset !== undefined);\n\t\toutput.finish();\n\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\tawait output.closeTempFile();\n\t\tif (observed.value.kind === \"yielded\" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task.value) ?? \"0\"))\n\t\t\tyieldedOutputOffsets.set(task.value, nextOffset);\n\t\tconst terminal = observed.value.kind === \"settled\" ? observed.value.result : undefined;\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\ttext: `${snapshot.content || \"(no output)\"}${snapshot.truncation.truncated ? \"\\n[Output truncated.]\" : \"\"}\\n\\n${JSON.stringify(observed.value)}${snapshot.fullOutputPath ? `\\nFull output: ${snapshot.fullOutputPath}` : \"\"}`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tdetails: {\n\t\t\t\tobservation: observed.value,\n\t\t\t\t...(terminal && \"exitCode\" in terminal ? { exitCode: terminal.exitCode } : {}),\n\t\t\t\t...(snapshot.truncation.truncated\n\t\t\t\t\t? { truncation: snapshot.truncation, fullOutputPath: snapshot.fullOutputPath }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\tawait output.closeTempFile();\n\t}\n}\n\nexport function validateBashWait(wait: WaitPolicy | undefined, ownerSupported = true): void {\n\tif (wait === undefined) return;\n\tif (\n\t\t!wait ||\n\t\ttypeof wait !== \"object\" ||\n\t\t(wait.kind !== \"background\" && wait.kind !== \"foreground\") ||\n\t\tObject.keys(wait).some((key) => key !== \"kind\" && (wait.kind !== \"foreground\" || key !== \"budgetMs\")) ||\n\t\t(wait.kind === \"foreground\" &&\n\t\t\twait.budgetMs !== undefined &&\n\t\t\t(typeof wait.budgetMs !== \"number\" || !Number.isFinite(wait.budgetMs) || wait.budgetMs < 0))\n\t)\n\t\tthrow new Error(\"Invalid bash wait: expected background or foreground with a finite non-negative budgetMs\");\n\tif (wait.kind === \"background\" && !ownerSupported)\n\t\tthrow new Error(\"Background bash observation requires a supported task owner\");\n}\n\nexport async function executeSupervisedCommand(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n\tpty: boolean,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst context = options.taskOwner;\n\tif (!context) throw new Error(\"Supervised command requires its task owner\");\n\tconst shell = options.shellConfig ?? getShellConfig(options.shellPath);\n\tif (process.platform === \"win32\" && shell.commandTransport === \"stdin\")\n\t\tthrow new Error(\"ContainmentUnavailable: run Atomic inside WSL to supervise Linux guest commands\");\n\tconst quote = (text: string) => `'${text.replaceAll(\"'\", \"'\\\\''\")}'`;\n\tconst invocation = [shell.shell, ...shell.args].map(quote).join(\" \");\n\tconst environment = createChildProcessEnvironment(\n\t\tpty ? { TERM: \"xterm-256color\" } : undefined,\n\t\toptions.env ?? getShellEnv(),\n\t);\n\t// Windows names are case-insensitive. Resolve ordered JS overrides before\n\t// crossing into the unordered native map, including explicit removals.\n\tconst launchEnvironment = new Map<string, [string, string | undefined]>();\n\tfor (const [key, value] of Object.entries(environment))\n\t\tlaunchEnvironment.set(process.platform === \"win32\" ? key.toUpperCase() : key, [key, value]);\n\t// The native command door merges env overrides. Clear omitted inherited shell\n\t// variables before invoking the configured shell, without embedding env values\n\t// (which may be secrets) into the retained command text.\n\tconst omitted = Object.keys(process.env).filter(\n\t\t(key) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && environment[key] === undefined,\n\t);\n\tconst clearInherited = omitted.length ? `unset ${omitted.map(quote).join(\" \")}; ` : \"\";\n\tconst launch =\n\t\tshell.commandTransport === \"stdin\"\n\t\t\t? `printf %s ${quote(command)} | ${invocation}`\n\t\t\t: `exec ${invocation} ${quote(command)}`;\n\tconst started = await context.supervisor.startCommandTask(\n\t\tcontext.owner,\n\t\t{\n\t\t\tkind: \"command\",\n\t\t\tcommand: process.platform === \"win32\" ? command : clearInherited + launch,\n\t\t\tdescription: options.commandDescription ?? command,\n\t\t\tcwd,\n\t\t\tenv: Object.fromEntries(\n\t\t\t\t[...launchEnvironment.values()].filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t),\n\t\t\t...(process.platform === \"win32\"\n\t\t\t\t? { shell: { program: shell.shell, args: shell.args }, inheritEnv: false }\n\t\t\t\t: {}),\n\t\t\tterminal: pty ? { kind: \"pty\", columns: options.cols ?? 120, rows: options.rows ?? 40 } : { kind: \"pipe\" },\n\t\t\t...(options.timeout === undefined ? {} : { executionTimeoutMs: options.timeout * 1000 }),\n\t\t},\n\t\tcrypto.randomUUID() as OperationId,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tconst abort = () => {\n\t\tvoid context.supervisor.cancelTask(task, \"user\");\n\t};\n\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\tif (options.signal?.aborted) abort();\n\tlet done = false;\n\tlet offset = \"0\";\n\tconst observation = context.supervisor.initialObservation(task, options.wait).finally(() => {\n\t\tdone = true;\n\t});\n\tconst drain = async () => {\n\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\tif (!page.ok) throw new Error(page.error.message);\n\t\tconst segments = [\n\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\toffsets,\n\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t})),\n\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\tfor (const segment of segments) {\n\t\t\toptions.onData(segment.bytes);\n\t\t\toffset = segment.offsets.end;\n\t\t}\n\t\tif (page.value.nextOffset !== undefined) offset = page.value.nextOffset;\n\t\treturn page.value.nextOffset !== undefined;\n\t};\n\ttry {\n\t\twhile (!done) {\n\t\t\tif (!(await drain())) await poll(10);\n\t\t}\n\t\tconst result = await observation;\n\t\tif (!result.ok) throw new Error(result.error.message);\n\t\tif (result.value.kind === \"yielded\") {\n\t\t\tawait drain();\n\t\t\treturn { exitCode: null, observation: result.value };\n\t\t}\n\t\twhile (await drain()) {\n\t\t\t/* Terminal output is finite; no live producer extends this drain. */\n\t\t}\n\t\tconst terminal = result.value.result;\n\t\tif (terminal.kind === \"cancelled\")\n\t\t\tthrow new Error(terminal.cause === \"execution-timeout\" ? `timeout:${options.timeout}` : \"aborted\");\n\t\tif (terminal.kind === \"failed\") throw new Error(`${terminal.code}: ${terminal.message}`);\n\t\treturn { exitCode: terminal.exitCode ?? null };\n\t} finally {\n\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t}\n}\n\nexport interface NativePtyExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\twait?: WaitPolicy;\n\tenv?: NodeJS.ProcessEnv;\n\tshellPath?: string;\n\tshellConfig?: ShellConfig;\n\tcommandDescription?: string;\n\tcols?: number;\n\trows?: number;\n\ttaskOwner?: SupervisedCommandOwner;\n}\n\nexport async function executeNativePty(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.taskOwner) return executeSupervisedCommand(command, cwd, options, true);\n\tconst loaded = loadNativePtyBinding();\n\tif (!loaded.ok) throw loaded.error;\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst shellConfig = options.shellConfig ?? getShellConfig(options.shellPath);\n\tconst session = new loaded.binding.PtySession();\n\tconst onAbort = () => {\n\t\ttry {\n\t\t\tsession.kill();\n\t\t} catch {}\n\t};\n\tif (options.signal) options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\tconst result = await session.start(\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\tcwd,\n\t\t\t\tenv: Object.fromEntries(\n\t\t\t\t\tObject.entries(\n\t\t\t\t\t\tcreateChildProcessEnvironment(\n\t\t\t\t\t\t\t{ TERM: \"xterm-256color\" },\n\t\t\t\t\t\t\t{ ...getShellEnv(), ...(options.env ?? {}) },\n\t\t\t\t\t\t),\n\t\t\t\t\t).filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t\t),\n\t\t\t\ttimeoutMs: options.timeout !== undefined ? Math.max(1, Math.floor(options.timeout * 1000)) : undefined,\n\t\t\t\tcols: options.cols ?? 120,\n\t\t\t\trows: options.rows ?? 40,\n\t\t\t\tshell: shellConfig.shell,\n\t\t\t\tshellArgs: shellConfig.args,\n\t\t\t\tcommandTransport: shellConfig.commandTransport,\n\t\t\t\tcloseStdinAfterCommand: shellConfig.commandTransport === \"stdin\",\n\t\t\t},\n\t\t\t(_error, chunk) => {\n\t\t\t\tif (chunk) options.onData(Buffer.from(chunk));\n\t\t\t},\n\t\t);\n\t\tif (options.signal?.aborted || result.cancelled) throw new Error(\"aborted\");\n\t\tif (result.timedOut ?? result.timed_out) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode: result.exitCode ?? result.exit_code ?? null };\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bash-pty-native.js","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAE,iBAAiB,EAAiC,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAqCjD,IAAI,gBAA8C,CAAC;AAEnD,MAAM,UAAU,0BAA0B;IACzC,gBAAgB,GAAG,SAAS,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB;IAC5B,IAAI,gBAAgB;QAAE,OAAO,gBAAgB,CAAC;IAC9C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,cAAc,CAA8B,CAAC;QACjG,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAC7C,gBAAgB,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,kBAAkB,cAAc,yBAAyB,CAAC,EAAE,CAAC;YAC9G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AAC,CAAC;IAC1E,CAAC;AACF,CAAC","sourcesContent":["import { setTimeout as poll } from \"node:timers/promises\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createModuleRequire } from \"../../utils/module-require.ts\";\nimport { getShellConfig, getShellEnv, type ShellConfig } from \"../../utils/shell.ts\";\nimport type { OperationId, TaskId, WaitOutcome, WaitPolicy } from \"../tasks/contracts.js\";\nimport type { OwnerLease, TaskLease, TaskSupervisor, WaitLease } from \"../tasks/supervisor.js\";\nimport { OutputAccumulator, type OutputAccumulatorOptions } from \"./output-accumulator.ts\";\nimport { completeUtf8PrefixLength } from \"./persisted-output-file.ts\";\n\nconst NATIVE_PACKAGE = \"@bastani/atomic-natives\";\n\ninterface NativePtyRunResult {\n\texitCode?: number;\n\texit_code?: number;\n\tcancelled?: boolean;\n\ttimedOut?: boolean;\n\ttimed_out?: boolean;\n}\n\ninterface NativePtySession {\n\tstart(\n\t\toptions: {\n\t\t\tcommand: string;\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeoutMs?: number;\n\t\t\tcols?: number;\n\t\t\trows?: number;\n\t\t\tshell?: string;\n\t\t\tshellArgs?: string[];\n\t\t\tcommandTransport?: \"argv\" | \"stdin\";\n\t\t\tcloseStdinAfterCommand?: boolean;\n\t\t},\n\t\tonChunk?: (error: Error | null, chunk: string) => void,\n\t): Promise<NativePtyRunResult>;\n\twrite(data: string): void;\n\tresize(cols: number, rows: number): void;\n\tkill(): void;\n}\n\ninterface NativePtyBinding {\n\tPtySession: new () => NativePtySession;\n}\n\ntype NativeLoadResult = { ok: true; binding: NativePtyBinding } | { ok: false; error: Error };\n\nlet cachedLoadResult: NativeLoadResult | undefined;\n\nexport function resetNativePtyBindingCache(): void {\n\tcachedLoadResult = undefined;\n}\n\nfunction loadNativePtyBinding(): NativeLoadResult {\n\tif (cachedLoadResult) return cachedLoadResult;\n\ttry {\n\t\tconst loaded = createModuleRequire(import.meta.url)(NATIVE_PACKAGE) as Partial<NativePtyBinding>;\n\t\tif (typeof loaded.PtySession !== \"function\") {\n\t\t\tcachedLoadResult = { ok: false, error: new Error(`Native package ${NATIVE_PACKAGE} is missing PtySession.`) };\n\t\t\treturn cachedLoadResult;\n\t\t}\n\t\tcachedLoadResult = { ok: true, binding: loaded as NativePtyBinding };\n\t\treturn cachedLoadResult;\n\t} catch (error) {\n\t\tcachedLoadResult = {\n\t\t\tok: false,\n\t\t\terror: new Error(\n\t\t\t\t`Native PTY package ${NATIVE_PACKAGE} is unavailable for ${process.platform}-${process.arch}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t),\n\t\t};\n\t\treturn cachedLoadResult;\n\t}\n}\n\nexport interface SupervisedCommandOwner {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n\twaitForTask?: (\n\t\ttaskId: TaskId,\n\t\tbudgetMs?: number,\n\t\tonRegistered?: (wait: WaitLease) => void,\n\t) => ReturnType<TaskSupervisor[\"waitForTaskId\"]>;\n\t/** Narrow a shared owner to the tasks this binding launched. */\n\townsTask?: (taskId: TaskId) => boolean;\n\tonCommandStarted?: (taskId: TaskId) => void;\n}\n\nexport function lookupOwnedTask(context: SupervisedCommandOwner, id: string): TaskLease {\n\tconst taskId = id as TaskId;\n\tconst task = context.supervisor.lookupTask(context.owner, taskId);\n\tif (!task.ok) throw new Error(`${task.error.code}: ${task.error.message}`);\n\tif (context.ownsTask && !context.ownsTask(taskId)) throw new Error(\"UnknownTask: task was not launched here\");\n\treturn task.value;\n}\nexport interface SupervisedCommandResult {\n\texitCode: number | null;\n\tobservation?: WaitOutcome;\n}\n\n// Bind progress to the task capability, not a tool instance or replaceable session binding.\nconst yieldedOutputOffsets = new WeakMap<TaskLease, string>();\n\nexport async function waitForSupervisedCommand(\n\tcontext: SupervisedCommandOwner | undefined,\n\tid: string,\n\tbudgetMs?: number,\n\tsignal?: AbortSignal,\n\toutputOptions?: OutputAccumulatorOptions,\n) {\n\tif (!context) throw new Error(\"Shell task wait requires a supported task owner\");\n\tif (signal?.aborted) throw new Error(\"aborted\");\n\tconst task = lookupOwnedTask(context, id);\n\tlet lease: WaitLease | undefined;\n\tconst abort = () => {\n\t\tif (lease) context.supervisor.disposeTaskWait(lease);\n\t};\n\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\tconst output = new OutputAccumulator(outputOptions);\n\ttry {\n\t\tconst registered = (wait: WaitLease) => {\n\t\t\tlease = wait;\n\t\t\tif (signal?.aborted) abort();\n\t\t};\n\t\tconst observed = await (context.waitForTask\n\t\t\t? context.waitForTask(id as TaskId, budgetMs, registered)\n\t\t\t: context.supervisor.waitForTaskId(context.owner, id as TaskId, budgetMs, registered));\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\tif (!observed.ok) throw new Error(`${observed.error.code}: ${observed.error.message}`);\n\t\tlet offset: string | undefined =\n\t\t\tobserved.value.kind === \"yielded\" ? (yieldedOutputOffsets.get(task) ?? \"0\") : \"0\";\n\t\tlet nextOffset: string;\n\t\tdo {\n\t\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\t\tif (!page.ok) throw new Error(`${page.error.code}: ${page.error.message}`);\n\t\t\tconst segments = [\n\t\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\t\toffsets,\n\t\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t\t})),\n\t\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\t\tconst bytes = Buffer.concat(segments.map((segment) => segment.bytes));\n\t\t\tconst completeBytes = observed.value.kind === \"yielded\" ? completeUtf8PrefixLength(bytes) : bytes.length;\n\t\t\toutput.append(bytes.subarray(0, completeBytes));\n\t\t\t// Re-read an incomplete UTF-8 suffix next time, including at the current live tail.\n\t\t\tnextOffset = page.value.nextOffset ?? segments.at(-1)?.offsets.end ?? offset;\n\t\t\tnextOffset = (BigInt(nextOffset) - BigInt(bytes.length - completeBytes)).toString();\n\t\t\tif (page.value.nextOffset !== undefined && observed.value.kind === \"yielded\")\n\t\t\t\toutput.append(Buffer.from(\"\\n[Additional output not shown; wait again to retrieve retained output.]\\n\"));\n\t\t\toffset = observed.value.kind === \"yielded\" ? undefined : page.value.nextOffset;\n\t\t} while (offset !== undefined);\n\t\toutput.finish();\n\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\tawait output.closeTempFile();\n\t\tif (observed.value.kind === \"yielded\" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task) ?? \"0\"))\n\t\t\tyieldedOutputOffsets.set(task, nextOffset);\n\t\tconst terminal = observed.value.kind === \"settled\" ? observed.value.result : undefined;\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\ttext: `${snapshot.content || \"(no output)\"}${snapshot.truncation.truncated ? \"\\n[Output truncated.]\" : \"\"}\\n\\n${JSON.stringify(observed.value)}${snapshot.fullOutputPath ? `\\nFull output: ${snapshot.fullOutputPath}` : \"\"}`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tdetails: {\n\t\t\t\tobservation: observed.value,\n\t\t\t\t...(terminal && \"exitCode\" in terminal ? { exitCode: terminal.exitCode } : {}),\n\t\t\t\t...(snapshot.truncation.truncated\n\t\t\t\t\t? { truncation: snapshot.truncation, fullOutputPath: snapshot.fullOutputPath }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\tawait output.closeTempFile();\n\t}\n}\n\nexport function validateBashWait(wait: WaitPolicy | undefined, ownerSupported = true): void {\n\tif (wait === undefined) return;\n\tif (\n\t\t!wait ||\n\t\ttypeof wait !== \"object\" ||\n\t\t(wait.kind !== \"background\" && wait.kind !== \"foreground\") ||\n\t\tObject.keys(wait).some((key) => key !== \"kind\" && (wait.kind !== \"foreground\" || key !== \"budgetMs\")) ||\n\t\t(wait.kind === \"foreground\" &&\n\t\t\twait.budgetMs !== undefined &&\n\t\t\t(typeof wait.budgetMs !== \"number\" || !Number.isFinite(wait.budgetMs) || wait.budgetMs < 0))\n\t)\n\t\tthrow new Error(\"Invalid bash wait: expected background or foreground with a finite non-negative budgetMs\");\n\tif (wait.kind === \"background\" && !ownerSupported)\n\t\tthrow new Error(\"Background bash observation requires a supported task owner\");\n}\n\nexport async function executeSupervisedCommand(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n\tpty: boolean,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst context = options.taskOwner;\n\tif (!context) throw new Error(\"Supervised command requires its task owner\");\n\tconst shell = options.shellConfig ?? getShellConfig(options.shellPath);\n\tif (process.platform === \"win32\" && shell.commandTransport === \"stdin\")\n\t\tthrow new Error(\"ContainmentUnavailable: run Atomic inside WSL to supervise Linux guest commands\");\n\tconst quote = (text: string) => `'${text.replaceAll(\"'\", \"'\\\\''\")}'`;\n\tconst invocation = [shell.shell, ...shell.args].map(quote).join(\" \");\n\tconst environment = createChildProcessEnvironment(\n\t\tpty ? { TERM: \"xterm-256color\" } : undefined,\n\t\toptions.env ?? getShellEnv(),\n\t);\n\t// Windows names are case-insensitive. Resolve ordered JS overrides before\n\t// crossing into the unordered native map, including explicit removals.\n\tconst launchEnvironment = new Map<string, [string, string | undefined]>();\n\tfor (const [key, value] of Object.entries(environment))\n\t\tlaunchEnvironment.set(process.platform === \"win32\" ? key.toUpperCase() : key, [key, value]);\n\t// The native command door merges env overrides. Clear omitted inherited shell\n\t// variables before invoking the configured shell, without embedding env values\n\t// (which may be secrets) into the retained command text.\n\tconst omitted = Object.keys(process.env).filter(\n\t\t(key) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && environment[key] === undefined,\n\t);\n\tconst clearInherited = omitted.length ? `unset ${omitted.map(quote).join(\" \")}; ` : \"\";\n\tconst launch =\n\t\tshell.commandTransport === \"stdin\"\n\t\t\t? `printf %s ${quote(command)} | ${invocation}`\n\t\t\t: `exec ${invocation} ${quote(command)}`;\n\tconst started = await context.supervisor.startCommandTask(\n\t\tcontext.owner,\n\t\t{\n\t\t\tkind: \"command\",\n\t\t\tcommand: process.platform === \"win32\" ? command : clearInherited + launch,\n\t\t\tdescription: options.commandDescription ?? command,\n\t\t\tcwd,\n\t\t\tenv: Object.fromEntries(\n\t\t\t\t[...launchEnvironment.values()].filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t),\n\t\t\t...(process.platform === \"win32\"\n\t\t\t\t? { shell: { program: shell.shell, args: shell.args }, inheritEnv: false }\n\t\t\t\t: {}),\n\t\t\tterminal: pty ? { kind: \"pty\", columns: options.cols ?? 120, rows: options.rows ?? 40 } : { kind: \"pipe\" },\n\t\t\t...(options.timeout === undefined ? {} : { executionTimeoutMs: options.timeout * 1000 }),\n\t\t},\n\t\tcrypto.randomUUID() as OperationId,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tcontext.onCommandStarted?.(context.supervisor.taskReference(task).taskId);\n\tconst abort = () => {\n\t\tvoid context.supervisor.cancelTask(task, \"user\");\n\t};\n\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\tif (options.signal?.aborted) abort();\n\tlet done = false;\n\tlet offset = \"0\";\n\tconst observation = context.supervisor.initialObservation(task, options.wait).finally(() => {\n\t\tdone = true;\n\t});\n\tconst drain = async () => {\n\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\tif (!page.ok) throw new Error(page.error.message);\n\t\tconst segments = [\n\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\toffsets,\n\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t})),\n\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\tfor (const segment of segments) {\n\t\t\toptions.onData(segment.bytes);\n\t\t\toffset = segment.offsets.end;\n\t\t}\n\t\tif (page.value.nextOffset !== undefined) offset = page.value.nextOffset;\n\t\treturn page.value.nextOffset !== undefined;\n\t};\n\ttry {\n\t\twhile (!done) {\n\t\t\tif (!(await drain())) await poll(10);\n\t\t}\n\t\tconst result = await observation;\n\t\tif (!result.ok) throw new Error(result.error.message);\n\t\tif (result.value.kind === \"yielded\") {\n\t\t\tawait drain();\n\t\t\treturn { exitCode: null, observation: result.value };\n\t\t}\n\t\twhile (await drain()) {\n\t\t\t/* Terminal output is finite; no live producer extends this drain. */\n\t\t}\n\t\tconst terminal = result.value.result;\n\t\tif (terminal.kind === \"cancelled\")\n\t\t\tthrow new Error(terminal.cause === \"execution-timeout\" ? `timeout:${options.timeout}` : \"aborted\");\n\t\tif (terminal.kind === \"failed\") throw new Error(`${terminal.code}: ${terminal.message}`);\n\t\treturn { exitCode: terminal.exitCode ?? null };\n\t} finally {\n\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t}\n}\n\nexport interface NativePtyExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\twait?: WaitPolicy;\n\tenv?: NodeJS.ProcessEnv;\n\tshellPath?: string;\n\tshellConfig?: ShellConfig;\n\tcommandDescription?: string;\n\tcols?: number;\n\trows?: number;\n\ttaskOwner?: SupervisedCommandOwner;\n}\n\nexport async function executeNativePty(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.taskOwner) return executeSupervisedCommand(command, cwd, options, true);\n\tconst loaded = loadNativePtyBinding();\n\tif (!loaded.ok) throw loaded.error;\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst shellConfig = options.shellConfig ?? getShellConfig(options.shellPath);\n\tconst session = new loaded.binding.PtySession();\n\tconst onAbort = () => {\n\t\ttry {\n\t\t\tsession.kill();\n\t\t} catch {}\n\t};\n\tif (options.signal) options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\tconst result = await session.start(\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\tcwd,\n\t\t\t\tenv: Object.fromEntries(\n\t\t\t\t\tObject.entries(\n\t\t\t\t\t\tcreateChildProcessEnvironment(\n\t\t\t\t\t\t\t{ TERM: \"xterm-256color\" },\n\t\t\t\t\t\t\t{ ...getShellEnv(), ...(options.env ?? {}) },\n\t\t\t\t\t\t),\n\t\t\t\t\t).filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t\t),\n\t\t\t\ttimeoutMs: options.timeout !== undefined ? Math.max(1, Math.floor(options.timeout * 1000)) : undefined,\n\t\t\t\tcols: options.cols ?? 120,\n\t\t\t\trows: options.rows ?? 40,\n\t\t\t\tshell: shellConfig.shell,\n\t\t\t\tshellArgs: shellConfig.args,\n\t\t\t\tcommandTransport: shellConfig.commandTransport,\n\t\t\t\tcloseStdinAfterCommand: shellConfig.commandTransport === \"stdin\",\n\t\t\t},\n\t\t\t(_error, chunk) => {\n\t\t\t\tif (chunk) options.onData(Buffer.from(chunk));\n\t\t\t},\n\t\t);\n\t\tif (options.signal?.aborted || result.cancelled) throw new Error(\"aborted\");\n\t\tif (result.timedOut ?? result.timed_out) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode: result.exitCode ?? result.exit_code ?? null };\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
3
3
|
import type { CancelReceipt } from "../tasks/contracts.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type SupervisedCommandOwner } from "./bash-pty-native.js";
|
|
5
5
|
declare const killSchema: Type.TObject<{
|
|
6
6
|
id: Type.TString;
|
|
7
7
|
}>;
|
|
8
8
|
export interface KillToolOptions {
|
|
9
9
|
/** Resolve the live trusted owner at execution time, including after session switches. */
|
|
10
|
-
taskOwner?: () => SupervisedCommandOwner;
|
|
10
|
+
taskOwner?: () => SupervisedCommandOwner | undefined;
|
|
11
11
|
}
|
|
12
12
|
export declare function createKillToolDefinition(options?: KillToolOptions): ToolDefinition<typeof killSchema, CancelReceipt>;
|
|
13
13
|
export declare function createKillTool(options?: KillToolOptions): import("@earendil-works/pi-agent-core").AgentTool<Type.TObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kill.d.ts","sourceRoot":"","sources":["../../../src/core/tools/kill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"kill.d.ts","sourceRoot":"","sources":["../../../src/core/tools/kill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGpF,QAAA,MAAM,UAAU;;EAEd,CAAC;AAEH,MAAM,WAAW,eAAe;IAC/B,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACrD;AAED,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,OAAO,UAAU,EAAE,aAAa,CAAC,CAgCpH;AAED,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe;;mBAEvD"}
|
package/dist/core/tools/kill.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { experimentalToolSamplingProperty } from "../experimental.js";
|
|
3
|
+
import { lookupOwnedTask } from "./bash-pty-native.js";
|
|
3
4
|
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
4
5
|
const killSchema = Type.Object({
|
|
5
6
|
id: Type.String({ description: "Task ID returned by a background or auto-yielded bash or powershell call" }),
|
|
@@ -17,9 +18,7 @@ export function createKillToolDefinition(options) {
|
|
|
17
18
|
if (!binding)
|
|
18
19
|
throw new Error("kill requires a supported task owner");
|
|
19
20
|
const { supervisor, owner } = binding;
|
|
20
|
-
const task =
|
|
21
|
-
if (!task.ok)
|
|
22
|
-
throw new Error(`${task.error.code}: ${task.error.message}`);
|
|
21
|
+
const task = lookupOwnedTask(binding, id);
|
|
23
22
|
const watched = supervisor.watchOwnerTasks(owner);
|
|
24
23
|
if (!watched.ok)
|
|
25
24
|
throw new Error(`${watched.error.code}: ${watched.error.message}`);
|
|
@@ -27,7 +26,7 @@ export function createKillToolDefinition(options) {
|
|
|
27
26
|
const record = watched.value.snapshot.tasks.find((entry) => entry.ref.taskId === id);
|
|
28
27
|
if (record?.kind !== "command")
|
|
29
28
|
throw new Error("kill only supports shell tasks");
|
|
30
|
-
const result = await supervisor.cancelTask(task
|
|
29
|
+
const result = await supervisor.cancelTask(task, "user");
|
|
31
30
|
if (!result.ok)
|
|
32
31
|
throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
33
32
|
const receipt = result.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kill.js","sourceRoot":"","sources":["../../../src/core/tools/kill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,I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\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { CancelReceipt } from \"../tasks/contracts.js\";\nimport { lookupOwnedTask, type SupervisedCommandOwner } from \"./bash-pty-native.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst killSchema = Type.Object({\n\tid: Type.String({ description: \"Task ID returned by a background or auto-yielded bash or powershell call\" }),\n});\n\nexport interface KillToolOptions {\n\t/** Resolve the live trusted owner at execution time, including after session switches. */\n\ttaskOwner?: () => SupervisedCommandOwner | undefined;\n}\n\nexport function createKillToolDefinition(options?: KillToolOptions): ToolDefinition<typeof killSchema, CancelReceipt> {\n\treturn {\n\t\tname: \"kill\",\n\t\tlabel: \"Kill\",\n\t\tdescription:\n\t\t\t\"Stop an owned background bash or PowerShell task by its task ID, not a PID. Does not stop subagents or other owners' tasks. Returns the cancellation decision and current execution/cleanup state; a cancellation request alone does not confirm termination.\",\n\t\tparameters: killSchema,\n\t\t...experimentalToolSamplingProperty(),\n\t\tpromptSnippet: \"Stop an owned background shell task by task ID\",\n\t\texecute: async (_toolCallId, { id }) => {\n\t\t\tconst binding = options?.taskOwner?.();\n\t\t\tif (!binding) throw new Error(\"kill requires a supported task owner\");\n\t\t\tconst { supervisor, owner } = binding;\n\t\t\tconst task = lookupOwnedTask(binding, id);\n\t\t\tconst watched = supervisor.watchOwnerTasks(owner);\n\t\t\tif (!watched.ok) throw new Error(`${watched.error.code}: ${watched.error.message}`);\n\t\t\ttry {\n\t\t\t\tconst record = watched.value.snapshot.tasks.find((entry) => entry.ref.taskId === id);\n\t\t\t\tif (record?.kind !== \"command\") throw new Error(\"kill only supports shell tasks\");\n\t\t\t\tconst result = await supervisor.cancelTask(task, \"user\");\n\t\t\t\tif (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);\n\t\t\t\tconst receipt = result.value;\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: JSON.stringify(receipt) }],\n\t\t\t\t\tdetails: receipt,\n\t\t\t\t\t...(receipt.cleanup.kind === \"failed\" ? { isError: true } : {}),\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\twatched.value.dispose();\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function createKillTool(options?: KillToolOptions) {\n\treturn wrapToolDefinition(createKillToolDefinition(options));\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ModelImageResizeOptions } from "@bastani/pi-ai/compat";
|
|
1
2
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
3
|
import { type Static, Type } from "typebox";
|
|
3
4
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
@@ -47,7 +48,10 @@ export interface ReadOperations {
|
|
|
47
48
|
detectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;
|
|
48
49
|
}
|
|
49
50
|
export interface ReadToolOptions {
|
|
51
|
+
/** Whether to auto-resize images. Default: true */
|
|
50
52
|
autoResizeImages?: boolean;
|
|
53
|
+
/** Fallback resize profile when the execution context has no model metadata. */
|
|
54
|
+
resizeOptions?: ModelImageResizeOptions;
|
|
51
55
|
operations?: ReadOperations;
|
|
52
56
|
hashlineStore?: HashlineSnapshotStore;
|
|
53
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,uBAAuB,EAAe,MAAM,uBAAuB,CAAC;AAC5G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO5C,OAAO,KAAK,EAAoB,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAExG,OAAO,EAGN,KAAK,kBAAkB,EAEvB,MAAM,qBAAqB,CA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YAAY,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAChG,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,EAAE,GAAG,SAAS,CAAC,CAAC;IAC9E,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAMD,MAAM,WAAW,eAAe;IAC/B,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gFAAgF;IAChF,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACtC;AA4LD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAklBhE;AACD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
|
package/dist/core/tools/read.js
CHANGED
|
@@ -212,6 +212,7 @@ function appendReadSelectors(pathValue, selector) {
|
|
|
212
212
|
}
|
|
213
213
|
export function createReadToolDefinition(cwd, options) {
|
|
214
214
|
const autoResizeImages = options?.autoResizeImages ?? true;
|
|
215
|
+
const fallbackResizeOptions = options?.resizeOptions;
|
|
215
216
|
const ops = options?.operations ?? defaultReadOperations;
|
|
216
217
|
const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
|
|
217
218
|
return {
|
|
@@ -524,7 +525,10 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
524
525
|
if (mimeType) {
|
|
525
526
|
// Read image as binary.
|
|
526
527
|
const buffer = await ops.readFile(absolutePath);
|
|
527
|
-
const processed = await processImage(buffer, mimeType, {
|
|
528
|
+
const processed = await processImage(buffer, mimeType, {
|
|
529
|
+
autoResizeImages,
|
|
530
|
+
resizeOptions: ctx?.model?.inputLimits?.images?.resize ?? fallbackResizeOptions,
|
|
531
|
+
});
|
|
528
532
|
if (!processed.ok) {
|
|
529
533
|
let textNote = `Read image file [${mimeType}]\n${processed.message}`;
|
|
530
534
|
if (nonVisionImageNote)
|