@caupulican/pi-adaptative 0.81.42 → 0.81.43
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 +37 -0
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bedrock.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +52 -49
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +62 -57
- package/dist/bundled-resources/prompts/skillify.md +1 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +16 -19
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +12 -26
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +15 -121
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +52 -79
- package/dist/bundled-resources/runtimes/pi-shell-engine/escapes.py +70 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +110 -61
- package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +106 -23
- package/dist/bundled-resources/runtimes/pi-shell-engine/paths.py +10 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +12 -4
- package/dist/bundled-resources/runtimes/pi-shell-engine/shell_args.py +22 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +9 -2
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +129 -259
- package/dist/bundled-resources/skills/authorized-web-security-audit/SKILL.md +187 -0
- package/dist/bundled-resources/skills/authorized-web-security-audit/references/assessment-contract.md +92 -0
- package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +134 -0
- package/dist/bundled-resources/skills/evidence-gated-tdd/SKILL.md +93 -0
- package/dist/bundled-resources/skills/evidence-gated-tdd/references/evidence-model.md +27 -0
- package/dist/bundled-resources/skills/evidence-gated-tdd/references/security-scanners.md +24 -0
- package/dist/bundled-resources/skills/harness-self-adaptation/SKILL.md +4 -2
- package/dist/bundled-resources/skills/secure-agent-tool-surfaces/SKILL.md +217 -0
- package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/defensive-exploit-catalogue.md +175 -0
- package/dist/bundled-resources/skills/secure-agent-tool-surfaces/references/tool-boundary-checklist.md +87 -0
- package/dist/bundled-resources/skills/skill-architect/SKILL.md +2 -2
- package/dist/bundled-resources/skills/skill-creator/SKILL.md +188 -0
- package/dist/bundled-resources/skills/skill-creator/references/pi-skill-contract.md +73 -0
- package/dist/bundled-resources/skills/skill-creator/scripts/init-skill.mjs +142 -0
- package/dist/bundled-resources/skills/skill-creator/scripts/validate-skill.mjs +122 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +8 -8
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/initial-message.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/piped-stdin.d.ts +4 -0
- package/dist/cli/piped-stdin.d.ts.map +1 -0
- package/dist/cli/piped-stdin.js +13 -0
- package/dist/cli/piped-stdin.js.map +1 -0
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -14
- package/dist/config.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts.map +1 -1
- package/dist/core/agent-directory-layout.js.map +1 -1
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +5 -9
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js +1 -12
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +10 -25
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +24 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +210 -237
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +13 -39
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/evidence-finding-projection.d.ts +11 -0
- package/dist/core/autonomy/evidence-finding-projection.d.ts.map +1 -0
- package/dist/core/autonomy/evidence-finding-projection.js +37 -0
- package/dist/core/autonomy/evidence-finding-projection.js.map +1 -0
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
- package/dist/core/autonomy/lane-private-paths.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +2 -3
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/status.d.ts.map +1 -1
- package/dist/core/autonomy/status.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +2 -4
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +2 -15
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/background-tool-task-controller.d.ts +88 -0
- package/dist/core/background-tool-task-controller.d.ts.map +1 -0
- package/dist/core/background-tool-task-controller.js +470 -0
- package/dist/core/background-tool-task-controller.js.map +1 -0
- package/dist/core/bash-execution-controller.d.ts +1 -0
- package/dist/core/bash-execution-controller.d.ts.map +1 -1
- package/dist/core/bash-execution-controller.js +5 -4
- package/dist/core/bash-execution-controller.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts.map +1 -1
- package/dist/core/bedrock-sso-login.js.map +1 -1
- package/dist/core/billing-failover-controller.d.ts.map +1 -1
- package/dist/core/billing-failover-controller.js +3 -3
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/billing-failover.d.ts.map +1 -1
- package/dist/core/billing-failover.js.map +1 -1
- package/dist/core/capability-contract.d.ts.map +1 -1
- package/dist/core/catalog-manager.d.ts.map +1 -1
- package/dist/core/catalog-manager.js +0 -0
- package/dist/core/catalog-manager.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +2 -0
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +21 -8
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +8 -0
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +0 -2
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
- package/dist/core/context/artifact-retrieval.js.map +1 -1
- package/dist/core/context/brain-curator.d.ts.map +1 -1
- package/dist/core/context/brain-curator.js +14 -33
- package/dist/core/context/brain-curator.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +16 -24
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-audit.d.ts.map +1 -1
- package/dist/core/context/context-audit.js +3 -17
- package/dist/core/context/context-audit.js.map +1 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/context-item.d.ts.map +1 -1
- package/dist/core/context/context-item.js.map +1 -1
- package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -1
- package/dist/core/context/context-prompt-enforcement.js +3 -16
- package/dist/core/context/context-prompt-enforcement.js.map +1 -1
- package/dist/core/context/context-prompt-policy.d.ts.map +1 -1
- package/dist/core/context/context-prompt-policy.js.map +1 -1
- package/dist/core/context/context-retention.d.ts.map +1 -1
- package/dist/core/context/context-retention.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/context-store.d.ts.map +1 -1
- package/dist/core/context/context-store.js.map +1 -1
- package/dist/core/context/context-tool-result.d.ts +4 -0
- package/dist/core/context/context-tool-result.d.ts.map +1 -0
- package/dist/core/context/context-tool-result.js +15 -0
- package/dist/core/context/context-tool-result.js.map +1 -0
- package/dist/core/context/current-work-memory.d.ts.map +1 -1
- package/dist/core/context/current-work-memory.js.map +1 -1
- package/dist/core/context/file-store-memory-provider.d.ts.map +1 -1
- package/dist/core/context/file-store-memory-provider.js +7 -28
- package/dist/core/context/file-store-memory-provider.js.map +1 -1
- package/dist/core/context/local-memory-search.d.ts +11 -0
- package/dist/core/context/local-memory-search.d.ts.map +1 -0
- package/dist/core/context/local-memory-search.js +37 -0
- package/dist/core/context/local-memory-search.js.map +1 -0
- package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
- package/dist/core/context/long-term-memory-trigger.js.map +1 -1
- package/dist/core/context/memory-diagnostics.d.ts.map +1 -1
- package/dist/core/context/memory-diagnostics.js.map +1 -1
- package/dist/core/context/memory-index-store.d.ts.map +1 -1
- package/dist/core/context/memory-index-store.js.map +1 -1
- package/dist/core/context/memory-prompt-block.d.ts.map +1 -1
- package/dist/core/context/memory-prompt-block.js.map +1 -1
- package/dist/core/context/memory-prompt-budget.d.ts.map +1 -1
- package/dist/core/context/memory-prompt-budget.js.map +1 -1
- package/dist/core/context/memory-provider-contract.d.ts.map +1 -1
- package/dist/core/context/memory-provider-contract.js.map +1 -1
- package/dist/core/context/memory-retrieval.d.ts.map +1 -1
- package/dist/core/context/memory-retrieval.js.map +1 -1
- package/dist/core/context/memory-tier-composer.d.ts.map +1 -1
- package/dist/core/context/memory-tier-composer.js.map +1 -1
- package/dist/core/context/message-text.d.ts +7 -0
- package/dist/core/context/message-text.d.ts.map +1 -0
- package/dist/core/context/message-text.js +68 -0
- package/dist/core/context/message-text.js.map +1 -0
- package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
- package/dist/core/context/okf-memory-provider.js +4 -30
- package/dist/core/context/okf-memory-provider.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/policy-engine.d.ts.map +1 -1
- package/dist/core/context/policy-engine.js.map +1 -1
- package/dist/core/context/policy-types.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context/storage-authority.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +14 -21
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +1 -3
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +64 -145
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts.map +1 -1
- package/dist/core/cost/session-usage.js.map +1 -1
- package/dist/core/cost-guard.d.ts.map +1 -1
- package/dist/core/cost-guard.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +2 -6
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-action-journal.d.ts.map +1 -1
- package/dist/core/delegation/worker-action-journal.js +0 -4
- package/dist/core/delegation/worker-action-journal.js.map +1 -1
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +13 -15
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js +1 -4
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +0 -2
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +5 -14
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +5 -6
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +0 -3
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +4 -5
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-process-owner.d.ts.map +1 -1
- package/dist/core/delegation/worker-process-owner.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +1 -2
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +3 -4
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -1
- package/dist/core/delegation/worker-resource-catalog.js.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.js +1 -4
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +2 -4
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +6 -18
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -1
- package/dist/core/delegation/worker-task-label.js.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +1 -4
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation.js +0 -2
- package/dist/core/delegation/worker-write-reservation.js.map +1 -1
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +26 -7
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +21 -74
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +4 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/session-tree-foundations.d.mts +67 -0
- package/dist/core/export-html/session-tree-foundations.mjs +313 -0
- package/dist/core/export-html/template.css +14 -41
- package/dist/core/export-html/template.html +3 -1
- package/dist/core/export-html/template.js +26 -435
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extension-import-authority.d.ts.map +1 -1
- package/dist/core/extension-import-authority.js.map +1 -1
- package/dist/core/extension-metadata.d.ts.map +1 -1
- package/dist/core/extension-metadata.js.map +1 -1
- package/dist/core/extensions/builtin.d.ts +17 -0
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +18 -54
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/entry-resolution.d.ts +3 -0
- package/dist/core/extensions/entry-resolution.d.ts.map +1 -0
- package/dist/core/extensions/entry-resolution.js +17 -0
- package/dist/core/extensions/entry-resolution.js.map +1 -0
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +76 -21
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +41 -112
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts.map +1 -1
- package/dist/core/extensions/storage.d.ts.map +1 -1
- package/dist/core/extensions/storage.js.map +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +2 -5
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +27 -33
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +0 -4
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +7 -5
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +0 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +2 -4
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
- package/dist/core/goals/goal-acceptance.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +1 -3
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- package/dist/core/goals/goal-record.d.ts.map +1 -1
- package/dist/core/goals/goal-record.js.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +15 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +27 -3
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +35 -51
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/natural-language-goal.d.ts +9 -0
- package/dist/core/goals/natural-language-goal.d.ts.map +1 -0
- package/dist/core/goals/natural-language-goal.js +23 -0
- package/dist/core/goals/natural-language-goal.js.map +1 -0
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/human-input-controller.d.ts.map +1 -1
- package/dist/core/human-input-controller.js +2 -3
- package/dist/core/human-input-controller.js.map +1 -1
- package/dist/core/human-input.d.ts.map +1 -1
- package/dist/core/human-input.js.map +1 -1
- package/dist/core/improvement-loop.d.ts.map +1 -1
- package/dist/core/improvement-loop.js +11 -11
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -1
- package/dist/core/install-telemetry.js.map +1 -1
- package/dist/core/isolated-text-completion.d.ts +17 -0
- package/dist/core/isolated-text-completion.d.ts.map +1 -0
- package/dist/core/isolated-text-completion.js +15 -0
- package/dist/core/isolated-text-completion.js.map +1 -0
- package/dist/core/keybindings.d.ts +47 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +12 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/observation-store.d.ts.map +1 -1
- package/dist/core/learning/observation-store.js +0 -2
- package/dist/core/learning/observation-store.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +1 -1
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +3 -0
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/learning/reflection-turn-analysis.d.ts +20 -0
- package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -0
- package/dist/core/learning/reflection-turn-analysis.js +136 -0
- package/dist/core/learning/reflection-turn-analysis.js.map +1 -0
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/learning/skill-curator.d.ts.map +1 -1
- package/dist/core/learning/skill-curator.js +0 -3
- package/dist/core/learning/skill-curator.js.map +1 -1
- package/dist/core/local-runtime-controller.d.ts +39 -0
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.js +41 -62
- package/dist/core/local-runtime-controller.js.map +1 -1
- package/dist/core/memory/effectiveness-tracker.d.ts.map +1 -1
- package/dist/core/memory/effectiveness-tracker.js +4 -2
- package/dist/core/memory/effectiveness-tracker.js.map +1 -1
- package/dist/core/memory/memory-manager.d.ts.map +1 -1
- package/dist/core/memory/memory-manager.js +7 -7
- package/dist/core/memory/memory-manager.js.map +1 -1
- package/dist/core/memory/memory-provider.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.d.ts +7 -0
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +48 -13
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts +47 -0
- package/dist/core/memory/providers/transcript-recall-worker-protocol.d.ts.map +1 -0
- package/dist/core/memory/providers/transcript-recall-worker-protocol.js +50 -0
- package/dist/core/memory/providers/transcript-recall-worker-protocol.js.map +1 -0
- package/dist/core/memory/providers/transcript-recall-worker.d.ts +2 -0
- package/dist/core/memory/providers/transcript-recall-worker.d.ts.map +1 -0
- package/dist/core/memory/providers/transcript-recall-worker.js +143 -0
- package/dist/core/memory/providers/transcript-recall-worker.js.map +1 -0
- package/dist/core/memory/providers/transcript-recall.d.ts +24 -13
- package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
- package/dist/core/memory/providers/transcript-recall.js +143 -141
- package/dist/core/memory/providers/transcript-recall.js.map +1 -1
- package/dist/core/memory/providers/user-memory-archive.d.ts +39 -0
- package/dist/core/memory/providers/user-memory-archive.d.ts.map +1 -0
- package/dist/core/memory/providers/user-memory-archive.js +258 -0
- package/dist/core/memory/providers/user-memory-archive.js.map +1 -0
- package/dist/core/memory/transcript-index.d.ts.map +1 -1
- package/dist/core/memory/transcript-index.js +1 -1
- package/dist/core/memory/transcript-index.js.map +1 -1
- package/dist/core/memory-controller.d.ts +9 -0
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +57 -16
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-output-json.d.ts +10 -0
- package/dist/core/model-output-json.d.ts.map +1 -0
- package/dist/core/model-output-json.js +43 -0
- package/dist/core/model-output-json.js.map +1 -0
- package/dist/core/model-registry.d.ts +8 -8
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +29 -52
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
- package/dist/core/model-router/config-diagnostics.js.map +1 -1
- package/dist/core/model-router/executor-route.d.ts.map +1 -1
- package/dist/core/model-router/executor-route.js.map +1 -1
- package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
- package/dist/core/model-router/fitness-gate.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.js +18 -36
- package/dist/core/model-router/route-judge.js.map +1 -1
- package/dist/core/model-router/session-buffer.d.ts.map +1 -1
- package/dist/core/model-router/session-buffer.js.map +1 -1
- package/dist/core/model-router/status.d.ts.map +1 -1
- package/dist/core/model-router/status.js.map +1 -1
- package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
- package/dist/core/model-router/tool-escalation.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +1 -0
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +25 -56
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +10 -0
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js +0 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts.map +1 -1
- package/dist/core/model-tool-protocol.js.map +1 -1
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +0 -1
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/context-sizing.d.ts.map +1 -1
- package/dist/core/models/context-sizing.js.map +1 -1
- package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
- package/dist/core/models/default-model-suggestions.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +0 -1
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts.map +1 -1
- package/dist/core/models/host-state-store.js +1 -6
- package/dist/core/models/host-state-store.js.map +1 -1
- package/dist/core/models/llamacpp-runtime.d.ts +4 -19
- package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
- package/dist/core/models/llamacpp-runtime.js +32 -136
- package/dist/core/models/llamacpp-runtime.js.map +1 -1
- package/dist/core/models/local-registration.d.ts.map +1 -1
- package/dist/core/models/local-registration.js +82 -115
- package/dist/core/models/local-registration.js.map +1 -1
- package/dist/core/models/local-runtime.d.ts +12 -18
- package/dist/core/models/local-runtime.d.ts.map +1 -1
- package/dist/core/models/local-runtime.js +60 -204
- package/dist/core/models/local-runtime.js.map +1 -1
- package/dist/core/models/model-endpoint.d.ts.map +1 -1
- package/dist/core/models/model-endpoint.js.map +1 -1
- package/dist/core/models/model-ref.d.ts.map +1 -1
- package/dist/core/models/model-ref.js.map +1 -1
- package/dist/core/models/needle-runtime.d.ts +7 -3
- package/dist/core/models/needle-runtime.d.ts.map +1 -1
- package/dist/core/models/needle-runtime.js +16 -92
- package/dist/core/models/needle-runtime.js.map +1 -1
- package/dist/core/models/perf-profile.d.ts +1 -1
- package/dist/core/models/perf-profile.d.ts.map +1 -1
- package/dist/core/models/perf-profile.js +6 -13
- package/dist/core/models/perf-profile.js.map +1 -1
- package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -1
- package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -1
- package/dist/core/models/runtime-arbiter.d.ts.map +1 -1
- package/dist/core/models/runtime-arbiter.js +3 -15
- package/dist/core/models/runtime-arbiter.js.map +1 -1
- package/dist/core/models/runtime-process.d.ts +100 -0
- package/dist/core/models/runtime-process.d.ts.map +1 -0
- package/dist/core/models/runtime-process.js +183 -0
- package/dist/core/models/runtime-process.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
- package/dist/core/orchestration/agent-resume.js.map +1 -1
- package/dist/core/orchestration/attempt-usage.d.ts.map +1 -1
- package/dist/core/orchestration/attempt-usage.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +0 -14
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +0 -2
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +1 -14
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/model-binding.d.ts.map +1 -1
- package/dist/core/orchestration/model-binding.js.map +1 -1
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
- package/dist/core/orchestration/policy-compiler.js +0 -3
- package/dist/core/orchestration/policy-compiler.js.map +1 -1
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -1
- package/dist/core/orchestration/policy-gate.js +0 -2
- package/dist/core/orchestration/policy-gate.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +1 -1
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/profile-store.d.ts.map +1 -1
- package/dist/core/orchestration/profile-store.js +0 -3
- package/dist/core/orchestration/profile-store.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +1 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +27 -42
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
- package/dist/core/orchestration/work-state-projection.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts +3 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +88 -353
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/process-identity.d.ts.map +1 -1
- package/dist/core/process-identity.js.map +1 -1
- package/dist/core/process-liveness.d.ts +3 -0
- package/dist/core/process-liveness.d.ts.map +1 -0
- package/dist/core/process-liveness.js +17 -0
- package/dist/core/process-liveness.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -1
- package/dist/core/process-matrix/resume-launcher.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +7 -8
- package/dist/core/profile-filter-controller.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +1 -2
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/profile-resource-selection.d.ts.map +1 -1
- package/dist/core/profile-resource-selection.js +18 -59
- package/dist/core/profile-resource-selection.js.map +1 -1
- package/dist/core/prompt-markup.d.ts +3 -0
- package/dist/core/prompt-markup.d.ts.map +1 -0
- package/dist/core/prompt-markup.js +7 -0
- package/dist/core/prompt-markup.js.map +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +13 -39
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/python-runtime.d.ts.map +1 -1
- package/dist/core/python-runtime.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +22 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +143 -25
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts +2 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +4 -14
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/request-auth.d.ts.map +1 -1
- package/dist/core/request-auth.js.map +1 -1
- package/dist/core/research/automata-provider.d.ts.map +1 -1
- package/dist/core/research/automata-provider.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -1
- package/dist/core/research/lane-model-resolver.js +0 -1
- package/dist/core/research/lane-model-resolver.js.map +1 -1
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -1
- package/dist/core/research/model-fitness-controller.js +17 -33
- package/dist/core/research/model-fitness-controller.js.map +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -25
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +5 -10
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -4
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +17 -48
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/research/workspace-collector.d.ts.map +1 -1
- package/dist/core/research/workspace-collector.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-ignore.d.ts +6 -0
- package/dist/core/resource-ignore.d.ts.map +1 -0
- package/dist/core/resource-ignore.js +44 -0
- package/dist/core/resource-ignore.js.map +1 -0
- package/dist/core/resource-loader.d.ts +0 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +52 -187
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/resource-profile-blocks.d.ts +3 -1
- package/dist/core/resource-profile-blocks.d.ts.map +1 -1
- package/dist/core/resource-profile-blocks.js +8 -5
- package/dist/core/resource-profile-blocks.js.map +1 -1
- package/dist/core/resource-profile-equality.d.ts.map +1 -1
- package/dist/core/resource-profile-equality.js.map +1 -1
- package/dist/core/resource-traversal.d.ts +43 -0
- package/dist/core/resource-traversal.d.ts.map +1 -0
- package/dist/core/resource-traversal.js +84 -0
- package/dist/core/resource-traversal.js.map +1 -0
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +4 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +25 -50
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +0 -1
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +70 -44
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -1
- package/dist/core/secrets/secret-dotenv.js +0 -1
- package/dist/core/secrets/secret-dotenv.js.map +1 -1
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -1
- package/dist/core/secrets/secret-vault-format.js +0 -1
- package/dist/core/secrets/secret-vault-format.js.map +1 -1
- package/dist/core/secrets/secret-vault.d.ts.map +1 -1
- package/dist/core/secrets/secret-vault.js +2 -10
- package/dist/core/secrets/secret-vault.js.map +1 -1
- package/dist/core/security/secret-text.d.ts.map +1 -1
- package/dist/core/security/secret-text.js.map +1 -1
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +18 -50
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-artifact-bundle.d.ts.map +1 -1
- package/dist/core/session-artifact-bundle.js.map +1 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +0 -1
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-entry-index.d.ts +8 -0
- package/dist/core/session-entry-index.d.ts.map +1 -0
- package/dist/core/session-entry-index.js +16 -0
- package/dist/core/session-entry-index.js.map +1 -0
- package/dist/core/session-image-store.d.ts.map +1 -1
- package/dist/core/session-image-store.js +0 -3
- package/dist/core/session-image-store.js.map +1 -1
- package/dist/core/session-jsonl-writer.d.ts +3 -0
- package/dist/core/session-jsonl-writer.d.ts.map +1 -0
- package/dist/core/session-jsonl-writer.js +38 -0
- package/dist/core/session-jsonl-writer.js.map +1 -0
- package/dist/core/session-manager-factory.d.ts.map +1 -1
- package/dist/core/session-manager-factory.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts.map +1 -1
- package/dist/core/session-snapshot.js.map +1 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +1 -4
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +0 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +64 -162
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skill-block.d.mts +8 -0
- package/dist/core/skill-block.mjs +52 -0
- package/dist/core/skill-discovery.d.ts +5 -0
- package/dist/core/skill-discovery.d.ts.map +1 -0
- package/dist/core/skill-discovery.js +34 -0
- package/dist/core/skill-discovery.js.map +1 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +23 -159
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/spawned-usage.d.ts +21 -0
- package/dist/core/spawned-usage.d.ts.map +1 -0
- package/dist/core/spawned-usage.js +29 -0
- package/dist/core/spawned-usage.js.map +1 -0
- package/dist/core/system-prompt-builder.d.ts +4 -0
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +15 -8
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +52 -35
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-command.d.ts.map +1 -1
- package/dist/core/tasks/task-command.js.map +1 -1
- package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -1
- package/dist/core/tasks/task-contract-monitor.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts.map +1 -1
- package/dist/core/tasks/task-projection.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/text-preview.d.ts +4 -0
- package/dist/core/text-preview.d.ts.map +1 -0
- package/dist/core/text-preview.js +33 -0
- package/dist/core/text-preview.js.map +1 -0
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +86 -87
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +4 -1
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js +19 -23
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-recovery-log-worker.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-worker.js.map +1 -1
- package/dist/core/tool-recovery-logger.d.ts.map +1 -1
- package/dist/core/tool-recovery-logger.js +12 -24
- package/dist/core/tool-recovery-logger.js.map +1 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.js +16 -22
- package/dist/core/tool-recovery-stats.js.map +1 -1
- package/dist/core/tool-repair-health.d.ts.map +1 -1
- package/dist/core/tool-repair-health.js.map +1 -1
- package/dist/core/tool-repair-settings.d.ts.map +1 -1
- package/dist/core/tool-repair-settings.js.map +1 -1
- package/dist/core/tool-selection/expected-utility.d.ts.map +1 -1
- package/dist/core/tool-selection/expected-utility.js.map +1 -1
- package/dist/core/tool-selection/promotion.d.ts.map +1 -1
- package/dist/core/tool-selection/promotion.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +2 -0
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +49 -7
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tool-selection/tool-phase-timing.d.ts +19 -0
- package/dist/core/tool-selection/tool-phase-timing.d.ts.map +1 -0
- package/dist/core/tool-selection/tool-phase-timing.js +63 -0
- package/dist/core/tool-selection/tool-phase-timing.js.map +1 -0
- package/dist/core/tool-selection/tool-selection-controller.d.ts +2 -5
- package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-selection-controller.js +50 -30
- package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts +16 -0
- package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.js +21 -0
- package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
- package/dist/core/toolkit/script-registry.d.ts.map +1 -1
- package/dist/core/toolkit/script-registry.js.map +1 -1
- package/dist/core/toolkit/script-runner.d.ts.map +1 -1
- package/dist/core/toolkit/script-runner.js.map +1 -1
- package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
- package/dist/core/tools/artifact-retrieve.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +2 -3
- package/dist/core/tools/ask-question.d.ts.map +1 -1
- package/dist/core/tools/ask-question.js +14 -40
- package/dist/core/tools/ask-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +83 -30
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/context-scout.d.ts.map +1 -1
- package/dist/core/tools/context-scout.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +9 -7
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +6 -6
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/fff-search-backend.d.ts +19 -0
- package/dist/core/tools/fff-search-backend.d.ts.map +1 -1
- package/dist/core/tools/fff-search-backend.js +28 -2
- package/dist/core/tools/fff-search-backend.js.map +1 -1
- package/dist/core/tools/file-encoding-policy.d.ts.map +1 -1
- package/dist/core/tools/file-encoding-policy.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +44 -108
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +7 -7
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +42 -102
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +20 -36
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +5 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
- package/dist/core/tools/orchestration-panel.js +5 -5
- package/dist/core/tools/orchestration-panel.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +24 -36
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/persistent-process-coordinator.d.ts +31 -0
- package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -0
- package/dist/core/tools/persistent-process-coordinator.js +123 -0
- package/dist/core/tools/persistent-process-coordinator.js.map +1 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +14 -13
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +29 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +31 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts +10 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -1
- package/dist/core/tools/search-command-guard.js +118 -31
- package/dist/core/tools/search-command-guard.js.map +1 -1
- package/dist/core/tools/search-router.d.ts.map +1 -1
- package/dist/core/tools/search-router.js.map +1 -1
- package/dist/core/tools/search-tool-runtime.d.ts +19 -0
- package/dist/core/tools/search-tool-runtime.d.ts.map +1 -0
- package/dist/core/tools/search-tool-runtime.js +12 -0
- package/dist/core/tools/search-tool-runtime.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
- package/dist/core/tools/shell-command-parser.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +4 -1
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/shell-execution-session.d.ts +4 -0
- package/dist/core/tools/shell-execution-session.d.ts.map +1 -0
- package/dist/core/tools/shell-execution-session.js +11 -0
- package/dist/core/tools/shell-execution-session.js.map +1 -0
- package/dist/core/tools/shell-output-projection.d.ts +49 -0
- package/dist/core/tools/shell-output-projection.d.ts.map +1 -0
- package/dist/core/tools/shell-output-projection.js +381 -0
- package/dist/core/tools/shell-output-projection.js.map +1 -0
- package/dist/core/tools/shell-session.d.ts +2 -13
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +36 -136
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/core/tools/skill-audit.d.ts.map +1 -1
- package/dist/core/tools/skill-audit.js.map +1 -1
- package/dist/core/tools/skillify.d.ts.map +1 -1
- package/dist/core/tools/skillify.js.map +1 -1
- package/dist/core/tools/task-steps.d.ts +8 -8
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +17 -18
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-task.d.ts +23 -0
- package/dist/core/tools/tool-task.d.ts.map +1 -0
- package/dist/core/tools/tool-task.js +93 -0
- package/dist/core/tools/tool-task.js.map +1 -0
- package/dist/core/tools/windows-shell-engine.d.ts +17 -11
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +339 -117
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/tools/windows-shell-state.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-state.js.map +1 -1
- package/dist/core/tools/worktree-sync.d.ts.map +1 -1
- package/dist/core/tools/worktree-sync.js +8 -12
- package/dist/core/tools/worktree-sync.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +0 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +7 -40
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +19 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +50 -15
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts.map +1 -1
- package/dist/core/util/bounded-file.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
- package/dist/core/util/bounded-jsonl.js +2 -9
- package/dist/core/util/bounded-jsonl.js.map +1 -1
- package/dist/core/util/bounded-value.d.ts.map +1 -1
- package/dist/core/util/bounded-value.js.map +1 -1
- package/dist/core/util/json-size.d.ts +3 -0
- package/dist/core/util/json-size.d.ts.map +1 -0
- package/dist/core/util/json-size.js +95 -0
- package/dist/core/util/json-size.js.map +1 -0
- package/dist/core/util/minimatch-cache.d.ts.map +1 -1
- package/dist/core/util/minimatch-cache.js.map +1 -1
- package/dist/core/util/value-guards.d.ts.map +1 -1
- package/dist/core/util/value-guards.js.map +1 -1
- package/dist/core/worktree-sync/codes.d.ts.map +1 -1
- package/dist/core/worktree-sync/git-engine.d.ts.map +1 -1
- package/dist/core/worktree-sync/git-engine.js +20 -36
- package/dist/core/worktree-sync/git-engine.js.map +1 -1
- package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
- package/dist/core/worktree-sync/lane-gate.js +1 -4
- package/dist/core/worktree-sync/lane-gate.js.map +1 -1
- package/dist/core/worktree-sync/runtime.d.ts.map +1 -1
- package/dist/core/worktree-sync/runtime.js.map +1 -1
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/core/worktree-sync/watcher.d.ts.map +1 -1
- package/dist/core/worktree-sync/watcher.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +10 -32
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +6 -19
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +3 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +96 -132
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.d.ts +1 -31
- package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +86 -307
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -1
- package/dist/modes/interactive/autocomplete-provider.js.map +1 -1
- package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -1
- package/dist/modes/interactive/autonomy-commands.js +2 -8
- package/dist/modes/interactive/autonomy-commands.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +5 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +17 -0
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/compaction-queue.d.ts.map +1 -1
- package/dist/modes/interactive/compaction-queue.js +13 -18
- package/dist/modes/interactive/compaction-queue.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +6 -10
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts +1 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +10 -21
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +1 -6
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +4 -9
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +0 -3
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -8
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +13 -35
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -8
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +14 -36
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +20 -43
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +0 -5
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +4 -8
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -6
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js +6 -8
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +0 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/expandable-markdown-message.d.ts +21 -0
- package/dist/modes/interactive/components/expandable-markdown-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-markdown-message.js +48 -0
- package/dist/modes/interactive/components/expandable-markdown-message.js.map +1 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/expandable-text.js +0 -2
- package/dist/modes/interactive/components/expandable-text.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +1 -9
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +2 -8
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +5 -20
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.js +0 -1
- package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -5
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +4 -10
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +2 -2
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +21 -44
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-suggestion-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-suggestion-selector.js +0 -1
- package/dist/modes/interactive/components/model-suggestion-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +16 -32
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.d.ts +3 -4
- package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.js +34 -93
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/profile-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/profile-selector.js +0 -1
- package/dist/modes/interactive/components/profile-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +3 -4
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +34 -79
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/selector-list.d.ts +63 -0
- package/dist/modes/interactive/components/selector-list.d.ts.map +1 -0
- package/dist/modes/interactive/components/selector-list.js +186 -0
- package/dist/modes/interactive/components/selector-list.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +34 -59
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +40 -138
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts +2 -4
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +9 -28
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +3 -8
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +12 -40
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts +2 -5
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js +11 -37
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts +2 -4
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +9 -31
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +9 -28
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +2 -3
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-panel-registry.js +5 -3
- package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -1
- package/dist/modes/interactive/components/tool-title.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-title.js +0 -4
- package/dist/modes/interactive/components/tool-title.js.map +1 -1
- package/dist/modes/interactive/components/transcript-pager.d.ts +26 -0
- package/dist/modes/interactive/components/transcript-pager.d.ts.map +1 -0
- package/dist/modes/interactive/components/transcript-pager.js +81 -0
- package/dist/modes/interactive/components/transcript-pager.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -12
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +42 -402
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +4 -16
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.js +2 -10
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +3 -6
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +0 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
- package/dist/modes/interactive/editor-overlay-host.js +0 -3
- package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +2 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +51 -72
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -15
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +23 -16
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +123 -204
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-selection-prompts.d.ts +20 -0
- package/dist/modes/interactive/interactive-selection-prompts.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-selection-prompts.js +43 -0
- package/dist/modes/interactive/interactive-selection-prompts.js.map +1 -0
- package/dist/modes/interactive/key-handlers.d.ts +2 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +4 -2
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -1
- package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
- package/dist/modes/interactive/local-model-commands.js +4 -9
- package/dist/modes/interactive/local-model-commands.js.map +1 -1
- package/dist/modes/interactive/model-fitness-presentation.d.ts +21 -0
- package/dist/modes/interactive/model-fitness-presentation.d.ts.map +1 -0
- package/dist/modes/interactive/model-fitness-presentation.js +13 -0
- package/dist/modes/interactive/model-fitness-presentation.js.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts +2 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +79 -171
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts +2 -0
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +12 -6
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +6 -23
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +21 -25
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
- package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -1
- package/dist/modes/interactive/signal-lifecycle.js.map +1 -1
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +12 -8
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +10 -76
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -1
- package/dist/modes/interactive/usage-commands.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +5 -22
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.js +1 -1
- package/dist/modes/rpc/jsonl.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +5 -20
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/termination-signals.d.ts +4 -0
- package/dist/modes/termination-signals.d.ts.map +1 -0
- package/dist/modes/termination-signals.js +21 -0
- package/dist/modes/termination-signals.js.map +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi-colors.d.ts +5 -0
- package/dist/utils/ansi-colors.d.ts.map +1 -0
- package/dist/utils/ansi-colors.js +38 -0
- package/dist/utils/ansi-colors.js.map +1 -0
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/deprecation.d.ts.map +1 -1
- package/dist/utils/deprecation.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/external-editor-command.d.ts.map +1 -1
- package/dist/utils/external-editor-command.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js.map +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +20 -28
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/highlight-js-languages.d.ts.map +1 -1
- package/dist/utils/html.d.ts.map +1 -1
- package/dist/utils/html.js.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize-worker.d.ts.map +1 -1
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/platform.js.map +1 -1
- package/dist/utils/process-memory.d.ts.map +1 -1
- package/dist/utils/process-memory.js.map +1 -1
- package/dist/utils/safe-write-stream.d.ts.map +1 -1
- package/dist/utils/safe-write-stream.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +2 -15
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/stdin-events.d.ts +8 -0
- package/dist/utils/stdin-events.d.ts.map +1 -0
- package/dist/utils/stdin-events.js +19 -0
- package/dist/utils/stdin-events.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +20 -13
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/windows-self-update.d.ts.map +1 -1
- package/dist/utils/windows-self-update.js.map +1 -1
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/compaction.md +11 -3
- package/docs/sessions.md +6 -0
- package/docs/settings.md +1 -1
- package/docs/windows.md +26 -1
- package/docs/work-directory.md +9 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +16 -16
- package/package.json +10 -10
- package/dist/utils/streaming-lines.d.ts +0 -20
- package/dist/utils/streaming-lines.d.ts.map +0 -1
- package/dist/utils/streaming-lines.js +0 -79
- package/dist/utils/streaming-lines.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-shell-engine.js","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAA6B,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EACN,gBAAgB,EAChB,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,GAEnB,MAAM,0BAA0B,CAAC;AAElC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAUnC,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAC1C,cAAc,CAAS;IAEhC,YAAY,OAAe,EAAE,cAAsB,EAAE;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IAAA,CACrC;CACD;AAED,SAAS,uBAAuB,GAAW;IAC1C,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AAC,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAClC,MAAM,IAAI,yBAAyB,CAClC,6CAA6C,QAAQ,CAAC,IAAI,IAAI,MAAM,yCAAyC,cAAc,EAAE,EAC7H,cAAc,CACd,CAAC;gBACH,CAAC;gBAED,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC/B,IAAI,KAAK,CAAC,WAAW;oBAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAClE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrC,CAAC;oBAAS,CAAC;gBACV,IAAI,KAAK,CAAC,GAAG;oBAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnD,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * The `python-engine` tier: per-command spawn of the bundled `pi-shell-engine` (D3 in the\n * blueprint). Wires the frozen §1.2/§1.3 stdin-JSON-request / 0x1e-framed-stdout protocol into a\n * `BashOperations`, threads `WindowsShellState` through both directions (D4), and degrades to a\n * named, actionable error when the Python runtime is not ready — the PowerShell floor keeps\n * working regardless (the router never routes simple commands here when the engine is off).\n */\n\nimport type { ChildProcess, SpawnOptions } from \"node:child_process\";\nimport { join } from \"node:path\";\nimport { getBundledResourcesDir } from \"../../config.ts\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport { getShellEnv, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\nimport type { BashOperations } from \"./bash.ts\";\nimport {\n\tapplyEngineFrame,\n\tgetOrCreateWindowsShellState,\n\tmergeEffectiveEnv,\n\tresolveEffectiveCwd,\n\ttype WindowsShellState,\n} from \"./windows-shell-state.ts\";\n\nconst ENGINE_FRAME_SENTINEL = 0x1e;\n\n/** The full §1.3 control-frame shape. */\nexport interface WindowsShellEngineFrame {\n\texitCode: number;\n\tcwd: string;\n\tenvDelta: Record<string, string | null>;\n\tunsupported: { code: \"unsupported\"; construct: string; message: string } | null;\n}\n\nexport class WindowsShellEngineFailure extends Error {\n\treadonly capturedOutput: string;\n\n\tconstructor(message: string, capturedOutput: string) {\n\t\tsuper(message);\n\t\tthis.name = \"WindowsShellEngineFailure\";\n\t\tthis.capturedOutput = capturedOutput;\n\t}\n}\n\nfunction resolveEngineScriptPath(): string {\n\treturn join(getBundledResourcesDir(), \"runtimes\", \"pi-shell-engine\", \"main.py\");\n}\n\nconst MAX_CONTROL_FRAME_BYTES = 64 * 1024;\n\n/** Parse the terminal frame from the dedicated control stream. Command output is never retained here. */\nfunction parseControlFrame(buffer: Buffer): WindowsShellEngineFrame | undefined {\n\tif (buffer.length < 2 || buffer[buffer.length - 1] !== ENGINE_FRAME_SENTINEL) return undefined;\n\tconst openIndex = buffer.lastIndexOf(ENGINE_FRAME_SENTINEL, buffer.length - 2);\n\tif (openIndex === -1) return undefined;\n\ttry {\n\t\tconst raw: unknown = JSON.parse(buffer.subarray(openIndex + 1, buffer.length - 1).toString(\"utf8\"));\n\t\tif (!isRecordObject(raw)) return undefined;\n\t\tif (typeof raw.exitCode !== \"number\" || !Number.isInteger(raw.exitCode)) return undefined;\n\t\tif (typeof raw.cwd !== \"string\" || !isRecordObject(raw.envDelta)) return undefined;\n\t\tif (raw.unsupported !== null && !isRecordObject(raw.unsupported)) return undefined;\n\t\tif (\n\t\t\traw.unsupported !== null &&\n\t\t\t(raw.unsupported.code !== \"unsupported\" ||\n\t\t\t\ttypeof raw.unsupported.construct !== \"string\" ||\n\t\t\t\ttypeof raw.unsupported.message !== \"string\")\n\t\t)\n\t\t\treturn undefined;\n\t\tfor (const value of Object.values(raw.envDelta)) {\n\t\t\tif (value !== null && typeof value !== \"string\") return undefined;\n\t\t}\n\t\treturn raw as unknown as WindowsShellEngineFrame;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport interface WindowsShellEngineOptions {\n\t/** Override for tests: resolves the Python runtime outcome. Default: `ensurePythonRuntime`. */\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\t/** Override for tests: absolute path to the engine's `main.py`. Default: the bundled runtime. */\n\tengineScriptPath?: string;\n\t/** Override for tests: the per-session state store lookup. Default: the shared module store. */\n\tgetState?: (sessionKey: string) => WindowsShellState;\n\t/** Override for tests: spawns the engine child process. Default: `spawnProcess` (cross-spawn on win32). */\n\tspawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;\n}\n\nfunction degradationError(\n\toutcome: Extract<PythonRuntimeOutcome, { status: \"offline\" | \"uv-unavailable\" | \"python-unavailable\" }>,\n) {\n\treturn new Error(\n\t\t`The Windows shell engine (Python) is unavailable: ${outcome.reason} The simple-command PowerShell floor still works; fix the Python runtime (uv/network) to restore pipelines, redirection, expansion, and chaining.`,\n\t);\n}\n\n/**\n * Create the `python-engine` tier `BashOperations` for one bash-tool session. `exec`'s `command`\n * argument is the RAW Bash source from the `python-engine` route (never PowerShell-translated).\n */\nexport function createWindowsShellEngineOperations(\n\tsessionKey: string,\n\toptions: WindowsShellEngineOptions = {},\n): BashOperations {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst engineScriptPath = options.engineScriptPath ?? resolveEngineScriptPath();\n\tconst getState = options.getState ?? getOrCreateWindowsShellState;\n\tconst spawn = options.spawn ?? spawnProcess;\n\n\treturn {\n\t\tasync exec(command, cwd, { onData, signal, timeout, env }) {\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw degradationError(runtime);\n\n\t\t\tconst state = getState(sessionKey);\n\t\t\tconst effectiveCwd = resolveEffectiveCwd(state, cwd);\n\t\t\tconst effectiveEnv = mergeEffectiveEnv(state, env ?? getShellEnv());\n\t\t\tconst timeoutMs = timeout !== undefined && timeout > 0 ? timeout * 1000 : undefined;\n\t\t\t// The engine's own soft deadline must fire and emit its cooperative exit-124 frame (which\n\t\t\t// preserves partial output) BEFORE the hard tree-kill backstop below, or the hard kill\n\t\t\t// always wins the race and the soft path never gets to run. Give it a head start; the hard\n\t\t\t// kill still bounds a hung engine that never reads its own deadline.\n\t\t\tconst requestTimeoutMs = timeoutMs !== undefined ? Math.max(timeoutMs - 500, 500) : undefined;\n\n\t\t\tconst request = {\n\t\t\t\tcommand,\n\t\t\t\tcwd: effectiveCwd,\n\t\t\t\tenv: effectiveEnv,\n\t\t\t\t...(requestTimeoutMs !== undefined ? { timeoutMs: requestTimeoutMs } : {}),\n\t\t\t};\n\n\t\t\tconst child = spawn(runtime.pythonPath, [\"-B\", engineScriptPath], {\n\t\t\t\tcwd: effectiveCwd,\n\t\t\t\tenv: {\n\t\t\t\t\t...effectiveEnv,\n\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t},\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\t\tlet controlBuffer: Buffer<ArrayBufferLike> = Buffer.alloc(0);\n\t\t\tlet controlOverflow = false;\n\n\t\t\t// Command output is the data stream: forward it immediately and never retain a\n\t\t\t// second full copy merely to find the terminal frame.\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\t\tonData(chunk);\n\t\t\t});\n\t\t\t// stderr is the bounded control stream. The Python engine routes command stderr\n\t\t\t// into stdout, so this channel contains only the terminal frame/diagnostics.\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\t\tif (controlOverflow) return;\n\t\t\t\tif (controlBuffer.length + chunk.length > MAX_CONTROL_FRAME_BYTES) {\n\t\t\t\t\tcontrolOverflow = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcontrolBuffer = Buffer.concat([controlBuffer, chunk]);\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tchild.stdin?.end(JSON.stringify(request), \"utf8\");\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeoutMs,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\t\t\tconst frame = controlOverflow ? undefined : parseControlFrame(controlBuffer);\n\t\t\t\tif (!frame) {\n\t\t\t\t\tconst capturedOutput = controlOverflow\n\t\t\t\t\t\t? `control frame exceeded ${MAX_CONTROL_FRAME_BYTES} bytes`\n\t\t\t\t\t\t: controlBuffer.toString(\"utf8\");\n\t\t\t\t\tthrow new WindowsShellEngineFailure(\n\t\t\t\t\t\t`Windows shell engine failed (process exit ${terminal.code ?? \"null\"}) without a parseable control frame.\\n${capturedOutput}`,\n\t\t\t\t\t\tcapturedOutput,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tapplyEngineFrame(state, frame);\n\t\t\t\tif (frame.unsupported) throw new Error(frame.unsupported.message);\n\t\t\t\treturn { exitCode: frame.exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"windows-shell-engine.js","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,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AAI,GAAG,EAA+C,CAAC;AAE9E,SAAS,gCAAgC,CACxC,GAAW,EACX,OAAkC;IAElC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,OAAO,GAAG,IAAI,mCAAmC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtE,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,gCAAgC,CAAC,GAAW;IAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,OAAO,EAAE,CAAC;AACnB,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,kCAAkC,CACjD,UAAkB,EAClB,OAAO,GAA8B,EAAE;IAEvC,OAAO;QACN,sFAAsF;QACtF,0FAA0F;QAC1F,uFAAuF;QACvF,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,CACnC,gCAAgC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC;KACtF,CAAC;AACH,CAAC","sourcesContent":["/**\n * Persistent Windows Python shell-engine sessions.\n *\n * One coordinator process is keyed to each agent session. Requests are serialized as JSON lines;\n * Node remains the sole owner of cwd/environment state and derives each request only after the\n * preceding terminal frame has been applied. Command bytes stream on stdout, followed by a\n * request-specific output barrier. A correlated control frame arrives on stderr. Requiring both\n * channels before settlement prevents cross-pipe tail loss and stale-frame reuse.\n *\n * Timeout, abort, protocol failure, or coordinator death resets the whole process tree. The next\n * request starts a clean coordinator from the last state Node actually acknowledged.\n */\n\nimport type { ChildProcess, SpawnOptions } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport { dirname, join } from \"node:path\";\nimport { getBundledResourcesDir } from \"../../config.ts\";\nimport { spawnProcess } from \"../../utils/child-process.ts\";\nimport { getShellConfig, getShellEnv } from \"../../utils/shell.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { isRecordObject } from \"../util/value-guards.ts\";\nimport type { BashOperations } from \"./bash.ts\";\nimport { PersistentProcessCoordinator } from \"./persistent-process-coordinator.ts\";\nimport { tokenizeShellCommand } from \"./shell-command-parser.ts\";\nimport {\n\tapplyEngineFrame,\n\tgetOrCreateWindowsShellState,\n\tmergeEffectiveEnv,\n\tresolveEffectiveCwd,\n\ttype WindowsShellState,\n} from \"./windows-shell-state.ts\";\n\nconst ENGINE_FRAME_SENTINEL = 0x1e;\nconst MAX_CONTROL_FRAME_BYTES = 64 * 1024;\nconst SOFT_DEADLINE_HEADSTART_MS = 100;\n\n/** State/result fields returned for every completed engine command. */\nexport interface WindowsShellEngineFrame {\n\texitCode: number;\n\tcwd: string;\n\tenvDelta: Record<string, string | null>;\n\tunsupported: { code: \"unsupported\"; construct: string; message: string } | null;\n}\n\ninterface WindowsShellEngineControlFrame extends WindowsShellEngineFrame {\n\trequestId: string;\n}\n\ninterface WindowsShellEngineRequest {\n\trequestId: string;\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n\tpowershellPath?: string;\n\ttimeoutMs?: number;\n}\n\ninterface ParsedControlFrame {\n\tkind: \"frame\";\n\tframe: WindowsShellEngineControlFrame;\n\tframeStart: number;\n\tframeEnd: number;\n}\n\ninterface InvalidControlFrame {\n\tkind: \"invalid\";\n}\n\ninterface ActiveEngineExec {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonChildClose(code: number | null): void;\n\tfail(error: Error): void;\n}\n\nexport class WindowsShellEngineFailure extends Error {\n\treadonly capturedOutput: string;\n\n\tconstructor(message: string, capturedOutput: string) {\n\t\tsuper(message);\n\t\tthis.name = \"WindowsShellEngineFailure\";\n\t\tthis.capturedOutput = capturedOutput;\n\t}\n}\n\nfunction resolveEngineScriptPath(): string {\n\treturn join(getBundledResourcesDir(), \"runtimes\", \"pi-shell-engine\", \"main.py\");\n}\n\nfunction invokesPowerShellScript(command: string): boolean {\n\tconst tokens = tokenizeShellCommand(command);\n\t// An unparseable command is already heading to the authoritative Python parser;\n\t// resolve conservatively so script adaptation cannot lose an explicit host choice.\n\tif (!tokens) return /\\.ps1\\b/iu.test(command);\n\n\tlet atCommandStart = true;\n\tlet skipRedirectTarget = false;\n\tfor (const token of tokens) {\n\t\tif (token.kind === \"operator\" || token.kind === \"pipe\") {\n\t\t\tatCommandStart = true;\n\t\t\tskipRedirectTarget = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (token.kind === \"redirect\") {\n\t\t\tskipRedirectTarget = !/^\\d*[<>]&[\\d-]+$/u.test(token.value);\n\t\t\tcontinue;\n\t\t}\n\t\tif (skipRedirectTarget) {\n\t\t\tskipRedirectTarget = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!atCommandStart || /^[A-Za-z_][A-Za-z0-9_]*=/u.test(token.value)) continue;\n\t\tif (token.value.toLowerCase().endsWith(\".ps1\")) return true;\n\t\tatCommandStart = false;\n\t}\n\treturn false;\n}\n\nfunction parseControlFrame(buffer: Buffer): ParsedControlFrame | InvalidControlFrame | undefined {\n\tconst frameStart = buffer.indexOf(ENGINE_FRAME_SENTINEL);\n\tif (frameStart === -1) return undefined;\n\tconst closeIndex = buffer.indexOf(ENGINE_FRAME_SENTINEL, frameStart + 1);\n\tif (closeIndex === -1) return undefined;\n\ttry {\n\t\tconst raw: unknown = JSON.parse(buffer.subarray(frameStart + 1, closeIndex).toString(\"utf8\"));\n\t\tif (\n\t\t\tisRecordObject(raw) &&\n\t\t\ttypeof raw.requestId === \"string\" &&\n\t\t\t/^[0-9a-f]{16}$/u.test(raw.requestId) &&\n\t\t\ttypeof raw.exitCode === \"number\" &&\n\t\t\tNumber.isInteger(raw.exitCode) &&\n\t\t\ttypeof raw.cwd === \"string\" &&\n\t\t\tisRecordObject(raw.envDelta) &&\n\t\t\t(raw.unsupported === null || isRecordObject(raw.unsupported)) &&\n\t\t\t(raw.unsupported === null ||\n\t\t\t\t(raw.unsupported.code === \"unsupported\" &&\n\t\t\t\t\ttypeof raw.unsupported.construct === \"string\" &&\n\t\t\t\t\ttypeof raw.unsupported.message === \"string\")) &&\n\t\t\tObject.values(raw.envDelta).every((value) => value === null || typeof value === \"string\")\n\t\t) {\n\t\t\treturn {\n\t\t\t\tkind: \"frame\",\n\t\t\t\tframe: raw as unknown as WindowsShellEngineControlFrame,\n\t\t\t\tframeStart,\n\t\t\t\tframeEnd: closeIndex + 1,\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// A complete delimited record that is not JSON is a terminal protocol fault.\n\t}\n\treturn { kind: \"invalid\" };\n}\n\nexport interface WindowsShellEngineOptions {\n\t/** Override for tests: resolves the Python runtime outcome. Default: `ensurePythonRuntime`. */\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\t/** Override for tests: absolute path to the engine's `main.py`. Default: the bundled runtime. */\n\tengineScriptPath?: string;\n\t/** Override for tests: the per-session state store lookup. Default: the shared module store. */\n\tgetState?: (sessionKey: string) => WindowsShellState;\n\t/** Override for tests: spawns the persistent coordinator. Default: `spawnProcess`. */\n\tspawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;\n\t/** Override for tests: selected PowerShell host used to adapt `.ps1` external commands. */\n\tresolvePowerShellPath?: () => string;\n}\n\nfunction degradationError(\n\toutcome: Extract<PythonRuntimeOutcome, { status: \"offline\" | \"uv-unavailable\" | \"python-unavailable\" }>,\n): Error {\n\treturn new Error(\n\t\t`The Windows shell engine (Python) is unavailable: ${outcome.reason} The simple-command PowerShell floor still works; fix the Python runtime (uv/network) to restore pipelines, redirection, expansion, and chaining.`,\n\t);\n}\n\nclass PersistentWindowsShellEngineSession {\n\tprivate readonly key: string;\n\tprivate readonly resolveRuntime: () => Promise<PythonRuntimeOutcome>;\n\tprivate readonly engineScriptPath: string;\n\tprivate readonly getState: (sessionKey: string) => WindowsShellState;\n\tprivate readonly spawn: (command: string, args: string[], options: SpawnOptions) => ChildProcess;\n\tprivate readonly resolvePowerShellPath: () => string;\n\tprivate readonly coordinator = new PersistentProcessCoordinator();\n\tprivate activeExec: ActiveEngineExec | null = null;\n\tprivate disposed = false;\n\n\tconstructor(key: string, options: WindowsShellEngineOptions) {\n\t\tthis.key = key;\n\t\tthis.resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\t\tthis.engineScriptPath = options.engineScriptPath ?? resolveEngineScriptPath();\n\t\tthis.getState = options.getState ?? getOrCreateWindowsShellState;\n\t\tthis.spawn = options.spawn ?? spawnProcess;\n\t\tthis.resolvePowerShellPath =\n\t\t\toptions.resolvePowerShellPath ??\n\t\t\t(() => (process.platform === \"win32\" ? getShellConfig(undefined, \"powershell\").shell : \"powershell\"));\n\t}\n\n\texec(\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: Parameters<BashOperations[\"exec\"]>[2],\n\t): Promise<{ exitCode: number | null }> {\n\t\treturn this.coordinator.runSerialized(() => this.execNow(command, cwd, options));\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tconst active = this.activeExec;\n\t\tthis.coordinator.dispose();\n\t\tactive?.fail(new Error(`Windows shell engine session \"${this.key}\" is disposed`));\n\t}\n\n\tprivate async execNow(\n\t\tcommand: string,\n\t\tcwd: string,\n\t\t{ onData, signal, timeout, env }: Parameters<BashOperations[\"exec\"]>[2],\n\t): Promise<{ exitCode: number | null }> {\n\t\tif (this.disposed) throw new Error(`Windows shell engine session \"${this.key}\" is disposed`);\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\tconst state = this.getState(this.key);\n\t\tconst effectiveCwd = resolveEffectiveCwd(state, cwd);\n\t\tconst effectiveEnv = mergeEffectiveEnv(state, env ?? getShellEnv());\n\t\tconst child = await this.ensureChild(effectiveEnv);\n\t\tif (this.disposed) {\n\t\t\tthis.killChild();\n\t\t\tthrow new Error(`Windows shell engine session \"${this.key}\" is disposed`);\n\t\t}\n\t\tif (signal?.aborted) {\n\t\t\tthis.killChild();\n\t\t\tthrow new Error(\"aborted\");\n\t\t}\n\t\tif (!child.stdin || !child.stdout || !child.stderr || child !== this.coordinator.child) {\n\t\t\tthis.killChild();\n\t\t\tthrow new Error(\"Failed to start Windows shell engine coordinator\");\n\t\t}\n\n\t\tconst timeoutMs = timeout !== undefined && timeout > 0 ? timeout * 1000 : undefined;\n\t\tconst requestTimeoutMs =\n\t\t\ttimeoutMs !== undefined ? Math.max(timeoutMs - SOFT_DEADLINE_HEADSTART_MS, 1) : undefined;\n\t\tconst requestId = randomBytes(8).toString(\"hex\");\n\t\tconst request: WindowsShellEngineRequest = {\n\t\t\trequestId,\n\t\t\tcommand,\n\t\t\tcwd: effectiveCwd,\n\t\t\tenv: effectiveEnv,\n\t\t\t...(invokesPowerShellScript(command) ? { powershellPath: this.resolvePowerShellPath() } : {}),\n\t\t\t...(requestTimeoutMs !== undefined ? { timeoutMs: requestTimeoutMs } : {}),\n\t\t};\n\t\tconst outputBarrier = Buffer.from(`\\x1e${requestId}\\x1e`, \"latin1\");\n\n\t\tthis.coordinator.setLoopRef(true);\n\t\ttry {\n\t\t\treturn await new Promise<{ exitCode: number | null }>((resolve, reject) => {\n\t\t\t\tlet settled = false;\n\t\t\t\tlet pendingOutput: Buffer<ArrayBufferLike> = Buffer.alloc(0);\n\t\t\t\tlet controlBuffer: Buffer<ArrayBufferLike> = Buffer.alloc(0);\n\t\t\t\tlet controlOverflow = false;\n\t\t\t\tlet sawOutputBarrier = false;\n\t\t\t\tlet controlFrame: WindowsShellEngineControlFrame | undefined;\n\t\t\t\tlet completionScheduled = false;\n\t\t\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\t\t\tconst settle = (finish: () => void): void => {\n\t\t\t\t\tif (settled) return;\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tif (timeoutTimer) clearTimeout(timeoutTimer);\n\t\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tif (this.activeExec === active) this.activeExec = null;\n\t\t\t\t\tfinish();\n\t\t\t\t};\n\n\t\t\t\tconst emitPending = (upTo: number): void => {\n\t\t\t\t\tif (upTo <= 0) return;\n\t\t\t\t\tonData(pendingOutput.subarray(0, upTo));\n\t\t\t\t\tpendingOutput = pendingOutput.subarray(upTo);\n\t\t\t\t};\n\n\t\t\t\tconst capturedControl = (): string =>\n\t\t\t\t\tcontrolOverflow\n\t\t\t\t\t\t? `control frame exceeded ${MAX_CONTROL_FRAME_BYTES} bytes`\n\t\t\t\t\t\t: controlBuffer.toString(\"utf8\");\n\n\t\t\t\tconst failAndReset = (error: Error): void => {\n\t\t\t\t\tif (settled) return;\n\t\t\t\t\temitPending(pendingOutput.length);\n\t\t\t\t\tthis.killChild();\n\t\t\t\t\tsettle(() => reject(error));\n\t\t\t\t};\n\n\t\t\t\tconst protocolFailure = (message: string): WindowsShellEngineFailure => {\n\t\t\t\t\tconst capturedOutput = capturedControl();\n\t\t\t\t\treturn new WindowsShellEngineFailure(`${message}\\n${capturedOutput}`, capturedOutput);\n\t\t\t\t};\n\n\t\t\t\tconst maybeComplete = (): void => {\n\t\t\t\t\tif (!sawOutputBarrier || !controlFrame || settled || completionScheduled) return;\n\t\t\t\t\tcompletionScheduled = true;\n\t\t\t\t\t// stdout and stderr are independent pipes. Keep this request active through the\n\t\t\t\t\t// next check phase so already-delivered post-barrier bytes are rejected here,\n\t\t\t\t\t// never forwarded into a queued request that starts in a promise microtask.\n\t\t\t\t\tsetImmediate(() => {\n\t\t\t\t\t\tif (settled || this.activeExec !== active || !controlFrame) return;\n\t\t\t\t\t\tapplyEngineFrame(state, controlFrame);\n\t\t\t\t\t\tif (controlFrame.unsupported) {\n\t\t\t\t\t\t\tsettle(() =>\n\t\t\t\t\t\t\t\treject(new Error(controlFrame?.unsupported?.message ?? \"Unsupported shell construct\")),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsettle(() => resolve({ exitCode: controlFrame?.exitCode ?? null }));\n\t\t\t\t\t});\n\t\t\t\t};\n\n\t\t\t\tconst onAbort = (): void => failAndReset(new Error(\"aborted\"));\n\n\t\t\t\tconst active: ActiveEngineExec = {\n\t\t\t\t\tonStdout: (data) => {\n\t\t\t\t\t\tif (sawOutputBarrier) {\n\t\t\t\t\t\t\tfailAndReset(protocolFailure(\"Windows shell engine emitted output after its terminal barrier.\"));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpendingOutput = pendingOutput.length === 0 ? data : Buffer.concat([pendingOutput, data]);\n\t\t\t\t\t\tconst barrierIndex = pendingOutput.indexOf(outputBarrier);\n\t\t\t\t\t\tif (barrierIndex !== -1) {\n\t\t\t\t\t\t\temitPending(barrierIndex);\n\t\t\t\t\t\t\tpendingOutput = pendingOutput.subarray(outputBarrier.length);\n\t\t\t\t\t\t\tif (pendingOutput.length > 0) {\n\t\t\t\t\t\t\t\tfailAndReset(protocolFailure(\"Windows shell engine emitted bytes after its terminal barrier.\"));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsawOutputBarrier = true;\n\t\t\t\t\t\t\tmaybeComplete();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\temitPending(pendingOutput.length - (outputBarrier.length - 1));\n\t\t\t\t\t},\n\t\t\t\t\tonStderr: (data) => {\n\t\t\t\t\t\tif (controlOverflow) return;\n\t\t\t\t\t\tif (controlBuffer.length + data.length > MAX_CONTROL_FRAME_BYTES) {\n\t\t\t\t\t\t\tcontrolOverflow = true;\n\t\t\t\t\t\t\tfailAndReset(protocolFailure(\"Windows shell engine control frame overflowed.\"));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontrolBuffer = controlBuffer.length === 0 ? data : Buffer.concat([controlBuffer, data]);\n\t\t\t\t\t\tconst parsed = parseControlFrame(controlBuffer);\n\t\t\t\t\t\tif (!parsed) return;\n\t\t\t\t\t\tif (parsed.kind === \"invalid\") {\n\t\t\t\t\t\t\tfailAndReset(protocolFailure(\"Windows shell engine returned a malformed control frame.\"));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parsed.frame.requestId !== requestId) {\n\t\t\t\t\t\t\tfailAndReset(\n\t\t\t\t\t\t\t\tprotocolFailure(\n\t\t\t\t\t\t\t\t\t`Windows shell engine returned stale control frame ${parsed.frame.requestId}; expected ${requestId}.`,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (controlBuffer.subarray(parsed.frameEnd).toString(\"utf8\").trim().length > 0) {\n\t\t\t\t\t\t\tfailAndReset(protocolFailure(\"Windows shell engine emitted trailing control bytes.\"));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontrolFrame = parsed.frame;\n\t\t\t\t\t\tmaybeComplete();\n\t\t\t\t\t},\n\t\t\t\t\tonChildClose: (code) => {\n\t\t\t\t\t\tconst capturedOutput = capturedControl();\n\t\t\t\t\t\temitPending(pendingOutput.length);\n\t\t\t\t\t\tsettle(() =>\n\t\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t\tnew WindowsShellEngineFailure(\n\t\t\t\t\t\t\t\t\t`Windows shell engine coordinator exited (${code ?? \"null\"}) before a complete terminal handoff.\\n${capturedOutput}`,\n\t\t\t\t\t\t\t\t\tcapturedOutput,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\tfail: (error) => failAndReset(error),\n\t\t\t\t};\n\n\t\t\t\tthis.activeExec = active;\n\t\t\t\tif (signal) signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutTimer = setTimeout(() => failAndReset(new Error(`timeout:${timeout}`)), timeoutMs);\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tchild.stdin?.write(`${JSON.stringify(request)}\\n`, \"utf8\", (error) => {\n\t\t\t\t\t\tif (!error) return;\n\t\t\t\t\t\tfailAndReset(new Error(`Failed to write to Windows shell engine coordinator: ${error.message}`));\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\t\tfailAndReset(new Error(`Failed to write to Windows shell engine coordinator: ${message}`));\n\t\t\t\t}\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.coordinator.setLoopRef(false);\n\t\t}\n\t}\n\n\tprivate async ensureChild(env: NodeJS.ProcessEnv): Promise<ChildProcess> {\n\t\tif (this.coordinator.child) return this.coordinator.child;\n\t\tconst runtime = await this.resolveRuntime();\n\t\tif (runtime.status !== \"ready\") throw degradationError(runtime);\n\t\tif (this.disposed) throw new Error(`Windows shell engine session \"${this.key}\" is disposed`);\n\n\t\tconst child = this.spawn(runtime.pythonPath, [\"-B\", this.engineScriptPath, \"--server\"], {\n\t\t\tcwd: dirname(this.engineScriptPath),\n\t\t\tenv: {\n\t\t\t\t...env,\n\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t},\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\twindowsHide: true,\n\t\t});\n\t\tthis.coordinator.attach(child, {\n\t\t\tonStdout: (data) => {\n\t\t\t\tconst active = this.activeExec;\n\t\t\t\tif (active) active.onStdout(data);\n\t\t\t\telse if (data.length > 0) this.killChild();\n\t\t\t},\n\t\t\tonStderr: (data) => {\n\t\t\t\tconst active = this.activeExec;\n\t\t\t\tif (active) active.onStderr(data);\n\t\t\t\telse if (data.length > 0) this.killChild();\n\t\t\t},\n\t\t\tonError: (error) => this.activeExec?.fail(error),\n\t\t\tonClose: (code) => this.activeExec?.onChildClose(code),\n\t\t});\n\t\treturn child;\n\t}\n\n\tprivate killChild(): void {\n\t\tthis.coordinator.kill();\n\t}\n}\n\nconst engineSessions = new Map<string, PersistentWindowsShellEngineSession>();\n\nfunction acquireWindowsShellEngineSession(\n\tkey: string,\n\toptions: WindowsShellEngineOptions,\n): PersistentWindowsShellEngineSession {\n\tconst existing = engineSessions.get(key);\n\tif (existing) return existing;\n\tconst session = new PersistentWindowsShellEngineSession(key, options);\n\tengineSessions.set(key, session);\n\treturn session;\n}\n\n/** Kill and forget a Python coordinator. The next call for this key starts a clean process. */\nexport function disposeWindowsShellEngineSession(key: string): void {\n\tconst session = engineSessions.get(key);\n\tif (!session) return;\n\tengineSessions.delete(key);\n\tsession.dispose();\n}\n\n/** Create the Python-engine tier for one bash-tool session. */\nexport function createWindowsShellEngineOperations(\n\tsessionKey: string,\n\toptions: WindowsShellEngineOptions = {},\n): BashOperations {\n\treturn {\n\t\t// Resolve through the registry for every command. Session teardown (for example after\n\t\t// credential/environment changes) deletes only this tenant's entry; an already-built tool\n\t\t// then lazily acquires a fresh coordinator instead of retaining the disposed instance.\n\t\texec: (command, cwd, execOptions) =>\n\t\t\tacquireWindowsShellEngineSession(sessionKey, options).exec(command, cwd, execOptions),\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-shell-state.d.ts","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC;AAED,
|
|
1
|
+
{"version":3,"file":"windows-shell-state.d.ts","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC;AAED,2FAA2F;AAC3F,MAAM,WAAW,gBAAgB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC;AAID,oEAAoE;AACpE,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAOlF;AAED,4FAA4F;AAC5F,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAKxF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAM1F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAOzG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-shell-state.js","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEhE,oEAAoE;AACpE,MAAM,UAAU,4BAA4B,CAAC,UAAkB
|
|
1
|
+
{"version":3,"file":"windows-shell-state.js","sourceRoot":"","sources":["../../../src/core/tools/windows-shell-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEhE,oEAAoE;AACpE,MAAM,UAAU,4BAA4B,CAAC,UAAkB;IAC9D,IAAI,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,KAAK,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QAClC,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IAC1D,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAwB,EAAE,KAAuB;IACjF,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC7B,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAwB,EAAE,YAAoB;IACjF,IAAI,KAAK,CAAC,OAAO,KAAK,YAAY,EAAE,CAAC;QACpC,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC;QAC7B,KAAK,CAAC,GAAG,GAAG,YAAY,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAwB,EAAE,OAA0B;IACrF,MAAM,MAAM,GAAsB,EAAE,GAAG,OAAO,EAAE,CAAC;IACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * Per-session Windows shell-engine state (D4 — the engine is the sole state mutator).\n *\n * `cwd`/`envDelta` are threaded into every `python-engine` invocation and updated from the\n * engine's control frame after each run; the PS tier consumes the same state through the\n * EXISTING `shell-session.ts` seams (`lastRequestedCwd` re-entry, `shallowEnvEquals` respawn).\n * This module owns no process/spawn logic — it is pure state carriage.\n */\n\nexport interface WindowsShellState {\n\tcwd: string;\n\t/** Host-requested cwd used to detect an intentional caller cwd change. */\n\thostCwd?: string;\n\tenvDelta: Record<string, string | null>;\n}\n\n/** The engine control-frame shape this module consumes (subset of the full §1.3 frame). */\nexport interface EngineFrameState {\n\tcwd: string;\n\tenvDelta: Record<string, string | null>;\n}\n\nconst windowsShellStates = new Map<string, WindowsShellState>();\n\n/** Get or lazily create the per-session-key Windows shell state. */\nexport function getOrCreateWindowsShellState(sessionKey: string): WindowsShellState {\n\tlet state = windowsShellStates.get(sessionKey);\n\tif (!state) {\n\t\tstate = { cwd: \"\", envDelta: {} };\n\t\twindowsShellStates.set(sessionKey, state);\n\t}\n\treturn state;\n}\n\n/** Drop a session's engine state (agent teardown). Safe to call for keys that never ran. */\nexport function disposeWindowsShellState(sessionKey: string): void {\n\twindowsShellStates.delete(sessionKey);\n}\n\n/**\n * Fold an engine control frame into the session state: `cwd` is set verbatim; `envDelta` entries\n * apply string => set, `null` => delete (§1.3).\n */\nexport function applyEngineFrame(state: WindowsShellState, frame: EngineFrameState): void {\n\tstate.cwd = frame.cwd;\n\tfor (const [key, value] of Object.entries(frame.envDelta)) {\n\t\tstate.envDelta[key] = value;\n\t}\n}\n\n/**\n * The cwd a NEXT call (engine or PS tier) must use: the state-adjusted cwd once the engine has run\n * at least one `cd`, otherwise the host-requested cwd. Both tiers call this with the SAME session\n * state so a `cd` in the engine is observed by the very next PS-tier call.\n */\nexport function resolveEffectiveCwd(state: WindowsShellState, requestedCwd: string): string {\n\tif (state.hostCwd !== requestedCwd) {\n\t\tstate.hostCwd = requestedCwd;\n\t\tstate.cwd = requestedCwd;\n\t}\n\treturn state.cwd;\n}\n\n/**\n * The env a NEXT call (engine or PS tier) must use: the base env plus every `export`/`unset` the\n * engine has applied so far.\n */\nexport function mergeEffectiveEnv(state: WindowsShellState, baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n\tconst merged: NodeJS.ProcessEnv = { ...baseEnv };\n\tfor (const [key, value] of Object.entries(state.envDelta)) {\n\t\tif (value === null) delete merged[key];\n\t\telse merged[key] = value;\n\t}\n\treturn merged;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-sync.d.ts","sourceRoot":"","sources":["../../../src/core/tools/worktree-sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAUN,KAAK,sBAAsB,EAC3B,MAAM,gCAAgC,CAAC;AA8DxC,QAAA,MAAM,kBAAkB;;;;;;;;EAA6B,CAAC;AAEtD,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACpC,UAAU,EAAE,MAAM,sBAAsB,CAAC;IACzC,QAAQ,EAAE,MAAM,4BAA4B,CAAC;IAC7C,YAAY,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACvC,mGAAmG;IACnG,QAAQ,EAAE,MAAM,OAAO,CAAC;CACxB;AAgED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,oBAAoB,GAAG,cAAc,CAiQ3F","sourcesContent":["import { isAbsolute, relative } from \"node:path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { ResolvedWorktreeSyncSettings } from \"../settings-manager.ts\";\nimport type { ConflictWorklist, SyncStatus } from \"../worktree-sync/codes.ts\";\nimport {\n\tabortSync,\n\tbuildSyncStatus,\n\tcontinueSync,\n\tcreateLane,\n\tlandLane,\n\treconcile,\n\treleaseLane,\n\tresolveRepoContext,\n\tsyncLane,\n\ttype WorktreeSyncEngineDeps,\n} from \"../worktree-sync/git-engine.ts\";\nimport { resolveLaneMutationPath } from \"../worktree-sync/lane-gate.ts\";\nimport { readLane } from \"../worktree-sync/store.ts\";\n\n/**\n * `worktree_sync` -- the ENTIRE agent-facing surface of the worktree-per-lane workflow: a closed\n * action set over the engine (`core/worktree-sync/git-engine.ts`) so agents never improvise git\n * ceremony. Every outcome carries a tagged code in `details`; refusal text always names the exact\n * recovery step. See docs/worktree-sync.md for the workflow and the G1-G11 gate table.\n */\n\nfunction createWorktreeSyncSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Union(\n\t\t\t\t[\n\t\t\t\t\tType.Literal(\"status\"),\n\t\t\t\t\tType.Literal(\"git_status\"),\n\t\t\t\t\tType.Literal(\"git_diff\"),\n\t\t\t\t\tType.Literal(\"git_add\"),\n\t\t\t\t\tType.Literal(\"git_commit\"),\n\t\t\t\t\tType.Literal(\"check\"),\n\t\t\t\t\tType.Literal(\"create_lane\"),\n\t\t\t\t\tType.Literal(\"sync\"),\n\t\t\t\t\tType.Literal(\"continue\"),\n\t\t\t\t\tType.Literal(\"abort_sync\"),\n\t\t\t\t\tType.Literal(\"land\"),\n\t\t\t\t\tType.Literal(\"release_lane\"),\n\t\t\t\t\tType.Literal(\"reconcile\"),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"status: the deterministic full picture (epoch, hub, lock, per-lane freshness/staleness, advice). git_status/git_diff: read the bound lane with fixed argv. git_add: stage only explicitly validated paths inside the lane. git_commit: commit with a literal message. check: run only the owner-configured trusted check command. create_lane: new worktree+branch off main. sync: rebase current main into a lane (conflicts return a worklist and leave the rebase in progress). continue: verify resolved conflicts (zero markers, mechanically checked), stage, drive on. abort_sync: abort the in-progress rebase. land: the ONLY door to main -- serialized, freshness-checked, gate-command-verified, ff-only. release_lane: remove a fully-landed lane (discarding unlanded work needs confirm). reconcile: re-sync the registry with git reality.\",\n\t\t\t\t},\n\t\t\t),\n\t\t\tlaneKey: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Target lane. Defaults to this session's bound lane (PI_WORKTREE_LANE) for sync/continue/abort_sync/land.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tgoalId: Type.Optional(\n\t\t\t\tType.String({ description: \"create_lane: goal to scope the auto-allocated lane key by.\" }),\n\t\t\t),\n\t\t\trequirementId: Type.Optional(Type.String({ description: \"create_lane: requirement this lane will work.\" })),\n\t\t\tpaths: Type.Optional(\n\t\t\t\tType.Array(Type.String(), {\n\t\t\t\t\tdescription: \"git_diff/git_add: explicit relative paths inside the bound lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(Type.String({ description: \"git_commit: literal commit message.\" })),\n\t\t\tconfirm: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'release_lane: pass exactly \"yes-discard-lane\" to release a lane that still has unlanded commits or dirty files (G11: never silent).',\n\t\t\t\t}),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst worktreeSyncSchema = createWorktreeSyncSchema();\n\nexport type WorktreeSyncToolInput = Static<typeof worktreeSyncSchema>;\n\nexport interface WorktreeSyncToolDeps {\n\tengineDeps: () => WorktreeSyncEngineDeps;\n\tsettings: () => ResolvedWorktreeSyncSettings;\n\tboundLaneKey: () => string | undefined;\n\t/** True iff this is a worker session (see session-role.ts) -- narrows the action surface below. */\n\tisWorker: () => boolean;\n}\n\n/** Actions a worker session may run unconditionally -- read-only status plus the sync/conflict\n * cycle on its own bound lane. Everything else is refused as `role_forbidden`, EXCEPT `land`,\n * which is instead gated by the `worktreeSync.workerLand` setting (still subject to normal\n * ownership/freshness gating downstream when allowed). */\nconst WORKER_ALLOWED_ACTIONS: ReadonlySet<WorktreeSyncToolInput[\"action\"]> = new Set([\n\t\"status\",\n\t\"git_status\",\n\t\"git_diff\",\n\t\"git_add\",\n\t\"git_commit\",\n\t\"check\",\n\t\"sync\",\n\t\"continue\",\n\t\"abort_sync\",\n]);\n\nfunction formatWorklist(worklist: ConflictWorklist): string[] {\n\tconst lines = [\n\t\t`Conflicts at rebase step ${worklist.step}${worklist.stoppedAtCommit ? ` (replaying ${worklist.stoppedAtCommit.sha.slice(0, 12)}: ${worklist.stoppedAtCommit.subject})` : \"\"}:`,\n\t];\n\tfor (const file of worklist.files) {\n\t\tlines.push(`- ${file.path} [${file.kind}]`);\n\t}\n\tlines.push(\n\t\t'Resolve the zdiff3 hunks in exactly these files (base section included), save, then call {\"action\":\"continue\"}. Staging and marker verification are automatic.',\n\t);\n\treturn lines;\n}\n\nfunction formatStatus(status: SyncStatus): string[] {\n\tconst lines = [\n\t\t`epoch ${status.epoch} | main ${status.mainBranch}@${status.mainSha.slice(0, 12)}` +\n\t\t\t`${status.hub ? ` | hub ${status.hub.clean ? \"clean\" : \"has local changes\"}` : \" | hub: main not checked out\"}` +\n\t\t\t`${status.lock.held ? ` | LOCK held by pid ${status.lock.holder?.pid ?? \"?\"}` : \"\"}`,\n\t];\n\tfor (const lane of status.lanes) {\n\t\tconst flags = [\n\t\t\tlane.registrationStatus !== \"active\" ? lane.registrationStatus : undefined,\n\t\t\tlane.rebaseInProgress ? \"REBASE-IN-PROGRESS\" : undefined,\n\t\t\tlane.syncRequired ? \"SYNC-REQUIRED\" : lane.stale ? \"stale\" : \"fresh\",\n\t\t\tlane.dirty ? \"dirty\" : undefined,\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\", \");\n\t\tlines.push(\n\t\t\t`- ${lane.laneKey} (${lane.branch}) +${lane.aheadOfMain}/-${lane.behindMain} [${flags}]` +\n\t\t\t\t`${lane.overlapWithLastLand.length > 0 ? ` overlap: ${lane.overlapWithLastLand.slice(0, 5).join(\", \")}` : \"\"}`,\n\t\t);\n\t}\n\tif (status.lanes.length === 0) lines.push(\"(no lanes)\");\n\tif (status.advice) lines.push(`advice: ${status.advice}`);\n\treturn lines;\n}\n\nconst WORKTREE_SYNC_PROMPT_GUIDELINES = [\n\t\"Work ONLY inside your lane worktree on your lane branch; never edit the hub checkout or touch main directly -- main moves exclusively through the land action.\",\n\t\"Commit your work on the lane branch, then land. Landing is refused while the lane is stale (G3): call sync first, resolve conflicts locally, then land.\",\n\t\"When a sync stops on conflicts, edit exactly the listed files, then call continue -- staging, marker verification, and rebase continuation are mechanical.\",\n\t\"After any other lane lands, your lane becomes stale; under the mandatory policy your file mutations are refused until you sync. git add/commit stay available to save WIP first.\",\n\t\"Check status when unsure -- it is the deterministic full picture; never infer sync state from raw git output.\",\n];\n\nexport function createWorktreeSyncToolDefinition(deps: WorktreeSyncToolDeps): ToolDefinition {\n\treturn {\n\t\tname: \"worktree_sync\",\n\t\tlabel: \"worktree_sync\",\n\t\tdescription:\n\t\t\t\"Hard-gated worktree-per-lane parallel work: each agent works in its own git worktree/branch; integration is always rebase-onto-main + ff-only land, serialized under one integration lock with the gate command verified at the exact landing tip. status/create_lane/sync/continue/abort_sync/land/release_lane/reconcile. Every outcome is a tagged code with the exact recovery step; landing while stale is structurally impossible.\",\n\t\tpromptSnippet: \"Coordinate parallel work: lane worktrees, rebase-onto-main sync, serialized gated landing.\",\n\t\tpromptGuidelines: WORKTREE_SYNC_PROMPT_GUIDELINES,\n\t\tparameters: worktreeSyncSchema,\n\t\texecutionMode: \"sequential\",\n\t\tasync execute(_toolCallId, input: WorktreeSyncToolInput, signal) {\n\t\t\tconst engineDeps: WorktreeSyncEngineDeps = { ...deps.engineDeps(), ...(signal ? { signal } : {}) };\n\t\t\tconst settings = deps.settings();\n\t\t\tconst laneKey = input.laneKey ?? deps.boundLaneKey();\n\n\t\t\tconst respond = (lines: string[], details: unknown) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: details as Record<string, unknown>,\n\t\t\t});\n\t\t\tconst needLane = (): string | undefined => {\n\t\t\t\tif (laneKey) return undefined;\n\t\t\t\treturn \"laneKey required: pass laneKey, or run inside a lane-bound session (PI_WORKTREE_LANE).\";\n\t\t\t};\n\n\t\t\tconst runTypedLaneAction = async (): Promise<ReturnType<typeof respond>> => {\n\t\t\t\tconst missingLane = needLane();\n\t\t\t\tif (missingLane) return respond([missingLane], { code: \"lane_not_found\", message: missingLane });\n\t\t\t\tconst context = await resolveRepoContext(engineDeps);\n\t\t\t\tif (\"code\" in context) return respond([`[${context.code}] ${context.message}`], context);\n\t\t\t\tconst lane = await readLane(context.paths, laneKey!);\n\t\t\t\tif (!lane || lane.status !== \"active\") {\n\t\t\t\t\tconst message = `active lane '${laneKey}' is not available`;\n\t\t\t\t\treturn respond([`[lane_not_found] ${message}`], { code: \"lane_not_found\", message });\n\t\t\t\t}\n\n\t\t\t\tconst requestedPaths = input.paths ?? [];\n\t\t\t\tconst gitPaths: string[] = [];\n\t\t\t\tfor (const requestedPath of requestedPaths) {\n\t\t\t\t\tif (!requestedPath || isAbsolute(requestedPath) || requestedPath.includes(\"\\0\")) {\n\t\t\t\t\t\tconst message = \"git path must be a non-empty relative path without NUL\";\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tconst resolved = resolveLaneMutationPath(lane.worktreePath, requestedPath);\n\t\t\t\t\tif (!resolved) {\n\t\t\t\t\t\tconst message = `path '${requestedPath}' escapes the lane worktree`;\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tgitPaths.push(relative(lane.worktreePath, resolved) || \".\");\n\t\t\t\t}\n\n\t\t\t\tlet command: string;\n\t\t\t\tlet args: string[];\n\t\t\t\tswitch (input.action) {\n\t\t\t\t\tcase \"git_status\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"status\", \"--short\", \"--branch\"];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_diff\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"diff\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_add\":\n\t\t\t\t\t\tif (gitPaths.length === 0) {\n\t\t\t\t\t\t\tconst message = \"git_add requires one or more explicit in-lane paths\";\n\t\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"add\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_commit\":\n\t\t\t\t\t\tif (!input.message?.trim() || input.message.includes(\"\\0\")) {\n\t\t\t\t\t\t\tconst message = \"git_commit requires a non-empty literal message\";\n\t\t\t\t\t\t\treturn respond([`[git_failed] ${message}`], { code: \"git_failed\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"commit\", \"-m\", input.message];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"check\": {\n\t\t\t\t\t\tconst trustedCommand = settings.gateCommand?.trim();\n\t\t\t\t\t\tif (!trustedCommand) {\n\t\t\t\t\t\t\tconst message = \"no trusted worktree check is configured\";\n\t\t\t\t\t\t\treturn respond([`[gate_command_unset] ${message}`], { code: \"gate_command_unset\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst shell = process.platform === \"win32\" ? \"cmd\" : \"sh\";\n\t\t\t\t\t\tconst shellFlag = process.platform === \"win32\" ? \"/c\" : \"-c\";\n\t\t\t\t\t\tconst result = await engineDeps.exec(shell, [shellFlag, trustedCommand], {\n\t\t\t\t\t\t\tcwd: lane.worktreePath,\n\t\t\t\t\t\t\ttimeout: 900_000,\n\t\t\t\t\t\t\tsignal: engineDeps.signal,\n\t\t\t\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\t\t\treturn respond([`[gate_failed] ${output || `trusted check exited ${result.code}`}`], {\n\t\t\t\t\t\t\t\tcode: \"gate_failed\",\n\t\t\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn respond([output || \"trusted check passed\"], { code: \"ok\", action: input.action });\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn respond([\"typed lane action is unavailable for this request\"], { code: \"role_forbidden\" });\n\t\t\t\t}\n\n\t\t\t\tconst result = await engineDeps.exec(command, args, {\n\t\t\t\t\tcwd: lane.worktreePath,\n\t\t\t\t\ttimeout: 60_000,\n\t\t\t\t\tsignal: engineDeps.signal,\n\t\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t\t});\n\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\treturn respond([`[git_failed] ${output || `${command} exited ${result.code}`}`], {\n\t\t\t\t\t\tcode: \"git_failed\",\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn respond([output || `${input.action} completed`], { code: \"ok\", action: input.action });\n\t\t\t};\n\n\t\t\tif (deps.isWorker()) {\n\t\t\t\tconst bound = deps.boundLaneKey();\n\t\t\t\tif (input.laneKey !== undefined && input.laneKey !== bound) {\n\t\t\t\t\tconst message = \"workers may only target their bound lane\";\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t\tconst landAllowed = input.action === \"land\" && settings.workerLand === \"allow\";\n\t\t\t\tif (!WORKER_ALLOWED_ACTIONS.has(input.action) && !landAllowed) {\n\t\t\t\t\tconst message =\n\t\t\t\t\t\tinput.action === \"land\"\n\t\t\t\t\t\t\t? 'workers may not land (worktreeSync.workerLand is \"deny\")'\n\t\t\t\t\t\t\t: `workers may not run action \"${input.action}\"`;\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (input.action) {\n\t\t\t\tcase \"git_status\":\n\t\t\t\tcase \"git_diff\":\n\t\t\t\tcase \"git_add\":\n\t\t\t\tcase \"git_commit\":\n\t\t\t\tcase \"check\":\n\t\t\t\t\treturn runTypedLaneAction();\n\t\t\t\tcase \"status\": {\n\t\t\t\t\tconst status = await buildSyncStatus(engineDeps, { policy: settings.syncPolicy });\n\t\t\t\t\tif (status.code !== \"ok\") return respond([`[${status.code}] ${status.message}`], status);\n\t\t\t\t\treturn respond(formatStatus(status), status);\n\t\t\t\t}\n\t\t\t\tcase \"create_lane\": {\n\t\t\t\t\tconst created = await createLane(engineDeps, {\n\t\t\t\t\t\t...(input.laneKey !== undefined ? { laneKey: input.laneKey } : {}),\n\t\t\t\t\t\t...(input.goalId !== undefined ? { goalId: input.goalId } : {}),\n\t\t\t\t\t\t...(input.requirementId !== undefined ? { requirementId: input.requirementId } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (created.code !== \"ok\") return respond([`[${created.code}] ${created.message}`], created);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${created.lane.laneKey}' created: branch ${created.lane.branch}, checkout ${created.lane.worktreePath}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcreated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst synced = await syncLane(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (synced.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tsynced.alreadyFresh\n\t\t\t\t\t\t\t\t\t? `lane '${synced.laneKey}' already contains current main -- nothing to do`\n\t\t\t\t\t\t\t\t\t: `lane '${synced.laneKey}' rebased onto current main (auto-continued ${synced.autoContinued} step(s))`,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tsynced,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (synced.code === \"sync_conflicts\") return respond(formatWorklist(synced.worklist), synced);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`[${synced.code}] ${synced.message}${synced.paths ? `\\n${synced.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\tsynced,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"continue\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst continued = await continueSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (continued.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`lane '${continued.laneKey}' rebase completed -- lane is fresh relative to the synced main`],\n\t\t\t\t\t\t\tcontinued,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (continued.code === \"sync_conflicts\") return respond(formatWorklist(continued.worklist), continued);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`[${continued.code}] ${continued.message}${continued.paths ? `\\n${continued.paths.join(\"\\n\")}` : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcontinued,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"abort_sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst aborted = await abortSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (aborted.code !== \"ok\") return respond([`[${aborted.code}] ${aborted.message}`], aborted);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`lane '${aborted.laneKey}' rebase aborted -- back to its pre-sync tip (still stale)`],\n\t\t\t\t\t\taborted,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"land\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst landed = await landLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\tgate: settings.gate,\n\t\t\t\t\t\t...(settings.gateCommand !== undefined ? { gateCommand: settings.gateCommand } : {}),\n\t\t\t\t\t\tgateTimeoutMs: settings.gateTimeoutMs,\n\t\t\t\t\t});\n\t\t\t\t\tif (landed.code !== \"ok\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`[${landed.code}] ${landed.message}${landed.paths ? `\\n${landed.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\t\tlanded,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${landed.laneKey}' LANDED: epoch ${landed.epoch}, main is now ${landed.mainSha.slice(0, 12)} (gate: ${landed.gate}). All other lanes must sync before their next land.`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tlanded,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"release_lane\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst released = await releaseLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\t...(input.confirm !== undefined ? { confirm: input.confirm } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (released.code !== \"released\") return respond([`[${released.code}] ${released.message}`], released);\n\t\t\t\t\treturn respond([`lane '${released.laneKey}' released`], released);\n\t\t\t\t}\n\t\t\t\tcase \"reconcile\": {\n\t\t\t\t\tconst reconciled = await reconcile(engineDeps);\n\t\t\t\t\tif (reconciled.code !== \"reconciled\")\n\t\t\t\t\t\treturn respond([`[${reconciled.code}] ${reconciled.message}`], reconciled);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`reconciled: ${reconciled.orphanedLaneKeys.length} orphaned, ${reconciled.reRegisteredLaneKeys.length} re-registered, ${reconciled.ownerClearedLaneKeys.length} owners cleared${reconciled.staleLockReleased ? \", stale lock released\" : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\treconciled,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worktree-sync.d.ts","sourceRoot":"","sources":["../../../src/core/tools/worktree-sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAUN,KAAK,sBAAsB,EAC3B,MAAM,gCAAgC,CAAC;AA8DxC,QAAA,MAAM,kBAAkB;;;;;;;;EAA6B,CAAC;AAEtD,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACpC,UAAU,EAAE,MAAM,sBAAsB,CAAC;IACzC,QAAQ,EAAE,MAAM,4BAA4B,CAAC;IAC7C,YAAY,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACvC,mGAAmG;IACnG,QAAQ,EAAE,MAAM,OAAO,CAAC;CACxB;AAgED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,oBAAoB,GAAG,cAAc,CA8P3F"}
|
|
@@ -133,6 +133,12 @@ export function createWorktreeSyncToolDefinition(deps) {
|
|
|
133
133
|
const message = `active lane '${laneKey}' is not available`;
|
|
134
134
|
return respond([`[lane_not_found] ${message}`], { code: "lane_not_found", message });
|
|
135
135
|
}
|
|
136
|
+
const execInLane = (command, args, timeout) => engineDeps.exec(command, args, {
|
|
137
|
+
cwd: lane.worktreePath,
|
|
138
|
+
timeout,
|
|
139
|
+
signal: engineDeps.signal,
|
|
140
|
+
maxBuffer: 1024 * 1024,
|
|
141
|
+
});
|
|
136
142
|
const requestedPaths = input.paths ?? [];
|
|
137
143
|
const gitPaths = [];
|
|
138
144
|
for (const requestedPath of requestedPaths) {
|
|
@@ -182,12 +188,7 @@ export function createWorktreeSyncToolDefinition(deps) {
|
|
|
182
188
|
}
|
|
183
189
|
const shell = process.platform === "win32" ? "cmd" : "sh";
|
|
184
190
|
const shellFlag = process.platform === "win32" ? "/c" : "-c";
|
|
185
|
-
const result = await
|
|
186
|
-
cwd: lane.worktreePath,
|
|
187
|
-
timeout: 900_000,
|
|
188
|
-
signal: engineDeps.signal,
|
|
189
|
-
maxBuffer: 1024 * 1024,
|
|
190
|
-
});
|
|
191
|
+
const result = await execInLane(shell, [shellFlag, trustedCommand], 900_000);
|
|
191
192
|
const output = `${result.stdout}\n${result.stderr}`.trim().slice(-8000);
|
|
192
193
|
if (result.code !== 0) {
|
|
193
194
|
return respond([`[gate_failed] ${output || `trusted check exited ${result.code}`}`], {
|
|
@@ -200,12 +201,7 @@ export function createWorktreeSyncToolDefinition(deps) {
|
|
|
200
201
|
default:
|
|
201
202
|
return respond(["typed lane action is unavailable for this request"], { code: "role_forbidden" });
|
|
202
203
|
}
|
|
203
|
-
const result = await
|
|
204
|
-
cwd: lane.worktreePath,
|
|
205
|
-
timeout: 60_000,
|
|
206
|
-
signal: engineDeps.signal,
|
|
207
|
-
maxBuffer: 1024 * 1024,
|
|
208
|
-
});
|
|
204
|
+
const result = await execInLane(command, args, 60_000);
|
|
209
205
|
const output = `${result.stdout}\n${result.stderr}`.trim().slice(-8000);
|
|
210
206
|
if (result.code !== 0) {
|
|
211
207
|
return respond([`[git_failed] ${output || `${command} exited ${result.code}`}`], {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-sync.js","sourceRoot":"","sources":["../../../src/core/tools/worktree-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,QAAQ,GAER,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,C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YACF,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["import { isAbsolute, relative } from \"node:path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { ResolvedWorktreeSyncSettings } from \"../settings-manager.ts\";\nimport type { ConflictWorklist, SyncStatus } from \"../worktree-sync/codes.ts\";\nimport {\n\tabortSync,\n\tbuildSyncStatus,\n\tcontinueSync,\n\tcreateLane,\n\tlandLane,\n\treconcile,\n\treleaseLane,\n\tresolveRepoContext,\n\tsyncLane,\n\ttype WorktreeSyncEngineDeps,\n} from \"../worktree-sync/git-engine.ts\";\nimport { resolveLaneMutationPath } from \"../worktree-sync/lane-gate.ts\";\nimport { readLane } from \"../worktree-sync/store.ts\";\n\n/**\n * `worktree_sync` -- the ENTIRE agent-facing surface of the worktree-per-lane workflow: a closed\n * action set over the engine (`core/worktree-sync/git-engine.ts`) so agents never improvise git\n * ceremony. Every outcome carries a tagged code in `details`; refusal text always names the exact\n * recovery step. See docs/worktree-sync.md for the workflow and the G1-G11 gate table.\n */\n\nfunction createWorktreeSyncSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Union(\n\t\t\t\t[\n\t\t\t\t\tType.Literal(\"status\"),\n\t\t\t\t\tType.Literal(\"git_status\"),\n\t\t\t\t\tType.Literal(\"git_diff\"),\n\t\t\t\t\tType.Literal(\"git_add\"),\n\t\t\t\t\tType.Literal(\"git_commit\"),\n\t\t\t\t\tType.Literal(\"check\"),\n\t\t\t\t\tType.Literal(\"create_lane\"),\n\t\t\t\t\tType.Literal(\"sync\"),\n\t\t\t\t\tType.Literal(\"continue\"),\n\t\t\t\t\tType.Literal(\"abort_sync\"),\n\t\t\t\t\tType.Literal(\"land\"),\n\t\t\t\t\tType.Literal(\"release_lane\"),\n\t\t\t\t\tType.Literal(\"reconcile\"),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"status: the deterministic full picture (epoch, hub, lock, per-lane freshness/staleness, advice). git_status/git_diff: read the bound lane with fixed argv. git_add: stage only explicitly validated paths inside the lane. git_commit: commit with a literal message. check: run only the owner-configured trusted check command. create_lane: new worktree+branch off main. sync: rebase current main into a lane (conflicts return a worklist and leave the rebase in progress). continue: verify resolved conflicts (zero markers, mechanically checked), stage, drive on. abort_sync: abort the in-progress rebase. land: the ONLY door to main -- serialized, freshness-checked, gate-command-verified, ff-only. release_lane: remove a fully-landed lane (discarding unlanded work needs confirm). reconcile: re-sync the registry with git reality.\",\n\t\t\t\t},\n\t\t\t),\n\t\t\tlaneKey: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Target lane. Defaults to this session's bound lane (PI_WORKTREE_LANE) for sync/continue/abort_sync/land.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tgoalId: Type.Optional(\n\t\t\t\tType.String({ description: \"create_lane: goal to scope the auto-allocated lane key by.\" }),\n\t\t\t),\n\t\t\trequirementId: Type.Optional(Type.String({ description: \"create_lane: requirement this lane will work.\" })),\n\t\t\tpaths: Type.Optional(\n\t\t\t\tType.Array(Type.String(), {\n\t\t\t\t\tdescription: \"git_diff/git_add: explicit relative paths inside the bound lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(Type.String({ description: \"git_commit: literal commit message.\" })),\n\t\t\tconfirm: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'release_lane: pass exactly \"yes-discard-lane\" to release a lane that still has unlanded commits or dirty files (G11: never silent).',\n\t\t\t\t}),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst worktreeSyncSchema = createWorktreeSyncSchema();\n\nexport type WorktreeSyncToolInput = Static<typeof worktreeSyncSchema>;\n\nexport interface WorktreeSyncToolDeps {\n\tengineDeps: () => WorktreeSyncEngineDeps;\n\tsettings: () => ResolvedWorktreeSyncSettings;\n\tboundLaneKey: () => string | undefined;\n\t/** True iff this is a worker session (see session-role.ts) -- narrows the action surface below. */\n\tisWorker: () => boolean;\n}\n\n/** Actions a worker session may run unconditionally -- read-only status plus the sync/conflict\n * cycle on its own bound lane. Everything else is refused as `role_forbidden`, EXCEPT `land`,\n * which is instead gated by the `worktreeSync.workerLand` setting (still subject to normal\n * ownership/freshness gating downstream when allowed). */\nconst WORKER_ALLOWED_ACTIONS: ReadonlySet<WorktreeSyncToolInput[\"action\"]> = new Set([\n\t\"status\",\n\t\"git_status\",\n\t\"git_diff\",\n\t\"git_add\",\n\t\"git_commit\",\n\t\"check\",\n\t\"sync\",\n\t\"continue\",\n\t\"abort_sync\",\n]);\n\nfunction formatWorklist(worklist: ConflictWorklist): string[] {\n\tconst lines = [\n\t\t`Conflicts at rebase step ${worklist.step}${worklist.stoppedAtCommit ? ` (replaying ${worklist.stoppedAtCommit.sha.slice(0, 12)}: ${worklist.stoppedAtCommit.subject})` : \"\"}:`,\n\t];\n\tfor (const file of worklist.files) {\n\t\tlines.push(`- ${file.path} [${file.kind}]`);\n\t}\n\tlines.push(\n\t\t'Resolve the zdiff3 hunks in exactly these files (base section included), save, then call {\"action\":\"continue\"}. Staging and marker verification are automatic.',\n\t);\n\treturn lines;\n}\n\nfunction formatStatus(status: SyncStatus): string[] {\n\tconst lines = [\n\t\t`epoch ${status.epoch} | main ${status.mainBranch}@${status.mainSha.slice(0, 12)}` +\n\t\t\t`${status.hub ? ` | hub ${status.hub.clean ? \"clean\" : \"has local changes\"}` : \" | hub: main not checked out\"}` +\n\t\t\t`${status.lock.held ? ` | LOCK held by pid ${status.lock.holder?.pid ?? \"?\"}` : \"\"}`,\n\t];\n\tfor (const lane of status.lanes) {\n\t\tconst flags = [\n\t\t\tlane.registrationStatus !== \"active\" ? lane.registrationStatus : undefined,\n\t\t\tlane.rebaseInProgress ? \"REBASE-IN-PROGRESS\" : undefined,\n\t\t\tlane.syncRequired ? \"SYNC-REQUIRED\" : lane.stale ? \"stale\" : \"fresh\",\n\t\t\tlane.dirty ? \"dirty\" : undefined,\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\", \");\n\t\tlines.push(\n\t\t\t`- ${lane.laneKey} (${lane.branch}) +${lane.aheadOfMain}/-${lane.behindMain} [${flags}]` +\n\t\t\t\t`${lane.overlapWithLastLand.length > 0 ? ` overlap: ${lane.overlapWithLastLand.slice(0, 5).join(\", \")}` : \"\"}`,\n\t\t);\n\t}\n\tif (status.lanes.length === 0) lines.push(\"(no lanes)\");\n\tif (status.advice) lines.push(`advice: ${status.advice}`);\n\treturn lines;\n}\n\nconst WORKTREE_SYNC_PROMPT_GUIDELINES = [\n\t\"Work ONLY inside your lane worktree on your lane branch; never edit the hub checkout or touch main directly -- main moves exclusively through the land action.\",\n\t\"Commit your work on the lane branch, then land. Landing is refused while the lane is stale (G3): call sync first, resolve conflicts locally, then land.\",\n\t\"When a sync stops on conflicts, edit exactly the listed files, then call continue -- staging, marker verification, and rebase continuation are mechanical.\",\n\t\"After any other lane lands, your lane becomes stale; under the mandatory policy your file mutations are refused until you sync. git add/commit stay available to save WIP first.\",\n\t\"Check status when unsure -- it is the deterministic full picture; never infer sync state from raw git output.\",\n];\n\nexport function createWorktreeSyncToolDefinition(deps: WorktreeSyncToolDeps): ToolDefinition {\n\treturn {\n\t\tname: \"worktree_sync\",\n\t\tlabel: \"worktree_sync\",\n\t\tdescription:\n\t\t\t\"Hard-gated worktree-per-lane parallel work: each agent works in its own git worktree/branch; integration is always rebase-onto-main + ff-only land, serialized under one integration lock with the gate command verified at the exact landing tip. status/create_lane/sync/continue/abort_sync/land/release_lane/reconcile. Every outcome is a tagged code with the exact recovery step; landing while stale is structurally impossible.\",\n\t\tpromptSnippet: \"Coordinate parallel work: lane worktrees, rebase-onto-main sync, serialized gated landing.\",\n\t\tpromptGuidelines: WORKTREE_SYNC_PROMPT_GUIDELINES,\n\t\tparameters: worktreeSyncSchema,\n\t\texecutionMode: \"sequential\",\n\t\tasync execute(_toolCallId, input: WorktreeSyncToolInput, signal) {\n\t\t\tconst engineDeps: WorktreeSyncEngineDeps = { ...deps.engineDeps(), ...(signal ? { signal } : {}) };\n\t\t\tconst settings = deps.settings();\n\t\t\tconst laneKey = input.laneKey ?? deps.boundLaneKey();\n\n\t\t\tconst respond = (lines: string[], details: unknown) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: details as Record<string, unknown>,\n\t\t\t});\n\t\t\tconst needLane = (): string | undefined => {\n\t\t\t\tif (laneKey) return undefined;\n\t\t\t\treturn \"laneKey required: pass laneKey, or run inside a lane-bound session (PI_WORKTREE_LANE).\";\n\t\t\t};\n\n\t\t\tconst runTypedLaneAction = async (): Promise<ReturnType<typeof respond>> => {\n\t\t\t\tconst missingLane = needLane();\n\t\t\t\tif (missingLane) return respond([missingLane], { code: \"lane_not_found\", message: missingLane });\n\t\t\t\tconst context = await resolveRepoContext(engineDeps);\n\t\t\t\tif (\"code\" in context) return respond([`[${context.code}] ${context.message}`], context);\n\t\t\t\tconst lane = await readLane(context.paths, laneKey!);\n\t\t\t\tif (!lane || lane.status !== \"active\") {\n\t\t\t\t\tconst message = `active lane '${laneKey}' is not available`;\n\t\t\t\t\treturn respond([`[lane_not_found] ${message}`], { code: \"lane_not_found\", message });\n\t\t\t\t}\n\n\t\t\t\tconst requestedPaths = input.paths ?? [];\n\t\t\t\tconst gitPaths: string[] = [];\n\t\t\t\tfor (const requestedPath of requestedPaths) {\n\t\t\t\t\tif (!requestedPath || isAbsolute(requestedPath) || requestedPath.includes(\"\\0\")) {\n\t\t\t\t\t\tconst message = \"git path must be a non-empty relative path without NUL\";\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tconst resolved = resolveLaneMutationPath(lane.worktreePath, requestedPath);\n\t\t\t\t\tif (!resolved) {\n\t\t\t\t\t\tconst message = `path '${requestedPath}' escapes the lane worktree`;\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tgitPaths.push(relative(lane.worktreePath, resolved) || \".\");\n\t\t\t\t}\n\n\t\t\t\tlet command: string;\n\t\t\t\tlet args: string[];\n\t\t\t\tswitch (input.action) {\n\t\t\t\t\tcase \"git_status\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"status\", \"--short\", \"--branch\"];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_diff\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"diff\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_add\":\n\t\t\t\t\t\tif (gitPaths.length === 0) {\n\t\t\t\t\t\t\tconst message = \"git_add requires one or more explicit in-lane paths\";\n\t\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"add\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_commit\":\n\t\t\t\t\t\tif (!input.message?.trim() || input.message.includes(\"\\0\")) {\n\t\t\t\t\t\t\tconst message = \"git_commit requires a non-empty literal message\";\n\t\t\t\t\t\t\treturn respond([`[git_failed] ${message}`], { code: \"git_failed\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"commit\", \"-m\", input.message];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"check\": {\n\t\t\t\t\t\tconst trustedCommand = settings.gateCommand?.trim();\n\t\t\t\t\t\tif (!trustedCommand) {\n\t\t\t\t\t\t\tconst message = \"no trusted worktree check is configured\";\n\t\t\t\t\t\t\treturn respond([`[gate_command_unset] ${message}`], { code: \"gate_command_unset\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst shell = process.platform === \"win32\" ? \"cmd\" : \"sh\";\n\t\t\t\t\t\tconst shellFlag = process.platform === \"win32\" ? \"/c\" : \"-c\";\n\t\t\t\t\t\tconst result = await engineDeps.exec(shell, [shellFlag, trustedCommand], {\n\t\t\t\t\t\t\tcwd: lane.worktreePath,\n\t\t\t\t\t\t\ttimeout: 900_000,\n\t\t\t\t\t\t\tsignal: engineDeps.signal,\n\t\t\t\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\t\t\treturn respond([`[gate_failed] ${output || `trusted check exited ${result.code}`}`], {\n\t\t\t\t\t\t\t\tcode: \"gate_failed\",\n\t\t\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn respond([output || \"trusted check passed\"], { code: \"ok\", action: input.action });\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn respond([\"typed lane action is unavailable for this request\"], { code: \"role_forbidden\" });\n\t\t\t\t}\n\n\t\t\t\tconst result = await engineDeps.exec(command, args, {\n\t\t\t\t\tcwd: lane.worktreePath,\n\t\t\t\t\ttimeout: 60_000,\n\t\t\t\t\tsignal: engineDeps.signal,\n\t\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t\t});\n\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\treturn respond([`[git_failed] ${output || `${command} exited ${result.code}`}`], {\n\t\t\t\t\t\tcode: \"git_failed\",\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn respond([output || `${input.action} completed`], { code: \"ok\", action: input.action });\n\t\t\t};\n\n\t\t\tif (deps.isWorker()) {\n\t\t\t\tconst bound = deps.boundLaneKey();\n\t\t\t\tif (input.laneKey !== undefined && input.laneKey !== bound) {\n\t\t\t\t\tconst message = \"workers may only target their bound lane\";\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t\tconst landAllowed = input.action === \"land\" && settings.workerLand === \"allow\";\n\t\t\t\tif (!WORKER_ALLOWED_ACTIONS.has(input.action) && !landAllowed) {\n\t\t\t\t\tconst message =\n\t\t\t\t\t\tinput.action === \"land\"\n\t\t\t\t\t\t\t? 'workers may not land (worktreeSync.workerLand is \"deny\")'\n\t\t\t\t\t\t\t: `workers may not run action \"${input.action}\"`;\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (input.action) {\n\t\t\t\tcase \"git_status\":\n\t\t\t\tcase \"git_diff\":\n\t\t\t\tcase \"git_add\":\n\t\t\t\tcase \"git_commit\":\n\t\t\t\tcase \"check\":\n\t\t\t\t\treturn runTypedLaneAction();\n\t\t\t\tcase \"status\": {\n\t\t\t\t\tconst status = await buildSyncStatus(engineDeps, { policy: settings.syncPolicy });\n\t\t\t\t\tif (status.code !== \"ok\") return respond([`[${status.code}] ${status.message}`], status);\n\t\t\t\t\treturn respond(formatStatus(status), status);\n\t\t\t\t}\n\t\t\t\tcase \"create_lane\": {\n\t\t\t\t\tconst created = await createLane(engineDeps, {\n\t\t\t\t\t\t...(input.laneKey !== undefined ? { laneKey: input.laneKey } : {}),\n\t\t\t\t\t\t...(input.goalId !== undefined ? { goalId: input.goalId } : {}),\n\t\t\t\t\t\t...(input.requirementId !== undefined ? { requirementId: input.requirementId } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (created.code !== \"ok\") return respond([`[${created.code}] ${created.message}`], created);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${created.lane.laneKey}' created: branch ${created.lane.branch}, checkout ${created.lane.worktreePath}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcreated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst synced = await syncLane(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (synced.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tsynced.alreadyFresh\n\t\t\t\t\t\t\t\t\t? `lane '${synced.laneKey}' already contains current main -- nothing to do`\n\t\t\t\t\t\t\t\t\t: `lane '${synced.laneKey}' rebased onto current main (auto-continued ${synced.autoContinued} step(s))`,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tsynced,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (synced.code === \"sync_conflicts\") return respond(formatWorklist(synced.worklist), synced);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`[${synced.code}] ${synced.message}${synced.paths ? `\\n${synced.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\tsynced,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"continue\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst continued = await continueSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (continued.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`lane '${continued.laneKey}' rebase completed -- lane is fresh relative to the synced main`],\n\t\t\t\t\t\t\tcontinued,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (continued.code === \"sync_conflicts\") return respond(formatWorklist(continued.worklist), continued);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`[${continued.code}] ${continued.message}${continued.paths ? `\\n${continued.paths.join(\"\\n\")}` : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcontinued,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"abort_sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst aborted = await abortSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (aborted.code !== \"ok\") return respond([`[${aborted.code}] ${aborted.message}`], aborted);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`lane '${aborted.laneKey}' rebase aborted -- back to its pre-sync tip (still stale)`],\n\t\t\t\t\t\taborted,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"land\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst landed = await landLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\tgate: settings.gate,\n\t\t\t\t\t\t...(settings.gateCommand !== undefined ? { gateCommand: settings.gateCommand } : {}),\n\t\t\t\t\t\tgateTimeoutMs: settings.gateTimeoutMs,\n\t\t\t\t\t});\n\t\t\t\t\tif (landed.code !== \"ok\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`[${landed.code}] ${landed.message}${landed.paths ? `\\n${landed.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\t\tlanded,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${landed.laneKey}' LANDED: epoch ${landed.epoch}, main is now ${landed.mainSha.slice(0, 12)} (gate: ${landed.gate}). All other lanes must sync before their next land.`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tlanded,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"release_lane\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst released = await releaseLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\t...(input.confirm !== undefined ? { confirm: input.confirm } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (released.code !== \"released\") return respond([`[${released.code}] ${released.message}`], released);\n\t\t\t\t\treturn respond([`lane '${released.laneKey}' released`], released);\n\t\t\t\t}\n\t\t\t\tcase \"reconcile\": {\n\t\t\t\t\tconst reconciled = await reconcile(engineDeps);\n\t\t\t\t\tif (reconciled.code !== \"reconciled\")\n\t\t\t\t\t\treturn respond([`[${reconciled.code}] ${reconciled.message}`], reconciled);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`reconciled: ${reconciled.orphanedLaneKeys.length} orphaned, ${reconciled.reRegisteredLaneKeys.length} re-registered, ${reconciled.ownerClearedLaneKeys.length} owners cleared${reconciled.staleLockReleased ? \", stale lock released\" : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\treconciled,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worktree-sync.js","sourceRoot":"","sources":["../../../src/core/tools/worktree-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,QAAQ,GAER,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,QAAQ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ebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { ResolvedWorktreeSyncSettings } from \"../settings-manager.ts\";\nimport type { ConflictWorklist, SyncStatus } from \"../worktree-sync/codes.ts\";\nimport {\n\tabortSync,\n\tbuildSyncStatus,\n\tcontinueSync,\n\tcreateLane,\n\tlandLane,\n\treconcile,\n\treleaseLane,\n\tresolveRepoContext,\n\tsyncLane,\n\ttype WorktreeSyncEngineDeps,\n} from \"../worktree-sync/git-engine.ts\";\nimport { resolveLaneMutationPath } from \"../worktree-sync/lane-gate.ts\";\nimport { readLane } from \"../worktree-sync/store.ts\";\n\n/**\n * `worktree_sync` -- the ENTIRE agent-facing surface of the worktree-per-lane workflow: a closed\n * action set over the engine (`core/worktree-sync/git-engine.ts`) so agents never improvise git\n * ceremony. Every outcome carries a tagged code in `details`; refusal text always names the exact\n * recovery step. See docs/worktree-sync.md for the workflow and the G1-G11 gate table.\n */\n\nfunction createWorktreeSyncSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Union(\n\t\t\t\t[\n\t\t\t\t\tType.Literal(\"status\"),\n\t\t\t\t\tType.Literal(\"git_status\"),\n\t\t\t\t\tType.Literal(\"git_diff\"),\n\t\t\t\t\tType.Literal(\"git_add\"),\n\t\t\t\t\tType.Literal(\"git_commit\"),\n\t\t\t\t\tType.Literal(\"check\"),\n\t\t\t\t\tType.Literal(\"create_lane\"),\n\t\t\t\t\tType.Literal(\"sync\"),\n\t\t\t\t\tType.Literal(\"continue\"),\n\t\t\t\t\tType.Literal(\"abort_sync\"),\n\t\t\t\t\tType.Literal(\"land\"),\n\t\t\t\t\tType.Literal(\"release_lane\"),\n\t\t\t\t\tType.Literal(\"reconcile\"),\n\t\t\t\t],\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"status: the deterministic full picture (epoch, hub, lock, per-lane freshness/staleness, advice). git_status/git_diff: read the bound lane with fixed argv. git_add: stage only explicitly validated paths inside the lane. git_commit: commit with a literal message. check: run only the owner-configured trusted check command. create_lane: new worktree+branch off main. sync: rebase current main into a lane (conflicts return a worklist and leave the rebase in progress). continue: verify resolved conflicts (zero markers, mechanically checked), stage, drive on. abort_sync: abort the in-progress rebase. land: the ONLY door to main -- serialized, freshness-checked, gate-command-verified, ff-only. release_lane: remove a fully-landed lane (discarding unlanded work needs confirm). reconcile: re-sync the registry with git reality.\",\n\t\t\t\t},\n\t\t\t),\n\t\t\tlaneKey: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Target lane. Defaults to this session's bound lane (PI_WORKTREE_LANE) for sync/continue/abort_sync/land.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tgoalId: Type.Optional(\n\t\t\t\tType.String({ description: \"create_lane: goal to scope the auto-allocated lane key by.\" }),\n\t\t\t),\n\t\t\trequirementId: Type.Optional(Type.String({ description: \"create_lane: requirement this lane will work.\" })),\n\t\t\tpaths: Type.Optional(\n\t\t\t\tType.Array(Type.String(), {\n\t\t\t\t\tdescription: \"git_diff/git_add: explicit relative paths inside the bound lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(Type.String({ description: \"git_commit: literal commit message.\" })),\n\t\t\tconfirm: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'release_lane: pass exactly \"yes-discard-lane\" to release a lane that still has unlanded commits or dirty files (G11: never silent).',\n\t\t\t\t}),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst worktreeSyncSchema = createWorktreeSyncSchema();\n\nexport type WorktreeSyncToolInput = Static<typeof worktreeSyncSchema>;\n\nexport interface WorktreeSyncToolDeps {\n\tengineDeps: () => WorktreeSyncEngineDeps;\n\tsettings: () => ResolvedWorktreeSyncSettings;\n\tboundLaneKey: () => string | undefined;\n\t/** True iff this is a worker session (see session-role.ts) -- narrows the action surface below. */\n\tisWorker: () => boolean;\n}\n\n/** Actions a worker session may run unconditionally -- read-only status plus the sync/conflict\n * cycle on its own bound lane. Everything else is refused as `role_forbidden`, EXCEPT `land`,\n * which is instead gated by the `worktreeSync.workerLand` setting (still subject to normal\n * ownership/freshness gating downstream when allowed). */\nconst WORKER_ALLOWED_ACTIONS: ReadonlySet<WorktreeSyncToolInput[\"action\"]> = new Set([\n\t\"status\",\n\t\"git_status\",\n\t\"git_diff\",\n\t\"git_add\",\n\t\"git_commit\",\n\t\"check\",\n\t\"sync\",\n\t\"continue\",\n\t\"abort_sync\",\n]);\n\nfunction formatWorklist(worklist: ConflictWorklist): string[] {\n\tconst lines = [\n\t\t`Conflicts at rebase step ${worklist.step}${worklist.stoppedAtCommit ? ` (replaying ${worklist.stoppedAtCommit.sha.slice(0, 12)}: ${worklist.stoppedAtCommit.subject})` : \"\"}:`,\n\t];\n\tfor (const file of worklist.files) {\n\t\tlines.push(`- ${file.path} [${file.kind}]`);\n\t}\n\tlines.push(\n\t\t'Resolve the zdiff3 hunks in exactly these files (base section included), save, then call {\"action\":\"continue\"}. Staging and marker verification are automatic.',\n\t);\n\treturn lines;\n}\n\nfunction formatStatus(status: SyncStatus): string[] {\n\tconst lines = [\n\t\t`epoch ${status.epoch} | main ${status.mainBranch}@${status.mainSha.slice(0, 12)}` +\n\t\t\t`${status.hub ? ` | hub ${status.hub.clean ? \"clean\" : \"has local changes\"}` : \" | hub: main not checked out\"}` +\n\t\t\t`${status.lock.held ? ` | LOCK held by pid ${status.lock.holder?.pid ?? \"?\"}` : \"\"}`,\n\t];\n\tfor (const lane of status.lanes) {\n\t\tconst flags = [\n\t\t\tlane.registrationStatus !== \"active\" ? lane.registrationStatus : undefined,\n\t\t\tlane.rebaseInProgress ? \"REBASE-IN-PROGRESS\" : undefined,\n\t\t\tlane.syncRequired ? \"SYNC-REQUIRED\" : lane.stale ? \"stale\" : \"fresh\",\n\t\t\tlane.dirty ? \"dirty\" : undefined,\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\", \");\n\t\tlines.push(\n\t\t\t`- ${lane.laneKey} (${lane.branch}) +${lane.aheadOfMain}/-${lane.behindMain} [${flags}]` +\n\t\t\t\t`${lane.overlapWithLastLand.length > 0 ? ` overlap: ${lane.overlapWithLastLand.slice(0, 5).join(\", \")}` : \"\"}`,\n\t\t);\n\t}\n\tif (status.lanes.length === 0) lines.push(\"(no lanes)\");\n\tif (status.advice) lines.push(`advice: ${status.advice}`);\n\treturn lines;\n}\n\nconst WORKTREE_SYNC_PROMPT_GUIDELINES = [\n\t\"Work ONLY inside your lane worktree on your lane branch; never edit the hub checkout or touch main directly -- main moves exclusively through the land action.\",\n\t\"Commit your work on the lane branch, then land. Landing is refused while the lane is stale (G3): call sync first, resolve conflicts locally, then land.\",\n\t\"When a sync stops on conflicts, edit exactly the listed files, then call continue -- staging, marker verification, and rebase continuation are mechanical.\",\n\t\"After any other lane lands, your lane becomes stale; under the mandatory policy your file mutations are refused until you sync. git add/commit stay available to save WIP first.\",\n\t\"Check status when unsure -- it is the deterministic full picture; never infer sync state from raw git output.\",\n];\n\nexport function createWorktreeSyncToolDefinition(deps: WorktreeSyncToolDeps): ToolDefinition {\n\treturn {\n\t\tname: \"worktree_sync\",\n\t\tlabel: \"worktree_sync\",\n\t\tdescription:\n\t\t\t\"Hard-gated worktree-per-lane parallel work: each agent works in its own git worktree/branch; integration is always rebase-onto-main + ff-only land, serialized under one integration lock with the gate command verified at the exact landing tip. status/create_lane/sync/continue/abort_sync/land/release_lane/reconcile. Every outcome is a tagged code with the exact recovery step; landing while stale is structurally impossible.\",\n\t\tpromptSnippet: \"Coordinate parallel work: lane worktrees, rebase-onto-main sync, serialized gated landing.\",\n\t\tpromptGuidelines: WORKTREE_SYNC_PROMPT_GUIDELINES,\n\t\tparameters: worktreeSyncSchema,\n\t\texecutionMode: \"sequential\",\n\t\tasync execute(_toolCallId, input: WorktreeSyncToolInput, signal) {\n\t\t\tconst engineDeps: WorktreeSyncEngineDeps = { ...deps.engineDeps(), ...(signal ? { signal } : {}) };\n\t\t\tconst settings = deps.settings();\n\t\t\tconst laneKey = input.laneKey ?? deps.boundLaneKey();\n\n\t\t\tconst respond = (lines: string[], details: unknown) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: details as Record<string, unknown>,\n\t\t\t});\n\t\t\tconst needLane = (): string | undefined => {\n\t\t\t\tif (laneKey) return undefined;\n\t\t\t\treturn \"laneKey required: pass laneKey, or run inside a lane-bound session (PI_WORKTREE_LANE).\";\n\t\t\t};\n\n\t\t\tconst runTypedLaneAction = async (): Promise<ReturnType<typeof respond>> => {\n\t\t\t\tconst missingLane = needLane();\n\t\t\t\tif (missingLane) return respond([missingLane], { code: \"lane_not_found\", message: missingLane });\n\t\t\t\tconst context = await resolveRepoContext(engineDeps);\n\t\t\t\tif (\"code\" in context) return respond([`[${context.code}] ${context.message}`], context);\n\t\t\t\tconst lane = await readLane(context.paths, laneKey!);\n\t\t\t\tif (!lane || lane.status !== \"active\") {\n\t\t\t\t\tconst message = `active lane '${laneKey}' is not available`;\n\t\t\t\t\treturn respond([`[lane_not_found] ${message}`], { code: \"lane_not_found\", message });\n\t\t\t\t}\n\t\t\t\tconst execInLane = (command: string, args: string[], timeout: number) =>\n\t\t\t\t\tengineDeps.exec(command, args, {\n\t\t\t\t\t\tcwd: lane.worktreePath,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tsignal: engineDeps.signal,\n\t\t\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t\t\t});\n\n\t\t\t\tconst requestedPaths = input.paths ?? [];\n\t\t\t\tconst gitPaths: string[] = [];\n\t\t\t\tfor (const requestedPath of requestedPaths) {\n\t\t\t\t\tif (!requestedPath || isAbsolute(requestedPath) || requestedPath.includes(\"\\0\")) {\n\t\t\t\t\t\tconst message = \"git path must be a non-empty relative path without NUL\";\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tconst resolved = resolveLaneMutationPath(lane.worktreePath, requestedPath);\n\t\t\t\t\tif (!resolved) {\n\t\t\t\t\t\tconst message = `path '${requestedPath}' escapes the lane worktree`;\n\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t}\n\t\t\t\t\tgitPaths.push(relative(lane.worktreePath, resolved) || \".\");\n\t\t\t\t}\n\n\t\t\t\tlet command: string;\n\t\t\t\tlet args: string[];\n\t\t\t\tswitch (input.action) {\n\t\t\t\t\tcase \"git_status\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"status\", \"--short\", \"--branch\"];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_diff\":\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"diff\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_add\":\n\t\t\t\t\t\tif (gitPaths.length === 0) {\n\t\t\t\t\t\t\tconst message = \"git_add requires one or more explicit in-lane paths\";\n\t\t\t\t\t\t\treturn respond([`[path_outside_lane] ${message}`], { code: \"path_outside_lane\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"add\", \"--\", ...gitPaths];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"git_commit\":\n\t\t\t\t\t\tif (!input.message?.trim() || input.message.includes(\"\\0\")) {\n\t\t\t\t\t\t\tconst message = \"git_commit requires a non-empty literal message\";\n\t\t\t\t\t\t\treturn respond([`[git_failed] ${message}`], { code: \"git_failed\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcommand = \"git\";\n\t\t\t\t\t\targs = [\"commit\", \"-m\", input.message];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"check\": {\n\t\t\t\t\t\tconst trustedCommand = settings.gateCommand?.trim();\n\t\t\t\t\t\tif (!trustedCommand) {\n\t\t\t\t\t\t\tconst message = \"no trusted worktree check is configured\";\n\t\t\t\t\t\t\treturn respond([`[gate_command_unset] ${message}`], { code: \"gate_command_unset\", message });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst shell = process.platform === \"win32\" ? \"cmd\" : \"sh\";\n\t\t\t\t\t\tconst shellFlag = process.platform === \"win32\" ? \"/c\" : \"-c\";\n\t\t\t\t\t\tconst result = await execInLane(shell, [shellFlag, trustedCommand], 900_000);\n\t\t\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\t\t\treturn respond([`[gate_failed] ${output || `trusted check exited ${result.code}`}`], {\n\t\t\t\t\t\t\t\tcode: \"gate_failed\",\n\t\t\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn respond([output || \"trusted check passed\"], { code: \"ok\", action: input.action });\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn respond([\"typed lane action is unavailable for this request\"], { code: \"role_forbidden\" });\n\t\t\t\t}\n\n\t\t\t\tconst result = await execInLane(command, args, 60_000);\n\t\t\t\tconst output = `${result.stdout}\\n${result.stderr}`.trim().slice(-8000);\n\t\t\t\tif (result.code !== 0) {\n\t\t\t\t\treturn respond([`[git_failed] ${output || `${command} exited ${result.code}`}`], {\n\t\t\t\t\t\tcode: \"git_failed\",\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\texitCode: result.code,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn respond([output || `${input.action} completed`], { code: \"ok\", action: input.action });\n\t\t\t};\n\n\t\t\tif (deps.isWorker()) {\n\t\t\t\tconst bound = deps.boundLaneKey();\n\t\t\t\tif (input.laneKey !== undefined && input.laneKey !== bound) {\n\t\t\t\t\tconst message = \"workers may only target their bound lane\";\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t\tconst landAllowed = input.action === \"land\" && settings.workerLand === \"allow\";\n\t\t\t\tif (!WORKER_ALLOWED_ACTIONS.has(input.action) && !landAllowed) {\n\t\t\t\t\tconst message =\n\t\t\t\t\t\tinput.action === \"land\"\n\t\t\t\t\t\t\t? 'workers may not land (worktreeSync.workerLand is \"deny\")'\n\t\t\t\t\t\t\t: `workers may not run action \"${input.action}\"`;\n\t\t\t\t\treturn respond([message], { code: \"role_forbidden\", message });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (input.action) {\n\t\t\t\tcase \"git_status\":\n\t\t\t\tcase \"git_diff\":\n\t\t\t\tcase \"git_add\":\n\t\t\t\tcase \"git_commit\":\n\t\t\t\tcase \"check\":\n\t\t\t\t\treturn runTypedLaneAction();\n\t\t\t\tcase \"status\": {\n\t\t\t\t\tconst status = await buildSyncStatus(engineDeps, { policy: settings.syncPolicy });\n\t\t\t\t\tif (status.code !== \"ok\") return respond([`[${status.code}] ${status.message}`], status);\n\t\t\t\t\treturn respond(formatStatus(status), status);\n\t\t\t\t}\n\t\t\t\tcase \"create_lane\": {\n\t\t\t\t\tconst created = await createLane(engineDeps, {\n\t\t\t\t\t\t...(input.laneKey !== undefined ? { laneKey: input.laneKey } : {}),\n\t\t\t\t\t\t...(input.goalId !== undefined ? { goalId: input.goalId } : {}),\n\t\t\t\t\t\t...(input.requirementId !== undefined ? { requirementId: input.requirementId } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (created.code !== \"ok\") return respond([`[${created.code}] ${created.message}`], created);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${created.lane.laneKey}' created: branch ${created.lane.branch}, checkout ${created.lane.worktreePath}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcreated,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst synced = await syncLane(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (synced.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tsynced.alreadyFresh\n\t\t\t\t\t\t\t\t\t? `lane '${synced.laneKey}' already contains current main -- nothing to do`\n\t\t\t\t\t\t\t\t\t: `lane '${synced.laneKey}' rebased onto current main (auto-continued ${synced.autoContinued} step(s))`,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tsynced,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (synced.code === \"sync_conflicts\") return respond(formatWorklist(synced.worklist), synced);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`[${synced.code}] ${synced.message}${synced.paths ? `\\n${synced.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\tsynced,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"continue\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst continued = await continueSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (continued.code === \"sync_clean\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`lane '${continued.laneKey}' rebase completed -- lane is fresh relative to the synced main`],\n\t\t\t\t\t\t\tcontinued,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (continued.code === \"sync_conflicts\") return respond(formatWorklist(continued.worklist), continued);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`[${continued.code}] ${continued.message}${continued.paths ? `\\n${continued.paths.join(\"\\n\")}` : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tcontinued,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"abort_sync\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst aborted = await abortSync(engineDeps, { laneKey: laneKey as string });\n\t\t\t\t\tif (aborted.code !== \"ok\") return respond([`[${aborted.code}] ${aborted.message}`], aborted);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[`lane '${aborted.laneKey}' rebase aborted -- back to its pre-sync tip (still stale)`],\n\t\t\t\t\t\taborted,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"land\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst landed = await landLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\tgate: settings.gate,\n\t\t\t\t\t\t...(settings.gateCommand !== undefined ? { gateCommand: settings.gateCommand } : {}),\n\t\t\t\t\t\tgateTimeoutMs: settings.gateTimeoutMs,\n\t\t\t\t\t});\n\t\t\t\t\tif (landed.code !== \"ok\") {\n\t\t\t\t\t\treturn respond(\n\t\t\t\t\t\t\t[`[${landed.code}] ${landed.message}${landed.paths ? `\\n${landed.paths.join(\"\\n\")}` : \"\"}`],\n\t\t\t\t\t\t\tlanded,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`lane '${landed.laneKey}' LANDED: epoch ${landed.epoch}, main is now ${landed.mainSha.slice(0, 12)} (gate: ${landed.gate}). All other lanes must sync before their next land.`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\tlanded,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase \"release_lane\": {\n\t\t\t\t\tconst missing = needLane();\n\t\t\t\t\tif (missing) return respond([missing], { code: \"lane_not_found\", message: missing });\n\t\t\t\t\tconst released = await releaseLane(engineDeps, {\n\t\t\t\t\t\tlaneKey: laneKey as string,\n\t\t\t\t\t\t...(input.confirm !== undefined ? { confirm: input.confirm } : {}),\n\t\t\t\t\t});\n\t\t\t\t\tif (released.code !== \"released\") return respond([`[${released.code}] ${released.message}`], released);\n\t\t\t\t\treturn respond([`lane '${released.laneKey}' released`], released);\n\t\t\t\t}\n\t\t\t\tcase \"reconcile\": {\n\t\t\t\t\tconst reconciled = await reconcile(engineDeps);\n\t\t\t\t\tif (reconciled.code !== \"reconciled\")\n\t\t\t\t\t\treturn respond([`[${reconciled.code}] ${reconciled.message}`], reconciled);\n\t\t\t\t\treturn respond(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`reconciled: ${reconciled.orphanedLaneKeys.length} orphaned, ${reconciled.reRegisteredLaneKeys.length} re-registered, ${reconciled.ownerClearedLaneKeys.length} owners cleared${reconciled.staleLockReleased ? \", stale lock released\" : \"\"}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\treconciled,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAOtF,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAQD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AA6ID,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CAkG/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { Container, Text } from \"@caupulican/pi-tui\";\nimport { mkdir as fsMkdir, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { applyEncodingPreservation, isValidUTF8, utf8ByteLength } from \"./file-encoding-policy.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Read existing file contents when available for encoding preservation */\n\treadFile?: (absolutePath: string) => Promise<Buffer>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\treadFile: (path) => fsReadFile(path),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\n\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\n\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\n\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\n\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t}\n\t}\n\n\treturn text;\n}\n\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: \"Create or overwrite files\",\n\t\tpromptGuidelines: [\"Use write only for new files or complete rewrites.\"],\n\t\tparameters: writeSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read existing file if available to preserve UTF-8 BOM and CRLF style.\n\t\t\t\tlet existingContent: string | undefined;\n\t\t\t\tif (ops.readFile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst existingBuffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\tif (isValidUTF8(existingBuffer)) {\n\t\t\t\t\t\t\texistingContent = existingBuffer.toString(\"utf-8\");\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore: file does not exist, is unreadable, or remote operations do not expose reads.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet finalContent = content;\n\t\t\t\tif (existingContent !== undefined) {\n\t\t\t\t\tfinalContent = applyEncodingPreservation(existingContent, content);\n\t\t\t\t}\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst byteCount = utf8ByteLength(finalContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote ${byteCount} bytes to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\t\tconst fileContent = str(renderArgs?.content);\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\t\tif (fileContent !== null) {\n\t\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tcomponent.cache = undefined;\n\t\t\t}\n\t\t\tcomponent.setText(\n\t\t\t\tformatWriteCall(\n\t\t\t\t\trenderArgs,\n\t\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\t\tif (!output) {\n\t\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\t\tcomponent.clear();\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(output);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAOtF,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAQD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AA6ID,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CAkG/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG"}
|
package/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,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;YAChF,CAAC;iBAAM,CAAC;gBACP,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;YAC7B,CAAC;YACD,SAAS,CAAC,OAAO,CAChB,eAAe,CACd,UAAU,EACV,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EAC5D,KAAK,EACL,SAAS,CAAC,KAAK,EACf,OAAO,CAAC,GAAG,CACX,CACD,CAAC;YACF,OAAO,SAAS,CAAC;QAAA,CACjB;QACD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE;YAC9C,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;gBACtF,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,OAA0B,EAAiC;IACvG,OAAO,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACnE","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { Container, Text } from \"@caupulican/pi-tui\";\nimport { mkdir as fsMkdir, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { applyEncodingPreservation, isValidUTF8, utf8ByteLength } from \"./file-encoding-policy.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Read existing file contents when available for encoding preservation */\n\treadFile?: (absolutePath: string) => Promise<Buffer>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\treadFile: (path) => fsReadFile(path),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\n\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\n\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\n\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\n\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t}\n\t}\n\n\treturn text;\n}\n\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: \"Create or overwrite files\",\n\t\tpromptGuidelines: [\"Use write only for new files or complete rewrites.\"],\n\t\tparameters: writeSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read existing file if available to preserve UTF-8 BOM and CRLF style.\n\t\t\t\tlet existingContent: string | undefined;\n\t\t\t\tif (ops.readFile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst existingBuffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\tif (isValidUTF8(existingBuffer)) {\n\t\t\t\t\t\t\texistingContent = existingBuffer.toString(\"utf-8\");\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore: file does not exist, is unreadable, or remote operations do not expose reads.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet finalContent = content;\n\t\t\t\tif (existingContent !== undefined) {\n\t\t\t\t\tfinalContent = applyEncodingPreservation(existingContent, content);\n\t\t\t\t}\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst byteCount = utf8ByteLength(finalContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote ${byteCount} bytes to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\t\tconst fileContent = str(renderArgs?.content);\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\t\tif (fileContent !== null) {\n\t\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tcomponent.cache = undefined;\n\t\t\t}\n\t\t\tcomponent.setText(\n\t\t\t\tformatWriteCall(\n\t\t\t\t\trenderArgs,\n\t\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\t\tif (!output) {\n\t\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\t\tcomponent.clear();\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(output);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,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,MAAM,EAAE,CAAC;gBACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;gBACtF,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,OAA0B;IACtE,OAAO,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { Container, Text } from \"@caupulican/pi-tui\";\nimport { mkdir as fsMkdir, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { applyEncodingPreservation, isValidUTF8, utf8ByteLength } from \"./file-encoding-policy.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Read existing file contents when available for encoding preservation */\n\treadFile?: (absolutePath: string) => Promise<Buffer>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\treadFile: (path) => fsReadFile(path),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\n\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\n\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\n\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\n\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t}\n\t}\n\n\treturn text;\n}\n\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: \"Create or overwrite files\",\n\t\tpromptGuidelines: [\"Use write only for new files or complete rewrites.\"],\n\t\tparameters: writeSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read existing file if available to preserve UTF-8 BOM and CRLF style.\n\t\t\t\tlet existingContent: string | undefined;\n\t\t\t\tif (ops.readFile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst existingBuffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\tif (isValidUTF8(existingBuffer)) {\n\t\t\t\t\t\t\texistingContent = existingBuffer.toString(\"utf-8\");\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore: file does not exist, is unreadable, or remote operations do not expose reads.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet finalContent = content;\n\t\t\t\tif (existingContent !== undefined) {\n\t\t\t\t\tfinalContent = applyEncodingPreservation(existingContent, content);\n\t\t\t\t}\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst byteCount = utf8ByteLength(finalContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote ${byteCount} bytes to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\t\tconst fileContent = str(renderArgs?.content);\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\t\tif (fileContent !== null) {\n\t\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tcomponent.cache = undefined;\n\t\t\t}\n\t\t\tcomponent.setText(\n\t\t\t\tformatWriteCall(\n\t\t\t\t\trenderArgs,\n\t\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\t\tif (!output) {\n\t\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\t\tcomponent.clear();\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(output);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
|