@kenkaiiii/gg-engine 0.0.0-stage → 7.1.0
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/LICENSE +661 -0
- package/NOTICE +43 -0
- package/README.md +53 -2
- package/assets/skills/bulletproof/SKILL.md +132 -0
- package/assets/skills/bulletproof/references/agent-surface.md +113 -0
- package/assets/skills/bulletproof/references/attack-classes.md +226 -0
- package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
- package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
- package/assets/skills/bulletproof/references/provenance.md +146 -0
- package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
- package/assets/skills/bulletproof/references/supply-chain.md +84 -0
- package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
- package/assets/skills/bulletproof/references/verification.md +74 -0
- package/assets/skills/compliance-guard/SKILL.md +115 -0
- package/assets/skills/compliance-guard/references/artifacts.md +199 -0
- package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
- package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
- package/assets/skills/compliance-guard/references/provenance.md +135 -0
- package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
- package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
- package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
- package/assets/skills/compliance-guard/references/us.md +194 -0
- package/assets/skills/durable/SKILL.md +114 -0
- package/assets/skills/durable/references/agent-db-safety.md +76 -0
- package/assets/skills/durable/references/backups-and-runtime.md +93 -0
- package/assets/skills/durable/references/migrations-and-schema.md +87 -0
- package/assets/skills/gg-guide/SKILL.md +43 -0
- package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
- package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
- package/assets/skills/gg-guide/references/code-mode.md +272 -0
- package/assets/skills/gg-guide/references/getting-started.md +295 -0
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
- package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
- package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
- package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
- package/assets/skills/gg-guide/references/settings.md +193 -0
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
- package/assets/skills/lean/SKILL.md +117 -0
- package/assets/skills/lean/references/memory-and-processes.md +99 -0
- package/assets/skills/lean/references/playbooks.md +134 -0
- package/dist/app-error.d.ts +22 -0
- package/dist/app-error.js +41 -0
- package/dist/app-error.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/core/acceptance-checks.d.ts +48 -0
- package/dist/core/acceptance-checks.js +151 -0
- package/dist/core/acceptance-checks.js.map +1 -0
- package/dist/core/action-threats.d.ts +68 -0
- package/dist/core/action-threats.js +894 -0
- package/dist/core/action-threats.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +79 -0
- package/dist/core/agent-notifications.js +125 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +87 -0
- package/dist/core/agent-session/mcp-tools.js +227 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +71 -0
- package/dist/core/agent-session/verification-tracker.js +295 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +1401 -0
- package/dist/core/agent-session.js +5160 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/agents.d.ts +63 -0
- package/dist/core/agents.js +160 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/ask-user.d.ts +163 -0
- package/dist/core/ask-user.js +178 -0
- package/dist/core/ask-user.js.map +1 -0
- package/dist/core/auto-update.d.ts +32 -0
- package/dist/core/auto-update.js +218 -0
- package/dist/core/auto-update.js.map +1 -0
- package/dist/core/autopilot-cycle.d.ts +127 -0
- package/dist/core/autopilot-cycle.js +182 -0
- package/dist/core/autopilot-cycle.js.map +1 -0
- package/dist/core/autopilot-gate.d.ts +106 -0
- package/dist/core/autopilot-gate.js +192 -0
- package/dist/core/autopilot-gate.js.map +1 -0
- package/dist/core/autopilot-verdict.d.ts +55 -0
- package/dist/core/autopilot-verdict.js +226 -0
- package/dist/core/autopilot-verdict.js.map +1 -0
- package/dist/core/blocked-packages-file.d.ts +33 -0
- package/dist/core/blocked-packages-file.js +274 -0
- package/dist/core/blocked-packages-file.js.map +1 -0
- package/dist/core/bundled-agents.d.ts +2 -0
- package/dist/core/bundled-agents.js +253 -0
- package/dist/core/bundled-agents.js.map +1 -0
- package/dist/core/cache-diagnostics.d.ts +72 -0
- package/dist/core/cache-diagnostics.js +200 -0
- package/dist/core/cache-diagnostics.js.map +1 -0
- package/dist/core/cache-expiry.d.ts +89 -0
- package/dist/core/cache-expiry.js +117 -0
- package/dist/core/cache-expiry.js.map +1 -0
- package/dist/core/checklist-detection.d.ts +8 -0
- package/dist/core/checklist-detection.js +238 -0
- package/dist/core/checklist-detection.js.map +1 -0
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +182 -0
- package/dist/core/checklist-items.js +228 -0
- package/dist/core/checklist-items.js.map +1 -0
- package/dist/core/checklist-prompt.d.ts +14 -0
- package/dist/core/checklist-prompt.js +64 -0
- package/dist/core/checklist-prompt.js.map +1 -0
- package/dist/core/checklist-snapshot.d.ts +7 -0
- package/dist/core/checklist-snapshot.js +46 -0
- package/dist/core/checklist-snapshot.js.map +1 -0
- package/dist/core/checklist-store.d.ts +45 -0
- package/dist/core/checklist-store.js +281 -0
- package/dist/core/checklist-store.js.map +1 -0
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +109 -0
- package/dist/core/checkpoint-store.js +260 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/claude-code/complete.d.ts +35 -0
- package/dist/core/claude-code/complete.js +125 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +67 -0
- package/dist/core/claude-code/events.js +460 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +94 -0
- package/dist/core/claude-code/live-session.js +525 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code/transcripts.d.ts +39 -0
- package/dist/core/claude-code/transcripts.js +195 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/code-retrieval-chunkers.d.ts +26 -0
- package/dist/core/code-retrieval-chunkers.js +264 -0
- package/dist/core/code-retrieval-chunkers.js.map +1 -0
- package/dist/core/code-retrieval.d.ts +18 -0
- package/dist/core/code-retrieval.js +124 -0
- package/dist/core/code-retrieval.js.map +1 -0
- package/dist/core/codex-request-shape.d.ts +7 -0
- package/dist/core/codex-request-shape.js +19 -0
- package/dist/core/codex-request-shape.js.map +1 -0
- package/dist/core/compaction/active-context.d.ts +16 -0
- package/dist/core/compaction/active-context.js +20 -0
- package/dist/core/compaction/active-context.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +281 -0
- package/dist/core/compaction/compactor.js +1451 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/plan-step-policy.d.ts +46 -0
- package/dist/core/compaction/plan-step-policy.js +57 -0
- package/dist/core/compaction/plan-step-policy.js.map +1 -0
- package/dist/core/compaction/policy.d.ts +36 -0
- package/dist/core/compaction/policy.js +144 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +32 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/token-estimator.d.ts +36 -0
- package/dist/core/compaction/token-estimator.js +180 -0
- package/dist/core/compaction/token-estimator.js.map +1 -0
- package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
- package/dist/core/compaction/tool-result-pruner.js +238 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -0
- package/dist/core/completion-review.d.ts +24 -0
- package/dist/core/completion-review.js +2 -0
- package/dist/core/completion-review.js.map +1 -0
- package/dist/core/context-files.d.ts +8 -0
- package/dist/core/context-files.js +46 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/context-limits.d.ts +40 -0
- package/dist/core/context-limits.js +43 -0
- package/dist/core/context-limits.js.map +1 -0
- package/dist/core/custom-commands.d.ts +18 -0
- package/dist/core/custom-commands.js +57 -0
- package/dist/core/custom-commands.js.map +1 -0
- package/dist/core/destructive-git-guard.d.ts +113 -0
- package/dist/core/destructive-git-guard.js +874 -0
- package/dist/core/destructive-git-guard.js.map +1 -0
- package/dist/core/display-items.d.ts +8 -0
- package/dist/core/display-items.js +2 -0
- package/dist/core/display-items.js.map +1 -0
- package/dist/core/encode-cwd.d.ts +41 -0
- package/dist/core/encode-cwd.js +53 -0
- package/dist/core/encode-cwd.js.map +1 -0
- package/dist/core/env-delta.d.ts +34 -0
- package/dist/core/env-delta.js +84 -0
- package/dist/core/env-delta.js.map +1 -0
- package/dist/core/event-bus.d.ts +178 -0
- package/dist/core/event-bus.js +171 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.js +68 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.d.ts +13 -0
- package/dist/core/extensions/plugin-bundles.js +45 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.js +2 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +119 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +50 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/frontmatter.d.ts +22 -0
- package/dist/core/frontmatter.js +90 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/goal-run-marker.d.ts +32 -0
- package/dist/core/goal-run-marker.js +178 -0
- package/dist/core/goal-run-marker.js.map +1 -0
- package/dist/core/goal-summary.d.ts +15 -0
- package/dist/core/goal-summary.js +110 -0
- package/dist/core/goal-summary.js.map +1 -0
- package/dist/core/goals-store.d.ts +208 -0
- package/dist/core/goals-store.js +577 -0
- package/dist/core/goals-store.js.map +1 -0
- package/dist/core/hashline.d.ts +51 -0
- package/dist/core/hashline.js +76 -0
- package/dist/core/hashline.js.map +1 -0
- package/dist/core/idle-wake.d.ts +62 -0
- package/dist/core/idle-wake.js +103 -0
- package/dist/core/idle-wake.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/injection-detect.d.ts +39 -0
- package/dist/core/injection-detect.js +241 -0
- package/dist/core/injection-detect.js.map +1 -0
- package/dist/core/installed-threats.d.ts +23 -0
- package/dist/core/installed-threats.js +71 -0
- package/dist/core/installed-threats.js.map +1 -0
- package/dist/core/internal-diagnostics.d.ts +159 -0
- package/dist/core/internal-diagnostics.js +495 -0
- package/dist/core/internal-diagnostics.js.map +1 -0
- package/dist/core/keep-awake.d.ts +88 -0
- package/dist/core/keep-awake.js +251 -0
- package/dist/core/keep-awake.js.map +1 -0
- package/dist/core/ken-ask-answer.d.ts +24 -0
- package/dist/core/ken-ask-answer.js +96 -0
- package/dist/core/ken-ask-answer.js.map +1 -0
- package/dist/core/ken-context.d.ts +119 -0
- package/dist/core/ken-context.js +447 -0
- package/dist/core/ken-context.js.map +1 -0
- package/dist/core/ken-model.d.ts +45 -0
- package/dist/core/ken-model.js +26 -0
- package/dist/core/ken-model.js.map +1 -0
- package/dist/core/ken-prompt.d.ts +21 -0
- package/dist/core/ken-prompt.js +370 -0
- package/dist/core/ken-prompt.js.map +1 -0
- package/dist/core/language-detector.d.ts +41 -0
- package/dist/core/language-detector.js +293 -0
- package/dist/core/language-detector.js.map +1 -0
- package/dist/core/live-preview.d.ts +26 -0
- package/dist/core/live-preview.js +80 -0
- package/dist/core/live-preview.js.map +1 -0
- package/dist/core/local-endpoint-store.d.ts +53 -0
- package/dist/core/local-endpoint-store.js +221 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +94 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loop-breaker.d.ts +89 -0
- package/dist/core/loop-breaker.js +204 -0
- package/dist/core/loop-breaker.js.map +1 -0
- package/dist/core/lsp/client.d.ts +206 -0
- package/dist/core/lsp/client.js +685 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/edit-telemetry.d.ts +26 -0
- package/dist/core/lsp/edit-telemetry.js +52 -0
- package/dist/core/lsp/edit-telemetry.js.map +1 -0
- package/dist/core/lsp/format.d.ts +11 -0
- package/dist/core/lsp/format.js +30 -0
- package/dist/core/lsp/format.js.map +1 -0
- package/dist/core/lsp/jsonrpc.d.ts +68 -0
- package/dist/core/lsp/jsonrpc.js +153 -0
- package/dist/core/lsp/jsonrpc.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +188 -0
- package/dist/core/lsp/manager.js +576 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +114 -0
- package/dist/core/lsp/pool.js +259 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/project-root.d.ts +9 -0
- package/dist/core/lsp/project-root.js +75 -0
- package/dist/core/lsp/project-root.js.map +1 -0
- package/dist/core/lsp/reference-project.d.ts +6 -0
- package/dist/core/lsp/reference-project.js +110 -0
- package/dist/core/lsp/reference-project.js.map +1 -0
- package/dist/core/lsp/servers.d.ts +44 -0
- package/dist/core/lsp/servers.js +289 -0
- package/dist/core/lsp/servers.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +17 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +64 -0
- package/dist/core/mcp/catalog-cache.js +166 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/client.d.ts +317 -0
- package/dist/core/mcp/client.js +1168 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/content.d.ts +23 -0
- package/dist/core/mcp/content.js +194 -0
- package/dist/core/mcp/content.js.map +1 -0
- package/dist/core/mcp/defaults.d.ts +26 -0
- package/dist/core/mcp/defaults.js +81 -0
- package/dist/core/mcp/defaults.js.map +1 -0
- package/dist/core/mcp/deferred-catalog.d.ts +53 -0
- package/dist/core/mcp/deferred-catalog.js +117 -0
- package/dist/core/mcp/deferred-catalog.js.map +1 -0
- package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
- package/dist/core/mcp/elicitation-bridge.js +36 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/index.d.ts +16 -0
- package/dist/core/mcp/index.js +10 -0
- package/dist/core/mcp/index.js.map +1 -0
- package/dist/core/mcp/loopback.d.ts +26 -0
- package/dist/core/mcp/loopback.js +66 -0
- package/dist/core/mcp/loopback.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +55 -0
- package/dist/core/mcp/oauth-provider.js +106 -0
- package/dist/core/mcp/oauth-provider.js.map +1 -0
- package/dist/core/mcp/oauth-store.d.ts +44 -0
- package/dist/core/mcp/oauth-store.js +76 -0
- package/dist/core/mcp/oauth-store.js.map +1 -0
- package/dist/core/mcp/parse-add-command.d.ts +50 -0
- package/dist/core/mcp/parse-add-command.js +391 -0
- package/dist/core/mcp/parse-add-command.js.map +1 -0
- package/dist/core/mcp/resolve-stdio.d.ts +77 -0
- package/dist/core/mcp/resolve-stdio.js +359 -0
- package/dist/core/mcp/resolve-stdio.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +157 -0
- package/dist/core/mcp/shared-pool.js +236 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/store.d.ts +100 -0
- package/dist/core/mcp/store.js +202 -0
- package/dist/core/mcp/store.js.map +1 -0
- package/dist/core/mcp/tool-guard.d.ts +58 -0
- package/dist/core/mcp/tool-guard.js +215 -0
- package/dist/core/mcp/tool-guard.js.map +1 -0
- package/dist/core/mcp/types.d.ts +57 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/message-images.d.ts +11 -0
- package/dist/core/message-images.js +52 -0
- package/dist/core/message-images.js.map +1 -0
- package/dist/core/model-unavailable.d.ts +14 -0
- package/dist/core/model-unavailable.js +23 -0
- package/dist/core/model-unavailable.js.map +1 -0
- package/dist/core/network-guard.d.ts +28 -0
- package/dist/core/network-guard.js +251 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/node-debugger.d.ts +148 -0
- package/dist/core/node-debugger.js +642 -0
- package/dist/core/node-debugger.js.map +1 -0
- package/dist/core/opencode-catalog-store.d.ts +20 -0
- package/dist/core/opencode-catalog-store.js +82 -0
- package/dist/core/opencode-catalog-store.js.map +1 -0
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/package-cooldown.d.ts +69 -0
- package/dist/core/package-cooldown.js +297 -0
- package/dist/core/package-cooldown.js.map +1 -0
- package/dist/core/package-threats.d.ts +92 -0
- package/dist/core/package-threats.js +1339 -0
- package/dist/core/package-threats.js.map +1 -0
- package/dist/core/parked-requests.d.ts +43 -0
- package/dist/core/parked-requests.js +34 -0
- package/dist/core/parked-requests.js.map +1 -0
- package/dist/core/persistent-shell.d.ts +81 -0
- package/dist/core/persistent-shell.js +452 -0
- package/dist/core/persistent-shell.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/plan-handoff.d.ts +38 -0
- package/dist/core/plan-handoff.js +21 -0
- package/dist/core/plan-handoff.js.map +1 -0
- package/dist/core/plan-submission-gate.d.ts +28 -0
- package/dist/core/plan-submission-gate.js +27 -0
- package/dist/core/plan-submission-gate.js.map +1 -0
- package/dist/core/platform-clis.d.ts +15 -0
- package/dist/core/platform-clis.js +299 -0
- package/dist/core/platform-clis.js.map +1 -0
- package/dist/core/process-gate.d.ts +61 -0
- package/dist/core/process-gate.js +103 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-manager.d.ts +242 -0
- package/dist/core/process-manager.js +902 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/progress/engine.d.ts +22 -0
- package/dist/core/progress/engine.js +131 -0
- package/dist/core/progress/engine.js.map +1 -0
- package/dist/core/progress/git-xp.d.ts +15 -0
- package/dist/core/progress/git-xp.js +100 -0
- package/dist/core/progress/git-xp.js.map +1 -0
- package/dist/core/progress/ranks.d.ts +31 -0
- package/dist/core/progress/ranks.js +310 -0
- package/dist/core/progress/ranks.js.map +1 -0
- package/dist/core/progress/rebuild.d.ts +8 -0
- package/dist/core/progress/rebuild.js +125 -0
- package/dist/core/progress/rebuild.js.map +1 -0
- package/dist/core/progress/store.d.ts +34 -0
- package/dist/core/progress/store.js +200 -0
- package/dist/core/progress/store.js.map +1 -0
- package/dist/core/progress/types.d.ts +56 -0
- package/dist/core/progress/types.js +2 -0
- package/dist/core/progress/types.js.map +1 -0
- package/dist/core/project-discovery.d.ts +64 -0
- package/dist/core/project-discovery.js +908 -0
- package/dist/core/project-discovery.js.map +1 -0
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/project-health-scan.d.ts +109 -0
- package/dist/core/project-health-scan.js +673 -0
- package/dist/core/project-health-scan.js.map +1 -0
- package/dist/core/project-health-score.d.ts +41 -0
- package/dist/core/project-health-score.js +257 -0
- package/dist/core/project-health-score.js.map +1 -0
- package/dist/core/prompt-command-expansion.d.ts +13 -0
- package/dist/core/prompt-command-expansion.js +48 -0
- package/dist/core/prompt-command-expansion.js.map +1 -0
- package/dist/core/prompt-commands.d.ts +13 -0
- package/dist/core/prompt-commands.js +370 -0
- package/dist/core/prompt-commands.js.map +1 -0
- package/dist/core/pull-requests.d.ts +18 -0
- package/dist/core/pull-requests.js +95 -0
- package/dist/core/pull-requests.js.map +1 -0
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +132 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.d.ts +42 -0
- package/dist/core/radio.js +499 -0
- package/dist/core/radio.js.map +1 -0
- package/dist/core/regrounding.d.ts +37 -0
- package/dist/core/regrounding.js +89 -0
- package/dist/core/regrounding.js.map +1 -0
- package/dist/core/resolve-start.d.ts +28 -0
- package/dist/core/resolve-start.js +35 -0
- package/dist/core/resolve-start.js.map +1 -0
- package/dist/core/run-claim.d.ts +36 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +58 -0
- package/dist/core/run-lifecycle.js +104 -0
- package/dist/core/run-lifecycle.js.map +1 -0
- package/dist/core/run-status.d.ts +17 -0
- package/dist/core/run-status.js +28 -0
- package/dist/core/run-status.js.map +1 -0
- package/dist/core/runtime-mode.d.ts +21 -0
- package/dist/core/runtime-mode.js +43 -0
- package/dist/core/runtime-mode.js.map +1 -0
- package/dist/core/sandbox-domains.d.ts +13 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +21 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox.d.ts +106 -0
- package/dist/core/sandbox.js +383 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/semantic-loop-check.d.ts +58 -0
- package/dist/core/semantic-loop-check.js +103 -0
- package/dist/core/semantic-loop-check.js.map +1 -0
- package/dist/core/session-compaction.d.ts +23 -0
- package/dist/core/session-compaction.js +54 -0
- package/dist/core/session-compaction.js.map +1 -0
- package/dist/core/session-export.d.ts +97 -0
- package/dist/core/session-export.js +368 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-history.d.ts +160 -0
- package/dist/core/session-history.js +467 -0
- package/dist/core/session-history.js.map +1 -0
- package/dist/core/session-manager.d.ts +512 -0
- package/dist/core/session-manager.js +1370 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-preview.d.ts +12 -0
- package/dist/core/session-preview.js +58 -0
- package/dist/core/session-preview.js.map +1 -0
- package/dist/core/session-storage.d.ts +78 -0
- package/dist/core/session-storage.js +659 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-summary-index.d.ts +51 -0
- package/dist/core/session-summary-index.js +192 -0
- package/dist/core/session-summary-index.js.map +1 -0
- package/dist/core/settings-manager.d.ts +113 -0
- package/dist/core/settings-manager.js +281 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/core/shell-path.d.ts +13 -0
- package/dist/core/shell-path.js +175 -0
- package/dist/core/shell-path.js.map +1 -0
- package/dist/core/shell-threats-popular-packages.d.ts +11 -0
- package/dist/core/shell-threats-popular-packages.js +675 -0
- package/dist/core/shell-threats-popular-packages.js.map +1 -0
- package/dist/core/shell-threats.d.ts +21 -0
- package/dist/core/shell-threats.js +235 -0
- package/dist/core/shell-threats.js.map +1 -0
- package/dist/core/shell.d.ts +54 -0
- package/dist/core/shell.js +99 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/core/shutdown.d.ts +70 -0
- package/dist/core/shutdown.js +144 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/skill-scan.d.ts +112 -0
- package/dist/core/skill-scan.js +781 -0
- package/dist/core/skill-scan.js.map +1 -0
- package/dist/core/skills.d.ts +80 -0
- package/dist/core/skills.js +270 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +58 -0
- package/dist/core/slash-commands.js +242 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/steering.d.ts +47 -0
- package/dist/core/steering.js +65 -0
- package/dist/core/steering.js.map +1 -0
- package/dist/core/steroids.d.ts +66 -0
- package/dist/core/steroids.js +243 -0
- package/dist/core/steroids.js.map +1 -0
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/stream-rules.d.ts +30 -0
- package/dist/core/stream-rules.js +151 -0
- package/dist/core/stream-rules.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +242 -0
- package/dist/core/subagent-manager.js +1075 -0
- package/dist/core/subagent-manager.js.map +1 -0
- package/dist/core/subagent-policy.d.ts +9 -0
- package/dist/core/subagent-policy.js +41 -0
- package/dist/core/subagent-policy.js.map +1 -0
- package/dist/core/subagent-receipt.d.ts +54 -0
- package/dist/core/subagent-receipt.js +274 -0
- package/dist/core/subagent-receipt.js.map +1 -0
- package/dist/core/subagent-store.d.ts +41 -0
- package/dist/core/subagent-store.js +284 -0
- package/dist/core/subagent-store.js.map +1 -0
- package/dist/core/subagent-turn-record.d.ts +18 -0
- package/dist/core/subagent-turn-record.js +82 -0
- package/dist/core/subagent-turn-record.js.map +1 -0
- package/dist/core/tasks-store.d.ts +31 -0
- package/dist/core/tasks-store.js +97 -0
- package/dist/core/tasks-store.js.map +1 -0
- package/dist/core/telegram-config.d.ts +20 -0
- package/dist/core/telegram-config.js +52 -0
- package/dist/core/telegram-config.js.map +1 -0
- package/dist/core/telegram.d.ts +114 -0
- package/dist/core/telegram.js +275 -0
- package/dist/core/telegram.js.map +1 -0
- package/dist/core/temp-paths.d.ts +5 -0
- package/dist/core/temp-paths.js +50 -0
- package/dist/core/temp-paths.js.map +1 -0
- package/dist/core/test-impact.d.ts +73 -0
- package/dist/core/test-impact.js +467 -0
- package/dist/core/test-impact.js.map +1 -0
- package/dist/core/threat-feed.d.ts +65 -0
- package/dist/core/threat-feed.js +334 -0
- package/dist/core/threat-feed.js.map +1 -0
- package/dist/core/trophies/catalog-more.d.ts +2 -0
- package/dist/core/trophies/catalog-more.js +837 -0
- package/dist/core/trophies/catalog-more.js.map +1 -0
- package/dist/core/trophies/catalog.d.ts +4 -0
- package/dist/core/trophies/catalog.js +649 -0
- package/dist/core/trophies/catalog.js.map +1 -0
- package/dist/core/trophies/engine.d.ts +70 -0
- package/dist/core/trophies/engine.js +347 -0
- package/dist/core/trophies/engine.js.map +1 -0
- package/dist/core/trophies/store.d.ts +17 -0
- package/dist/core/trophies/store.js +113 -0
- package/dist/core/trophies/store.js.map +1 -0
- package/dist/core/trophies/types.d.ts +87 -0
- package/dist/core/trophies/types.js +74 -0
- package/dist/core/trophies/types.js.map +1 -0
- package/dist/core/ui-adoption.d.ts +32 -0
- package/dist/core/ui-adoption.js +302 -0
- package/dist/core/ui-adoption.js.map +1 -0
- package/dist/core/ui-compatibility.d.ts +10 -0
- package/dist/core/ui-compatibility.js +51 -0
- package/dist/core/ui-compatibility.js.map +1 -0
- package/dist/core/ui-registry.d.ts +101 -0
- package/dist/core/ui-registry.js +292 -0
- package/dist/core/ui-registry.js.map +1 -0
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verification-evidence.d.ts +49 -0
- package/dist/core/verification-evidence.js +816 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-gate.d.ts +77 -0
- package/dist/core/verification-gate.js +504 -0
- package/dist/core/verification-gate.js.map +1 -0
- package/dist/core/verification-snapshot.d.ts +7 -0
- package/dist/core/verification-snapshot.js +109 -0
- package/dist/core/verification-snapshot.js.map +1 -0
- package/dist/core/verify-commands.d.ts +34 -0
- package/dist/core/verify-commands.js +203 -0
- package/dist/core/verify-commands.js.map +1 -0
- package/dist/core/voice-transcriber.d.ts +32 -0
- package/dist/core/voice-transcriber.js +114 -0
- package/dist/core/voice-transcriber.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +56 -0
- package/dist/core/workspace-guard.js +334 -0
- package/dist/core/workspace-guard.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +104 -0
- package/dist/system-prompt.js +480 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-support/fake-home.d.ts +19 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/test-support/keep-alive.d.ts +14 -0
- package/dist/test-support/keep-alive.js +17 -0
- package/dist/test-support/keep-alive.js.map +1 -0
- package/dist/test-support/slow-git.d.ts +1 -0
- package/dist/test-support/slow-git.js +21 -0
- package/dist/test-support/slow-git.js.map +1 -0
- package/dist/test-support/system-tools.d.ts +6 -0
- package/dist/test-support/system-tools.js +36 -0
- package/dist/test-support/system-tools.js.map +1 -0
- package/dist/tools/ask-user.d.ts +34 -0
- package/dist/tools/ask-user.js +99 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/background-watch-lint.d.ts +18 -0
- package/dist/tools/background-watch-lint.js +102 -0
- package/dist/tools/background-watch-lint.js.map +1 -0
- package/dist/tools/bash-read-evidence.d.ts +23 -0
- package/dist/tools/bash-read-evidence.js +180 -0
- package/dist/tools/bash-read-evidence.js.map +1 -0
- package/dist/tools/bash.d.ts +64 -0
- package/dist/tools/bash.js +552 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser-api.d.ts +27 -0
- package/dist/tools/browser-api.js +449 -0
- package/dist/tools/browser-api.js.map +1 -0
- package/dist/tools/browser-sandbox.d.ts +16 -0
- package/dist/tools/browser-sandbox.js +158 -0
- package/dist/tools/browser-sandbox.js.map +1 -0
- package/dist/tools/browser-session.d.ts +84 -0
- package/dist/tools/browser-session.js +304 -0
- package/dist/tools/browser-session.js.map +1 -0
- package/dist/tools/browser-snapshot.d.ts +19 -0
- package/dist/tools/browser-snapshot.js +109 -0
- package/dist/tools/browser-snapshot.js.map +1 -0
- package/dist/tools/browser.d.ts +11 -0
- package/dist/tools/browser.js +106 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/checklist.d.ts +49 -0
- package/dist/tools/checklist.js +154 -0
- package/dist/tools/checklist.js.map +1 -0
- package/dist/tools/compress.d.ts +56 -0
- package/dist/tools/compress.js +226 -0
- package/dist/tools/compress.js.map +1 -0
- package/dist/tools/debug.d.ts +54 -0
- package/dist/tools/debug.js +230 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +123 -0
- package/dist/tools/edit-diff.js +476 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit-targets.d.ts +10 -0
- package/dist/tools/edit-targets.js +31 -0
- package/dist/tools/edit-targets.js.map +1 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +695 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/enter-plan.d.ts +7 -0
- package/dist/tools/enter-plan.js +20 -0
- package/dist/tools/enter-plan.js.map +1 -0
- package/dist/tools/exit-plan.d.ts +7 -0
- package/dist/tools/exit-plan.js +51 -0
- package/dist/tools/exit-plan.js.map +1 -0
- package/dist/tools/find.d.ts +17 -0
- package/dist/tools/find.js +100 -0
- package/dist/tools/find.js.map +1 -0
- package/dist/tools/generate-image.d.ts +83 -0
- package/dist/tools/generate-image.js +625 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/grep-scan.d.ts +96 -0
- package/dist/tools/grep-scan.js +283 -0
- package/dist/tools/grep-scan.js.map +1 -0
- package/dist/tools/grep.d.ts +48 -0
- package/dist/tools/grep.js +1013 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/html-extract.d.ts +57 -0
- package/dist/tools/html-extract.js +130 -0
- package/dist/tools/html-extract.js.map +1 -0
- package/dist/tools/index.d.ts +198 -0
- package/dist/tools/index.js +216 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/live-preview.d.ts +23 -0
- package/dist/tools/live-preview.js +41 -0
- package/dist/tools/live-preview.js.map +1 -0
- package/dist/tools/ls.d.ts +9 -0
- package/dist/tools/ls.js +59 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/operations.d.ts +86 -0
- package/dist/tools/operations.js +117 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/overflow.d.ts +17 -0
- package/dist/tools/overflow.js +68 -0
- package/dist/tools/overflow.js.map +1 -0
- package/dist/tools/path-utils.d.ts +30 -0
- package/dist/tools/path-utils.js +74 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/pdf-extract.d.ts +17 -0
- package/dist/tools/pdf-extract.js +43 -0
- package/dist/tools/pdf-extract.js.map +1 -0
- package/dist/tools/prompt-hints.d.ts +46 -0
- package/dist/tools/prompt-hints.js +171 -0
- package/dist/tools/prompt-hints.js.map +1 -0
- package/dist/tools/read-only-bash.d.ts +31 -0
- package/dist/tools/read-only-bash.js +338 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-tracker.d.ts +43 -0
- package/dist/tools/read-tracker.js +120 -0
- package/dist/tools/read-tracker.js.map +1 -0
- package/dist/tools/read.d.ts +18 -0
- package/dist/tools/read.js +316 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/redaction-guard.d.ts +10 -0
- package/dist/tools/redaction-guard.js +55 -0
- package/dist/tools/redaction-guard.js.map +1 -0
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/safe-env.d.ts +1 -0
- package/dist/tools/safe-env.js +79 -0
- package/dist/tools/safe-env.js.map +1 -0
- package/dist/tools/session-stats.d.ts +26 -0
- package/dist/tools/session-stats.js +51 -0
- package/dist/tools/session-stats.js.map +1 -0
- package/dist/tools/side-web-search.d.ts +34 -0
- package/dist/tools/side-web-search.js +146 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +12 -0
- package/dist/tools/skill.js +94 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/source-path.d.ts +8 -0
- package/dist/tools/source-path.js +135 -0
- package/dist/tools/source-path.js.map +1 -0
- package/dist/tools/steroids.d.ts +44 -0
- package/dist/tools/steroids.js +356 -0
- package/dist/tools/steroids.js.map +1 -0
- package/dist/tools/subagent-control.d.ts +5 -0
- package/dist/tools/subagent-control.js +211 -0
- package/dist/tools/subagent-control.js.map +1 -0
- package/dist/tools/subagent-shared.d.ts +115 -0
- package/dist/tools/subagent-shared.js +182 -0
- package/dist/tools/subagent-shared.js.map +1 -0
- package/dist/tools/subagent.d.ts +39 -0
- package/dist/tools/subagent.js +412 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/task-output.d.ts +10 -0
- package/dist/tools/task-output.js +74 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/task-send.d.ts +11 -0
- package/dist/tools/task-send.js +36 -0
- package/dist/tools/task-send.js.map +1 -0
- package/dist/tools/task-stop.d.ts +8 -0
- package/dist/tools/task-stop.js +15 -0
- package/dist/tools/task-stop.js.map +1 -0
- package/dist/tools/tasks.d.ts +15 -0
- package/dist/tools/tasks.js +94 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/tool-search.d.ts +26 -0
- package/dist/tools/tool-search.js +81 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/tool-tiers.d.ts +65 -0
- package/dist/tools/tool-tiers.js +121 -0
- package/dist/tools/tool-tiers.js.map +1 -0
- package/dist/tools/truncate.d.ts +39 -0
- package/dist/tools/truncate.js +242 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/ui-adopt.d.ts +16 -0
- package/dist/tools/ui-adopt.js +66 -0
- package/dist/tools/ui-adopt.js.map +1 -0
- package/dist/tools/ui-registry.d.ts +15 -0
- package/dist/tools/ui-registry.js +39 -0
- package/dist/tools/ui-registry.js.map +1 -0
- package/dist/tools/verification-review.d.ts +2 -0
- package/dist/tools/verification-review.js +41 -0
- package/dist/tools/verification-review.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +52 -0
- package/dist/tools/web-fetch.js +986 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.js +926 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +16 -0
- package/dist/tools/write.js +196 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/commit-message.d.ts +25 -0
- package/dist/utils/commit-message.js +72 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/git.d.ts +102 -0
- package/dist/utils/git.js +325 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github-ci.d.ts +9 -0
- package/dist/utils/github-ci.js +138 -0
- package/dist/utils/github-ci.js.map +1 -0
- package/dist/utils/github.d.ts +19 -0
- package/dist/utils/github.js +67 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/image.d.ts +166 -0
- package/dist/utils/image.js +673 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/open-browser.d.ts +13 -0
- package/dist/utils/open-browser.js +31 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/plan-steps.d.ts +90 -0
- package/dist/utils/plan-steps.js +209 -0
- package/dist/utils/plan-steps.js.map +1 -0
- package/dist/utils/process.d.ts +48 -0
- package/dist/utils/process.js +175 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/prompt-enhancer.d.ts +34 -0
- package/dist/utils/prompt-enhancer.js +178 -0
- package/dist/utils/prompt-enhancer.js.map +1 -0
- package/dist/utils/text.d.ts +61 -0
- package/dist/utils/text.js +68 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +87 -3
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { BackgroundGitError, runBackgroundGit } from "../utils/git.js";
|
|
5
|
+
import { log } from "@kenkaiiii/gg-core";
|
|
6
|
+
const MAX_DEPTH = 6;
|
|
7
|
+
const GIT_TIMEOUT_MS = 3_000;
|
|
8
|
+
const MAX_LISTED_FILES = 5;
|
|
9
|
+
// ── Shell scanning ─────────────────────────────────────────
|
|
10
|
+
/**
|
|
11
|
+
* Split shell source into simple commands (arrays of unquoted words).
|
|
12
|
+
* Not a full shell parser: it errs toward surfacing commands (heredoc bodies
|
|
13
|
+
* fed to a shell, substitutions inside double quotes), because a false
|
|
14
|
+
* positive costs only a `git status` call.
|
|
15
|
+
*/
|
|
16
|
+
function scanShell(src, depth, out) {
|
|
17
|
+
let words = [];
|
|
18
|
+
let word = "";
|
|
19
|
+
let inWord = false;
|
|
20
|
+
let skipNextWord = false;
|
|
21
|
+
let heredocPending = false;
|
|
22
|
+
const heredocs = [];
|
|
23
|
+
let heredocStripTabs = false;
|
|
24
|
+
const nested = (inner) => {
|
|
25
|
+
if (depth < MAX_DEPTH)
|
|
26
|
+
scanShell(inner, depth + 1, out);
|
|
27
|
+
};
|
|
28
|
+
const endWord = () => {
|
|
29
|
+
if (inWord) {
|
|
30
|
+
if (skipNextWord) {
|
|
31
|
+
skipNextWord = false;
|
|
32
|
+
if (heredocPending) {
|
|
33
|
+
heredocs.push({ delimiter: word, stripTabs: heredocStripTabs });
|
|
34
|
+
heredocPending = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
words.push(word);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
word = "";
|
|
42
|
+
inWord = false;
|
|
43
|
+
};
|
|
44
|
+
const endCommand = () => {
|
|
45
|
+
endWord();
|
|
46
|
+
if (words.length > 0)
|
|
47
|
+
out.push(words);
|
|
48
|
+
words = [];
|
|
49
|
+
skipNextWord = false;
|
|
50
|
+
heredocPending = false;
|
|
51
|
+
};
|
|
52
|
+
let i = 0;
|
|
53
|
+
while (i < src.length) {
|
|
54
|
+
const ch = src.charAt(i);
|
|
55
|
+
const next = src.charAt(i + 1);
|
|
56
|
+
if (ch === "\\") {
|
|
57
|
+
if (next !== "\n") {
|
|
58
|
+
word += next;
|
|
59
|
+
inWord = true;
|
|
60
|
+
}
|
|
61
|
+
i += 2;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === "'") {
|
|
65
|
+
const close = src.indexOf("'", i + 1);
|
|
66
|
+
const end = close === -1 ? src.length : close;
|
|
67
|
+
word += src.slice(i + 1, end);
|
|
68
|
+
inWord = true;
|
|
69
|
+
i = end + 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (ch === '"') {
|
|
73
|
+
i = scanDoubleQuoted(src, i + 1, (text) => (word += text), nested);
|
|
74
|
+
inWord = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === "`") {
|
|
78
|
+
const close = findBacktickClose(src, i + 1);
|
|
79
|
+
nested(src.slice(i + 1, close));
|
|
80
|
+
inWord = true;
|
|
81
|
+
i = close + 1;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (ch === "$" && next === "(") {
|
|
85
|
+
const close = findParenClose(src, i + 2);
|
|
86
|
+
nested(src.slice(i + 2, close));
|
|
87
|
+
inWord = true;
|
|
88
|
+
i = close + 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (ch === "$" && next === "'") {
|
|
92
|
+
i += 1; // ANSI-C quoting: treat the body as a plain single-quoted string
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if ((ch === "<" || ch === ">") && next === "(") {
|
|
96
|
+
endWord();
|
|
97
|
+
const close = findParenClose(src, i + 2);
|
|
98
|
+
nested(src.slice(i + 2, close));
|
|
99
|
+
i = close + 1;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (ch === " " || ch === "\t") {
|
|
103
|
+
endWord();
|
|
104
|
+
i += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (ch === "\n") {
|
|
108
|
+
const commandWords = [...words, ...(inWord && !skipNextWord ? [word] : [])];
|
|
109
|
+
endCommand();
|
|
110
|
+
i += 1;
|
|
111
|
+
// Heredoc bodies start on the next line. Scan them only when they feed
|
|
112
|
+
// a shell (`bash <<EOF`); for `cat <<EOF > notes.md` they are data.
|
|
113
|
+
while (heredocs.length > 0) {
|
|
114
|
+
const doc = heredocs.shift();
|
|
115
|
+
if (!doc)
|
|
116
|
+
break;
|
|
117
|
+
const { body, resume } = readHeredoc(src, i, doc.delimiter, doc.stripTabs);
|
|
118
|
+
if (commandWords.some((w) => SHELLS.has(commandName(w))))
|
|
119
|
+
nested(body);
|
|
120
|
+
i = resume;
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (ch === "#" && !inWord) {
|
|
125
|
+
const nl = src.indexOf("\n", i);
|
|
126
|
+
i = nl === -1 ? src.length : nl;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (ch === ";" || ch === "(" || ch === ")") {
|
|
130
|
+
endCommand();
|
|
131
|
+
i += 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (ch === "|") {
|
|
135
|
+
endCommand();
|
|
136
|
+
i += next === "|" || next === "&" ? 2 : 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (ch === "&") {
|
|
140
|
+
if (next === ">") {
|
|
141
|
+
endWord();
|
|
142
|
+
i += src.charAt(i + 2) === ">" ? 3 : 2;
|
|
143
|
+
skipNextWord = true;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
endCommand();
|
|
147
|
+
i += next === "&" ? 2 : 1;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (ch === "<" || ch === ">") {
|
|
151
|
+
// A bare fd number glued to the operator (`2>`) is not a word.
|
|
152
|
+
if (inWord && /^\d+$/.test(word)) {
|
|
153
|
+
word = "";
|
|
154
|
+
inWord = false;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
endWord();
|
|
158
|
+
}
|
|
159
|
+
const op = /^(?:<<<|<<-|<<|<>|>>|>\||>&|<&|>|<)/.exec(src.slice(i))?.[0] ?? ch;
|
|
160
|
+
if (op === "<<" || op === "<<-") {
|
|
161
|
+
heredocPending = true;
|
|
162
|
+
heredocStripTabs = op === "<<-";
|
|
163
|
+
}
|
|
164
|
+
skipNextWord = true;
|
|
165
|
+
i += op.length;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
word += ch;
|
|
169
|
+
inWord = true;
|
|
170
|
+
i += 1;
|
|
171
|
+
}
|
|
172
|
+
endCommand();
|
|
173
|
+
}
|
|
174
|
+
/** Consume a double-quoted string starting after the opening quote; returns
|
|
175
|
+
* the index after the closing quote. Substitutions inside are scanned. */
|
|
176
|
+
function scanDoubleQuoted(src, start, append, nested) {
|
|
177
|
+
let i = start;
|
|
178
|
+
while (i < src.length) {
|
|
179
|
+
const ch = src.charAt(i);
|
|
180
|
+
const next = src.charAt(i + 1);
|
|
181
|
+
if (ch === '"')
|
|
182
|
+
return i + 1;
|
|
183
|
+
if (ch === "\\" && '$`"\\\n'.includes(next) && next !== "") {
|
|
184
|
+
if (next !== "\n")
|
|
185
|
+
append(next);
|
|
186
|
+
i += 2;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (ch === "$" && next === "(") {
|
|
190
|
+
const close = findParenClose(src, i + 2);
|
|
191
|
+
nested(src.slice(i + 2, close));
|
|
192
|
+
append(src.slice(i, close + 1));
|
|
193
|
+
i = close + 1;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (ch === "`") {
|
|
197
|
+
const close = findBacktickClose(src, i + 1);
|
|
198
|
+
nested(src.slice(i + 1, close));
|
|
199
|
+
i = close + 1;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
append(ch);
|
|
203
|
+
i += 1;
|
|
204
|
+
}
|
|
205
|
+
return src.length;
|
|
206
|
+
}
|
|
207
|
+
/** Index of the `)` closing a `$(`/`(` whose body starts at `start`. */
|
|
208
|
+
function findParenClose(src, start) {
|
|
209
|
+
let depth = 1;
|
|
210
|
+
let i = start;
|
|
211
|
+
while (i < src.length) {
|
|
212
|
+
const ch = src.charAt(i);
|
|
213
|
+
if (ch === "\\") {
|
|
214
|
+
i += 2;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (ch === "'") {
|
|
218
|
+
const close = src.indexOf("'", i + 1);
|
|
219
|
+
i = close === -1 ? src.length : close + 1;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (ch === '"') {
|
|
223
|
+
i = scanDoubleQuoted(src, i + 1, () => { }, () => { });
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (ch === "(")
|
|
227
|
+
depth += 1;
|
|
228
|
+
if (ch === ")") {
|
|
229
|
+
depth -= 1;
|
|
230
|
+
if (depth === 0)
|
|
231
|
+
return i;
|
|
232
|
+
}
|
|
233
|
+
i += 1;
|
|
234
|
+
}
|
|
235
|
+
return src.length;
|
|
236
|
+
}
|
|
237
|
+
function findBacktickClose(src, start) {
|
|
238
|
+
let i = start;
|
|
239
|
+
while (i < src.length) {
|
|
240
|
+
const ch = src.charAt(i);
|
|
241
|
+
if (ch === "\\") {
|
|
242
|
+
i += 2;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (ch === "`")
|
|
246
|
+
return i;
|
|
247
|
+
i += 1;
|
|
248
|
+
}
|
|
249
|
+
return src.length;
|
|
250
|
+
}
|
|
251
|
+
function readHeredoc(src, start, delimiter, stripTabs) {
|
|
252
|
+
const lines = [];
|
|
253
|
+
let i = start;
|
|
254
|
+
while (i < src.length) {
|
|
255
|
+
const nl = src.indexOf("\n", i);
|
|
256
|
+
const end = nl === -1 ? src.length : nl;
|
|
257
|
+
const line = src.slice(i, end);
|
|
258
|
+
i = end + 1;
|
|
259
|
+
if ((stripTabs ? line.replace(/^\t+/, "") : line) === delimiter)
|
|
260
|
+
break;
|
|
261
|
+
lines.push(line);
|
|
262
|
+
}
|
|
263
|
+
return { body: lines.join("\n"), resume: Math.min(i, src.length) };
|
|
264
|
+
}
|
|
265
|
+
// ── Command unwrapping ─────────────────────────────────────
|
|
266
|
+
const SHELLS = new Set(["bash", "sh", "zsh", "ksh", "dash", "ash", "fish"]);
|
|
267
|
+
/** Commands that run their operands as a command (possibly after options). */
|
|
268
|
+
const EXEC_WRAPPERS = new Set([
|
|
269
|
+
"sudo",
|
|
270
|
+
"doas",
|
|
271
|
+
"env",
|
|
272
|
+
"nohup",
|
|
273
|
+
"timeout",
|
|
274
|
+
"gtimeout",
|
|
275
|
+
"nice",
|
|
276
|
+
"ionice",
|
|
277
|
+
"exec",
|
|
278
|
+
"command",
|
|
279
|
+
"builtin",
|
|
280
|
+
"time",
|
|
281
|
+
"stdbuf",
|
|
282
|
+
"setsid",
|
|
283
|
+
"xargs",
|
|
284
|
+
"chronic",
|
|
285
|
+
"caffeinate",
|
|
286
|
+
"unbuffer",
|
|
287
|
+
"flock",
|
|
288
|
+
"watch",
|
|
289
|
+
]);
|
|
290
|
+
/** Words that do not run their operands; stop looking for a wrapped child. */
|
|
291
|
+
const NON_EXEC_COMMANDS = new Set([
|
|
292
|
+
"echo",
|
|
293
|
+
"printf",
|
|
294
|
+
"cat",
|
|
295
|
+
"grep",
|
|
296
|
+
"egrep",
|
|
297
|
+
"fgrep",
|
|
298
|
+
"rg",
|
|
299
|
+
"sed",
|
|
300
|
+
"awk",
|
|
301
|
+
"head",
|
|
302
|
+
"tail",
|
|
303
|
+
"less",
|
|
304
|
+
"more",
|
|
305
|
+
"man",
|
|
306
|
+
"which",
|
|
307
|
+
"type",
|
|
308
|
+
"tee",
|
|
309
|
+
"wc",
|
|
310
|
+
]);
|
|
311
|
+
const SHELL_KEYWORDS = new Set([
|
|
312
|
+
"if",
|
|
313
|
+
"then",
|
|
314
|
+
"else",
|
|
315
|
+
"elif",
|
|
316
|
+
"fi",
|
|
317
|
+
"do",
|
|
318
|
+
"done",
|
|
319
|
+
"while",
|
|
320
|
+
"until",
|
|
321
|
+
"case",
|
|
322
|
+
"esac",
|
|
323
|
+
"!",
|
|
324
|
+
"{",
|
|
325
|
+
"}",
|
|
326
|
+
"function",
|
|
327
|
+
]);
|
|
328
|
+
/** Basename of a command word, `.exe` stripped (`/usr/bin/git`, `git.exe`). */
|
|
329
|
+
export function commandName(word) {
|
|
330
|
+
return (word.split(/[\\/]/).pop() ?? word).replace(/\.exe$/i, "");
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Expand the home and working-directory forms a model writes in paths:
|
|
334
|
+
* `~`, `$HOME`/`${HOME}` (any case, which also covers PowerShell `$home`),
|
|
335
|
+
* `$env:USERPROFILE`/`$env:HOME`, cmd `%USERPROFILE%`, and `$PWD`/`${PWD}`. Other variables stay
|
|
336
|
+
* literal, so they resolve to a harmless relative path.
|
|
337
|
+
*/
|
|
338
|
+
export function expandShellPath(p, cwd) {
|
|
339
|
+
return p
|
|
340
|
+
.replace(/^(?:~|\$\{?home\}?|\$env:(?:userprofile|home)|%userprofile%)(?=[\\/]|$)/i, os.homedir())
|
|
341
|
+
.replace(/^\$\{?PWD\}?(?=[\\/]|$)/, cwd);
|
|
342
|
+
}
|
|
343
|
+
function isPowerShell(name) {
|
|
344
|
+
const lower = name.toLowerCase();
|
|
345
|
+
return lower === "powershell" || lower === "pwsh";
|
|
346
|
+
}
|
|
347
|
+
function walkScript(script, ctx) {
|
|
348
|
+
const commands = [];
|
|
349
|
+
scanShell(script, ctx.depth, commands);
|
|
350
|
+
// `cd` persists for later commands in the same script (approximation: a
|
|
351
|
+
// subshell's cd leaks too, which only ever widens what gets checked).
|
|
352
|
+
const local = { ...ctx };
|
|
353
|
+
for (const words of commands)
|
|
354
|
+
walkWords(words, local);
|
|
355
|
+
}
|
|
356
|
+
function walkWords(input, ctx) {
|
|
357
|
+
let words = input;
|
|
358
|
+
while (words.length > 0 &&
|
|
359
|
+
(SHELL_KEYWORDS.has(words[0] ?? "") || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[0] ?? ""))) {
|
|
360
|
+
words = words.slice(1);
|
|
361
|
+
}
|
|
362
|
+
const head = words[0];
|
|
363
|
+
if (head === undefined)
|
|
364
|
+
return;
|
|
365
|
+
const name = commandName(head);
|
|
366
|
+
const args = words.slice(1);
|
|
367
|
+
if (name === "cd" || name === "pushd") {
|
|
368
|
+
const target = args.find((a) => !a.startsWith("-"));
|
|
369
|
+
// `cd -` goes somewhere we cannot know; keep the current guess.
|
|
370
|
+
if (target === undefined && !args.includes("-"))
|
|
371
|
+
ctx.cwd = os.homedir();
|
|
372
|
+
else if (target !== undefined)
|
|
373
|
+
ctx.cwd = path.resolve(ctx.cwd, expandShellPath(target, ctx.cwd));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (ctx.wanted(name)) {
|
|
377
|
+
ctx.out.push({ name, args, cwd: ctx.cwd, viaXargs: ctx.viaXargs });
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (ctx.depth >= MAX_DEPTH)
|
|
381
|
+
return;
|
|
382
|
+
const deeper = { ...ctx, depth: ctx.depth + 1 };
|
|
383
|
+
if (SHELLS.has(name)) {
|
|
384
|
+
// `bash -c 'script'`, also clustered (`-lc`, `-ec`).
|
|
385
|
+
const flagIndex = args.findIndex((a) => /^-[A-Za-z]*c[A-Za-z]*$/.test(a));
|
|
386
|
+
const script = flagIndex === -1 ? undefined : args[flagIndex + 1];
|
|
387
|
+
if (script !== undefined)
|
|
388
|
+
walkScript(script, deeper);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (isPowerShell(name)) {
|
|
392
|
+
// `pwsh -c '…'` / `powershell -Command "…"` (any unambiguous prefix).
|
|
393
|
+
const flagIndex = args.findIndex((a) => /^-c(?:o(?:m(?:m(?:a(?:n(?:d)?)?)?)?)?)?$/i.test(a));
|
|
394
|
+
const script = flagIndex === -1 ? undefined : args.slice(flagIndex + 1).join(" ");
|
|
395
|
+
if (script)
|
|
396
|
+
walkScript(script, deeper);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (name === "eval") {
|
|
400
|
+
walkScript(args.join(" "), deeper);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (EXEC_WRAPPERS.has(name)) {
|
|
404
|
+
// Wrapper options vary (`timeout 5`, `sudo -u bob`, `env X=1`, `nice -n 5`);
|
|
405
|
+
// rather than model each, take the first word that is itself something we
|
|
406
|
+
// analyse, stopping at a command that merely displays its operands.
|
|
407
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
408
|
+
const candidate = commandName(args[index] ?? "");
|
|
409
|
+
if (ctx.wanted(candidate) ||
|
|
410
|
+
candidate === "cd" ||
|
|
411
|
+
candidate === "eval" ||
|
|
412
|
+
SHELLS.has(candidate) ||
|
|
413
|
+
isPowerShell(candidate) ||
|
|
414
|
+
EXEC_WRAPPERS.has(candidate)) {
|
|
415
|
+
walkWords(args.slice(index), { ...deeper, viaXargs: ctx.viaXargs || name === "xargs" });
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (NON_EXEC_COMMANDS.has(candidate))
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Every simple command in `command` whose name satisfies `wanted`, in source
|
|
425
|
+
* order, after splitting on `&&`/`;`/`||`/pipes, entering subshells,
|
|
426
|
+
* substitutions and `if`/`for`/`while` bodies, unwrapping `bash -c`/`eval`/
|
|
427
|
+
* `pwsh -c` scripts and exec wrappers (`sudo`, `env`, `timeout`, `xargs`, …),
|
|
428
|
+
* and following `cd`. Pure: nothing is executed.
|
|
429
|
+
*/
|
|
430
|
+
export function walkShell(command, cwd, wanted) {
|
|
431
|
+
const out = [];
|
|
432
|
+
walkScript(command, { cwd, depth: 0, viaXargs: false, wanted, out });
|
|
433
|
+
return out;
|
|
434
|
+
}
|
|
435
|
+
// ── git classification ─────────────────────────────────────
|
|
436
|
+
/** True for a short-option cluster (`-fdx`) containing `letter`. */
|
|
437
|
+
export function hasShort(tokens, letter) {
|
|
438
|
+
return tokens.some((t) => /^-[A-Za-z]+$/.test(t) && t.slice(1).includes(letter));
|
|
439
|
+
}
|
|
440
|
+
/** Exact long option, or an unambiguous abbreviation of at least `minLength`. */
|
|
441
|
+
export function hasLong(tokens, option, minLength = option.length) {
|
|
442
|
+
return tokens.some((t) => {
|
|
443
|
+
const name = t.split("=", 1)[0] ?? t;
|
|
444
|
+
return name.startsWith("--") && name.length >= minLength && option.startsWith(name);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
export function splitAtDoubleDash(tokens) {
|
|
448
|
+
const index = tokens.indexOf("--");
|
|
449
|
+
return index === -1
|
|
450
|
+
? { before: [...tokens], after: null }
|
|
451
|
+
: { before: tokens.slice(0, index), after: tokens.slice(index + 1) };
|
|
452
|
+
}
|
|
453
|
+
/** Non-option operands, skipping the values of options in `withValue`. */
|
|
454
|
+
export function operands(tokens, withValue) {
|
|
455
|
+
const result = [];
|
|
456
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
457
|
+
const token = tokens[i] ?? "";
|
|
458
|
+
if (token.startsWith("-")) {
|
|
459
|
+
if (withValue.has(token))
|
|
460
|
+
i += 1;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
result.push(token);
|
|
464
|
+
}
|
|
465
|
+
return result;
|
|
466
|
+
}
|
|
467
|
+
export function isPathspecShaped(operand) {
|
|
468
|
+
return (operand === "." ||
|
|
469
|
+
operand === ".." ||
|
|
470
|
+
/^\.\.?[\\/]/.test(operand) ||
|
|
471
|
+
/^(?:[\\/]|[A-Za-z]:[\\/])/.test(operand) ||
|
|
472
|
+
operand.endsWith("/") ||
|
|
473
|
+
operand.startsWith(":") ||
|
|
474
|
+
/[*?[]/.test(operand));
|
|
475
|
+
}
|
|
476
|
+
const CHECKOUT_VALUE_OPTS = new Set(["--conflict", "-U", "--unified"]);
|
|
477
|
+
const RESTORE_VALUE_OPTS = new Set([
|
|
478
|
+
"-s",
|
|
479
|
+
"--source",
|
|
480
|
+
"--conflict",
|
|
481
|
+
"-U",
|
|
482
|
+
"--unified",
|
|
483
|
+
"--inter-hunk-context",
|
|
484
|
+
]);
|
|
485
|
+
const CLEAN_VALUE_OPTS = new Set(["-e", "--exclude"]);
|
|
486
|
+
const BRANCH_VALUE_OPTS = new Set([
|
|
487
|
+
"-t",
|
|
488
|
+
"--track",
|
|
489
|
+
"-u",
|
|
490
|
+
"--set-upstream-to",
|
|
491
|
+
]);
|
|
492
|
+
const PUSH_VALUE_OPTS = new Set([
|
|
493
|
+
"-o",
|
|
494
|
+
"--push-option",
|
|
495
|
+
"--repo",
|
|
496
|
+
"--receive-pack",
|
|
497
|
+
"--exec",
|
|
498
|
+
]);
|
|
499
|
+
/** Parse git's global options (`-C`, `--git-dir`, `-c k=v`, …) off the front of `args`. */
|
|
500
|
+
export function parseGitInvocation(args, cwd) {
|
|
501
|
+
let dir = cwd;
|
|
502
|
+
const gitArgs = [];
|
|
503
|
+
let i = 0;
|
|
504
|
+
while (i < args.length) {
|
|
505
|
+
const arg = args[i] ?? "";
|
|
506
|
+
if (arg === "-C") {
|
|
507
|
+
dir = path.resolve(dir, expandShellPath(args[i + 1] ?? ".", dir));
|
|
508
|
+
i += 2;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (arg === "--git-dir" || arg === "--work-tree") {
|
|
512
|
+
gitArgs.push(`${arg}=${path.resolve(dir, expandShellPath(args[i + 1] ?? ".", dir))}`);
|
|
513
|
+
i += 2;
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const assigned = /^(--git-dir|--work-tree)=(.*)$/.exec(arg);
|
|
517
|
+
if (assigned) {
|
|
518
|
+
gitArgs.push(`${assigned[1]}=${path.resolve(dir, expandShellPath(assigned[2] ?? ".", dir))}`);
|
|
519
|
+
i += 1;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (arg === "-c" ||
|
|
523
|
+
arg === "--namespace" ||
|
|
524
|
+
arg === "--config-env" ||
|
|
525
|
+
arg === "--super-prefix") {
|
|
526
|
+
i += 2;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (arg.startsWith("-")) {
|
|
530
|
+
i += 1;
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
return { dir, gitArgs, subcommand: args[i], rest: args.slice(i + 1) };
|
|
536
|
+
}
|
|
537
|
+
function analyzeGit(args, cwd) {
|
|
538
|
+
const { dir, gitArgs, subcommand, rest } = parseGitInvocation(args, cwd);
|
|
539
|
+
if (subcommand === undefined)
|
|
540
|
+
return null;
|
|
541
|
+
const base = {
|
|
542
|
+
display: truncate(["git", subcommand, ...rest].join(" ")),
|
|
543
|
+
dir,
|
|
544
|
+
gitArgs,
|
|
545
|
+
pathspecs: [],
|
|
546
|
+
refs: [],
|
|
547
|
+
};
|
|
548
|
+
switch (subcommand) {
|
|
549
|
+
case "reset":
|
|
550
|
+
// Git rejects paths with --hard, so it is always the whole tree.
|
|
551
|
+
return hasLong(rest, "--hard", 4) ? { ...base, kind: "reset-hard" } : null;
|
|
552
|
+
case "checkout": {
|
|
553
|
+
const { before, after } = splitAtDoubleDash(rest);
|
|
554
|
+
if (before.some((t) => t === "-b" || t === "-B" || t === "--orphan"))
|
|
555
|
+
return null;
|
|
556
|
+
if (hasLong(before, "--force") || hasShort(before, "f")) {
|
|
557
|
+
return { ...base, kind: "checkout-paths", pathspecs: after ?? [] };
|
|
558
|
+
}
|
|
559
|
+
if (hasLong(before, "--pathspec-from-file", 12))
|
|
560
|
+
return { ...base, kind: "checkout-paths" };
|
|
561
|
+
if (after !== null) {
|
|
562
|
+
return after.length > 0 ? { ...base, kind: "checkout-paths", pathspecs: after } : null;
|
|
563
|
+
}
|
|
564
|
+
const positional = operands(before, CHECKOUT_VALUE_OPTS);
|
|
565
|
+
if (positional.length >= 2) {
|
|
566
|
+
return { ...base, kind: "checkout-paths", pathspecs: positional.slice(1) };
|
|
567
|
+
}
|
|
568
|
+
const operand = positional[0];
|
|
569
|
+
if (operand === undefined || hasShort(before, "d") || hasLong(before, "--detach", 5)) {
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
if (isPathspecShaped(operand)) {
|
|
573
|
+
return { ...base, kind: "checkout-paths", pathspecs: [operand] };
|
|
574
|
+
}
|
|
575
|
+
if (existsSync(path.resolve(dir, operand))) {
|
|
576
|
+
return { ...base, kind: "checkout-paths", pathspecs: [operand], maybeRef: operand };
|
|
577
|
+
}
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
case "restore": {
|
|
581
|
+
const { before, after } = splitAtDoubleDash(rest);
|
|
582
|
+
if (before.some((t) => t === "-h" || t === "--help"))
|
|
583
|
+
return null;
|
|
584
|
+
const staged = before.includes("--staged") || hasShort(before, "S");
|
|
585
|
+
const worktree = before.includes("--worktree") || hasShort(before, "W");
|
|
586
|
+
if (staged && !worktree)
|
|
587
|
+
return null;
|
|
588
|
+
const pathspecs = [...operands(before, RESTORE_VALUE_OPTS), ...(after ?? [])];
|
|
589
|
+
const fromFile = hasLong(before, "--pathspec-from-file", 12);
|
|
590
|
+
if (pathspecs.length === 0 && !fromFile)
|
|
591
|
+
return null;
|
|
592
|
+
return { ...base, kind: "restore-worktree", pathspecs: fromFile ? [] : pathspecs };
|
|
593
|
+
}
|
|
594
|
+
case "clean": {
|
|
595
|
+
const { before, after } = splitAtDoubleDash(rest);
|
|
596
|
+
if (hasShort(before, "n") || hasLong(before, "--dry-run", 5))
|
|
597
|
+
return null;
|
|
598
|
+
if (!hasShort(before, "f") && !hasLong(before, "--force"))
|
|
599
|
+
return null;
|
|
600
|
+
const ignored = hasShort(before, "x") ? "also" : hasShort(before, "X") ? "only" : undefined;
|
|
601
|
+
return {
|
|
602
|
+
...base,
|
|
603
|
+
kind: "clean",
|
|
604
|
+
pathspecs: [...operands(before, CLEAN_VALUE_OPTS), ...(after ?? [])],
|
|
605
|
+
ignored,
|
|
606
|
+
directories: hasShort(before, "d"),
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
case "stash": {
|
|
610
|
+
const [action, target] = operands(rest, new Set());
|
|
611
|
+
if (action === "drop")
|
|
612
|
+
return { ...base, kind: "stash-drop", refs: [target ?? "stash@{0}"] };
|
|
613
|
+
if (action === "clear")
|
|
614
|
+
return { ...base, kind: "stash-clear" };
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
case "branch": {
|
|
618
|
+
if (hasShort(rest, "r") || hasLong(rest, "--remotes", 5))
|
|
619
|
+
return null;
|
|
620
|
+
const forceDelete = hasShort(rest, "D") ||
|
|
621
|
+
((hasShort(rest, "d") || hasLong(rest, "--delete", 5)) &&
|
|
622
|
+
(hasShort(rest, "f") || hasLong(rest, "--force")));
|
|
623
|
+
if (!forceDelete)
|
|
624
|
+
return null;
|
|
625
|
+
const refs = operands(rest, BRANCH_VALUE_OPTS);
|
|
626
|
+
return refs.length > 0 ? { ...base, kind: "branch-force-delete", refs } : null;
|
|
627
|
+
}
|
|
628
|
+
case "push": {
|
|
629
|
+
// --force-with-lease / --force-if-includes are the safe forms: exact
|
|
630
|
+
// `--force` and `-f` only. A `+refspec` is a per-ref force.
|
|
631
|
+
const forced = rest.includes("--force") ||
|
|
632
|
+
hasShort(rest, "f") ||
|
|
633
|
+
operands(rest, PUSH_VALUE_OPTS).some((ref) => ref.startsWith("+"));
|
|
634
|
+
return forced ? { ...base, kind: "force-push" } : null;
|
|
635
|
+
}
|
|
636
|
+
default:
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function truncate(text, max = 120) {
|
|
641
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Parse `command` and return every git invocation in it that can destroy
|
|
645
|
+
* work, with the directory each would run in. Pure apart from `existsSync`
|
|
646
|
+
* for ambiguous `git checkout <name>`.
|
|
647
|
+
*/
|
|
648
|
+
export function findDestructiveGitCommands(command, cwd) {
|
|
649
|
+
const out = [];
|
|
650
|
+
for (const call of walkShell(command, cwd, (name) => name === "git")) {
|
|
651
|
+
// xargs appends operands read from stdin; stand in "." (whole tree)
|
|
652
|
+
// so `… | xargs git checkout --` is checked rather than parsed as empty.
|
|
653
|
+
const match = analyzeGit(call.viaXargs ? [...call.args, "."] : call.args, call.cwd);
|
|
654
|
+
if (!match)
|
|
655
|
+
continue;
|
|
656
|
+
// A pathspec still holding a variable (`for f in …; do git checkout -- $f`)
|
|
657
|
+
// could name anything once expanded: check the whole tree instead of a
|
|
658
|
+
// literal `$f` that matches no file.
|
|
659
|
+
if (match.pathspecs.some((spec) => spec.includes("$")))
|
|
660
|
+
match.pathspecs = [];
|
|
661
|
+
out.push(match);
|
|
662
|
+
}
|
|
663
|
+
return out;
|
|
664
|
+
}
|
|
665
|
+
class GuardError extends Error {
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Run an inspection git command against the target repo with repo-config
|
|
669
|
+
* execution sinks (fsmonitor, hooks, filters, …) disabled — see
|
|
670
|
+
* runBackgroundGit. `gitArgs` are the command's own `--git-dir`/`--work-tree`.
|
|
671
|
+
*/
|
|
672
|
+
async function runGit(dir, gitArgs, args) {
|
|
673
|
+
try {
|
|
674
|
+
const { stdout } = await runBackgroundGit(args, {
|
|
675
|
+
cwd: dir,
|
|
676
|
+
globalArgs: gitArgs,
|
|
677
|
+
timeoutMs: GIT_TIMEOUT_MS,
|
|
678
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
679
|
+
env: { LC_ALL: "C" },
|
|
680
|
+
});
|
|
681
|
+
return { code: 0, stdout };
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
// A numeric code is git's exit status; a string (ENOENT) or a kill
|
|
685
|
+
// (timeout) means the guard itself could not inspect the repo.
|
|
686
|
+
if (error instanceof BackgroundGitError && typeof error.code === "number" && !error.killed) {
|
|
687
|
+
return { code: error.code, stdout: error.stdout };
|
|
688
|
+
}
|
|
689
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
690
|
+
throw new GuardError(`git ${args.join(" ")} failed: ${message}`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/** `git status --porcelain=v1 -z`, parsed. Null when `dir` is not a repo. */
|
|
694
|
+
async function gitStatus(match, extra) {
|
|
695
|
+
const result = await runGit(match.dir, match.gitArgs, [
|
|
696
|
+
"status",
|
|
697
|
+
"--porcelain=v1",
|
|
698
|
+
"-z",
|
|
699
|
+
...extra,
|
|
700
|
+
"--",
|
|
701
|
+
...match.pathspecs,
|
|
702
|
+
]);
|
|
703
|
+
if (result.code !== 0)
|
|
704
|
+
return null;
|
|
705
|
+
const parts = result.stdout.split("\0");
|
|
706
|
+
const entries = [];
|
|
707
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
708
|
+
const part = parts[i] ?? "";
|
|
709
|
+
if (part.length < 4)
|
|
710
|
+
continue;
|
|
711
|
+
const code = part.slice(0, 2);
|
|
712
|
+
entries.push({ code, file: part.slice(3) });
|
|
713
|
+
if (code.startsWith("R") || code.startsWith("C"))
|
|
714
|
+
i += 1; // rename source path
|
|
715
|
+
}
|
|
716
|
+
return entries;
|
|
717
|
+
}
|
|
718
|
+
function listFiles(entries) {
|
|
719
|
+
const names = entries.slice(0, MAX_LISTED_FILES).map((e) => e.file);
|
|
720
|
+
const more = entries.length - names.length;
|
|
721
|
+
return names.join(", ") + (more > 0 ? `, and ${more} more` : "");
|
|
722
|
+
}
|
|
723
|
+
function describeTracked(entries) {
|
|
724
|
+
const counts = new Map();
|
|
725
|
+
for (const { code } of entries) {
|
|
726
|
+
const label = code.includes("D")
|
|
727
|
+
? "deleted"
|
|
728
|
+
: code.includes("A")
|
|
729
|
+
? "added"
|
|
730
|
+
: code.includes("U")
|
|
731
|
+
? "conflicted"
|
|
732
|
+
: code.startsWith("R")
|
|
733
|
+
? "renamed"
|
|
734
|
+
: "modified";
|
|
735
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
736
|
+
}
|
|
737
|
+
const breakdown = [...counts].map(([label, n]) => `${n} ${label}`).join(", ");
|
|
738
|
+
const noun = entries.length === 1 ? "file" : "files";
|
|
739
|
+
return `${entries.length} changed ${noun} (${breakdown}): ${listFiles(entries)}`;
|
|
740
|
+
}
|
|
741
|
+
const NO_UNDO = "Checkpoints do not capture shell commands, so this could not be undone.";
|
|
742
|
+
function stashAdvice(label, untracked = "-u") {
|
|
743
|
+
return (`Safe alternative: first save the work with \`git stash push ${untracked} -m "gg: before ${label}"\` ` +
|
|
744
|
+
"(that alone also leaves a clean tree; recover with `git stash pop`), or use ask_user to " +
|
|
745
|
+
"confirm the user really wants these changes discarded.");
|
|
746
|
+
}
|
|
747
|
+
async function evaluate(match) {
|
|
748
|
+
const where = match.pathspecs.length > 0 ? ` (${match.pathspecs.join(" ")})` : "";
|
|
749
|
+
switch (match.kind) {
|
|
750
|
+
case "force-push":
|
|
751
|
+
return (`Blocked \`${match.display}\`: a plain force-push overwrites remote commits that are ` +
|
|
752
|
+
"not in your local branch, and nothing here can restore them. Use " +
|
|
753
|
+
"`git push --force-with-lease` (add `--force-if-includes` for extra safety) instead. " +
|
|
754
|
+
"If the user explicitly wants a plain force-push, ask them to run it themselves.");
|
|
755
|
+
case "reset-hard":
|
|
756
|
+
case "checkout-paths":
|
|
757
|
+
case "restore-worktree": {
|
|
758
|
+
if (match.maybeRef !== undefined) {
|
|
759
|
+
const ref = await runGit(match.dir, match.gitArgs, [
|
|
760
|
+
"rev-parse",
|
|
761
|
+
"--verify",
|
|
762
|
+
"--quiet",
|
|
763
|
+
`${match.maybeRef}^{commit}`,
|
|
764
|
+
]);
|
|
765
|
+
if (ref.code === 0)
|
|
766
|
+
return null; // a branch switch, which git refuses if it would clobber
|
|
767
|
+
}
|
|
768
|
+
const status = await gitStatus(match, ["--untracked-files=no"]);
|
|
769
|
+
const tracked = (status ?? []).filter((e) => !e.code.startsWith("?") && !e.code.startsWith("!"));
|
|
770
|
+
if (tracked.length === 0)
|
|
771
|
+
return null;
|
|
772
|
+
return (`Blocked \`${match.display}\`: it would permanently discard uncommitted changes in ` +
|
|
773
|
+
`${match.dir}${where} — ${describeTracked(tracked)}. ${NO_UNDO} ` +
|
|
774
|
+
stashAdvice(match.kind === "reset-hard" ? "reset" : "discarding changes"));
|
|
775
|
+
}
|
|
776
|
+
case "clean": {
|
|
777
|
+
const extra = ["--untracked-files=normal", ...(match.ignored ? ["--ignored"] : [])];
|
|
778
|
+
const status = await gitStatus(match, extra);
|
|
779
|
+
const removable = (status ?? []).filter((e) => {
|
|
780
|
+
const untracked = e.code === "??";
|
|
781
|
+
const ignored = e.code === "!!";
|
|
782
|
+
if (!untracked && !ignored)
|
|
783
|
+
return false;
|
|
784
|
+
if (untracked && match.ignored === "only")
|
|
785
|
+
return false;
|
|
786
|
+
if (ignored && match.ignored === undefined)
|
|
787
|
+
return false;
|
|
788
|
+
// Without -d (and no explicit pathspec), untracked directories stay.
|
|
789
|
+
if (e.file.endsWith("/") && !match.directories && match.pathspecs.length === 0)
|
|
790
|
+
return false;
|
|
791
|
+
return true;
|
|
792
|
+
});
|
|
793
|
+
if (removable.length === 0)
|
|
794
|
+
return null;
|
|
795
|
+
const noun = removable.length === 1 ? "file" : "files";
|
|
796
|
+
return (`Blocked \`${match.display}\`: it would permanently delete ${removable.length} untracked ` +
|
|
797
|
+
`${noun} in ${match.dir}${where}: ${listFiles(removable)}. ${NO_UNDO} ` +
|
|
798
|
+
"Preview with `git clean -n` (same flags). " +
|
|
799
|
+
stashAdvice("clean", match.ignored ? "-a" : "-u"));
|
|
800
|
+
}
|
|
801
|
+
case "stash-drop":
|
|
802
|
+
case "stash-clear": {
|
|
803
|
+
const list = await runGit(match.dir, match.gitArgs, ["stash", "list"]);
|
|
804
|
+
const entries = list.code === 0 ? list.stdout.split("\n").filter((l) => l.length > 0) : [];
|
|
805
|
+
if (entries.length === 0)
|
|
806
|
+
return null;
|
|
807
|
+
const target = match.kind === "stash-clear"
|
|
808
|
+
? `all ${entries.length} stash ${entries.length === 1 ? "entry" : "entries"}`
|
|
809
|
+
: (entries.find((l) => l.startsWith(`${match.refs[0] ?? ""}:`)) ?? match.refs[0] ?? "");
|
|
810
|
+
return (`Blocked \`${match.display}\`: it would permanently delete ${target}. ` +
|
|
811
|
+
"Inspect with `git stash list` / `git stash show -p <entry>`, or keep it as a branch with " +
|
|
812
|
+
"`git stash branch <name> <entry>`. If the user explicitly wants it gone, ask them " +
|
|
813
|
+
"(ask_user) and have them run it themselves.");
|
|
814
|
+
}
|
|
815
|
+
case "branch-force-delete": {
|
|
816
|
+
const losses = [];
|
|
817
|
+
for (const branch of match.refs) {
|
|
818
|
+
const ref = `refs/heads/${branch}`;
|
|
819
|
+
const result = await runGit(match.dir, match.gitArgs, [
|
|
820
|
+
"rev-list",
|
|
821
|
+
"--count",
|
|
822
|
+
ref,
|
|
823
|
+
"--not",
|
|
824
|
+
`--exclude=${ref}`,
|
|
825
|
+
"--all",
|
|
826
|
+
]);
|
|
827
|
+
// Nonzero: no such branch — git branch -D will just fail.
|
|
828
|
+
const count = result.code === 0 ? Number.parseInt(result.stdout.trim(), 10) : 0;
|
|
829
|
+
if (count > 0)
|
|
830
|
+
losses.push(`${branch} (${count} commit${count === 1 ? "" : "s"})`);
|
|
831
|
+
}
|
|
832
|
+
if (losses.length === 0)
|
|
833
|
+
return null;
|
|
834
|
+
return (`Blocked \`${match.display}\`: these branches have commits that exist on no other branch, ` +
|
|
835
|
+
`tag or remote, so deleting them loses that work: ${losses.join(", ")}. ` +
|
|
836
|
+
"Use `git branch -d` (refuses unmerged branches), push or merge the branch first, or — if " +
|
|
837
|
+
"the user explicitly asked to delete it — keep a backup ref first " +
|
|
838
|
+
"(`git tag backup/<branch> <branch>`) and then delete.");
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Returns a block message for the model when `command` would destroy
|
|
844
|
+
* uncommitted work (or force-push), or null to let it run.
|
|
845
|
+
*/
|
|
846
|
+
export async function checkDestructiveGit(command, options) {
|
|
847
|
+
try {
|
|
848
|
+
if (!/\bgit\b/.test(command))
|
|
849
|
+
return null;
|
|
850
|
+
let matches = findDestructiveGitCommands(command, options.cwd);
|
|
851
|
+
if (matches.length === 0)
|
|
852
|
+
return null;
|
|
853
|
+
if (options.resolveCwd) {
|
|
854
|
+
const real = await options.resolveCwd();
|
|
855
|
+
if (real && path.isAbsolute(real) && real !== options.cwd)
|
|
856
|
+
matches = findDestructiveGitCommands(command, real);
|
|
857
|
+
}
|
|
858
|
+
const reasons = [];
|
|
859
|
+
for (const match of matches) {
|
|
860
|
+
// A directory the command creates first cannot hold uncommitted work yet.
|
|
861
|
+
if (match.kind !== "force-push" && !existsSync(match.dir))
|
|
862
|
+
continue;
|
|
863
|
+
const reason = await evaluate(match);
|
|
864
|
+
if (reason)
|
|
865
|
+
reasons.push(reason);
|
|
866
|
+
}
|
|
867
|
+
return reasons.length > 0 ? reasons.join("\n") : null;
|
|
868
|
+
}
|
|
869
|
+
catch (error) {
|
|
870
|
+
log("WARN", "git-guard", `Destructive-git guard failed open: ${error.message}`);
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
//# sourceMappingURL=destructive-git-guard.js.map
|