ceulen 0.5.1 → 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,167 @@
|
|
|
1
|
+
// repair settings layering + the /config row contract.
|
|
2
|
+
//
|
|
3
|
+
// The agent dir is redirected via PI_CODING_AGENT_DIR (read at call time by
|
|
4
|
+
// lib/settings.ts), so the tests never touch the real ~/.pi/agent file.
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { after, beforeEach, describe, it } from "node:test";
|
|
7
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_REPAIR_SETTINGS,
|
|
13
|
+
projectShadow,
|
|
14
|
+
readRepairSettings,
|
|
15
|
+
settingsPath,
|
|
16
|
+
writeRepairSection,
|
|
17
|
+
type RepairSettings,
|
|
18
|
+
} from "../lib/settings.js";
|
|
19
|
+
import { buildRepairGroups } from "../configPanel.js";
|
|
20
|
+
|
|
21
|
+
const dirs: string[] = [];
|
|
22
|
+
let agentDir: string;
|
|
23
|
+
let cwd: string;
|
|
24
|
+
const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
25
|
+
|
|
26
|
+
async function tempDir(): Promise<string> {
|
|
27
|
+
const dir = await mkdtemp(join(tmpdir(), "repair-settings-"));
|
|
28
|
+
dirs.push(dir);
|
|
29
|
+
return dir;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function trustedCtx(cwdPath: string, trusted = true): ExtensionContext {
|
|
33
|
+
return { cwd: cwdPath, isProjectTrusted: () => trusted } as unknown as ExtensionContext;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
agentDir = await tempDir();
|
|
38
|
+
cwd = await tempDir();
|
|
39
|
+
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
after(async () => {
|
|
43
|
+
if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
44
|
+
else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
|
|
45
|
+
await Promise.all(dirs.map((d) => rm(d, { recursive: true, force: true })));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function writeGlobal(repair: unknown): Promise<void> {
|
|
49
|
+
await writeFile(settingsPath(), JSON.stringify({ repair }, null, 2) + "\n");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function writeProject(cwdPath: string, repair: unknown): Promise<void> {
|
|
53
|
+
await mkdir(join(cwdPath, ".pi"), { recursive: true });
|
|
54
|
+
await writeFile(join(cwdPath, ".pi", "settings.json"), JSON.stringify({ repair }, null, 2) + "\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("readRepairSettings", () => {
|
|
58
|
+
it("defaults: repair on, guards on, autoBg off @120s", () => {
|
|
59
|
+
assert.deepEqual(readRepairSettings(trustedCtx(cwd)), DEFAULT_REPAIR_SETTINGS);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("reads the global agent-dir `repair` section", async () => {
|
|
63
|
+
await writeGlobal({ arguments: false, autoBg: true, autoBgSecs: 30 });
|
|
64
|
+
const s = readRepairSettings(trustedCtx(cwd));
|
|
65
|
+
assert.equal(s.arguments, false);
|
|
66
|
+
assert.equal(s.autoBg, true);
|
|
67
|
+
assert.equal(s.autoBgSecs, 30);
|
|
68
|
+
assert.equal(s.guards, true, "untouched keys keep the default");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("trusted project file overrides the global layer field-wise", async () => {
|
|
72
|
+
await writeGlobal({ guards: false, autoBgSecs: 30 });
|
|
73
|
+
await writeProject(cwd, { guards: true, autoBgSecs: 45, autoBg: true });
|
|
74
|
+
const s = readRepairSettings(trustedCtx(cwd));
|
|
75
|
+
assert.equal(s.guards, true, "project wins");
|
|
76
|
+
assert.equal(s.autoBgSecs, 45, "project wins");
|
|
77
|
+
assert.equal(s.autoBg, true, "project-only key");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("an UNTRUSTED project file is ignored entirely", async () => {
|
|
81
|
+
await writeGlobal({ guards: false });
|
|
82
|
+
await writeProject(cwd, { guards: true, autoBg: true });
|
|
83
|
+
const s = readRepairSettings(trustedCtx(cwd, false));
|
|
84
|
+
assert.equal(s.guards, false, "global value survives an untrusted project");
|
|
85
|
+
assert.equal(s.autoBg, false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("clamps autoBgSecs: fractional floors to ≥1, garbage falls back", async () => {
|
|
89
|
+
await writeGlobal({ autoBgSecs: 0.5 });
|
|
90
|
+
assert.equal(readRepairSettings(trustedCtx(cwd)).autoBgSecs, 1, "0.5 → floor 0 → clamped to 1");
|
|
91
|
+
await writeGlobal({ autoBgSecs: -10 });
|
|
92
|
+
assert.equal(readRepairSettings(trustedCtx(cwd)).autoBgSecs, 1);
|
|
93
|
+
await writeGlobal({ autoBgSecs: "abc" });
|
|
94
|
+
assert.equal(readRepairSettings(trustedCtx(cwd)).autoBgSecs, 120, "non-number → default");
|
|
95
|
+
await writeGlobal({ autoBgSecs: 30.9 });
|
|
96
|
+
assert.equal(readRepairSettings(trustedCtx(cwd)).autoBgSecs, 30);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("ignores wrong-typed booleans and a corrupt file", async () => {
|
|
100
|
+
await writeGlobal({ arguments: "yes", guards: 0 });
|
|
101
|
+
let s = readRepairSettings(trustedCtx(cwd));
|
|
102
|
+
assert.equal(s.arguments, true);
|
|
103
|
+
assert.equal(s.guards, true);
|
|
104
|
+
await writeFile(settingsPath(), "{ not json");
|
|
105
|
+
s = readRepairSettings(trustedCtx(cwd));
|
|
106
|
+
assert.deepEqual(s, DEFAULT_REPAIR_SETTINGS);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("writeRepairSection", () => {
|
|
111
|
+
it("merges into an existing settings file without dropping other sections", async () => {
|
|
112
|
+
await writeFile(settingsPath(), JSON.stringify({ router: { baseUrl: "http://x" }, repair: { guards: false } }));
|
|
113
|
+
const file = writeRepairSection({ autoBg: true, autoBgSecs: 15 });
|
|
114
|
+
const json = JSON.parse(await readFile(file, "utf8"));
|
|
115
|
+
assert.deepEqual(json.router, { baseUrl: "http://x" });
|
|
116
|
+
assert.deepEqual(json.repair, { guards: false, autoBg: true, autoBgSecs: 15 });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("creates the file when missing and refuses to clobber corrupt JSON", async () => {
|
|
120
|
+
writeRepairSection({ arguments: false });
|
|
121
|
+
assert.equal(JSON.parse(await readFile(settingsPath(), "utf8")).repair.arguments, false);
|
|
122
|
+
await writeFile(settingsPath(), "{ broken");
|
|
123
|
+
assert.throws(() => writeRepairSection({ guards: false }), /not valid JSON/);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("projectShadow", () => {
|
|
128
|
+
it("reports only a TRUSTED project file that carries a repair section", async () => {
|
|
129
|
+
assert.equal(projectShadow(cwd, true), false);
|
|
130
|
+
await writeProject(cwd, { guards: false });
|
|
131
|
+
assert.equal(projectShadow(cwd, true), true);
|
|
132
|
+
assert.equal(projectShadow(cwd, false), false, "untrusted files are ignored (and never load)");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("buildRepairGroups (panel contract)", () => {
|
|
137
|
+
it("renders the five repair.* rows on the Tools tab with the documented defaults", () => {
|
|
138
|
+
const groups = buildRepairGroups({ ...DEFAULT_REPAIR_SETTINGS });
|
|
139
|
+
assert.equal(groups.length, 1);
|
|
140
|
+
assert.equal(groups[0].tab, "Tools");
|
|
141
|
+
assert.equal(groups[0].label, "Repair");
|
|
142
|
+
const keys = groups[0].rows.map((r) => r.key);
|
|
143
|
+
assert.deepEqual(keys, [
|
|
144
|
+
"repair.arguments",
|
|
145
|
+
"repair.editRetry",
|
|
146
|
+
"repair.guards",
|
|
147
|
+
"repair.autoBg",
|
|
148
|
+
"repair.autoBgSecs",
|
|
149
|
+
]);
|
|
150
|
+
assert.ok(keys.every((k) => k.startsWith("repair.")), "row keys route back to this module");
|
|
151
|
+
const byKey = new Map(groups[0].rows.map((r) => [r.key, r]));
|
|
152
|
+
assert.equal(byKey.get("repair.autoBg")!.kind, "toggle");
|
|
153
|
+
assert.equal(byKey.get("repair.autoBg")!.value, false);
|
|
154
|
+
assert.match(String(byKey.get("repair.autoBg")!.warning), /next session/);
|
|
155
|
+
assert.equal(byKey.get("repair.autoBgSecs")!.kind, "number");
|
|
156
|
+
assert.equal(byKey.get("repair.autoBgSecs")!.value, 120);
|
|
157
|
+
// Toggles are set/get wired (Enter commits through the row's setter).
|
|
158
|
+
byKey.get("repair.guards")!.set(false);
|
|
159
|
+
assert.equal(byKey.get("repair.guards")!.value, false);
|
|
160
|
+
// The row's setter clamps into the working config (the panel kernel keeps
|
|
161
|
+
// the raw value on the row — same contract as every ceulen number row).
|
|
162
|
+
const cfg: RepairSettings = { ...DEFAULT_REPAIR_SETTINGS };
|
|
163
|
+
byKey.get("repair.autoBgSecs")!.set(45.8);
|
|
164
|
+
cfg.autoBgSecs = Math.max(1, Math.floor(Number(45.8)));
|
|
165
|
+
assert.equal(Math.floor(Number(byKey.get("repair.autoBgSecs")!.value)), 45);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Wrapper INTEGRATION test — the munin this-binding lesson: pure-function
|
|
2
|
+
// tests alone do not prove the wiring. This drives `wrapToolDefinition` around
|
|
3
|
+
// a REAL `createEditToolDefinition` (pi's own core edit tool) against a real
|
|
4
|
+
// temp file, through the full documented repair chain:
|
|
5
|
+
//
|
|
6
|
+
// prepareArguments (schema repair / read-notice decontamination)
|
|
7
|
+
// → execute → core exact-match MISMATCH
|
|
8
|
+
// → trim-tolerant retry rebuilt from the file's real bytes → SUCCESS
|
|
9
|
+
// → (unresolvable case) nearest-region + apply_patch escalation message
|
|
10
|
+
//
|
|
11
|
+
// A "faithful fake" would not catch a changed core-factory signature, a moved
|
|
12
|
+
// ctx.cwd contract, or a rewritten core error string — the real definition does.
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { after, describe, it } from "node:test";
|
|
18
|
+
import { createEditToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
19
|
+
import { wrapToolDefinition } from "../index.js";
|
|
20
|
+
|
|
21
|
+
const dirs: string[] = [];
|
|
22
|
+
const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
23
|
+
|
|
24
|
+
after(async () => {
|
|
25
|
+
if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
26
|
+
else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
|
|
27
|
+
await Promise.all(dirs.map((d) => rm(d, { recursive: true, force: true })));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// The module entry reads settings per tool call — point the agent dir at an
|
|
31
|
+
// empty temp dir so these tests never read the developer's real settings.json.
|
|
32
|
+
async function tempDir(): Promise<string> {
|
|
33
|
+
const dir = await mkdtemp(join(tmpdir(), "repair-wrapper-"));
|
|
34
|
+
dirs.push(dir);
|
|
35
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
36
|
+
return dir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeWrapped(
|
|
40
|
+
onRepair: (tool: string, kinds: readonly string[]) => void,
|
|
41
|
+
counts = new Map<string, number>(),
|
|
42
|
+
active: string[] = ["apply_patch"],
|
|
43
|
+
) {
|
|
44
|
+
// factory = the REAL core tool factory: execute() re-creates the definition
|
|
45
|
+
// from ctx.cwd on every call, exactly as the module registers it.
|
|
46
|
+
return wrapToolDefinition(
|
|
47
|
+
createEditToolDefinition(process.cwd()),
|
|
48
|
+
createEditToolDefinition,
|
|
49
|
+
() => true,
|
|
50
|
+
onRepair,
|
|
51
|
+
counts,
|
|
52
|
+
() => active,
|
|
53
|
+
() => true,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ctxFor = (cwd: string) => ({ cwd } as any);
|
|
58
|
+
|
|
59
|
+
describe("wrapToolDefinition × real edit tool (integration)", () => {
|
|
60
|
+
it("repairs nested snake_case aliases, then recovers an indentation mismatch via the trim-tolerant retry", async () => {
|
|
61
|
+
const dir = await tempDir();
|
|
62
|
+
await writeFile(join(dir, "a.ts"), "alpha\n indented\nomega\n", "utf-8");
|
|
63
|
+
|
|
64
|
+
const repairs: string[] = [];
|
|
65
|
+
const wrapped = makeWrapped((tool, kinds) => repairs.push(`${tool}:${kinds.join("+")}`));
|
|
66
|
+
|
|
67
|
+
// Cursor-trained payload: snake_case inside edits[], and the model dropped
|
|
68
|
+
// the file's indentation — the exact double failure this module exists for.
|
|
69
|
+
const prepared: any = wrapped.prepareArguments({
|
|
70
|
+
path: "a.ts",
|
|
71
|
+
edits: [{ old_text: "alpha\nindented", new_text: "alpha\n INDENTED" }],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
assert.equal(prepared.edits[0].oldText, "alpha\nindented", "schema repair renamed old_text");
|
|
75
|
+
assert.equal(prepared.edits[0].newText, "alpha\n INDENTED", "schema repair renamed new_text");
|
|
76
|
+
assert.ok(!("old_text" in prepared.edits[0]), "alias key removed");
|
|
77
|
+
assert.ok(repairs.some((r) => r === "edit:param-alias"), `alias repair recorded (got ${repairs.join(", ")})`);
|
|
78
|
+
|
|
79
|
+
// Relative path + ctx.cwd proves the wrapper re-creates the tool from the
|
|
80
|
+
// call's cwd (the registered template was built from process.cwd()).
|
|
81
|
+
const result: any = await wrapped.execute("t1", prepared, undefined, undefined, ctxFor(dir));
|
|
82
|
+
assert.equal(result.isError, undefined);
|
|
83
|
+
assert.equal(await readFile(join(dir, "a.ts"), "utf-8"), "alpha\n INDENTED\nomega\n");
|
|
84
|
+
assert.ok(repairs.includes("edit:trim-match-retry"), `retry recorded (got ${repairs.join(", ")})`);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("strips a read-tool contamination notice from oldText, so a contaminated copy still applies", async () => {
|
|
88
|
+
const dir = await tempDir();
|
|
89
|
+
await writeFile(join(dir, "b.ts"), "const a = 1;\nconst b = 2;\n", "utf-8");
|
|
90
|
+
|
|
91
|
+
const repairs: string[] = [];
|
|
92
|
+
const wrapped = makeWrapped((tool, kinds) => repairs.push(`${tool}:${kinds.join("+")}`));
|
|
93
|
+
|
|
94
|
+
const prepared: any = wrapped.prepareArguments({
|
|
95
|
+
path: "b.ts",
|
|
96
|
+
edits: [{
|
|
97
|
+
oldText: "const b = 2;\n\n[Showing lines 1-2 of 90. Use offset=3 to continue.]",
|
|
98
|
+
newText: "const b = 3;",
|
|
99
|
+
}],
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
assert.equal(prepared.edits[0].oldText, "const b = 2;", "notice stripped before the core match");
|
|
103
|
+
assert.ok(repairs.includes("edit:read-notice-stripped"), `decontamination recorded (got ${repairs.join(", ")})`);
|
|
104
|
+
|
|
105
|
+
const result: any = await wrapped.execute("t2", prepared, undefined, undefined, ctxFor(dir));
|
|
106
|
+
assert.equal(result.isError, undefined);
|
|
107
|
+
assert.equal(await readFile(join(dir, "b.ts"), "utf-8"), "const a = 1;\nconst b = 3;\n");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("rejects a no-op edit before any I/O", async () => {
|
|
111
|
+
const dir = await tempDir();
|
|
112
|
+
const wrapped = makeWrapped(() => {});
|
|
113
|
+
await assert.rejects(
|
|
114
|
+
() => wrapped.execute("t3", { path: "missing.ts", edits: [{ oldText: "same", newText: "same" }] }, undefined, undefined, ctxFor(dir)),
|
|
115
|
+
/edits\[0\] is a no-op/,
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("escalates an unresolvable mismatch: nearest region + apply_patch nudge, counting per file", async () => {
|
|
120
|
+
const dir = await tempDir();
|
|
121
|
+
await writeFile(join(dir, "c.ts"), "alpha\nbeta\ngamma\n", "utf-8");
|
|
122
|
+
|
|
123
|
+
const counts = new Map<string, number>();
|
|
124
|
+
const wrapped = makeWrapped(() => {}, counts);
|
|
125
|
+
|
|
126
|
+
const miss = () => wrapped.execute(
|
|
127
|
+
"t4",
|
|
128
|
+
{ path: "c.ts", edits: [{ oldText: "no such content anywhere near here", newText: "x" }] },
|
|
129
|
+
undefined,
|
|
130
|
+
undefined,
|
|
131
|
+
ctxFor(dir),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
await assert.rejects(miss, (err: Error) => {
|
|
135
|
+
assert.match(err.message, /Could not find the exact text in c\.ts/);
|
|
136
|
+
assert.match(err.message, /Nearest matching region/);
|
|
137
|
+
assert.match(err.message, /edit has failed 1× on this file\. Switch to apply_patch/);
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Second miss on the SAME file escalates the counter (per-file, per-session).
|
|
142
|
+
await assert.rejects(miss, /edit has failed 2× on this file/);
|
|
143
|
+
assert.equal(counts.size, 1, "one counter entry per file");
|
|
144
|
+
|
|
145
|
+
// A successful edit clears the escalation counter for that file.
|
|
146
|
+
const ok: any = await wrapped.execute(
|
|
147
|
+
"t5",
|
|
148
|
+
{ path: "c.ts", edits: [{ oldText: "beta", newText: "BETA" }] },
|
|
149
|
+
undefined,
|
|
150
|
+
undefined,
|
|
151
|
+
ctxFor(dir),
|
|
152
|
+
);
|
|
153
|
+
assert.equal(ok.isError, undefined);
|
|
154
|
+
assert.equal(counts.size, 0, "counter cleared after a successful edit");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("omits the apply_patch nudge when apply_patch is not an active tool", async () => {
|
|
158
|
+
const dir = await tempDir();
|
|
159
|
+
await writeFile(join(dir, "d.ts"), "alpha\n", "utf-8");
|
|
160
|
+
const wrapped = makeWrapped(() => {}, new Map(), []);
|
|
161
|
+
await assert.rejects(
|
|
162
|
+
() => wrapped.execute("t6", { path: "d.ts", edits: [{ oldText: "nowhere", newText: "x" }] }, undefined, undefined, ctxFor(dir)),
|
|
163
|
+
(err: Error) => {
|
|
164
|
+
assert.doesNotMatch(err.message, /apply_patch/);
|
|
165
|
+
return true;
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("passes the mismatch straight through when editRetry is off", async () => {
|
|
171
|
+
const dir = await tempDir();
|
|
172
|
+
await writeFile(join(dir, "e.ts"), "alpha\n", "utf-8");
|
|
173
|
+
const repairs: string[] = [];
|
|
174
|
+
const wrapped = wrapToolDefinition(
|
|
175
|
+
createEditToolDefinition(process.cwd()),
|
|
176
|
+
createEditToolDefinition,
|
|
177
|
+
() => true,
|
|
178
|
+
(tool, kinds) => repairs.push(`${tool}:${kinds.join("+")}`),
|
|
179
|
+
new Map(),
|
|
180
|
+
() => ["apply_patch"],
|
|
181
|
+
() => false, // repair.editRetry = off
|
|
182
|
+
);
|
|
183
|
+
await assert.rejects(
|
|
184
|
+
() => wrapped.execute("t7", { path: "e.ts", edits: [{ oldText: "nowhere", newText: "x" }] }, undefined, undefined, ctxFor(dir)),
|
|
185
|
+
(err: Error) => {
|
|
186
|
+
assert.doesNotMatch(err.message, /Nearest matching region|apply_patch/);
|
|
187
|
+
return true;
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
assert.ok(!repairs.includes("edit:trim-match-retry"));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("read wrapper adds the offset/limit default and appends the note to the result", async () => {
|
|
194
|
+
const dir = await tempDir();
|
|
195
|
+
await writeFile(join(dir, "f.txt"), "one\ntwo\n", "utf-8");
|
|
196
|
+
const { createReadToolDefinition } = await import("@earendil-works/pi-coding-agent");
|
|
197
|
+
const wrapped = wrapToolDefinition(
|
|
198
|
+
createReadToolDefinition(process.cwd()),
|
|
199
|
+
createReadToolDefinition,
|
|
200
|
+
() => false,
|
|
201
|
+
() => {},
|
|
202
|
+
);
|
|
203
|
+
const prepared: any = wrapped.prepareArguments({ path: "f.txt", limit: 10 });
|
|
204
|
+
assert.equal(prepared.offset, 1, "limit without offset defaults offset to 1");
|
|
205
|
+
const result: any = await wrapped.execute("t8", prepared, undefined, undefined, ctxFor(dir));
|
|
206
|
+
const texts = (result.content ?? []).map((c: any) => c.text ?? "").join("\n");
|
|
207
|
+
assert.match(texts, /defaulted to 1/);
|
|
208
|
+
assert.ok(!("__mtReadNote" in result), "note marker never leaks into the result");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -80,10 +80,14 @@ export function registerCommands(pi: ExtensionAPI): void {
|
|
|
80
80
|
const count = ctx.modelRegistry
|
|
81
81
|
.getAll()
|
|
82
82
|
.filter((m) => m.provider === PROVIDER_ID).length;
|
|
83
|
+
const classifiers = ctx.modelRegistry.getModelsOfType("classifier", PROVIDER_ID);
|
|
83
84
|
const lines = [
|
|
84
85
|
"── Router Status ──",
|
|
85
86
|
configSummary(settings),
|
|
86
87
|
`Models in catalog: ${count}`,
|
|
88
|
+
classifiers.length > 0
|
|
89
|
+
? `Classifier models: ${classifiers.length} (${classifiers.map((m) => m.id).join(", ")})`
|
|
90
|
+
: "Classifier models: 0",
|
|
87
91
|
"",
|
|
88
92
|
"Commands:",
|
|
89
93
|
" /login router Store API key (auth.json)",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import type { RouterSettings } from "./config.js";
|
|
2
3
|
|
|
3
4
|
// ── Types ────────────────────────────────────────────────────────────────────
|
|
@@ -16,6 +17,14 @@ export interface RouterModelsResponse {
|
|
|
16
17
|
data: RouterModelRaw[];
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/** System One decision model advertisement (yardmaster GET /v1/systemone/models). */
|
|
21
|
+
export interface RouterDecisionModelRaw {
|
|
22
|
+
id: string;
|
|
23
|
+
object?: string;
|
|
24
|
+
owned_by?: string;
|
|
25
|
+
family?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
/** Pi model shape with optional reasoning-level support. */
|
|
20
29
|
export type PiModel = {
|
|
21
30
|
id: string;
|
|
@@ -69,6 +78,32 @@ export async function fetchModels(
|
|
|
69
78
|
return payload.data ?? [];
|
|
70
79
|
}
|
|
71
80
|
|
|
81
|
+
/** Discover decision-model ids from a yardmaster's System One endpoint:
|
|
82
|
+
* GET {base}/v1/systemone/models. Deliberately absent on plain OmniRoute
|
|
83
|
+
* deployments (decision ids are excluded from /v1/models there too) — 404
|
|
84
|
+
* and any other failure returns [] so the chat catalog is unaffected. */
|
|
85
|
+
export async function fetchSystemoneModels(
|
|
86
|
+
config: RouterSettings,
|
|
87
|
+
signal?: AbortSignal,
|
|
88
|
+
apiKey?: string,
|
|
89
|
+
): Promise<RouterDecisionModelRaw[]> {
|
|
90
|
+
const headers: Record<string, string> = { Accept: "application/json" };
|
|
91
|
+
const key = apiKey ?? process.env.ROUTER_API_KEY ?? process.env.NINE_ROUTER_API_KEY;
|
|
92
|
+
if (key) headers.Authorization = `Bearer ${key}`;
|
|
93
|
+
// Same /v1 convention as fetchModels (never double the segment).
|
|
94
|
+
const url = /\/v1\/?$/.test(config.baseUrl)
|
|
95
|
+
? `${config.baseUrl.replace(/\/+$/, "")}/systemone/models`
|
|
96
|
+
: `${config.baseUrl}/v1/systemone/models`;
|
|
97
|
+
try {
|
|
98
|
+
const response = await fetchWithTimeout(url, { headers, signal });
|
|
99
|
+
if (!response.ok) return [];
|
|
100
|
+
const payload = (await response.json()) as RouterModelsResponse;
|
|
101
|
+
return (payload.data ?? []).filter((m) => typeof m?.id === "string" && m.id);
|
|
102
|
+
} catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
72
107
|
/** Upstreams that reject assistant turns without reasoning_content while
|
|
73
108
|
* thinking mode is on (400 "The `reasoning_content` in the thinking mode must
|
|
74
109
|
* be passed back to the API"). Verified ONLY for the ocg/ wire — pi's native
|
|
@@ -89,6 +124,11 @@ function detectThinkingFormat(modelId: string): string {
|
|
|
89
124
|
// Pattern overrides (first match wins, matching 9router's PATTERN_THINKING)
|
|
90
125
|
if (id.includes("gpt-5.6-sol")) return "openai-max"; // accepts max
|
|
91
126
|
if (id.includes("codex")) return "codex-pattern"; // cannot disable thinking
|
|
127
|
+
// The yardmaster combo backend validates the CC enum (off|low|medium|high|
|
|
128
|
+
// xhigh|max, live-probed 2026-10-03): "none"/"minimal" 400. Family detection
|
|
129
|
+
// below would file combo/deepseek-* under the deepseek-native map (off→
|
|
130
|
+
// "none") and break every off-level call — route combo/ to the enum map first.
|
|
131
|
+
if (/^combo\//.test(id)) return "cc-enum";
|
|
92
132
|
|
|
93
133
|
// Model-family detection (matching 9router's FORMAT_LEVELS keys)
|
|
94
134
|
if (id.includes("deepseek")) return "deepseek";
|
|
@@ -236,6 +276,10 @@ const FORMAT_TO_LEVEL_MAP: Record<string, Record<string, string | null>> = {
|
|
|
236
276
|
// (GLM's single thinking-on tier), max→"max"; xhigh/minimal unsupported (hidden).
|
|
237
277
|
"zai": { off:"none", minimal:null, low:"high", medium:"high", high:"high", xhigh:null, max:"max" },
|
|
238
278
|
"minimax": { off:"none", minimal:null, low:"low", medium:"medium", high:"high", xhigh:"xhigh", max:"xhigh" },
|
|
279
|
+
// Yardmaster CC-enum backends (combo/, live-probed): valid effort values are
|
|
280
|
+
// exactly off|low|medium|high|xhigh|max — "none"/"minimal" 400. "off" is
|
|
281
|
+
// honored (omitting it leaves the upstream defaulting to thinking ON).
|
|
282
|
+
"cc-enum": { off:"off", minimal:null, low:"low", medium:"medium", high:"high", xhigh:"xhigh", max:"max" },
|
|
239
283
|
};
|
|
240
284
|
|
|
241
285
|
function getThinkingLevelMap(modelId: string): Record<string, string | null> {
|
|
@@ -365,6 +409,23 @@ export function applyReasoning(model: PiModel, enableReasoning: boolean): PiMode
|
|
|
365
409
|
};
|
|
366
410
|
}
|
|
367
411
|
|
|
412
|
+
/** Decision-model entry for the provider catalog (pi's classifier model type).
|
|
413
|
+
* api is set per model — the provider-level api is chat-only. 64k context is
|
|
414
|
+
* pi-ai's catalog figure for jev; /v1/systemone/models carries no metadata. */
|
|
415
|
+
type ClassifierModelConfig = Extract<ProviderModelConfig, { type: "classifier" }>;
|
|
416
|
+
|
|
417
|
+
export function mapClassifierModel(raw: RouterDecisionModelRaw): ClassifierModelConfig {
|
|
418
|
+
return {
|
|
419
|
+
type: "classifier",
|
|
420
|
+
id: raw.id,
|
|
421
|
+
name: raw.id,
|
|
422
|
+
api: "typesafe-system-one",
|
|
423
|
+
input: ["text"],
|
|
424
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
425
|
+
contextWindow: 64_000,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
368
429
|
// ── Internal helpers ─────────────────────────────────────────────────────────
|
|
369
430
|
|
|
370
431
|
async function fetchWithTimeout(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ProviderConfig, ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { RouterSettings } from "./config.js";
|
|
3
|
-
import { fetchModels, mapModel, applyReasoning, resolveVision, type PiModel } from "./client.js";
|
|
3
|
+
import { fetchModels, fetchSystemoneModels, mapModel, mapClassifierModel, applyReasoning, resolveVision, type PiModel } from "./client.js";
|
|
4
|
+
import { systemoneClassify } from "./systemone.js";
|
|
4
5
|
|
|
5
6
|
export const PROVIDER_ID = "router";
|
|
6
7
|
|
|
@@ -95,6 +96,11 @@ export function registerProvider(pi: ExtensionAPI, settings: RouterSettings): vo
|
|
|
95
96
|
apiKey: "$ROUTER_API_KEY",
|
|
96
97
|
api: "openai-completions",
|
|
97
98
|
models: [],
|
|
99
|
+
// System One decision models (Jev) discovered on /v1/systemone/models —
|
|
100
|
+
// the classifier implementation is keyed by the models' api (see
|
|
101
|
+
// lib/systemone.ts). The composer only wires provider.classify when this
|
|
102
|
+
// map is present.
|
|
103
|
+
classifiers: { "typesafe-system-one": { classify: systemoneClassify } },
|
|
98
104
|
// SDK type says Promise<ProviderModelConfig[]>, but the composer treats a
|
|
99
105
|
// falsy return as "no change" (provider-composer.js `if (refreshed)`) —
|
|
100
106
|
// returning undefined keeps the restored list. Runtime-verified.
|
|
@@ -106,22 +112,37 @@ export function registerProvider(pi: ExtensionAPI, settings: RouterSettings): vo
|
|
|
106
112
|
|
|
107
113
|
if (!context.allowNetwork || context.signal.aborted) {
|
|
108
114
|
if (checkedAt !== undefined) lastFetchedAt = checkedAt;
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
if (!stored?.length) return undefined;
|
|
116
|
+
// Mixed persisted catalog (chat + classifier since the systemone
|
|
117
|
+
// discovery): classifier entries pass through verbatim (their
|
|
118
|
+
// baseUrl re-stamps from config in applyExtension); chat entries
|
|
119
|
+
// re-map with the current reasoning flag. Vision is re-resolved so
|
|
120
|
+
// stale persisted flags self-heal — /v1/models vision metadata lies
|
|
121
|
+
// in both directions (see client.ts VISION_OVERRIDES/VISION_DOWNGRADES)
|
|
122
|
+
// and old caches froze it verbatim.
|
|
123
|
+
return stored.map((m) =>
|
|
124
|
+
(m as { type?: string }).type === "classifier"
|
|
125
|
+
? m
|
|
126
|
+
: applyReasoning(
|
|
127
|
+
// Array.isArray guards legacy/malformed store entries (treated as text-only).
|
|
128
|
+
{ ...m, input: resolveVision(m.id, Array.isArray(m.input) && m.input.includes("image")) ? ["text", "image"] : ["text"] } as PiModel,
|
|
129
|
+
settings.enableReasoning,
|
|
130
|
+
),
|
|
131
|
+
) as unknown as ProviderModelConfig[];
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
const cred = context.credential as { type?: string; key?: string } | undefined;
|
|
122
|
-
|
|
135
|
+
// Both endpoints in parallel; a decision-endpoint failure (404 on
|
|
136
|
+
// non-yardmaster routers) degrades to a chat-only catalog.
|
|
137
|
+
const [raw, decisions] = await Promise.all([
|
|
138
|
+
fetchModels(settings, context.signal, cred?.key),
|
|
139
|
+
fetchSystemoneModels(settings, context.signal, cred?.key),
|
|
140
|
+
]);
|
|
123
141
|
if (context.signal.aborted) return undefined;
|
|
124
|
-
const models =
|
|
142
|
+
const models = [
|
|
143
|
+
...raw.map((m) => mapModel(m, settings.enableReasoning)),
|
|
144
|
+
...decisions.map(mapClassifierModel),
|
|
145
|
+
] as unknown as ProviderModelConfig[];
|
|
125
146
|
if (!models.length) return undefined; // keep restored models on empty fetch
|
|
126
147
|
lastFetchedAt = Date.now();
|
|
127
148
|
// persist entry is Model<Api>[] at runtime; our mapped shape is compatible
|