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,43 @@
|
|
|
1
|
+
// turn_end cache-stats guard (ported from pi-model-tools
|
|
2
|
+
// extensions/test/unit/cache-stats.test.ts): usage fields that are missing,
|
|
3
|
+
// undefined, or NaN must fall back to 0 — never poison the session sums or the
|
|
4
|
+
// hit-rate display.
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { after, before, describe, it } from "node:test";
|
|
7
|
+
import { createFakePi, isolateAgentDir } from "./harness.js";
|
|
8
|
+
|
|
9
|
+
let restoreAgentDir: () => void;
|
|
10
|
+
before(() => { restoreAgentDir = isolateAgentDir("ceulen-steering-cache-").restore; });
|
|
11
|
+
after(() => { restoreAgentDir(); });
|
|
12
|
+
|
|
13
|
+
function makeHarness() {
|
|
14
|
+
const h = createFakePi(["bash", "read", "edit", "str_replace_editor"]);
|
|
15
|
+
const ctx = () => h.ctx("glm-5.2");
|
|
16
|
+
const fire = (name: string, event: any) => h.fire(name, event, ctx());
|
|
17
|
+
const status = () => h.status(ctx());
|
|
18
|
+
return { fire, status };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("turn_end cache stats", () => {
|
|
22
|
+
it("missing usage fields fall back to 0 (counts as a miss turn)", () => {
|
|
23
|
+
const h = makeHarness();
|
|
24
|
+
h.fire("session_start", {});
|
|
25
|
+
h.fire("turn_end", { turnIndex: 0, message: { role: "assistant", usage: { input: 100 } }, toolResults: [] });
|
|
26
|
+
const text = h.status();
|
|
27
|
+
assert.ok(text.includes("Input: 100 · cached: 0 · written: 0"), `missing fields → zeros, got: ${text.split("Prompt cache")[1]}`);
|
|
28
|
+
assert.ok(text.includes("0 hit turns · 1 miss turns"), "no cacheRead → miss turn");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("NaN usage fields fall back to 0 (no NaN poisoning)", () => {
|
|
32
|
+
const h = makeHarness();
|
|
33
|
+
h.fire("session_start", {});
|
|
34
|
+
h.fire("turn_end", { turnIndex: 0, message: { role: "assistant", usage: { input: 50, cacheRead: NaN, cacheWrite: undefined } }, toolResults: [] });
|
|
35
|
+
h.fire("turn_end", { turnIndex: 1, message: { role: "assistant", usage: { input: NaN, cacheRead: 80, cacheWrite: "7" as unknown as number } }, toolResults: [] });
|
|
36
|
+
const text = h.status();
|
|
37
|
+
const cacheBlock = text.split("**Prompt cache (this session):**")[1] ?? "";
|
|
38
|
+
assert.ok(cacheBlock.length > 0, "cache block still shown (input > 0 survives the guard)");
|
|
39
|
+
assert.ok(!cacheBlock.includes("NaN"), `no NaN in status, got: ${cacheBlock}`);
|
|
40
|
+
assert.ok(cacheBlock.includes("Input: 50 · cached: 80 · written: 0"), `NaN fields contribute 0, got: ${cacheBlock}`);
|
|
41
|
+
assert.ok(cacheBlock.includes("1 hit turns · 1 miss turns"), "NaN cacheRead counts as miss, real cacheRead as hit");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// Ported from pi-model-tools extensions/test/unit/shell-helpers.test.ts — the
|
|
2
|
+
// steering half only (checkDangerousCommand belongs to another module).
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import {
|
|
6
|
+
isSemanticMissToolCall,
|
|
7
|
+
missedDedicatedTool,
|
|
8
|
+
dedicatedToolForShellCommand,
|
|
9
|
+
suggestBestSerenaCommand,
|
|
10
|
+
extractSymbolFromGrep,
|
|
11
|
+
categorizeToolError,
|
|
12
|
+
closestToolHint,
|
|
13
|
+
detectReasoningRejection,
|
|
14
|
+
commandLooksLikeSemanticCodeSearch,
|
|
15
|
+
} from "../lib/errors.js";
|
|
16
|
+
|
|
17
|
+
describe("semantic miss detection", () => {
|
|
18
|
+
it("does not flag reads of code files (read is the correct tool for content)", () => {
|
|
19
|
+
assert.equal(isSemanticMissToolCall("read", { path: "extensions/index.ts" }), false);
|
|
20
|
+
assert.equal(isSemanticMissToolCall("read", { path: "src/app.py?x=1" }), false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("does not flag docs, package/config files, or non-code reads", () => {
|
|
24
|
+
assert.equal(isSemanticMissToolCall("read", { path: "README.md" }), false);
|
|
25
|
+
assert.equal(isSemanticMissToolCall("read", { path: "package.json" }), false);
|
|
26
|
+
assert.equal(isSemanticMissToolCall("read", { path: ".gitignore" }), false);
|
|
27
|
+
assert.equal(isSemanticMissToolCall("read", { path: "notes.txt" }), false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("flags shell semantic code searches", () => {
|
|
31
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "rg 'function foo' src/**/*.ts" }), true);
|
|
32
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "find src -name '*.ts' -print" }), true);
|
|
33
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -R 'class User' src" }), true);
|
|
34
|
+
// Simple cat/head/tail on code files are NOT semantic misses — handled by dedicatedToolForShellCommand
|
|
35
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "cat index.ts" }), false);
|
|
36
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "head -n 10 src/main.go" }), false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("does not flag normal shell commands or non-code exact searches", () => {
|
|
40
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "ls -la" }), false);
|
|
41
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "pwd" }), false);
|
|
42
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "git status --short" }), false);
|
|
43
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "npm test" }), false);
|
|
44
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -R PI_MODEL_TOOLS README.md" }), false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("does not flag compound shell jobs (pipelines/chains) — legit shell work", () => {
|
|
48
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'sqi_manager_task' system_tasks.c | head" }), false);
|
|
49
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "cat file.txt | grep foo" }), false);
|
|
50
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep foo src | head -n 5; echo done" }), false);
|
|
51
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "ls -la; pwd" }), false);
|
|
52
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "find . -name '*.ts' | wc -l" }), false);
|
|
53
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "git status --short | grep modified" }), false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("does not flag searches in vendored SDK paths (Serena cannot index them)", () => {
|
|
57
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'sqi_manager_task' vendors/microchip/boards/curiosity_pic32mzef/system_tasks.c" }), false);
|
|
58
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'init' vendor/foo.c" }), false);
|
|
59
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "rg 'task' third_party/rtos/kernel.c" }), false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("still excludes dot-prefixed dirs (.git/.next/.cache) from steering", () => {
|
|
63
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'foo' .git/hooks/pre-commit" }), false);
|
|
64
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'foo' repo/.git/config" }), false);
|
|
65
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'foo' .next/server.ts" }), false);
|
|
66
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'foo' .cache/build.ts" }), false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("does not flag searches in node_modules or .d.ts (Serena cannot index these)", () => {
|
|
70
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'ResourceLoader' node_modules/@earendil-works/types.d.ts" }), false);
|
|
71
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -F 'ResourceLoader' dist/index.d.ts" }), false);
|
|
72
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "find node_modules -name '*.d.ts'" }), false);
|
|
73
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep 'ResourceLoader' build/output.d.ts" }), false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("does not flag quoted grep patterns (literal text search, not symbol lookup)", () => {
|
|
77
|
+
assert.equal(isSemanticMissToolCall("grep", { pattern: "'exact error string'" }), false);
|
|
78
|
+
assert.equal(isSemanticMissToolCall("grep", { pattern: "\"getSystemPromptSource\"" }), false);
|
|
79
|
+
assert.equal(isSemanticMissToolCall("grep", { pattern: "`template literal`" }), false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("still flags real symbol searches in project source", () => {
|
|
83
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "grep -rn 'class UserService' src/index.ts" }), true);
|
|
84
|
+
assert.equal(isSemanticMissToolCall("bash", { command: "rg 'function foo' src/**/*.ts" }), true);
|
|
85
|
+
assert.equal(isSemanticMissToolCall("grep", { pattern: "UserService", path: "src/index.ts" }), true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("commandLooksLikeSemanticCodeSearch ignores non-code text searches", () => {
|
|
89
|
+
assert.equal(commandLooksLikeSemanticCodeSearch("grep -R PI_MODEL_TOOLS README.md"), false);
|
|
90
|
+
assert.equal(commandLooksLikeSemanticCodeSearch(undefined), false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("dedicated tool miss detection", () => {
|
|
95
|
+
const active = ["bash", "ls", "find", "grep", "read", "write"];
|
|
96
|
+
|
|
97
|
+
it("prefers fff search tools when they are active", () => {
|
|
98
|
+
const fffActive = [...active, "ffgrep", "fffind"];
|
|
99
|
+
assert.equal(dedicatedToolForShellCommand("find src -name '*.ts'", fffActive), "fffind");
|
|
100
|
+
assert.equal(dedicatedToolForShellCommand("grep -R PI_MODEL_TOOLS README.md", fffActive), "ffgrep");
|
|
101
|
+
// plain builtins still chosen when fff tools are absent
|
|
102
|
+
assert.equal(dedicatedToolForShellCommand("find src -name '*.ts'", active), "find");
|
|
103
|
+
assert.equal(dedicatedToolForShellCommand("grep -R PI_MODEL_TOOLS README.md", active), "grep");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("maps simple shell substitutions to dedicated Pi tools", () => {
|
|
107
|
+
assert.equal(dedicatedToolForShellCommand("ls extensions", active), "ls");
|
|
108
|
+
assert.equal(dedicatedToolForShellCommand("cat README.md", active), "read");
|
|
109
|
+
assert.equal(dedicatedToolForShellCommand("head -n 5 README.md", active), "read");
|
|
110
|
+
assert.equal(dedicatedToolForShellCommand("head README.md", active), "read");
|
|
111
|
+
assert.equal(dedicatedToolForShellCommand("tail -20 README.md", active), "read");
|
|
112
|
+
assert.equal(dedicatedToolForShellCommand("sed -n '1,20p' README.md", active), undefined, "sed -n is a real command");
|
|
113
|
+
assert.equal(dedicatedToolForShellCommand("echo 'hello' > /tmp/test.md", active), "write");
|
|
114
|
+
assert.equal(dedicatedToolForShellCommand("printf 'content' > /tmp/file", active), "write");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("does not flag commands that genuinely need a shell", () => {
|
|
118
|
+
assert.equal(dedicatedToolForShellCommand("ls | wc -l", active), undefined);
|
|
119
|
+
assert.equal(dedicatedToolForShellCommand("git status --short", active), undefined);
|
|
120
|
+
assert.equal(dedicatedToolForShellCommand("npm test", active), undefined);
|
|
121
|
+
assert.equal(dedicatedToolForShellCommand("grep foo README.md && echo ok", active), undefined);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("reports missed dedicated tools for bash calls", () => {
|
|
125
|
+
assert.equal(missedDedicatedTool("bash", { command: "ls extensions" }, ["bash", "ls"]), "ls");
|
|
126
|
+
assert.equal(missedDedicatedTool("read", { path: "README.md" }, ["bash", "ls"]), undefined);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("suggestBestSerenaCommand", () => {
|
|
131
|
+
const tools = ["serena_get_symbols_overview", "serena_find_symbol", "serena_search_for_pattern"];
|
|
132
|
+
|
|
133
|
+
it("extracts symbol from grep -rn command", () => {
|
|
134
|
+
const result = suggestBestSerenaCommand({ command: "grep -rn \"wrapToolDefinition\" src/" }, tools);
|
|
135
|
+
assert.ok(result.includes("serena_find_symbol"));
|
|
136
|
+
assert.ok(result.includes("wrapToolDefinition"));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("extracts symbol from rg command", () => {
|
|
140
|
+
const result = suggestBestSerenaCommand({ command: "rg 'REASONING_FIELDS'" }, tools);
|
|
141
|
+
assert.ok(result.includes("serena_find_symbol"));
|
|
142
|
+
assert.ok(result.includes("REASONING_FIELDS"));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("extracts class search", () => {
|
|
146
|
+
const result = suggestBestSerenaCommand({ command: "grep -rn 'class UserService' src/" }, tools);
|
|
147
|
+
// 'class UserService' (with space) is not a clean symbol — falls back to overview
|
|
148
|
+
assert.ok(result.includes("serena_"));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("does not pick post-pipeline tokens as the symbol (regression: echo/head)", () => {
|
|
152
|
+
const result = suggestBestSerenaCommand({ command: "grep -rn 'sqi_manager_task' system_tasks.c | head; echo ===" }, tools);
|
|
153
|
+
// The metachar stop keeps the scan on grep's own args → picks sqi_manager_task, never echo/===
|
|
154
|
+
assert.ok(result.includes("sqi_manager_task"), `expected symbol in: ${result}`);
|
|
155
|
+
assert.ok(!result.includes("echo"), `must not suggest echo: ${result}`);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("continues past quoted tokens containing metachars (a|b is literal content)", () => {
|
|
159
|
+
// Quoted | is literal pattern content, not a shell separator. But per the
|
|
160
|
+
// "first non-flag token is the pattern" rule, a QUOTED textual pattern
|
|
161
|
+
// ("a|b") means the search is textual — no symbol is suggested after it.
|
|
162
|
+
assert.equal(extractSymbolFromGrep("rg \"a|b\" MyClass src/"), undefined, "textual quoted pattern → no symbol");
|
|
163
|
+
// A clean single-quoted pattern is still extracted, even with a quoted
|
|
164
|
+
// metachar token AFTER it (proves the m[3] stop doesn't fire on quoted |):
|
|
165
|
+
assert.equal(extractSymbolFromGrep("grep -rn 'MyClass' \"a|b\" src/"), "MyClass", "clean pattern extracted past quoted |");
|
|
166
|
+
// Unquoted | still stops the scan (post-pipeline tokens never count):
|
|
167
|
+
assert.equal(extractSymbolFromGrep("grep -rn 'MyClass' file.ts | head"), "MyClass", "unquoted | stops after grep args");
|
|
168
|
+
assert.equal(extractSymbolFromGrep("grep -rn 'MyClass' file.ts | head; echo ==="), "MyClass", "chain after pipe still extracts");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("does not suggest directory names as symbols after a textual quoted pattern", () => {
|
|
172
|
+
// "class Foo" is a textual pattern (rejected by the symbol filter); the scan
|
|
173
|
+
// must NOT fall through to trailing path args like src/app/lib.
|
|
174
|
+
const result = suggestBestSerenaCommand({ command: "grep -rn \"class Foo\" src" }, tools);
|
|
175
|
+
assert.ok(!result.includes("name_path_pattern: \"src\""), `must not suggest src as symbol: ${result}`);
|
|
176
|
+
assert.ok(!result.includes("name_path_pattern: \"app\""), `must not suggest app as symbol: ${result}`);
|
|
177
|
+
assert.ok(result.includes("serena_"), "falls back to a generic serena suggestion");
|
|
178
|
+
// Direct: the same command yields no symbol at all.
|
|
179
|
+
assert.equal(extractSymbolFromGrep("grep -rn \"class Foo\" src"), undefined);
|
|
180
|
+
// Unquoted clean pattern still extracts (no quoted-textual-pattern stop):
|
|
181
|
+
assert.equal(extractSymbolFromGrep("grep -rn MyClass src"), "MyClass");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("extracts pattern after a quoted token with metachars (find -exec grep)", () => {
|
|
185
|
+
const result = suggestBestSerenaCommand({ command: "find . -name '*.ts' -exec grep 'a|b' {} \\;" }, tools);
|
|
186
|
+
assert.ok(result.includes("serena_"), `expected serena suggestion: ${result}`);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("falls back to overview/search for unrecognized patterns", () => {
|
|
190
|
+
const result = suggestBestSerenaCommand({ command: "find src -name '*.ts' -exec grep 'something' {} \\;" }, tools);
|
|
191
|
+
assert.ok(result.includes("serena_get_symbols_overview") || result.includes("serena_search_for_pattern"));
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("handles missing/non-object input", () => {
|
|
195
|
+
assert.ok(suggestBestSerenaCommand({}, tools).includes("serena_"));
|
|
196
|
+
assert.ok(suggestBestSerenaCommand("not an object", tools).includes("serena_"));
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("categorizeToolError", () => {
|
|
201
|
+
it("classifies rate limits", () => {
|
|
202
|
+
const info = categorizeToolError("bash", { content: [{ type: "text", text: "rate limit exceeded (429)" }] });
|
|
203
|
+
assert.equal(info.category, "rate_limit");
|
|
204
|
+
assert.match(info.hint, /rate-limited/i);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("classifies edit mismatches", () => {
|
|
208
|
+
const info = categorizeToolError("edit", { content: [{ type: "text", text: "Could not find edits matching oldText" }] });
|
|
209
|
+
assert.equal(info.category, "edit_mismatch");
|
|
210
|
+
assert.match(info.hint, /exact unique matching/i);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("classifies edit mismatch even when the enriched nearest-region snippet contains 'timeout'/'429'", () => {
|
|
214
|
+
// Regression: nearestBlock appends raw file lines; before the fix these
|
|
215
|
+
// matched the rate_limit/timeout patterns first → wrong recovery hint.
|
|
216
|
+
const text = "Could not find the exact text in a.ts. The old text must match exactly.\n\nNearest matching region (lines 5-8):\nconst timeout = 5000;\nif (status === 429) { rate limit }";
|
|
217
|
+
const info = categorizeToolError("edit", { content: [{ type: "text", text }] });
|
|
218
|
+
assert.equal(info.category, "edit_mismatch");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("still classifies genuine rate_limit for non-edit tools", () => {
|
|
222
|
+
const info = categorizeToolError("bash", { content: [{ type: "text", text: "429 too many requests" }] });
|
|
223
|
+
assert.equal(info.category, "rate_limit");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("classifies path-not-found", () => {
|
|
227
|
+
const info = categorizeToolError("read", { content: [{ type: "text", text: "ENOENT: no such file or directory" }] });
|
|
228
|
+
assert.equal(info.category, "path_not_found");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("classifies unknown errors", () => {
|
|
232
|
+
const info = categorizeToolError("read", "something weird happened");
|
|
233
|
+
assert.equal(info.category, "unknown");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("suggests closest active tool on tool_not_found", () => {
|
|
237
|
+
const info = categorizeToolError("ffind", { content: [{ type: "text", text: "Tool ffind not found" }] }, ["read", "grep", "ffgrep", "find", "edit"]);
|
|
238
|
+
assert.equal(info.category, "tool_not_found");
|
|
239
|
+
assert.match(info.hint, /not active/);
|
|
240
|
+
assert.match(info.hint, /find|ffgrep/);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("falls back to generic hint when no active tool is close", () => {
|
|
244
|
+
const info = categorizeToolError("ffind", { content: [{ type: "text", text: "Tool ffind not found" }] }, ["web_search", "munin_store"]);
|
|
245
|
+
assert.equal(info.category, "tool_not_found");
|
|
246
|
+
assert.doesNotMatch(info.hint, /not active/);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("extracts missing tool from 'No such tool: X' error format", () => {
|
|
250
|
+
const info = categorizeToolError("bash", { content: [{ type: "text", text: "No such tool: edit_file" }] }, ["edit", "read", "write"]);
|
|
251
|
+
assert.equal(info.category, "tool_not_found");
|
|
252
|
+
assert.match(info.hint, /edit/);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("classifies 'Tool read_file not found' as tool_not_found, not path_not_found", () => {
|
|
256
|
+
// Branch-order regression: 'file not found' inside the tool name must not
|
|
257
|
+
// shadow the tool_not_found gate (most common hallucinated names).
|
|
258
|
+
const info = categorizeToolError("read_file", { content: [{ type: "text", text: "Tool read_file not found" }] }, ["read", "edit", "bash"]);
|
|
259
|
+
assert.equal(info.category, "tool_not_found");
|
|
260
|
+
assert.match(info.hint, /Closest available: read/);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("handles single-quoted tool names", () => {
|
|
264
|
+
const info = categorizeToolError("bash", { content: [{ type: "text", text: "Tool 'ffind' not found" }] }, ["read", "grep", "find"]);
|
|
265
|
+
assert.equal(info.category, "tool_not_found");
|
|
266
|
+
assert.match(info.hint, /not active/);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("closestToolHint ignores trivially short names", () => {
|
|
270
|
+
assert.equal(closestToolHint("e", ["edit", "read", "bash"]), undefined);
|
|
271
|
+
assert.equal(closestToolHint("ed", ["edit", "read", "bash"]), undefined);
|
|
272
|
+
assert.match(closestToolHint("read_file", ["read", "edit"]) ?? "", /read/);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe("detectReasoningRejection", () => {
|
|
277
|
+
it("detects explicit reasoning-field rejection", () => {
|
|
278
|
+
assert.equal(detectReasoningRejection("400: reasoning_content is not supported by this model"), true);
|
|
279
|
+
assert.equal(detectReasoningRejection("Unknown parameter: reasoning_content"), true);
|
|
280
|
+
assert.equal(detectReasoningRejection("reasoning fields are not allowed in assistant messages"), true);
|
|
281
|
+
});
|
|
282
|
+
it("detects content-length/token-limit overflow mentioning tokens or reasoning", () => {
|
|
283
|
+
assert.equal(detectReasoningRejection("The prompt is too long: 128000 tokens exceeds the limit"), true);
|
|
284
|
+
assert.equal(detectReasoningRejection("content exceeds maximum length of 64K characters"), true);
|
|
285
|
+
assert.equal(detectReasoningRejection("message too long, 120000 tokens"), true);
|
|
286
|
+
});
|
|
287
|
+
it("detects common OpenAI-style context-length and request-token-limit 400s", () => {
|
|
288
|
+
assert.equal(detectReasoningRejection("The request exceeds the maximum token limit of 64000"), true);
|
|
289
|
+
assert.equal(detectReasoningRejection("maximum context length is 128000 tokens"), true);
|
|
290
|
+
assert.equal(detectReasoningRejection("This model's maximum context length is 128000 tokens. However, your messages resulted in 130000 tokens"), true);
|
|
291
|
+
assert.equal(detectReasoningRejection("maximum input tokens per request exceeded"), true);
|
|
292
|
+
});
|
|
293
|
+
it("detects reasoning-block count overflows", () => {
|
|
294
|
+
assert.equal(detectReasoningRejection("The total number of reasoning_content blocks exceeds the maximum allowed"), true);
|
|
295
|
+
});
|
|
296
|
+
it("does NOT flag unrelated errors", () => {
|
|
297
|
+
assert.equal(detectReasoningRejection("rate limit exceeded (429)"), false);
|
|
298
|
+
assert.equal(detectReasoningRejection("invalid api key"), false);
|
|
299
|
+
assert.equal(detectReasoningRejection("Could not find edits matching oldText"), false);
|
|
300
|
+
assert.equal(detectReasoningRejection(""), false);
|
|
301
|
+
});
|
|
302
|
+
it("does NOT flag length errors without token/reasoning mention", () => {
|
|
303
|
+
assert.equal(detectReasoningRejection("file too long"), false);
|
|
304
|
+
assert.equal(detectReasoningRejection("output too long, truncated"), false);
|
|
305
|
+
// Regex-3 boundary: first sub-pattern matches, second (token/char/reasoning) does not.
|
|
306
|
+
assert.equal(detectReasoningRejection("input exceeds maximum size"), false);
|
|
307
|
+
assert.equal(detectReasoningRejection("message limit reached for this request"), false);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Ported from pi-model-tools extensions/test/unit/model-detection.test.ts
|
|
2
|
+
// (the detectFamily + isRecord halves; the env-helper tests moved to
|
|
3
|
+
// settings.test.ts, since those knobs are `steering` settings rows now).
|
|
4
|
+
import assert from "node:assert";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import { detectFamily, isRecord } from "../lib/family.js";
|
|
7
|
+
|
|
8
|
+
describe("detectFamily", () => {
|
|
9
|
+
const cases: Array<{ id: string; provider?: string; expected: string | null; label: string }> = [
|
|
10
|
+
// DeepSeek V4
|
|
11
|
+
{ id: "deepseek-v4-flash", provider: "opencode-go", expected: "deepseek-v4", label: "deepseek-v4-flash" },
|
|
12
|
+
{ id: "deepseek-v4-pro", provider: "opencode-go", expected: "deepseek-v4", label: "deepseek-v4-pro" },
|
|
13
|
+
{ id: "ocg/deepseek-v4-flash", provider: "9router", expected: "deepseek-v4", label: "9router deepseek" },
|
|
14
|
+
{ id: "deepseek-flash", provider: "deepseek", expected: "deepseek-v4", label: "deepseek-flash (V4.1 canonical)" },
|
|
15
|
+
{ id: "ds/deepseek-flash", provider: "router", expected: "deepseek-v4", label: "router deepseek-flash" },
|
|
16
|
+
{ id: "deepseek-v4.1-flash", provider: "opencode-go", expected: "deepseek-v4", label: "deepseek-v4.1-flash" },
|
|
17
|
+
// GLM family
|
|
18
|
+
{ id: "glm-5.2", provider: "zai-coding-cn", expected: "glm", label: "glm-5.2" },
|
|
19
|
+
{ id: "glm-4.7", provider: "zai", expected: "glm", label: "glm-4.7" },
|
|
20
|
+
{ id: "z-ai/glm-5.2", provider: "openrouter", expected: "glm", label: "openrouter glm" },
|
|
21
|
+
{ id: "glm-5-turbo", provider: "zai", expected: "glm", label: "glm-5-turbo" },
|
|
22
|
+
// Non-matching
|
|
23
|
+
{ id: "claude-opus-4.8", provider: "anthropic", expected: null, label: "claude" },
|
|
24
|
+
{ id: "gpt-5.5", provider: "openai", expected: null, label: "gpt" },
|
|
25
|
+
{ id: "deepseek-v3", provider: "deepseek", expected: null, label: "deepseek-v3 (not v4)" },
|
|
26
|
+
{ id: "deepseek-chat", provider: "deepseek", expected: null, label: "deepseek-chat (not v4)" },
|
|
27
|
+
{ id: "deepseek-r1", provider: "openrouter", expected: null, label: "deepseek-r1 (not v4)" },
|
|
28
|
+
];
|
|
29
|
+
for (const { id, provider, expected, label } of cases) {
|
|
30
|
+
it(`detects ${label} as ${expected}`, () => {
|
|
31
|
+
assert.strictEqual(detectFamily({ id, provider }), expected);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
it("returns null for empty/undefined", () => {
|
|
35
|
+
assert.strictEqual(detectFamily(undefined), null);
|
|
36
|
+
assert.strictEqual(detectFamily({}), null);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("isRecord", () => {
|
|
41
|
+
it("returns true for plain objects", () => { assert.strictEqual(isRecord({}), true); assert.strictEqual(isRecord({ a: 1 }), true); });
|
|
42
|
+
it("returns false for null, arrays, primitives", () => { assert.strictEqual(isRecord(null), false); assert.strictEqual(isRecord([]), false); assert.strictEqual(isRecord("x"), false); });
|
|
43
|
+
});
|