@caupulican/pi-adaptative 0.81.39 → 0.81.41
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 +77 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +3 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +4 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +31 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +25 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +79 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +293 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -0
- package/dist/core/agent-session-contracts.js +26 -0
- package/dist/core/agent-session-contracts.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +400 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +74 -518
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +370 -1432
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +48 -9
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +56 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +141 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts +16 -0
- package/dist/core/bedrock-sso-login.d.ts.map +1 -0
- package/dist/core/bedrock-sso-login.js +98 -0
- package/dist/core/bedrock-sso-login.js.map +1 -0
- package/dist/core/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +13 -17
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +3 -3
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +16 -37
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +5 -3
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +4 -5
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +2 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/extension-import-authority.d.ts +6 -0
- package/dist/core/extension-import-authority.d.ts.map +1 -0
- package/dist/core/extension-import-authority.js +10 -0
- package/dist/core/extension-import-authority.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.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +52 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +20 -5
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts +2 -0
- package/dist/core/extensions/stale-context.d.ts.map +1 -0
- package/dist/core/extensions/stale-context.js +2 -0
- package/dist/core/extensions/stale-context.js.map +1 -0
- package/dist/core/extensions/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +78 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +53 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts +14 -9
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +47 -75
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +11 -0
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
- package/dist/core/goals/compact-goal-context.js +59 -0
- package/dist/core/goals/compact-goal-context.js.map +1 -0
- package/dist/core/goals/goal-acceptance.d.ts +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +27 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +90 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +52 -11
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.js +4 -32
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +9 -179
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +43 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +102 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-record.d.ts +17 -0
- package/dist/core/goals/goal-record.d.ts.map +1 -0
- package/dist/core/goals/goal-record.js +31 -0
- package/dist/core/goals/goal-record.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +42 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-session-controller.js +128 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +46 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +91 -24
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +9 -10
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +60 -75
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +20 -12
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +133 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input-controller.d.ts +47 -0
- package/dist/core/human-input-controller.d.ts.map +1 -0
- package/dist/core/human-input-controller.js +181 -0
- package/dist/core/human-input-controller.js.map +1 -0
- package/dist/core/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/local-runtime-controller.d.ts +1 -1
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.js.map +1 -1
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -19
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts +6 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -5
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +17 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +38 -25
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +5 -5
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +200 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts +8 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +23 -5
- package/dist/core/profile-filter-controller.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +5 -5
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +5 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/request-auth.d.ts +7 -0
- package/dist/core/request-auth.d.ts.map +1 -0
- package/dist/core/request-auth.js +8 -0
- package/dist/core/request-auth.js.map +1 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +233 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +41 -23
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +365 -253
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +68 -25
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.js +241 -0
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +27 -0
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
- package/dist/core/secrets/secret-dotenv.js +183 -0
- package/dist/core/secrets/secret-dotenv.js.map +1 -0
- package/dist/core/secrets/secret-vault-format.d.ts +112 -0
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault-format.js +397 -0
- package/dist/core/secrets/secret-vault-format.js.map +1 -0
- package/dist/core/secrets/secret-vault.d.ts +72 -0
- package/dist/core/secrets/secret-vault.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault.js +671 -0
- package/dist/core/secrets/secret-vault.js.map +1 -0
- package/dist/core/session-analytics.d.ts +4 -23
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +67 -70
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +11 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +24 -5
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- package/dist/core/session-tree-navigator.d.ts +4 -6
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +4 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +81 -29
- 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 +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +86 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +89 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-recovery-stats.d.ts +21 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +59 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +148 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +106 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -8
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +2 -63
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +10 -8
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +106 -28
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +40 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +124 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -3
- package/dist/core/tools/output-accumulator.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 +3 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- package/dist/core/tools/search-command-guard.d.ts +14 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -0
- package/dist/core/tools/search-command-guard.js +333 -0
- package/dist/core/tools/search-command-guard.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts +38 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -0
- package/dist/core/tools/secret-store.js +412 -0
- package/dist/core/tools/secret-store.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +16 -0
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
- package/dist/core/tools/shell-command-parser.js +113 -0
- package/dist/core/tools/shell-command-parser.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +99 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +6 -2
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +4 -4
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -51
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
- package/dist/modes/interactive/components/activity-lane.js +304 -0
- package/dist/modes/interactive/components/activity-lane.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +19 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-text.js +17 -0
- package/dist/modes/interactive/components/expandable-text.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +30 -21
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +53 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +3 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/usage-action-selector.js +46 -0
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +77 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +15 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +27 -19
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts +6 -2
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js +10 -5
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-event-controller.js +328 -0
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +22 -24
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +245 -595
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
- package/dist/modes/interactive/loaded-resources-view.js +147 -0
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js +8 -2
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +0 -5
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +27 -8
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +150 -64
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/interactive/usage-commands.d.ts +34 -0
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
- package/dist/modes/interactive/usage-commands.js +225 -0
- package/dist/modes/interactive/usage-commands.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +5 -3
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +38 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +28 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/providers.md +9 -1
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +14 -0
- package/docs/ui-reference/orchestration-before.txt +13 -0
- package/docs/ui-reference/orchestration-reference.txt +16 -0
- package/docs/usage.md +22 -2
- package/docs/work-directory.md +19 -8
- 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/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- 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 +13 -13
- package/package.json +4 -4
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-process.js","sourceRoot":"","sources":["../../../src/core/tools/run-process.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAGhG,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CACnC;IACC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,8CAA8C,EAAE,CAAC;IACxF,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,+CAA+C,EAAE,CAAC,CAAC;CAChH,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAkBF,MAAM,0BAA0B,GAAG;IAClC,MAAM;IACN,SAAS;IACT,YAAY;I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AE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;wBAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;qBACD;iBAC7B,CAAC;YACH,CAAC;oBAAS,CAAC;gBACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC5C,gBAAgB,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC7D,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW,EAAE,OAA8B,EAAa;IAC5F,OAAO,kBAAkB,CAAC,8BAA8B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACxE","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { OrchestrationExecutionPolicy } from \"../orchestration/contracts.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst runProcessSchema = Type.Object(\n\t{\n\t\texecutable: Type.String({ description: \"Exact owner-allowed executable name or path.\" }),\n\t\targs: Type.Optional(Type.Array(Type.String(), { description: \"Direct argv entries. No shell parsing occurs.\" })),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunProcessInput = Static<typeof runProcessSchema>;\n\nexport interface RunProcessDetails {\n\toutcome: \"exited\" | \"failed\" | \"aborted\" | \"timeout\" | \"output_limit\";\n\texecutable: string;\n\texitCode: number | null;\n\tdurationMs: number;\n\ttruncated: boolean;\n}\n\nexport interface RunProcessToolOptions {\n\tpolicy: OrchestrationExecutionPolicy;\n\tmaxWallClockMs: number;\n\tspawn?: typeof spawnProcess;\n}\n\nconst SAFE_ENVIRONMENT_VARIABLES = [\n\t\"PATH\",\n\t\"PATHEXT\",\n\t\"SystemRoot\",\n\t\"WINDIR\",\n\t\"COMSPEC\",\n\t\"TMPDIR\",\n\t\"TMP\",\n\t\"TEMP\",\n] as const;\n\nfunction scopedEnvironment(allowedNames: readonly string[]): NodeJS.ProcessEnv {\n\tconst names = new Set<string>([...SAFE_ENVIRONMENT_VARIABLES, ...allowedNames]);\n\tconst environment: NodeJS.ProcessEnv = {};\n\tfor (const name of names) {\n\t\tconst value = process.env[name];\n\t\tif (value !== undefined) environment[name] = value;\n\t}\n\treturn environment;\n}\n\nfunction collectBoundedOutput(\n\tchild: ChildProcess,\n\tmaxBytes: number,\n\tabort: () => void,\n): {\n\tread(): { stdout: string; stderr: string; truncated: boolean };\n} {\n\tlet remaining = maxBytes;\n\tlet truncated = false;\n\tconst stdout: Buffer[] = [];\n\tconst stderr: Buffer[] = [];\n\tconst collect = (target: Buffer[]) => (chunk: Buffer) => {\n\t\tif (remaining <= 0) return;\n\t\tconst retained = chunk.subarray(0, remaining);\n\t\ttarget.push(retained);\n\t\tremaining -= retained.length;\n\t\tif (retained.length < chunk.length || remaining === 0) {\n\t\t\ttruncated = true;\n\t\t\tabort();\n\t\t}\n\t};\n\tchild.stdout?.on(\"data\", collect(stdout));\n\tchild.stderr?.on(\"data\", collect(stderr));\n\treturn {\n\t\tread: () => ({\n\t\t\tstdout: Buffer.concat(stdout).toString(\"utf-8\"),\n\t\t\tstderr: Buffer.concat(stderr).toString(\"utf-8\"),\n\t\t\ttruncated,\n\t\t}),\n\t};\n}\n\nexport function createRunProcessToolDefinition(cwd: string, options: RunProcessToolOptions): ToolDefinition {\n\tconst allowedExecutables = new Set(options.policy.allowedExecutables);\n\treturn {\n\t\tname: \"run_process\",\n\t\tlabel: \"Run Process\",\n\t\tdescription: `Run one owner-allowed executable using direct argv without a shell. Allowed: ${options.policy.allowedExecutables.join(\", \")}.`,\n\t\tpromptSnippet: \"Run an owner-allowed executable through a constrained direct-argv launcher (not OS isolation).\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use only an executable listed by the profile. Arguments are passed literally; shell operators and interpolation are unavailable.\",\n\t\t\t\"Treat a non-zero exit code, timeout, abort, or output-limit termination as failure.\",\n\t\t],\n\t\tparameters: runProcessSchema,\n\t\tasync execute(_toolCallId, input: RunProcessInput, signal) {\n\t\t\tif (!allowedExecutables.has(input.executable)) {\n\t\t\t\tthrow new Error(`process_executable_denied: '${input.executable}' is not owner-allowed.`);\n\t\t\t}\n\t\t\tconst args = input.args ?? [];\n\t\t\tif (input.executable.includes(\"\\0\") || args.some((argument) => argument.includes(\"\\0\"))) {\n\t\t\t\tthrow new Error(\"process_argument_invalid: executable and argv must not contain NUL bytes.\");\n\t\t\t}\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst outputLimitAbort = new AbortController();\n\t\t\tlet outputLimitReached = false;\n\t\t\tconst child = (options.spawn ?? spawnProcess)(input.executable, [...args], {\n\t\t\t\tcwd,\n\t\t\t\tenv: scopedEnvironment(options.policy.allowedEnvironmentVariables),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tconst output = collectBoundedOutput(child, options.policy.maxOutputBytes, () => {\n\t\t\t\toutputLimitReached = true;\n\t\t\t\toutputLimitAbort.abort();\n\t\t\t});\n\t\t\tconst combinedAbort = new AbortController();\n\t\t\tconst abort = () => combinedAbort.abort();\n\t\t\tif (signal?.aborted || outputLimitAbort.signal.aborted) abort();\n\t\t\telse {\n\t\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\toutputLimitAbort.signal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: combinedAbort.signal,\n\t\t\t\t\ttimeoutMs: options.maxWallClockMs > 0 ? options.maxWallClockMs : undefined,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tconst captured = output.read();\n\t\t\t\tconst outcome: RunProcessDetails[\"outcome\"] = outputLimitReached\n\t\t\t\t\t? \"output_limit\"\n\t\t\t\t\t: terminal.reason === \"timeout\"\n\t\t\t\t\t\t? \"timeout\"\n\t\t\t\t\t\t: terminal.reason === \"aborted\"\n\t\t\t\t\t\t\t? \"aborted\"\n\t\t\t\t\t\t\t: terminal.code === 0\n\t\t\t\t\t\t\t\t? \"exited\"\n\t\t\t\t\t\t\t\t: \"failed\";\n\t\t\t\tconst body = [\n\t\t\t\t\t`outcome: ${outcome}`,\n\t\t\t\t\t`exitCode: ${terminal.code ?? \"null\"}`,\n\t\t\t\t\tcaptured.stdout ? `stdout:\\n${captured.stdout}` : \"stdout: (empty)\",\n\t\t\t\t\tcaptured.stderr ? `stderr:\\n${captured.stderr}` : \"stderr: (empty)\",\n\t\t\t\t].join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\texecutable: input.executable,\n\t\t\t\t\t\texitCode: terminal.code,\n\t\t\t\t\t\tdurationMs: Date.now() - startedAt,\n\t\t\t\t\t\ttruncated: captured.truncated,\n\t\t\t\t\t} satisfies RunProcessDetails,\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\toutputLimitAbort.signal.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function createRunProcessTool(cwd: string, options: RunProcessToolOptions): AgentTool {\n\treturn wrapToolDefinition(createRunProcessToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const BROAD_SEARCH_OUTPUT_ROUTE: "route-to-file";
|
|
2
|
+
export type SearchScopeAssessment = {
|
|
3
|
+
kind: "scoped";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "broad";
|
|
6
|
+
searchTool: "rg" | "grep" | "find" | "fd";
|
|
7
|
+
reason: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Reject shell searches whose filesystem scope cannot be proven narrow. Dedicated grep/find
|
|
11
|
+
* tools already own result caps and artifacts; this closes the raw-shell bypass before execution.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assessShellSearchScope(command: string, cwd: string): SearchScopeAssessment;
|
|
14
|
+
//# sourceMappingURL=search-command-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-command-guard.d.ts","sourceRoot":"","sources":["../../../src/core/tools/search-command-guard.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,iBAA2B,CAAC;AAElE,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA4ShF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB,CA4B1F","sourcesContent":["import { homedir } from \"node:os\";\nimport { basename, resolve } from \"node:path\";\nimport { tokenizeShellCommand } from \"./shell-command-parser.ts\";\n\nexport const BROAD_SEARCH_OUTPUT_ROUTE = \"route-to-file\" as const;\n\nexport type SearchScopeAssessment =\n\t| { kind: \"scoped\" }\n\t| { kind: \"broad\"; searchTool: \"rg\" | \"grep\" | \"find\" | \"fd\"; reason: string };\n\nconst RG_LONG_VALUE_FLAGS = new Set([\n\t\"--after-context\",\n\t\"--before-context\",\n\t\"--color\",\n\t\"--colors\",\n\t\"--context\",\n\t\"--context-separator\",\n\t\"--encoding\",\n\t\"--engine\",\n\t\"--field-context-separator\",\n\t\"--field-match-separator\",\n\t\"--glob\",\n\t\"--iglob\",\n\t\"--ignore-file\",\n\t\"--max-columns\",\n\t\"--max-count\",\n\t\"--max-depth\",\n\t\"--max-filesize\",\n\t\"--path-separator\",\n\t\"--pre\",\n\t\"--pre-glob\",\n\t\"--replace\",\n\t\"--sort\",\n\t\"--sortr\",\n\t\"--threads\",\n\t\"--type\",\n\t\"--type-add\",\n\t\"--type-clear\",\n\t\"--type-not\",\n]);\nconst RG_SHORT_VALUE_FLAGS = new Set(\"ABCEMTdfgjmrt\".split(\"\"));\nconst RG_SCOPE_LONG_FLAGS = new Set([\"--glob\", \"--iglob\", \"--max-depth\", \"--type\", \"--type-not\"]);\nconst RG_SCOPE_SHORT_FLAGS = new Set([\"g\", \"t\", \"T\"]);\nconst RG_META_FLAGS = new Set([\"--generate\", \"--help\", \"--pcre2-version\", \"--type-list\", \"--version\", \"-h\"]);\n\ntype TargetScope = \"current\" | \"global\" | \"narrow\";\n\nfunction targetScope(target: string, cwd: string): TargetScope {\n\tconst normalized = target.trim().replace(/[\\\\/]+$/u, \"\") || target.trim();\n\tif (\n\t\tnormalized === \"/\" ||\n\t\tnormalized === \"\\\\\" ||\n\t\t/^[A-Za-z]:$/u.test(normalized) ||\n\t\tnormalized === \"~\" ||\n\t\tnormalized === \"$HOME\" ||\n\t\tnormalized === \"%USERPROFILE%\" ||\n\t\tresolve(normalized) === resolve(homedir())\n\t) {\n\t\treturn \"global\";\n\t}\n\tif (\n\t\tnormalized === \".\" ||\n\t\tnormalized === \"*\" ||\n\t\tnormalized === \"**\" ||\n\t\tnormalized === \"./*\" ||\n\t\tnormalized === \"./**\" ||\n\t\tnormalized === \"$PWD\" ||\n\t\tnormalized === \"$(pwd)\" ||\n\t\tnormalized === \"%CD%\" ||\n\t\tresolve(cwd, normalized) === resolve(cwd)\n\t)\n\t\treturn \"current\";\n\treturn \"narrow\";\n}\n\nfunction hasSafeTarget(targets: string[], cwd: string, hasScopeFilter: boolean): boolean {\n\tif (targets.includes(\"-\")) return true;\n\tconst scopes = (targets.length > 0 ? targets : [\".\"]).map((target) => targetScope(target, cwd));\n\tif (scopes.includes(\"global\")) return false;\n\treturn scopes.includes(\"narrow\") || hasScopeFilter;\n}\n\ninterface RgArguments {\n\tfilesMode: boolean;\n\thasPatternOption: boolean;\n\thasScopeFilter: boolean;\n\tmetaOnly: boolean;\n\tpositionals: string[];\n}\n\nfunction parseRgArguments(args: string[]): RgArguments {\n\tconst parsed: RgArguments = {\n\t\tfilesMode: false,\n\t\thasPatternOption: false,\n\t\thasScopeFilter: false,\n\t\tmetaOnly: false,\n\t\tpositionals: [],\n\t};\n\tlet pastDoubleDash = false;\n\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) {\n\t\t\tparsed.positionals.push(arg);\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--\") {\n\t\t\tpastDoubleDash = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (RG_META_FLAGS.has(arg)) {\n\t\t\tparsed.metaOnly = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--files\") {\n\t\t\tparsed.filesMode = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--regexp\" || arg === \"--file\") {\n\t\t\tparsed.hasPatternOption = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"--regexp=\") || arg.startsWith(\"--file=\")) {\n\t\t\tparsed.hasPatternOption = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"--\")) {\n\t\t\tconst flag = arg.split(\"=\", 1)[0];\n\t\t\tif (RG_SCOPE_LONG_FLAGS.has(flag)) parsed.hasScopeFilter = true;\n\t\t\tif (RG_LONG_VALUE_FLAGS.has(flag) && !arg.includes(\"=\")) index++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\") && arg.length > 1) {\n\t\t\tconst cluster = arg.slice(1);\n\t\t\tfor (let flagIndex = 0; flagIndex < cluster.length; flagIndex++) {\n\t\t\t\tconst flag = cluster[flagIndex];\n\t\t\t\tif (flag === \"e\" || flag === \"f\") parsed.hasPatternOption = true;\n\t\t\t\tif (RG_SCOPE_SHORT_FLAGS.has(flag)) parsed.hasScopeFilter = true;\n\t\t\t\tif (flag === \"e\" || RG_SHORT_VALUE_FLAGS.has(flag)) {\n\t\t\t\t\tif (flagIndex === cluster.length - 1) index++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tparsed.positionals.push(arg);\n\t}\n\n\treturn parsed;\n}\n\nfunction assessRg(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst parsed = parseRgArguments(args);\n\tif (parsed.metaOnly) return { kind: \"scoped\" };\n\tconst targets = parsed.filesMode\n\t\t? parsed.positionals\n\t\t: parsed.hasPatternOption\n\t\t\t? parsed.positionals\n\t\t\t: parsed.positionals.slice(1);\n\tif (readsPipe && targets.length === 0 && !parsed.filesMode) return { kind: \"scoped\" };\n\tif (hasSafeTarget(targets, cwd, parsed.hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"rg\",\n\t\treason: \"rg would search the whole working tree without a narrow path, glob, or type filter\",\n\t};\n}\n\nfunction assessRecursiveGrep(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst recursive = args.some(\n\t\t(arg) => arg === \"-r\" || arg === \"-R\" || arg === \"--recursive\" || /^-[^-]*[rR]/u.test(arg),\n\t);\n\tif (!recursive || readsPipe) return { kind: \"scoped\" };\n\tconst hasPatternOption = args.some((arg) => arg === \"-e\" || arg.startsWith(\"-e\") || arg === \"--regexp\");\n\tconst hasScopeFilter = args.some(\n\t\t(arg) =>\n\t\t\targ === \"--include\" ||\n\t\t\targ.startsWith(\"--include=\") ||\n\t\t\targ === \"--exclude\" ||\n\t\t\targ.startsWith(\"--exclude=\") ||\n\t\t\targ === \"--exclude-dir\" ||\n\t\t\targ.startsWith(\"--exclude-dir=\"),\n\t);\n\tconst valueFlags = new Set([\"-A\", \"-B\", \"-C\", \"-D\", \"-d\", \"-e\", \"-f\", \"-m\", \"--regexp\"]);\n\tconst positionals: string[] = [];\n\tlet pastDoubleDash = false;\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) positionals.push(arg);\n\t\telse if (arg === \"--\") pastDoubleDash = true;\n\t\telse if (valueFlags.has(arg) || [\"--include\", \"--exclude\", \"--exclude-dir\"].includes(arg)) index++;\n\t\telse if (!arg.startsWith(\"-\")) positionals.push(arg);\n\t}\n\tconst targets = hasPatternOption ? positionals : positionals.slice(1);\n\tif (hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"grep\",\n\t\treason: \"recursive grep would scan the whole working tree without a narrow path or include filter\",\n\t};\n}\n\nfunction assessFind(args: string[], cwd: string): SearchScopeAssessment {\n\tlet index = 0;\n\twhile (index < args.length) {\n\t\tconst arg = args[index];\n\t\tif (arg === \"-H\" || arg === \"-L\" || arg === \"-P\" || /^-O\\d*$/u.test(arg)) index++;\n\t\telse if (arg === \"-D\") index += 2;\n\t\telse break;\n\t}\n\tconst targets: string[] = [];\n\twhile (index < args.length && !args[index].startsWith(\"-\") && args[index] !== \"!\" && args[index] !== \"(\") {\n\t\ttargets.push(args[index++]);\n\t}\n\tconst hasScopeFilter = args.some((arg) => [\"-iname\", \"-ipath\", \"-iregex\", \"-name\", \"-path\", \"-regex\"].includes(arg));\n\tif (hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"find\",\n\t\treason: \"find would enumerate the whole working tree without a narrow path or name/path predicate\",\n\t};\n}\n\nfunction assessFd(args: string[], cwd: string): SearchScopeAssessment {\n\tconst positionals: string[] = [];\n\tlet hasScopeFilter = false;\n\tlet pastDoubleDash = false;\n\tconst valueFlags = new Set([\n\t\t\"-d\",\n\t\t\"--max-depth\",\n\t\t\"--min-depth\",\n\t\t\"-e\",\n\t\t\"--extension\",\n\t\t\"-E\",\n\t\t\"--exclude\",\n\t\t\"-t\",\n\t\t\"--type\",\n\t\t\"--base-directory\",\n\t\t\"--changed-before\",\n\t\t\"--changed-within\",\n\t\t\"--color\",\n\t\t\"--owner\",\n\t\t\"--path-separator\",\n\t\t\"--search-path\",\n\t]);\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) positionals.push(arg);\n\t\telse if (arg === \"--\") pastDoubleDash = true;\n\t\telse if (arg === \"-e\" || arg === \"--extension\") {\n\t\t\thasScopeFilter = true;\n\t\t\tindex++;\n\t\t} else if (arg.startsWith(\"--extension=\")) hasScopeFilter = true;\n\t\telse if (valueFlags.has(arg)) index++;\n\t\telse if (!arg.startsWith(\"-\")) positionals.push(arg);\n\t}\n\tconst pattern = positionals[0];\n\tconst targets = positionals.slice(1);\n\tconst meaningfulPattern = Boolean(pattern && pattern !== \".\" && pattern !== \".*\" && pattern !== \"*\");\n\tif (meaningfulPattern || hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"fd\",\n\t\treason: \"fd would enumerate the whole working tree without a narrow pattern, path, glob, extension, or type\",\n\t};\n}\n\nfunction commandName(value: string): string {\n\treturn basename(value)\n\t\t.toLowerCase()\n\t\t.replace(/\\.exe$/u, \"\");\n}\n\nfunction stripInvocationPrefixes(args: string[]): string[] {\n\tlet index = 0;\n\twhile (index < args.length && /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index])) index++;\n\tif (args[index] === \"command\") {\n\t\tindex++;\n\t\twhile (args[index]?.startsWith(\"-\")) index++;\n\t}\n\tif (args[index] === \"env\") {\n\t\tindex++;\n\t\twhile (args[index]?.startsWith(\"-\") || /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index] ?? \"\")) index++;\n\t}\n\treturn args.slice(index);\n}\n\nfunction assessInvocation(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst invocation = stripInvocationPrefixes(args);\n\tconst name = commandName(invocation[0] ?? \"\");\n\tconst commandArgs = invocation.slice(1);\n\tswitch (name) {\n\t\tcase \"rg\":\n\t\tcase \"ripgrep\":\n\t\t\treturn assessRg(commandArgs, cwd, readsPipe);\n\t\tcase \"grep\":\n\t\t\treturn assessRecursiveGrep(commandArgs, cwd, readsPipe);\n\t\tcase \"find\":\n\t\t\treturn assessFind(commandArgs, cwd);\n\t\tcase \"fd\":\n\t\tcase \"fdfind\":\n\t\t\treturn assessFd(commandArgs, cwd);\n\t\tdefault:\n\t\t\treturn { kind: \"scoped\" };\n\t}\n}\n\n/**\n * Reject shell searches whose filesystem scope cannot be proven narrow. Dedicated grep/find\n * tools already own result caps and artifacts; this closes the raw-shell bypass before execution.\n */\nexport function assessShellSearchScope(command: string, cwd: string): SearchScopeAssessment {\n\tconst tokens = tokenizeShellCommand(command);\n\tif (!tokens) {\n\t\treturn { kind: \"scoped\" };\n\t}\n\n\tlet invocation: string[] = [];\n\tlet ignoreRedirectTarget = false;\n\tlet readsPipe = false;\n\tconst assessCurrent = (): SearchScopeAssessment => assessInvocation(invocation, cwd, readsPipe);\n\n\tfor (const token of tokens) {\n\t\tif (token.kind === \"arg\") {\n\t\t\tif (!ignoreRedirectTarget) invocation.push(token.value);\n\t\t\tcontinue;\n\t\t}\n\t\tif (token.kind === \"redirect\") {\n\t\t\tignoreRedirectTarget = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst assessment = assessCurrent();\n\t\tif (assessment.kind === \"broad\") return assessment;\n\t\tinvocation = [];\n\t\tignoreRedirectTarget = false;\n\t\treadsPipe = token.kind === \"pipe\";\n\t}\n\n\treturn assessCurrent();\n}\n"]}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { basename, resolve } from "node:path";
|
|
3
|
+
import { tokenizeShellCommand } from "./shell-command-parser.js";
|
|
4
|
+
export const BROAD_SEARCH_OUTPUT_ROUTE = "route-to-file";
|
|
5
|
+
const RG_LONG_VALUE_FLAGS = new Set([
|
|
6
|
+
"--after-context",
|
|
7
|
+
"--before-context",
|
|
8
|
+
"--color",
|
|
9
|
+
"--colors",
|
|
10
|
+
"--context",
|
|
11
|
+
"--context-separator",
|
|
12
|
+
"--encoding",
|
|
13
|
+
"--engine",
|
|
14
|
+
"--field-context-separator",
|
|
15
|
+
"--field-match-separator",
|
|
16
|
+
"--glob",
|
|
17
|
+
"--iglob",
|
|
18
|
+
"--ignore-file",
|
|
19
|
+
"--max-columns",
|
|
20
|
+
"--max-count",
|
|
21
|
+
"--max-depth",
|
|
22
|
+
"--max-filesize",
|
|
23
|
+
"--path-separator",
|
|
24
|
+
"--pre",
|
|
25
|
+
"--pre-glob",
|
|
26
|
+
"--replace",
|
|
27
|
+
"--sort",
|
|
28
|
+
"--sortr",
|
|
29
|
+
"--threads",
|
|
30
|
+
"--type",
|
|
31
|
+
"--type-add",
|
|
32
|
+
"--type-clear",
|
|
33
|
+
"--type-not",
|
|
34
|
+
]);
|
|
35
|
+
const RG_SHORT_VALUE_FLAGS = new Set("ABCEMTdfgjmrt".split(""));
|
|
36
|
+
const RG_SCOPE_LONG_FLAGS = new Set(["--glob", "--iglob", "--max-depth", "--type", "--type-not"]);
|
|
37
|
+
const RG_SCOPE_SHORT_FLAGS = new Set(["g", "t", "T"]);
|
|
38
|
+
const RG_META_FLAGS = new Set(["--generate", "--help", "--pcre2-version", "--type-list", "--version", "-h"]);
|
|
39
|
+
function targetScope(target, cwd) {
|
|
40
|
+
const normalized = target.trim().replace(/[\\/]+$/u, "") || target.trim();
|
|
41
|
+
if (normalized === "/" ||
|
|
42
|
+
normalized === "\\" ||
|
|
43
|
+
/^[A-Za-z]:$/u.test(normalized) ||
|
|
44
|
+
normalized === "~" ||
|
|
45
|
+
normalized === "$HOME" ||
|
|
46
|
+
normalized === "%USERPROFILE%" ||
|
|
47
|
+
resolve(normalized) === resolve(homedir())) {
|
|
48
|
+
return "global";
|
|
49
|
+
}
|
|
50
|
+
if (normalized === "." ||
|
|
51
|
+
normalized === "*" ||
|
|
52
|
+
normalized === "**" ||
|
|
53
|
+
normalized === "./*" ||
|
|
54
|
+
normalized === "./**" ||
|
|
55
|
+
normalized === "$PWD" ||
|
|
56
|
+
normalized === "$(pwd)" ||
|
|
57
|
+
normalized === "%CD%" ||
|
|
58
|
+
resolve(cwd, normalized) === resolve(cwd))
|
|
59
|
+
return "current";
|
|
60
|
+
return "narrow";
|
|
61
|
+
}
|
|
62
|
+
function hasSafeTarget(targets, cwd, hasScopeFilter) {
|
|
63
|
+
if (targets.includes("-"))
|
|
64
|
+
return true;
|
|
65
|
+
const scopes = (targets.length > 0 ? targets : ["."]).map((target) => targetScope(target, cwd));
|
|
66
|
+
if (scopes.includes("global"))
|
|
67
|
+
return false;
|
|
68
|
+
return scopes.includes("narrow") || hasScopeFilter;
|
|
69
|
+
}
|
|
70
|
+
function parseRgArguments(args) {
|
|
71
|
+
const parsed = {
|
|
72
|
+
filesMode: false,
|
|
73
|
+
hasPatternOption: false,
|
|
74
|
+
hasScopeFilter: false,
|
|
75
|
+
metaOnly: false,
|
|
76
|
+
positionals: [],
|
|
77
|
+
};
|
|
78
|
+
let pastDoubleDash = false;
|
|
79
|
+
for (let index = 0; index < args.length; index++) {
|
|
80
|
+
const arg = args[index];
|
|
81
|
+
if (pastDoubleDash) {
|
|
82
|
+
parsed.positionals.push(arg);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (arg === "--") {
|
|
86
|
+
pastDoubleDash = true;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (RG_META_FLAGS.has(arg)) {
|
|
90
|
+
parsed.metaOnly = true;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (arg === "--files") {
|
|
94
|
+
parsed.filesMode = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (arg === "--regexp" || arg === "--file") {
|
|
98
|
+
parsed.hasPatternOption = true;
|
|
99
|
+
index++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (arg.startsWith("--regexp=") || arg.startsWith("--file=")) {
|
|
103
|
+
parsed.hasPatternOption = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (arg.startsWith("--")) {
|
|
107
|
+
const flag = arg.split("=", 1)[0];
|
|
108
|
+
if (RG_SCOPE_LONG_FLAGS.has(flag))
|
|
109
|
+
parsed.hasScopeFilter = true;
|
|
110
|
+
if (RG_LONG_VALUE_FLAGS.has(flag) && !arg.includes("="))
|
|
111
|
+
index++;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
115
|
+
const cluster = arg.slice(1);
|
|
116
|
+
for (let flagIndex = 0; flagIndex < cluster.length; flagIndex++) {
|
|
117
|
+
const flag = cluster[flagIndex];
|
|
118
|
+
if (flag === "e" || flag === "f")
|
|
119
|
+
parsed.hasPatternOption = true;
|
|
120
|
+
if (RG_SCOPE_SHORT_FLAGS.has(flag))
|
|
121
|
+
parsed.hasScopeFilter = true;
|
|
122
|
+
if (flag === "e" || RG_SHORT_VALUE_FLAGS.has(flag)) {
|
|
123
|
+
if (flagIndex === cluster.length - 1)
|
|
124
|
+
index++;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
parsed.positionals.push(arg);
|
|
131
|
+
}
|
|
132
|
+
return parsed;
|
|
133
|
+
}
|
|
134
|
+
function assessRg(args, cwd, readsPipe) {
|
|
135
|
+
const parsed = parseRgArguments(args);
|
|
136
|
+
if (parsed.metaOnly)
|
|
137
|
+
return { kind: "scoped" };
|
|
138
|
+
const targets = parsed.filesMode
|
|
139
|
+
? parsed.positionals
|
|
140
|
+
: parsed.hasPatternOption
|
|
141
|
+
? parsed.positionals
|
|
142
|
+
: parsed.positionals.slice(1);
|
|
143
|
+
if (readsPipe && targets.length === 0 && !parsed.filesMode)
|
|
144
|
+
return { kind: "scoped" };
|
|
145
|
+
if (hasSafeTarget(targets, cwd, parsed.hasScopeFilter))
|
|
146
|
+
return { kind: "scoped" };
|
|
147
|
+
return {
|
|
148
|
+
kind: "broad",
|
|
149
|
+
searchTool: "rg",
|
|
150
|
+
reason: "rg would search the whole working tree without a narrow path, glob, or type filter",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function assessRecursiveGrep(args, cwd, readsPipe) {
|
|
154
|
+
const recursive = args.some((arg) => arg === "-r" || arg === "-R" || arg === "--recursive" || /^-[^-]*[rR]/u.test(arg));
|
|
155
|
+
if (!recursive || readsPipe)
|
|
156
|
+
return { kind: "scoped" };
|
|
157
|
+
const hasPatternOption = args.some((arg) => arg === "-e" || arg.startsWith("-e") || arg === "--regexp");
|
|
158
|
+
const hasScopeFilter = args.some((arg) => arg === "--include" ||
|
|
159
|
+
arg.startsWith("--include=") ||
|
|
160
|
+
arg === "--exclude" ||
|
|
161
|
+
arg.startsWith("--exclude=") ||
|
|
162
|
+
arg === "--exclude-dir" ||
|
|
163
|
+
arg.startsWith("--exclude-dir="));
|
|
164
|
+
const valueFlags = new Set(["-A", "-B", "-C", "-D", "-d", "-e", "-f", "-m", "--regexp"]);
|
|
165
|
+
const positionals = [];
|
|
166
|
+
let pastDoubleDash = false;
|
|
167
|
+
for (let index = 0; index < args.length; index++) {
|
|
168
|
+
const arg = args[index];
|
|
169
|
+
if (pastDoubleDash)
|
|
170
|
+
positionals.push(arg);
|
|
171
|
+
else if (arg === "--")
|
|
172
|
+
pastDoubleDash = true;
|
|
173
|
+
else if (valueFlags.has(arg) || ["--include", "--exclude", "--exclude-dir"].includes(arg))
|
|
174
|
+
index++;
|
|
175
|
+
else if (!arg.startsWith("-"))
|
|
176
|
+
positionals.push(arg);
|
|
177
|
+
}
|
|
178
|
+
const targets = hasPatternOption ? positionals : positionals.slice(1);
|
|
179
|
+
if (hasSafeTarget(targets, cwd, hasScopeFilter))
|
|
180
|
+
return { kind: "scoped" };
|
|
181
|
+
return {
|
|
182
|
+
kind: "broad",
|
|
183
|
+
searchTool: "grep",
|
|
184
|
+
reason: "recursive grep would scan the whole working tree without a narrow path or include filter",
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function assessFind(args, cwd) {
|
|
188
|
+
let index = 0;
|
|
189
|
+
while (index < args.length) {
|
|
190
|
+
const arg = args[index];
|
|
191
|
+
if (arg === "-H" || arg === "-L" || arg === "-P" || /^-O\d*$/u.test(arg))
|
|
192
|
+
index++;
|
|
193
|
+
else if (arg === "-D")
|
|
194
|
+
index += 2;
|
|
195
|
+
else
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
const targets = [];
|
|
199
|
+
while (index < args.length && !args[index].startsWith("-") && args[index] !== "!" && args[index] !== "(") {
|
|
200
|
+
targets.push(args[index++]);
|
|
201
|
+
}
|
|
202
|
+
const hasScopeFilter = args.some((arg) => ["-iname", "-ipath", "-iregex", "-name", "-path", "-regex"].includes(arg));
|
|
203
|
+
if (hasSafeTarget(targets, cwd, hasScopeFilter))
|
|
204
|
+
return { kind: "scoped" };
|
|
205
|
+
return {
|
|
206
|
+
kind: "broad",
|
|
207
|
+
searchTool: "find",
|
|
208
|
+
reason: "find would enumerate the whole working tree without a narrow path or name/path predicate",
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function assessFd(args, cwd) {
|
|
212
|
+
const positionals = [];
|
|
213
|
+
let hasScopeFilter = false;
|
|
214
|
+
let pastDoubleDash = false;
|
|
215
|
+
const valueFlags = new Set([
|
|
216
|
+
"-d",
|
|
217
|
+
"--max-depth",
|
|
218
|
+
"--min-depth",
|
|
219
|
+
"-e",
|
|
220
|
+
"--extension",
|
|
221
|
+
"-E",
|
|
222
|
+
"--exclude",
|
|
223
|
+
"-t",
|
|
224
|
+
"--type",
|
|
225
|
+
"--base-directory",
|
|
226
|
+
"--changed-before",
|
|
227
|
+
"--changed-within",
|
|
228
|
+
"--color",
|
|
229
|
+
"--owner",
|
|
230
|
+
"--path-separator",
|
|
231
|
+
"--search-path",
|
|
232
|
+
]);
|
|
233
|
+
for (let index = 0; index < args.length; index++) {
|
|
234
|
+
const arg = args[index];
|
|
235
|
+
if (pastDoubleDash)
|
|
236
|
+
positionals.push(arg);
|
|
237
|
+
else if (arg === "--")
|
|
238
|
+
pastDoubleDash = true;
|
|
239
|
+
else if (arg === "-e" || arg === "--extension") {
|
|
240
|
+
hasScopeFilter = true;
|
|
241
|
+
index++;
|
|
242
|
+
}
|
|
243
|
+
else if (arg.startsWith("--extension="))
|
|
244
|
+
hasScopeFilter = true;
|
|
245
|
+
else if (valueFlags.has(arg))
|
|
246
|
+
index++;
|
|
247
|
+
else if (!arg.startsWith("-"))
|
|
248
|
+
positionals.push(arg);
|
|
249
|
+
}
|
|
250
|
+
const pattern = positionals[0];
|
|
251
|
+
const targets = positionals.slice(1);
|
|
252
|
+
const meaningfulPattern = Boolean(pattern && pattern !== "." && pattern !== ".*" && pattern !== "*");
|
|
253
|
+
if (meaningfulPattern || hasSafeTarget(targets, cwd, hasScopeFilter))
|
|
254
|
+
return { kind: "scoped" };
|
|
255
|
+
return {
|
|
256
|
+
kind: "broad",
|
|
257
|
+
searchTool: "fd",
|
|
258
|
+
reason: "fd would enumerate the whole working tree without a narrow pattern, path, glob, extension, or type",
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function commandName(value) {
|
|
262
|
+
return basename(value)
|
|
263
|
+
.toLowerCase()
|
|
264
|
+
.replace(/\.exe$/u, "");
|
|
265
|
+
}
|
|
266
|
+
function stripInvocationPrefixes(args) {
|
|
267
|
+
let index = 0;
|
|
268
|
+
while (index < args.length && /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index]))
|
|
269
|
+
index++;
|
|
270
|
+
if (args[index] === "command") {
|
|
271
|
+
index++;
|
|
272
|
+
while (args[index]?.startsWith("-"))
|
|
273
|
+
index++;
|
|
274
|
+
}
|
|
275
|
+
if (args[index] === "env") {
|
|
276
|
+
index++;
|
|
277
|
+
while (args[index]?.startsWith("-") || /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index] ?? ""))
|
|
278
|
+
index++;
|
|
279
|
+
}
|
|
280
|
+
return args.slice(index);
|
|
281
|
+
}
|
|
282
|
+
function assessInvocation(args, cwd, readsPipe) {
|
|
283
|
+
const invocation = stripInvocationPrefixes(args);
|
|
284
|
+
const name = commandName(invocation[0] ?? "");
|
|
285
|
+
const commandArgs = invocation.slice(1);
|
|
286
|
+
switch (name) {
|
|
287
|
+
case "rg":
|
|
288
|
+
case "ripgrep":
|
|
289
|
+
return assessRg(commandArgs, cwd, readsPipe);
|
|
290
|
+
case "grep":
|
|
291
|
+
return assessRecursiveGrep(commandArgs, cwd, readsPipe);
|
|
292
|
+
case "find":
|
|
293
|
+
return assessFind(commandArgs, cwd);
|
|
294
|
+
case "fd":
|
|
295
|
+
case "fdfind":
|
|
296
|
+
return assessFd(commandArgs, cwd);
|
|
297
|
+
default:
|
|
298
|
+
return { kind: "scoped" };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Reject shell searches whose filesystem scope cannot be proven narrow. Dedicated grep/find
|
|
303
|
+
* tools already own result caps and artifacts; this closes the raw-shell bypass before execution.
|
|
304
|
+
*/
|
|
305
|
+
export function assessShellSearchScope(command, cwd) {
|
|
306
|
+
const tokens = tokenizeShellCommand(command);
|
|
307
|
+
if (!tokens) {
|
|
308
|
+
return { kind: "scoped" };
|
|
309
|
+
}
|
|
310
|
+
let invocation = [];
|
|
311
|
+
let ignoreRedirectTarget = false;
|
|
312
|
+
let readsPipe = false;
|
|
313
|
+
const assessCurrent = () => assessInvocation(invocation, cwd, readsPipe);
|
|
314
|
+
for (const token of tokens) {
|
|
315
|
+
if (token.kind === "arg") {
|
|
316
|
+
if (!ignoreRedirectTarget)
|
|
317
|
+
invocation.push(token.value);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (token.kind === "redirect") {
|
|
321
|
+
ignoreRedirectTarget = true;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const assessment = assessCurrent();
|
|
325
|
+
if (assessment.kind === "broad")
|
|
326
|
+
return assessment;
|
|
327
|
+
invocation = [];
|
|
328
|
+
ignoreRedirectTarget = false;
|
|
329
|
+
readsPipe = token.kind === "pipe";
|
|
330
|
+
}
|
|
331
|
+
return assessCurrent();
|
|
332
|
+
}
|
|
333
|
+
//# sourceMappingURL=search-command-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-command-guard.js","sourceRoot":"","sources":["../../../src/core/tools/search-command-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAwB,CAAC;AAMlE,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IACnC,iBAAiB;IACjB,kBAAkB;IAClB,SAAS;IACT,UAAU;IACV,WAAW;IACX,qBAAqB;IACrB,YAAY;IACZ,UAAU;IACV,2BAA2B;IAC3B,yBAAyB;IACzB,QAAQ;IACR,SAAS;IACT,eAAe;IACf,eAAe;IACf,aAAa;IACb,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,OAAO;IACP,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,SAAS;IACT,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,cAAc;IACd,YAAY;CACZ,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAChE,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AO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC;AAAA,CACD;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,GAAW,EAAyB;IAC3F,MAAM,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU,GAAa,EAAE,CAAC;IAC9B,IAAI,oBAAoB,GAAG,KAAK,CAAC;IACjC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,MAAM,aAAa,GAAG,GAA0B,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IAEhG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,oBAAoB;gBAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxD,SAAS;QACV,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/B,oBAAoB,GAAG,IAAI,CAAC;YAC5B,SAAS;QACV,CAAC;QACD,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;QACnC,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,UAAU,CAAC;QACnD,UAAU,GAAG,EAAE,CAAC;QAChB,oBAAoB,GAAG,KAAK,CAAC;QAC7B,SAAS,GAAG,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;IACnC,CAAC;IAED,OAAO,aAAa,EAAE,CAAC;AAAA,CACvB","sourcesContent":["import { homedir } from \"node:os\";\nimport { basename, resolve } from \"node:path\";\nimport { tokenizeShellCommand } from \"./shell-command-parser.ts\";\n\nexport const BROAD_SEARCH_OUTPUT_ROUTE = \"route-to-file\" as const;\n\nexport type SearchScopeAssessment =\n\t| { kind: \"scoped\" }\n\t| { kind: \"broad\"; searchTool: \"rg\" | \"grep\" | \"find\" | \"fd\"; reason: string };\n\nconst RG_LONG_VALUE_FLAGS = new Set([\n\t\"--after-context\",\n\t\"--before-context\",\n\t\"--color\",\n\t\"--colors\",\n\t\"--context\",\n\t\"--context-separator\",\n\t\"--encoding\",\n\t\"--engine\",\n\t\"--field-context-separator\",\n\t\"--field-match-separator\",\n\t\"--glob\",\n\t\"--iglob\",\n\t\"--ignore-file\",\n\t\"--max-columns\",\n\t\"--max-count\",\n\t\"--max-depth\",\n\t\"--max-filesize\",\n\t\"--path-separator\",\n\t\"--pre\",\n\t\"--pre-glob\",\n\t\"--replace\",\n\t\"--sort\",\n\t\"--sortr\",\n\t\"--threads\",\n\t\"--type\",\n\t\"--type-add\",\n\t\"--type-clear\",\n\t\"--type-not\",\n]);\nconst RG_SHORT_VALUE_FLAGS = new Set(\"ABCEMTdfgjmrt\".split(\"\"));\nconst RG_SCOPE_LONG_FLAGS = new Set([\"--glob\", \"--iglob\", \"--max-depth\", \"--type\", \"--type-not\"]);\nconst RG_SCOPE_SHORT_FLAGS = new Set([\"g\", \"t\", \"T\"]);\nconst RG_META_FLAGS = new Set([\"--generate\", \"--help\", \"--pcre2-version\", \"--type-list\", \"--version\", \"-h\"]);\n\ntype TargetScope = \"current\" | \"global\" | \"narrow\";\n\nfunction targetScope(target: string, cwd: string): TargetScope {\n\tconst normalized = target.trim().replace(/[\\\\/]+$/u, \"\") || target.trim();\n\tif (\n\t\tnormalized === \"/\" ||\n\t\tnormalized === \"\\\\\" ||\n\t\t/^[A-Za-z]:$/u.test(normalized) ||\n\t\tnormalized === \"~\" ||\n\t\tnormalized === \"$HOME\" ||\n\t\tnormalized === \"%USERPROFILE%\" ||\n\t\tresolve(normalized) === resolve(homedir())\n\t) {\n\t\treturn \"global\";\n\t}\n\tif (\n\t\tnormalized === \".\" ||\n\t\tnormalized === \"*\" ||\n\t\tnormalized === \"**\" ||\n\t\tnormalized === \"./*\" ||\n\t\tnormalized === \"./**\" ||\n\t\tnormalized === \"$PWD\" ||\n\t\tnormalized === \"$(pwd)\" ||\n\t\tnormalized === \"%CD%\" ||\n\t\tresolve(cwd, normalized) === resolve(cwd)\n\t)\n\t\treturn \"current\";\n\treturn \"narrow\";\n}\n\nfunction hasSafeTarget(targets: string[], cwd: string, hasScopeFilter: boolean): boolean {\n\tif (targets.includes(\"-\")) return true;\n\tconst scopes = (targets.length > 0 ? targets : [\".\"]).map((target) => targetScope(target, cwd));\n\tif (scopes.includes(\"global\")) return false;\n\treturn scopes.includes(\"narrow\") || hasScopeFilter;\n}\n\ninterface RgArguments {\n\tfilesMode: boolean;\n\thasPatternOption: boolean;\n\thasScopeFilter: boolean;\n\tmetaOnly: boolean;\n\tpositionals: string[];\n}\n\nfunction parseRgArguments(args: string[]): RgArguments {\n\tconst parsed: RgArguments = {\n\t\tfilesMode: false,\n\t\thasPatternOption: false,\n\t\thasScopeFilter: false,\n\t\tmetaOnly: false,\n\t\tpositionals: [],\n\t};\n\tlet pastDoubleDash = false;\n\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) {\n\t\t\tparsed.positionals.push(arg);\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--\") {\n\t\t\tpastDoubleDash = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (RG_META_FLAGS.has(arg)) {\n\t\t\tparsed.metaOnly = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--files\") {\n\t\t\tparsed.filesMode = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--regexp\" || arg === \"--file\") {\n\t\t\tparsed.hasPatternOption = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"--regexp=\") || arg.startsWith(\"--file=\")) {\n\t\t\tparsed.hasPatternOption = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"--\")) {\n\t\t\tconst flag = arg.split(\"=\", 1)[0];\n\t\t\tif (RG_SCOPE_LONG_FLAGS.has(flag)) parsed.hasScopeFilter = true;\n\t\t\tif (RG_LONG_VALUE_FLAGS.has(flag) && !arg.includes(\"=\")) index++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\") && arg.length > 1) {\n\t\t\tconst cluster = arg.slice(1);\n\t\t\tfor (let flagIndex = 0; flagIndex < cluster.length; flagIndex++) {\n\t\t\t\tconst flag = cluster[flagIndex];\n\t\t\t\tif (flag === \"e\" || flag === \"f\") parsed.hasPatternOption = true;\n\t\t\t\tif (RG_SCOPE_SHORT_FLAGS.has(flag)) parsed.hasScopeFilter = true;\n\t\t\t\tif (flag === \"e\" || RG_SHORT_VALUE_FLAGS.has(flag)) {\n\t\t\t\t\tif (flagIndex === cluster.length - 1) index++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tparsed.positionals.push(arg);\n\t}\n\n\treturn parsed;\n}\n\nfunction assessRg(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst parsed = parseRgArguments(args);\n\tif (parsed.metaOnly) return { kind: \"scoped\" };\n\tconst targets = parsed.filesMode\n\t\t? parsed.positionals\n\t\t: parsed.hasPatternOption\n\t\t\t? parsed.positionals\n\t\t\t: parsed.positionals.slice(1);\n\tif (readsPipe && targets.length === 0 && !parsed.filesMode) return { kind: \"scoped\" };\n\tif (hasSafeTarget(targets, cwd, parsed.hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"rg\",\n\t\treason: \"rg would search the whole working tree without a narrow path, glob, or type filter\",\n\t};\n}\n\nfunction assessRecursiveGrep(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst recursive = args.some(\n\t\t(arg) => arg === \"-r\" || arg === \"-R\" || arg === \"--recursive\" || /^-[^-]*[rR]/u.test(arg),\n\t);\n\tif (!recursive || readsPipe) return { kind: \"scoped\" };\n\tconst hasPatternOption = args.some((arg) => arg === \"-e\" || arg.startsWith(\"-e\") || arg === \"--regexp\");\n\tconst hasScopeFilter = args.some(\n\t\t(arg) =>\n\t\t\targ === \"--include\" ||\n\t\t\targ.startsWith(\"--include=\") ||\n\t\t\targ === \"--exclude\" ||\n\t\t\targ.startsWith(\"--exclude=\") ||\n\t\t\targ === \"--exclude-dir\" ||\n\t\t\targ.startsWith(\"--exclude-dir=\"),\n\t);\n\tconst valueFlags = new Set([\"-A\", \"-B\", \"-C\", \"-D\", \"-d\", \"-e\", \"-f\", \"-m\", \"--regexp\"]);\n\tconst positionals: string[] = [];\n\tlet pastDoubleDash = false;\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) positionals.push(arg);\n\t\telse if (arg === \"--\") pastDoubleDash = true;\n\t\telse if (valueFlags.has(arg) || [\"--include\", \"--exclude\", \"--exclude-dir\"].includes(arg)) index++;\n\t\telse if (!arg.startsWith(\"-\")) positionals.push(arg);\n\t}\n\tconst targets = hasPatternOption ? positionals : positionals.slice(1);\n\tif (hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"grep\",\n\t\treason: \"recursive grep would scan the whole working tree without a narrow path or include filter\",\n\t};\n}\n\nfunction assessFind(args: string[], cwd: string): SearchScopeAssessment {\n\tlet index = 0;\n\twhile (index < args.length) {\n\t\tconst arg = args[index];\n\t\tif (arg === \"-H\" || arg === \"-L\" || arg === \"-P\" || /^-O\\d*$/u.test(arg)) index++;\n\t\telse if (arg === \"-D\") index += 2;\n\t\telse break;\n\t}\n\tconst targets: string[] = [];\n\twhile (index < args.length && !args[index].startsWith(\"-\") && args[index] !== \"!\" && args[index] !== \"(\") {\n\t\ttargets.push(args[index++]);\n\t}\n\tconst hasScopeFilter = args.some((arg) => [\"-iname\", \"-ipath\", \"-iregex\", \"-name\", \"-path\", \"-regex\"].includes(arg));\n\tif (hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"find\",\n\t\treason: \"find would enumerate the whole working tree without a narrow path or name/path predicate\",\n\t};\n}\n\nfunction assessFd(args: string[], cwd: string): SearchScopeAssessment {\n\tconst positionals: string[] = [];\n\tlet hasScopeFilter = false;\n\tlet pastDoubleDash = false;\n\tconst valueFlags = new Set([\n\t\t\"-d\",\n\t\t\"--max-depth\",\n\t\t\"--min-depth\",\n\t\t\"-e\",\n\t\t\"--extension\",\n\t\t\"-E\",\n\t\t\"--exclude\",\n\t\t\"-t\",\n\t\t\"--type\",\n\t\t\"--base-directory\",\n\t\t\"--changed-before\",\n\t\t\"--changed-within\",\n\t\t\"--color\",\n\t\t\"--owner\",\n\t\t\"--path-separator\",\n\t\t\"--search-path\",\n\t]);\n\tfor (let index = 0; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (pastDoubleDash) positionals.push(arg);\n\t\telse if (arg === \"--\") pastDoubleDash = true;\n\t\telse if (arg === \"-e\" || arg === \"--extension\") {\n\t\t\thasScopeFilter = true;\n\t\t\tindex++;\n\t\t} else if (arg.startsWith(\"--extension=\")) hasScopeFilter = true;\n\t\telse if (valueFlags.has(arg)) index++;\n\t\telse if (!arg.startsWith(\"-\")) positionals.push(arg);\n\t}\n\tconst pattern = positionals[0];\n\tconst targets = positionals.slice(1);\n\tconst meaningfulPattern = Boolean(pattern && pattern !== \".\" && pattern !== \".*\" && pattern !== \"*\");\n\tif (meaningfulPattern || hasSafeTarget(targets, cwd, hasScopeFilter)) return { kind: \"scoped\" };\n\treturn {\n\t\tkind: \"broad\",\n\t\tsearchTool: \"fd\",\n\t\treason: \"fd would enumerate the whole working tree without a narrow pattern, path, glob, extension, or type\",\n\t};\n}\n\nfunction commandName(value: string): string {\n\treturn basename(value)\n\t\t.toLowerCase()\n\t\t.replace(/\\.exe$/u, \"\");\n}\n\nfunction stripInvocationPrefixes(args: string[]): string[] {\n\tlet index = 0;\n\twhile (index < args.length && /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index])) index++;\n\tif (args[index] === \"command\") {\n\t\tindex++;\n\t\twhile (args[index]?.startsWith(\"-\")) index++;\n\t}\n\tif (args[index] === \"env\") {\n\t\tindex++;\n\t\twhile (args[index]?.startsWith(\"-\") || /^[A-Za-z_][A-Za-z0-9_]*=/u.test(args[index] ?? \"\")) index++;\n\t}\n\treturn args.slice(index);\n}\n\nfunction assessInvocation(args: string[], cwd: string, readsPipe: boolean): SearchScopeAssessment {\n\tconst invocation = stripInvocationPrefixes(args);\n\tconst name = commandName(invocation[0] ?? \"\");\n\tconst commandArgs = invocation.slice(1);\n\tswitch (name) {\n\t\tcase \"rg\":\n\t\tcase \"ripgrep\":\n\t\t\treturn assessRg(commandArgs, cwd, readsPipe);\n\t\tcase \"grep\":\n\t\t\treturn assessRecursiveGrep(commandArgs, cwd, readsPipe);\n\t\tcase \"find\":\n\t\t\treturn assessFind(commandArgs, cwd);\n\t\tcase \"fd\":\n\t\tcase \"fdfind\":\n\t\t\treturn assessFd(commandArgs, cwd);\n\t\tdefault:\n\t\t\treturn { kind: \"scoped\" };\n\t}\n}\n\n/**\n * Reject shell searches whose filesystem scope cannot be proven narrow. Dedicated grep/find\n * tools already own result caps and artifacts; this closes the raw-shell bypass before execution.\n */\nexport function assessShellSearchScope(command: string, cwd: string): SearchScopeAssessment {\n\tconst tokens = tokenizeShellCommand(command);\n\tif (!tokens) {\n\t\treturn { kind: \"scoped\" };\n\t}\n\n\tlet invocation: string[] = [];\n\tlet ignoreRedirectTarget = false;\n\tlet readsPipe = false;\n\tconst assessCurrent = (): SearchScopeAssessment => assessInvocation(invocation, cwd, readsPipe);\n\n\tfor (const token of tokens) {\n\t\tif (token.kind === \"arg\") {\n\t\t\tif (!ignoreRedirectTarget) invocation.push(token.value);\n\t\t\tcontinue;\n\t\t}\n\t\tif (token.kind === \"redirect\") {\n\t\t\tignoreRedirectTarget = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst assessment = assessCurrent();\n\t\tif (assessment.kind === \"broad\") return assessment;\n\t\tinvocation = [];\n\t\tignoreRedirectTarget = false;\n\t\treadsPipe = token.kind === \"pipe\";\n\t}\n\n\treturn assessCurrent();\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import { type SecretProfileSummary, SecretVault } from "../secrets/secret-vault.ts";
|
|
3
|
+
declare const secretStoreSchema: Type.TObject<{
|
|
4
|
+
action: Type.TUnion<[Type.TLiteral<"set">, Type.TLiteral<"list">, Type.TLiteral<"materialize">, Type.TLiteral<"remove">, Type.TLiteral<"lock">]>;
|
|
5
|
+
profile: Type.TOptional<Type.TString>;
|
|
6
|
+
description: Type.TOptional<Type.TString>;
|
|
7
|
+
envFile: Type.TOptional<Type.TString>;
|
|
8
|
+
variableNames: Type.TOptional<Type.TArray<Type.TString>>;
|
|
9
|
+
scope: Type.TOptional<Type.TUnion<[Type.TLiteral<"managed">, Type.TLiteral<"workspace">]>>;
|
|
10
|
+
}>;
|
|
11
|
+
export type SecretStoreToolInput = Static<typeof secretStoreSchema>;
|
|
12
|
+
export type SecretStoreStatus = "cancelled" | "error" | "listed" | "locked" | "materialized" | "removed" | "stored" | "unavailable";
|
|
13
|
+
export interface SecretStoreToolDetails {
|
|
14
|
+
action: SecretStoreToolInput["action"];
|
|
15
|
+
status: SecretStoreStatus;
|
|
16
|
+
profile?: string;
|
|
17
|
+
variableNames?: string[];
|
|
18
|
+
profiles?: SecretProfileSummary[];
|
|
19
|
+
scope?: "managed" | "workspace";
|
|
20
|
+
envFile?: string;
|
|
21
|
+
materialized?: boolean;
|
|
22
|
+
code?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SecretStoreToolOptions {
|
|
26
|
+
agentDir?: string;
|
|
27
|
+
vault?: SecretVault;
|
|
28
|
+
}
|
|
29
|
+
export declare function createSecretStoreToolDefinition(options: SecretStoreToolOptions): import("../extensions/types.ts").ToolDefinition<Type.TObject<{
|
|
30
|
+
action: Type.TUnion<[Type.TLiteral<"set">, Type.TLiteral<"list">, Type.TLiteral<"materialize">, Type.TLiteral<"remove">, Type.TLiteral<"lock">]>;
|
|
31
|
+
profile: Type.TOptional<Type.TString>;
|
|
32
|
+
description: Type.TOptional<Type.TString>;
|
|
33
|
+
envFile: Type.TOptional<Type.TString>;
|
|
34
|
+
variableNames: Type.TOptional<Type.TArray<Type.TString>>;
|
|
35
|
+
scope: Type.TOptional<Type.TUnion<[Type.TLiteral<"managed">, Type.TLiteral<"workspace">]>>;
|
|
36
|
+
}>, SecretStoreToolDetails, any> & import("../extensions/types.ts").ToolDefinition<any, any, any>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=secret-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-store.d.ts","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAK5C,OAAO,EAQN,KAAK,oBAAoB,EACzB,WAAW,EAEX,MAAM,4BAA4B,CAAC;AAOpC,QAAA,MAAM,iBAAiB;;;;;;;EA0DtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEpE,MAAM,MAAM,iBAAiB,GAC1B,WAAW,GACX,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,SAAS,GACT,QAAQ,GACR,aAAa,CAAC;AAEjB,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB;AA8YD,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,sBAAsB;;;;;;;kGA6E9E","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"]}
|