@caupulican/pi-adaptative 0.85.4 → 0.86.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/dist/bun/cli.d.ts +1 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/core/agent-paths.d.ts +3 -3
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +3 -3
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +11 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +14 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -2
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +2 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +19 -8
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +11 -5
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +34 -8
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +3 -3
- package/dist/core/autonomy/subagent-prompt.js +9 -9
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +10 -8
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +23 -13
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bash-execution-controller.d.ts +4 -0
- package/dist/core/bash-execution-controller.d.ts.map +1 -1
- package/dist/core/bash-execution-controller.js +11 -4
- package/dist/core/bash-execution-controller.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +4 -3
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/billing-failover-controller.d.ts +2 -2
- package/dist/core/billing-failover-controller.d.ts.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/capability-contract.d.ts +1 -1
- package/dist/core/capability-contract.d.ts.map +1 -1
- package/dist/core/capability-contract.js +0 -1
- package/dist/core/capability-contract.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +8 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +73 -3
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +2 -2
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +9 -1
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/artifact-retrieval.d.ts +1 -1
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
- package/dist/core/context/artifact-retrieval.js +1 -1
- package/dist/core/context/artifact-retrieval.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -6
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +151 -63
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-composition.js +1 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +5 -2
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/file-store-memory-provider.js +1 -1
- package/dist/core/context/file-store-memory-provider.js.map +1 -1
- package/dist/core/context/tool-output-packer.d.ts +1 -1
- package/dist/core/context/tool-output-packer.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.js +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 +7 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +2 -2
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +8 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +1 -1
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +2 -2
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts +1 -1
- package/dist/core/cost/session-usage.d.ts.map +1 -1
- package/dist/core/cost/session-usage.js +1 -1
- package/dist/core/cost/session-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts +1 -0
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +3 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/worker-actions.js +1 -1
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +27 -8
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +191 -33
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +45 -6
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js +110 -13
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +180 -160
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +23 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-authority-resolver.js +128 -0
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -0
- package/dist/core/delegation/worker-conversation-store.d.ts +2 -1
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +4 -3
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +7 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +260 -87
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +25 -4
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js +90 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +22 -12
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +4 -2
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +0 -2
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -35
- 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 +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +6 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +20 -6
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +47 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js +210 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -0
- package/dist/core/extensions/builtin.d.ts +2 -2
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +2 -2
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/bundled-virtual-modules.d.ts +2 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +129 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/factory-runtime.d.ts +22 -0
- package/dist/core/extensions/factory-runtime.d.ts.map +1 -0
- package/dist/core/extensions/factory-runtime.js +334 -0
- package/dist/core/extensions/factory-runtime.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/lifecycle.d.ts +13 -0
- package/dist/core/extensions/lifecycle.d.ts.map +1 -0
- package/dist/core/extensions/lifecycle.js +52 -0
- package/dist/core/extensions/lifecycle.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +3 -24
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +21 -531
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts +51 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +59 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/foreground-recovery-controller.d.ts +2 -1
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +3 -3
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.js +1 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +1 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +1 -1
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +1 -1
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +1 -1
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/providers/user-memory-archive.js +1 -1
- package/dist/core/memory/providers/user-memory-archive.js.map +1 -1
- package/dist/core/model-registry.d.ts +2 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +4 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +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-controller.js +1 -1
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.js +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +1 -1
- package/dist/core/model-tool-protocol.d.ts.map +1 -1
- package/dist/core/model-tool-protocol.js +1 -1
- package/dist/core/model-tool-protocol.js.map +1 -1
- package/dist/core/models/llamacpp-runtime.d.ts +7 -0
- package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
- package/dist/core/models/llamacpp-runtime.js +8 -3
- package/dist/core/models/llamacpp-runtime.js.map +1 -1
- package/dist/core/models/local-runtime.js +1 -1
- package/dist/core/models/local-runtime.js.map +1 -1
- package/dist/core/models/runtime-process.d.ts.map +1 -1
- package/dist/core/models/runtime-process.js +5 -18
- package/dist/core/models/runtime-process.js.map +1 -1
- package/dist/core/orchestration/bounded-string-array.d.ts +11 -0
- package/dist/core/orchestration/bounded-string-array.d.ts.map +1 -0
- package/dist/core/orchestration/bounded-string-array.js +17 -0
- package/dist/core/orchestration/bounded-string-array.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +16 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +38 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +11 -3
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +0 -1
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +3 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +12 -10
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +94 -104
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +4 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/model-binding.d.ts +1 -1
- package/dist/core/orchestration/model-binding.d.ts.map +1 -1
- package/dist/core/orchestration/model-binding.js +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 +8 -9
- package/dist/core/orchestration/policy-compiler.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +4 -10
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/task-profile-writer.js +1 -1
- package/dist/core/orchestration/task-profile-writer.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 +58 -3
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +10 -17
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +15 -1
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +55 -34
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +4 -3
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +2 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/model-fitness-controller.js +1 -1
- package/dist/core/research/model-fitness-controller.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +2 -2
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +1 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +10 -19
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -70
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.js +3 -3
- 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 +47 -18
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +1 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +1 -1
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/bitwarden-credential-storage.d.ts +51 -0
- package/dist/core/secrets/bitwarden-credential-storage.d.ts.map +1 -0
- package/dist/core/secrets/bitwarden-credential-storage.js +345 -0
- package/dist/core/secrets/bitwarden-credential-storage.js.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts +8 -4
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +31 -29
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +109 -0
- package/dist/core/secrets/credential-manager.d.ts.map +1 -0
- package/dist/core/secrets/credential-manager.js +384 -0
- package/dist/core/secrets/credential-manager.js.map +1 -0
- package/dist/core/secrets/credential-project.d.ts +4 -0
- package/dist/core/secrets/credential-project.d.ts.map +1 -0
- package/dist/core/secrets/credential-project.js +145 -0
- package/dist/core/secrets/credential-project.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +1 -1
- package/dist/core/secrets/secret-dotenv.js +1 -1
- package/dist/core/secrets/secret-dotenv.js.map +1 -1
- package/dist/core/security/context-threat-scanner.d.ts +14 -0
- package/dist/core/security/context-threat-scanner.d.ts.map +1 -0
- package/dist/core/security/context-threat-scanner.js +71 -0
- package/dist/core/security/context-threat-scanner.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +4 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +49 -11
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +10 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -2
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-recovery-logger.js +1 -1
- package/dist/core/tool-recovery-logger.js.map +1 -1
- package/dist/core/tools/artifact-retrieve.js +1 -1
- package/dist/core/tools/artifact-retrieve.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +179 -28
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.d.ts +44 -0
- package/dist/core/tools/extensionify-runtime.d.ts.map +1 -0
- package/dist/core/tools/extensionify-runtime.js +115 -0
- package/dist/core/tools/extensionify-runtime.js.map +1 -0
- package/dist/core/tools/extensionify.d.ts +9 -30
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +10 -140
- package/dist/core/tools/extensionify.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 +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -0
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +1 -1
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/index.d.ts +2 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +7 -43
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/profile-writer.js +3 -3
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/python.d.ts +2 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js +17 -12
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/render-utils.js +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +2 -0
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +7 -3
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts +8 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -1
- package/dist/core/tools/search-command-guard.js +54 -0
- package/dist/core/tools/search-command-guard.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +8 -18
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +83 -348
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +9 -4
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +6 -4
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/core/tools/tool-definition-factory.d.ts +32 -0
- package/dist/core/tools/tool-definition-factory.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-factory.js +55 -0
- package/dist/core/tools/tool-definition-factory.js.map +1 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +79 -32
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +24 -18
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +1 -1
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +35 -14
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +1 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +27 -4
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts +21 -0
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -0
- package/dist/modes/interactive/secret-menu-controller.js +276 -0
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -0
- package/dist/utils/child-process.js +1 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +2 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +43 -48
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/zip-extractor.d.ts +8 -0
- package/dist/utils/zip-extractor.d.ts.map +1 -0
- package/dist/utils/zip-extractor.js +275 -0
- package/dist/utils/zip-extractor.js.map +1 -0
- package/docs/harness-architecture.md +34 -22
- package/docs/index.md +1 -1
- package/docs/resources.md +1 -1
- package/docs/settings.md +39 -103
- package/docs/usage.md +7 -5
- package/docs/worker-profiles.md +9 -7
- 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 +12 -12
- package/package.json +7 -5
- package/dist/core/secrets/secret-vault-format.d.ts +0 -112
- package/dist/core/secrets/secret-vault-format.d.ts.map +0 -1
- package/dist/core/secrets/secret-vault-format.js +0 -396
- package/dist/core/secrets/secret-vault-format.js.map +0 -1
- package/dist/core/secrets/secret-vault.d.ts +0 -72
- package/dist/core/secrets/secret-vault.d.ts.map +0 -1
- package/dist/core/secrets/secret-vault.js +0 -663
- package/dist/core/secrets/secret-vault.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret-store.js","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,wDAAwD,CAAC;AAElG,OAAO,EAAE,UAAU,EAAyB,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EACN,yBAAyB,EACzB,4BAA4B,EAC5B,iCAAiC,EACjC,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC9B,4BAA4B,EAE5B,WAAW,EACX,gBAAgB,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAA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AC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YACnD,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport { ExtensionEditorComponent } from \"../../modes/interactive/components/extension-editor.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { defineTool, type ExtensionContext } from \"../extensions/types.ts\";\nimport { parseDotenvDocument, SecretDotenvError } from \"../secrets/secret-dotenv.ts\";\nimport {\n\tMAX_VARIABLES_PER_PROFILE,\n\tSECRET_DESCRIPTION_MAX_CHARS,\n\tSECRET_PRINTABLE_METADATA_PATTERN,\n\tSECRET_PROFILE_ID_MAX_CHARS,\n\tSECRET_PROFILE_ID_PATTERN,\n\tSECRET_VARIABLE_NAME_MAX_CHARS,\n\tSECRET_VARIABLE_NAME_PATTERN,\n\ttype SecretProfileSummary,\n\tSecretVault,\n\tSecretVaultError,\n} from \"../secrets/secret-vault.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n} from \"./orchestration-panel.ts\";\n\nconst secretStoreSchema = Type.Object(\n\t{\n\t\taction: Type.Union(\n\t\t\t[\n\t\t\t\tType.Literal(\"set\"),\n\t\t\t\tType.Literal(\"list\"),\n\t\t\t\tType.Literal(\"materialize\"),\n\t\t\t\tType.Literal(\"remove\"),\n\t\t\t\tType.Literal(\"lock\"),\n\t\t\t],\n\t\t\t{ description: \"Credential-management action.\" },\n\t\t),\n\t\tprofile: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: SECRET_PROFILE_ID_MAX_CHARS,\n\t\t\t\tpattern: SECRET_PROFILE_ID_PATTERN,\n\t\t\t\tdescription: \"Portable profile identifier, such as project-dev or aws-work.\",\n\t\t\t}),\n\t\t),\n\t\tdescription: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: SECRET_DESCRIPTION_MAX_CHARS,\n\t\t\t\tpattern: SECRET_PRINTABLE_METADATA_PATTERN,\n\t\t\t\tdescription: \"Non-secret profile description.\",\n\t\t\t}),\n\t\t),\n\t\tenvFile: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 512,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Relative dotenv location inside the current workspace, such as .env, .env.local, or config/dev.env. Valid only for set.\",\n\t\t\t}),\n\t\t),\n\t\tvariableNames: Type.Optional(\n\t\t\tType.Array(\n\t\t\t\tType.String({\n\t\t\t\t\tminLength: 1,\n\t\t\t\t\tmaxLength: SECRET_VARIABLE_NAME_MAX_CHARS,\n\t\t\t\t\tpattern: SECRET_VARIABLE_NAME_PATTERN,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\tminItems: 1,\n\t\t\t\t\tmaxItems: MAX_VARIABLES_PER_PROFILE,\n\t\t\t\t\tdescription: \"Specific variable names to remove. Omit to remove the whole profile.\",\n\t\t\t\t},\n\t\t\t),\n\t\t),\n\t\tscope: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"managed\"), Type.Literal(\"workspace\")], {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Materialization target. workspace resolves the durable current-project binding; managed writes private Pi state.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type SecretStoreToolInput = Static<typeof secretStoreSchema>;\n\nexport type SecretStoreStatus =\n\t| \"cancelled\"\n\t| \"error\"\n\t| \"listed\"\n\t| \"locked\"\n\t| \"materialized\"\n\t| \"removed\"\n\t| \"stored\"\n\t| \"unavailable\";\n\nexport interface SecretStoreToolDetails {\n\taction: SecretStoreToolInput[\"action\"];\n\tstatus: SecretStoreStatus;\n\tprofile?: string;\n\tvariableNames?: string[];\n\tprofiles?: SecretProfileSummary[];\n\tscope?: \"managed\" | \"workspace\";\n\tenvFile?: string;\n\tmaterialized?: boolean;\n\tcode?: string;\n\tmessage?: string;\n}\n\nexport interface SecretStoreToolOptions {\n\tagentDir?: string;\n\tvault?: SecretVault;\n}\n\ntype SecretStoreResult = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: SecretStoreToolDetails;\n};\n\nfunction result(details: SecretStoreToolDetails, text: string): SecretStoreResult {\n\treturn { content: [{ type: \"text\", text }], details };\n}\n\nfunction cancelled(action: SecretStoreToolInput[\"action\"], profile?: string): SecretStoreResult {\n\treturn result(\n\t\t{ action, status: \"cancelled\", ...(profile ? { profile } : {}), code: \"owner_cancelled\" },\n\t\t\"Secret store action was cancelled by the owner.\",\n\t);\n}\n\nfunction failed(action: SecretStoreToolInput[\"action\"], error: unknown, profile?: string): SecretStoreResult {\n\tconst code = error instanceof SecretVaultError ? error.code : \"safe_failure\";\n\tconst message =\n\t\terror instanceof SecretVaultError ? error.message : \"Secret store failed safely without exposing values.\";\n\treturn result(\n\t\t{ action, status: \"error\", ...(profile ? { profile } : {}), code, message },\n\t\t`Secret store failed: ${message}`,\n\t);\n}\n\nfunction invalid(\n\taction: SecretStoreToolInput[\"action\"],\n\tcode: string,\n\tmessage: string,\n\tprofile?: string,\n): SecretStoreResult {\n\treturn result(\n\t\t{ action, status: \"error\", ...(profile ? { profile } : {}), code, message },\n\t\t`Secret store request is invalid: ${message}`,\n\t);\n}\n\nfunction panelModel(details: SecretStoreToolDetails | undefined, expanded: boolean): OrchestrationPanelModel {\n\tif (!details) return { label: \"secrets\", status: \"error\", emptyText: \"No secret-store result was retained.\" };\n\tconst success = [\"listed\", \"locked\", \"materialized\", \"removed\", \"stored\"].includes(details.status);\n\tconst rows = expanded\n\t\t? (details.profiles ?? []).map((profile) => ({\n\t\t\t\tstatus: \"info\" as const,\n\t\t\t\tlabel: profile.profile,\n\t\t\t\tmeta: [\n\t\t\t\t\t`${profile.variableNames.length} variable${profile.variableNames.length === 1 ? \"\" : \"s\"}`,\n\t\t\t\t\t`${profile.bindings.length} binding${profile.bindings.length === 1 ? \"\" : \"s\"}`,\n\t\t\t\t],\n\t\t\t\tdetails: [\n\t\t\t\t\t...(profile.description ? [profile.description] : []),\n\t\t\t\t\t...profile.bindings.map((binding) => `${binding.envFile} · ${binding.workspace}`),\n\t\t\t\t],\n\t\t\t}))\n\t\t: undefined;\n\treturn {\n\t\tlabel: \"secrets\",\n\t\taction: details.status,\n\t\tstatus: success ? \"success\" : details.status === \"cancelled\" ? \"warning\" : \"error\",\n\t\tsummary: [\n\t\t\tdetails.profile,\n\t\t\tdetails.envFile,\n\t\t\tdetails.scope,\n\t\t\tdetails.variableNames\n\t\t\t\t? `${details.variableNames.length} variable${details.variableNames.length === 1 ? \"\" : \"s\"}`\n\t\t\t\t: undefined,\n\t\t\tdetails.profiles ? `${details.profiles.length} profile${details.profiles.length === 1 ? \"\" : \"s\"}` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows,\n\t\tnotices:\n\t\t\texpanded && details.message ? [{ status: success ? \"info\" : \"error\", text: details.message }] : undefined,\n\t};\n}\n\nasync function ensureUnlocked(\n\tvault: SecretVault,\n\taction: SecretStoreToolInput[\"action\"],\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n\tprofile?: string,\n): Promise<SecretStoreResult | undefined> {\n\tif (vault.isUnlocked) return undefined;\n\tif (await vault.exists()) {\n\t\twhile (!signal?.aborted) {\n\t\t\tlet passphrase = await ctx.ui.input(\"Unlock secret vault\", \"Master passphrase\", {\n\t\t\t\tsignal,\n\t\t\t\tsensitive: true,\n\t\t\t});\n\t\t\tif (passphrase === undefined || signal?.aborted) return cancelled(action, profile);\n\t\t\ttry {\n\t\t\t\tawait vault.unlock(passphrase);\n\t\t\t\treturn undefined;\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof SecretVaultError && [\"invalid_passphrase\", \"unlock_failed\"].includes(error.code)) {\n\t\t\t\t\tctx.ui.notify(error.message, \"error\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn failed(action, error, profile);\n\t\t\t} finally {\n\t\t\t\tpassphrase = \"\";\n\t\t\t}\n\t\t}\n\t\treturn cancelled(action, profile);\n\t}\n\n\twhile (!signal?.aborted) {\n\t\tlet passphrase = await ctx.ui.input(\"Create secret vault\", \"New master passphrase\", { signal, sensitive: true });\n\t\tif (passphrase === undefined || signal?.aborted) return cancelled(action, profile);\n\t\tlet confirmation = await ctx.ui.input(\"Confirm secret vault\", \"Repeat master passphrase\", {\n\t\t\tsignal,\n\t\t\tsensitive: true,\n\t\t});\n\t\tif (confirmation === undefined || signal?.aborted) {\n\t\t\tpassphrase = \"\";\n\t\t\treturn cancelled(action, profile);\n\t\t}\n\t\ttry {\n\t\t\tif (passphrase !== confirmation) {\n\t\t\t\tctx.ui.notify(\"The two master passphrases do not match.\", \"error\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait vault.initialize(passphrase);\n\t\t\treturn undefined;\n\t\t} catch (error) {\n\t\t\tif (error instanceof SecretVaultError && error.code === \"invalid_passphrase\") {\n\t\t\t\tctx.ui.notify(error.message, \"error\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn failed(action, error, profile);\n\t\t} finally {\n\t\t\tpassphrase = \"\";\n\t\t\tconfirmation = \"\";\n\t\t}\n\t}\n\treturn cancelled(action, profile);\n}\n\nfunction validateInput(input: SecretStoreToolInput): SecretStoreResult | undefined {\n\tif (input.action === \"lock\" || input.action === \"list\") {\n\t\tif (\n\t\t\tinput.profile !== undefined ||\n\t\t\tinput.description !== undefined ||\n\t\t\tinput.envFile !== undefined ||\n\t\t\tinput.variableNames !== undefined ||\n\t\t\tinput.scope !== undefined\n\t\t) {\n\t\t\treturn invalid(input.action, \"unexpected_fields\", `Action ${input.action} does not accept profile fields.`);\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (input.action === \"set\" && !input.profile) {\n\t\treturn invalid(input.action, \"profile_required\", \"Action set requires a profile.\");\n\t}\n\tif (input.action === \"remove\" && !input.profile) {\n\t\treturn invalid(input.action, \"profile_required\", \"Action remove requires a profile.\");\n\t}\n\tif (input.action !== \"set\" && (input.description !== undefined || input.envFile !== undefined)) {\n\t\treturn invalid(\n\t\t\tinput.action,\n\t\t\t\"unexpected_profile_fields\",\n\t\t\t\"description and envFile are valid only for set.\",\n\t\t\tinput.profile,\n\t\t);\n\t}\n\tif (input.action !== \"remove\" && input.variableNames !== undefined) {\n\t\treturn invalid(\n\t\t\tinput.action,\n\t\t\t\"unexpected_variable_names\",\n\t\t\t\"variableNames is valid only for remove.\",\n\t\t\tinput.profile,\n\t\t);\n\t}\n\tif (input.action !== \"materialize\" && input.scope !== undefined) {\n\t\treturn invalid(input.action, \"unexpected_scope\", \"scope is valid only for materialize.\", input.profile);\n\t}\n\tif (input.variableNames && new Set(input.variableNames).size !== input.variableNames.length) {\n\t\treturn invalid(input.action, \"duplicate_variables\", \"Variable names must be unique.\", input.profile);\n\t}\n\treturn undefined;\n}\n\nasync function openPrivateDotenvEditor(\n\tctx: ExtensionContext,\n\ttitle: string,\n\tprefill: string,\n\tsignal: AbortSignal | undefined,\n): Promise<string | undefined> {\n\tif (signal?.aborted) return undefined;\n\ttry {\n\t\treturn await ctx.ui.custom<string | undefined>(\n\t\t\t(tui, _theme, keybindings, done) =>\n\t\t\t\tnew ExtensionEditorComponent(\n\t\t\t\t\ttui,\n\t\t\t\t\tkeybindings,\n\t\t\t\t\ttitle,\n\t\t\t\t\tprefill,\n\t\t\t\t\t(value) => done(value),\n\t\t\t\t\t() => done(undefined),\n\t\t\t\t\t{\n\t\t\t\t\t\tprivateContent: true,\n\t\t\t\t\t\tallowExternalEditor: false,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tnotice: \"Private plaintext editor · content stays local and never enters model context\",\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t);\n\t} catch (error) {\n\t\tif (signal?.aborted) return undefined;\n\t\tthrow error;\n\t}\n}\n\nasync function captureValidDotenv(\n\tctx: ExtensionContext,\n\ttitle: string,\n\tprefill: string,\n\tsignal: AbortSignal | undefined,\n): Promise<{ document: string; variableNames: string[] } | undefined> {\n\tlet draft = prefill;\n\twhile (!signal?.aborted) {\n\t\tconst edited = await openPrivateDotenvEditor(ctx, title, draft, signal);\n\t\tif (edited === undefined || signal?.aborted) return undefined;\n\t\ttry {\n\t\t\tconst parsed = parseDotenvDocument(edited);\n\t\t\tconst variableNames = parsed.variables.map((variable) => variable.name);\n\t\t\tfor (const variable of parsed.variables) variable.value = \"\";\n\t\t\tdraft = \"\";\n\t\t\treturn { document: parsed.document, variableNames };\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(error instanceof SecretDotenvError ? error.message : \"The dotenv document is invalid.\", \"error\");\n\t\t\tdraft = edited;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function executeSet(\n\tvault: SecretVault,\n\tinput: SecretStoreToolInput & { profile: string },\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n): Promise<SecretStoreResult> {\n\tlet document = \"\";\n\tlet originalUnmanagedContent: string | undefined;\n\ttry {\n\t\tconst target = vault.resolveBindingTarget(ctx.cwd, input.envFile ?? \".env\");\n\t\tconst destinationState = await vault.inspectEnvDestination(target.destination, input.profile);\n\t\tif (destinationState === \"managed-other\") {\n\t\t\treturn invalid(\n\t\t\t\tinput.action,\n\t\t\t\t\"destination_conflict\",\n\t\t\t\t\"The selected dotenv location is already managed by another profile.\",\n\t\t\t\tinput.profile,\n\t\t\t);\n\t\t}\n\t\tconst storedDocument = await vault.getProfileDocument(input.profile);\n\t\tlet prefill = storedDocument ?? \"\";\n\t\tif (destinationState === \"unmanaged\") {\n\t\t\toriginalUnmanagedContent = await vault.readOwnerDotenv(target.destination);\n\t\t\tprefill = originalUnmanagedContent;\n\t\t}\n\t\tif (destinationState === \"managed-profile\" && storedDocument === undefined) {\n\t\t\treturn invalid(\n\t\t\t\tinput.action,\n\t\t\t\t\"profile_missing\",\n\t\t\t\t\"The dotenv target claims this profile, but the encrypted profile is missing.\",\n\t\t\t\tinput.profile,\n\t\t\t);\n\t\t}\n\n\t\tconst captured = await captureValidDotenv(\n\t\t\tctx,\n\t\t\t`Secrets · ${input.profile} → ${target.destination}`,\n\t\t\tprefill,\n\t\t\tsignal,\n\t\t);\n\t\tprefill = \"\";\n\t\tif (!captured) return cancelled(input.action, input.profile);\n\t\tdocument = captured.document;\n\t\tawait vault.replaceProfileDocument(input.profile, input.description, document, {\n\t\t\tworkspace: target.workspace,\n\t\t\tenvFile: target.envFile,\n\t\t});\n\t\ttry {\n\t\t\tawait vault.materializeEnv(input.profile, target.destination, {\n\t\t\t\tallowReplaceUnmanaged: destinationState === \"unmanaged\",\n\t\t\t\texpectedUnmanagedContent: originalUnmanagedContent,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof SecretVaultError ? error.message : \"Dotenv materialization failed safely.\";\n\t\t\tctx.ui.notify(`Profile stored, but ${target.destination} was not refreshed: ${message}`, \"warning\");\n\t\t\treturn result(\n\t\t\t\t{\n\t\t\t\t\taction: input.action,\n\t\t\t\t\tstatus: \"stored\",\n\t\t\t\t\tprofile: input.profile,\n\t\t\t\t\tenvFile: target.envFile,\n\t\t\t\t\tvariableNames: captured.variableNames,\n\t\t\t\t\tmaterialized: false,\n\t\t\t\t\tcode: \"materialization_failed\",\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\t`Stored profile ${input.profile}, but its bound dotenv could not be refreshed. Retry secret_store materialize; no values were exposed.`,\n\t\t\t);\n\t\t}\n\t\tctx.ui.notify(`Credential profile ${input.profile} stored and activated at ${target.destination}`, \"info\");\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"stored\",\n\t\t\t\tprofile: input.profile,\n\t\t\t\tenvFile: target.envFile,\n\t\t\t\tvariableNames: captured.variableNames,\n\t\t\t\tmaterialized: true,\n\t\t\t},\n\t\t\t`Stored and activated ${captured.variableNames.length} variables for profile ${input.profile} at its bound workspace dotenv location. Values never entered model context.`,\n\t\t);\n\t} catch (error) {\n\t\treturn failed(input.action, error, input.profile);\n\t} finally {\n\t\tdocument = \"\";\n\t\toriginalUnmanagedContent = undefined;\n\t}\n}\n\nasync function executeMaterialize(\n\tvault: SecretVault,\n\tinput: SecretStoreToolInput,\n\tctx: ExtensionContext,\n): Promise<SecretStoreResult> {\n\ttry {\n\t\tconst scope = input.scope ?? \"workspace\";\n\t\tconst binding = await vault.resolveBindingForWorkspace(ctx.cwd, input.profile);\n\t\tconst destination = scope === \"managed\" ? vault.getManagedEnvPath(binding.profile) : binding.destination;\n\t\tconst destinationState = await vault.inspectEnvDestination(destination, binding.profile);\n\t\tif (destinationState === \"unmanaged\" || destinationState === \"managed-other\") {\n\t\t\treturn invalid(\n\t\t\t\tinput.action,\n\t\t\t\t\"destination_conflict\",\n\t\t\t\t\"The bound dotenv location is no longer safely managed. Use set to review it in the private editor.\",\n\t\t\t\tbinding.profile,\n\t\t\t);\n\t\t}\n\t\tconst materialized = await vault.materializeEnv(binding.profile, destination, {\n\t\t\tactivationWorkspace: ctx.cwd,\n\t\t\tmanaged: scope === \"managed\",\n\t\t});\n\t\tctx.ui.notify(`Credential profile ${binding.profile} activated at ${destination}`, \"info\");\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"materialized\",\n\t\t\t\tprofile: binding.profile,\n\t\t\t\tvariableNames: materialized.variableNames,\n\t\t\t\tscope,\n\t\t\t\tenvFile: scope === \"workspace\" ? binding.envFile : undefined,\n\t\t\t\tmaterialized: true,\n\t\t\t},\n\t\t\t`Activated profile ${binding.profile} for the current workspace. Its dotenv and process environment are available without exposing values to the model.`,\n\t\t);\n\t} catch (error) {\n\t\treturn failed(input.action, error, input.profile);\n\t}\n}\n\nasync function executeRemove(\n\tvault: SecretVault,\n\tinput: SecretStoreToolInput & { profile: string },\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n): Promise<SecretStoreResult> {\n\tconst target = input.variableNames?.length\n\t\t? `${input.variableNames.join(\", \")} from profile ${input.profile}`\n\t\t: `the entire profile ${input.profile}`;\n\tconst approved = await ctx.ui.confirm(\n\t\t\"Remove stored secrets\",\n\t\t`Remove ${target}? Pi-managed workspace and private dotenv copies are invalidated.`,\n\t\t{ signal },\n\t);\n\tif (!approved || signal?.aborted) return cancelled(input.action, input.profile);\n\ttry {\n\t\tconst removal = await vault.removeProfile(input.profile, input.variableNames);\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"removed\",\n\t\t\t\tprofile: input.profile,\n\t\t\t\tvariableNames: removal.removedVariableNames,\n\t\t\t},\n\t\t\t`Removed ${removal.removedVariableNames.length} secret variable${removal.removedVariableNames.length === 1 ? \"\" : \"s\"} from profile ${input.profile}.`,\n\t\t);\n\t} catch (error) {\n\t\treturn failed(input.action, error, input.profile);\n\t}\n}\n\nexport function createSecretStoreToolDefinition(options: SecretStoreToolOptions) {\n\tconst vault = options.vault ?? (options.agentDir ? SecretVault.forAgentDir(options.agentDir) : undefined);\n\tif (!vault) throw new Error(\"secret_store requires an agentDir or SecretVault\");\n\treturn defineTool<typeof secretStoreSchema, SecretStoreToolDetails>({\n\t\tname: \"secret_store\",\n\t\tlabel: \"Secret Store\",\n\t\tdescription:\n\t\t\t\"Open a model-blind native dotenv editor, encrypt owner credentials, bind profiles to workspace dotenv locations, and activate them for normal process use without returning values to the model.\",\n\t\tpromptSnippet:\n\t\t\t\"Manage credentials through the model-blind secret vault. Before credential-dependent work, materialize the current workspace binding; use set to open the owner's private dotenv editor.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use secret_store whenever credentials are needed. Never ask the owner to paste a secret into chat or place a value in tool arguments.\",\n\t\t\t\"Use set with a profile and relative envFile. The harness opens a private plaintext editor, persists the workspace binding, writes the dotenv, and activates the environment.\",\n\t\t\t\"Before credential-dependent commands in a later session, call materialize without a profile to resolve the current workspace binding. Use list only when selection or discovery is needed.\",\n\t\t\t\"After activation, run the consuming application normally. Never read, grep, print, echo, source, or otherwise inspect credential files or environment values.\",\n\t\t\t\"Treat cancellation as owner intent. Do not immediately repeat the same credential request.\",\n\t\t],\n\t\tparameters: secretStoreSchema,\n\t\texecutionMode: \"sequential\",\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(toolResult, { expanded, isPartial }, theme: Theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"secrets\",\n\t\t\t\t\taction: \"waiting for you\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, panelModel(toolResult.details, expanded), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, ctx) {\n\t\t\tif (!ctx.hasUI || ctx.mode !== \"tui\") {\n\t\t\t\treturn result(\n\t\t\t\t\t{\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\tstatus: \"unavailable\",\n\t\t\t\t\t\t...(input.profile ? { profile: input.profile } : {}),\n\t\t\t\t\t\tcode: \"user_tui_required\",\n\t\t\t\t\t\tmessage: \"Secret values can be captured only in a user-visible TUI session.\",\n\t\t\t\t\t},\n\t\t\t\t\t\"secret_store requires a user-visible TUI session.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (signal?.aborted) return cancelled(input.action, input.profile);\n\t\t\tconst validation = validateInput(input);\n\t\t\tif (validation) return validation;\n\t\t\tif (input.action === \"lock\") {\n\t\t\t\tvault.lock();\n\t\t\t\treturn result(\n\t\t\t\t\t{ action: input.action, status: \"locked\" },\n\t\t\t\t\t\"Secret vault locked; cached key, credential environment, and exact-value redaction cache were cleared.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst unlockResult = await ensureUnlocked(vault, input.action, ctx, signal, input.profile);\n\t\t\t\tif (unlockResult) return unlockResult;\n\t\t\t\tif (input.action === \"list\") {\n\t\t\t\t\tconst profiles = await vault.listProfiles();\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"listed\", profiles },\n\t\t\t\t\t\t`Secret vault contains ${profiles.length} profile${profiles.length === 1 ? \"\" : \"s\"}. Only names, variable names, and workspace bindings were returned.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (input.action === \"set\" && input.profile) {\n\t\t\t\t\treturn executeSet(vault, { ...input, profile: input.profile }, ctx, signal);\n\t\t\t\t}\n\t\t\t\tif (input.action === \"materialize\") return executeMaterialize(vault, input, ctx);\n\t\t\t\tif (!input.profile) return invalid(input.action, \"profile_required\", \"A profile is required.\");\n\t\t\t\treturn executeRemove(vault, { ...input, profile: input.profile }, ctx, signal);\n\t\t\t} catch (error) {\n\t\t\t\treturn failed(input.action, error, input.profile);\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"secret-store.js","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAEN,sBAAsB,EAEtB,sBAAsB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAE3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CACpC;IACC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE;QAC5F,WAAW,EAAE,4EAA4E;KACzF,CAAC;IACF,OAAO,EAAE,IAAI,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B,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { defineTool } from \"../extensions/types.ts\";\nimport {\n\ttype CredentialManager,\n\tCredentialManagerError,\n\ttype CredentialProfileSummary,\n\tCredentialStorageError,\n} from \"../secrets/credential-manager.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n} from \"./orchestration-panel.ts\";\n\nconst secretStoreSchema = Type.Object(\n\t{\n\t\taction: Type.Union([Type.Literal(\"status\"), Type.Literal(\"list\"), Type.Literal(\"activate\")], {\n\t\t\tdescription: \"Credential-use action. Credential mutation is owner-only through /secrets.\",\n\t\t}),\n\t\tprofile: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 96,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._-]*$\",\n\t\t\t\tdescription: \"Bound profile to activate. Omit when the project has exactly one bound profile.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type SecretStoreToolInput = Static<typeof secretStoreSchema>;\n\nexport type SecretStoreStatus = \"activated\" | \"available\" | \"cancelled\" | \"error\" | \"listed\" | \"unavailable\";\n\nexport interface SecretStoreToolDetails {\n\taction: SecretStoreToolInput[\"action\"];\n\tstatus: SecretStoreStatus;\n\tprofile?: string;\n\tvariableNames?: string[];\n\tprofiles?: CredentialProfileSummary[];\n\tproject?: string;\n\tconnected?: boolean;\n\tcode?: string;\n\tmessage?: string;\n}\n\nexport interface SecretStoreToolOptions {\n\tmanager: CredentialManager;\n}\n\ntype SecretStoreResult = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: SecretStoreToolDetails;\n};\n\nfunction result(details: SecretStoreToolDetails, text: string): SecretStoreResult {\n\treturn { content: [{ type: \"text\", text }], details };\n}\n\nfunction invalid(input: SecretStoreToolInput): SecretStoreResult | undefined {\n\tif (input.action !== \"activate\" && input.profile !== undefined) {\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"error\",\n\t\t\t\tcode: \"unexpected_profile\",\n\t\t\t\tmessage: `Action ${input.action} does not accept a profile.`,\n\t\t\t},\n\t\t\t`Secret store request is invalid: action ${input.action} does not accept a profile.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\nfunction failed(input: SecretStoreToolInput, error: unknown): SecretStoreResult {\n\tconst known = error instanceof CredentialManagerError || error instanceof CredentialStorageError;\n\tconst code = known ? error.code : \"safe_failure\";\n\tconst message = known ? error.message : \"Credential activation failed safely without exposing values.\";\n\tconst status: SecretStoreStatus = [\"owner_setup_required\", \"not_connected\", \"provider_unavailable\"].includes(code)\n\t\t? \"unavailable\"\n\t\t: \"error\";\n\treturn result(\n\t\t{\n\t\t\taction: input.action,\n\t\t\tstatus,\n\t\t\t...(input.profile ? { profile: input.profile } : {}),\n\t\t\tcode,\n\t\t\tmessage,\n\t\t},\n\t\t`Credential action failed: ${message}`,\n\t);\n}\n\nfunction panelModel(details: SecretStoreToolDetails | undefined, expanded: boolean): OrchestrationPanelModel {\n\tif (!details) return { label: \"secrets\", status: \"error\", emptyText: \"No credential result was retained.\" };\n\tconst success = [\"activated\", \"available\", \"listed\"].includes(details.status);\n\treturn {\n\t\tlabel: \"secrets\",\n\t\taction: details.status,\n\t\tstatus: success ? \"success\" : details.status === \"cancelled\" ? \"warning\" : \"error\",\n\t\tsummary: [\n\t\t\tdetails.profile,\n\t\t\tdetails.project,\n\t\t\tdetails.variableNames\n\t\t\t\t? `${details.variableNames.length} variable${details.variableNames.length === 1 ? \"\" : \"s\"}`\n\t\t\t\t: undefined,\n\t\t\tdetails.profiles ? `${details.profiles.length} profile${details.profiles.length === 1 ? \"\" : \"s\"}` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows: expanded\n\t\t\t? details.profiles?.map((profile) => ({\n\t\t\t\t\tstatus: profile.boundToCurrentProject ? (\"succeeded\" as const) : (\"info\" as const),\n\t\t\t\t\tlabel: profile.profile,\n\t\t\t\t\tmeta: [\n\t\t\t\t\t\t`${profile.variableNames.length} variable${profile.variableNames.length === 1 ? \"\" : \"s\"}`,\n\t\t\t\t\t\tprofile.boundToCurrentProject ? \"bound here\" : \"not bound here\",\n\t\t\t\t\t],\n\t\t\t\t\tdetails: profile.description ? [profile.description] : undefined,\n\t\t\t\t}))\n\t\t\t: undefined,\n\t\tnotices:\n\t\t\texpanded && details.message ? [{ status: success ? \"info\" : \"error\", text: details.message }] : undefined,\n\t};\n}\n\nexport function createSecretStoreToolDefinition(options: SecretStoreToolOptions) {\n\tconst { manager } = options;\n\treturn defineTool<typeof secretStoreSchema, SecretStoreToolDetails>({\n\t\tname: \"secret_store\",\n\t\tlabel: \"Secret Store\",\n\t\tdescription:\n\t\t\t\"Discover and activate owner-authorized Bitwarden credential profiles for the current project without exposing values.\",\n\t\tpromptSnippet:\n\t\t\t\"Activate project credentials with secret_store before credential-dependent commands. Credential setup and mutation are owner-only through /secrets.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use secret_store activate before credential-dependent work. It works in TUI, print, and RPC modes and returns metadata only.\",\n\t\t\t\"Omit profile when the project has one binding. Use list to select among multiple authorized profiles.\",\n\t\t\t\"Never ask the owner to paste a credential into chat or pass a value through tool arguments.\",\n\t\t\t\"After activation, run the consuming command normally. Never print, inspect, grep, or echo credential environment values.\",\n\t\t\t\"If owner_setup_required is returned, tell the owner to run /secrets in a TUI session. Do not repeatedly retry.\",\n\t\t],\n\t\tparameters: secretStoreSchema,\n\t\texecutionMode: \"sequential\",\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(toolResult, { expanded, isPartial }, theme: Theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"secrets\",\n\t\t\t\t\taction: \"activating\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, panelModel(toolResult.details, expanded), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, ctx) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\treturn result(\n\t\t\t\t\t{ action: input.action, status: \"cancelled\", code: \"cancelled\" },\n\t\t\t\t\t\"Credential action cancelled.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst validation = invalid(input);\n\t\t\tif (validation) return validation;\n\t\t\ttry {\n\t\t\t\tif (input.action === \"status\") {\n\t\t\t\t\tconst status = manager.status;\n\t\t\t\t\tif (!status.sessionAvailable) {\n\t\t\t\t\t\treturn result(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\t\t\tstatus: \"unavailable\",\n\t\t\t\t\t\t\t\tconnected: false,\n\t\t\t\t\t\t\t\tcode: \"owner_setup_required\",\n\t\t\t\t\t\t\t\tmessage: \"The owner must connect Bitwarden with /secrets.\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"Bitwarden owner setup is required. Run /secrets in a TUI session.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"available\", connected: status.connected },\n\t\t\t\t\t\tstatus.connected\n\t\t\t\t\t\t\t? \"Bitwarden is connected for this Pi session.\"\n\t\t\t\t\t\t\t: \"A Bitwarden session key is available and will be validated on activation.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (input.action === \"list\") {\n\t\t\t\t\tconst profiles = await manager.listForProject(ctx.cwd, signal);\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"listed\", profiles },\n\t\t\t\t\t\t`Found ${profiles.length} credential profile${profiles.length === 1 ? \"\" : \"s\"}; only metadata was returned.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst activated = await manager.activateForProject(ctx.cwd, input.profile, signal);\n\t\t\t\treturn result(\n\t\t\t\t\t{\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\tstatus: \"activated\",\n\t\t\t\t\t\tprofile: activated.profile,\n\t\t\t\t\t\tvariableNames: activated.variableNames,\n\t\t\t\t\t\tproject: activated.project,\n\t\t\t\t\t},\n\t\t\t\t\t`Activated ${activated.profile} for ${activated.project}. Credential values remain hidden.`,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn failed(input, error);\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-contract-router.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-contract-router.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC3B;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"shell-contract-router.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-contract-router.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC3B;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AA4T1C,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAClC,kBAAkB,CAwEpB"}
|
|
@@ -132,9 +132,14 @@ function quotePowerShell(value) {
|
|
|
132
132
|
function powershellArray(values) {
|
|
133
133
|
return `@(${values.map(quotePowerShell).join(", ")})`;
|
|
134
134
|
}
|
|
135
|
+
const POWERSHELL_STATUS_FUNCTION = "__pi_complete_status";
|
|
136
|
+
/** Keep persistent sessions alive; fall back to a real process exit for one-shot/custom hosts. */
|
|
137
|
+
function completePowerShellStatus(code) {
|
|
138
|
+
return `if (Test-Path -LiteralPath 'Function:\\${POWERSHELL_STATUS_FUNCTION}') { ${POWERSHELL_STATUS_FUNCTION} ${code} } else { exit ${code} }`;
|
|
139
|
+
}
|
|
135
140
|
function externalCommand(argv) {
|
|
136
141
|
const invocation = `& ${argv.map(quotePowerShell).join(" ")}`;
|
|
137
|
-
return `${invocation}\
|
|
142
|
+
return `$global:LASTEXITCODE = $null\n${invocation}\n$__pi_external_succeeded = $?\n$__pi_external_code = if ($null -ne $global:LASTEXITCODE) { [int]$global:LASTEXITCODE } elseif ($__pi_external_succeeded) { 0 } else { 1 }\n${completePowerShellStatus("$__pi_external_code")}`;
|
|
138
143
|
}
|
|
139
144
|
function parseFlags(argv, allowedFlags) {
|
|
140
145
|
const flags = new Set();
|
|
@@ -187,7 +192,7 @@ function routeHeadOrTail(argv, tail) {
|
|
|
187
192
|
function routeGrep(argv) {
|
|
188
193
|
if (argv.length !== 3 || argv[1].startsWith("-") || argv[2].startsWith("-"))
|
|
189
194
|
return undefined;
|
|
190
|
-
return
|
|
195
|
+
return `$__pi_grep_code = 0; try { [string[]]$matches = @(Select-String -LiteralPath ${quotePowerShell(argv[2])} -Pattern ${quotePowerShell(argv[1])} -CaseSensitive -ErrorAction Stop | ForEach-Object { $_.Line }); if ($matches.Count -eq 0) { $__pi_grep_code = 1 } else { $matches } } catch { [Console]::Error.WriteLine($_.Exception.Message); $__pi_grep_code = 2 }; ${completePowerShellStatus("$__pi_grep_code")}`;
|
|
191
196
|
}
|
|
192
197
|
function routeFind(argv) {
|
|
193
198
|
let searchPath = ".";
|
|
@@ -257,9 +262,9 @@ function routeBuiltIn(argv) {
|
|
|
257
262
|
return `[Console]::Out.${method}((${powershellArray(argv.slice(valueIndex))} -join ' '))`;
|
|
258
263
|
}
|
|
259
264
|
if (command === "true" && argv.length === 1)
|
|
260
|
-
return "
|
|
265
|
+
return completePowerShellStatus("0");
|
|
261
266
|
if (command === "false" && argv.length === 1)
|
|
262
|
-
return "
|
|
267
|
+
return completePowerShellStatus("1");
|
|
263
268
|
if (command === "which" && argv.length === 2) {
|
|
264
269
|
return `(Get-Command -Name ${quotePowerShell(argv[1])} -CommandType Application -ErrorAction Stop).Source`;
|
|
265
270
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-contract-router.js","sourceRoot":"","sources":["../../../src/core/tools/shell-contract-router.ts"],"names":[],"mappings":"AAMA,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC9F,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACpC,QAAQ;IACR,UAAU;IACV,SAAS;IACT,MAAM;IACN,GAAG;IACH,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;IACN,KAAK;IACL,IAAI;IACJ,OAAO;CACP,CAAC,CAAC;AAQH,MAAM,qBAAqB,G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AAE,aAAa;YACnB,KAAK,EAAE,gFAAgF,kBAAkB,EAAE;SAC3G,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,OAAO;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACnE,IAAI,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3C,wFAAwF;QACxF,wCAAwC;QACxC,IAAI,YAAY;YAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;QAC5D,OAAO;YACN,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,eAAe,IAAI,CAAC,CAAC,CAAC,0FAA0F;SACvH,CAAC;IACH,CAAC;IACD,IAAI,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,OAAO;YACN,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,6EAA6E;SACpF,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;AACrE,CAAC","sourcesContent":["export type ShellContractRoute =\n\t| { kind: \"passthrough\"; command: string }\n\t| { kind: \"powershell\"; command: string; argv: readonly string[] }\n\t| { kind: \"python-engine\"; command: string }\n\t| { kind: \"unsupported\"; error: string };\n\nconst ENGINE_OWNED_BUILTINS = new Set([\"cd\", \"export\", \"unset\", \"exit\", \"break\", \"continue\"]);\nconst ENGINE_ONLY_BUILTINS = new Set([\n\t\"printf\",\n\t\"basename\",\n\t\"dirname\",\n\t\"test\",\n\t\"[\",\n\t\"sed\",\n\t\"wc\",\n\t\"sort\",\n\t\"uniq\",\n\t\"cut\",\n\t\"tr\",\n\t\"xargs\",\n]);\n\ninterface TokenizeResult {\n\tok: boolean;\n\targv?: string[];\n\terror?: string;\n}\n\nconst BLOCKED_NESTED_SHELLS = new Set([\n\t\"bash\",\n\t\"sh\",\n\t\"zsh\",\n\t\"fish\",\n\t\"cmd\",\n\t\"cmd.exe\",\n\t\"powershell\",\n\t\"powershell.exe\",\n\t\"pwsh\",\n\t\"pwsh.exe\",\n\t\"wsl\",\n\t\"wsl.exe\",\n]);\nconst UNSUPPORTED_OPERATOR_MESSAGE =\n\t\"Unsupported Bash construct on Windows. Use one simple command per call; pipelines, redirection, command substitution, variable expansion, shell chaining, and nested shells are not translated.\";\n\nfunction tokenizePortableCommand(command: string): TokenizeResult {\n\tconst argv: string[] = [];\n\tlet token = \"\";\n\tlet tokenStarted = false;\n\tlet quote: \"single\" | \"double\" | undefined;\n\tlet escaping = false;\n\n\tconst finishToken = () => {\n\t\tif (!tokenStarted) return;\n\t\targv.push(token);\n\t\ttoken = \"\";\n\t\ttokenStarted = false;\n\t};\n\n\tconst source = command.trim();\n\tfor (let index = 0; index < source.length; index++) {\n\t\tconst character = source[index];\n\t\tconst nextCharacter = source[index + 1];\n\t\tif (escaping) {\n\t\t\ttoken += character;\n\t\t\ttokenStarted = true;\n\t\t\tescaping = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === \"single\") {\n\t\t\tif (character === \"'\") quote = undefined;\n\t\t\telse token += character;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === \"double\") {\n\t\t\tif (character === '\"') {\n\t\t\t\tquote = undefined;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (character === \"\\\\\") {\n\t\t\t\tif (nextCharacter && '\"$`\\\\'.includes(nextCharacter)) {\n\t\t\t\t\ttoken += nextCharacter;\n\t\t\t\t\ttokenStarted = true;\n\t\t\t\t\tindex++;\n\t\t\t\t} else {\n\t\t\t\t\ttoken += character;\n\t\t\t\t\ttokenStarted = true;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (character === \"$\" || character === \"`\") {\n\t\t\t\treturn { ok: false, error: UNSUPPORTED_OPERATOR_MESSAGE };\n\t\t\t}\n\t\t\ttoken += character;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === \"'\") {\n\t\t\tquote = \"single\";\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === '\"') {\n\t\t\tquote = \"double\";\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"\\\\\") {\n\t\t\tif (/^[A-Za-z]:/u.test(token) || token.startsWith(\"\\\\\\\\\")) {\n\t\t\t\ttoken += character;\n\t\t\t\ttokenStarted = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (token === \"\" && nextCharacter === \"\\\\\") {\n\t\t\t\ttoken = \"\\\\\\\\\";\n\t\t\t\ttokenStarted = true;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tescaping = true;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (/\\s/u.test(character)) {\n\t\t\tfinishToken();\n\t\t\tcontinue;\n\t\t}\n\t\tif (\"|><&;\\n\\r$`(){}*?[]\".includes(character) || character === \"#\" || (character === \"~\" && token === \"\")) {\n\t\t\treturn { ok: false, error: UNSUPPORTED_OPERATOR_MESSAGE };\n\t\t}\n\t\ttoken += character;\n\t\ttokenStarted = true;\n\t}\n\n\tif (escaping) return { ok: false, error: \"Unsupported trailing escape in Bash-like command.\" };\n\tif (quote) return { ok: false, error: \"Unclosed quote in Bash-like command.\" };\n\tfinishToken();\n\treturn argv.length > 0 ? { ok: true, argv } : { ok: false, error: \"Shell command is empty.\" };\n}\n\nfunction quotePowerShell(value: string): string {\n\treturn `'${value.replaceAll(\"'\", \"''\")}'`;\n}\n\nfunction powershellArray(values: readonly string[]): string {\n\treturn `@(${values.map(quotePowerShell).join(\", \")})`;\n}\n\nfunction externalCommand(argv: readonly string[]): string {\n\tconst invocation = `& ${argv.map(quotePowerShell).join(\" \")}`;\n\treturn `${invocation}\\nif ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }\\nif (-not $?) { exit 1 }`;\n}\n\nfunction parseFlags(\n\targv: readonly string[],\n\tallowedFlags: ReadonlySet<string>,\n): { flags: Set<string>; operands: string[] } | undefined {\n\tconst flags = new Set<string>();\n\tconst operands: string[] = [];\n\tlet optionsEnded = false;\n\tfor (const value of argv) {\n\t\tif (!optionsEnded && value === \"--\") {\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!optionsEnded && value.startsWith(\"-\") && value !== \"-\") {\n\t\t\tif (!allowedFlags.has(value)) return undefined;\n\t\t\tflags.add(value);\n\t\t\tcontinue;\n\t\t}\n\t\toperands.push(value);\n\t}\n\treturn { flags, operands };\n}\n\nfunction routeLs(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-a\", \"-A\", \"-l\", \"-1\", \"-la\", \"-al\"]));\n\tif (!parsed || parsed.operands.length > 1) return undefined;\n\tconst target = parsed.operands[0] ?? \".\";\n\tconst includeHidden = [...parsed.flags].some((flag) => flag.includes(\"a\") || flag.includes(\"A\"));\n\tconst hiddenFilter = includeHidden ? \"\" : \" | Where-Object { -not $_.Name.StartsWith('.') }\";\n\treturn `[string[]]$items = @(Get-ChildItem -LiteralPath ${quotePowerShell(target)}${includeHidden ? \" -Force\" : \"\"} -ErrorAction Stop${hiddenFilter} | ForEach-Object { if ($_.PSIsContainer) { $_.Name + '/' } else { $_.Name } }); [Array]::Sort($items, [StringComparer]::Ordinal); $items`;\n}\n\nfunction routeCat(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"--\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `foreach ($path in ${powershellArray(parsed.operands)}) { [Console]::Out.Write([IO.File]::ReadAllText($path)) }`;\n}\n\nfunction routeHeadOrTail(argv: readonly string[], tail: boolean): string | undefined {\n\tlet count = 10;\n\tlet operands = argv.slice(1);\n\tif (operands[0] === \"-n\") {\n\t\tconst parsedCount = Number(operands[1]);\n\t\tif (!Number.isInteger(parsedCount) || parsedCount < 0) return undefined;\n\t\tcount = parsedCount;\n\t\toperands = operands.slice(2);\n\t}\n\tif (operands.length !== 1 || operands[0].startsWith(\"-\")) return undefined;\n\treturn `Get-Content -LiteralPath ${quotePowerShell(operands[0])} ${tail ? \"-Tail\" : \"-TotalCount\"} ${count} -ErrorAction Stop`;\n}\n\nfunction routeGrep(argv: readonly string[]): string | undefined {\n\tif (argv.length !== 3 || argv[1].startsWith(\"-\") || argv[2].startsWith(\"-\")) return undefined;\n\treturn `[string[]]$matches = @(Select-String -LiteralPath ${quotePowerShell(argv[2])} -Pattern ${quotePowerShell(argv[1])} -CaseSensitive -ErrorAction Stop | ForEach-Object { $_.Line }); if ($matches.Count -eq 0) { exit 1 }; $matches`;\n}\n\nfunction routeFind(argv: readonly string[]): string | undefined {\n\tlet searchPath = \".\";\n\tlet type: \"File\" | \"Directory\" | undefined;\n\tlet filter: string | undefined;\n\tlet index = 1;\n\tif (argv[index] && !argv[index].startsWith(\"-\")) searchPath = argv[index++];\n\twhile (index < argv.length) {\n\t\tconst option = argv[index++];\n\t\tif (option === \"-type\" && (argv[index] === \"f\" || argv[index] === \"d\")) {\n\t\t\ttype = argv[index++] === \"f\" ? \"File\" : \"Directory\";\n\t\t\tcontinue;\n\t\t}\n\t\tif (option === \"-name\" && argv[index]) {\n\t\t\tfilter = argv[index++];\n\t\t\tcontinue;\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst typeFlag = type ? ` -${type}` : \"\";\n\tconst filterFlag = filter ? ` -Filter ${quotePowerShell(filter)}` : \"\";\n\treturn `[string[]]$paths = @(Get-ChildItem -LiteralPath ${quotePowerShell(searchPath)} -Recurse -Force${typeFlag}${filterFlag} -ErrorAction Stop | ForEach-Object { $_.FullName.Replace('\\\\', '/') }); [Array]::Sort($paths, [StringComparer]::Ordinal); $paths`;\n}\n\nfunction routeRemove(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-f\", \"-r\", \"-rf\", \"-fr\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\tconst recursive = [...parsed.flags].some((flag) => flag.includes(\"r\"));\n\tconst force = [...parsed.flags].some((flag) => flag.includes(\"f\"));\n\treturn `foreach ($path in ${powershellArray(parsed.operands)}) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Force${recursive ? \" -Recurse\" : \"\"} -ErrorAction Stop }${force ? \"\" : ' else { throw \"rm: path not found: $path\" }'} }`;\n}\n\nfunction routeCopyOrMove(argv: readonly string[], move: boolean): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), move ? new Set<string>() : new Set([\"-r\", \"-R\"]));\n\tif (!parsed || parsed.operands.length !== 2) return undefined;\n\tconst [source, destination] = parsed.operands;\n\tconst recurse = !move && parsed.flags.size > 0 ? \" -Recurse\" : \"\";\n\tconst rejectDirectoryWithoutRecursion =\n\t\t!move && parsed.flags.size === 0\n\t\t\t? `$sourceItem = Get-Item -LiteralPath ${quotePowerShell(source)} -Force -ErrorAction Stop; if ($sourceItem.PSIsContainer) { throw 'cp: source is a directory; use -r' }; `\n\t\t\t: \"\";\n\treturn `${rejectDirectoryWithoutRecursion}${move ? \"Move-Item\" : \"Copy-Item\"} -LiteralPath ${quotePowerShell(source)} -Destination ${quotePowerShell(destination)}${recurse} -ErrorAction Stop`;\n}\n\nfunction routeMkdir(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-p\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `${powershellArray(parsed.operands)} | ForEach-Object { New-Item -ItemType Directory -Path $_${parsed.flags.has(\"-p\") ? \" -Force\" : \"\"} -ErrorAction Stop | Out-Null }`;\n}\n\nfunction routeTouch(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set());\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `${powershellArray(parsed.operands)} | ForEach-Object { if (Test-Path -LiteralPath $_) { (Get-Item -LiteralPath $_ -ErrorAction Stop).LastWriteTime = Get-Date } else { New-Item -ItemType File -Path $_ -ErrorAction Stop | Out-Null } }`;\n}\n\nfunction routeBuiltIn(argv: readonly string[]): string | undefined {\n\tconst command = argv[0].toLowerCase();\n\tif (command === \"pwd\" && argv.length === 1) return \"(Get-Location).Path\";\n\tif (command === \"echo\") {\n\t\tlet valueIndex = 1;\n\t\twhile (/^-n+$/u.test(argv[valueIndex] ?? \"\")) valueIndex++;\n\t\tif (/^-[neE]+$/u.test(argv[valueIndex] ?? \"\") && /[eE]/u.test(argv[valueIndex] ?? \"\")) return undefined;\n\t\tconst method = valueIndex > 1 ? \"Write\" : \"WriteLine\";\n\t\treturn `[Console]::Out.${method}((${powershellArray(argv.slice(valueIndex))} -join ' '))`;\n\t}\n\tif (command === \"true\" && argv.length === 1) return \"exit 0\";\n\tif (command === \"false\" && argv.length === 1) return \"exit 1\";\n\tif (command === \"which\" && argv.length === 2) {\n\t\treturn `(Get-Command -Name ${quotePowerShell(argv[1])} -CommandType Application -ErrorAction Stop).Source`;\n\t}\n\tif (command === \"ls\") return routeLs(argv);\n\tif (command === \"cat\") return routeCat(argv);\n\tif (command === \"head\") return routeHeadOrTail(argv, false);\n\tif (command === \"tail\") return routeHeadOrTail(argv, true);\n\tif (command === \"grep\") return routeGrep(argv);\n\tif (command === \"find\") return routeFind(argv);\n\tif (command === \"rm\") return routeRemove(argv);\n\tif (command === \"cp\") return routeCopyOrMove(argv, false);\n\tif (command === \"mv\") return routeCopyOrMove(argv, true);\n\tif (command === \"mkdir\") return routeMkdir(argv);\n\tif (command === \"touch\") return routeTouch(argv);\n\treturn undefined;\n}\n\nconst ROUTED_BUILTIN_NAMES = new Set([\n\t\"pwd\",\n\t\"echo\",\n\t\"true\",\n\t\"false\",\n\t\"which\",\n\t\"ls\",\n\t\"cat\",\n\t\"head\",\n\t\"tail\",\n\t\"grep\",\n\t\"find\",\n\t\"rm\",\n\t\"cp\",\n\t\"mv\",\n\t\"mkdir\",\n\t\"touch\",\n]);\n\nexport function routeShellContract(\n\tcommand: string,\n\tplatform: NodeJS.Platform = process.platform,\n\toptions?: { pythonEngine?: boolean },\n): ShellContractRoute {\n\tif (platform !== \"win32\") return { kind: \"passthrough\", command };\n\tconst pythonEngine = options?.pythonEngine === true;\n\tconst tokenized = tokenizePortableCommand(command);\n\n\t// Complex constructs (pipelines, redirection, expansion, quoting the tokenizer refuses, …) are\n\t// exactly the grammar the Python engine owns; with the engine off this is the original\n\t// fail-closed floor verbatim.\n\tif (!tokenized.ok || !tokenized.argv) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn { kind: \"unsupported\", error: tokenized.error ?? UNSUPPORTED_OPERATOR_MESSAGE };\n\t}\n\n\tconst argv = tokenized.argv;\n\tconst commandName = argv[0].toLowerCase();\n\n\t// Inline env assignments (`NAME=value [cmd]`) are a state-mutating/expansion form the engine\n\t// supports (§2.1); with the engine off this is the original fail-closed floor verbatim.\n\tif (/^[A-Za-z_][A-Za-z0-9_]*=/u.test(argv[0])) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: \"Inline environment assignments are not supported. Configure the environment outside the shell command.\",\n\t\t};\n\t}\n\n\t// State mutators and controlled exit route to the engine unconditionally when enabled: the\n\t// engine is the sole state owner and must frame `exit` instead of terminating the PS backend.\n\tif (ENGINE_OWNED_BUILTINS.has(commandName)) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\tif (commandName === \"exit\") {\n\t\t\treturn {\n\t\t\t\tkind: \"unsupported\",\n\t\t\t\terror: \"The Bash-like 'exit' builtin requires the Windows Python shell engine so Pi can preserve its terminal result protocol.\",\n\t\t\t};\n\t\t}\n\t}\n\tif (ENGINE_ONLY_BUILTINS.has(commandName)) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `The Bash-like '${argv[0]}' builtin requires the Windows Python shell engine. Enable windowsShell.pythonEngine to use it portably.`,\n\t\t};\n\t}\n\n\tif (BLOCKED_NESTED_SHELLS.has(commandName)) {\n\t\tconst powershellGuidance = [\"powershell\", \"powershell.exe\", \"pwsh\", \"pwsh.exe\"].includes(commandName)\n\t\t\t? \" Invoke the .ps1 path directly with its arguments, without powershell.exe -File or pwsh -File.\"\n\t\t\t: \" Invoke the target executable or supported script directly.\";\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `Nested shell execution is not supported by the Windows shell contract router.${powershellGuidance}`,\n\t\t};\n\t}\n\tconst builtIn = routeBuiltIn(argv);\n\tif (builtIn) return { kind: \"powershell\", command: builtIn, argv };\n\tif (ROUTED_BUILTIN_NAMES.has(commandName)) {\n\t\t// The PS floor rejected the FORM (flags/argument shape); the engine supports the fuller\n\t\t// flag set for the same builtin (§2.2).\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `Unsupported ${argv[0]} form on Windows. Use a simpler Bash-like form or Pi's dedicated read/search/edit tools.`,\n\t\t};\n\t}\n\tif (commandName.endsWith(\".sh\") || commandName.includes(\"/bin/\")) {\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: \"POSIX shell scripts are not supported by the Windows shell contract router.\",\n\t\t};\n\t}\n\treturn { kind: \"powershell\", command: externalCommand(argv), argv };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell-contract-router.js","sourceRoot":"","sources":["../../../src/core/tools/shell-contract-router.ts"],"names":[],"mappings":"AAMA,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAA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C;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;AACrE,CAAC","sourcesContent":["export type ShellContractRoute =\n\t| { kind: \"passthrough\"; command: string }\n\t| { kind: \"powershell\"; command: string; argv: readonly string[] }\n\t| { kind: \"python-engine\"; command: string }\n\t| { kind: \"unsupported\"; error: string };\n\nconst ENGINE_OWNED_BUILTINS = new Set([\"cd\", \"export\", \"unset\", \"exit\", \"break\", \"continue\"]);\nconst ENGINE_ONLY_BUILTINS = new Set([\n\t\"printf\",\n\t\"basename\",\n\t\"dirname\",\n\t\"test\",\n\t\"[\",\n\t\"sed\",\n\t\"wc\",\n\t\"sort\",\n\t\"uniq\",\n\t\"cut\",\n\t\"tr\",\n\t\"xargs\",\n]);\n\ninterface TokenizeResult {\n\tok: boolean;\n\targv?: string[];\n\terror?: string;\n}\n\nconst BLOCKED_NESTED_SHELLS = new Set([\n\t\"bash\",\n\t\"sh\",\n\t\"zsh\",\n\t\"fish\",\n\t\"cmd\",\n\t\"cmd.exe\",\n\t\"powershell\",\n\t\"powershell.exe\",\n\t\"pwsh\",\n\t\"pwsh.exe\",\n\t\"wsl\",\n\t\"wsl.exe\",\n]);\nconst UNSUPPORTED_OPERATOR_MESSAGE =\n\t\"Unsupported Bash construct on Windows. Use one simple command per call; pipelines, redirection, command substitution, variable expansion, shell chaining, and nested shells are not translated.\";\n\nfunction tokenizePortableCommand(command: string): TokenizeResult {\n\tconst argv: string[] = [];\n\tlet token = \"\";\n\tlet tokenStarted = false;\n\tlet quote: \"single\" | \"double\" | undefined;\n\tlet escaping = false;\n\n\tconst finishToken = () => {\n\t\tif (!tokenStarted) return;\n\t\targv.push(token);\n\t\ttoken = \"\";\n\t\ttokenStarted = false;\n\t};\n\n\tconst source = command.trim();\n\tfor (let index = 0; index < source.length; index++) {\n\t\tconst character = source[index];\n\t\tconst nextCharacter = source[index + 1];\n\t\tif (escaping) {\n\t\t\ttoken += character;\n\t\t\ttokenStarted = true;\n\t\t\tescaping = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === \"single\") {\n\t\t\tif (character === \"'\") quote = undefined;\n\t\t\telse token += character;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === \"double\") {\n\t\t\tif (character === '\"') {\n\t\t\t\tquote = undefined;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (character === \"\\\\\") {\n\t\t\t\tif (nextCharacter && '\"$`\\\\'.includes(nextCharacter)) {\n\t\t\t\t\ttoken += nextCharacter;\n\t\t\t\t\ttokenStarted = true;\n\t\t\t\t\tindex++;\n\t\t\t\t} else {\n\t\t\t\t\ttoken += character;\n\t\t\t\t\ttokenStarted = true;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (character === \"$\" || character === \"`\") {\n\t\t\t\treturn { ok: false, error: UNSUPPORTED_OPERATOR_MESSAGE };\n\t\t\t}\n\t\t\ttoken += character;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === \"'\") {\n\t\t\tquote = \"single\";\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === '\"') {\n\t\t\tquote = \"double\";\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"\\\\\") {\n\t\t\tif (/^[A-Za-z]:/u.test(token) || token.startsWith(\"\\\\\\\\\")) {\n\t\t\t\ttoken += character;\n\t\t\t\ttokenStarted = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (token === \"\" && nextCharacter === \"\\\\\") {\n\t\t\t\ttoken = \"\\\\\\\\\";\n\t\t\t\ttokenStarted = true;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tescaping = true;\n\t\t\ttokenStarted = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (/\\s/u.test(character)) {\n\t\t\tfinishToken();\n\t\t\tcontinue;\n\t\t}\n\t\tif (\"|><&;\\n\\r$`(){}*?[]\".includes(character) || character === \"#\" || (character === \"~\" && token === \"\")) {\n\t\t\treturn { ok: false, error: UNSUPPORTED_OPERATOR_MESSAGE };\n\t\t}\n\t\ttoken += character;\n\t\ttokenStarted = true;\n\t}\n\n\tif (escaping) return { ok: false, error: \"Unsupported trailing escape in Bash-like command.\" };\n\tif (quote) return { ok: false, error: \"Unclosed quote in Bash-like command.\" };\n\tfinishToken();\n\treturn argv.length > 0 ? { ok: true, argv } : { ok: false, error: \"Shell command is empty.\" };\n}\n\nfunction quotePowerShell(value: string): string {\n\treturn `'${value.replaceAll(\"'\", \"''\")}'`;\n}\n\nfunction powershellArray(values: readonly string[]): string {\n\treturn `@(${values.map(quotePowerShell).join(\", \")})`;\n}\n\nconst POWERSHELL_STATUS_FUNCTION = \"__pi_complete_status\";\n\n/** Keep persistent sessions alive; fall back to a real process exit for one-shot/custom hosts. */\nfunction completePowerShellStatus(code: string): string {\n\treturn `if (Test-Path -LiteralPath 'Function:\\\\${POWERSHELL_STATUS_FUNCTION}') { ${POWERSHELL_STATUS_FUNCTION} ${code} } else { exit ${code} }`;\n}\n\nfunction externalCommand(argv: readonly string[]): string {\n\tconst invocation = `& ${argv.map(quotePowerShell).join(\" \")}`;\n\treturn `$global:LASTEXITCODE = $null\\n${invocation}\\n$__pi_external_succeeded = $?\\n$__pi_external_code = if ($null -ne $global:LASTEXITCODE) { [int]$global:LASTEXITCODE } elseif ($__pi_external_succeeded) { 0 } else { 1 }\\n${completePowerShellStatus(\"$__pi_external_code\")}`;\n}\n\nfunction parseFlags(\n\targv: readonly string[],\n\tallowedFlags: ReadonlySet<string>,\n): { flags: Set<string>; operands: string[] } | undefined {\n\tconst flags = new Set<string>();\n\tconst operands: string[] = [];\n\tlet optionsEnded = false;\n\tfor (const value of argv) {\n\t\tif (!optionsEnded && value === \"--\") {\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!optionsEnded && value.startsWith(\"-\") && value !== \"-\") {\n\t\t\tif (!allowedFlags.has(value)) return undefined;\n\t\t\tflags.add(value);\n\t\t\tcontinue;\n\t\t}\n\t\toperands.push(value);\n\t}\n\treturn { flags, operands };\n}\n\nfunction routeLs(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-a\", \"-A\", \"-l\", \"-1\", \"-la\", \"-al\"]));\n\tif (!parsed || parsed.operands.length > 1) return undefined;\n\tconst target = parsed.operands[0] ?? \".\";\n\tconst includeHidden = [...parsed.flags].some((flag) => flag.includes(\"a\") || flag.includes(\"A\"));\n\tconst hiddenFilter = includeHidden ? \"\" : \" | Where-Object { -not $_.Name.StartsWith('.') }\";\n\treturn `[string[]]$items = @(Get-ChildItem -LiteralPath ${quotePowerShell(target)}${includeHidden ? \" -Force\" : \"\"} -ErrorAction Stop${hiddenFilter} | ForEach-Object { if ($_.PSIsContainer) { $_.Name + '/' } else { $_.Name } }); [Array]::Sort($items, [StringComparer]::Ordinal); $items`;\n}\n\nfunction routeCat(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"--\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `foreach ($path in ${powershellArray(parsed.operands)}) { [Console]::Out.Write([IO.File]::ReadAllText($path)) }`;\n}\n\nfunction routeHeadOrTail(argv: readonly string[], tail: boolean): string | undefined {\n\tlet count = 10;\n\tlet operands = argv.slice(1);\n\tif (operands[0] === \"-n\") {\n\t\tconst parsedCount = Number(operands[1]);\n\t\tif (!Number.isInteger(parsedCount) || parsedCount < 0) return undefined;\n\t\tcount = parsedCount;\n\t\toperands = operands.slice(2);\n\t}\n\tif (operands.length !== 1 || operands[0].startsWith(\"-\")) return undefined;\n\treturn `Get-Content -LiteralPath ${quotePowerShell(operands[0])} ${tail ? \"-Tail\" : \"-TotalCount\"} ${count} -ErrorAction Stop`;\n}\n\nfunction routeGrep(argv: readonly string[]): string | undefined {\n\tif (argv.length !== 3 || argv[1].startsWith(\"-\") || argv[2].startsWith(\"-\")) return undefined;\n\treturn `$__pi_grep_code = 0; try { [string[]]$matches = @(Select-String -LiteralPath ${quotePowerShell(argv[2])} -Pattern ${quotePowerShell(argv[1])} -CaseSensitive -ErrorAction Stop | ForEach-Object { $_.Line }); if ($matches.Count -eq 0) { $__pi_grep_code = 1 } else { $matches } } catch { [Console]::Error.WriteLine($_.Exception.Message); $__pi_grep_code = 2 }; ${completePowerShellStatus(\"$__pi_grep_code\")}`;\n}\n\nfunction routeFind(argv: readonly string[]): string | undefined {\n\tlet searchPath = \".\";\n\tlet type: \"File\" | \"Directory\" | undefined;\n\tlet filter: string | undefined;\n\tlet index = 1;\n\tif (argv[index] && !argv[index].startsWith(\"-\")) searchPath = argv[index++];\n\twhile (index < argv.length) {\n\t\tconst option = argv[index++];\n\t\tif (option === \"-type\" && (argv[index] === \"f\" || argv[index] === \"d\")) {\n\t\t\ttype = argv[index++] === \"f\" ? \"File\" : \"Directory\";\n\t\t\tcontinue;\n\t\t}\n\t\tif (option === \"-name\" && argv[index]) {\n\t\t\tfilter = argv[index++];\n\t\t\tcontinue;\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst typeFlag = type ? ` -${type}` : \"\";\n\tconst filterFlag = filter ? ` -Filter ${quotePowerShell(filter)}` : \"\";\n\treturn `[string[]]$paths = @(Get-ChildItem -LiteralPath ${quotePowerShell(searchPath)} -Recurse -Force${typeFlag}${filterFlag} -ErrorAction Stop | ForEach-Object { $_.FullName.Replace('\\\\', '/') }); [Array]::Sort($paths, [StringComparer]::Ordinal); $paths`;\n}\n\nfunction routeRemove(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-f\", \"-r\", \"-rf\", \"-fr\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\tconst recursive = [...parsed.flags].some((flag) => flag.includes(\"r\"));\n\tconst force = [...parsed.flags].some((flag) => flag.includes(\"f\"));\n\treturn `foreach ($path in ${powershellArray(parsed.operands)}) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Force${recursive ? \" -Recurse\" : \"\"} -ErrorAction Stop }${force ? \"\" : ' else { throw \"rm: path not found: $path\" }'} }`;\n}\n\nfunction routeCopyOrMove(argv: readonly string[], move: boolean): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), move ? new Set<string>() : new Set([\"-r\", \"-R\"]));\n\tif (!parsed || parsed.operands.length !== 2) return undefined;\n\tconst [source, destination] = parsed.operands;\n\tconst recurse = !move && parsed.flags.size > 0 ? \" -Recurse\" : \"\";\n\tconst rejectDirectoryWithoutRecursion =\n\t\t!move && parsed.flags.size === 0\n\t\t\t? `$sourceItem = Get-Item -LiteralPath ${quotePowerShell(source)} -Force -ErrorAction Stop; if ($sourceItem.PSIsContainer) { throw 'cp: source is a directory; use -r' }; `\n\t\t\t: \"\";\n\treturn `${rejectDirectoryWithoutRecursion}${move ? \"Move-Item\" : \"Copy-Item\"} -LiteralPath ${quotePowerShell(source)} -Destination ${quotePowerShell(destination)}${recurse} -ErrorAction Stop`;\n}\n\nfunction routeMkdir(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set([\"-p\"]));\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `${powershellArray(parsed.operands)} | ForEach-Object { New-Item -ItemType Directory -Path $_${parsed.flags.has(\"-p\") ? \" -Force\" : \"\"} -ErrorAction Stop | Out-Null }`;\n}\n\nfunction routeTouch(argv: readonly string[]): string | undefined {\n\tconst parsed = parseFlags(argv.slice(1), new Set());\n\tif (!parsed || parsed.operands.length === 0) return undefined;\n\treturn `${powershellArray(parsed.operands)} | ForEach-Object { if (Test-Path -LiteralPath $_) { (Get-Item -LiteralPath $_ -ErrorAction Stop).LastWriteTime = Get-Date } else { New-Item -ItemType File -Path $_ -ErrorAction Stop | Out-Null } }`;\n}\n\nfunction routeBuiltIn(argv: readonly string[]): string | undefined {\n\tconst command = argv[0].toLowerCase();\n\tif (command === \"pwd\" && argv.length === 1) return \"(Get-Location).Path\";\n\tif (command === \"echo\") {\n\t\tlet valueIndex = 1;\n\t\twhile (/^-n+$/u.test(argv[valueIndex] ?? \"\")) valueIndex++;\n\t\tif (/^-[neE]+$/u.test(argv[valueIndex] ?? \"\") && /[eE]/u.test(argv[valueIndex] ?? \"\")) return undefined;\n\t\tconst method = valueIndex > 1 ? \"Write\" : \"WriteLine\";\n\t\treturn `[Console]::Out.${method}((${powershellArray(argv.slice(valueIndex))} -join ' '))`;\n\t}\n\tif (command === \"true\" && argv.length === 1) return completePowerShellStatus(\"0\");\n\tif (command === \"false\" && argv.length === 1) return completePowerShellStatus(\"1\");\n\tif (command === \"which\" && argv.length === 2) {\n\t\treturn `(Get-Command -Name ${quotePowerShell(argv[1])} -CommandType Application -ErrorAction Stop).Source`;\n\t}\n\tif (command === \"ls\") return routeLs(argv);\n\tif (command === \"cat\") return routeCat(argv);\n\tif (command === \"head\") return routeHeadOrTail(argv, false);\n\tif (command === \"tail\") return routeHeadOrTail(argv, true);\n\tif (command === \"grep\") return routeGrep(argv);\n\tif (command === \"find\") return routeFind(argv);\n\tif (command === \"rm\") return routeRemove(argv);\n\tif (command === \"cp\") return routeCopyOrMove(argv, false);\n\tif (command === \"mv\") return routeCopyOrMove(argv, true);\n\tif (command === \"mkdir\") return routeMkdir(argv);\n\tif (command === \"touch\") return routeTouch(argv);\n\treturn undefined;\n}\n\nconst ROUTED_BUILTIN_NAMES = new Set([\n\t\"pwd\",\n\t\"echo\",\n\t\"true\",\n\t\"false\",\n\t\"which\",\n\t\"ls\",\n\t\"cat\",\n\t\"head\",\n\t\"tail\",\n\t\"grep\",\n\t\"find\",\n\t\"rm\",\n\t\"cp\",\n\t\"mv\",\n\t\"mkdir\",\n\t\"touch\",\n]);\n\nexport function routeShellContract(\n\tcommand: string,\n\tplatform: NodeJS.Platform = process.platform,\n\toptions?: { pythonEngine?: boolean },\n): ShellContractRoute {\n\tif (platform !== \"win32\") return { kind: \"passthrough\", command };\n\tconst pythonEngine = options?.pythonEngine === true;\n\tconst tokenized = tokenizePortableCommand(command);\n\n\t// Complex constructs (pipelines, redirection, expansion, quoting the tokenizer refuses, …) are\n\t// exactly the grammar the Python engine owns; with the engine off this is the original\n\t// fail-closed floor verbatim.\n\tif (!tokenized.ok || !tokenized.argv) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn { kind: \"unsupported\", error: tokenized.error ?? UNSUPPORTED_OPERATOR_MESSAGE };\n\t}\n\n\tconst argv = tokenized.argv;\n\tconst commandName = argv[0].toLowerCase();\n\n\t// Inline env assignments (`NAME=value [cmd]`) are a state-mutating/expansion form the engine\n\t// supports (§2.1); with the engine off this is the original fail-closed floor verbatim.\n\tif (/^[A-Za-z_][A-Za-z0-9_]*=/u.test(argv[0])) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: \"Inline environment assignments are not supported. Configure the environment outside the shell command.\",\n\t\t};\n\t}\n\n\t// State mutators and controlled exit route to the engine unconditionally when enabled: the\n\t// engine is the sole state owner and must frame `exit` instead of terminating the PS backend.\n\tif (ENGINE_OWNED_BUILTINS.has(commandName)) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\tif (commandName === \"exit\") {\n\t\t\treturn {\n\t\t\t\tkind: \"unsupported\",\n\t\t\t\terror: \"The Bash-like 'exit' builtin requires the Windows Python shell engine so Pi can preserve its terminal result protocol.\",\n\t\t\t};\n\t\t}\n\t}\n\tif (ENGINE_ONLY_BUILTINS.has(commandName)) {\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `The Bash-like '${argv[0]}' builtin requires the Windows Python shell engine. Enable windowsShell.pythonEngine to use it portably.`,\n\t\t};\n\t}\n\n\tif (BLOCKED_NESTED_SHELLS.has(commandName)) {\n\t\tconst powershellGuidance = [\"powershell\", \"powershell.exe\", \"pwsh\", \"pwsh.exe\"].includes(commandName)\n\t\t\t? \" Invoke the .ps1 path directly with its arguments, without powershell.exe -File or pwsh -File.\"\n\t\t\t: \" Invoke the target executable or supported script directly.\";\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `Nested shell execution is not supported by the Windows shell contract router.${powershellGuidance}`,\n\t\t};\n\t}\n\tconst builtIn = routeBuiltIn(argv);\n\tif (builtIn) return { kind: \"powershell\", command: builtIn, argv };\n\tif (ROUTED_BUILTIN_NAMES.has(commandName)) {\n\t\t// The PS floor rejected the FORM (flags/argument shape); the engine supports the fuller\n\t\t// flag set for the same builtin (§2.2).\n\t\tif (pythonEngine) return { kind: \"python-engine\", command };\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: `Unsupported ${argv[0]} form on Windows. Use a simpler Bash-like form or Pi's dedicated read/search/edit tools.`,\n\t\t};\n\t}\n\tif (commandName.endsWith(\".sh\") || commandName.includes(\"/bin/\")) {\n\t\treturn {\n\t\t\tkind: \"unsupported\",\n\t\t\terror: \"POSIX shell scripts are not supported by the Windows shell contract router.\",\n\t\t};\n\t}\n\treturn { kind: \"powershell\", command: externalCommand(argv), argv };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-session.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAMH,OAAO,EAA+B,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAO/F,MAAM,WAAW,uBAAuB;IACvC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kGAAkG;IAClG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,SAAS,CAAC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OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,EAGnD;IAED,IAAI,WAAW,IAAI,qBAAqB,CAEvC;IAED,4FAA4F;IAC5F,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAEzG;IAED,OAAO,IAAI,IAAI,CAMd;YAEa,OAAO;IA6IrB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,SAAS;CAIjB;AAID,iGAAiG;AACjG,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,GAAG,sBAAsB,CAO9G;AAED,4FAA4F;AAC5F,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAK/D"}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
import { randomBytes } from "node:crypto";
|
|
36
36
|
import { basename } from "node:path";
|
|
37
|
-
import { createSilenceWatchdog } from "@caupulican/pi-agent-core";
|
|
37
|
+
import { createSilenceWatchdog } from "@caupulican/pi-agent-core/reliability";
|
|
38
38
|
import { spawn } from "child_process";
|
|
39
39
|
import { getShellConfig, getShellEnv } from "../../utils/shell.js";
|
|
40
40
|
import { PersistentProcessCoordinator } from "./persistent-process-coordinator.js";
|
|
@@ -87,6 +87,7 @@ export function buildPowerShellWire(command, nonce, cdTo) {
|
|
|
87
87
|
const POWERSHELL_BOOTSTRAP = [
|
|
88
88
|
"$ProgressPreference = 'SilentlyContinue'",
|
|
89
89
|
"try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}",
|
|
90
|
+
"function global:__pi_complete_status([int]$Code) { $global:LASTEXITCODE = $Code }",
|
|
90
91
|
"$__pi_in = [Console]::In",
|
|
91
92
|
"while ($true) {",
|
|
92
93
|
"\t$__pi_line = $__pi_in.ReadLine()",
|
|
@@ -95,11 +96,12 @@ const POWERSHELL_BOOTSTRAP = [
|
|
|
95
96
|
"\tif ($__pi_sp -lt 1) { continue }",
|
|
96
97
|
"\t$__pi_nonce = $__pi_line.Substring(0, $__pi_sp)",
|
|
97
98
|
"\t$__pi_cmd = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($__pi_line.Substring($__pi_sp + 1)))",
|
|
98
|
-
"\t$global:LASTEXITCODE =
|
|
99
|
+
"\t$global:LASTEXITCODE = $null",
|
|
99
100
|
"\t$__pi_thrown = $false",
|
|
100
|
-
"\
|
|
101
|
+
"\t$__pi_succeeded = $false",
|
|
102
|
+
"\ttry { Invoke-Expression $__pi_cmd; $__pi_succeeded = $? } catch { $__pi_thrown = $true; $__pi_msg = ($_ | Out-String).TrimEnd(); if ($__pi_msg) { [Console]::Out.WriteLine($__pi_msg) } }",
|
|
101
103
|
"\t$__pi_code = $global:LASTEXITCODE",
|
|
102
|
-
"\tif ($null -eq $__pi_code) { $__pi_code = 0 }",
|
|
104
|
+
"\tif ($null -eq $__pi_code) { $__pi_code = if ($__pi_succeeded) { 0 } else { 1 } }",
|
|
103
105
|
"\tif ($__pi_thrown -and ($__pi_code -eq 0)) { $__pi_code = 1 }",
|
|
104
106
|
"\t[Console]::Out.Write(('{0}{1}{2}:{3}{1}' -f [char]10, [char]30, $__pi_nonce, $__pi_code))",
|
|
105
107
|
"}",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-session.js","sourceRoot":"","sources":["../../../src/core/tools/shell-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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GAAG,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Persistent shell sessions for the bash tool.\n *\n * One long-lived shell process per agent (keyed registry) replaces process-per-command spawning.\n * On Windows every command previously paid a full PowerShell boot; a persistent session pays it\n * once. Shell state (current directory, environment variables) persists across an agent's\n * commands; each key gets an isolated session so concurrently running agents never share state.\n *\n * Protocol: commands stream to the session over stdin and are terminated by a per-command\n * sentinel carrying a random nonce and the exit code. Bash wraps commands in an eval of a quoted\n * heredoc (arbitrary content stays data; syntax errors stay contained in eval); PowerShell runs a\n * ReadLine loop decoding base64 lines (no external binaries involved). On bash, command stderr is\n * merged into stdout at the shell so sentinel ordering is guaranteed on one pipe.\n *\n * PowerShell runs each command as a bare `Invoke-Expression`, NOT piped into `Out-Default`: piping\n * a native command's output into another pipeline stage forces PowerShell's NativeCommandProcessor\n * to capture that child's stdout/stderr into an internal pipe and read it to EOF before the\n * pipeline completes. A detached grandchild that inherited those handles (e.g. `start /b` holding\n * stdio open) then keeps that internal pipe's write end open, so the sentinel — written after the\n * pipeline \"completes\" — waits for the grandchild to die instead of the direct child. The bare\n * invocation lets a native command's stdout/stderr handles be inherited directly by the child\n * process; the direct child's own exit is what unblocks the sentinel line, exactly like the\n * per-command backend and like bash's stdio inheritance above. The bounded consequence: a native\n * command's stderr no longer merges into the session's stdout pipe (there is no capturing pipeline\n * stage to merge it) — it arrives on the session's own stderr pipe instead, forwarded via\n * `onStderr` -> `onData` same as the shell's own diagnostics. PowerShell 5.1's habit of wrapping\n * redirected stderr text in a `NativeCommandError` record also disappears, which is an accuracy\n * improvement (the raw stderr bytes are reported, not a wrapped/duplicated rendering of them).\n *\n * Kill semantics: timeout/abort/silence kill the WHOLE session process tree (a hung foreground\n * command cannot be killed individually without job control) and the next exec respawns a fresh\n * session, losing accumulated shell state by design. A command that exits the shell itself\n * (`exit 3`) reports the shell's exit code and also respawns lazily afterwards.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport { basename } from \"node:path\";\nimport { createSilenceWatchdog } from \"@caupulican/pi-agent-core\";\nimport { spawn } from \"child_process\";\nimport { getShellConfig, getShellEnv, type PlatformShellToolName } from \"../../utils/shell.ts\";\nimport { PersistentProcessCoordinator } from \"./persistent-process-coordinator.ts\";\n\nconst SENTINEL_BYTE = 0x1e;\n/** Longest possible sentinel: \"\\n\" + 0x1e + 16-hex nonce + \":\" + exit code digits + 0x1e. */\nconst SENTINEL_HOLDBACK_BYTES = 64;\n\nexport interface ShellSessionExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\t/** Wall-clock bound in seconds; when set, a breach kills the session and throws `timeout:<s>`. */\n\ttimeoutSeconds?: number;\n\t/** Output-silence bound in ms; when set, silence kills the session and throws `silence:<s>`. */\n\tsilenceMs?: number;\n\tenv?: NodeJS.ProcessEnv;\n}\n\nfunction escapeSingleQuotesPosix(value: string): string {\n\treturn value.replace(/'/g, \"'\\\\''\");\n}\n\nfunction escapeSingleQuotesPowerShell(value: string): string {\n\treturn value.replace(/'/g, \"''\");\n}\n\n/**\n * The whole command is heredoc-quoted data: eval keeps syntax errors contained (a raw syntax\n * error on the session's stdin would abort the shell), and the random delimiter makes content\n * collisions with agent output practically impossible. `< /dev/null` gives commands the same\n * EOF-stdin the per-command backend's `stdio: [\"ignore\", ...]` provided.\n */\nexport function buildBashWire(command: string, nonce: string, cdTo: string | null): string {\n\tconst body = cdTo ? `command cd -- '${escapeSingleQuotesPosix(cdTo)}' && {\\n${command}\\n}` : command;\n\treturn [\n\t\t`{ eval \"$(cat <<'PI_EOF_${nonce}'`,\n\t\tbody,\n\t\t`PI_EOF_${nonce}`,\n\t\t`)\"; } < /dev/null 2>&1`,\n\t\t`printf '\\\\n\\\\036%s:%s\\\\036' '${nonce}' \"$?\"`,\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\n/** One protocol line: `<nonce> <base64(utf8 command)>`. Base64 keeps arbitrary multi-line commands line-safe. */\nexport function buildPowerShellWire(command: string, nonce: string, cdTo: string | null): string {\n\tconst body = cdTo\n\t\t? `Set-Location -LiteralPath '${escapeSingleQuotesPowerShell(cdTo)}' -ErrorAction Stop\\n${command}`\n\t\t: command;\n\treturn `${nonce} ${Buffer.from(body, \"utf8\").toString(\"base64\")}\\n`;\n}\n\n/**\n * PowerShell 5.1-compatible REPL bootstrap. Exit code mirrors `-Command` semantics as closely as\n * a loop can: a native command's $LASTEXITCODE wins, a terminating error forces 1, otherwise 0.\n * Passed as one direct `-Command` argument. `-EncodedCommand` makes PowerShell serialize host,\n * warning, and progress records as CLIXML on stderr whenever pipes are attached; Pi then sees\n * duplicate XML mixed into the same command's plain stdout. Node preserves this script as one\n * argv entry without involving cmd.exe quoting.\n *\n * The command runs as a bare `Invoke-Expression` (no `2>&1 | Out-Default` capture pipeline) — see\n * the module doc header for why: a native command's stdio handles are inherited directly by its\n * child process instead of being captured through a PowerShell-internal pipe, so the sentinel is\n * unblocked by the direct child's own exit rather than by any grandchild holding those handles.\n */\nconst POWERSHELL_BOOTSTRAP = [\n\t\"$ProgressPreference = 'SilentlyContinue'\",\n\t\"try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}\",\n\t\"$__pi_in = [Console]::In\",\n\t\"while ($true) {\",\n\t\"\\t$__pi_line = $__pi_in.ReadLine()\",\n\t\"\\tif ($null -eq $__pi_line) { break }\",\n\t\"\\t$__pi_sp = $__pi_line.IndexOf(' ')\",\n\t\"\\tif ($__pi_sp -lt 1) { continue }\",\n\t\"\\t$__pi_nonce = $__pi_line.Substring(0, $__pi_sp)\",\n\t\"\\t$__pi_cmd = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($__pi_line.Substring($__pi_sp + 1)))\",\n\t\"\\t$global:LASTEXITCODE = 0\",\n\t\"\\t$__pi_thrown = $false\",\n\t\"\\ttry { Invoke-Expression $__pi_cmd } catch { $__pi_thrown = $true; $__pi_msg = ($_ | Out-String).TrimEnd(); if ($__pi_msg) { [Console]::Out.WriteLine($__pi_msg) } }\",\n\t\"\\t$__pi_code = $global:LASTEXITCODE\",\n\t\"\\tif ($null -eq $__pi_code) { $__pi_code = 0 }\",\n\t\"\\tif ($__pi_thrown -and ($__pi_code -eq 0)) { $__pi_code = 1 }\",\n\t\"\\t[Console]::Out.Write(('{0}{1}{2}:{3}{1}' -f [char]10, [char]30, $__pi_nonce, $__pi_code))\",\n\t\"}\",\n].join(\"\\n\");\n\nfunction shallowEnvEquals(a: NodeJS.ProcessEnv, b: NodeJS.ProcessEnv): boolean {\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\tfor (const key of aKeys) {\n\t\tif (a[key] !== b[key]) return false;\n\t}\n\treturn true;\n}\n\ninterface ActiveExec {\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 PersistentShellSession {\n\tprivate readonly key: string;\n\tprivate readonly kind: PlatformShellToolName;\n\tprivate readonly coordinator = new PersistentProcessCoordinator();\n\tprivate childEnv: NodeJS.ProcessEnv | null = null;\n\tprivate lastRequestedCwd: string | null = null;\n\tprivate activeExec: ActiveExec | null = null;\n\tprivate disposed = false;\n\n\tconstructor(key: string, kind: PlatformShellToolName) {\n\t\tthis.key = key;\n\t\tthis.kind = kind;\n\t}\n\n\tget sessionKind(): PlatformShellToolName {\n\t\treturn this.kind;\n\t}\n\n\t/** Serialized: one command at a time per session, later calls queue behind earlier ones. */\n\texec(command: string, cwd: string, options: ShellSessionExecOptions): 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\tthis.activeExec?.fail(new Error(`Shell session \"${this.key}\" is disposed`));\n\t\tthis.coordinator.dispose();\n\t\tthis.resetChildState();\n\t}\n\n\tprivate async execNow(\n\t\tcommand: string,\n\t\tcwd: string,\n\t\t{ onData, signal, timeoutSeconds, silenceMs, env }: ShellSessionExecOptions,\n\t): Promise<{ exitCode: number | null }> {\n\t\tif (this.disposed) throw new Error(`Shell session \"${this.key}\" is disposed`);\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\tconst resolvedEnv = env ?? getShellEnv();\n\t\t// The environment is spawn-time shell config: an env that differs from the running\n\t\t// session's (e.g. a spawn hook rewriting it per command) requires a fresh shell.\n\t\tif (this.coordinator.child && this.childEnv && !shallowEnvEquals(this.childEnv, resolvedEnv)) {\n\t\t\tthis.killChild();\n\t\t}\n\n\t\t// Re-enter the host-requested cwd only when it CHANGES between calls; an unchanged\n\t\t// request preserves the agent's own in-session `cd` (that persistence is the feature).\n\t\tlet cdTo: string | null = null;\n\t\tif (!this.coordinator.child) {\n\t\t\tthis.spawnChild(cwd, resolvedEnv);\n\t\t} else if (this.lastRequestedCwd !== cwd) {\n\t\t\tcdTo = cwd;\n\t\t}\n\t\tthis.lastRequestedCwd = cwd;\n\n\t\tconst child = this.coordinator.child;\n\t\tif (!child?.stdin || !child.stdout || !child.stderr) {\n\t\t\tthis.killChild();\n\t\t\tthrow new Error(`Failed to start ${this.kind} session`);\n\t\t}\n\n\t\tconst nonce = randomBytes(8).toString(\"hex\");\n\t\tconst wire =\n\t\t\tthis.kind === \"powershell\" ? buildPowerShellWire(command, nonce, cdTo) : buildBashWire(command, nonce, cdTo);\n\t\tconst sentinelPrefix = Buffer.from(`\\n\\x1e${nonce}:`, \"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 pending: Buffer = Buffer.alloc(0);\n\t\t\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\t\t\tconst silenceWatchdog =\n\t\t\t\t\ttimeoutSeconds === undefined && silenceMs !== undefined && silenceMs > 0\n\t\t\t\t\t\t? createSilenceWatchdog({\n\t\t\t\t\t\t\t\tsilenceMs,\n\t\t\t\t\t\t\t\tonSilence: () => {\n\t\t\t\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\t\t\t\tsettle(() => reject(new Error(`silence:${silenceMs / 1000}`)));\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\tconst settle = (finish: () => 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\tsilenceWatchdog?.disarm();\n\t\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.activeExec = null;\n\t\t\t\t\tfinish();\n\t\t\t\t};\n\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tthis.killChild();\n\t\t\t\t\tsettle(() => reject(new Error(\"aborted\")));\n\t\t\t\t};\n\n\t\t\t\tconst emitPending = (upTo: number) => {\n\t\t\t\t\tif (upTo <= 0) return;\n\t\t\t\t\tonData(pending.subarray(0, upTo));\n\t\t\t\t\tpending = pending.subarray(upTo);\n\t\t\t\t};\n\n\t\t\t\tthis.activeExec = {\n\t\t\t\t\tonStdout: (data) => {\n\t\t\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\t\t\tpending = pending.length === 0 ? data : Buffer.concat([pending, data]);\n\t\t\t\t\t\tconst prefixIndex = pending.indexOf(sentinelPrefix);\n\t\t\t\t\t\tif (prefixIndex !== -1) {\n\t\t\t\t\t\t\tconst closeIndex = pending.indexOf(SENTINEL_BYTE, prefixIndex + sentinelPrefix.length);\n\t\t\t\t\t\t\tif (closeIndex !== -1) {\n\t\t\t\t\t\t\t\tconst codeText = pending\n\t\t\t\t\t\t\t\t\t.subarray(prefixIndex + sentinelPrefix.length, closeIndex)\n\t\t\t\t\t\t\t\t\t.toString(\"latin1\");\n\t\t\t\t\t\t\t\temitPending(prefixIndex);\n\t\t\t\t\t\t\t\tconst parsed = Number.parseInt(codeText, 10);\n\t\t\t\t\t\t\t\t// Defer the settle by one microtask turn: with the bare Invoke-Expression\n\t\t\t\t\t\t\t\t// form a native command's stderr now arrives on the session's OWN stderr\n\t\t\t\t\t\t\t\t// pipe (see module doc header) instead of being pre-merged into the same\n\t\t\t\t\t\t\t\t// stdout bytes the sentinel rides on. Node fires already-queued stream\n\t\t\t\t\t\t\t\t// 'data' events in event-loop order; queueing the resolution behind a\n\t\t\t\t\t\t\t\t// microtask guarantees any stderr chunk the kernel delivered alongside (or\n\t\t\t\t\t\t\t\t// just before) this stdout chunk has already run its 'data' handler — and\n\t\t\t\t\t\t\t\t// thus reached `onData` — before the promise settles, so callers never see a\n\t\t\t\t\t\t\t\t// truncated stderr tail immediately after resolution.\n\t\t\t\t\t\t\t\tqueueMicrotask(() => settle(() => resolve({ exitCode: Number.isNaN(parsed) ? null : parsed })));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Stream promptly but retain a tail large enough to hold any split sentinel.\n\t\t\t\t\t\temitPending(pending.length - SENTINEL_HOLDBACK_BYTES);\n\t\t\t\t\t},\n\t\t\t\t\tonStderr: (data) => {\n\t\t\t\t\t\t// The command's stderr is merged into stdout at the shell; this pipe only\n\t\t\t\t\t\t// carries the session shell's own diagnostics. Forward for visibility.\n\t\t\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\t\t\tonData(data);\n\t\t\t\t\t},\n\t\t\t\t\tonChildClose: (code) => {\n\t\t\t\t\t\t// The command terminated the shell itself (e.g. `exit 3`) or the shell\n\t\t\t\t\t\t// crashed: report its exit code like the per-command backend would.\n\t\t\t\t\t\temitPending(pending.length);\n\t\t\t\t\t\tsettle(() => resolve({ exitCode: code }));\n\t\t\t\t\t},\n\t\t\t\t\tfail: (error) => {\n\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\tsettle(() => reject(error));\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tif (signal) signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\tif (timeoutSeconds !== undefined && timeoutSeconds > 0) {\n\t\t\t\t\ttimeoutTimer = setTimeout(() => {\n\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\tsettle(() => reject(new Error(`timeout:${timeoutSeconds}`)));\n\t\t\t\t\t}, timeoutSeconds * 1000);\n\t\t\t\t}\n\n\t\t\t\tchild.stdin?.write(wire, (error) => {\n\t\t\t\t\tif (!error) return;\n\t\t\t\t\tthis.killChild();\n\t\t\t\t\tsettle(() => reject(new Error(`Failed to write to ${this.kind} session: ${error.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 spawnChild(cwd: string, env: NodeJS.ProcessEnv): void {\n\t\tconst { shell } = getShellConfig(undefined, this.kind);\n\t\tconst args =\n\t\t\tthis.kind === \"powershell\"\n\t\t\t\t? [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", POWERSHELL_BOOTSTRAP]\n\t\t\t\t: basename(shell).toLowerCase().includes(\"bash\")\n\t\t\t\t\t? [\"--noprofile\", \"--norc\"]\n\t\t\t\t\t: [];\n\t\tconst child = spawn(shell, args, {\n\t\t\tcwd,\n\t\t\tenv,\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) => this.activeExec?.onStdout(data),\n\t\t\tonStderr: (data) => this.activeExec?.onStderr(data),\n\t\t\tonError: (error) => {\n\t\t\t\tthis.resetChildState();\n\t\t\t\tthis.activeExec?.fail(error);\n\t\t\t},\n\t\t\tonClose: (code) => {\n\t\t\t\tthis.resetChildState();\n\t\t\t\tthis.activeExec?.onChildClose(code);\n\t\t\t},\n\t\t});\n\t\tthis.childEnv = env;\n\t\tthis.lastRequestedCwd = cwd;\n\t}\n\n\tprivate resetChildState(): void {\n\t\tthis.childEnv = null;\n\t\tthis.lastRequestedCwd = null;\n\t}\n\n\tprivate killChild(): void {\n\t\tthis.coordinator.kill();\n\t\tthis.resetChildState();\n\t}\n}\n\nconst shellSessions = new Map<string, PersistentShellSession>();\n\n/** Get or lazily create the persistent session for a key. A kind change replaces the session. */\nexport function acquirePersistentShellSession(key: string, kind: PlatformShellToolName): PersistentShellSession {\n\tconst existing = shellSessions.get(key);\n\tif (existing && existing.sessionKind === kind) return existing;\n\texisting?.dispose();\n\tconst session = new PersistentShellSession(key, kind);\n\tshellSessions.set(key, session);\n\treturn session;\n}\n\n/** Kill and forget a session (agent teardown). Safe to call for keys that never spawned. */\nexport function disposePersistentShellSession(key: string): void {\n\tconst session = shellSessions.get(key);\n\tif (!session) return;\n\tshellSessions.delete(key);\n\tsession.dispose();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell-session.js","sourceRoot":"","sources":["../../../src/core/tools/shell-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,WAAW,EAA8B,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,6FAA6F;AAC7F,MAAM,uBAAuB,GAAG,EAA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;QACpB,IAAI,CAAC,gBAAgB,GAAG,GAAG,CAAC;IAC7B,CAAC;IAEO,eAAe;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,CAAC;IAEO,SAAS;QAChB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,eAAe,EAAE,CAAC;IACxB,CAAC;CACD;AAED,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;AAEhE,iGAAiG;AACjG,MAAM,UAAU,6BAA6B,CAAC,GAAW,EAAE,IAA2B;IACrF,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC/D,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACtD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,6BAA6B,CAAC,GAAW;IACxD,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Persistent shell sessions for the bash tool.\n *\n * One long-lived shell process per agent (keyed registry) replaces process-per-command spawning.\n * On Windows every command previously paid a full PowerShell boot; a persistent session pays it\n * once. Shell state (current directory, environment variables) persists across an agent's\n * commands; each key gets an isolated session so concurrently running agents never share state.\n *\n * Protocol: commands stream to the session over stdin and are terminated by a per-command\n * sentinel carrying a random nonce and the exit code. Bash wraps commands in an eval of a quoted\n * heredoc (arbitrary content stays data; syntax errors stay contained in eval); PowerShell runs a\n * ReadLine loop decoding base64 lines (no external binaries involved). On bash, command stderr is\n * merged into stdout at the shell so sentinel ordering is guaranteed on one pipe.\n *\n * PowerShell runs each command as a bare `Invoke-Expression`, NOT piped into `Out-Default`: piping\n * a native command's output into another pipeline stage forces PowerShell's NativeCommandProcessor\n * to capture that child's stdout/stderr into an internal pipe and read it to EOF before the\n * pipeline completes. A detached grandchild that inherited those handles (e.g. `start /b` holding\n * stdio open) then keeps that internal pipe's write end open, so the sentinel — written after the\n * pipeline \"completes\" — waits for the grandchild to die instead of the direct child. The bare\n * invocation lets a native command's stdout/stderr handles be inherited directly by the child\n * process; the direct child's own exit is what unblocks the sentinel line, exactly like the\n * per-command backend and like bash's stdio inheritance above. The bounded consequence: a native\n * command's stderr no longer merges into the session's stdout pipe (there is no capturing pipeline\n * stage to merge it) — it arrives on the session's own stderr pipe instead, forwarded via\n * `onStderr` -> `onData` same as the shell's own diagnostics. PowerShell 5.1's habit of wrapping\n * redirected stderr text in a `NativeCommandError` record also disappears, which is an accuracy\n * improvement (the raw stderr bytes are reported, not a wrapped/duplicated rendering of them).\n *\n * Kill semantics: timeout/abort/silence kill the WHOLE session process tree (a hung foreground\n * command cannot be killed individually without job control) and the next exec respawns a fresh\n * session, losing accumulated shell state by design. A command that exits the shell itself\n * (`exit 3`) reports the shell's exit code and also respawns lazily afterwards.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport { basename } from \"node:path\";\nimport { createSilenceWatchdog } from \"@caupulican/pi-agent-core/reliability\";\nimport { spawn } from \"child_process\";\nimport { getShellConfig, getShellEnv, type PlatformShellToolName } from \"../../utils/shell.ts\";\nimport { PersistentProcessCoordinator } from \"./persistent-process-coordinator.ts\";\n\nconst SENTINEL_BYTE = 0x1e;\n/** Longest possible sentinel: \"\\n\" + 0x1e + 16-hex nonce + \":\" + exit code digits + 0x1e. */\nconst SENTINEL_HOLDBACK_BYTES = 64;\n\nexport interface ShellSessionExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\t/** Wall-clock bound in seconds; when set, a breach kills the session and throws `timeout:<s>`. */\n\ttimeoutSeconds?: number;\n\t/** Output-silence bound in ms; when set, silence kills the session and throws `silence:<s>`. */\n\tsilenceMs?: number;\n\tenv?: NodeJS.ProcessEnv;\n}\n\nfunction escapeSingleQuotesPosix(value: string): string {\n\treturn value.replace(/'/g, \"'\\\\''\");\n}\n\nfunction escapeSingleQuotesPowerShell(value: string): string {\n\treturn value.replace(/'/g, \"''\");\n}\n\n/**\n * The whole command is heredoc-quoted data: eval keeps syntax errors contained (a raw syntax\n * error on the session's stdin would abort the shell), and the random delimiter makes content\n * collisions with agent output practically impossible. `< /dev/null` gives commands the same\n * EOF-stdin the per-command backend's `stdio: [\"ignore\", ...]` provided.\n */\nexport function buildBashWire(command: string, nonce: string, cdTo: string | null): string {\n\tconst body = cdTo ? `command cd -- '${escapeSingleQuotesPosix(cdTo)}' && {\\n${command}\\n}` : command;\n\treturn [\n\t\t`{ eval \"$(cat <<'PI_EOF_${nonce}'`,\n\t\tbody,\n\t\t`PI_EOF_${nonce}`,\n\t\t`)\"; } < /dev/null 2>&1`,\n\t\t`printf '\\\\n\\\\036%s:%s\\\\036' '${nonce}' \"$?\"`,\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\n/** One protocol line: `<nonce> <base64(utf8 command)>`. Base64 keeps arbitrary multi-line commands line-safe. */\nexport function buildPowerShellWire(command: string, nonce: string, cdTo: string | null): string {\n\tconst body = cdTo\n\t\t? `Set-Location -LiteralPath '${escapeSingleQuotesPowerShell(cdTo)}' -ErrorAction Stop\\n${command}`\n\t\t: command;\n\treturn `${nonce} ${Buffer.from(body, \"utf8\").toString(\"base64\")}\\n`;\n}\n\n/**\n * PowerShell 5.1-compatible REPL bootstrap. Exit code mirrors `-Command` semantics as closely as\n * a loop can: a native command's $LASTEXITCODE wins, a terminating error forces 1, otherwise 0.\n * Passed as one direct `-Command` argument. `-EncodedCommand` makes PowerShell serialize host,\n * warning, and progress records as CLIXML on stderr whenever pipes are attached; Pi then sees\n * duplicate XML mixed into the same command's plain stdout. Node preserves this script as one\n * argv entry without involving cmd.exe quoting.\n *\n * The command runs as a bare `Invoke-Expression` (no `2>&1 | Out-Default` capture pipeline) — see\n * the module doc header for why: a native command's stdio handles are inherited directly by its\n * child process instead of being captured through a PowerShell-internal pipe, so the sentinel is\n * unblocked by the direct child's own exit rather than by any grandchild holding those handles.\n */\nconst POWERSHELL_BOOTSTRAP = [\n\t\"$ProgressPreference = 'SilentlyContinue'\",\n\t\"try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}\",\n\t\"function global:__pi_complete_status([int]$Code) { $global:LASTEXITCODE = $Code }\",\n\t\"$__pi_in = [Console]::In\",\n\t\"while ($true) {\",\n\t\"\\t$__pi_line = $__pi_in.ReadLine()\",\n\t\"\\tif ($null -eq $__pi_line) { break }\",\n\t\"\\t$__pi_sp = $__pi_line.IndexOf(' ')\",\n\t\"\\tif ($__pi_sp -lt 1) { continue }\",\n\t\"\\t$__pi_nonce = $__pi_line.Substring(0, $__pi_sp)\",\n\t\"\\t$__pi_cmd = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($__pi_line.Substring($__pi_sp + 1)))\",\n\t\"\\t$global:LASTEXITCODE = $null\",\n\t\"\\t$__pi_thrown = $false\",\n\t\"\\t$__pi_succeeded = $false\",\n\t\"\\ttry { Invoke-Expression $__pi_cmd; $__pi_succeeded = $? } catch { $__pi_thrown = $true; $__pi_msg = ($_ | Out-String).TrimEnd(); if ($__pi_msg) { [Console]::Out.WriteLine($__pi_msg) } }\",\n\t\"\\t$__pi_code = $global:LASTEXITCODE\",\n\t\"\\tif ($null -eq $__pi_code) { $__pi_code = if ($__pi_succeeded) { 0 } else { 1 } }\",\n\t\"\\tif ($__pi_thrown -and ($__pi_code -eq 0)) { $__pi_code = 1 }\",\n\t\"\\t[Console]::Out.Write(('{0}{1}{2}:{3}{1}' -f [char]10, [char]30, $__pi_nonce, $__pi_code))\",\n\t\"}\",\n].join(\"\\n\");\n\nfunction shallowEnvEquals(a: NodeJS.ProcessEnv, b: NodeJS.ProcessEnv): boolean {\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\tfor (const key of aKeys) {\n\t\tif (a[key] !== b[key]) return false;\n\t}\n\treturn true;\n}\n\ninterface ActiveExec {\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 PersistentShellSession {\n\tprivate readonly key: string;\n\tprivate readonly kind: PlatformShellToolName;\n\tprivate readonly coordinator = new PersistentProcessCoordinator();\n\tprivate childEnv: NodeJS.ProcessEnv | null = null;\n\tprivate lastRequestedCwd: string | null = null;\n\tprivate activeExec: ActiveExec | null = null;\n\tprivate disposed = false;\n\n\tconstructor(key: string, kind: PlatformShellToolName) {\n\t\tthis.key = key;\n\t\tthis.kind = kind;\n\t}\n\n\tget sessionKind(): PlatformShellToolName {\n\t\treturn this.kind;\n\t}\n\n\t/** Serialized: one command at a time per session, later calls queue behind earlier ones. */\n\texec(command: string, cwd: string, options: ShellSessionExecOptions): 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\tthis.activeExec?.fail(new Error(`Shell session \"${this.key}\" is disposed`));\n\t\tthis.coordinator.dispose();\n\t\tthis.resetChildState();\n\t}\n\n\tprivate async execNow(\n\t\tcommand: string,\n\t\tcwd: string,\n\t\t{ onData, signal, timeoutSeconds, silenceMs, env }: ShellSessionExecOptions,\n\t): Promise<{ exitCode: number | null }> {\n\t\tif (this.disposed) throw new Error(`Shell session \"${this.key}\" is disposed`);\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\tconst resolvedEnv = env ?? getShellEnv();\n\t\t// The environment is spawn-time shell config: an env that differs from the running\n\t\t// session's (e.g. a spawn hook rewriting it per command) requires a fresh shell.\n\t\tif (this.coordinator.child && this.childEnv && !shallowEnvEquals(this.childEnv, resolvedEnv)) {\n\t\t\tthis.killChild();\n\t\t}\n\n\t\t// Re-enter the host-requested cwd only when it CHANGES between calls; an unchanged\n\t\t// request preserves the agent's own in-session `cd` (that persistence is the feature).\n\t\tlet cdTo: string | null = null;\n\t\tif (!this.coordinator.child) {\n\t\t\tthis.spawnChild(cwd, resolvedEnv);\n\t\t} else if (this.lastRequestedCwd !== cwd) {\n\t\t\tcdTo = cwd;\n\t\t}\n\t\tthis.lastRequestedCwd = cwd;\n\n\t\tconst child = this.coordinator.child;\n\t\tif (!child?.stdin || !child.stdout || !child.stderr) {\n\t\t\tthis.killChild();\n\t\t\tthrow new Error(`Failed to start ${this.kind} session`);\n\t\t}\n\n\t\tconst nonce = randomBytes(8).toString(\"hex\");\n\t\tconst wire =\n\t\t\tthis.kind === \"powershell\" ? buildPowerShellWire(command, nonce, cdTo) : buildBashWire(command, nonce, cdTo);\n\t\tconst sentinelPrefix = Buffer.from(`\\n\\x1e${nonce}:`, \"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 pending: Buffer = Buffer.alloc(0);\n\t\t\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\t\t\tconst silenceWatchdog =\n\t\t\t\t\ttimeoutSeconds === undefined && silenceMs !== undefined && silenceMs > 0\n\t\t\t\t\t\t? createSilenceWatchdog({\n\t\t\t\t\t\t\t\tsilenceMs,\n\t\t\t\t\t\t\t\tonSilence: () => {\n\t\t\t\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\t\t\t\tsettle(() => reject(new Error(`silence:${silenceMs / 1000}`)));\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\tconst settle = (finish: () => 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\tsilenceWatchdog?.disarm();\n\t\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.activeExec = null;\n\t\t\t\t\tfinish();\n\t\t\t\t};\n\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tthis.killChild();\n\t\t\t\t\tsettle(() => reject(new Error(\"aborted\")));\n\t\t\t\t};\n\n\t\t\t\tconst emitPending = (upTo: number) => {\n\t\t\t\t\tif (upTo <= 0) return;\n\t\t\t\t\tonData(pending.subarray(0, upTo));\n\t\t\t\t\tpending = pending.subarray(upTo);\n\t\t\t\t};\n\n\t\t\t\tthis.activeExec = {\n\t\t\t\t\tonStdout: (data) => {\n\t\t\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\t\t\tpending = pending.length === 0 ? data : Buffer.concat([pending, data]);\n\t\t\t\t\t\tconst prefixIndex = pending.indexOf(sentinelPrefix);\n\t\t\t\t\t\tif (prefixIndex !== -1) {\n\t\t\t\t\t\t\tconst closeIndex = pending.indexOf(SENTINEL_BYTE, prefixIndex + sentinelPrefix.length);\n\t\t\t\t\t\t\tif (closeIndex !== -1) {\n\t\t\t\t\t\t\t\tconst codeText = pending\n\t\t\t\t\t\t\t\t\t.subarray(prefixIndex + sentinelPrefix.length, closeIndex)\n\t\t\t\t\t\t\t\t\t.toString(\"latin1\");\n\t\t\t\t\t\t\t\temitPending(prefixIndex);\n\t\t\t\t\t\t\t\tconst parsed = Number.parseInt(codeText, 10);\n\t\t\t\t\t\t\t\t// Defer the settle by one microtask turn: with the bare Invoke-Expression\n\t\t\t\t\t\t\t\t// form a native command's stderr now arrives on the session's OWN stderr\n\t\t\t\t\t\t\t\t// pipe (see module doc header) instead of being pre-merged into the same\n\t\t\t\t\t\t\t\t// stdout bytes the sentinel rides on. Node fires already-queued stream\n\t\t\t\t\t\t\t\t// 'data' events in event-loop order; queueing the resolution behind a\n\t\t\t\t\t\t\t\t// microtask guarantees any stderr chunk the kernel delivered alongside (or\n\t\t\t\t\t\t\t\t// just before) this stdout chunk has already run its 'data' handler — and\n\t\t\t\t\t\t\t\t// thus reached `onData` — before the promise settles, so callers never see a\n\t\t\t\t\t\t\t\t// truncated stderr tail immediately after resolution.\n\t\t\t\t\t\t\t\tqueueMicrotask(() => settle(() => resolve({ exitCode: Number.isNaN(parsed) ? null : parsed })));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Stream promptly but retain a tail large enough to hold any split sentinel.\n\t\t\t\t\t\temitPending(pending.length - SENTINEL_HOLDBACK_BYTES);\n\t\t\t\t\t},\n\t\t\t\t\tonStderr: (data) => {\n\t\t\t\t\t\t// The command's stderr is merged into stdout at the shell; this pipe only\n\t\t\t\t\t\t// carries the session shell's own diagnostics. Forward for visibility.\n\t\t\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\t\t\tonData(data);\n\t\t\t\t\t},\n\t\t\t\t\tonChildClose: (code) => {\n\t\t\t\t\t\t// The command terminated the shell itself (e.g. `exit 3`) or the shell\n\t\t\t\t\t\t// crashed: report its exit code like the per-command backend would.\n\t\t\t\t\t\temitPending(pending.length);\n\t\t\t\t\t\tsettle(() => resolve({ exitCode: code }));\n\t\t\t\t\t},\n\t\t\t\t\tfail: (error) => {\n\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\tsettle(() => reject(error));\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tif (signal) signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\tif (timeoutSeconds !== undefined && timeoutSeconds > 0) {\n\t\t\t\t\ttimeoutTimer = setTimeout(() => {\n\t\t\t\t\t\tthis.killChild();\n\t\t\t\t\t\tsettle(() => reject(new Error(`timeout:${timeoutSeconds}`)));\n\t\t\t\t\t}, timeoutSeconds * 1000);\n\t\t\t\t}\n\n\t\t\t\tchild.stdin?.write(wire, (error) => {\n\t\t\t\t\tif (!error) return;\n\t\t\t\t\tthis.killChild();\n\t\t\t\t\tsettle(() => reject(new Error(`Failed to write to ${this.kind} session: ${error.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 spawnChild(cwd: string, env: NodeJS.ProcessEnv): void {\n\t\tconst { shell } = getShellConfig(undefined, this.kind);\n\t\tconst args =\n\t\t\tthis.kind === \"powershell\"\n\t\t\t\t? [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", POWERSHELL_BOOTSTRAP]\n\t\t\t\t: basename(shell).toLowerCase().includes(\"bash\")\n\t\t\t\t\t? [\"--noprofile\", \"--norc\"]\n\t\t\t\t\t: [];\n\t\tconst child = spawn(shell, args, {\n\t\t\tcwd,\n\t\t\tenv,\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) => this.activeExec?.onStdout(data),\n\t\t\tonStderr: (data) => this.activeExec?.onStderr(data),\n\t\t\tonError: (error) => {\n\t\t\t\tthis.resetChildState();\n\t\t\t\tthis.activeExec?.fail(error);\n\t\t\t},\n\t\t\tonClose: (code) => {\n\t\t\t\tthis.resetChildState();\n\t\t\t\tthis.activeExec?.onChildClose(code);\n\t\t\t},\n\t\t});\n\t\tthis.childEnv = env;\n\t\tthis.lastRequestedCwd = cwd;\n\t}\n\n\tprivate resetChildState(): void {\n\t\tthis.childEnv = null;\n\t\tthis.lastRequestedCwd = null;\n\t}\n\n\tprivate killChild(): void {\n\t\tthis.coordinator.kill();\n\t\tthis.resetChildState();\n\t}\n}\n\nconst shellSessions = new Map<string, PersistentShellSession>();\n\n/** Get or lazily create the persistent session for a key. A kind change replaces the session. */\nexport function acquirePersistentShellSession(key: string, kind: PlatformShellToolName): PersistentShellSession {\n\tconst existing = shellSessions.get(key);\n\tif (existing && existing.sessionKind === kind) return existing;\n\texisting?.dispose();\n\tconst session = new PersistentShellSession(key, kind);\n\tshellSessions.set(key, session);\n\treturn session;\n}\n\n/** Kill and forget a session (agent teardown). Safe to call for keys that never spawned. */\nexport function disposePersistentShellSession(key: string): void {\n\tconst session = shellSessions.get(key);\n\tif (!session) return;\n\tshellSessions.delete(key);\n\tsession.dispose();\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ArtifactRetrieveToolOptions } from "./artifact-retrieve.ts";
|
|
2
|
+
import { type BashToolOptions } from "./bash.ts";
|
|
3
|
+
import { type EditToolOptions } from "./edit.ts";
|
|
4
|
+
import { type ExtensionifyRuntimeOptions } from "./extensionify-runtime.ts";
|
|
5
|
+
import { type FindToolOptions } from "./find.ts";
|
|
6
|
+
import { type GrepToolOptions } from "./grep.ts";
|
|
7
|
+
import { type LsToolOptions } from "./ls.ts";
|
|
8
|
+
import { type PythonToolOptions } from "./python.ts";
|
|
9
|
+
import { type ReadToolOptions } from "./read.ts";
|
|
10
|
+
import { type SkillAuditToolOptions } from "./skill-audit.ts";
|
|
11
|
+
import { type SkillifyToolOptions } from "./skillify.ts";
|
|
12
|
+
import { type WriteToolOptions } from "./write.ts";
|
|
13
|
+
export type ToolDef = ToolDefinition<any, any>;
|
|
14
|
+
export type ToolName = "read" | "bash" | "python" | "edit" | "write" | "grep" | "find" | "ls" | "skill_audit" | "skillify" | "extensionify" | "artifact_retrieve";
|
|
15
|
+
export declare const allToolNames: ReadonlySet<ToolName>;
|
|
16
|
+
export interface ToolDefinitionOptions {
|
|
17
|
+
read?: ReadToolOptions;
|
|
18
|
+
bash?: BashToolOptions;
|
|
19
|
+
python?: PythonToolOptions;
|
|
20
|
+
write?: WriteToolOptions;
|
|
21
|
+
edit?: EditToolOptions;
|
|
22
|
+
grep?: GrepToolOptions;
|
|
23
|
+
find?: FindToolOptions;
|
|
24
|
+
ls?: LsToolOptions;
|
|
25
|
+
skill_audit?: SkillAuditToolOptions;
|
|
26
|
+
skillify?: SkillifyToolOptions;
|
|
27
|
+
extensionify: ExtensionifyRuntimeOptions;
|
|
28
|
+
artifact_retrieve?: ArtifactRetrieveToolOptions;
|
|
29
|
+
}
|
|
30
|
+
export declare function createToolDefinitionWithRuntime(toolName: ToolName, cwd: string, options: ToolDefinitionOptions): ToolDef;
|
|
31
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
32
|
+
//# sourceMappingURL=tool-definition-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-definition-factory.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAwC,MAAM,wBAAwB,CAAC;AAChH,OAAO,EAAE,KAAK,eAAe,EAA4B,MAAM,WAAW,CAAC;AAC3E,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAEN,KAAK,0BAA0B,EAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAA8B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAkC,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAgC,KAAK,mBAAmB,EAAE,MAAM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