ceulen 0.5.0 → 0.7.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 +317 -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.ts +93 -7
- 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 +217 -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 +286 -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 +586 -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 +105 -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 +161 -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/lib/client.ts +61 -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 +179 -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/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 +2451 -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 +223 -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 +752 -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 +350 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/usage/index.ts +59 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -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 +193 -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 +148 -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 +132 -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 +151 -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 +718 -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 +207 -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 +345 -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,357 @@
|
|
|
1
|
+
// Ported from pi-model-tools extensions/test/unit/guidance.test.ts.
|
|
2
|
+
// Local change: the PI_MODEL_TOOLS_* env toggles are `steering` settings rows
|
|
3
|
+
// now, so the hook tests write a settings file into a temp agent dir and fire a
|
|
4
|
+
// turn (settings are re-read per before_agent_start).
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { after, before, beforeEach, describe, it } from "node:test";
|
|
9
|
+
import { createFakePi, isolateAgentDir } from "./harness.js";
|
|
10
|
+
import {
|
|
11
|
+
applyPatchPreferenceGuidance,
|
|
12
|
+
clearGuidanceCache,
|
|
13
|
+
deepSeekSelectionGuidance,
|
|
14
|
+
githubCloneFirstToolHint,
|
|
15
|
+
readUncertainPathHint,
|
|
16
|
+
runTaskFirstToolHint,
|
|
17
|
+
superPowerPrompt,
|
|
18
|
+
} from "../lib/guidance.js";
|
|
19
|
+
|
|
20
|
+
let AGENT: string;
|
|
21
|
+
let restoreAgentDir: () => void;
|
|
22
|
+
|
|
23
|
+
before(() => {
|
|
24
|
+
const isolated = isolateAgentDir("ceulen-steering-guidance-");
|
|
25
|
+
AGENT = isolated.dir;
|
|
26
|
+
restoreAgentDir = isolated.restore;
|
|
27
|
+
});
|
|
28
|
+
after(() => { restoreAgentDir(); });
|
|
29
|
+
beforeEach(() => { writeFileSync(join(AGENT, "settings.json"), "{}"); });
|
|
30
|
+
/** Write the `steering` section the next turn will read. */
|
|
31
|
+
const setSettings = (steering: Record<string, unknown>) => writeFileSync(join(AGENT, "settings.json"), JSON.stringify({ steering }));
|
|
32
|
+
|
|
33
|
+
describe("deepSeekSelectionGuidance", () => {
|
|
34
|
+
it("includes the compact routing table with serena entries when serena is active", () => {
|
|
35
|
+
const g = deepSeekSelectionGuidance(["read", "bash", "serena_find_symbol", "serena_find_referencing_symbols"]);
|
|
36
|
+
assert.match(g, /pick the right tool on the first try/);
|
|
37
|
+
assert.match(g, /"run tests".*bash/);
|
|
38
|
+
assert.match(g, /path uncertain.*find before read/);
|
|
39
|
+
assert.match(g, /serena_find_symbol/);
|
|
40
|
+
assert.match(g, /serena_find_referencing_symbols/);
|
|
41
|
+
assert.match(g, /serena_get_symbols_overview/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("omits serena entries when serena is not active", () => {
|
|
45
|
+
const g = deepSeekSelectionGuidance(["ls", "grep", "bash", "write"]);
|
|
46
|
+
assert.doesNotMatch(g, /serena/);
|
|
47
|
+
assert.match(g, /"list files in <dir>" → ls/);
|
|
48
|
+
assert.match(g, /create a file → write/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("produces consistent memoized output for same tool set", () => {
|
|
52
|
+
clearGuidanceCache();
|
|
53
|
+
const a = deepSeekSelectionGuidance(["bash", "read"]);
|
|
54
|
+
const b = deepSeekSelectionGuidance(["read", "bash"]);
|
|
55
|
+
const c = deepSeekSelectionGuidance(["bash", "read", "serena_find_symbol"]);
|
|
56
|
+
assert.equal(a, b);
|
|
57
|
+
assert.notEqual(a, c);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("runTaskFirstToolHint", () => {
|
|
62
|
+
it("fires a bash-FIRST hint for run/build/execute tasks", () => {
|
|
63
|
+
assert.match(runTaskFirstToolHint("Run the unit tests.")!, /FIRST tool call MUST be bash/i);
|
|
64
|
+
assert.ok(runTaskFirstToolHint("Build the project and report errors."));
|
|
65
|
+
assert.ok(runTaskFirstToolHint("Lint the source files."));
|
|
66
|
+
assert.ok(runTaskFirstToolHint("Execute the test suite."));
|
|
67
|
+
assert.ok(runTaskFirstToolHint("Compile the TypeScript."));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("returns undefined for discovery/explanation tasks (no false positives)", () => {
|
|
71
|
+
assert.equal(runTaskFirstToolHint("Find all test files for the project."), undefined);
|
|
72
|
+
assert.equal(runTaskFirstToolHint("Find TypeScript test files under extensions/test."), undefined);
|
|
73
|
+
assert.equal(runTaskFirstToolHint("Inspect symbols in index.ts and summarize them."), undefined);
|
|
74
|
+
assert.equal(runTaskFirstToolHint("Find the definition of deepSeekSelectionGuidance."), undefined);
|
|
75
|
+
assert.equal(runTaskFirstToolHint("Analyze the codebase at https://github.com/octocat/Hello-World."), undefined);
|
|
76
|
+
assert.equal(runTaskFirstToolHint("List files in the project."), undefined);
|
|
77
|
+
assert.equal(runTaskFirstToolHint("How does the test runner work?"), undefined);
|
|
78
|
+
assert.equal(runTaskFirstToolHint(""), undefined);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("readUncertainPathHint", () => {
|
|
83
|
+
it("fires a find-FIRST hint for bare-filename reads with no directory path", () => {
|
|
84
|
+
assert.match(readUncertainPathHint("Read the first 20 lines of guidance.ts under the lib dir.")!, /Call find FIRST/i);
|
|
85
|
+
assert.ok(readUncertainPathHint("Show me the contents of cli.py."));
|
|
86
|
+
assert.ok(readUncertainPathHint("Read auth.ts."));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("returns undefined when an exact dir/file path is given or for non-read/symbol tasks", () => {
|
|
90
|
+
assert.equal(readUncertainPathHint("Read only the first 20 lines of README.md."), undefined);
|
|
91
|
+
assert.equal(readUncertainPathHint("Read the README scope section."), undefined);
|
|
92
|
+
assert.equal(readUncertainPathHint("Inspect symbols in extensions/index.ts and summarize them."), undefined);
|
|
93
|
+
assert.equal(readUncertainPathHint("Find the definition of deepSeekSelectionGuidance."), undefined);
|
|
94
|
+
assert.equal(readUncertainPathHint("Read src/config/app.ts carefully."), undefined);
|
|
95
|
+
assert.equal(readUncertainPathHint("Run the unit tests."), undefined);
|
|
96
|
+
assert.equal(readUncertainPathHint(""), undefined);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("githubCloneFirstToolHint", () => {
|
|
101
|
+
it("fires a bash-FIRST hint for analyze-a-repo-URL requests", () => {
|
|
102
|
+
assert.match(githubCloneFirstToolHint("Analyze the codebase at https://github.com/octocat/Hello-World and summarize its structure.")!, /FIRST tool call MUST be bash.*git clone/is);
|
|
103
|
+
assert.ok(githubCloneFirstToolHint("Review the code at https://gitlab.com/foo/bar."));
|
|
104
|
+
assert.ok(githubCloneFirstToolHint("Understand the architecture of https://github.com/owner/repo.git"));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("returns undefined for page-level reads (issues/PRs) and non-repo/non-analyze prompts", () => {
|
|
108
|
+
assert.equal(githubCloneFirstToolHint("Read the issue at https://github.com/octocat/Hello-World/issues/1."), undefined, "issue page → web tool");
|
|
109
|
+
assert.equal(githubCloneFirstToolHint("Summarize PR https://github.com/owner/repo/pull/42."), undefined, "PR → web tool");
|
|
110
|
+
assert.equal(githubCloneFirstToolHint("What is the release at https://github.com/owner/repo/releases/tag/v1?"), undefined, "release → web tool");
|
|
111
|
+
assert.equal(githubCloneFirstToolHint("Inspect symbols in pi-model-tools/extensions/index.ts."), undefined, "no repo URL");
|
|
112
|
+
assert.equal(githubCloneFirstToolHint("Run the tests."), undefined, "no repo URL");
|
|
113
|
+
assert.equal(githubCloneFirstToolHint(""), undefined);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("applyPatchPreferenceGuidance", () => {
|
|
118
|
+
it("returns guidance when apply_patch is in active tools", () => {
|
|
119
|
+
const out = applyPatchPreferenceGuidance(["edit", "apply_patch", "read"]);
|
|
120
|
+
assert.ok(out, "expected guidance when apply_patch active");
|
|
121
|
+
assert.match(out!, /apply_patch/);
|
|
122
|
+
assert.match(out!, /UNIQUELY/i);
|
|
123
|
+
assert.match(out!, /frontmatter/i, "should mention YAML frontmatter");
|
|
124
|
+
assert.match(out!, /Create a new file .* write .*never create files from bash/i, "should steer file creation away from bash writes");
|
|
125
|
+
assert.match(out!, /one-strike/i, "should mention one-strike-switch rule");
|
|
126
|
+
assert.match(out!, /≤3 lines/, "should mention ~3-line threshold for edit");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("returns undefined when apply_patch is not active", () => {
|
|
130
|
+
assert.equal(applyPatchPreferenceGuidance(["edit", "read", "bash"]), undefined);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("superPowerPrompt", () => {
|
|
135
|
+
it("returns the base prompt when no custom text is configured", () => {
|
|
136
|
+
const result = superPowerPrompt();
|
|
137
|
+
assert.ok(result.length > 100);
|
|
138
|
+
assert.match(result, /DEEPSEEK-V4-SUPERPOWER/);
|
|
139
|
+
assert.match(result, /NEVER refuse/);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("uses the custom text when the settings row is set", () => {
|
|
143
|
+
assert.equal(superPowerPrompt("You are a helpful assistant."), "You are a helpful assistant.");
|
|
144
|
+
assert.match(superPowerPrompt(" "), /DEEPSEEK-V4-SUPERPOWER/);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("prompt-aware hints apply to ALL families (not DeepSeek-only)", () => {
|
|
149
|
+
it("fires github-clone and run hints for a GLM model", () => {
|
|
150
|
+
const { fire, ctx } = createFakePi(["bash", "find", "read"]);
|
|
151
|
+
const beforeStart = fire("before_agent_start",
|
|
152
|
+
{ systemPrompt: "base", systemPromptOptions: { selectedTools: ["bash", "find", "read"] }, prompt: "Analyze the codebase at https://github.com/octocat/Hello-World and summarize its structure." },
|
|
153
|
+
ctx("glm-5.2"));
|
|
154
|
+
// Hints are per-turn dynamic → injected into the current user message by
|
|
155
|
+
// before_provider_request, NOT the system prompt (cache-head stability).
|
|
156
|
+
assert.equal(beforeStart, undefined, "no static system-prompt content for this tool set (no apply_patch → no patch hint)");
|
|
157
|
+
const payload = { messages: [{ role: "user", content: "Analyze the codebase at https://github.com/octocat/Hello-World." }] };
|
|
158
|
+
const result = fire("before_provider_request", { payload }, ctx("glm-5.2"));
|
|
159
|
+
assert.ok(result, "GLM should receive prompt-aware hints via the user message");
|
|
160
|
+
assert.match(result.messages[0].content, /FIRST tool call MUST be bash.*git clone/is);
|
|
161
|
+
// GLM must NOT receive the verbose DeepSeek selection-guidance text block.
|
|
162
|
+
assert.doesNotMatch(result.messages[0].content, /DeepSeek V4 — pick the right tool/);
|
|
163
|
+
assert.doesNotMatch(result.messages[0].content, /DEEPSEEK-V4-SUPERPOWER/);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("fires read-uncertain-path hint for a GLM bare-filename read", () => {
|
|
167
|
+
const { fire, ctx } = createFakePi(["find", "read"]);
|
|
168
|
+
const beforeStart = fire("before_agent_start",
|
|
169
|
+
{ systemPrompt: "base", systemPromptOptions: { selectedTools: ["find", "read"] }, prompt: "Read the first 20 lines of guidance.ts under pi-model-tools." },
|
|
170
|
+
ctx("glm-5.2"));
|
|
171
|
+
assert.equal(beforeStart, undefined, "no DeepSeek selection-guidance block for this tool set");
|
|
172
|
+
const payload = { messages: [{ role: "user", content: "Read the first 20 lines of guidance.ts under pi-model-tools." }] };
|
|
173
|
+
const result = fire("before_provider_request", { payload }, ctx("glm-5.2"));
|
|
174
|
+
assert.ok(result);
|
|
175
|
+
assert.match(result.messages[0].content, /Call find FIRST/i);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("GLM + apply_patch active → patch-hint guidance is appended to the system prompt", () => {
|
|
179
|
+
const { fire, ctx } = createFakePi(["edit", "apply_patch", "read"]);
|
|
180
|
+
const beforeStart = fire("before_agent_start",
|
|
181
|
+
{ systemPrompt: "base", systemPromptOptions: { selectedTools: ["edit", "apply_patch", "read"] }, prompt: "Refactor the auth module." },
|
|
182
|
+
ctx("glm-5.2"));
|
|
183
|
+
assert.ok(beforeStart, "GLM should receive the static patch-hint block (un-gated 2026-09)");
|
|
184
|
+
assert.match(beforeStart.systemPrompt, /apply_patch \(preferred for non-trivial edits\)/);
|
|
185
|
+
assert.match(beforeStart.systemPrompt, /Create a new file .* write .*never create files from bash/i);
|
|
186
|
+
// DeepSeek-only blocks stay absent for GLM.
|
|
187
|
+
assert.doesNotMatch(beforeStart.systemPrompt, /DeepSeek V4 — pick the right tool/);
|
|
188
|
+
assert.doesNotMatch(beforeStart.systemPrompt, /DEEPSEEK-V4-SUPERPOWER/);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("leaves the incoming system prompt intact (compose, never clobber)", () => {
|
|
192
|
+
const { fire, ctx } = createFakePi(["edit", "apply_patch", "read"]);
|
|
193
|
+
const incoming = "PONYTAIL LINE\n\nAdvisor notes: …\n\nbase prompt";
|
|
194
|
+
const beforeStart = fire("before_agent_start",
|
|
195
|
+
{ systemPrompt: incoming, systemPromptOptions: { selectedTools: ["edit", "apply_patch", "read"] }, prompt: "refactor" },
|
|
196
|
+
ctx("glm-5.2"));
|
|
197
|
+
assert.ok(beforeStart.systemPrompt.startsWith(incoming), "earlier handlers' prompt text is preserved verbatim as the head");
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("Super Power Mode (settings row `steering.superpower`)", () => {
|
|
202
|
+
it("injects the super power prompt into the system prompt when enabled for DeepSeek V4", () => {
|
|
203
|
+
setSettings({ superpower: true });
|
|
204
|
+
const { fire, ctx } = createFakePi(["read", "bash"]);
|
|
205
|
+
const result = fire("before_agent_start", { systemPrompt: "base prompt", systemPromptOptions: { selectedTools: ["read", "bash"] } }, ctx("deepseek-v4-flash"));
|
|
206
|
+
assert.ok(result, "should return a modified system prompt");
|
|
207
|
+
assert.match(result.systemPrompt, /DEEPSEEK-V4-SUPERPOWER/);
|
|
208
|
+
assert.match(result.systemPrompt, /base prompt/);
|
|
209
|
+
assert.ok(result.systemPrompt.indexOf("DEEPSEEK-V4-SUPERPOWER") < result.systemPrompt.indexOf("base prompt"),
|
|
210
|
+
"super power prompt should appear before the base system prompt");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("uses the custom prompt text from steering.superpowerPrompt", () => {
|
|
214
|
+
setSettings({ superpower: true, superpowerPrompt: "You are CUSTOM SUPERPOWER." });
|
|
215
|
+
const { fire, ctx } = createFakePi(["read", "bash"]);
|
|
216
|
+
const result = fire("before_agent_start", { systemPrompt: "base", systemPromptOptions: { selectedTools: ["read", "bash"] } }, ctx("deepseek-v4-flash"));
|
|
217
|
+
assert.match(result.systemPrompt, /CUSTOM SUPERPOWER/);
|
|
218
|
+
assert.doesNotMatch(result.systemPrompt, /DEEPSEEK-V4-SUPERPOWER/);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("does not inject the super power prompt by default (row off)", () => {
|
|
222
|
+
const { fire, ctx } = createFakePi(["read", "bash"]);
|
|
223
|
+
const result = fire("before_agent_start", { systemPrompt: "base prompt", systemPromptOptions: { selectedTools: ["read", "bash"] } }, ctx("deepseek-v4-flash"));
|
|
224
|
+
assert.doesNotMatch(result.systemPrompt, /DEEPSEEK-V4-SUPERPOWER/);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("does not modify prompt for non-DeepSeek models", () => {
|
|
228
|
+
setSettings({ superpower: true });
|
|
229
|
+
const { fire, ctx } = createFakePi(["read"]);
|
|
230
|
+
const result = fire("before_agent_start", { systemPrompt: "base prompt", systemPromptOptions: { selectedTools: ["read"] } }, ctx("gpt-5.5"));
|
|
231
|
+
assert.equal(result, undefined, "should not modify non-DeepSeek prompts");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("orders: super power → guidance → base prompt", () => {
|
|
235
|
+
setSettings({ superpower: true });
|
|
236
|
+
const { fire, ctx } = createFakePi(["read", "bash", "serena_find_symbol"]);
|
|
237
|
+
const result = fire("before_agent_start",
|
|
238
|
+
{ systemPrompt: "base prompt", systemPromptOptions: { selectedTools: ["read", "bash", "serena_find_symbol"] } },
|
|
239
|
+
ctx("deepseek-v4-flash"));
|
|
240
|
+
assert.ok(result);
|
|
241
|
+
const sys = result.systemPrompt;
|
|
242
|
+
const spIdx = sys.indexOf("DEEPSEEK-V4-SUPERPOWER");
|
|
243
|
+
const guidanceIdx = sys.indexOf("DeepSeek V4 — pick the right tool");
|
|
244
|
+
const baseIdx = sys.indexOf("base prompt");
|
|
245
|
+
assert.ok(spIdx >= 0 && guidanceIdx >= 0 && baseIdx >= 0);
|
|
246
|
+
assert.ok(spIdx < guidanceIdx, "super power before guidance");
|
|
247
|
+
assert.ok(guidanceIdx < baseIdx, "guidance before base prompt");
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("selection guidance row", () => {
|
|
252
|
+
it("off → no DeepSeek routing table in the system prompt", () => {
|
|
253
|
+
setSettings({ selectionGuidance: false });
|
|
254
|
+
const { fire, ctx } = createFakePi(["read", "bash"]);
|
|
255
|
+
const result = fire("before_agent_start", { systemPrompt: "base", systemPromptOptions: { selectedTools: ["read", "bash"] } }, ctx("deepseek-v4-flash"));
|
|
256
|
+
assert.equal(result, undefined, "nothing to add once guidance is off (no apply_patch active)");
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe("first-tool hints row", () => {
|
|
261
|
+
it("off → the run-task hint is never injected", () => {
|
|
262
|
+
setSettings({ firstToolHints: false });
|
|
263
|
+
const { fire, ctx } = createFakePi(["bash", "read", "find"]);
|
|
264
|
+
fire("before_agent_start", { systemPrompt: "base", systemPromptOptions: { selectedTools: ["bash", "read", "find"] }, prompt: "Run the unit tests." }, ctx("deepseek-v4-flash"));
|
|
265
|
+
const result = fire("before_provider_request", { payload: { messages: [{ role: "user", content: "Run the unit tests." }] } }, ctx("deepseek-v4-flash"));
|
|
266
|
+
assert.equal(result, undefined, "hints disabled → payload untouched");
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe("cache-stable system prompt (deterministic active-tools source)", () => {
|
|
271
|
+
it("produces byte-identical system prompt whether or not the host populates selectedTools", () => {
|
|
272
|
+
setSettings({ superpower: true });
|
|
273
|
+
const { fire, ctx } = createFakePi(["read", "bash", "serena_find_symbol"]);
|
|
274
|
+
const c = ctx("deepseek-v4-flash");
|
|
275
|
+
// Turn A: host populates selectedTools.
|
|
276
|
+
const withSelected = fire("before_agent_start",
|
|
277
|
+
{ systemPrompt: "base prompt", systemPromptOptions: { selectedTools: ["read", "bash", "serena_find_symbol"] }, prompt: "hi" }, c);
|
|
278
|
+
// Turn B: host omits selectedTools → falls back to pi.getActiveTools().
|
|
279
|
+
const withoutSelected = fire("before_agent_start",
|
|
280
|
+
{ systemPrompt: "base prompt", systemPromptOptions: { selectedTools: undefined }, prompt: "hi" }, c);
|
|
281
|
+
assert.ok(withSelected, "system prompt should be modified");
|
|
282
|
+
assert.ok(withoutSelected, "system prompt should be modified");
|
|
283
|
+
assert.strictEqual(withSelected.systemPrompt, withoutSelected.systemPrompt,
|
|
284
|
+
"same active tools must yield byte-identical system prompt (cache head)");
|
|
285
|
+
// Selection guidance must be present in BOTH (the fallback must resolve).
|
|
286
|
+
assert.match(withoutSelected.systemPrompt, /DeepSeek V4 — pick the right tool/);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("pendingGuidance lifecycle (first provider round of a turn only)", () => {
|
|
291
|
+
it("injects on round 1, never again once the model has produced output", () => {
|
|
292
|
+
const { fire, ctx } = createFakePi(["bash", "read", "find"]);
|
|
293
|
+
const c = ctx("deepseek-v4-flash");
|
|
294
|
+
// before_agent_start with a run-task prompt → bash-first hint fires.
|
|
295
|
+
const beforeStart = fire("before_agent_start",
|
|
296
|
+
{ systemPrompt: "base", systemPromptOptions: { selectedTools: ["bash", "read", "find"] }, prompt: "Run the unit tests." }, c);
|
|
297
|
+
assert.ok(beforeStart, "DeepSeek still gets the static selection guidance");
|
|
298
|
+
// The DYNAMIC run-task hint must NOT be in the system prompt (cache head).
|
|
299
|
+
assert.doesNotMatch(beforeStart.systemPrompt, /FIRST tool call MUST be bash/i);
|
|
300
|
+
|
|
301
|
+
// Round 1 of the turn (first provider call): guidance appended.
|
|
302
|
+
const payload1 = { messages: [{ role: "user", content: "Run the unit tests." }] };
|
|
303
|
+
const r1 = fire("before_provider_request", { payload: payload1 }, c);
|
|
304
|
+
assert.ok(r1, "first provider round receives the guidance");
|
|
305
|
+
assert.match(r1.messages[0].content, /FIRST tool call MUST be bash/i);
|
|
306
|
+
|
|
307
|
+
// Round 1 of a LATER turn in the same session: the payload carries prior
|
|
308
|
+
// assistant history, but the tail is the new plain user prompt → the hint
|
|
309
|
+
// MUST still fire (gate is tail-based, not any-assistant-message-based).
|
|
310
|
+
const payloadMulti = { messages: [
|
|
311
|
+
{ role: "user", content: "Run the unit tests." },
|
|
312
|
+
{ role: "assistant", content: "done" },
|
|
313
|
+
{ role: "user", content: "Execute the build now." },
|
|
314
|
+
] };
|
|
315
|
+
const rMulti = fire("before_provider_request", { payload: payloadMulti }, c);
|
|
316
|
+
assert.ok(rMulti, "later-turn round 1 with plain-prompt tail still gets guidance");
|
|
317
|
+
assert.match(rMulti.messages[2].content, /FIRST tool call MUST be bash/i);
|
|
318
|
+
assert.doesNotMatch(rMulti.messages[0].content, /FIRST tool call MUST be bash/i, "prior turns stay guidance-free");
|
|
319
|
+
|
|
320
|
+
// Round 2, OpenAI-style payload (tool results are role "tool"): the hint
|
|
321
|
+
// must NOT be re-appended — re-injecting after the model has complied reads
|
|
322
|
+
// as a repeated demand and loops strict models into re-running bash.
|
|
323
|
+
const payload2 = { messages: [
|
|
324
|
+
{ role: "user", content: "Run the unit tests." },
|
|
325
|
+
{ role: "assistant", content: "", tool_calls: [{ function: { name: "bash", arguments: "{}" } }] },
|
|
326
|
+
{ role: "tool", content: "ok", name: "bash" },
|
|
327
|
+
] };
|
|
328
|
+
const r2 = fire("before_provider_request", { payload: payload2 }, c);
|
|
329
|
+
assert.equal(r2, undefined, "round 2 (OpenAI-style) gets no guidance re-injection");
|
|
330
|
+
|
|
331
|
+
// Round 2, anthropic-style payload (tool results live in a user message):
|
|
332
|
+
// the last user message is the tool-result container — the hint must still
|
|
333
|
+
// not be appended after it.
|
|
334
|
+
const payload2a = { messages: [
|
|
335
|
+
{ role: "user", content: "Run the unit tests." },
|
|
336
|
+
{ role: "assistant", content: [{ type: "tool_use", id: "t1", name: "bash", input: {} }] },
|
|
337
|
+
{ role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: "ok" }] },
|
|
338
|
+
] };
|
|
339
|
+
const r2a = fire("before_provider_request", { payload: payload2a }, c);
|
|
340
|
+
assert.equal(r2a, undefined, "round 2 (anthropic-style) gets no guidance re-injection");
|
|
341
|
+
|
|
342
|
+
// A NEW turn (before_agent_start fires again with a non-matching prompt) must
|
|
343
|
+
// clear pendingGuidance so it does not leak into the next turn.
|
|
344
|
+
fire("before_agent_start", { systemPrompt: "base", systemPromptOptions: { selectedTools: ["bash", "read", "find"] }, prompt: "hello" }, c);
|
|
345
|
+
const payload3 = { messages: [{ role: "user", content: "hello" }] };
|
|
346
|
+
const r3 = fire("before_provider_request", { payload: payload3 }, c);
|
|
347
|
+
assert.equal(r3, undefined, "new turn with no dynamic guidance leaves payload untouched");
|
|
348
|
+
|
|
349
|
+
// A new matching turn re-arms the hint for ITS round 1.
|
|
350
|
+
const beforeStart3 = fire("before_agent_start",
|
|
351
|
+
{ systemPrompt: "base", systemPromptOptions: { selectedTools: ["bash", "read", "find"] }, prompt: "Execute the lint step." }, c);
|
|
352
|
+
assert.ok(beforeStart3);
|
|
353
|
+
const payload4 = { messages: [{ role: "user", content: "Execute the lint step." }] };
|
|
354
|
+
const r4 = fire("before_provider_request", { payload: payload4 }, c);
|
|
355
|
+
assert.ok(r4, "a new matching turn gets guidance on its own round 1");
|
|
356
|
+
});
|
|
357
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Fake-pi harness for the steering lifecycle tests (adapted from
|
|
2
|
+
// pi-model-tools' ds-anchor-wiring / cache-stats / guidance harnesses): the
|
|
3
|
+
// module's handlers are collected off a stub ExtensionAPI and fired directly
|
|
4
|
+
// with synthetic events, so the returned results can be asserted on.
|
|
5
|
+
|
|
6
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import steeringModule from "../index.js";
|
|
10
|
+
|
|
11
|
+
type Hook = (event: any, ctx: any) => any;
|
|
12
|
+
|
|
13
|
+
/** Point the `steering` settings reads at a throwaway agent dir, so the tests
|
|
14
|
+
* never see the developer's real ~/.pi/agent/settings.json. Call from
|
|
15
|
+
* before()/after() with the returned restore(). */
|
|
16
|
+
export function isolateAgentDir(prefix = "ceulen-steering-test-"): { dir: string; restore: () => void } {
|
|
17
|
+
const real = process.env.PI_CODING_AGENT_DIR;
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), prefix));
|
|
19
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
20
|
+
return {
|
|
21
|
+
dir,
|
|
22
|
+
restore: () => {
|
|
23
|
+
if (real === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
24
|
+
else process.env.PI_CODING_AGENT_DIR = real;
|
|
25
|
+
rmSync(dir, { recursive: true, force: true });
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Write a `steering` settings section into the isolated agent dir — the next
|
|
31
|
+
* turn (before_agent_start) picks it up. */
|
|
32
|
+
export function setSteeringSettings(dir: string, steering: Record<string, unknown>): void {
|
|
33
|
+
writeFileSync(join(dir, "settings.json"), JSON.stringify({ steering }, null, 2));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface FakePi {
|
|
37
|
+
fire: (name: string, event: any, ctx: any) => any;
|
|
38
|
+
ctx: (id: string, extra?: Record<string, unknown>) => any;
|
|
39
|
+
status: (ctx: any) => string;
|
|
40
|
+
setEntries: (entries: any[]) => void;
|
|
41
|
+
/** Messages the module steered into the session (reminders). */
|
|
42
|
+
messages: Array<{ message: any; options: any }>;
|
|
43
|
+
commands: Record<string, any>;
|
|
44
|
+
notifications: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createFakePi(activeTools: string[] = ["bash", "read", "edit", "grep", "str_replace_editor"]): FakePi {
|
|
48
|
+
const hooks = new Map<string, Hook[]>();
|
|
49
|
+
const commands: Record<string, any> = {};
|
|
50
|
+
const messages: Array<{ message: any; options: any }> = [];
|
|
51
|
+
const notifications: string[] = [];
|
|
52
|
+
let entries: any[] = [];
|
|
53
|
+
|
|
54
|
+
const pi: any = {
|
|
55
|
+
registerCommand: (name: string, def: any) => { commands[name] = def; },
|
|
56
|
+
on: (name: string, fn: Hook) => { (hooks.get(name) ?? hooks.set(name, []).get(name)!).push(fn); },
|
|
57
|
+
getActiveTools: () => activeTools,
|
|
58
|
+
getAllTools: () => activeTools.map((name) => ({ name })),
|
|
59
|
+
sendMessage: (message: any, options: any) => { messages.push({ message, options }); },
|
|
60
|
+
};
|
|
61
|
+
steeringModule(pi);
|
|
62
|
+
|
|
63
|
+
const fire = (name: string, event: any, ctx: any) => {
|
|
64
|
+
let last: any;
|
|
65
|
+
for (const handler of hooks.get(name) ?? []) last = handler(event, ctx) ?? last;
|
|
66
|
+
return last;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const ctx = (id: string, extra: Record<string, unknown> = {}): any => ({
|
|
70
|
+
model: { id, provider: "test" },
|
|
71
|
+
cwd: "/tmp",
|
|
72
|
+
isProjectTrusted: () => false,
|
|
73
|
+
sessionManager: { getEntries: () => entries },
|
|
74
|
+
ui: { notify: (message: string) => { notifications.push(message); } },
|
|
75
|
+
...extra,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const status = (c: any): string => {
|
|
79
|
+
let text = "";
|
|
80
|
+
commands.steering.handler({}, { model: c.model, cwd: c.cwd, ui: { notify: (t: string) => { text = t; } } });
|
|
81
|
+
return text;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
fire,
|
|
86
|
+
ctx,
|
|
87
|
+
status,
|
|
88
|
+
setEntries: (e: any[]) => { entries = e; },
|
|
89
|
+
messages,
|
|
90
|
+
commands,
|
|
91
|
+
notifications,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Ported from pi-model-tools extensions/test/unit/reasoning-content.test.ts.
|
|
2
|
+
// Local change: the PI_MODEL_TOOLS_REASONING_MAX_CHARS env knob is passed as
|
|
3
|
+
// stripReasoningContent's second argument.
|
|
4
|
+
import assert from "node:assert";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import { stripReasoningContent, cleanLeakedContent, cleanLeakedContentFromMessages, appendGuidanceToLastUserMessage } from "../lib/history.js";
|
|
7
|
+
|
|
8
|
+
describe("cleanLeakedContent", () => {
|
|
9
|
+
it("strips Reasoning: header", () => {
|
|
10
|
+
assert.strictEqual(cleanLeakedContent("Reasoning: thinking...\nAnswer", new Set(["read"])), "Answer");
|
|
11
|
+
});
|
|
12
|
+
it("strips backtick tool calls matching active tools", () => {
|
|
13
|
+
assert.strictEqual(cleanLeakedContent("Use `grep(\"x\")` now", new Set(["grep"])), "Use now");
|
|
14
|
+
});
|
|
15
|
+
it("does NOT strip non-matching calls", () => {
|
|
16
|
+
const c = "Using `random()` here";
|
|
17
|
+
assert.strictEqual(cleanLeakedContent(c, new Set(["grep"])), c);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("cleanLeakedContentFromMessages", () => {
|
|
22
|
+
it("cleans leaked content from assistant messages", () => {
|
|
23
|
+
const payload = { messages: [
|
|
24
|
+
{ role: "user", content: "find it" },
|
|
25
|
+
{ role: "assistant", content: "Reasoning: ...\nI'll `grep(\"x\")` now" },
|
|
26
|
+
]};
|
|
27
|
+
const result = cleanLeakedContentFromMessages(payload, ["grep"]) as any;
|
|
28
|
+
assert.ok(!result.messages[1].content.includes("Reasoning"));
|
|
29
|
+
assert.ok(!result.messages[1].content.includes("`grep"));
|
|
30
|
+
});
|
|
31
|
+
it("returns original when no changes needed", () => {
|
|
32
|
+
const payload = { messages: [{ role: "user", content: "hello" }] };
|
|
33
|
+
assert.strictEqual(cleanLeakedContentFromMessages(payload, []), payload);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("stripReasoningContent", () => {
|
|
38
|
+
it("strips reasoning from ALL assistant messages uniformly (cache-stable)", () => {
|
|
39
|
+
const payload = { messages: [
|
|
40
|
+
{ role: "assistant", content: "old", reasoning_content: "old reasoning" },
|
|
41
|
+
{ role: "user", content: "q" },
|
|
42
|
+
{ role: "assistant", content: "new", reasoning_content: "current" },
|
|
43
|
+
]};
|
|
44
|
+
const result = stripReasoningContent(payload) as any;
|
|
45
|
+
assert.strictEqual(result.messages[0].reasoning_content, "");
|
|
46
|
+
assert.strictEqual(result.messages[2].reasoning_content, "");
|
|
47
|
+
});
|
|
48
|
+
it("a given message's reasoning is stripped identically as the array grows (byte-stable across turns)", () => {
|
|
49
|
+
// Turn N: A1 is the last assistant → stripped.
|
|
50
|
+
const turnN = stripReasoningContent({ messages: [
|
|
51
|
+
{ role: "user", content: "q1" },
|
|
52
|
+
{ role: "assistant", content: "a1", reasoning_content: "think1" },
|
|
53
|
+
]}) as any;
|
|
54
|
+
// Turn N+1: A1 is now a PRIOR assistant → must produce the same bytes.
|
|
55
|
+
const turnN1 = stripReasoningContent({ messages: [
|
|
56
|
+
{ role: "user", content: "q1" },
|
|
57
|
+
{ role: "assistant", content: "a1", reasoning_content: "think1" },
|
|
58
|
+
{ role: "user", content: "q2" },
|
|
59
|
+
{ role: "assistant", content: "a2", reasoning_content: "think2" },
|
|
60
|
+
]}) as any;
|
|
61
|
+
assert.strictEqual(turnN.messages[1].reasoning_content, "");
|
|
62
|
+
assert.strictEqual(turnN1.messages[1].reasoning_content, "");
|
|
63
|
+
// Byte-identical serialization of message A1 in both calls.
|
|
64
|
+
assert.strictEqual(JSON.stringify(turnN.messages[1]), JSON.stringify(turnN1.messages[1]));
|
|
65
|
+
});
|
|
66
|
+
it("returns original when no assistant messages", () => {
|
|
67
|
+
const payload = { messages: [{ role: "user", content: "hi" }] };
|
|
68
|
+
assert.strictEqual(stripReasoningContent(payload), payload);
|
|
69
|
+
});
|
|
70
|
+
it("truncates long reasoning to N CHARS (not tokens) when a budget is given", () => {
|
|
71
|
+
const long = "x".repeat(100);
|
|
72
|
+
const result = stripReasoningContent({ messages: [
|
|
73
|
+
{ role: "assistant", content: "a", reasoning_content: long },
|
|
74
|
+
] }, 50) as any;
|
|
75
|
+
assert.ok(result.messages[0].reasoning_content.length < 100, "should be truncated");
|
|
76
|
+
assert.match(result.messages[0].reasoning_content, /\[reasoning truncated\]$/);
|
|
77
|
+
assert.strictEqual(result.messages[0].reasoning_content.length, 50 + "\n\n[reasoning truncated]".length);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("appendGuidanceToLastUserMessage", () => {
|
|
82
|
+
it("appends guidance to the last user message (string content)", () => {
|
|
83
|
+
const payload = { messages: [
|
|
84
|
+
{ role: "user", content: "first" },
|
|
85
|
+
{ role: "assistant", content: "ok" },
|
|
86
|
+
{ role: "user", content: "current prompt" },
|
|
87
|
+
]};
|
|
88
|
+
const result = appendGuidanceToLastUserMessage(payload, "GUIDE TEXT") as any;
|
|
89
|
+
assert.match(result.messages[2].content, /^current prompt\n\nGUIDE TEXT$/);
|
|
90
|
+
assert.strictEqual(result.messages[0].content, "first"); // untouched
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("appends to the last text part when content is an array", () => {
|
|
94
|
+
const payload = { messages: [
|
|
95
|
+
{ role: "user", content: [{ type: "text", text: "hello" }] },
|
|
96
|
+
]};
|
|
97
|
+
const result = appendGuidanceToLastUserMessage(payload, "GUIDE") as any;
|
|
98
|
+
assert.strictEqual(result.messages[0].content[0].text, "hello\n\nGUIDE");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("adds a text part when the array has no text part", () => {
|
|
102
|
+
const payload = { messages: [
|
|
103
|
+
{ role: "user", content: [{ type: "image", image: "x" }] },
|
|
104
|
+
]};
|
|
105
|
+
const result = appendGuidanceToLastUserMessage(payload, "GUIDE") as any;
|
|
106
|
+
assert.strictEqual(result.messages[0].content[1].text, "GUIDE");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("returns the original payload when no user message exists", () => {
|
|
110
|
+
const payload = { messages: [{ role: "assistant", content: "hi" }] };
|
|
111
|
+
assert.strictEqual(appendGuidanceToLastUserMessage(payload, "GUIDE"), payload);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("returns the original payload when there is no messages array", () => {
|
|
115
|
+
const payload = { system: "only" };
|
|
116
|
+
assert.strictEqual(appendGuidanceToLastUserMessage(payload, "GUIDE"), payload);
|
|
117
|
+
});
|
|
118
|
+
});
|