ceulen 0.5.1 → 0.8.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/CHANGELOG.md +365 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.test.ts +67 -0
- package/extensions/lib/registry.ts +104 -8
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +235 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +288 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +649 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +108 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +186 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/configPanel.ts +24 -10
- package/extensions/modules/router/lib/client.ts +63 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +260 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/rules/index.ts +120 -0
- package/extensions/modules/rules/lib/rules.ts +348 -0
- package/extensions/modules/rules/test/lib.test.ts +263 -0
- package/extensions/modules/rules/test/module.test.ts +222 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2464 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +228 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +763 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +524 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/todo/index.ts +478 -0
- package/extensions/modules/todo/test/todo.test.ts +252 -0
- package/extensions/modules/usage/index.ts +70 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/usage/test/session-accumulators.test.ts +85 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +218 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +157 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +198 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +154 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +721 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +230 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +364 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* repair module — tool-call hardening for EVERY model.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the tool-hardening half of @bacnh85/pi-model-tools 0.9.5. The
|
|
5
|
+
* bundle's DELIBERATE deviation from upstream: upstream gated repair + guards
|
|
6
|
+
* on a detected model family (deepseek-v4 / glm); here repair IS the
|
|
7
|
+
* model-agnostic layer, so the deterministic half (schema argument repair,
|
|
8
|
+
* read-notice decontamination, destructive-command + guessed-path guards) runs
|
|
9
|
+
* for all models, and only the family-specific steering half stays out of the
|
|
10
|
+
* bundle entirely.
|
|
11
|
+
*
|
|
12
|
+
* What it registers:
|
|
13
|
+
* - read/write/edit/grep/find/ls/bash, WRAPPED ONCE each (pi lets an
|
|
14
|
+
* extension tool override a built-in by name): schema-driven arg repair,
|
|
15
|
+
* read defaults + a note, bash no-output annotation, edit no-op guard +
|
|
16
|
+
* trim-tolerant retry + nearest-region error + apply_patch escalation.
|
|
17
|
+
* - apply_patch (Codex-style V4D diffs) and str_replace_editor (DSH Minimal
|
|
18
|
+
* pair) as new tools.
|
|
19
|
+
* - a `tool_call` guard hook and the `/repair` status command.
|
|
20
|
+
*
|
|
21
|
+
* Settings (`repair` section, lib/settings.ts) are read PER TOOL CALL, so the
|
|
22
|
+
* /config toggles apply to the next turn. Exception: the bash description
|
|
23
|
+
* clause + the auto-background mechanics bind ONCE at load (a byte-stable
|
|
24
|
+
* description is required for the prompt cache), so `repair.autoBg` /
|
|
25
|
+
* `repair.autoBgSecs` take effect on the next session.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
29
|
+
import { existsSync } from "node:fs";
|
|
30
|
+
import { readFile } from "node:fs/promises";
|
|
31
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
32
|
+
import {
|
|
33
|
+
createBashToolDefinition,
|
|
34
|
+
createEditToolDefinition,
|
|
35
|
+
createFindToolDefinition,
|
|
36
|
+
createGrepToolDefinition,
|
|
37
|
+
createLsToolDefinition,
|
|
38
|
+
createLocalBashOperations,
|
|
39
|
+
createReadToolDefinition,
|
|
40
|
+
createWriteToolDefinition,
|
|
41
|
+
defineTool,
|
|
42
|
+
} from "@earendil-works/pi-coding-agent";
|
|
43
|
+
import { Type } from "typebox";
|
|
44
|
+
import { readDisabledTools } from "../../lib/tools.js";
|
|
45
|
+
import { abortAllBgJobs, bashAutoBgClause, setBgDeliveryEnabled, wrapWithAutoBg } from "./lib/auto-bg.js";
|
|
46
|
+
import {
|
|
47
|
+
computeRetryEdit,
|
|
48
|
+
isEditMismatchError,
|
|
49
|
+
nearestBlock,
|
|
50
|
+
normalizeToLF,
|
|
51
|
+
parseFailedEditIndex,
|
|
52
|
+
stripBom,
|
|
53
|
+
stripReadContamination,
|
|
54
|
+
} from "./lib/edit-repair.js";
|
|
55
|
+
import { createStrReplaceEditorToolDefinition } from "./lib/editor.js";
|
|
56
|
+
import { checkDangerousCommand, isRecord, looksLikeCodePath } from "./lib/guards.js";
|
|
57
|
+
import { repairToolArguments, type RepairKind } from "./lib/input-repair.js";
|
|
58
|
+
import { applyPatchToFiles, parsePatch, PatchParseError } from "./lib/patch.js";
|
|
59
|
+
import { readRepairSettings } from "./lib/settings.js";
|
|
60
|
+
|
|
61
|
+
// ── Wrapper helpers (ported from upstream extensions/index.ts) ──
|
|
62
|
+
|
|
63
|
+
function addReadDefaults(args: unknown): unknown {
|
|
64
|
+
if (!isRecord(args)) return args;
|
|
65
|
+
if ((args.offset !== undefined) === (args.limit !== undefined)) return args;
|
|
66
|
+
const defaults = args.limit !== undefined ? { offset: 1 } : { limit: 2000 };
|
|
67
|
+
const note = args.limit !== undefined
|
|
68
|
+
? "Note: offset was not provided; defaulted to 1."
|
|
69
|
+
: "Note: limit was not provided; defaulted to 2000 lines.";
|
|
70
|
+
const out = { ...args, ...defaults } as Record<string, unknown>;
|
|
71
|
+
// Non-enumerable so host-side schema validation of prepared args (which
|
|
72
|
+
// walks enumerable keys) never rejects the marker; execute still reads it
|
|
73
|
+
// via property access. JSON-cloning hosts drop it silently — the note is
|
|
74
|
+
// cosmetic, so that degrades gracefully.
|
|
75
|
+
Object.defineProperty(out, "__mtReadNote", { value: note, enumerable: false, configurable: true });
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function appendReadNote(result: any, note: unknown) {
|
|
80
|
+
if (typeof note !== "string" || !note) return result;
|
|
81
|
+
return { ...result, content: [...(Array.isArray(result?.content) ? result.content : []), { type: "text", text: note }] };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Strip read-tool contamination notices from an edit's oldText fields. Mutates
|
|
85
|
+
// in place and reports whether anything changed.
|
|
86
|
+
function decontaminateEditArgs(args: any): boolean {
|
|
87
|
+
if (!isRecord(args)) return false;
|
|
88
|
+
const hasOld = Array.isArray(args.edits)
|
|
89
|
+
? args.edits.some((e: any) => isRecord(e) && typeof e.oldText === "string")
|
|
90
|
+
: typeof args.oldText === "string";
|
|
91
|
+
if (!hasOld) return false;
|
|
92
|
+
let changed = false;
|
|
93
|
+
const clean = (s: string): string => {
|
|
94
|
+
const r = stripReadContamination(s);
|
|
95
|
+
if (r.changed) changed = true;
|
|
96
|
+
return r.text;
|
|
97
|
+
};
|
|
98
|
+
if (Array.isArray(args.edits)) {
|
|
99
|
+
for (const e of args.edits) if (isRecord(e) && typeof e.oldText === "string") e.oldText = clean(e.oldText);
|
|
100
|
+
}
|
|
101
|
+
if (typeof args.oldText === "string") args.oldText = clean(args.oldText);
|
|
102
|
+
return changed;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Locate the file, read it, and report its (BOM-stripped, LF-normalized)
|
|
106
|
+
// content for trim-tolerant retry. Returns null on any I/O problem.
|
|
107
|
+
async function readFileForRetry(filePath: string, cwd: string): Promise<string | null> {
|
|
108
|
+
const abs = resolvePath(cwd, filePath);
|
|
109
|
+
try {
|
|
110
|
+
const buf = await readFile(abs);
|
|
111
|
+
return normalizeToLF(stripBom(buf.toString("utf-8")));
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The full wrapped-tool definition factory. Exported for the wrapper
|
|
118
|
+
* integration test (a real edit tool definition + a temp file drives it). */
|
|
119
|
+
export function wrapToolDefinition(
|
|
120
|
+
base: any,
|
|
121
|
+
factory: (cwd: string) => any,
|
|
122
|
+
shouldRepair: () => boolean,
|
|
123
|
+
onRepair: (toolName: string, repairs: readonly RepairKind[]) => void,
|
|
124
|
+
editMismatchCounts?: Map<string, number>,
|
|
125
|
+
activeToolNames?: () => readonly string[],
|
|
126
|
+
// Deviation from upstream: the edit retry/escalation block is gated on the
|
|
127
|
+
// `repair.editRetry` toggle. Read-notice decontamination and the no-op guard
|
|
128
|
+
// stay unconditional (upstream: always on — both are deterministic and safe).
|
|
129
|
+
shouldEditRetry: () => boolean = () => true,
|
|
130
|
+
): any {
|
|
131
|
+
return {
|
|
132
|
+
...base,
|
|
133
|
+
prepareArguments(args: unknown) {
|
|
134
|
+
let prepared = base.prepareArguments ? base.prepareArguments(args as never) : args;
|
|
135
|
+
if (shouldRepair()) {
|
|
136
|
+
const repaired = repairToolArguments(base.name, base.parameters, prepared);
|
|
137
|
+
if (repaired.repaired) { onRepair(base.name, repaired.repairs); prepared = repaired.args; }
|
|
138
|
+
}
|
|
139
|
+
// Strip read-tool contamination from edit oldText (always on — it's a
|
|
140
|
+
// safe, deterministic fix for the documented mismatch root cause).
|
|
141
|
+
if (base.name === "edit" && isRecord(prepared)) {
|
|
142
|
+
if (decontaminateEditArgs(prepared)) {
|
|
143
|
+
onRepair(base.name, ["read-notice-stripped"]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return base.name === "read" ? addReadDefaults(prepared) : prepared;
|
|
147
|
+
},
|
|
148
|
+
async execute(toolCallId: string, params: any, signal: AbortSignal | undefined, onUpdate: any, ctx: any) {
|
|
149
|
+
const cwd = ctx?.cwd || process.cwd();
|
|
150
|
+
const freshDef = factory(cwd);
|
|
151
|
+
const readNote = base.name === "read" && isRecord(params) ? params.__mtReadNote : undefined;
|
|
152
|
+
if (isRecord(params)) delete params.__mtReadNote;
|
|
153
|
+
|
|
154
|
+
if (base.name !== "edit") {
|
|
155
|
+
try {
|
|
156
|
+
const result = await freshDef.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
157
|
+
return base.name === "read" ? appendReadNote(result, readNote) : result;
|
|
158
|
+
} catch (err: any) {
|
|
159
|
+
// Session mining: "(no output) / Command exited with code 1" after a
|
|
160
|
+
// search reads as a crash, so models retry the same command. Annotate
|
|
161
|
+
// it as a no-match result — but only for search-like commands; for
|
|
162
|
+
// predicates (git diff --quiet, test -f, kill -0) exit 1 IS the answer.
|
|
163
|
+
const message: string = err?.message ? String(err.message) : "";
|
|
164
|
+
const command = typeof params?.command === "string" ? params.command : "";
|
|
165
|
+
if (base.name === "bash" && /\b(rg|grep|find|fd|ls|which|whereis|ag|ack)\b/.test(command) && /^\(no output\)\s*\n*\s*Command exited with code \d+/.test(message)) {
|
|
166
|
+
throw new Error(`${message}\n\nNote: no output with a non-zero exit usually means the search/lookup found no matches — change the pattern or tool instead of retrying the same command.`);
|
|
167
|
+
}
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// edit: try once; on a match-failure, retry once with trim-tolerant
|
|
173
|
+
// matching (copying actual file bytes) before giving up with a richer
|
|
174
|
+
// error that shows the nearest region.
|
|
175
|
+
// No-op guard: oldText === newText produces zero change; the core only
|
|
176
|
+
// reports it post-hoc as "might indicate special characters". Fail fast
|
|
177
|
+
// with the index so the model fixes targeting instead of re-sending.
|
|
178
|
+
const noopIdx = (Array.isArray(params?.edits) ? params.edits : typeof params?.oldText === "string" ? [{ oldText: params.oldText, newText: params.newText }] : [])
|
|
179
|
+
.findIndex((e: any) => isRecord(e) && e.oldText === e.newText);
|
|
180
|
+
if (noopIdx !== -1) throw new Error(`edits[${noopIdx}] is a no-op: oldText equals newText. The replacement produces no change — check which region you meant to target.`);
|
|
181
|
+
try {
|
|
182
|
+
const result = await freshDef.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
183
|
+
editMismatchCounts?.delete(resolvePath(cwd, typeof params?.path === "string" ? params.path : ""));
|
|
184
|
+
return result;
|
|
185
|
+
} catch (catchedErr: any) {
|
|
186
|
+
let err: any = catchedErr;
|
|
187
|
+
if (!shouldEditRetry()) throw err;
|
|
188
|
+
const initialMessage: string = err?.message ? String(err.message) : "";
|
|
189
|
+
if (!isEditMismatchError(initialMessage)) throw err;
|
|
190
|
+
|
|
191
|
+
const filePath = typeof params?.path === "string" ? params.path : "";
|
|
192
|
+
if (!filePath) throw err;
|
|
193
|
+
const fileContent = await readFileForRetry(filePath, cwd);
|
|
194
|
+
if (fileContent === null) throw err;
|
|
195
|
+
|
|
196
|
+
const edits: { oldText: string; newText: string }[] = Array.isArray(params?.edits) && params.edits.length > 0
|
|
197
|
+
? params.edits
|
|
198
|
+
: (typeof params?.oldText === "string" ? [{ oldText: params.oldText, newText: params.newText }] : []);
|
|
199
|
+
if (edits.length === 0) throw err;
|
|
200
|
+
|
|
201
|
+
const retry = computeRetryEdit(fileContent, edits, parseFailedEditIndex(initialMessage));
|
|
202
|
+
if (retry) {
|
|
203
|
+
// Rebuild oldText from the file's real bytes (real indentation) so the
|
|
204
|
+
// core exact matcher succeeds; keep the model's newText as-is.
|
|
205
|
+
const fixedParams = { ...params };
|
|
206
|
+
if (Array.isArray(fixedParams.edits)) fixedParams.edits = retry.fixedEdits;
|
|
207
|
+
else fixedParams.oldText = retry.fixedEdits[0].oldText;
|
|
208
|
+
onRepair(base.name, ["trim-match-retry"]);
|
|
209
|
+
try {
|
|
210
|
+
return await freshDef.execute(toolCallId, fixedParams, signal, onUpdate, ctx);
|
|
211
|
+
} catch (retryErr: any) {
|
|
212
|
+
// A failed trim-retry is still a miss — fall through to the
|
|
213
|
+
// unresolvable path below so it counts toward escalation.
|
|
214
|
+
err = retryErr;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Unresolvable: enrich the error with the nearest region so the model
|
|
219
|
+
// can copy verbatim on the next turn.
|
|
220
|
+
const message: string = err?.message ? String(err.message) : "";
|
|
221
|
+
const failing = edits[Math.min(parseFailedEditIndex(message), edits.length - 1)];
|
|
222
|
+
const nearest = failing ? nearestBlock(fileContent, stripReadContamination(failing.oldText).text) : "";
|
|
223
|
+
// Session mining: 26% of mismatches fail again on retry (wrong content,
|
|
224
|
+
// not whitespace). Escalate after the FIRST miss on the same file — the
|
|
225
|
+
// trim-tolerant retry has already run by this point, so a second exact-
|
|
226
|
+
// match attempt almost never recovers (2026-09: 8/8 next-call success
|
|
227
|
+
// after the nudge; max observed retry depth 3 when gated at 2).
|
|
228
|
+
const misses = editMismatchCounts ? (editMismatchCounts.get(resolvePath(cwd, filePath)) ?? 0) + 1 : 1;
|
|
229
|
+
editMismatchCounts?.set(resolvePath(cwd, filePath), misses);
|
|
230
|
+
const escalate = misses >= 1 && (!activeToolNames || activeToolNames().includes("apply_patch"))
|
|
231
|
+
? `\n\nedit has failed ${misses}× on this file. Switch to apply_patch with a small V4D diff (context + -/+ lines) — it does not require exact oldText.`
|
|
232
|
+
: "";
|
|
233
|
+
throw new Error(nearest ? `${message}\n\n${nearest}${escalate}` : `${message}${escalate}`);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ── Module ──
|
|
240
|
+
|
|
241
|
+
export default function repairModule(pi: ExtensionAPI) {
|
|
242
|
+
const settings = readRepairSettings();
|
|
243
|
+
// The bash description half AND the auto-background mechanics bind once at
|
|
244
|
+
// load: the description sits in the cache-safe request head, so it must be
|
|
245
|
+
// byte-stable per session (never per-turn guidance).
|
|
246
|
+
const autoBgOn = settings.autoBg;
|
|
247
|
+
const autoBgSecs = settings.autoBgSecs;
|
|
248
|
+
|
|
249
|
+
// Per-tool kill-switch: a tool named in ceulen.disabledTools registers
|
|
250
|
+
// inactive, so /config's live tool toggles keep working over the wrapped
|
|
251
|
+
// built-ins too. The persisted list re-applies on every load.
|
|
252
|
+
const disabled = readDisabledTools();
|
|
253
|
+
const repairCounts = new Map<string, number>();
|
|
254
|
+
// Per-file edit-mismatch counters — escalate to apply_patch after repeated
|
|
255
|
+
// unresolvable misses on the same file (26% retry-fail tail).
|
|
256
|
+
const editMismatchCounts = new Map<string, number>();
|
|
257
|
+
|
|
258
|
+
const onRepair = (toolName: string, repairs: readonly RepairKind[]) => {
|
|
259
|
+
repairCounts.set(toolName, (repairCounts.get(toolName) ?? 0) + 1);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// ── Wrapped built-ins, registered ONCE each ──
|
|
263
|
+
const toolFactories: Record<string, (cwd: string) => any> = {
|
|
264
|
+
read: createReadToolDefinition,
|
|
265
|
+
write: createWriteToolDefinition,
|
|
266
|
+
edit: createEditToolDefinition,
|
|
267
|
+
grep: createGrepToolDefinition,
|
|
268
|
+
find: createFindToolDefinition,
|
|
269
|
+
ls: createLsToolDefinition,
|
|
270
|
+
bash: (cwd: string) => {
|
|
271
|
+
const def = createBashToolDefinition(
|
|
272
|
+
cwd,
|
|
273
|
+
autoBgOn ? { operations: wrapWithAutoBg(createLocalBashOperations(), { pi, thresholdSecs: autoBgSecs }) } : undefined,
|
|
274
|
+
);
|
|
275
|
+
return { ...def, description: `${def.description}\n\n${bashAutoBgClause(autoBgOn, autoBgSecs)}` };
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
for (const factory of Object.values(toolFactories)) {
|
|
279
|
+
const template = factory(process.cwd());
|
|
280
|
+
pi.registerTool({
|
|
281
|
+
...wrapToolDefinition(
|
|
282
|
+
template,
|
|
283
|
+
factory,
|
|
284
|
+
() => readRepairSettings().arguments,
|
|
285
|
+
onRepair,
|
|
286
|
+
editMismatchCounts,
|
|
287
|
+
() => pi.getActiveTools(),
|
|
288
|
+
() => readRepairSettings().editRetry,
|
|
289
|
+
),
|
|
290
|
+
defaultActive: !disabled.has(template.name),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ── apply_patch: Codex-style diff/patch tool (robust for weak models) ──
|
|
295
|
+
pi.registerTool({
|
|
296
|
+
...defineTool({
|
|
297
|
+
name: "apply_patch",
|
|
298
|
+
label: "apply_patch",
|
|
299
|
+
description: [
|
|
300
|
+
"Apply a Codex-style V4D patch to edit one or more files. Emit only changed lines plus a little surrounding context (a small diff), which is easier to get right than reproducing a large verbatim block. Supported sections: `*** Add File: <path>` (only `+` lines), `*** Delete File: <path>` (no payload), `*** Update File: <path>` or `*** Update File: <old> → <new>` (rename). Inside an Update section, each hunk is preceded by a `@@` anchor line whose text is an unchanged context line, then `-` removed lines and `+` added lines. Leading-space context lines (` `) are also allowed. If the @@ anchor text is restated as the immediately-following context or removed line, the duplicate is auto-collapsed. Context+removed must match UNIQUELY in the file. Wrap the whole patch in `*** Begin Patch` ... `*** End Patch`.",
|
|
301
|
+
"",
|
|
302
|
+
"Example:",
|
|
303
|
+
"*** Begin Patch", "*** Update File: src/foo.ts", "@@ export function foo()", "- return 1", "+ return 2", "*** End Patch",
|
|
304
|
+
].join("\n"),
|
|
305
|
+
promptSnippet: "Apply a diff/patch to edit one or more files (Codex V4D format)",
|
|
306
|
+
promptGuidelines: [
|
|
307
|
+
"Use apply_patch for multi-line or multi-file edits: emit a small diff (context + -/+ lines) instead of reproducing large verbatim oldText blocks.",
|
|
308
|
+
"Each Update hunk needs a unique anchor: include enough unchanged context lines so the context+removed block matches exactly once in the file.",
|
|
309
|
+
"If the @@ anchor repeats on the very next line (as space-context or -removed), the duplicate is auto-collapsed.",
|
|
310
|
+
"For a single tiny one-line replacement, edit is fine; for anything larger or spanning multiple files, prefer apply_patch.",
|
|
311
|
+
],
|
|
312
|
+
parameters: Type.Object({ patch: Type.String({ description: "The V4D patch text, wrapped in *** Begin Patch ... *** End Patch." }) }),
|
|
313
|
+
renderShell: "self",
|
|
314
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
315
|
+
const cwd = ctx?.cwd || process.cwd();
|
|
316
|
+
let parsed;
|
|
317
|
+
try {
|
|
318
|
+
parsed = parsePatch(params.patch);
|
|
319
|
+
} catch (err) {
|
|
320
|
+
const msg = err instanceof PatchParseError ? err.message : String(err);
|
|
321
|
+
return { content: [{ type: "text", text: `Invalid patch: ${msg}` }], isError: true, details: undefined };
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const res = await applyPatchToFiles(parsed, cwd);
|
|
325
|
+
const summary = res.files.map((f) => {
|
|
326
|
+
if (f.kind === "add") return `Added ${f.path}`;
|
|
327
|
+
if (f.kind === "delete") return `Deleted ${f.path}`;
|
|
328
|
+
return `Updated ${f.path}`;
|
|
329
|
+
}).join("\n");
|
|
330
|
+
const exactness = res.exact ? "" : "\nNote: some hunks matched via fuzzy (whitespace/Unicode) normalization.";
|
|
331
|
+
return {
|
|
332
|
+
content: [{ type: "text", text: `${summary}${exactness}` }],
|
|
333
|
+
details: { diff: res.diff, files: res.files.map((f) => f.path) },
|
|
334
|
+
};
|
|
335
|
+
} catch (err) {
|
|
336
|
+
return { content: [{ type: "text", text: err instanceof Error ? err.message : String(err) }], isError: true, details: undefined };
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
}),
|
|
340
|
+
defaultActive: !disabled.has("apply_patch"),
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// ── str_replace_editor: DSH Minimal-pair editor (byte-faithful schema) ──
|
|
344
|
+
pi.registerTool({
|
|
345
|
+
...createStrReplaceEditorToolDefinition(process.cwd()),
|
|
346
|
+
defaultActive: !disabled.has("str_replace_editor"),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// ── Session lifecycle ──
|
|
350
|
+
pi.on("session_start", () => {
|
|
351
|
+
// Per-session — misses from a prior session must not escalate.
|
|
352
|
+
editMismatchCounts.clear();
|
|
353
|
+
repairCounts.clear();
|
|
354
|
+
});
|
|
355
|
+
if (autoBgOn) {
|
|
356
|
+
pi.on("session_start", () => setBgDeliveryEnabled(true));
|
|
357
|
+
// Delivery is suppressed so the aborts don't fire triggerTurn follow-ups
|
|
358
|
+
// into a session that is going away (/new and /resume also fire
|
|
359
|
+
// session_shutdown, so cross-session leakage can't happen).
|
|
360
|
+
pi.on("session_shutdown", () => {
|
|
361
|
+
abortAllBgJobs(true);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ── tool_call: destructive-bash + read-on-guessed-path guards (ALL models).
|
|
366
|
+
// Upstream gated these on a detected family; repair is the model-agnostic
|
|
367
|
+
// layer here, so the guards are ungated (only the `repair.guards` toggle). ──
|
|
368
|
+
pi.on("tool_call", (event, ctx) => {
|
|
369
|
+
if (!readRepairSettings().guards) return;
|
|
370
|
+
if (event.toolName === "bash") {
|
|
371
|
+
const command = isRecord(event.input) ? event.input.command : undefined;
|
|
372
|
+
const danger = checkDangerousCommand(command);
|
|
373
|
+
if (danger) return { block: true, reason: `Safety: ${danger}` };
|
|
374
|
+
}
|
|
375
|
+
if (event.toolName === "read" && isRecord(event.input) && ctx.cwd) {
|
|
376
|
+
const filePath = typeof event.input.path === "string" ? event.input.path.trim() : "";
|
|
377
|
+
if (filePath && looksLikeCodePath(filePath) && !existsSync(resolvePath(ctx.cwd, filePath))) {
|
|
378
|
+
const filename = filePath.split("/").pop() ?? filePath;
|
|
379
|
+
const relDir = dirname(filePath);
|
|
380
|
+
const dirPart = relDir !== "." ? ` under ${relDir}/` : "";
|
|
381
|
+
return { block: true, reason: `Path not found: "${filePath}". Use find to locate "${filename}"${dirPart}, then read.` };
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// ── /repair (bare = status) ──
|
|
387
|
+
pi.registerCommand("repair", {
|
|
388
|
+
description: "Show tool-hardening status: repair counts, guards, bash auto-background.",
|
|
389
|
+
handler: async (_args, ctx) => {
|
|
390
|
+
const live = readRepairSettings();
|
|
391
|
+
const total = [...repairCounts.values()].reduce((a, b) => a + b, 0);
|
|
392
|
+
const lines = [
|
|
393
|
+
"## repair status",
|
|
394
|
+
"",
|
|
395
|
+
"**Settings** (global settings.json ⊕ trusted project):",
|
|
396
|
+
` Argument repair: ${live.arguments ? "on" : "off"}`,
|
|
397
|
+
` Edit mismatch repair: ${live.editRetry ? "on" : "off"}`,
|
|
398
|
+
` Tool-call guards: ${live.guards ? "on" : "off"}`,
|
|
399
|
+
` Auto-background bash: ${live.autoBg ? `on @${live.autoBgSecs}s` : "off"}${live.autoBg !== autoBgOn || live.autoBgSecs !== autoBgSecs ? ` (bound at load: ${autoBgOn ? `on @${autoBgSecs}s` : "off"} — next session applies)` : ""}`,
|
|
400
|
+
"",
|
|
401
|
+
`**Repairs this session:** ${total} total`,
|
|
402
|
+
];
|
|
403
|
+
for (const [tool, count] of [...repairCounts.entries()].sort((a, b) => b[1] - a[1])) {
|
|
404
|
+
lines.push(` ${tool}: ${count}`);
|
|
405
|
+
}
|
|
406
|
+
lines.push(
|
|
407
|
+
"",
|
|
408
|
+
`**Escalation counters (edit misses per file):** ${editMismatchCounts.size}`,
|
|
409
|
+
"**Tools:** apply_patch + str_replace_editor registered; read/write/edit/grep/find/ls/bash wrapped.",
|
|
410
|
+
);
|
|
411
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
}
|