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,478 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
6
|
+
import { buildEvidence, createRuntime, reviewTurn, SYSTEM, type WatcherHost, type IsolatedCall } from "../lib/watcher.js";
|
|
7
|
+
import { ADVISOR_MARKER_ENV } from "../../../lib/advisor-marker.js";
|
|
8
|
+
import type { AdvisorConfig } from "../lib/config.js";
|
|
9
|
+
|
|
10
|
+
const NO_USAGE = { input: 0, output: 0, cacheRead: 0, totalTokens: 0, cost: 0 };
|
|
11
|
+
|
|
12
|
+
// Injectable fake isolated-model call — tests never hit a provider.
|
|
13
|
+
// failFrom[n] fails the nth candidate (0-based) to simulate per-model errors.
|
|
14
|
+
let reply = "";
|
|
15
|
+
let failWith: Error | undefined;
|
|
16
|
+
let calls = 0;
|
|
17
|
+
const fake: IsolatedCall = async (_ctx, models) => {
|
|
18
|
+
calls++;
|
|
19
|
+
if (failWith) throw failWith;
|
|
20
|
+
return { text: reply, model: models[0] ?? "", usage: NO_USAGE };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let host: any;
|
|
24
|
+
function makeHost(): any {
|
|
25
|
+
const h = {
|
|
26
|
+
cards: [] as any[],
|
|
27
|
+
asides: [] as any[],
|
|
28
|
+
userMessages: [] as any[],
|
|
29
|
+
notifications: [] as string[],
|
|
30
|
+
appendEntry: (customType: string, data: any) => h.cards.push({ customType, data }),
|
|
31
|
+
sendMessage: (message: { customType: string; content: string; display: boolean; details?: unknown }, options?: any) => h.asides.push({ message, options }),
|
|
32
|
+
sendUserMessage: (content: string, options?: any) => h.userMessages.push({ content, options }),
|
|
33
|
+
notify: (message: string) => h.notifications.push(message),
|
|
34
|
+
};
|
|
35
|
+
return h;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function entries(toolCalls: number, startId = 1): any[] {
|
|
39
|
+
const list: any[] = [{ type: "message", id: `m${startId}`, parentId: null, timestamp: `${startId}`, message: { role: "user", content: [{ type: "text", text: "do the thing" }], timestamp: startId } }];
|
|
40
|
+
for (let i = 0; i < toolCalls; i++) {
|
|
41
|
+
list.push({ type: "message", id: `t${startId}-${i}`, parentId: list[list.length - 1].id, timestamp: `${startId}${i}`, message: { role: "assistant", content: [{ type: "toolCall", id: `tc${startId}-${i}`, name: "read", arguments: {} }], timestamp: startId * 10 + i } });
|
|
42
|
+
list.push({ type: "message", id: `r${startId}-${i}`, parentId: `t${startId}-${i}`, timestamp: `${startId}${i}r`, message: { role: "toolResult", toolCallId: `tc${startId}-${i}`, toolName: "read", content: [{ type: "text", text: "ok" }], isError: false, timestamp: startId * 10 + i + 0.5 } });
|
|
43
|
+
}
|
|
44
|
+
list.push({ type: "message", id: `a${startId}`, parentId: list[list.length - 1].id, timestamp: `${startId}a`, message: { role: "assistant", content: [{ type: "text", text: "done" }], timestamp: startId * 10 + 9 } });
|
|
45
|
+
return list;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ctx(ents: any[], notifications?: { count: number }): any {
|
|
49
|
+
return {
|
|
50
|
+
sessionManager: {
|
|
51
|
+
getEntries: () => ents,
|
|
52
|
+
getLeafId: () => ents[ents.length - 1]?.id,
|
|
53
|
+
},
|
|
54
|
+
getSystemPrompt: () => "PRIMARY PROMPT",
|
|
55
|
+
modelRegistry: { getAvailable: () => [], find: () => ({ contextWindow: 32_768 }) },
|
|
56
|
+
ui: { notify: () => { if (notifications) notifications.count++; } },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function config(over: Partial<AdvisorConfig["watch"]> = {}): AdvisorConfig {
|
|
61
|
+
return { enabled: true, models: ["prov/reviewer", "prov/reviewer-backup"], watch: { minToolCalls: 3, immuneTurns: 3, ...over } };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function setup(toolCallCount: number, c: AdvisorConfig = config()) {
|
|
65
|
+
return { rt: createRuntime(c, c.models), e: entries(toolCallCount) };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const asHost = (h: any): WatcherHost => h;
|
|
69
|
+
|
|
70
|
+
describe("reviewTurn", () => {
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
reply = "";
|
|
73
|
+
failWith = undefined;
|
|
74
|
+
calls = 0;
|
|
75
|
+
host = makeHost();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("never reviews when no advisor model is configured (primary model must not self-review)", async () => {
|
|
79
|
+
const rt = createRuntime(config(), []);
|
|
80
|
+
await reviewTurn(rt, ctx(entries(5)), asHost(host), fake);
|
|
81
|
+
assert.equal(calls, 0);
|
|
82
|
+
assert.equal(rt.stats.reviews, 0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("records the serving model from the chain on success", async () => {
|
|
86
|
+
reply = '{"severity":"nit","note":"unused import in foo.ts"}';
|
|
87
|
+
const { rt, e } = setup(5);
|
|
88
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
89
|
+
assert.equal(rt.stats.lastModel, "prov/reviewer", "first chain entry serves and is recorded");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("accumulates usage from the serving call into the cumulative stats", async () => {
|
|
93
|
+
reply = '{"severity":"nit","note":"unused import in foo.ts"}';
|
|
94
|
+
let n = 0;
|
|
95
|
+
const withUsage: IsolatedCall = async (_ctx, models) => {
|
|
96
|
+
n++;
|
|
97
|
+
return { text: reply, model: models[0] ?? "", usage: { input: 100 * n, output: 10 * n, cacheRead: 5, totalTokens: 115 * n, cost: 0.01 * n } };
|
|
98
|
+
};
|
|
99
|
+
const { rt, e } = setup(5);
|
|
100
|
+
await reviewTurn(rt, ctx(e), asHost(host), withUsage);
|
|
101
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), withUsage);
|
|
102
|
+
assert.deepEqual(rt.stats.usage, { input: 300, output: 30, cacheRead: 10, cost: 0.03 });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("a serving call without usage data adds nothing (defensive)", async () => {
|
|
106
|
+
reply = '{"severity":"nit","note":"x"}';
|
|
107
|
+
const noUsage: IsolatedCall = async (_ctx, models) => ({ text: reply, model: models[0] ?? "", usage: undefined as never });
|
|
108
|
+
const { rt, e } = setup(5);
|
|
109
|
+
await reviewTurn(rt, ctx(e), asHost(host), noUsage);
|
|
110
|
+
assert.deepEqual(rt.stats.usage, { input: 0, output: 0, cacheRead: 0, cost: 0 });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("skips trivial turns below minToolCalls without a model call", async () => {
|
|
114
|
+
const { rt, e } = setup(2);
|
|
115
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
116
|
+
assert.equal(calls, 0);
|
|
117
|
+
assert.equal(rt.stats.skippedTrivial, 1);
|
|
118
|
+
assert.equal(rt.stats.reviews, 0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("threshold 0 reviews every turn", async () => {
|
|
122
|
+
const { rt, e } = setup(1, config({ minToolCalls: 0 }));
|
|
123
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
124
|
+
assert.equal(calls, 1);
|
|
125
|
+
assert.equal(rt.stats.reviews, 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("second distinct concern within cooldown still steers (concerns never defer)", async () => {
|
|
129
|
+
reply = '{"severity":"concern","note":"first concern about imports"}';
|
|
130
|
+
const { rt, e } = setup(5);
|
|
131
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
132
|
+
assert.equal(host.userMessages.length, 1, "first concern steers");
|
|
133
|
+
assert.equal(rt.steerCooldownTurns, 3, "steer arms the cooldown");
|
|
134
|
+
// second distinct concern arrives inside the cooldown window → still steers:
|
|
135
|
+
// concerns carry a must-address contract, only nits defer
|
|
136
|
+
reply = '{"severity":"concern","note":"second distinct concern about tests"}';
|
|
137
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
138
|
+
assert.equal(host.userMessages.length, 2, "second concern steers despite cooldown");
|
|
139
|
+
assert.equal(host.asides.length, 0, "no deferral for concerns");
|
|
140
|
+
assert.equal(host.cards.length, 0, "no deferred card for concerns");
|
|
141
|
+
assert.equal(rt.stats.concerns, 2, "still counted once per accepted note");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("second distinct nit within cooldown is deferred to a next-turn aside", async () => {
|
|
145
|
+
reply = '{"severity":"nit","note":"first nit about imports"}';
|
|
146
|
+
const { rt, e } = setup(5);
|
|
147
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
148
|
+
assert.equal(host.userMessages.length, 1, "first nit steers");
|
|
149
|
+
// second distinct nit arrives inside the cooldown window → deferred aside
|
|
150
|
+
reply = '{"severity":"nit","note":"second distinct nit about tests"}';
|
|
151
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
152
|
+
assert.equal(host.userMessages.length, 1, "no second steer while on cooldown");
|
|
153
|
+
assert.equal(host.asides.length, 1, "deferred as LLM-visible next-turn aside");
|
|
154
|
+
assert.equal(host.asides[0].options?.deliverAs, "nextTurn");
|
|
155
|
+
assert.equal(host.asides[0].message.display, false, "deferred LLM message is not displayed — the immediate card is the visible surface");
|
|
156
|
+
assert.equal(host.asides[0].message.details.deferred, true, "message details carry the deferred flag (message-renderer label parity)");
|
|
157
|
+
assert.equal(host.cards.length, 1, "deferred note gets an immediate display card");
|
|
158
|
+
assert.equal(host.cards[0].data.deferred, true, "card marked deferred");
|
|
159
|
+
assert.equal(host.cards[0].data.severity, "nit");
|
|
160
|
+
assert.equal(host.cards[0].data.timestamp, host.asides[0].message.details.timestamp, "card and message share one timestamp");
|
|
161
|
+
assert.ok(host.asides[0].message.content.includes("tests"));
|
|
162
|
+
assert.equal(rt.stats.nits, 2, "still counted once per accepted note");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("nit steers via sendUserMessage followUp (accepted notes all wake the idle agent)", async () => {
|
|
166
|
+
reply = '{"severity":"nit","note":"unused import in foo.ts"}';
|
|
167
|
+
const { rt, e } = setup(5);
|
|
168
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
169
|
+
// agent_settled is idle — there is no next step boundary, so a nit that
|
|
170
|
+
// doesn't wake the agent is never acted on. All accepted notes steer.
|
|
171
|
+
assert.equal(host.cards.length, 0);
|
|
172
|
+
assert.equal(host.asides.length, 0, "nits no longer go to a non-interrupting aside at settle");
|
|
173
|
+
assert.equal(host.userMessages.length, 1);
|
|
174
|
+
assert.equal(host.userMessages[0].options?.deliverAs, "followUp");
|
|
175
|
+
assert.ok(host.userMessages[0].content.includes("unused import in foo.ts"));
|
|
176
|
+
assert.equal(rt.stats.nits, 1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("concern steers via sendUserMessage followUp", async () => {
|
|
180
|
+
reply = '{"severity":"concern","note":"edit went to the wrong file"}';
|
|
181
|
+
const { rt, e } = setup(5);
|
|
182
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
183
|
+
assert.equal(host.userMessages.length, 1);
|
|
184
|
+
assert.equal(host.userMessages[0].options?.deliverAs, "followUp");
|
|
185
|
+
assert.ok(host.userMessages[0].content.includes("wrong file"));
|
|
186
|
+
assert.equal(rt.stats.concerns, 1);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("nit after cooldown expires steers again (cooldown recovery cycle)", async () => {
|
|
190
|
+
reply = '{"severity":"nit","note":"first nit about imports"}';
|
|
191
|
+
const { rt, e } = setup(5);
|
|
192
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
193
|
+
assert.equal(host.userMessages.length, 1);
|
|
194
|
+
assert.equal(rt.steerCooldownTurns, 3, "steer arms the cooldown (immuneTurns)");
|
|
195
|
+
// Distinct nit inside the cooldown window → deferred aside
|
|
196
|
+
reply = '{"severity":"nit","note":"second distinct nit about tests"}';
|
|
197
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
198
|
+
assert.equal(host.userMessages.length, 1, "second nit deferred while on cooldown");
|
|
199
|
+
assert.equal(host.asides.length, 1, "deferred as next-turn aside");
|
|
200
|
+
assert.equal(host.cards.length, 1, "deferred note gets an immediate display card");
|
|
201
|
+
assert.equal(rt.stats.nits, 2);
|
|
202
|
+
assert.equal(rt.steerCooldownTurns, 2, "cooldown ticks once per settled turn (deferral does not double-tick)");
|
|
203
|
+
// Two more settled turns tick the cooldown 2→1→0 → the next nit steers.
|
|
204
|
+
reply = '{"severity":"nit","note":"third distinct nit after cooldown"}';
|
|
205
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2), ...entries(4, 3)]), asHost(host), fake);
|
|
206
|
+
assert.equal(host.userMessages.length, 1, "still deferred (cooldown 1 > 0)");
|
|
207
|
+
reply = '{"severity":"nit","note":"fourth distinct nit after cooldown"}';
|
|
208
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2), ...entries(4, 3), ...entries(4, 4)]), asHost(host), fake);
|
|
209
|
+
assert.equal(host.userMessages.length, 2, "nit steers again after cooldown expired");
|
|
210
|
+
assert.equal(rt.steerCooldownTurns, 3, "steer re-arms cooldown");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("blocker steers via followUp", async () => {
|
|
214
|
+
reply = '{"severity":"concern","note":"first concern about imports"}';
|
|
215
|
+
const { rt, e } = setup(5);
|
|
216
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
217
|
+
reply = '{"severity":"blocker","note":"escalation: the migration drops data"}';
|
|
218
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
219
|
+
assert.equal(host.userMessages.length, 2, "blocker steers");
|
|
220
|
+
assert.equal(host.asides.length, 0);
|
|
221
|
+
assert.equal((host.userMessages[1].content as any).includes("(blocker"), true);
|
|
222
|
+
assert.equal(rt.stats.blockers, 1);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("duplicate note is suppressed by the guard", async () => {
|
|
226
|
+
reply = '{"severity":"nit","note":"unused import in foo.ts"}';
|
|
227
|
+
const { rt, e } = setup(5);
|
|
228
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
229
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
230
|
+
assert.equal(host.userMessages.length, 1, "identical note not repeated");
|
|
231
|
+
assert.equal(rt.guard.counts.suppressed, 1);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("empty and unparseable output are no-ops, unparseable counted", async () => {
|
|
235
|
+
const { rt, e } = setup(5);
|
|
236
|
+
reply = "";
|
|
237
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
238
|
+
assert.equal(rt.stats.reviews, 1);
|
|
239
|
+
assert.equal(rt.stats.parseFailures, 0);
|
|
240
|
+
reply = "I think everything is fine!";
|
|
241
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
242
|
+
assert.equal(rt.stats.parseFailures, 1);
|
|
243
|
+
assert.equal(host.cards.length + host.userMessages.length, 0);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("pauses after 3 consecutive model failures and notifies once", async () => {
|
|
247
|
+
failWith = new Error("boom");
|
|
248
|
+
const { rt, e } = setup(5);
|
|
249
|
+
let list = e;
|
|
250
|
+
for (let turn = 1; turn <= 4; turn++) {
|
|
251
|
+
await reviewTurn(rt, ctx(list), asHost(host), fake);
|
|
252
|
+
if (turn < 4) list = [...list, ...entries(4, turn + 1)];
|
|
253
|
+
}
|
|
254
|
+
assert.equal(rt.stats.modelFailures, 3, "third failure pauses; fourth skipped");
|
|
255
|
+
assert.equal(rt.stats.paused, true);
|
|
256
|
+
assert.equal(host.notifications.length, 1, "one pause notification via the liveness-gated host");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("resumes after enableWatch clears pause", async () => {
|
|
260
|
+
failWith = new Error("boom");
|
|
261
|
+
const { rt, e } = setup(5);
|
|
262
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
263
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
264
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2), ...entries(4, 3)]), asHost(host), fake);
|
|
265
|
+
assert.equal(rt.stats.paused, true);
|
|
266
|
+
rt.stats.paused = false; rt.failures = 0; // what enableWatch does
|
|
267
|
+
failWith = undefined;
|
|
268
|
+
reply = '{"severity":"nit","note":"fresh note after recovery"}';
|
|
269
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2), ...entries(4, 3), ...entries(4, 4)]), asHost(host), fake);
|
|
270
|
+
assert.equal(rt.stats.reviews, 1);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("cursor still advances past the failed review", async () => {
|
|
274
|
+
failWith = new Error("quota");
|
|
275
|
+
const { rt, e } = setup(5);
|
|
276
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
277
|
+
assert.equal(rt.cursor, e[e.length - 1].id);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("chain exhaustion from per-model failures counts as ONE failure per turn", async () => {
|
|
281
|
+
// Fake chain runner: both candidates fail → the chain throws once.
|
|
282
|
+
const exhausting: IsolatedCall = async () => { throw new Error("429 rate limited"); };
|
|
283
|
+
const { rt, e } = setup(5);
|
|
284
|
+
await reviewTurn(rt, ctx(e), asHost(host), exhausting);
|
|
285
|
+
assert.equal(rt.stats.modelFailures, 1, "whole-chain failure counts once");
|
|
286
|
+
assert.equal(rt.stats.paused, false, "single turn failure does not pause");
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("cursor semantics", () => {
|
|
291
|
+
beforeEach(() => {
|
|
292
|
+
reply = "";
|
|
293
|
+
failWith = undefined;
|
|
294
|
+
calls = 0;
|
|
295
|
+
host = makeHost();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("counts only new tool calls since the previous review", async () => {
|
|
299
|
+
const rt = createRuntime(config({ minToolCalls: 3 }), ["prov/reviewer"]);
|
|
300
|
+
const first = entries(4);
|
|
301
|
+
await reviewTurn(rt, ctx(first), asHost(host), fake);
|
|
302
|
+
assert.equal(calls, 1);
|
|
303
|
+
const second = [...first, ...entries(1, 2)]; // only 1 new tool call
|
|
304
|
+
await reviewTurn(rt, ctx(second), asHost(host), fake);
|
|
305
|
+
assert.equal(calls, 1, "second turn below threshold — no review");
|
|
306
|
+
assert.equal(rt.stats.skippedTrivial, 1);
|
|
307
|
+
const third = [...second, ...entries(5, 3)]; // 5 new tool calls
|
|
308
|
+
await reviewTurn(rt, ctx(third), asHost(host), fake);
|
|
309
|
+
assert.equal(calls, 2);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("reviewer SYSTEM prompt matches delivery: every accepted note reaches the agent, nobody is card-only", () => {
|
|
313
|
+
// Regression: a prompt claiming some severity is "surfaced as a card / does
|
|
314
|
+
// not interrupt" would mis-calibrate the reviewer LLM against reviewTurn's
|
|
315
|
+
// delivery (steer, or deferred LLM-visible next-turn aside during cooldown).
|
|
316
|
+
// Pin the invariant: every accepted note is delivered and the agent responds.
|
|
317
|
+
assert.ok(SYSTEM.includes("Every accepted note is delivered to the primary agent and it will respond"),
|
|
318
|
+
"prompt must state every accepted note reaches the agent and it responds");
|
|
319
|
+
assert.ok(/steering/.test(SYSTEM) && /deferred to the next turn as a visible note/.test(SYSTEM),
|
|
320
|
+
"prompt must describe both steer and cooldown-deferred delivery");
|
|
321
|
+
assert.ok(!/surfaced as a card|does not interrupt/.test(SYSTEM),
|
|
322
|
+
"prompt must not claim any severity is non-interrupting / card-only");
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("reviewer SYSTEM prompt carries the omp-parity silence rules", () => {
|
|
326
|
+
// The noise classes omp's reviewer prompt bans after production incidents
|
|
327
|
+
// (#3520): restating what the agent already has, intent/ceremony advice,
|
|
328
|
+
// scope policing, unsolicited back-compat, second-guessing, partial work.
|
|
329
|
+
for (const needle of [
|
|
330
|
+
"What the agent already has", // type errors, LSP diagnostics, failed builds
|
|
331
|
+
"User intent or ceremony", // never advise seeking clarification
|
|
332
|
+
"Scope or ambition", // a large diff alone is NOT a problem
|
|
333
|
+
"Backwards compatibility", // never raise unsolicited deprecation/migration
|
|
334
|
+
"committed decisions", // never second-guess unless certain
|
|
335
|
+
"Partial in-progress work", // critique only the end state
|
|
336
|
+
]) {
|
|
337
|
+
assert.ok(SYSTEM.includes(needle), `prompt must ban the noise class: ${needle}`);
|
|
338
|
+
}
|
|
339
|
+
assert.ok(SYSTEM.includes("Cite only transcript evidence"), "notes must cite evidence");
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("buildEvidence model-ref parsing", () => {
|
|
344
|
+
it("resolves :level-suffixed refs so evidence is sized from the real context window", () => {
|
|
345
|
+
const seen: string[] = [];
|
|
346
|
+
const ctx = {
|
|
347
|
+
modelRegistry: {
|
|
348
|
+
find: (provider: string, id: string) => {
|
|
349
|
+
seen.push(`${provider}/${id}`);
|
|
350
|
+
return { contextWindow: 8192 };
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
getSystemPrompt: () => "",
|
|
354
|
+
} as never;
|
|
355
|
+
const big = { role: "user", content: [{ type: "text", text: "x".repeat(10_000) }] };
|
|
356
|
+
const messages = [big, { ...big }, { ...big }];
|
|
357
|
+
const pinned = buildEvidence(ctx, ["prov/m:high"], messages, "");
|
|
358
|
+
assert.deepEqual(seen, ["prov/m"], "suffix stripped for the registry lookup");
|
|
359
|
+
assert.equal(pinned, buildEvidence(ctx, ["prov/m"], messages, ""),
|
|
360
|
+
"identical sizing with or without the thinking pin (8192 window → smaller budget than the 32k default)");
|
|
361
|
+
assert.notEqual(pinned, buildEvidence(ctx, undefined, messages, ""),
|
|
362
|
+
"unresolvable refs fall back to the default budget — the pin must not land there");
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe("buildEvidence bounded transcript", () => {
|
|
367
|
+
// Minimal ctx: find resolves the window, getSystemPrompt feeds the reserve.
|
|
368
|
+
function evCtx(contextWindow = 32_768): any {
|
|
369
|
+
return {
|
|
370
|
+
modelRegistry: { find: () => ({ contextWindow }) },
|
|
371
|
+
getSystemPrompt: () => "",
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const msg = (role: string, text: string): any => ({ role, content: [{ type: "text", text }] });
|
|
376
|
+
|
|
377
|
+
it("truncates entries serialized above the entry limit (role preserved, marker added)", () => {
|
|
378
|
+
const big = msg("user", "x".repeat(30_000)); // 32k window → entryLimit 24576 < serialized
|
|
379
|
+
const out = JSON.parse(buildEvidence(evCtx(), undefined, [big], ""));
|
|
380
|
+
assert.equal(out.messages.length, 1, "first entry always kept");
|
|
381
|
+
assert.equal(out.omitted, 0);
|
|
382
|
+
assert.equal(out.messages[0].role, "user", "role survives truncation");
|
|
383
|
+
assert.ok(out.messages[0].content.startsWith("[Transcript entry truncated]\n"), "truncation marker present");
|
|
384
|
+
assert.ok(out.messages[0].content.length < 30_000, "content bounded below the original");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("recent window skips over-budget entries but keeps scanning older smaller ones", () => {
|
|
388
|
+
// 8k window → maxBytes 16384: two 6000-char entries fit, the third is
|
|
389
|
+
// skipped, and the small entry below it (older = later in reverse scan)
|
|
390
|
+
// still fits (continue, not break).
|
|
391
|
+
const messages = [
|
|
392
|
+
msg("user", "start"),
|
|
393
|
+
msg("user", "kept-after-skip"),
|
|
394
|
+
msg("assistant", "b".repeat(6_000)), // oldest big — skipped once budget is spent
|
|
395
|
+
msg("user", "c".repeat(6_000)),
|
|
396
|
+
msg("assistant", "d".repeat(6_000)), // pushes the window over budget
|
|
397
|
+
];
|
|
398
|
+
const out = JSON.parse(buildEvidence(evCtx(8_192), ["prov/m"], messages, ""));
|
|
399
|
+
assert.equal(out.messages.length, 4, "first + two big + small-after-skip");
|
|
400
|
+
assert.equal(out.omitted, 1, "exactly the over-budget entry is omitted");
|
|
401
|
+
const texts = out.messages.map((m: any) => m.content[0].text);
|
|
402
|
+
assert.ok(texts.includes("c".repeat(6_000)) && texts.includes("d".repeat(6_000)), "recent big entries kept");
|
|
403
|
+
assert.ok(texts.includes("kept-after-skip"), "loop continues past a skipped entry");
|
|
404
|
+
assert.ok(!texts.some((t: string) => t.includes("b".repeat(6_000))), "the over-budget entry is the omitted one");
|
|
405
|
+
assert.equal(out.messages[0].content[0].text, "start", "first entry always kept");
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// The sidecar protocol that lets a supervising parent (subagent's herdr
|
|
410
|
+
// runner) wait for the review verdict instead of collecting a draft the
|
|
411
|
+
// advisor is about to correct. Only delegated children carry the env var.
|
|
412
|
+
describe("advisor marker sidecar", () => {
|
|
413
|
+
let dir: string;
|
|
414
|
+
let file: string;
|
|
415
|
+
beforeEach(() => {
|
|
416
|
+
reply = "";
|
|
417
|
+
failWith = undefined;
|
|
418
|
+
calls = 0;
|
|
419
|
+
host = makeHost();
|
|
420
|
+
dir = mkdtempSync(join(tmpdir(), "advisor-marker-"));
|
|
421
|
+
file = join(dir, "stamp.advisor.json");
|
|
422
|
+
process.env[ADVISOR_MARKER_ENV] = file;
|
|
423
|
+
});
|
|
424
|
+
afterEach(() => {
|
|
425
|
+
delete process.env[ADVISOR_MARKER_ENV];
|
|
426
|
+
rmSync(dir, { recursive: true, force: true });
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it("publishes reviewing mid-call, then done+steered when the note wakes the child", async () => {
|
|
430
|
+
reply = '{"severity":"concern","note":"the report cites an unverified claim"}';
|
|
431
|
+
const seen: string[] = [];
|
|
432
|
+
const probe: IsolatedCall = async (_ctx, models) => {
|
|
433
|
+
seen.push(JSON.parse(readFileSync(file, "utf8")).phase);
|
|
434
|
+
return { text: reply, model: models[0] ?? "", usage: NO_USAGE };
|
|
435
|
+
};
|
|
436
|
+
const { rt, e } = setup(5);
|
|
437
|
+
await reviewTurn(rt, ctx(e), asHost(host), probe);
|
|
438
|
+
assert.deepEqual(seen, ["reviewing"], "mid-call phase is reviewing");
|
|
439
|
+
const marker = JSON.parse(readFileSync(file, "utf8"));
|
|
440
|
+
assert.equal(marker.phase, "done");
|
|
441
|
+
assert.equal(marker.steered, true);
|
|
442
|
+
assert.ok(typeof marker.at === "number", "timestamp present for freshness checks");
|
|
443
|
+
assert.equal(host.userMessages.length, 1, "the concern steered a follow-up turn");
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("publishes done without steering when the review finds nothing", async () => {
|
|
447
|
+
reply = "";
|
|
448
|
+
const { rt, e } = setup(5);
|
|
449
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
450
|
+
const marker = JSON.parse(readFileSync(file, "utf8"));
|
|
451
|
+
assert.equal(marker.phase, "done");
|
|
452
|
+
assert.equal(marker.steered, false);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it("a nit deferred by the cooldown is not a steer (the child is not woken)", async () => {
|
|
456
|
+
reply = '{"severity":"concern","note":"first concern about imports"}';
|
|
457
|
+
const { rt, e } = setup(5);
|
|
458
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
459
|
+
reply = '{"severity":"nit","note":"second, distinct naming nit"}';
|
|
460
|
+
await reviewTurn(rt, ctx([...e, ...entries(4, 2)]), asHost(host), fake);
|
|
461
|
+
const marker = JSON.parse(readFileSync(file, "utf8"));
|
|
462
|
+
assert.equal(marker.steered, false, "deferred nit is staged for the next turn, not steered");
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("skip paths publish no marker (the parent's grace poll reads that as 'collect now')", async () => {
|
|
466
|
+
const { rt, e } = setup(2); // below minToolCalls 3
|
|
467
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
468
|
+
assert.equal(existsSync(file), false);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it("writes nothing when the env var is unset (the parent's own session)", async () => {
|
|
472
|
+
delete process.env[ADVISOR_MARKER_ENV];
|
|
473
|
+
reply = '{"severity":"concern","note":"x"}';
|
|
474
|
+
const { rt, e } = setup(5);
|
|
475
|
+
await reviewTurn(rt, ctx(e), asHost(host), fake);
|
|
476
|
+
assert.equal(existsSync(file), false);
|
|
477
|
+
});
|
|
478
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// classifier's /config contribution — Model tab, Classifier (Jev) section.
|
|
2
|
+
//
|
|
3
|
+
// Rows write the global `classifier` section (see lib/settings.ts). The model
|
|
4
|
+
// menu lists the router provider's discovered decision models at open time via
|
|
5
|
+
// the module-level registry stash (extension config factories get no ctx; the
|
|
6
|
+
// session_start handler in index.ts supplies it — same pattern as router's
|
|
7
|
+
// lastCtx). Enable + tool rows are prepended by the config module automatically.
|
|
8
|
+
|
|
9
|
+
import type { ExtensionContext, ModelRegistry } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import { row, type PanelGroup } from "../../lib/panel.js";
|
|
11
|
+
import type { ModuleConfig } from "../../lib/registry.js";
|
|
12
|
+
import { getClassifierSettings, writeClassifierSection, type ClassifierSettings } from "./lib/settings.js";
|
|
13
|
+
|
|
14
|
+
/** Registry stash — set by the module's session_start (config panel opens per
|
|
15
|
+
* command, always after a session exists). */
|
|
16
|
+
let registry: ModelRegistry | undefined;
|
|
17
|
+
|
|
18
|
+
/** Test/session hook: supply the live registry for the model menu. */
|
|
19
|
+
export function setClassifierRegistry(r: ModelRegistry | undefined): void {
|
|
20
|
+
registry = r;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Build the classifier panel groups over a working copy (mutated by setters).
|
|
24
|
+
* Exported for tests. */
|
|
25
|
+
export function buildClassifierGroups(cfg: ClassifierSettings): PanelGroup[] {
|
|
26
|
+
const modelMenu = () => {
|
|
27
|
+
const ids = (registry?.getModelsOfType("classifier", "router") ?? []).map((m) => m.id);
|
|
28
|
+
return [
|
|
29
|
+
{ value: "", label: "(auto — first available)", description: "Resolve the decision model at ask time." },
|
|
30
|
+
...ids.map((id) => ({ value: id, label: id })),
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
key: "classifier",
|
|
36
|
+
label: "Classifier (Jev)",
|
|
37
|
+
tab: "Model",
|
|
38
|
+
icon: "⚖",
|
|
39
|
+
rows: [
|
|
40
|
+
row("classifier.model", "Decision model", "string", cfg.model, (v) => {
|
|
41
|
+
cfg.model = String(v ?? "").trim();
|
|
42
|
+
}, {
|
|
43
|
+
description: "Router decision model for Jev asks. Empty = first available from /v1/systemone/models discovery.",
|
|
44
|
+
menu: modelMenu,
|
|
45
|
+
defaultValue: "",
|
|
46
|
+
}),
|
|
47
|
+
row("classifier.permission.enabled", "Bash verdicts", "toggle", cfg.permission.enabled, (v) => {
|
|
48
|
+
cfg.permission.enabled = Boolean(v);
|
|
49
|
+
}, {
|
|
50
|
+
description: "Classify bash commands (reversible + serves the task) and audit verdicts to classifier.log. Observes only — never gates execution.",
|
|
51
|
+
defaultValue: true,
|
|
52
|
+
}),
|
|
53
|
+
row("classifier.permission.mode", "Mode", "string", cfg.permission.mode, (v) => {
|
|
54
|
+
cfg.permission.mode = v === "observe" ? "observe" : "enforce";
|
|
55
|
+
}, {
|
|
56
|
+
values: ["enforce", "observe"],
|
|
57
|
+
description: "enforce also shows confident safe-verdicts in the transcript; observe logs only. Neither mode blocks or approves anything.",
|
|
58
|
+
defaultValue: "enforce",
|
|
59
|
+
}),
|
|
60
|
+
row("classifier.permission.threshold", "Threshold (0-1)", "string", String(cfg.permission.threshold), (v) => {
|
|
61
|
+
const t = parseFloat(String(v));
|
|
62
|
+
cfg.permission.threshold = t > 0 && t < 1 ? t : cfg.permission.threshold;
|
|
63
|
+
}, {
|
|
64
|
+
description: "Both nouls must clear it. Saved values outside (0,1) fall back to 0.9.",
|
|
65
|
+
defaultValue: "0.9",
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const OWNED_KEYS = ["classifier.model", "classifier.permission.enabled", "classifier.permission.mode", "classifier.permission.threshold"];
|
|
73
|
+
|
|
74
|
+
/** classifier's ModuleConfig for the central /config panel. */
|
|
75
|
+
export function classifierConfig(): ModuleConfig {
|
|
76
|
+
const before = getClassifierSettings();
|
|
77
|
+
const working = structuredClone(before);
|
|
78
|
+
return {
|
|
79
|
+
groups: () => buildClassifierGroups(working),
|
|
80
|
+
save: async (edited, ctx: ExtensionContext) => {
|
|
81
|
+
if (!OWNED_KEYS.some((k) => edited.has(k))) return;
|
|
82
|
+
if (
|
|
83
|
+
working.model === before.model &&
|
|
84
|
+
working.permission.enabled === before.permission.enabled &&
|
|
85
|
+
working.permission.mode === before.permission.mode &&
|
|
86
|
+
working.permission.threshold === before.permission.threshold
|
|
87
|
+
) {
|
|
88
|
+
ctx.ui.notify("No changes.", "info");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
writeClassifierSection({
|
|
92
|
+
model: working.model !== before.model ? working.model : undefined,
|
|
93
|
+
enabled: working.permission.enabled !== before.permission.enabled ? working.permission.enabled : undefined,
|
|
94
|
+
mode: working.permission.mode !== before.permission.mode ? working.permission.mode : undefined,
|
|
95
|
+
threshold: working.permission.threshold !== before.permission.threshold ? working.permission.threshold : undefined,
|
|
96
|
+
});
|
|
97
|
+
const after = getClassifierSettings();
|
|
98
|
+
ctx.ui.notify(
|
|
99
|
+
`Classifier saved. Model: ${after.model || "(auto)"} · bash verdicts ${after.permission.enabled ? after.permission.mode : "disabled"} at ${after.permission.threshold} (audit-only, never gates execution).`,
|
|
100
|
+
"info",
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|