@kenkaiiii/gg-engine 0.0.0-stage → 7.0.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 +269 -0
- package/assets/skills/gg-guide/references/getting-started.md +290 -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 +278 -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/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 +510 -0
- package/dist/core/session-manager.js +1368 -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 +239 -0
- package/dist/core/subagent-manager.js +1059 -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 +37 -0
- package/dist/tools/subagent.js +406 -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,695 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { resolvePath, rejectSymlink } from "./path-utils.js";
|
|
4
|
+
import { fuzzyFindText, normalizeForFuzzyMatch, countOccurrences, generateDiff, findClosestSnippet, findOccurrenceLines, stripBlankEdges, applyDotdotdots, applyMissingLeadingWhitespace, } from "./edit-diff.js";
|
|
5
|
+
import { localOperations } from "./operations.js";
|
|
6
|
+
import { isFresh, recordWrite } from "./read-tracker.js";
|
|
7
|
+
import { resolveAnchoredEdit } from "../core/hashline.js";
|
|
8
|
+
import { isPlanModeActive, planModeRestriction } from "../core/runtime-mode.js";
|
|
9
|
+
import { resolveWriteGuard } from "../core/workspace-guard.js";
|
|
10
|
+
import { redactedOldTextHint, redactionLossError } from "./redaction-guard.js";
|
|
11
|
+
import { configWriteBlockMessage } from "../core/action-threats.js";
|
|
12
|
+
function isMutationCallback(value) {
|
|
13
|
+
return typeof value === "function";
|
|
14
|
+
}
|
|
15
|
+
function isPlanModeRef(value) {
|
|
16
|
+
return (typeof value === "object" &&
|
|
17
|
+
value !== null &&
|
|
18
|
+
typeof value.current === "boolean");
|
|
19
|
+
}
|
|
20
|
+
const EditAnchorSchema = z.object({
|
|
21
|
+
start_line: z.number().int().min(1),
|
|
22
|
+
start_hash: z.string(),
|
|
23
|
+
end_line: z.number().int().min(1),
|
|
24
|
+
end_hash: z.string(),
|
|
25
|
+
});
|
|
26
|
+
const EditItemFields = z.object({
|
|
27
|
+
old_text: z.string().optional(),
|
|
28
|
+
new_text: z.string().optional(),
|
|
29
|
+
replace_all: z.boolean().optional(),
|
|
30
|
+
span: EditAnchorSchema.optional(),
|
|
31
|
+
lines: z.array(z.string()).optional(),
|
|
32
|
+
});
|
|
33
|
+
// The text-form `anchor` staleness guard is still honoured, but no longer
|
|
34
|
+
// advertised: 3 of ~4,700 real edit calls used it, and its schema cost ~85
|
|
35
|
+
// tokens on every request (bench/prompt-diet). Unknown keys pass through and
|
|
36
|
+
// `anchor` alone is validated here.
|
|
37
|
+
const EditItem = EditItemFields.loose().superRefine((item, ctx) => {
|
|
38
|
+
if (item.anchor === undefined)
|
|
39
|
+
return;
|
|
40
|
+
if (!EditAnchorSchema.safeParse(item.anchor).success) {
|
|
41
|
+
ctx.addIssue({
|
|
42
|
+
code: "custom",
|
|
43
|
+
path: ["anchor"],
|
|
44
|
+
message: "anchor needs start_line, start_hash, end_line, end_hash",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// Several models (opus-5, sonnet-5, fable-5, glm-5.x) occasionally send `edits`
|
|
49
|
+
// as a JSON string instead of a real array, which trips Zod and makes the model
|
|
50
|
+
// fall back to sed/python. Coerce the well-formed case back into an array before
|
|
51
|
+
// validation.
|
|
52
|
+
const coerceStringifiedEdits = (v) => {
|
|
53
|
+
if (typeof v !== "string")
|
|
54
|
+
return v;
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(v);
|
|
57
|
+
return Array.isArray(parsed) ? parsed : v;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Reaching the array schema with a string means the coercion above could not
|
|
64
|
+
// parse it. Every observed case is a hand-serialized array whose inner escaping
|
|
65
|
+
// broke, whose `new_text` key went missing, or that was truncated mid-write.
|
|
66
|
+
//
|
|
67
|
+
// A lenient repair stage (the `jsonrepair` package, as used by several agent
|
|
68
|
+
// runtimes) was measured against 41 real failures from ~/.gg session logs: it
|
|
69
|
+
// parses 11, but only 2 faithfully. The rest pass this schema while silently
|
|
70
|
+
// dropping content -- it closes the JSON at the first error, so a truncated
|
|
71
|
+
// stream yields a short `new_text` and one 8.8KB payload came back with 11% of
|
|
72
|
+
// its characters. Those write partial code over a real file. Recovering 2 in 41
|
|
73
|
+
// is not worth 4 corrupted files, so this stays a hard rejection.
|
|
74
|
+
//
|
|
75
|
+
// What was actually costing turns is the message: Zod's stock "expected array,
|
|
76
|
+
// received string" never tells the model what it did, so it re-sends the
|
|
77
|
+
// identical payload until the agent loop's repeat counter turns the turn fatal.
|
|
78
|
+
// Name the mistake and the way out instead.
|
|
79
|
+
const STRINGIFIED_EDITS_ERROR = "`edits` arrived as a JSON-encoded string and could not be parsed back into an array. " +
|
|
80
|
+
"Send `edits` as a real JSON array of objects, never as a string. " +
|
|
81
|
+
"Re-sending the same large payload usually breaks the same way: split the work into " +
|
|
82
|
+
"several `edit` calls carrying one or two smaller edits each.";
|
|
83
|
+
const EditList = z.preprocess(coerceStringifiedEdits, z
|
|
84
|
+
.array(EditItem, {
|
|
85
|
+
// Narrow to "an array was expected, a string arrived" so a nested
|
|
86
|
+
// string-typed mistake (`anchor: "x"`, `replace_all: "true"`) keeps
|
|
87
|
+
// its own accurate message. Any non-matching issue returns undefined
|
|
88
|
+
// and falls through to Zod's default.
|
|
89
|
+
error: (issue) => issue.code === "invalid_type" &&
|
|
90
|
+
issue.expected === "array" &&
|
|
91
|
+
typeof issue.input === "string"
|
|
92
|
+
? STRINGIFIED_EDITS_ERROR
|
|
93
|
+
: undefined,
|
|
94
|
+
})
|
|
95
|
+
.min(1));
|
|
96
|
+
// Multi-file entries take the text form only: a replay test batched all 7
|
|
97
|
+
// files 8/8 times either way, and dropping the anchor/span forms here keeps
|
|
98
|
+
// ~2k chars of duplicated schema out of every request.
|
|
99
|
+
const TextEditItem = EditItemFields.pick({ old_text: true, new_text: true, replace_all: true });
|
|
100
|
+
const FileEdits = z.object({
|
|
101
|
+
file_path: z.string(),
|
|
102
|
+
edits: z.preprocess(coerceStringifiedEdits, z.array(TextEditItem).min(1)),
|
|
103
|
+
});
|
|
104
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
105
|
+
/** An `edits` item that is really a `files` entry: only nested `edits` (+ optional file_path). */
|
|
106
|
+
const isNestedFileEntry = (v) => isRecord(v) &&
|
|
107
|
+
Array.isArray(coerceStringifiedEdits(v.edits)) &&
|
|
108
|
+
Object.keys(v).every((key) => key === "edits" || key === "file_path");
|
|
109
|
+
// Prompt-diet bench (bench/prompt-diet, GLM-5.3-Flash): the model's commonest
|
|
110
|
+
// malformed edit call puts the multi-file shape under `edits`, either
|
|
111
|
+
// `edits: [{file_path, edits}]` or `file_path` + `edits: [{edits}]`. Zod would
|
|
112
|
+
// strip the nested keys and the call fails with no file to edit, costing a
|
|
113
|
+
// turn. Both shapes are unambiguous, so route them to the intended form.
|
|
114
|
+
const normalizeMisnestedEdits = (raw) => {
|
|
115
|
+
if (!isRecord(raw) || raw.files !== undefined)
|
|
116
|
+
return raw;
|
|
117
|
+
const edits = coerceStringifiedEdits(raw.edits);
|
|
118
|
+
if (!Array.isArray(edits) || edits.length === 0 || !edits.every(isNestedFileEntry))
|
|
119
|
+
return raw;
|
|
120
|
+
const { edits: _nested, ...rest } = raw;
|
|
121
|
+
if (raw.file_path === undefined && edits.every((e) => typeof e.file_path === "string")) {
|
|
122
|
+
return { ...rest, files: edits };
|
|
123
|
+
}
|
|
124
|
+
if (typeof raw.file_path === "string" &&
|
|
125
|
+
edits.every((e) => e.file_path === undefined || e.file_path === raw.file_path)) {
|
|
126
|
+
return { ...rest, edits: edits.flatMap((e) => coerceStringifiedEdits(e.edits)) };
|
|
127
|
+
}
|
|
128
|
+
return raw;
|
|
129
|
+
};
|
|
130
|
+
// Haiku 5.5 (bench/h2h arena, 2026-10-09: a 6-file refactor lost a turn to it)
|
|
131
|
+
// flattens the `files` form into `edits`, naming the file on every item and
|
|
132
|
+
// sending no top-level `file_path`:
|
|
133
|
+
// { edits: [{ file_path, old_text, new_text }, ...] }
|
|
134
|
+
// Each item says which file it edits, so group them, in first-seen order, into
|
|
135
|
+
// `files`. Only text-form items qualify: `files` takes no span/anchor edits, so
|
|
136
|
+
// any other key keeps the existing "Provide file_path and edits" rejection.
|
|
137
|
+
const FLAT_FILE_ITEM_KEYS = new Set(["file_path", "old_text", "new_text", "replace_all"]);
|
|
138
|
+
const isFlatFileItem = (v) => isRecord(v) &&
|
|
139
|
+
typeof v.file_path === "string" &&
|
|
140
|
+
typeof v.old_text === "string" &&
|
|
141
|
+
Object.keys(v).every((key) => FLAT_FILE_ITEM_KEYS.has(key));
|
|
142
|
+
const groupFlatFileEdits = (raw) => {
|
|
143
|
+
if (!isRecord(raw) || raw.files !== undefined || raw.file_path !== undefined)
|
|
144
|
+
return raw;
|
|
145
|
+
const edits = coerceStringifiedEdits(raw.edits);
|
|
146
|
+
if (!Array.isArray(edits) || edits.length === 0 || !edits.every(isFlatFileItem))
|
|
147
|
+
return raw;
|
|
148
|
+
const byFile = new Map();
|
|
149
|
+
for (const { file_path: filePath, ...edit } of edits) {
|
|
150
|
+
const fileEdits = byFile.get(filePath) ?? [];
|
|
151
|
+
fileEdits.push(edit);
|
|
152
|
+
byFile.set(filePath, fileEdits);
|
|
153
|
+
}
|
|
154
|
+
const { edits: _flat, ...rest } = raw;
|
|
155
|
+
return {
|
|
156
|
+
...rest,
|
|
157
|
+
files: [...byFile].map(([filePath, fileEdits]) => ({ file_path: filePath, edits: fileEdits })),
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
// Haiku 5.5 (bench/h2h: 20 of 76 edit calls across 30 runs, and the cause of
|
|
161
|
+
// a failed run) closes the `edits` string where `old_text` should end, which
|
|
162
|
+
// pushes `new_text` up to the top level:
|
|
163
|
+
// { file_path, edits: '[{"old_text">OLD', new_text: 'NEW' }
|
|
164
|
+
// OLD is then the raw, complete old text: the model ended it with its own
|
|
165
|
+
// string terminator, and NEW is a separately parsed, complete JSON string.
|
|
166
|
+
// Nothing is guessed, and the matcher still requires OLD to match the file
|
|
167
|
+
// exactly once, so a wrong recovery fails like any other bad `old_text`.
|
|
168
|
+
// Any other shape (no top-level new_text, extra keys) keeps the hard
|
|
169
|
+
// rejection below.
|
|
170
|
+
const SPLIT_OLD_TEXT_PREFIX = '[{"old_text">';
|
|
171
|
+
const SPLIT_OLD_TEXT_KEYS = new Set(["file_path", "edits", "new_text", "atomic"]);
|
|
172
|
+
const recoverSplitOldText = (raw) => {
|
|
173
|
+
if (!isRecord(raw) || typeof raw.edits !== "string" || typeof raw.new_text !== "string") {
|
|
174
|
+
return raw;
|
|
175
|
+
}
|
|
176
|
+
if (!raw.edits.startsWith(SPLIT_OLD_TEXT_PREFIX))
|
|
177
|
+
return raw;
|
|
178
|
+
if (!Object.keys(raw).every((key) => SPLIT_OLD_TEXT_KEYS.has(key)))
|
|
179
|
+
return raw;
|
|
180
|
+
const oldText = raw.edits.slice(SPLIT_OLD_TEXT_PREFIX.length);
|
|
181
|
+
if (oldText.length === 0)
|
|
182
|
+
return raw;
|
|
183
|
+
const { new_text: newText, ...rest } = raw;
|
|
184
|
+
return { ...rest, edits: [{ old_text: oldText, new_text: newText }] };
|
|
185
|
+
};
|
|
186
|
+
// A single flat edit, the shape most agents' edit tools use:
|
|
187
|
+
// { file_path, old_text, new_text, replace_all? }
|
|
188
|
+
// Haiku 5.5 sends it unprompted, and the schema used to strip the unknown
|
|
189
|
+
// top-level fields, leaving `{ file_path }`: the change was lost and the call
|
|
190
|
+
// failed. Lifted into `edits` only when it is the whole call (no `edits`/
|
|
191
|
+
// `files`, no other keys), so nothing is merged or guessed.
|
|
192
|
+
const FLAT_EDIT_KEYS = new Set(["file_path", "old_text", "new_text", "replace_all", "atomic"]);
|
|
193
|
+
const liftFlatEdit = (raw) => {
|
|
194
|
+
if (!isRecord(raw) || typeof raw.old_text !== "string")
|
|
195
|
+
return raw;
|
|
196
|
+
if (raw.edits !== undefined || raw.files !== undefined)
|
|
197
|
+
return raw;
|
|
198
|
+
if (!Object.keys(raw).every((key) => FLAT_EDIT_KEYS.has(key)))
|
|
199
|
+
return raw;
|
|
200
|
+
const { old_text: oldText, new_text: newText, replace_all: replaceAll, ...rest } = raw;
|
|
201
|
+
return {
|
|
202
|
+
...rest,
|
|
203
|
+
edits: [
|
|
204
|
+
{
|
|
205
|
+
old_text: oldText,
|
|
206
|
+
new_text: newText,
|
|
207
|
+
...(replaceAll === undefined ? {} : { replace_all: replaceAll }),
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
const EditParams = z.preprocess((raw) => groupFlatFileEdits(normalizeMisnestedEdits(recoverSplitOldText(liftFlatEdit(raw)))), z.object({
|
|
213
|
+
file_path: z.string().optional(),
|
|
214
|
+
edits: EditList.optional(),
|
|
215
|
+
files: z
|
|
216
|
+
.array(FileEdits)
|
|
217
|
+
.min(1)
|
|
218
|
+
.optional()
|
|
219
|
+
.describe("Several files: [{file_path, edits}], instead of file_path/edits"),
|
|
220
|
+
atomic: z.boolean().optional().describe("All-or-nothing per file"),
|
|
221
|
+
}));
|
|
222
|
+
function tryMatch(working, old, next, replaceAll) {
|
|
223
|
+
if (old.length === 0)
|
|
224
|
+
return { ok: false, reason: "not_found" };
|
|
225
|
+
const occurrences = countOccurrences(working, old, !replaceAll);
|
|
226
|
+
if (replaceAll && occurrences > 0) {
|
|
227
|
+
const parts = [];
|
|
228
|
+
let cursor = 0;
|
|
229
|
+
// Search only untouched input: replacements can contain old_text or create
|
|
230
|
+
// new matches at their boundaries, neither of which belongs to this edit.
|
|
231
|
+
for (let replaced = 0; replaced < occurrences; replaced++) {
|
|
232
|
+
const match = fuzzyFindText(working.slice(cursor), old);
|
|
233
|
+
if (!match.found || match.matchLength === 0)
|
|
234
|
+
return { ok: false, reason: "not_found" };
|
|
235
|
+
const start = cursor + match.index;
|
|
236
|
+
parts.push(working.slice(cursor, start), next);
|
|
237
|
+
cursor = start + match.matchLength;
|
|
238
|
+
}
|
|
239
|
+
parts.push(working.slice(cursor));
|
|
240
|
+
return { ok: true, newWorking: parts.join("") };
|
|
241
|
+
}
|
|
242
|
+
if (occurrences === 0)
|
|
243
|
+
return { ok: false, reason: "not_found" };
|
|
244
|
+
if (occurrences > 1)
|
|
245
|
+
return { ok: false, reason: "ambiguous", occurrences };
|
|
246
|
+
const match = fuzzyFindText(working, old);
|
|
247
|
+
if (!match.found)
|
|
248
|
+
return { ok: false, reason: "not_found" };
|
|
249
|
+
return {
|
|
250
|
+
ok: true,
|
|
251
|
+
newWorking: working.slice(0, match.index) + next + working.slice(match.index + match.matchLength),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Riskiest strategy used in a batch, worst first. When one edit landed by exact
|
|
256
|
+
* text and another only by `...` elision, the elision is what a resulting
|
|
257
|
+
* breakage should be attributed to.
|
|
258
|
+
*/
|
|
259
|
+
const SOURCE_RISK = ["dotdotdot", "blank_edges", "indent_flex", "text", "span"];
|
|
260
|
+
function riskiestSource(outcomes) {
|
|
261
|
+
const used = new Set(outcomes.map((o) => o.source).filter(Boolean));
|
|
262
|
+
return SOURCE_RISK.find((s) => used.has(s));
|
|
263
|
+
}
|
|
264
|
+
export function createEditTool(cwd, readFiles, ops = localOperations, planModeRefOrOnFileMutated, onFileMutated, onPreFileMutation, getDiagnostics, getWriteGuardSettings) {
|
|
265
|
+
const planModeRef = isPlanModeRef(planModeRefOrOnFileMutated)
|
|
266
|
+
? planModeRefOrOnFileMutated
|
|
267
|
+
: undefined;
|
|
268
|
+
const mutationCallback = isMutationCallback(planModeRefOrOnFileMutated)
|
|
269
|
+
? planModeRefOrOnFileMutated
|
|
270
|
+
: onFileMutated;
|
|
271
|
+
return {
|
|
272
|
+
name: "edit",
|
|
273
|
+
description: "Edit files. `old_text`: verbatim, unique unless replace_all. Or `span` (from read " +
|
|
274
|
+
"anchors:true) + full replacement `lines`. Re-send only failed edits.",
|
|
275
|
+
parameters: EditParams,
|
|
276
|
+
executionMode: "sequential",
|
|
277
|
+
async execute({ file_path, edits, files, atomic = false }) {
|
|
278
|
+
if (isPlanModeActive(planModeRef)) {
|
|
279
|
+
return planModeRestriction("edit");
|
|
280
|
+
}
|
|
281
|
+
const targets = resolveEditTargets(file_path, edits, files);
|
|
282
|
+
if (!targets.ok)
|
|
283
|
+
throw new Error(targets.error);
|
|
284
|
+
if (targets.value.length === 1) {
|
|
285
|
+
const only = targets.value[0];
|
|
286
|
+
return editOneFile(only.file_path, only.edits, atomic);
|
|
287
|
+
}
|
|
288
|
+
// Files apply in order, each independently: one file's failure never
|
|
289
|
+
// rolls back another, and the result says exactly which to re-issue.
|
|
290
|
+
const parts = [];
|
|
291
|
+
const diffs = [];
|
|
292
|
+
let failed = 0;
|
|
293
|
+
for (const target of targets.value) {
|
|
294
|
+
try {
|
|
295
|
+
const result = await editOneFile(target.file_path, target.edits, atomic);
|
|
296
|
+
const content = typeof result === "string" ? result : result.content;
|
|
297
|
+
if (typeof result !== "string" && result.details.diff)
|
|
298
|
+
diffs.push(result.details.diff);
|
|
299
|
+
if (typeof result === "string" && result.startsWith("Error:"))
|
|
300
|
+
failed++;
|
|
301
|
+
parts.push(`### ${target.file_path}\n${content}`);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
failed++;
|
|
305
|
+
parts.push(`### ${target.file_path}\nFAILED — ${error instanceof Error ? error.message : String(error)}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const total = targets.value.length;
|
|
309
|
+
if (failed === total)
|
|
310
|
+
throw new Error(`All ${total} files failed; no changes written.\n\n${parts.join("\n\n")}`);
|
|
311
|
+
const header = failed === 0
|
|
312
|
+
? `Edited ${total} files.`
|
|
313
|
+
: `Edited ${total - failed} of ${total} files. ${failed} failed — re-issue ONLY the failed files (the rest are already done).`;
|
|
314
|
+
return { content: `${header}\n\n${parts.join("\n\n")}`, details: { diff: diffs.join("\n") } };
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
async function editOneFile(file_path, edits, atomic) {
|
|
318
|
+
const resolved = resolvePath(cwd, file_path);
|
|
319
|
+
await rejectSymlink(resolved);
|
|
320
|
+
// Workspace write guard: outside cwd/tmp/~/.gg requires user approval.
|
|
321
|
+
const guard = resolveWriteGuard(cwd, resolved, getWriteGuardSettings?.());
|
|
322
|
+
if (!guard.allowed) {
|
|
323
|
+
return `Error: ${guard.reason}`;
|
|
324
|
+
}
|
|
325
|
+
// No prior read is required: every old_text, span and anchor is matched
|
|
326
|
+
// against the live content below, which proves the model knows the text
|
|
327
|
+
// it replaces (it may have seen it via `cat`, or changed the file itself
|
|
328
|
+
// with a script). A read that no longer matches disk is forgotten, so the
|
|
329
|
+
// file counts as unread again: the edit still validates against live
|
|
330
|
+
// content, but a later full-file `write` needs a fresh read.
|
|
331
|
+
if (readFiles?.has(resolved) && !(await isFresh(readFiles, resolved, ops))) {
|
|
332
|
+
readFiles.delete(resolved);
|
|
333
|
+
}
|
|
334
|
+
const original = await ops.readFile(resolved);
|
|
335
|
+
const hasCRLF = original.includes("\r\n");
|
|
336
|
+
const originalNormalized = hasCRLF ? original.replace(/\r\n/g, "\n") : original;
|
|
337
|
+
// Anchors pin lines in the file AS READ, so they always verify against the
|
|
338
|
+
// original (pre-edit) line array — earlier edits in the batch don't shift
|
|
339
|
+
// what an anchor refers to.
|
|
340
|
+
const originalLines = originalNormalized.split("\n");
|
|
341
|
+
const fileName = path.basename(resolved);
|
|
342
|
+
const outcomes = new Array(edits.length);
|
|
343
|
+
// ── Phase 1: span-form edits (hash-anchored replacement). Spans resolve
|
|
344
|
+
// against the file AS READ and apply bottom-up so indices stay valid.
|
|
345
|
+
// Text-form edits then run on the result in phase 2.
|
|
346
|
+
const isSpanForm = (e) => e.span !== undefined || e.lines !== undefined;
|
|
347
|
+
const spanResolved = [];
|
|
348
|
+
for (let i = 0; i < edits.length; i++) {
|
|
349
|
+
const e = edits[i];
|
|
350
|
+
if (!isSpanForm(e)) {
|
|
351
|
+
if (e.old_text === undefined || e.new_text === undefined) {
|
|
352
|
+
outcomes[i] = {
|
|
353
|
+
ok: false,
|
|
354
|
+
failure: {
|
|
355
|
+
reason: "invalid",
|
|
356
|
+
detail: "provide either old_text+new_text, or span+lines — this edit has neither",
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (!e.span || !e.lines || e.old_text !== undefined || e.new_text !== undefined) {
|
|
363
|
+
outcomes[i] = {
|
|
364
|
+
ok: false,
|
|
365
|
+
failure: {
|
|
366
|
+
reason: "invalid",
|
|
367
|
+
detail: "span form requires BOTH span and lines, and must not mix with old_text/new_text",
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const res = resolveAnchoredEdit(originalLines, e.span);
|
|
373
|
+
if (!res.ok) {
|
|
374
|
+
outcomes[i] = { ok: false, failure: { reason: "stale_anchor" } };
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
spanResolved.push({ index: i, start: res.startIndex, end: res.endIndex, lines: e.lines });
|
|
378
|
+
}
|
|
379
|
+
// Reject overlapping spans (keep the first, fail the rest) — overlap means
|
|
380
|
+
// the model double-addressed the same region and the result is undefined.
|
|
381
|
+
spanResolved.sort((a, b) => a.start - b.start || a.index - b.index);
|
|
382
|
+
const spanApplied = [];
|
|
383
|
+
let lastEnd = -1;
|
|
384
|
+
for (const s of spanResolved) {
|
|
385
|
+
if (s.start <= lastEnd) {
|
|
386
|
+
outcomes[s.index] = { ok: false, failure: { reason: "overlap" } };
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
spanApplied.push(s);
|
|
390
|
+
lastEnd = s.end;
|
|
391
|
+
}
|
|
392
|
+
const workingLines = [...originalLines];
|
|
393
|
+
for (let i = spanApplied.length - 1; i >= 0; i--) {
|
|
394
|
+
const s = spanApplied[i];
|
|
395
|
+
workingLines.splice(s.start, s.end - s.start + 1, ...s.lines);
|
|
396
|
+
outcomes[s.index] = { ok: true, source: "span" };
|
|
397
|
+
}
|
|
398
|
+
let working = workingLines.join("\n");
|
|
399
|
+
// ── Phase 2: text-form edits, sequential on the working buffer.
|
|
400
|
+
for (let i = 0; i < edits.length; i++) {
|
|
401
|
+
if (outcomes[i] !== undefined)
|
|
402
|
+
continue; // span-form or invalid, already settled
|
|
403
|
+
const { old_text, new_text, replace_all } = edits[i];
|
|
404
|
+
const parsedAnchor = EditAnchorSchema.safeParse(edits[i].anchor);
|
|
405
|
+
const anchor = parsedAnchor.success ? parsedAnchor.data : undefined;
|
|
406
|
+
if (old_text === undefined || new_text === undefined)
|
|
407
|
+
continue; // settled above
|
|
408
|
+
// Optional staleness guard (opt-in). Runs BEFORE the fuzzy match ladder:
|
|
409
|
+
// if the model supplied an anchor and the file drifted since it read it,
|
|
410
|
+
// reject this edit instead of risking a misplaced fuzzy match. The fuzzy
|
|
411
|
+
// path below is byte-identical to today when `anchor` is absent.
|
|
412
|
+
if (anchor) {
|
|
413
|
+
const res = resolveAnchoredEdit(originalLines, anchor);
|
|
414
|
+
if (!res.ok) {
|
|
415
|
+
outcomes[i] = { ok: false, failure: { reason: "stale_anchor" } };
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const normalizedOld = hasCRLF ? old_text.replace(/\r\n/g, "\n") : old_text;
|
|
420
|
+
const normalizedNew = hasCRLF ? new_text.replace(/\r\n/g, "\n") : new_text;
|
|
421
|
+
const replaceAll = replace_all ?? false;
|
|
422
|
+
// Identical replacements are explicit no-op successes. They should not
|
|
423
|
+
// block atomic batches that contain real edits, and all-no-op batches
|
|
424
|
+
// should report success without writing.
|
|
425
|
+
if (normalizedOld === normalizedNew) {
|
|
426
|
+
outcomes[i] = { ok: true };
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (normalizedOld.length === 0 ||
|
|
430
|
+
(!working.includes(normalizedOld) && normalizeForFuzzyMatch(normalizedOld).length === 0)) {
|
|
431
|
+
outcomes[i] = {
|
|
432
|
+
ok: false,
|
|
433
|
+
failure: {
|
|
434
|
+
reason: "invalid",
|
|
435
|
+
detail: "old_text is empty after normalization; provide visible surrounding context.",
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
// Aider's full fallback ladder, run only when the primary match
|
|
441
|
+
// returns "not_found". Ambiguous matches deliberately don't fall
|
|
442
|
+
// through — the model needs to add context, not paraphrase further.
|
|
443
|
+
// Order mirrors aider/coders/editblock_coder.py:
|
|
444
|
+
// 1. exact + smart-quote/dash fuzzy (in tryMatch)
|
|
445
|
+
// 2. indent-flex (model omitted/shortened leading whitespace)
|
|
446
|
+
// 3. drop spurious leading/trailing blank lines, retry 1+2
|
|
447
|
+
// 4. dotdotdots (`...` elision with preserved middle)
|
|
448
|
+
let source = "text";
|
|
449
|
+
let result = tryMatch(working, normalizedOld, normalizedNew, replaceAll);
|
|
450
|
+
const tryFallbacks = (oldText) => {
|
|
451
|
+
const flexed = applyMissingLeadingWhitespace(working, oldText, normalizedNew);
|
|
452
|
+
if (flexed !== null)
|
|
453
|
+
return flexed;
|
|
454
|
+
// Re-run primary matcher on the stripped variant as a cheap retry.
|
|
455
|
+
const exact = tryMatch(working, oldText, normalizedNew, replaceAll);
|
|
456
|
+
if (exact.ok)
|
|
457
|
+
return exact.newWorking;
|
|
458
|
+
return null;
|
|
459
|
+
};
|
|
460
|
+
if (!result.ok && result.reason === "not_found") {
|
|
461
|
+
const indentFlexed = applyMissingLeadingWhitespace(working, normalizedOld, normalizedNew);
|
|
462
|
+
if (indentFlexed !== null) {
|
|
463
|
+
result = { ok: true, newWorking: indentFlexed };
|
|
464
|
+
source = "indent_flex";
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (!result.ok && result.reason === "not_found") {
|
|
468
|
+
const stripped = stripBlankEdges(normalizedOld);
|
|
469
|
+
if (stripped !== null) {
|
|
470
|
+
const candidate = tryFallbacks(stripped);
|
|
471
|
+
if (candidate !== null) {
|
|
472
|
+
result = { ok: true, newWorking: candidate };
|
|
473
|
+
source = "blank_edges";
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (!result.ok && result.reason === "not_found") {
|
|
478
|
+
if (replaceAll && /^[ \t]*\.\.\.[ \t]*$/m.test(normalizedOld)) {
|
|
479
|
+
outcomes[i] = {
|
|
480
|
+
ok: false,
|
|
481
|
+
failure: {
|
|
482
|
+
reason: "invalid",
|
|
483
|
+
detail: "replace_all does not support ... elision; use complete matching text or separate uniquely anchored edits.",
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const elided = applyDotdotdots(working, normalizedOld, normalizedNew);
|
|
489
|
+
if (elided !== null) {
|
|
490
|
+
result = { ok: true, newWorking: elided };
|
|
491
|
+
source = "dotdotdot";
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (result.ok) {
|
|
495
|
+
working = result.newWorking;
|
|
496
|
+
outcomes[i] = { ok: true, source };
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (result.reason === "not_found") {
|
|
500
|
+
// Capture the closest-match snippet eagerly against the current
|
|
501
|
+
// working buffer; we'll decide whether to render it post-loop based
|
|
502
|
+
// on whether other edits in this batch succeeded.
|
|
503
|
+
const closest = findClosestSnippet(working, normalizedOld);
|
|
504
|
+
outcomes[i] = {
|
|
505
|
+
ok: false,
|
|
506
|
+
failure: {
|
|
507
|
+
reason: "not_found",
|
|
508
|
+
closestSnippet: closest?.snippet ?? null,
|
|
509
|
+
closestLine: closest?.topLine ?? null,
|
|
510
|
+
redactedHint: redactedOldTextHint(normalizedOld),
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
const occurrences = result.occurrences ?? 0;
|
|
516
|
+
const matches = findOccurrenceLines(working, normalizedOld);
|
|
517
|
+
const matchLines = matches.map((m) => ` line ${m.line}: ${m.preview}`).join("\n");
|
|
518
|
+
const more = occurrences > matches.length ? `\n …and ${occurrences - matches.length} more` : "";
|
|
519
|
+
outcomes[i] = {
|
|
520
|
+
ok: false,
|
|
521
|
+
failure: { reason: "ambiguous", occurrences, matchLines, more },
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const failures = outcomes
|
|
526
|
+
.map((o, i) => (o.ok || !o.failure ? null : { index: i, failure: o.failure }))
|
|
527
|
+
.filter((x) => x !== null);
|
|
528
|
+
const successCount = outcomes.length - failures.length;
|
|
529
|
+
// Closest-match snippets only get suppressed when successes will ACTUALLY
|
|
530
|
+
// be persisted (partial-apply with at least one win). In atomic mode we
|
|
531
|
+
// throw before writing, so the model retries against an unchanged file
|
|
532
|
+
// and the snippet is its only guidance — keep it.
|
|
533
|
+
const willPersistSuccesses = successCount > 0 && !atomic;
|
|
534
|
+
const formatFailureMessage = (f) => {
|
|
535
|
+
if (f.reason === "stale_anchor") {
|
|
536
|
+
return `the file changed since you read it (anchor mismatch) — re-read \`${file_path}\` and retry`;
|
|
537
|
+
}
|
|
538
|
+
if (f.reason === "noop") {
|
|
539
|
+
return `old_text and new_text are identical in ${fileName} — this edit would be a no-op. Either fix new_text or drop this edit.`;
|
|
540
|
+
}
|
|
541
|
+
if (f.reason === "invalid") {
|
|
542
|
+
return `invalid edit: ${f.detail}.`;
|
|
543
|
+
}
|
|
544
|
+
if (f.reason === "overlap") {
|
|
545
|
+
return (`span overlaps another span edit in this batch — the overlapping region was addressed twice. ` +
|
|
546
|
+
`Merge the overlapping spans into one edit and retry.`);
|
|
547
|
+
}
|
|
548
|
+
if (f.reason === "ambiguous") {
|
|
549
|
+
return (`old_text found ${f.occurrences} times in ${fileName}. ` +
|
|
550
|
+
"Include more surrounding context to make the match unique, " +
|
|
551
|
+
"or set replace_all: true to swap every occurrence.\n" +
|
|
552
|
+
"Matches at:\n" +
|
|
553
|
+
f.matchLines +
|
|
554
|
+
f.more);
|
|
555
|
+
}
|
|
556
|
+
const base = `old_text not found in ${fileName}. ` +
|
|
557
|
+
"Text must match verbatim — do not paraphrase. " +
|
|
558
|
+
"Fix this edit's old_text to match the file exactly (re-read the region below if unsure); " +
|
|
559
|
+
"the file is unchanged, so successful edits and prior reads are still valid." +
|
|
560
|
+
f.redactedHint;
|
|
561
|
+
// Build a bounded read suggestion around the closest-match line so the
|
|
562
|
+
// model can re-read just that region (e.g. ±25 lines) instead of the
|
|
563
|
+
// whole file. Skipped when willPersistSuccesses — see comment above.
|
|
564
|
+
const readHint = f.closestLine !== null && !willPersistSuccesses
|
|
565
|
+
? `\nSuggested re-read: \`read file_path="${file_path}" offset=${Math.max(1, f.closestLine - 25)} limit=50\``
|
|
566
|
+
: "";
|
|
567
|
+
if (willPersistSuccesses || !f.closestSnippet)
|
|
568
|
+
return base + readHint;
|
|
569
|
+
return `${base}${readHint}\nClosest match in file:\n${f.closestSnippet}`;
|
|
570
|
+
};
|
|
571
|
+
const formatFailures = () => {
|
|
572
|
+
if (failures.length === 1 && edits.length === 1) {
|
|
573
|
+
return formatFailureMessage(failures[0].failure);
|
|
574
|
+
}
|
|
575
|
+
return failures
|
|
576
|
+
.map((f) => `[edit ${f.index + 1}/${edits.length}] ${formatFailureMessage(f.failure)}`)
|
|
577
|
+
.join("\n\n");
|
|
578
|
+
};
|
|
579
|
+
// Atomic-mode failure, OR partial-mode failure where literally nothing
|
|
580
|
+
// succeeded. Either way nothing should be written and we throw to make
|
|
581
|
+
// the model retry the whole batch.
|
|
582
|
+
if (failures.length > 0 && (atomic || successCount === 0)) {
|
|
583
|
+
// Nothing was written — the file is byte-identical to the last read, so
|
|
584
|
+
// the read tracker stays valid. We deliberately do NOT invalidate it
|
|
585
|
+
// here: doing so turned a precise "old_text not found (closest match
|
|
586
|
+
// below)" error into a misleading "File must be read first" on every
|
|
587
|
+
// following edit, hiding the real fix from the model. A genuine on-disk
|
|
588
|
+
// change (formatter/external edit) is caught by the freshness check.
|
|
589
|
+
const header = atomic && failures.length > 0
|
|
590
|
+
? `${failures.length} of ${edits.length} edit${edits.length === 1 ? "" : "s"} failed; no changes written (atomic).\n\n`
|
|
591
|
+
: edits.length > 1
|
|
592
|
+
? `${failures.length} of ${edits.length} edits failed; no changes written.\n\n`
|
|
593
|
+
: "";
|
|
594
|
+
throw new Error(header + formatFailures());
|
|
595
|
+
}
|
|
596
|
+
// Never replace real secrets with the placeholder the model was shown.
|
|
597
|
+
const lossError = redactionLossError(originalNormalized, working, fileName);
|
|
598
|
+
if (lossError)
|
|
599
|
+
throw new Error(lossError);
|
|
600
|
+
// Action guard: no switching on auto-run / guard-off settings elsewhere.
|
|
601
|
+
const configBlocked = configWriteBlockMessage(resolved, working, originalNormalized);
|
|
602
|
+
if (configBlocked)
|
|
603
|
+
throw new Error(configBlocked);
|
|
604
|
+
const relPath = path.relative(cwd, resolved);
|
|
605
|
+
const diff = generateDiff(originalNormalized, working, relPath);
|
|
606
|
+
const changed = working !== originalNormalized;
|
|
607
|
+
// LSP diagnostics for the just-written content. Best-effort enhancement:
|
|
608
|
+
// any failure (or an opted-out provider) leaves output identical to today.
|
|
609
|
+
let diagnosticsNote = "";
|
|
610
|
+
if (changed) {
|
|
611
|
+
const finalContent = hasCRLF ? working.replace(/\n/g, "\r\n") : working;
|
|
612
|
+
// Snapshot the pre-mutation on-disk state for /rewind before writing.
|
|
613
|
+
await onPreFileMutation?.(resolved);
|
|
614
|
+
await ops.writeFile(resolved, finalContent);
|
|
615
|
+
await recordWrite(readFiles, resolved, finalContent, ops, "edit");
|
|
616
|
+
await mutationCallback?.(resolved);
|
|
617
|
+
// recordWrite refreshed the tracker to the just-written content, so the
|
|
618
|
+
// next edit (including retries of the skipped ones) validates against an
|
|
619
|
+
// accurate snapshot. No invalidation — the failure message already
|
|
620
|
+
// carries the closest match and a bounded re-read hint.
|
|
621
|
+
if (getDiagnostics) {
|
|
622
|
+
try {
|
|
623
|
+
diagnosticsNote = await getDiagnostics(resolved, finalContent, riskiestSource(outcomes));
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
// Diagnostics must never break a successful edit.
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (failures.length === 0) {
|
|
631
|
+
if (!changed) {
|
|
632
|
+
const summary = edits.length > 1
|
|
633
|
+
? `No changes needed in ${relPath}; ${edits.length} edits were no-ops.`
|
|
634
|
+
: `No changes needed in ${relPath}; edit was a no-op.`;
|
|
635
|
+
return { content: summary, details: { diff } };
|
|
636
|
+
}
|
|
637
|
+
const summary = edits.length > 1
|
|
638
|
+
? `Successfully applied ${edits.length} edits to ${relPath}.`
|
|
639
|
+
: `Successfully replaced text in ${relPath}.`;
|
|
640
|
+
return { content: summary + diagnosticsNote, details: { diff } };
|
|
641
|
+
}
|
|
642
|
+
// Partial success — the loud header is deliberate: the model has to know
|
|
643
|
+
// that work was saved AND that only the listed edits need to be retried.
|
|
644
|
+
const noun = failures.length === 1 ? "edit" : "edits";
|
|
645
|
+
const content = `Applied ${successCount} of ${edits.length} edits to ${relPath}.\n` +
|
|
646
|
+
`${failures.length} ${noun} skipped — re-issue ONLY these (the rest are already done, do not redo them):\n\n` +
|
|
647
|
+
formatFailures() +
|
|
648
|
+
diagnosticsNote;
|
|
649
|
+
return { content, details: { diff } };
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
/** Exactly one form: `file_path`+`edits`, or `files`. */
|
|
653
|
+
function resolveEditTargets(file_path, edits, files) {
|
|
654
|
+
const single = file_path !== undefined || edits !== undefined;
|
|
655
|
+
if (files !== undefined && single) {
|
|
656
|
+
return { ok: false, error: "Use either file_path+edits or files, not both." };
|
|
657
|
+
}
|
|
658
|
+
if (files !== undefined)
|
|
659
|
+
return { ok: true, value: files };
|
|
660
|
+
if (file_path === undefined || edits === undefined) {
|
|
661
|
+
return {
|
|
662
|
+
ok: false,
|
|
663
|
+
error: "Provide file_path and edits (one file), or files (several files).",
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
return { ok: true, value: [{ file_path, edits }] };
|
|
667
|
+
}
|
|
668
|
+
// The edit tool as Claude models see it: three flat fields, the shape every
|
|
669
|
+
// other coding agent's edit tool uses (Claude Code, Copilot CLI, Goose).
|
|
670
|
+
// GG's nested form (`edits[]`, `files[]`, line spans) made Haiku 5.5 send the
|
|
671
|
+
// list as a JSON string in 30-57% of calls and think more per line of code
|
|
672
|
+
// than any peer; with this shape it sent 166/166 edits well-formed and its
|
|
673
|
+
// thinking per line of code matched the peers (bench/h2h arena, 2026-10-09).
|
|
674
|
+
//
|
|
675
|
+
// Only the advertised schema changes. Arguments still go through EditParams,
|
|
676
|
+
// which lifts a flat call into `edits` and keeps accepting every nested shape
|
|
677
|
+
// (resumed sessions, callers inside GG), so execution is identical.
|
|
678
|
+
const FLAT_EDIT_SCHEMA = {
|
|
679
|
+
type: "object",
|
|
680
|
+
properties: {
|
|
681
|
+
file_path: { type: "string" },
|
|
682
|
+
old_text: { type: "string" },
|
|
683
|
+
new_text: { type: "string" },
|
|
684
|
+
replace_all: { type: "boolean" },
|
|
685
|
+
},
|
|
686
|
+
required: ["file_path", "old_text", "new_text"],
|
|
687
|
+
};
|
|
688
|
+
export function createFlatEditTool(...args) {
|
|
689
|
+
return {
|
|
690
|
+
...createEditTool(...args),
|
|
691
|
+
description: "Edit a file by replacing old_text (verbatim, unique unless replace_all) with new_text.",
|
|
692
|
+
rawInputSchema: FLAT_EDIT_SCHEMA,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
//# sourceMappingURL=edit.js.map
|