@caupulican/pi-adaptative 0.81.40 → 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 +25 -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 +1 -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 +1 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +22 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-paths.d.ts +6 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +12 -0
- 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.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +26 -405
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +86 -307
- 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/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +2 -1
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +3 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +1 -0
- 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/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +1 -1
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +3 -8
- 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-pipeline.d.ts +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +7 -33
- 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 +1 -0
- package/dist/core/default-tool-surface.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/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +2 -3
- 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 +14 -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/types.d.ts +8 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +1 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +13 -13
- package/dist/core/foreground-recovery-controller.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.map +1 -1
- package/dist/core/goals/goal-acceptance.js +2 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts +2 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +5 -8
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- 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 +42 -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 +35 -12
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js +98 -13
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- 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-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 +45 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +85 -15
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +1 -4
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +49 -34
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +18 -8
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +134 -11
- 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/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/model-capability.d.ts +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +0 -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 +16 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +32 -16
- package/dist/core/model-resolver.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.map +1 -1
- package/dist/core/model-selection-controller.d.ts +1 -1
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +3 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
- package/dist/core/orchestration/work-state-projection.js +1 -1
- package/dist/core/orchestration/work-state-projection.js.map +1 -1
- 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/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/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 +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +3 -1
- package/dist/core/reflection-controller.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/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +16 -6
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +8 -0
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +15 -3
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +132 -79
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -1
- 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 +39 -69
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-role.d.ts +5 -0
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +14 -1
- package/dist/core/session-role.js.map +1 -1
- 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 +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- 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/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +1 -0
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +2 -4
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.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/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.map +1 -1
- package/dist/core/tools/delegate-status.js +6 -7
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +6 -8
- package/dist/core/tools/delegate.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 +5 -3
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +97 -19
- 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/orchestration-panel.d.ts +1 -4
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
- package/dist/core/tools/orchestration-panel.js +0 -44
- package/dist/core/tools/orchestration-panel.js.map +1 -1
- 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/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.map +1 -1
- package/dist/core/tools/task-steps.js +4 -7
- package/dist/core/tools/task-steps.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/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +25 -11
- package/dist/main.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/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 +4 -4
- 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/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +1 -0
- 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 +20 -25
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +196 -608
- package/dist/modes/interactive/interactive-mode.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/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 +10 -6
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +123 -70
- package/dist/modes/interactive/session-flow-commands.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/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/docs/UI_POLISH_ORCHESTRATION.md +25 -31
- package/docs/UI_QUALITY_ORCHESTRATION.md +22 -24
- package/docs/providers.md +9 -1
- package/docs/ui-reference/README.md +6 -6
- package/docs/ui-reference/orchestration-after.txt +14 -7
- package/docs/ui-reference/orchestration-before.txt +12 -6
- package/docs/ui-reference/orchestration-reference.txt +15 -5
- package/docs/usage.md +9 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +13 -13
- package/package.json +4 -4
|
@@ -110,14 +110,12 @@ export function createDelegateToolDefinition(deps) {
|
|
|
110
110
|
return emptyOrchestrationCall();
|
|
111
111
|
},
|
|
112
112
|
renderResult(result, { expanded, isPartial }, theme) {
|
|
113
|
-
if (isPartial)
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return new OrchestrationPanelComponent(theme, delegatePanelModel(result.details), expanded);
|
|
113
|
+
if (isPartial)
|
|
114
|
+
return emptyOrchestrationCall();
|
|
115
|
+
const details = result.details;
|
|
116
|
+
if (!expanded && details?.started)
|
|
117
|
+
return emptyOrchestrationCall();
|
|
118
|
+
return new OrchestrationPanelComponent(theme, delegatePanelModel(details), expanded);
|
|
121
119
|
},
|
|
122
120
|
async execute(_toolCallId, input) {
|
|
123
121
|
const request = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAK5C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAG3B,MAAM,0BAA0B,CAAC;AAElC,SAAS,oBAAoB,GAAG;IAC/B,OAAO,IAAI,CAAC,MAAM,CACjB;QACC,SAAS,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,MAAM,CAAC;YACX,WAAW,EACV,uNAAuN;SACxN,CAAC,CACF;QACD,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC;YACzB,WAAW,EACV,mTAAmT;SACpT,CAAC;KACF,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAAA,CACF;AAED,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;AAiC9C,MAAM,yBAAyB,GAC9B,6eAA6e,CAAC;AAE/e,iGAAiG;AACjG,+DAA+D;AAC/D,MAAM,gCAAgC,GAAG,yBAAyB,CAAC;AAEnE,kGAAkG;AAClG,uGAAqG;AACrG,qDAAqD;AACrD,MAAM,0BAA0B,GAAG,GAAG,yBAAyB,iRAAiR,CAAC;AAEjV,MAAM,sCAAsC,GAAG;IAC9C,8HAA8H;IAC9H,2HAA2H;IAC3H,oIAAoI;IACpI,uFAAuF;IACvF,kHAAkH;CAClH,CAAC;AAEF,MAAM,gCAAgC,GAAG;IACxC,8HAA8H;IAC9H,2HAA2H;IAC3H,oIAAoI;IACpI,oLAAoL;IACpL,oHAAoH;IACpH,uHAAuH;CACvH,CAAC;AAEF,SAAS,kBAAkB,CAAC,OAAw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e,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5D,OAAO,EAAE;oBACR,OAAO,EAAE,IAAI;oBACb,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,IAAI,KAAK,CAAC,SAAS;oBACnD,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM;oBAC1B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK;oBACxB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM;oBAC1B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU;oBAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ;oBAC3B,OAAO,EAAE,OAAO,EAAE,OAAO;oBACzB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;oBAC/C,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;iBAC/C;aACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Omit only when the owner configured a default workerDelegation.orchestrationProfile.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tinstructions: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"The self-contained task for a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.\",\n\t\t\t}),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result only ever surfaces later via the event-driven terminal\n// handoff followed by one delegate_status retrieval.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.\",\n\t\"Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline =\n\t\tdeps.orchestrationProfiles && deps.orchestrationProfiles.length > 0\n\t\t\t? `Available owner-authored orchestration profiles: ${deps.orchestrationProfiles\n\t\t\t\t\t.map((profile) => `${profile.profileId} (${profile.role}: ${profile.description})`)\n\t\t\t\t\t.join(\"; \")}. Select by profileId; never infer or request a model/thinking override.`\n\t\t\t: \"Delegation requires an owner-authored orchestration profile. Select its profileId, or rely on the owner's configured default; model and thinking overrides do not exist.\";\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Delegate a bounded task to an isolated, least-privilege worker lane.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"workers\",\n\t\t\t\t\taction: \"dispatching\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(\n\t\t\t\ttheme,\n\t\t\t\tdelegatePanelModel(result.details as DelegateToolDetails | undefined),\n\t\t\t\texpanded,\n\t\t\t);\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst request = {\n\t\t\t\tinstructions: input.instructions,\n\t\t\t\t...(input.profileId ? { profileId: input.profileId } : {}),\n\t\t\t};\n\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\tif (!started.started) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\tdetails: { started: false, skipReason: started.skipReason, profileId: input.profileId },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — wait for its terminal handoff, then retrieve once with delegate_status`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: started.record.profileId ?? input.profileId,\n\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\tlabel: started.record.label,\n\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\tif (!run.started) {\n\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\tdetails: { started: false, skipReason: reason, profileId: input.profileId },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst outcome = run.outcome;\n\t\t\tconst lines: string[] = [\n\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t];\n\t\t\tif (outcome) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\toutcome.claim.summary,\n\t\t\t\t);\n\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\tlines.push(`Blockers: ${outcome.claim.blockers.join(\"; \")}`);\n\t\t\t\t}\n\t\t\t\tfor (const finding of outcome.claim.evidence?.findings ?? []) {\n\t\t\t\t\tlines.push(`- Finding: ${finding.summary}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\tstarted: true,\n\t\t\t\t\tprofileId: run.record?.profileId ?? input.profileId,\n\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAK5C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAG3B,MAAM,0BAA0B,CAAC;AAElC,SAAS,oBAAoB,GAAG;IAC/B,OAAO,IAAI,CAAC,MAAM,CACjB;QACC,SAAS,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,MAAM,CAAC;YACX,WAAW,EACV,uNAAuN;SACxN,CAAC,CACF;QACD,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC;YACzB,WAAW,EACV,mTAAmT;SACpT,CAAC;KACF,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAAA,CACF;AAED,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;AAiC9C,MAAM,yBAAyB,GA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nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Omit only when the owner configured a default workerDelegation.orchestrationProfile.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tinstructions: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"The self-contained task for a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.\",\n\t\t\t}),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result only ever surfaces later via the event-driven terminal\n// handoff followed by one delegate_status retrieval.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.\",\n\t\"Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline =\n\t\tdeps.orchestrationProfiles && deps.orchestrationProfiles.length > 0\n\t\t\t? `Available owner-authored orchestration profiles: ${deps.orchestrationProfiles\n\t\t\t\t\t.map((profile) => `${profile.profileId} (${profile.role}: ${profile.description})`)\n\t\t\t\t\t.join(\"; \")}. Select by profileId; never infer or request a model/thinking override.`\n\t\t\t: \"Delegation requires an owner-authored orchestration profile. Select its profileId, or rely on the owner's configured default; model and thinking overrides do not exist.\";\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Delegate a bounded task to an isolated, least-privilege worker lane.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return emptyOrchestrationCall();\n\t\t\tconst details = result.details as DelegateToolDetails | undefined;\n\t\t\tif (!expanded && details?.started) return emptyOrchestrationCall();\n\t\t\treturn new OrchestrationPanelComponent(theme, delegatePanelModel(details), expanded);\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst request = {\n\t\t\t\tinstructions: input.instructions,\n\t\t\t\t...(input.profileId ? { profileId: input.profileId } : {}),\n\t\t\t};\n\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\tif (!started.started) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\tdetails: { started: false, skipReason: started.skipReason, profileId: input.profileId },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — wait for its terminal handoff, then retrieve once with delegate_status`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: started.record.profileId ?? input.profileId,\n\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\tlabel: started.record.label,\n\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\tif (!run.started) {\n\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\tdetails: { started: false, skipReason: reason, profileId: input.profileId },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst outcome = run.outcome;\n\t\t\tconst lines: string[] = [\n\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t];\n\t\t\tif (outcome) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\toutcome.claim.summary,\n\t\t\t\t);\n\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\tlines.push(`Blockers: ${outcome.claim.blockers.join(\"; \")}`);\n\t\t\t\t}\n\t\t\t\tfor (const finding of outcome.claim.evidence?.findings ?? []) {\n\t\t\t\t\tlines.push(`- Finding: ${finding.summary}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\tstarted: true,\n\t\t\t\t\tprofileId: run.record?.profileId ?? input.profileId,\n\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { isComplexShellCommand, parseCommandPrefixes, tokenizeCommand } from "./shell-command-parser.ts";
|
|
1
2
|
export interface FilterResult {
|
|
2
3
|
output: string;
|
|
3
4
|
exitCode: number;
|
|
@@ -23,13 +24,6 @@ interface GitFilterOptions {
|
|
|
23
24
|
timeout?: number;
|
|
24
25
|
}
|
|
25
26
|
export declare function unicodeTruncate(str: string, maxLength: number): string;
|
|
26
|
-
export declare function tokenizeCommand(command: string): string[] | null;
|
|
27
|
-
export interface ParsedCommand {
|
|
28
|
-
envVars: Record<string, string>;
|
|
29
|
-
coreCommandTokens: string[];
|
|
30
|
-
}
|
|
31
|
-
export declare function parseCommandPrefixes(command: string): ParsedCommand | null;
|
|
32
|
-
export declare function isComplexShellCommand(command: string): boolean;
|
|
33
27
|
export declare function runGitQuery(cwd: string, globalOptions: string[], args: string[], options?: GitFilterOptions): Promise<GitQueryResult>;
|
|
34
28
|
export declare function classifyGitCommand(command: string, parentEnv?: NodeJS.ProcessEnv): {
|
|
35
29
|
eligible: boolean;
|
|
@@ -45,5 +39,4 @@ export declare function compactDiff(diffOutput: string, maxLines?: number): {
|
|
|
45
39
|
};
|
|
46
40
|
export declare function executeFilteredGit(cwd: string, subcommand: string, globalOptions: string[], subcommandArgs: string[], options?: GitFilterOptions): Promise<FilterResult>;
|
|
47
41
|
export declare function makeGitCommandForDisplay(globalOptions: string[], subcommand: string, args: string[]): string;
|
|
48
|
-
export {};
|
|
49
42
|
//# sourceMappingURL=git-filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-filter.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-filter.ts"],"names":[],"mappings":"AA4CA,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAc;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,QAAQ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,EAAE,MAAM,EAAE,QAAQ,SAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAgEzG;AA4RD,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,cAAc,EAAE,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,YAAY,CAAC,CA6BvB;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAE5G","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport { existsSync, type WriteStream } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport { createSafeWriteStream } from \"../../utils/safe-write-stream.ts\";\nimport { trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\n/**\n * Retention budget for git output held in memory while filtering. Output beyond\n * the budget is spilled to a temp file so a giant `git log -p`/`git diff` cannot\n * exhaust the V8 heap. Override with PI_GIT_FILTER_MAX_RETAINED_BYTES.\n */\nconst DEFAULT_MAX_RETAINED_GIT_OUTPUT_BYTES = 48 * 1024 * 1024;\nconst MAX_RETAINED_GIT_STDERR_BYTES = 8 * 1024 * 1024;\nconst DEFAULT_GIT_FILTER_TIMEOUT_SECONDS = 10 * 60;\nconst GIT_FILTER_KILL_GRACE_MS = 2_000;\n\nfunction maxRetainedGitOutputBytes(): number {\n\tconst raw = process.env.PI_GIT_FILTER_MAX_RETAINED_BYTES;\n\tif (raw !== undefined) {\n\t\tconst parsed = Number.parseInt(raw, 10);\n\t\tif (Number.isFinite(parsed) && parsed > 0) return parsed;\n\t}\n\treturn DEFAULT_MAX_RETAINED_GIT_OUTPUT_BYTES;\n}\n\nconst SUPPORTED_SUBCOMMANDS = new Set([\n\t\"status\",\n\t\"log\",\n\t\"diff\",\n\t\"show\",\n\t\"add\",\n\t\"commit\",\n\t\"push\",\n\t\"pull\",\n\t\"branch\",\n\t\"fetch\",\n\t\"stash\",\n\t\"worktree\",\n]);\n\nexport interface FilterResult {\n\toutput: string;\n\texitCode: number;\n\trawOut: string;\n\trawBytes?: Buffer;\n\t/** Set when git output exceeded the in-memory retention budget; the file holds the full output. */\n\tfullOutputPath?: string;\n}\n\ninterface GitQueryResult {\n\tstdout: string;\n\tstderr: string;\n\tstatus: number | null;\n\t/** Full raw output (stderr then stdout). Absent when output overflowed to disk. */\n\trawBytes?: Buffer;\n\t/** Set when stdout exceeded the retention budget and was spilled to a temp file. */\n\toverflow?: { fullOutputPath: string; totalBytes: number };\n}\n\ninterface GitFilterOptions {\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n}\n\nexport function unicodeTruncate(str: string, maxLength: number): string {\n\tconst chars = Array.from(str);\n\tif (chars.length <= maxLength) return str;\n\treturn `${chars.slice(0, maxLength).join(\"\")}...`;\n}\n\nexport function tokenizeCommand(command: string): string[] | null {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inDoubleQuotes = false;\n\tlet inSingleQuotes = false;\n\tlet escapeNext = false;\n\n\tfor (let i = 0; i < command.length; i++) {\n\t\tconst char = command[i];\n\t\tif (escapeNext) {\n\t\t\tcurrent += char;\n\t\t\tescapeNext = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"\\\\\" && !inSingleQuotes) {\n\t\t\tescapeNext = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '\"' && !inSingleQuotes) {\n\t\t\tinDoubleQuotes = !inDoubleQuotes;\n\t\t} else if (char === \"'\" && !inDoubleQuotes) {\n\t\t\tinSingleQuotes = !inSingleQuotes;\n\t\t} else if (/\\s/.test(char) && !inDoubleQuotes && !inSingleQuotes) {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\tif (inDoubleQuotes || inSingleQuotes || escapeNext) return null;\n\tif (current) args.push(current);\n\treturn args;\n}\n\nexport interface ParsedCommand {\n\tenvVars: Record<string, string>;\n\tcoreCommandTokens: string[];\n}\n\nexport function parseCommandPrefixes(command: string): ParsedCommand | null {\n\tconst tokens = tokenizeCommand(command);\n\tif (!tokens || tokens.length === 0) return null;\n\n\tconst envVars: Record<string, string> = {};\n\tlet i = 0;\n\tconst envPattern = /^([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$/;\n\n\twhile (i < tokens.length) {\n\t\tconst token = tokens[i];\n\t\tconst match = token.match(envPattern);\n\t\tif (!match) break;\n\t\tlet value = match[2];\n\t\tif ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n\t\t\tvalue = value.slice(1, -1);\n\t\t}\n\t\tenvVars[match[1]] = value;\n\t\ti++;\n\t}\n\n\treturn { envVars, coreCommandTokens: tokens.slice(i) };\n}\n\nexport function isComplexShellCommand(command: string): boolean {\n\treturn /[|><&;\\n\\r$`()*?[\\]#]/.test(command);\n}\n\nfunction quoteForShell(arg: string): string {\n\tif (/^[A-Za-z0-9_./:=+-]+$/.test(arg)) return arg;\n\treturn `'${arg.replace(/'/g, `'\"'\"'`)}'`;\n}\n\nfunction gitCommand(globalOptions: string[], args: string[]): string {\n\treturn [\"git\", ...globalOptions, ...args].map(quoteForShell).join(\" \");\n}\n\nfunction rawText(res: GitQueryResult, combine = false): string {\n\tif (combine) return `${res.stderr}${res.stderr && res.stdout ? \"\\n\" : \"\"}${res.stdout}`;\n\treturn res.stderr || res.stdout;\n}\n\nfunction applyOverflowDisclosure(res: GitQueryResult, result: FilterResult): FilterResult {\n\tif (!res.overflow) return result;\n\tconst totalMb = (res.overflow.totalBytes / (1024 * 1024)).toFixed(1);\n\treturn {\n\t\t...result,\n\t\toutput: `${result.output}\\n\\n[git output was ${totalMb}MB; filtered view computed from the retained head. Full output: ${res.overflow.fullOutputPath}]`,\n\t\tfullOutputPath: res.overflow.fullOutputPath,\n\t};\n}\n\nfunction resultFromQuery(res: GitQueryResult, output: string, exitCode = res.status ?? 0): FilterResult {\n\treturn applyOverflowDisclosure(res, { output, exitCode, rawOut: rawText(res), rawBytes: res.rawBytes });\n}\n\nexport async function runGitQuery(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<GitQueryResult> {\n\tif (options?.signal?.aborted) throw new Error(\"aborted\");\n\n\tconst child = spawn(\"git\", [...globalOptions, ...args], {\n\t\tcwd,\n\t\tdetached: process.platform !== \"win32\",\n\t\tenv: { ...process.env, LC_ALL: \"C\" },\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\twindowsHide: true,\n\t});\n\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\tconst stdoutChunks: Buffer[] = [];\n\tconst stderrChunks: Buffer[] = [];\n\tconst maxRetainedBytes = maxRetainedGitOutputBytes();\n\tlet retainedStdoutBytes = 0;\n\tlet totalStdoutBytes = 0;\n\tlet retainedStderrBytes = 0;\n\tlet overflowPath: string | undefined;\n\tlet overflowStream: WriteStream | undefined;\n\tlet overflowStreamEnded = false;\n\tlet overflowWriteError: Error | undefined;\n\tconst timeoutSeconds =\n\t\toptions?.timeout && options.timeout > 0 ? options.timeout : DEFAULT_GIT_FILTER_TIMEOUT_SECONDS;\n\n\ttry {\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\ttotalStdoutBytes += chunk.length;\n\t\t\tif (overflowStream) {\n\t\t\t\toverflowStream.write(chunk);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstdoutChunks.push(chunk);\n\t\t\tretainedStdoutBytes += chunk.length;\n\t\t\tif (retainedStdoutBytes > maxRetainedBytes) {\n\t\t\t\toverflowPath = join(\n\t\t\t\t\tgetProcessWorkRun(getAgentDir(), \"outputs\", \"git\").path,\n\t\t\t\t\t`pi-git-${randomBytes(8).toString(\"hex\")}.log`,\n\t\t\t\t);\n\t\t\t\toverflowStream = createSafeWriteStream(overflowPath, (error) => {\n\t\t\t\t\toverflowWriteError = error;\n\t\t\t\t});\n\t\t\t\tfor (const retained of stdoutChunks) overflowStream.write(retained);\n\t\t\t}\n\t\t});\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstderrChunks.push(chunk);\n\t\t\tretainedStderrBytes += chunk.length;\n\t\t\twhile (retainedStderrBytes > MAX_RETAINED_GIT_STDERR_BYTES && stderrChunks.length > 1) {\n\t\t\t\tretainedStderrBytes -= stderrChunks.shift()?.length ?? 0;\n\t\t\t}\n\t\t});\n\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\tsignal: options?.signal,\n\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\tkillGraceMs: GIT_FILTER_KILL_GRACE_MS,\n\t\t});\n\t\tif (terminal.reason === \"aborted\") throw new Error(\"aborted\");\n\t\tif (terminal.reason === \"timeout\") throw new Error(`timeout:${timeoutSeconds}`);\n\t\tconst status = terminal.code;\n\t\tconst stdoutBuffer = Buffer.concat(stdoutChunks);\n\t\tconst stderrBuffer = Buffer.concat(stderrChunks);\n\t\tif (overflowStream !== undefined && overflowPath !== undefined) {\n\t\t\tif (stderrBuffer.length > 0 && !overflowStream.writableEnded) {\n\t\t\t\toverflowStream.write(\"\\n--- stderr ---\\n\");\n\t\t\t\toverflowStream.write(stderrBuffer);\n\t\t\t}\n\t\t\tconst stream = overflowStream;\n\t\t\tawait new Promise<void>((resolveEnd) => {\n\t\t\t\tstream.end(() => resolveEnd());\n\t\t\t});\n\t\t\toverflowStreamEnded = true;\n\t\t\tif (overflowWriteError !== undefined) {\n\t\t\t\t// Spill failed (e.g. disk full): disclose the loss instead of pointing\n\t\t\t\t// consumers at a broken artifact, and keep the retained head usable.\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\t\t\tstderr: `${stderrBuffer.toString(\"utf-8\")}\\n[git output overflow spill failed: ${overflowWriteError.message}; output beyond the retained head was lost]`,\n\t\t\t\t\tstatus,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\t\tstderr: stderrBuffer.toString(\"utf-8\"),\n\t\t\t\tstatus,\n\t\t\t\toverflow: { fullOutputPath: overflowPath, totalBytes: totalStdoutBytes },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\tstderr: stderrBuffer.toString(\"utf-8\"),\n\t\t\tstatus,\n\t\t\trawBytes: Buffer.concat([stderrBuffer, stdoutBuffer]),\n\t\t};\n\t} finally {\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tif (overflowStream !== undefined && !overflowStreamEnded) overflowStream.end();\n\t}\n}\n\nexport function classifyGitCommand(\n\tcommand: string,\n\tparentEnv?: NodeJS.ProcessEnv,\n): {\n\teligible: boolean;\n\tsubcommand?: string;\n\tglobalOptions?: string[];\n\tsubcommandArgs?: string[];\n\tlocalEnv?: Record<string, string>;\n} {\n\tif (isComplexShellCommand(command)) return { eligible: false };\n\n\tconst parsed = parseCommandPrefixes(command);\n\tif (!parsed || parsed.coreCommandTokens.length === 0) return { eligible: false };\n\n\tconst { envVars, coreCommandTokens } = parsed;\n\tconst toolFilterDisabled =\n\t\tprocess.env.PI_TOOL_FILTER_DISABLED === \"1\" ||\n\t\tparentEnv?.PI_TOOL_FILTER_DISABLED === \"1\" ||\n\t\tenvVars.PI_TOOL_FILTER_DISABLED === \"1\";\n\tconst gitFilterDisabled =\n\t\tprocess.env.PI_GIT_FILTER_DISABLED === \"1\" ||\n\t\tparentEnv?.PI_GIT_FILTER_DISABLED === \"1\" ||\n\t\tenvVars.PI_GIT_FILTER_DISABLED === \"1\";\n\tif (toolFilterDisabled || gitFilterDisabled) return { eligible: false };\n\n\tconst envKeys = Object.keys(envVars).filter(\n\t\t(key) => key !== \"PI_TOOL_FILTER_DISABLED\" && key !== \"PI_GIT_FILTER_DISABLED\",\n\t);\n\tif (envKeys.length > 0) return { eligible: false };\n\n\tconst cmdName = coreCommandTokens[0];\n\tif (cmdName !== \"git\" && cmdName !== \"yadm\") return { eligible: false };\n\n\tlet idx = 1;\n\tconst globalOptions: string[] = [];\n\twhile (idx < coreCommandTokens.length) {\n\t\tconst token = coreCommandTokens[idx];\n\t\tif (token === \"-C\" || token === \"-c\" || token === \"--git-dir\" || token === \"--work-tree\") {\n\t\t\tif (idx + 1 >= coreCommandTokens.length) return { eligible: false };\n\t\t\tglobalOptions.push(token, coreCommandTokens[idx + 1]);\n\t\t\tidx += 2;\n\t\t} else if (token.startsWith(\"--git-dir=\") || token.startsWith(\"--work-tree=\")) {\n\t\t\tglobalOptions.push(token);\n\t\t\tidx++;\n\t\t} else if (\n\t\t\ttoken === \"--no-pager\" ||\n\t\t\ttoken === \"--no-optional-locks\" ||\n\t\t\ttoken === \"--bare\" ||\n\t\t\ttoken === \"--literal-pathspecs\"\n\t\t) {\n\t\t\tglobalOptions.push(token);\n\t\t\tidx++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (idx === coreCommandTokens.length) return { eligible: false };\n\tconst subcommand = coreCommandTokens[idx];\n\tif (!SUPPORTED_SUBCOMMANDS.has(subcommand)) return { eligible: false };\n\n\treturn {\n\t\teligible: true,\n\t\tsubcommand,\n\t\tglobalOptions,\n\t\tsubcommandArgs: coreCommandTokens.slice(idx + 1),\n\t\tlocalEnv: envVars,\n\t};\n}\n\nexport function detectGitState(gitDir: string): string[] {\n\tconst states: string[] = [];\n\tif (!gitDir) return states;\n\tif (existsSync(join(gitDir, \"rebase-merge\")) || existsSync(join(gitDir, \"rebase-apply\"))) {\n\t\tstates.push(\"rebase in progress\");\n\t}\n\tif (existsSync(join(gitDir, \"MERGE_HEAD\"))) states.push(\"merge in progress\");\n\tif (existsSync(join(gitDir, \"CHERRY_PICK_HEAD\"))) states.push(\"cherry-pick in progress\");\n\tif (existsSync(join(gitDir, \"REVERT_HEAD\"))) states.push(\"revert in progress\");\n\tif (existsSync(join(gitDir, \"BISECT_LOG\"))) states.push(\"bisect in progress\");\n\tif (existsSync(join(gitDir, \"applying\"))) states.push(\"am in progress\");\n\treturn states;\n}\n\nasync function handleStatus(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst isSimple =\n\t\targs.length === 0 || args.every((arg) => arg === \"-s\" || arg === \"--short\" || arg === \"-b\" || arg === \"--branch\");\n\n\tif (!isSimple) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"status\", ...args], options);\n\t\tconst rawOut = rawText(res);\n\t\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t\tconst cleanedLines = res.stdout\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.filter((line) => line.length > 0 && !line.trim().startsWith(\"(use \"));\n\t\tconst output = cleanedLines.join(\"\\n\");\n\t\treturn resultFromQuery(res, output || \"success\", 0);\n\t}\n\n\tconst res = await runGitQuery(cwd, globalOptions, [\"status\", \"--porcelain=v1\", \"-b\"], options);\n\tlet rawOut = rawText(res);\n\tif (res.status !== 0) {\n\t\tif (rawOut.includes(\"not a git repository\")) rawOut = \"fatal: not a git repository\";\n\t\treturn { output: rawOut.trim(), exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t}\n\n\tconst lines = res.stdout.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tlet branchLine = \"\";\n\tconst fileLines: string[] = [];\n\tfor (const line of lines) {\n\t\tif (line.startsWith(\"##\")) {\n\t\t\tbranchLine = line;\n\t\t} else {\n\t\t\tfileLines.push(line);\n\t\t}\n\t}\n\n\tlet statePrefix = \"\";\n\tconst gitDirRes = await runGitQuery(cwd, globalOptions, [\"rev-parse\", \"--git-dir\"], options);\n\tif (gitDirRes.status === 0) {\n\t\tconst gitDir = resolve(cwd, gitDirRes.stdout.trim());\n\t\tconst states = detectGitState(gitDir);\n\t\tif (states.length > 0) statePrefix = `[${states.join(\", \")}]\\n`;\n\t}\n\n\tif (branchLine.includes(\"HEAD (no branch)\")) {\n\t\tconst headHashRes = await runGitQuery(cwd, globalOptions, [\"rev-parse\", \"--short\", \"HEAD\"], options);\n\t\tconst hash = headHashRes.status === 0 ? headHashRes.stdout.trim() : \"unknown\";\n\t\tbranchLine = `## HEAD (detached at ${hash})`;\n\t}\n\n\tif (fileLines.length === 0) {\n\t\treturn resultFromQuery(res, `${statePrefix}${branchLine}\\nnothing to commit, working tree clean`, 0);\n\t}\n\treturn resultFromQuery(res, `${statePrefix}${branchLine}\\n${fileLines.join(\"\\n\")}`, 0);\n}\n\nasync function handleLog(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst hasLimit = args.some(\n\t\t(arg) => /^-n\\d+$/.test(arg) || arg === \"-n\" || /^-?\\d+$/.test(arg) || arg.startsWith(\"--max-count\"),\n\t);\n\tconst hasPretty = args.some(\n\t\t(arg) => arg.startsWith(\"--pretty\") || arg.startsWith(\"--format\") || arg === \"--oneline\",\n\t);\n\n\tconst logArgs = hasLimit ? [\"log\", ...args] : [\"log\", \"-n\", \"10\", \"--no-merges\", ...args];\n\tconst res = await runGitQuery(cwd, globalOptions, logArgs, options);\n\tif (hasPretty) return resultFromQuery(res, rawText(res), res.status ?? 0);\n\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\n\tconst commits = res.stdout.split(/(?=^commit [0-9a-f]{7,40})/m).filter((commit) => commit.trim().length > 0);\n\tconst compactedCommits: string[] = [];\n\tconst trailerPrefixes = [\n\t\t\"Signed-off-by:\",\n\t\t\"Co-authored-by:\",\n\t\t\"Reported-by:\",\n\t\t\"Reviewed-by:\",\n\t\t\"Tested-by:\",\n\t\t\"Suggested-by:\",\n\t\t\"CC:\",\n\t];\n\n\tfor (const commit of commits) {\n\t\tconst lines = commit.split(\"\\n\");\n\t\tconst commitLine = lines[0];\n\t\tif (!commitLine) continue;\n\t\tconst shortCommitLine = commitLine.replace(/^commit ([0-9a-f]{7})[0-9a-f]+/, \"commit $1\");\n\t\tconst bodyLines: string[] = [];\n\t\tfor (let i = 1; i < lines.length; i++) {\n\t\t\tconst line = lines[i];\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (!trimmed) continue;\n\t\t\tif (line.startsWith(\"Author:\") || line.startsWith(\"Date:\") || line.startsWith(\"Merge:\")) continue;\n\t\t\tif (trailerPrefixes.some((prefix) => trimmed.startsWith(prefix))) continue;\n\t\t\tbodyLines.push(line);\n\t\t}\n\t\tconst displayBody = bodyLines.slice(0, 3).map((line) => unicodeTruncate(line, 160));\n\t\tconst omitted = bodyLines.length - displayBody.length;\n\t\tif (omitted > 0) displayBody.push(` ... (${omitted} lines omitted)`);\n\t\tcompactedCommits.push(`${shortCommitLine}\\n${displayBody.join(\"\\n\")}`);\n\t}\n\n\treturn resultFromQuery(res, compactedCommits.join(\"\\n\\n\"), 0);\n}\n\nexport function compactDiff(diffOutput: string, maxLines = 150): { compacted: string; truncated: boolean } {\n\tconst lines = diffOutput.split(\"\\n\");\n\tconst output: string[] = [];\n\tlet linesCount = 0;\n\tlet truncated = false;\n\tlet contextBuffer: string[] = [];\n\tlet trailingContextRemaining = 0;\n\n\tfor (const line of lines) {\n\t\tif (linesCount >= maxLines) {\n\t\t\ttruncated = true;\n\t\t\tbreak;\n\t\t}\n\t\tif (\n\t\t\tline.startsWith(\"diff --git\") ||\n\t\t\tline.startsWith(\"--- \") ||\n\t\t\tline.startsWith(\"+++ \") ||\n\t\t\tline.startsWith(\"index \")\n\t\t) {\n\t\t\tcontextBuffer = [];\n\t\t\ttrailingContextRemaining = 0;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"@@ \")) {\n\t\t\tcontextBuffer = [];\n\t\t\ttrailingContextRemaining = 0;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"+\") || line.startsWith(\"-\")) {\n\t\t\tfor (const ctx of contextBuffer) {\n\t\t\t\tif (linesCount >= maxLines) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\toutput.push(ctx);\n\t\t\t\tlinesCount++;\n\t\t\t}\n\t\t\tcontextBuffer = [];\n\t\t\tif (truncated) break;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\ttrailingContextRemaining = 3;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\" \")) {\n\t\t\tif (trailingContextRemaining > 0) {\n\t\t\t\toutput.push(line);\n\t\t\t\tlinesCount++;\n\t\t\t\ttrailingContextRemaining--;\n\t\t\t} else {\n\t\t\t\tcontextBuffer.push(line);\n\t\t\t\tif (contextBuffer.length > 3) contextBuffer.shift();\n\t\t\t}\n\t\t} else {\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t}\n\t}\n\n\treturn { compacted: output.join(\"\\n\"), truncated };\n}\n\nasync function handleDiff(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst cleanArgs = [...args];\n\tconst noCompactIndex = cleanArgs.indexOf(\"--no-compact\");\n\tconst optOut = noCompactIndex !== -1;\n\tif (optOut) cleanArgs.splice(noCompactIndex, 1);\n\n\tconst statFlags = [\"--stat\", \"--numstat\", \"--shortstat\", \"--summary\", \"--name-only\", \"--name-status\", \"--check\"];\n\tconst isStatOnly = cleanArgs.some((arg) => statFlags.includes(arg));\n\tif (optOut || isStatOnly) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"diff\", ...cleanArgs], options);\n\t\treturn resultFromQuery(res, rawText(res), res.status ?? 0);\n\t}\n\n\tconst hasDoubleDash = cleanArgs.includes(\"--\");\n\tif (!hasDoubleDash) {\n\t\tconst pathIdx = cleanArgs.findIndex((arg) => {\n\t\t\tif (arg.startsWith(\"-\")) return false;\n\t\t\tif (!(arg.includes(\"/\") || arg.includes(\".\") || existsSync(join(cwd, arg)))) return false;\n\t\t\treturn existsSync(resolve(cwd, arg));\n\t\t});\n\t\tif (pathIdx !== -1) cleanArgs.splice(pathIdx, 0, \"--\");\n\t}\n\n\tconst statRes = await runGitQuery(cwd, globalOptions, [\"diff\", \"--stat\", ...cleanArgs], options);\n\tif (statRes.status !== 0) return resultFromQuery(statRes, rawText(statRes), statRes.status ?? 1);\n\tconst diffRes = await runGitQuery(cwd, globalOptions, [\"diff\", ...cleanArgs], options);\n\tif (diffRes.status !== 0) return resultFromQuery(diffRes, rawText(diffRes), diffRes.status ?? 1);\n\n\tconst { compacted, truncated } = compactDiff(diffRes.stdout);\n\tlet output = `${statRes.stdout.trimEnd()}\\n\\n${compacted}`.trim();\n\tif (truncated) output += \"\\n\\n[Diff truncated. Re-run with: git diff --no-compact]\";\n\treturn applyOverflowDisclosure(diffRes, { output, exitCode: 0, rawOut: diffRes.stdout, rawBytes: diffRes.rawBytes });\n}\n\nasync function handleShow(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst statFlags = [\"--stat\", \"--numstat\", \"--shortstat\", \"--summary\", \"--name-only\", \"--name-status\", \"--check\"];\n\tconst hasStatOnly = args.some((arg) => statFlags.includes(arg));\n\tconst hasPretty = args.some(\n\t\t(arg) => arg.startsWith(\"--pretty\") || arg.startsWith(\"--format\") || arg === \"--oneline\",\n\t);\n\tconst hasBlob = args.some((arg) => !arg.startsWith(\"-\") && arg.includes(\":\"));\n\tif (hasStatOnly || hasPretty || hasBlob) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"show\", ...args], options);\n\t\treturn resultFromQuery(res, rawText(res), res.status ?? 0);\n\t}\n\n\tconst showRes = await runGitQuery(cwd, globalOptions, [\"show\", ...args], options);\n\tconst rawOut = rawText(showRes);\n\tif (showRes.status !== 0)\n\t\treturn { output: rawOut, exitCode: showRes.status ?? 1, rawOut, rawBytes: showRes.rawBytes };\n\n\tconst lines = showRes.stdout.split(\"\\n\");\n\tconst diffStart = lines.findIndex((line) => line.startsWith(\"diff --git\"));\n\tconst headerLines = diffStart === -1 ? lines : lines.slice(0, diffStart);\n\tconst diffLines = diffStart === -1 ? [] : lines.slice(diffStart);\n\tconst summaryLines = headerLines.filter((line) => {\n\t\tconst trimmed = line.trim();\n\t\tif (!trimmed) return false;\n\t\tif (line.startsWith(\"Author:\") || line.startsWith(\"Date:\") || line.startsWith(\"Merge:\")) return false;\n\t\treturn true;\n\t});\n\tconst shortSummary = summaryLines\n\t\t.slice(0, 4)\n\t\t.map((line) => unicodeTruncate(line.replace(/^commit ([0-9a-f]{7})[0-9a-f]+/, \"commit $1\"), 160));\n\tconst { compacted, truncated } = compactDiff(diffLines.join(\"\\n\"));\n\tlet output = shortSummary.join(\"\\n\");\n\tif (compacted.trim()) output += `\\n\\n${compacted}`;\n\tif (truncated) output += \"\\n\\n[Diff truncated.]\";\n\treturn resultFromQuery(showRes, output.trim(), 0);\n}\n\nasync function handlePassthroughGit(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, args, options);\n\treturn resultFromQuery(res, rawText(res, true).trim(), res.status ?? 0);\n}\n\nasync function handleAdd(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tif (args.length === 0) return handlePassthroughGit(cwd, globalOptions, [\"add\"], options);\n\tconst addRes = await runGitQuery(cwd, globalOptions, [\"add\", ...args], options);\n\tconst rawOut = rawText(addRes);\n\tif (addRes.status !== 0) return { output: rawOut, exitCode: addRes.status ?? 1, rawOut, rawBytes: addRes.rawBytes };\n\tconst statRes = await runGitQuery(cwd, globalOptions, [\"diff\", \"--cached\", \"--stat\"], options);\n\tif (statRes.status === 0 && statRes.stdout.trim().length > 0) {\n\t\treturn { output: `Staged changes:\\n${statRes.stdout.trim()}`, exitCode: 0, rawOut, rawBytes: addRes.rawBytes };\n\t}\n\treturn { output: rawOut.trim() || \"Successfully staged.\", exitCode: 0, rawOut, rawBytes: addRes.rawBytes };\n}\n\nasync function handleCommit(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst hasMsg = args.some(\n\t\t(arg) => arg === \"-m\" || arg === \"-F\" || arg.startsWith(\"--message\") || arg.startsWith(\"--file\"),\n\t);\n\tif (!hasMsg) return { output: \"\", exitCode: -100, rawOut: \"\" };\n\tconst res = await runGitQuery(cwd, globalOptions, [\"commit\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (rawOut.includes(\"nothing to commit\") || rawOut.includes(\"working tree clean\")) {\n\t\treturn { output: \"nothing to commit, working tree clean\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst firstLine = rawOut\n\t\t.split(\"\\n\")\n\t\t.find((line) => line.trim().length > 0)\n\t\t?.trim();\n\treturn { output: firstLine || \"Committed successfully.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handlePush(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"push\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tconst outputLines = rawOut\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trimEnd())\n\t\t.filter((line) => {\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (!trimmed) return false;\n\t\t\treturn ![\"Writing objects:\", \"Counting objects:\", \"Delta compression\", \"Compressing objects:\", \"Total \"].some(\n\t\t\t\t(prefix) => trimmed.startsWith(prefix),\n\t\t\t);\n\t\t});\n\tif (res.status !== 0)\n\t\treturn { output: outputLines.join(\"\\n\"), exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (outputLines.some((line) => line.includes(\"Everything up-to-date\"))) {\n\t\treturn { output: \"Everything up-to-date.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst remoteMessages = outputLines.filter((line) => line.trim().startsWith(\"remote:\"));\n\tconst pushDetail = outputLines.find((line) => line.includes(\"->\"));\n\tconst summary = pushDetail ? `Pushed: ${pushDetail.trim()}` : \"Push successful.\";\n\treturn { output: [...remoteMessages, summary].join(\"\\n\"), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handlePull(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"pull\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (rawOut.includes(\"Already up to date.\"))\n\t\treturn { output: \"Already up to date.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst lines = rawOut.split(\"\\n\");\n\tconst summary = lines.filter(\n\t\t(line) => line.includes(\"Fast-forward\") || line.includes(\"file changed\") || line.includes(\"files changed\"),\n\t);\n\treturn { output: summary.join(\"\\n\") || \"Pull successful.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleFetch(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"fetch\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tconst refs = rawOut\n\t\t.split(\"\\n\")\n\t\t.filter((line) => line.includes(\"[new branch]\") || line.includes(\"[new tag]\") || line.includes(\"->\"));\n\treturn {\n\t\toutput: refs.length\n\t\t\t? `Fetched:\\n${refs.map((line) => line.trim()).join(\"\\n\")}`\n\t\t\t: \"Fetch successful (no new refs).\",\n\t\texitCode: 0,\n\t\trawOut,\n\t\trawBytes: res.rawBytes,\n\t};\n}\n\nasync function handleBranch(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tif (args.includes(\"--show-current\")) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", \"--show-current\"], options);\n\t\treturn { output: res.stdout.trim(), exitCode: res.status ?? 0, rawOut: rawText(res), rawBytes: res.rawBytes };\n\t}\n\tconst isWrite = args.some(\n\t\t(arg) =>\n\t\t\targ === \"-d\" || arg === \"-D\" || arg === \"-m\" || arg === \"-M\" || (!arg.startsWith(\"-\") && args.length === 1),\n\t);\n\tif (isWrite) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", ...args], options);\n\t\tconst rawOut = rawText(res);\n\t\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t\treturn { output: rawOut.trim() || \"Branch updated successfully.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", \"--no-color\", ...args], options);\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tconst lines = res.stdout.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tconst remoteBranches = lines.filter((line) => line.includes(\"remotes/\"));\n\tconst localBranches = lines.filter((line) => !line.includes(\"remotes/\"));\n\tconst remoteDisplay = remoteBranches.slice(0, 5);\n\tconst omitted = remoteBranches.length - remoteDisplay.length;\n\tif (omitted > 0) remoteDisplay.push(` remotes/... (${omitted} more remote branches)`);\n\treturn { output: [...localBranches, ...remoteDisplay].join(\"\\n\"), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleStash(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst sub = args[0] || \"push\";\n\tconst res = await runGitQuery(cwd, globalOptions, [\"stash\", ...args], options);\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (sub === \"list\")\n\t\treturn { output: res.stdout.trim() || \"No stashes found.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tif (sub === \"show\") {\n\t\tconst { compacted, truncated } = compactDiff(res.stdout);\n\t\treturn applyOverflowDisclosure(res, {\n\t\t\toutput: `${compacted.trim()}${truncated ? \"\\n\\n[Diff truncated.]\" : \"\"}`,\n\t\t\texitCode: 0,\n\t\t\trawOut,\n\t\t\trawBytes: res.rawBytes,\n\t\t});\n\t}\n\tif (res.stdout.includes(\"No local changes to save\"))\n\t\treturn { output: \"No local changes to save.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst firstLine = res.stdout\n\t\t.split(\"\\n\")\n\t\t.find((line) => line.trim().length > 0)\n\t\t?.trim();\n\treturn { output: firstLine || \"Stash successful.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleWorktree(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst sub = args[0] || \"list\";\n\tconst res = await runGitQuery(cwd, globalOptions, [\"worktree\", ...(sub === \"list\" ? [\"list\"] : args)], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (sub !== \"list\") return { output: rawOut.trim(), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst home = process.env.HOME || \"\";\n\tconst output = res.stdout\n\t\t.split(\"\\n\")\n\t\t.map((line) => (home && line.startsWith(home) ? `~${line.slice(home.length)}` : line))\n\t\t.join(\"\\n\")\n\t\t.trim();\n\treturn { output, exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nexport async function executeFilteredGit(\n\tcwd: string,\n\tsubcommand: string,\n\tglobalOptions: string[],\n\tsubcommandArgs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tswitch (subcommand) {\n\t\tcase \"status\":\n\t\t\treturn handleStatus(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"log\":\n\t\t\treturn handleLog(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"diff\":\n\t\t\treturn handleDiff(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"show\":\n\t\t\treturn handleShow(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"add\":\n\t\t\treturn handleAdd(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"commit\":\n\t\t\treturn handleCommit(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"push\":\n\t\t\treturn handlePush(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"pull\":\n\t\t\treturn handlePull(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"branch\":\n\t\t\treturn handleBranch(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"fetch\":\n\t\t\treturn handleFetch(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"stash\":\n\t\t\treturn handleStash(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"worktree\":\n\t\t\treturn handleWorktree(cwd, globalOptions, subcommandArgs, options);\n\t\tdefault:\n\t\t\treturn { output: \"\", exitCode: -100, rawOut: \"\" };\n\t}\n}\n\nexport function makeGitCommandForDisplay(globalOptions: string[], subcommand: string, args: string[]): string {\n\treturn gitCommand(globalOptions, [subcommand, ...args]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git-filter.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-filter.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAoCzG,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAc;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AAED,UAAU,gBAAgB;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAItE;AA8BD,wBAAsB,WAAW,CAChC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EAAE,EACvB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,cAAc,CAAC,CAkGzB;AAED,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,CAAC,UAAU,GAC3B;IACF,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CA4DA;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYvD;AAoHD,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,SAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAgEzG;AA4RD,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,cAAc,EAAE,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,YAAY,CAAC,CA6BvB;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAE5G","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport { existsSync, type WriteStream } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport { createSafeWriteStream } from \"../../utils/safe-write-stream.ts\";\nimport { trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport { isComplexShellCommand, parseCommandPrefixes } from \"./shell-command-parser.ts\";\n\nexport { isComplexShellCommand, parseCommandPrefixes, tokenizeCommand } from \"./shell-command-parser.ts\";\n\n/**\n * Retention budget for git output held in memory while filtering. Output beyond\n * the budget is spilled to a temp file so a giant `git log -p`/`git diff` cannot\n * exhaust the V8 heap. Override with PI_GIT_FILTER_MAX_RETAINED_BYTES.\n */\nconst DEFAULT_MAX_RETAINED_GIT_OUTPUT_BYTES = 48 * 1024 * 1024;\nconst MAX_RETAINED_GIT_STDERR_BYTES = 8 * 1024 * 1024;\nconst DEFAULT_GIT_FILTER_TIMEOUT_SECONDS = 10 * 60;\nconst GIT_FILTER_KILL_GRACE_MS = 2_000;\n\nfunction maxRetainedGitOutputBytes(): number {\n\tconst raw = process.env.PI_GIT_FILTER_MAX_RETAINED_BYTES;\n\tif (raw !== undefined) {\n\t\tconst parsed = Number.parseInt(raw, 10);\n\t\tif (Number.isFinite(parsed) && parsed > 0) return parsed;\n\t}\n\treturn DEFAULT_MAX_RETAINED_GIT_OUTPUT_BYTES;\n}\n\nconst SUPPORTED_SUBCOMMANDS = new Set([\n\t\"status\",\n\t\"log\",\n\t\"diff\",\n\t\"show\",\n\t\"add\",\n\t\"commit\",\n\t\"push\",\n\t\"pull\",\n\t\"branch\",\n\t\"fetch\",\n\t\"stash\",\n\t\"worktree\",\n]);\n\nexport interface FilterResult {\n\toutput: string;\n\texitCode: number;\n\trawOut: string;\n\trawBytes?: Buffer;\n\t/** Set when git output exceeded the in-memory retention budget; the file holds the full output. */\n\tfullOutputPath?: string;\n}\n\ninterface GitQueryResult {\n\tstdout: string;\n\tstderr: string;\n\tstatus: number | null;\n\t/** Full raw output (stderr then stdout). Absent when output overflowed to disk. */\n\trawBytes?: Buffer;\n\t/** Set when stdout exceeded the retention budget and was spilled to a temp file. */\n\toverflow?: { fullOutputPath: string; totalBytes: number };\n}\n\ninterface GitFilterOptions {\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n}\n\nexport function unicodeTruncate(str: string, maxLength: number): string {\n\tconst chars = Array.from(str);\n\tif (chars.length <= maxLength) return str;\n\treturn `${chars.slice(0, maxLength).join(\"\")}...`;\n}\n\nfunction quoteForShell(arg: string): string {\n\tif (/^[A-Za-z0-9_./:=+-]+$/.test(arg)) return arg;\n\treturn `'${arg.replace(/'/g, `'\"'\"'`)}'`;\n}\n\nfunction gitCommand(globalOptions: string[], args: string[]): string {\n\treturn [\"git\", ...globalOptions, ...args].map(quoteForShell).join(\" \");\n}\n\nfunction rawText(res: GitQueryResult, combine = false): string {\n\tif (combine) return `${res.stderr}${res.stderr && res.stdout ? \"\\n\" : \"\"}${res.stdout}`;\n\treturn res.stderr || res.stdout;\n}\n\nfunction applyOverflowDisclosure(res: GitQueryResult, result: FilterResult): FilterResult {\n\tif (!res.overflow) return result;\n\tconst totalMb = (res.overflow.totalBytes / (1024 * 1024)).toFixed(1);\n\treturn {\n\t\t...result,\n\t\toutput: `${result.output}\\n\\n[git output was ${totalMb}MB; filtered view computed from the retained head. Full output: ${res.overflow.fullOutputPath}]`,\n\t\tfullOutputPath: res.overflow.fullOutputPath,\n\t};\n}\n\nfunction resultFromQuery(res: GitQueryResult, output: string, exitCode = res.status ?? 0): FilterResult {\n\treturn applyOverflowDisclosure(res, { output, exitCode, rawOut: rawText(res), rawBytes: res.rawBytes });\n}\n\nexport async function runGitQuery(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<GitQueryResult> {\n\tif (options?.signal?.aborted) throw new Error(\"aborted\");\n\n\tconst child = spawn(\"git\", [...globalOptions, ...args], {\n\t\tcwd,\n\t\tdetached: process.platform !== \"win32\",\n\t\tenv: { ...process.env, LC_ALL: \"C\" },\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\twindowsHide: true,\n\t});\n\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\tconst stdoutChunks: Buffer[] = [];\n\tconst stderrChunks: Buffer[] = [];\n\tconst maxRetainedBytes = maxRetainedGitOutputBytes();\n\tlet retainedStdoutBytes = 0;\n\tlet totalStdoutBytes = 0;\n\tlet retainedStderrBytes = 0;\n\tlet overflowPath: string | undefined;\n\tlet overflowStream: WriteStream | undefined;\n\tlet overflowStreamEnded = false;\n\tlet overflowWriteError: Error | undefined;\n\tconst timeoutSeconds =\n\t\toptions?.timeout && options.timeout > 0 ? options.timeout : DEFAULT_GIT_FILTER_TIMEOUT_SECONDS;\n\n\ttry {\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\ttotalStdoutBytes += chunk.length;\n\t\t\tif (overflowStream) {\n\t\t\t\toverflowStream.write(chunk);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstdoutChunks.push(chunk);\n\t\t\tretainedStdoutBytes += chunk.length;\n\t\t\tif (retainedStdoutBytes > maxRetainedBytes) {\n\t\t\t\toverflowPath = join(\n\t\t\t\t\tgetProcessWorkRun(getAgentDir(), \"outputs\", \"git\").path,\n\t\t\t\t\t`pi-git-${randomBytes(8).toString(\"hex\")}.log`,\n\t\t\t\t);\n\t\t\t\toverflowStream = createSafeWriteStream(overflowPath, (error) => {\n\t\t\t\t\toverflowWriteError = error;\n\t\t\t\t});\n\t\t\t\tfor (const retained of stdoutChunks) overflowStream.write(retained);\n\t\t\t}\n\t\t});\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\tstderrChunks.push(chunk);\n\t\t\tretainedStderrBytes += chunk.length;\n\t\t\twhile (retainedStderrBytes > MAX_RETAINED_GIT_STDERR_BYTES && stderrChunks.length > 1) {\n\t\t\t\tretainedStderrBytes -= stderrChunks.shift()?.length ?? 0;\n\t\t\t}\n\t\t});\n\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\tsignal: options?.signal,\n\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\tkillGraceMs: GIT_FILTER_KILL_GRACE_MS,\n\t\t});\n\t\tif (terminal.reason === \"aborted\") throw new Error(\"aborted\");\n\t\tif (terminal.reason === \"timeout\") throw new Error(`timeout:${timeoutSeconds}`);\n\t\tconst status = terminal.code;\n\t\tconst stdoutBuffer = Buffer.concat(stdoutChunks);\n\t\tconst stderrBuffer = Buffer.concat(stderrChunks);\n\t\tif (overflowStream !== undefined && overflowPath !== undefined) {\n\t\t\tif (stderrBuffer.length > 0 && !overflowStream.writableEnded) {\n\t\t\t\toverflowStream.write(\"\\n--- stderr ---\\n\");\n\t\t\t\toverflowStream.write(stderrBuffer);\n\t\t\t}\n\t\t\tconst stream = overflowStream;\n\t\t\tawait new Promise<void>((resolveEnd) => {\n\t\t\t\tstream.end(() => resolveEnd());\n\t\t\t});\n\t\t\toverflowStreamEnded = true;\n\t\t\tif (overflowWriteError !== undefined) {\n\t\t\t\t// Spill failed (e.g. disk full): disclose the loss instead of pointing\n\t\t\t\t// consumers at a broken artifact, and keep the retained head usable.\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\t\t\tstderr: `${stderrBuffer.toString(\"utf-8\")}\\n[git output overflow spill failed: ${overflowWriteError.message}; output beyond the retained head was lost]`,\n\t\t\t\t\tstatus,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\t\tstderr: stderrBuffer.toString(\"utf-8\"),\n\t\t\t\tstatus,\n\t\t\t\toverflow: { fullOutputPath: overflowPath, totalBytes: totalStdoutBytes },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstdout: stdoutBuffer.toString(\"utf-8\"),\n\t\t\tstderr: stderrBuffer.toString(\"utf-8\"),\n\t\t\tstatus,\n\t\t\trawBytes: Buffer.concat([stderrBuffer, stdoutBuffer]),\n\t\t};\n\t} finally {\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tif (overflowStream !== undefined && !overflowStreamEnded) overflowStream.end();\n\t}\n}\n\nexport function classifyGitCommand(\n\tcommand: string,\n\tparentEnv?: NodeJS.ProcessEnv,\n): {\n\teligible: boolean;\n\tsubcommand?: string;\n\tglobalOptions?: string[];\n\tsubcommandArgs?: string[];\n\tlocalEnv?: Record<string, string>;\n} {\n\tif (isComplexShellCommand(command)) return { eligible: false };\n\n\tconst parsed = parseCommandPrefixes(command);\n\tif (!parsed || parsed.coreCommandTokens.length === 0) return { eligible: false };\n\n\tconst { envVars, coreCommandTokens } = parsed;\n\tconst toolFilterDisabled =\n\t\tprocess.env.PI_TOOL_FILTER_DISABLED === \"1\" ||\n\t\tparentEnv?.PI_TOOL_FILTER_DISABLED === \"1\" ||\n\t\tenvVars.PI_TOOL_FILTER_DISABLED === \"1\";\n\tconst gitFilterDisabled =\n\t\tprocess.env.PI_GIT_FILTER_DISABLED === \"1\" ||\n\t\tparentEnv?.PI_GIT_FILTER_DISABLED === \"1\" ||\n\t\tenvVars.PI_GIT_FILTER_DISABLED === \"1\";\n\tif (toolFilterDisabled || gitFilterDisabled) return { eligible: false };\n\n\tconst envKeys = Object.keys(envVars).filter(\n\t\t(key) => key !== \"PI_TOOL_FILTER_DISABLED\" && key !== \"PI_GIT_FILTER_DISABLED\",\n\t);\n\tif (envKeys.length > 0) return { eligible: false };\n\n\tconst cmdName = coreCommandTokens[0];\n\tif (cmdName !== \"git\" && cmdName !== \"yadm\") return { eligible: false };\n\n\tlet idx = 1;\n\tconst globalOptions: string[] = [];\n\twhile (idx < coreCommandTokens.length) {\n\t\tconst token = coreCommandTokens[idx];\n\t\tif (token === \"-C\" || token === \"-c\" || token === \"--git-dir\" || token === \"--work-tree\") {\n\t\t\tif (idx + 1 >= coreCommandTokens.length) return { eligible: false };\n\t\t\tglobalOptions.push(token, coreCommandTokens[idx + 1]);\n\t\t\tidx += 2;\n\t\t} else if (token.startsWith(\"--git-dir=\") || token.startsWith(\"--work-tree=\")) {\n\t\t\tglobalOptions.push(token);\n\t\t\tidx++;\n\t\t} else if (\n\t\t\ttoken === \"--no-pager\" ||\n\t\t\ttoken === \"--no-optional-locks\" ||\n\t\t\ttoken === \"--bare\" ||\n\t\t\ttoken === \"--literal-pathspecs\"\n\t\t) {\n\t\t\tglobalOptions.push(token);\n\t\t\tidx++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (idx === coreCommandTokens.length) return { eligible: false };\n\tconst subcommand = coreCommandTokens[idx];\n\tif (!SUPPORTED_SUBCOMMANDS.has(subcommand)) return { eligible: false };\n\n\treturn {\n\t\teligible: true,\n\t\tsubcommand,\n\t\tglobalOptions,\n\t\tsubcommandArgs: coreCommandTokens.slice(idx + 1),\n\t\tlocalEnv: envVars,\n\t};\n}\n\nexport function detectGitState(gitDir: string): string[] {\n\tconst states: string[] = [];\n\tif (!gitDir) return states;\n\tif (existsSync(join(gitDir, \"rebase-merge\")) || existsSync(join(gitDir, \"rebase-apply\"))) {\n\t\tstates.push(\"rebase in progress\");\n\t}\n\tif (existsSync(join(gitDir, \"MERGE_HEAD\"))) states.push(\"merge in progress\");\n\tif (existsSync(join(gitDir, \"CHERRY_PICK_HEAD\"))) states.push(\"cherry-pick in progress\");\n\tif (existsSync(join(gitDir, \"REVERT_HEAD\"))) states.push(\"revert in progress\");\n\tif (existsSync(join(gitDir, \"BISECT_LOG\"))) states.push(\"bisect in progress\");\n\tif (existsSync(join(gitDir, \"applying\"))) states.push(\"am in progress\");\n\treturn states;\n}\n\nasync function handleStatus(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst isSimple =\n\t\targs.length === 0 || args.every((arg) => arg === \"-s\" || arg === \"--short\" || arg === \"-b\" || arg === \"--branch\");\n\n\tif (!isSimple) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"status\", ...args], options);\n\t\tconst rawOut = rawText(res);\n\t\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t\tconst cleanedLines = res.stdout\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.filter((line) => line.length > 0 && !line.trim().startsWith(\"(use \"));\n\t\tconst output = cleanedLines.join(\"\\n\");\n\t\treturn resultFromQuery(res, output || \"success\", 0);\n\t}\n\n\tconst res = await runGitQuery(cwd, globalOptions, [\"status\", \"--porcelain=v1\", \"-b\"], options);\n\tlet rawOut = rawText(res);\n\tif (res.status !== 0) {\n\t\tif (rawOut.includes(\"not a git repository\")) rawOut = \"fatal: not a git repository\";\n\t\treturn { output: rawOut.trim(), exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t}\n\n\tconst lines = res.stdout.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tlet branchLine = \"\";\n\tconst fileLines: string[] = [];\n\tfor (const line of lines) {\n\t\tif (line.startsWith(\"##\")) {\n\t\t\tbranchLine = line;\n\t\t} else {\n\t\t\tfileLines.push(line);\n\t\t}\n\t}\n\n\tlet statePrefix = \"\";\n\tconst gitDirRes = await runGitQuery(cwd, globalOptions, [\"rev-parse\", \"--git-dir\"], options);\n\tif (gitDirRes.status === 0) {\n\t\tconst gitDir = resolve(cwd, gitDirRes.stdout.trim());\n\t\tconst states = detectGitState(gitDir);\n\t\tif (states.length > 0) statePrefix = `[${states.join(\", \")}]\\n`;\n\t}\n\n\tif (branchLine.includes(\"HEAD (no branch)\")) {\n\t\tconst headHashRes = await runGitQuery(cwd, globalOptions, [\"rev-parse\", \"--short\", \"HEAD\"], options);\n\t\tconst hash = headHashRes.status === 0 ? headHashRes.stdout.trim() : \"unknown\";\n\t\tbranchLine = `## HEAD (detached at ${hash})`;\n\t}\n\n\tif (fileLines.length === 0) {\n\t\treturn resultFromQuery(res, `${statePrefix}${branchLine}\\nnothing to commit, working tree clean`, 0);\n\t}\n\treturn resultFromQuery(res, `${statePrefix}${branchLine}\\n${fileLines.join(\"\\n\")}`, 0);\n}\n\nasync function handleLog(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst hasLimit = args.some(\n\t\t(arg) => /^-n\\d+$/.test(arg) || arg === \"-n\" || /^-?\\d+$/.test(arg) || arg.startsWith(\"--max-count\"),\n\t);\n\tconst hasPretty = args.some(\n\t\t(arg) => arg.startsWith(\"--pretty\") || arg.startsWith(\"--format\") || arg === \"--oneline\",\n\t);\n\n\tconst logArgs = hasLimit ? [\"log\", ...args] : [\"log\", \"-n\", \"10\", \"--no-merges\", ...args];\n\tconst res = await runGitQuery(cwd, globalOptions, logArgs, options);\n\tif (hasPretty) return resultFromQuery(res, rawText(res), res.status ?? 0);\n\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\n\tconst commits = res.stdout.split(/(?=^commit [0-9a-f]{7,40})/m).filter((commit) => commit.trim().length > 0);\n\tconst compactedCommits: string[] = [];\n\tconst trailerPrefixes = [\n\t\t\"Signed-off-by:\",\n\t\t\"Co-authored-by:\",\n\t\t\"Reported-by:\",\n\t\t\"Reviewed-by:\",\n\t\t\"Tested-by:\",\n\t\t\"Suggested-by:\",\n\t\t\"CC:\",\n\t];\n\n\tfor (const commit of commits) {\n\t\tconst lines = commit.split(\"\\n\");\n\t\tconst commitLine = lines[0];\n\t\tif (!commitLine) continue;\n\t\tconst shortCommitLine = commitLine.replace(/^commit ([0-9a-f]{7})[0-9a-f]+/, \"commit $1\");\n\t\tconst bodyLines: string[] = [];\n\t\tfor (let i = 1; i < lines.length; i++) {\n\t\t\tconst line = lines[i];\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (!trimmed) continue;\n\t\t\tif (line.startsWith(\"Author:\") || line.startsWith(\"Date:\") || line.startsWith(\"Merge:\")) continue;\n\t\t\tif (trailerPrefixes.some((prefix) => trimmed.startsWith(prefix))) continue;\n\t\t\tbodyLines.push(line);\n\t\t}\n\t\tconst displayBody = bodyLines.slice(0, 3).map((line) => unicodeTruncate(line, 160));\n\t\tconst omitted = bodyLines.length - displayBody.length;\n\t\tif (omitted > 0) displayBody.push(` ... (${omitted} lines omitted)`);\n\t\tcompactedCommits.push(`${shortCommitLine}\\n${displayBody.join(\"\\n\")}`);\n\t}\n\n\treturn resultFromQuery(res, compactedCommits.join(\"\\n\\n\"), 0);\n}\n\nexport function compactDiff(diffOutput: string, maxLines = 150): { compacted: string; truncated: boolean } {\n\tconst lines = diffOutput.split(\"\\n\");\n\tconst output: string[] = [];\n\tlet linesCount = 0;\n\tlet truncated = false;\n\tlet contextBuffer: string[] = [];\n\tlet trailingContextRemaining = 0;\n\n\tfor (const line of lines) {\n\t\tif (linesCount >= maxLines) {\n\t\t\ttruncated = true;\n\t\t\tbreak;\n\t\t}\n\t\tif (\n\t\t\tline.startsWith(\"diff --git\") ||\n\t\t\tline.startsWith(\"--- \") ||\n\t\t\tline.startsWith(\"+++ \") ||\n\t\t\tline.startsWith(\"index \")\n\t\t) {\n\t\t\tcontextBuffer = [];\n\t\t\ttrailingContextRemaining = 0;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"@@ \")) {\n\t\t\tcontextBuffer = [];\n\t\t\ttrailingContextRemaining = 0;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\"+\") || line.startsWith(\"-\")) {\n\t\t\tfor (const ctx of contextBuffer) {\n\t\t\t\tif (linesCount >= maxLines) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\toutput.push(ctx);\n\t\t\t\tlinesCount++;\n\t\t\t}\n\t\t\tcontextBuffer = [];\n\t\t\tif (truncated) break;\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t\ttrailingContextRemaining = 3;\n\t\t\tcontinue;\n\t\t}\n\t\tif (line.startsWith(\" \")) {\n\t\t\tif (trailingContextRemaining > 0) {\n\t\t\t\toutput.push(line);\n\t\t\t\tlinesCount++;\n\t\t\t\ttrailingContextRemaining--;\n\t\t\t} else {\n\t\t\t\tcontextBuffer.push(line);\n\t\t\t\tif (contextBuffer.length > 3) contextBuffer.shift();\n\t\t\t}\n\t\t} else {\n\t\t\toutput.push(line);\n\t\t\tlinesCount++;\n\t\t}\n\t}\n\n\treturn { compacted: output.join(\"\\n\"), truncated };\n}\n\nasync function handleDiff(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst cleanArgs = [...args];\n\tconst noCompactIndex = cleanArgs.indexOf(\"--no-compact\");\n\tconst optOut = noCompactIndex !== -1;\n\tif (optOut) cleanArgs.splice(noCompactIndex, 1);\n\n\tconst statFlags = [\"--stat\", \"--numstat\", \"--shortstat\", \"--summary\", \"--name-only\", \"--name-status\", \"--check\"];\n\tconst isStatOnly = cleanArgs.some((arg) => statFlags.includes(arg));\n\tif (optOut || isStatOnly) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"diff\", ...cleanArgs], options);\n\t\treturn resultFromQuery(res, rawText(res), res.status ?? 0);\n\t}\n\n\tconst hasDoubleDash = cleanArgs.includes(\"--\");\n\tif (!hasDoubleDash) {\n\t\tconst pathIdx = cleanArgs.findIndex((arg) => {\n\t\t\tif (arg.startsWith(\"-\")) return false;\n\t\t\tif (!(arg.includes(\"/\") || arg.includes(\".\") || existsSync(join(cwd, arg)))) return false;\n\t\t\treturn existsSync(resolve(cwd, arg));\n\t\t});\n\t\tif (pathIdx !== -1) cleanArgs.splice(pathIdx, 0, \"--\");\n\t}\n\n\tconst statRes = await runGitQuery(cwd, globalOptions, [\"diff\", \"--stat\", ...cleanArgs], options);\n\tif (statRes.status !== 0) return resultFromQuery(statRes, rawText(statRes), statRes.status ?? 1);\n\tconst diffRes = await runGitQuery(cwd, globalOptions, [\"diff\", ...cleanArgs], options);\n\tif (diffRes.status !== 0) return resultFromQuery(diffRes, rawText(diffRes), diffRes.status ?? 1);\n\n\tconst { compacted, truncated } = compactDiff(diffRes.stdout);\n\tlet output = `${statRes.stdout.trimEnd()}\\n\\n${compacted}`.trim();\n\tif (truncated) output += \"\\n\\n[Diff truncated. Re-run with: git diff --no-compact]\";\n\treturn applyOverflowDisclosure(diffRes, { output, exitCode: 0, rawOut: diffRes.stdout, rawBytes: diffRes.rawBytes });\n}\n\nasync function handleShow(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst statFlags = [\"--stat\", \"--numstat\", \"--shortstat\", \"--summary\", \"--name-only\", \"--name-status\", \"--check\"];\n\tconst hasStatOnly = args.some((arg) => statFlags.includes(arg));\n\tconst hasPretty = args.some(\n\t\t(arg) => arg.startsWith(\"--pretty\") || arg.startsWith(\"--format\") || arg === \"--oneline\",\n\t);\n\tconst hasBlob = args.some((arg) => !arg.startsWith(\"-\") && arg.includes(\":\"));\n\tif (hasStatOnly || hasPretty || hasBlob) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"show\", ...args], options);\n\t\treturn resultFromQuery(res, rawText(res), res.status ?? 0);\n\t}\n\n\tconst showRes = await runGitQuery(cwd, globalOptions, [\"show\", ...args], options);\n\tconst rawOut = rawText(showRes);\n\tif (showRes.status !== 0)\n\t\treturn { output: rawOut, exitCode: showRes.status ?? 1, rawOut, rawBytes: showRes.rawBytes };\n\n\tconst lines = showRes.stdout.split(\"\\n\");\n\tconst diffStart = lines.findIndex((line) => line.startsWith(\"diff --git\"));\n\tconst headerLines = diffStart === -1 ? lines : lines.slice(0, diffStart);\n\tconst diffLines = diffStart === -1 ? [] : lines.slice(diffStart);\n\tconst summaryLines = headerLines.filter((line) => {\n\t\tconst trimmed = line.trim();\n\t\tif (!trimmed) return false;\n\t\tif (line.startsWith(\"Author:\") || line.startsWith(\"Date:\") || line.startsWith(\"Merge:\")) return false;\n\t\treturn true;\n\t});\n\tconst shortSummary = summaryLines\n\t\t.slice(0, 4)\n\t\t.map((line) => unicodeTruncate(line.replace(/^commit ([0-9a-f]{7})[0-9a-f]+/, \"commit $1\"), 160));\n\tconst { compacted, truncated } = compactDiff(diffLines.join(\"\\n\"));\n\tlet output = shortSummary.join(\"\\n\");\n\tif (compacted.trim()) output += `\\n\\n${compacted}`;\n\tif (truncated) output += \"\\n\\n[Diff truncated.]\";\n\treturn resultFromQuery(showRes, output.trim(), 0);\n}\n\nasync function handlePassthroughGit(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, args, options);\n\treturn resultFromQuery(res, rawText(res, true).trim(), res.status ?? 0);\n}\n\nasync function handleAdd(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tif (args.length === 0) return handlePassthroughGit(cwd, globalOptions, [\"add\"], options);\n\tconst addRes = await runGitQuery(cwd, globalOptions, [\"add\", ...args], options);\n\tconst rawOut = rawText(addRes);\n\tif (addRes.status !== 0) return { output: rawOut, exitCode: addRes.status ?? 1, rawOut, rawBytes: addRes.rawBytes };\n\tconst statRes = await runGitQuery(cwd, globalOptions, [\"diff\", \"--cached\", \"--stat\"], options);\n\tif (statRes.status === 0 && statRes.stdout.trim().length > 0) {\n\t\treturn { output: `Staged changes:\\n${statRes.stdout.trim()}`, exitCode: 0, rawOut, rawBytes: addRes.rawBytes };\n\t}\n\treturn { output: rawOut.trim() || \"Successfully staged.\", exitCode: 0, rawOut, rawBytes: addRes.rawBytes };\n}\n\nasync function handleCommit(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst hasMsg = args.some(\n\t\t(arg) => arg === \"-m\" || arg === \"-F\" || arg.startsWith(\"--message\") || arg.startsWith(\"--file\"),\n\t);\n\tif (!hasMsg) return { output: \"\", exitCode: -100, rawOut: \"\" };\n\tconst res = await runGitQuery(cwd, globalOptions, [\"commit\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (rawOut.includes(\"nothing to commit\") || rawOut.includes(\"working tree clean\")) {\n\t\treturn { output: \"nothing to commit, working tree clean\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst firstLine = rawOut\n\t\t.split(\"\\n\")\n\t\t.find((line) => line.trim().length > 0)\n\t\t?.trim();\n\treturn { output: firstLine || \"Committed successfully.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handlePush(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"push\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tconst outputLines = rawOut\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trimEnd())\n\t\t.filter((line) => {\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (!trimmed) return false;\n\t\t\treturn ![\"Writing objects:\", \"Counting objects:\", \"Delta compression\", \"Compressing objects:\", \"Total \"].some(\n\t\t\t\t(prefix) => trimmed.startsWith(prefix),\n\t\t\t);\n\t\t});\n\tif (res.status !== 0)\n\t\treturn { output: outputLines.join(\"\\n\"), exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (outputLines.some((line) => line.includes(\"Everything up-to-date\"))) {\n\t\treturn { output: \"Everything up-to-date.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst remoteMessages = outputLines.filter((line) => line.trim().startsWith(\"remote:\"));\n\tconst pushDetail = outputLines.find((line) => line.includes(\"->\"));\n\tconst summary = pushDetail ? `Pushed: ${pushDetail.trim()}` : \"Push successful.\";\n\treturn { output: [...remoteMessages, summary].join(\"\\n\"), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handlePull(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"pull\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (rawOut.includes(\"Already up to date.\"))\n\t\treturn { output: \"Already up to date.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst lines = rawOut.split(\"\\n\");\n\tconst summary = lines.filter(\n\t\t(line) => line.includes(\"Fast-forward\") || line.includes(\"file changed\") || line.includes(\"files changed\"),\n\t);\n\treturn { output: summary.join(\"\\n\") || \"Pull successful.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleFetch(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst res = await runGitQuery(cwd, globalOptions, [\"fetch\", ...args], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tconst refs = rawOut\n\t\t.split(\"\\n\")\n\t\t.filter((line) => line.includes(\"[new branch]\") || line.includes(\"[new tag]\") || line.includes(\"->\"));\n\treturn {\n\t\toutput: refs.length\n\t\t\t? `Fetched:\\n${refs.map((line) => line.trim()).join(\"\\n\")}`\n\t\t\t: \"Fetch successful (no new refs).\",\n\t\texitCode: 0,\n\t\trawOut,\n\t\trawBytes: res.rawBytes,\n\t};\n}\n\nasync function handleBranch(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tif (args.includes(\"--show-current\")) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", \"--show-current\"], options);\n\t\treturn { output: res.stdout.trim(), exitCode: res.status ?? 0, rawOut: rawText(res), rawBytes: res.rawBytes };\n\t}\n\tconst isWrite = args.some(\n\t\t(arg) =>\n\t\t\targ === \"-d\" || arg === \"-D\" || arg === \"-m\" || arg === \"-M\" || (!arg.startsWith(\"-\") && args.length === 1),\n\t);\n\tif (isWrite) {\n\t\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", ...args], options);\n\t\tconst rawOut = rawText(res);\n\t\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\t\treturn { output: rawOut.trim() || \"Branch updated successfully.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\t}\n\tconst res = await runGitQuery(cwd, globalOptions, [\"branch\", \"--no-color\", ...args], options);\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tconst lines = res.stdout.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tconst remoteBranches = lines.filter((line) => line.includes(\"remotes/\"));\n\tconst localBranches = lines.filter((line) => !line.includes(\"remotes/\"));\n\tconst remoteDisplay = remoteBranches.slice(0, 5);\n\tconst omitted = remoteBranches.length - remoteDisplay.length;\n\tif (omitted > 0) remoteDisplay.push(` remotes/... (${omitted} more remote branches)`);\n\treturn { output: [...localBranches, ...remoteDisplay].join(\"\\n\"), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleStash(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst sub = args[0] || \"push\";\n\tconst res = await runGitQuery(cwd, globalOptions, [\"stash\", ...args], options);\n\tconst rawOut = rawText(res);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (sub === \"list\")\n\t\treturn { output: res.stdout.trim() || \"No stashes found.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tif (sub === \"show\") {\n\t\tconst { compacted, truncated } = compactDiff(res.stdout);\n\t\treturn applyOverflowDisclosure(res, {\n\t\t\toutput: `${compacted.trim()}${truncated ? \"\\n\\n[Diff truncated.]\" : \"\"}`,\n\t\t\texitCode: 0,\n\t\t\trawOut,\n\t\t\trawBytes: res.rawBytes,\n\t\t});\n\t}\n\tif (res.stdout.includes(\"No local changes to save\"))\n\t\treturn { output: \"No local changes to save.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst firstLine = res.stdout\n\t\t.split(\"\\n\")\n\t\t.find((line) => line.trim().length > 0)\n\t\t?.trim();\n\treturn { output: firstLine || \"Stash successful.\", exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nasync function handleWorktree(\n\tcwd: string,\n\tglobalOptions: string[],\n\targs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tconst sub = args[0] || \"list\";\n\tconst res = await runGitQuery(cwd, globalOptions, [\"worktree\", ...(sub === \"list\" ? [\"list\"] : args)], options);\n\tconst rawOut = rawText(res, true);\n\tif (res.status !== 0) return { output: rawOut, exitCode: res.status ?? 1, rawOut, rawBytes: res.rawBytes };\n\tif (sub !== \"list\") return { output: rawOut.trim(), exitCode: 0, rawOut, rawBytes: res.rawBytes };\n\tconst home = process.env.HOME || \"\";\n\tconst output = res.stdout\n\t\t.split(\"\\n\")\n\t\t.map((line) => (home && line.startsWith(home) ? `~${line.slice(home.length)}` : line))\n\t\t.join(\"\\n\")\n\t\t.trim();\n\treturn { output, exitCode: 0, rawOut, rawBytes: res.rawBytes };\n}\n\nexport async function executeFilteredGit(\n\tcwd: string,\n\tsubcommand: string,\n\tglobalOptions: string[],\n\tsubcommandArgs: string[],\n\toptions?: GitFilterOptions,\n): Promise<FilterResult> {\n\tswitch (subcommand) {\n\t\tcase \"status\":\n\t\t\treturn handleStatus(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"log\":\n\t\t\treturn handleLog(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"diff\":\n\t\t\treturn handleDiff(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"show\":\n\t\t\treturn handleShow(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"add\":\n\t\t\treturn handleAdd(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"commit\":\n\t\t\treturn handleCommit(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"push\":\n\t\t\treturn handlePush(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"pull\":\n\t\t\treturn handlePull(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"branch\":\n\t\t\treturn handleBranch(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"fetch\":\n\t\t\treturn handleFetch(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"stash\":\n\t\t\treturn handleStash(cwd, globalOptions, subcommandArgs, options);\n\t\tcase \"worktree\":\n\t\t\treturn handleWorktree(cwd, globalOptions, subcommandArgs, options);\n\t\tdefault:\n\t\t\treturn { output: \"\", exitCode: -100, rawOut: \"\" };\n\t}\n}\n\nexport function makeGitCommandForDisplay(globalOptions: string[], subcommand: string, args: string[]): string {\n\treturn gitCommand(globalOptions, [subcommand, ...args]);\n}\n"]}
|
|
@@ -7,6 +7,8 @@ import { waitForChildProcessWithTermination } from "../../utils/child-process.js
|
|
|
7
7
|
import { createSafeWriteStream } from "../../utils/safe-write-stream.js";
|
|
8
8
|
import { trackDetachedChildPid, untrackDetachedChildPid } from "../../utils/shell.js";
|
|
9
9
|
import { getProcessWorkRun } from "../../utils/work-directory.js";
|
|
10
|
+
import { isComplexShellCommand, parseCommandPrefixes } from "./shell-command-parser.js";
|
|
11
|
+
export { isComplexShellCommand, parseCommandPrefixes, tokenizeCommand } from "./shell-command-parser.js";
|
|
10
12
|
/**
|
|
11
13
|
* Retention budget for git output held in memory while filtering. Output beyond
|
|
12
14
|
* the budget is spilled to a temp file so a giant `git log -p`/`git diff` cannot
|
|
@@ -45,69 +47,6 @@ export function unicodeTruncate(str, maxLength) {
|
|
|
45
47
|
return str;
|
|
46
48
|
return `${chars.slice(0, maxLength).join("")}...`;
|
|
47
49
|
}
|
|
48
|
-
export function tokenizeCommand(command) {
|
|
49
|
-
const args = [];
|
|
50
|
-
let current = "";
|
|
51
|
-
let inDoubleQuotes = false;
|
|
52
|
-
let inSingleQuotes = false;
|
|
53
|
-
let escapeNext = false;
|
|
54
|
-
for (let i = 0; i < command.length; i++) {
|
|
55
|
-
const char = command[i];
|
|
56
|
-
if (escapeNext) {
|
|
57
|
-
current += char;
|
|
58
|
-
escapeNext = false;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (char === "\\" && !inSingleQuotes) {
|
|
62
|
-
escapeNext = true;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (char === '"' && !inSingleQuotes) {
|
|
66
|
-
inDoubleQuotes = !inDoubleQuotes;
|
|
67
|
-
}
|
|
68
|
-
else if (char === "'" && !inDoubleQuotes) {
|
|
69
|
-
inSingleQuotes = !inSingleQuotes;
|
|
70
|
-
}
|
|
71
|
-
else if (/\s/.test(char) && !inDoubleQuotes && !inSingleQuotes) {
|
|
72
|
-
if (current) {
|
|
73
|
-
args.push(current);
|
|
74
|
-
current = "";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
current += char;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (inDoubleQuotes || inSingleQuotes || escapeNext)
|
|
82
|
-
return null;
|
|
83
|
-
if (current)
|
|
84
|
-
args.push(current);
|
|
85
|
-
return args;
|
|
86
|
-
}
|
|
87
|
-
export function parseCommandPrefixes(command) {
|
|
88
|
-
const tokens = tokenizeCommand(command);
|
|
89
|
-
if (!tokens || tokens.length === 0)
|
|
90
|
-
return null;
|
|
91
|
-
const envVars = {};
|
|
92
|
-
let i = 0;
|
|
93
|
-
const envPattern = /^([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$/;
|
|
94
|
-
while (i < tokens.length) {
|
|
95
|
-
const token = tokens[i];
|
|
96
|
-
const match = token.match(envPattern);
|
|
97
|
-
if (!match)
|
|
98
|
-
break;
|
|
99
|
-
let value = match[2];
|
|
100
|
-
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
101
|
-
value = value.slice(1, -1);
|
|
102
|
-
}
|
|
103
|
-
envVars[match[1]] = value;
|
|
104
|
-
i++;
|
|
105
|
-
}
|
|
106
|
-
return { envVars, coreCommandTokens: tokens.slice(i) };
|
|
107
|
-
}
|
|
108
|
-
export function isComplexShellCommand(command) {
|
|
109
|
-
return /[|><&;\n\r$`()*?[\]#]/.test(command);
|
|
110
|
-
}
|
|
111
50
|
function quoteForShell(arg) {
|
|
112
51
|
if (/^[A-Za-z0-9_./:=+-]+$/.test(arg))
|
|
113
52
|
return arg;
|