ceulen 0.5.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +365 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.test.ts +67 -0
- package/extensions/lib/registry.ts +104 -8
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +235 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +288 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +649 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +108 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +186 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/configPanel.ts +24 -10
- package/extensions/modules/router/lib/client.ts +63 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +260 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/rules/index.ts +120 -0
- package/extensions/modules/rules/lib/rules.ts +348 -0
- package/extensions/modules/rules/test/lib.test.ts +263 -0
- package/extensions/modules/rules/test/module.test.ts +222 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2464 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +228 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +763 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +524 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/todo/index.ts +478 -0
- package/extensions/modules/todo/test/todo.test.ts +252 -0
- package/extensions/modules/usage/index.ts +70 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/usage/test/session-accumulators.test.ts +85 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +218 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +157 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +198 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +154 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +721 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +230 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +364 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* classifier — System One decision models (TypeSafe Jev) for ceulen.
|
|
3
|
+
*
|
|
4
|
+
* Ported from @bacnh85/pi-classifier 0.2.3 (extensions/index.js), rewired to
|
|
5
|
+
* the MODEL REGISTRY: the router provider (lib/provider.ts) discovers decision
|
|
6
|
+
* models on /v1/systemone/models and carries the System One classifier impl,
|
|
7
|
+
* so this module has no endpoint, no API-key resolution, and no wire code —
|
|
8
|
+
* every ask goes through ctx.modelRegistry.classify() (request-time auth via
|
|
9
|
+
* the shared ROUTER credential, never rejects).
|
|
10
|
+
*
|
|
11
|
+
* 1. `classify` tool: the agent sends {state, questions}, gets typed answers.
|
|
12
|
+
* 2. Bash verdict hook: classifies each bash command (reversible + serves
|
|
13
|
+
* the task) and AUDITS the verdict to ~/.pi/agent/classifier.log. Static
|
|
14
|
+
* RISKY list first; never blocks; every failure falls through safely.
|
|
15
|
+
* NOTE: pi 1.0.0 core has NO built-in per-call approval prompt
|
|
16
|
+
* (docs/security.md) and `tool_call` can only block, never approve — so
|
|
17
|
+
* this hook is an observer/auditor, not a permission gate. "enforce" vs
|
|
18
|
+
* "observe" only changes whether confident verdicts get a visible
|
|
19
|
+
* annotation in the transcript; neither mode changes execution.
|
|
20
|
+
*
|
|
21
|
+
* Config: `classifier` section of ~/.pi/agent/settings.json (global only —
|
|
22
|
+
* see lib/settings.ts). /config owns the rows (Model tab → Classifier).
|
|
23
|
+
* pi-classifier's planGate is NOT ported and NOT consumed by the plan module:
|
|
24
|
+
* pi 1.0.0's `tool_call` hook can only block, never approve, so a gate could
|
|
25
|
+
* only have trimmed plan-mode confirm prompts (source preserved in
|
|
26
|
+
* pi-extensions git history).
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { appendFile, mkdir } from "node:fs/promises";
|
|
30
|
+
import { homedir } from "node:os";
|
|
31
|
+
import { join } from "node:path";
|
|
32
|
+
import { Type } from "typebox";
|
|
33
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
34
|
+
import { getClassifierSettings } from "./lib/settings.js";
|
|
35
|
+
import { setClassifierRegistry } from "./configPanel.js";
|
|
36
|
+
import { readDisabledTools } from "../../lib/tools.js";
|
|
37
|
+
|
|
38
|
+
// ── Risk gate (static, before Jev ever sees a command) ──────────────────────
|
|
39
|
+
|
|
40
|
+
const RISKY = [
|
|
41
|
+
/\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r)/, // rm -rf
|
|
42
|
+
/\bsudo\b/, /\bdoas\b/,
|
|
43
|
+
/\bgit\s+push\b[^|;&]*--force/, /\bgit\s+push\s+-f\b/, /\bgit\s+reset\s+--hard\b/,
|
|
44
|
+
/curl[^|;&]*\|\s*(ba)?sh/, /wget[^|;&]*\|\s*(ba)?sh/, // pipe-to-shell
|
|
45
|
+
/\b(npm|pnpm|yarn|bun)\s+publish\b/, /\bgh\s+release\s+(create|upload)\b/,
|
|
46
|
+
/\bterraform\s+(apply|destroy)\b/, /\bkubectl\s+(delete|apply)\b/,
|
|
47
|
+
/(^|\s)~?\/?\.?(ssh|aws|gnupg|kube)(\/|$)/, /id_rsa|\.pem\b|credentials\b/i,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/** True when the command matches the static risk list — never sent to Jev.
|
|
51
|
+
* Exported for tests. Intentionally shallow: a new RISKY shape = new entry. */
|
|
52
|
+
export function isRisky(command: string): boolean {
|
|
53
|
+
return RISKY.some((re) => re.test(command));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Split a compound command into top-level segments the RISKY check can see.
|
|
57
|
+
* Split on operators only — a separator inside quotes can only ADD a prompt,
|
|
58
|
+
* never hide a command. Exported for tests. */
|
|
59
|
+
export function segments(command: string): string[] {
|
|
60
|
+
return String(command).split(/&&|\|\||[;|&]|`|\$\(/).map((s) => s.trim()).filter(Boolean);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Read a probability from a Jev answer. The registry path returns
|
|
64
|
+
* {type:"bool", probability}; raw wire {noul} is tolerated. Malformed/
|
|
65
|
+
* missing/out-of-range → NaN → fail-safe. Exported for tests. */
|
|
66
|
+
export function noul(answers: unknown, id: string): number {
|
|
67
|
+
const a = (answers as Record<string, unknown> | undefined)?.[id];
|
|
68
|
+
const v = a && typeof a === "object" ? (a as Record<string, unknown>).probability ?? (a as Record<string, unknown>).noul : a;
|
|
69
|
+
return typeof v === "number" && v >= 0 && v <= 1 ? v : NaN;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** LRU verdict cache — repeated `bun test` shouldn't re-pay Jev every time.
|
|
73
|
+
* ponytail: insertion-order map, cap 100. Exported for tests. */
|
|
74
|
+
export function createVerdictCache(cap = 100) {
|
|
75
|
+
const m = new Map<string, unknown>();
|
|
76
|
+
return {
|
|
77
|
+
get(k: string): unknown {
|
|
78
|
+
if (!m.has(k)) return undefined;
|
|
79
|
+
const v = m.get(k);
|
|
80
|
+
m.delete(k);
|
|
81
|
+
m.set(k, v!); // refresh recency
|
|
82
|
+
return v;
|
|
83
|
+
},
|
|
84
|
+
set(k: string, v: unknown): void {
|
|
85
|
+
if (m.has(k)) m.delete(k);
|
|
86
|
+
m.set(k, v);
|
|
87
|
+
if (m.size > cap) m.delete(m.keys().next().value!);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Audit line per decision. Best-effort: never throws into the tool path.
|
|
93
|
+
* 0600 — the log records full bash commands and task text, same
|
|
94
|
+
* permission discipline as pi's settings/auth files. */
|
|
95
|
+
function audit(entry: Record<string, unknown>): Promise<void> {
|
|
96
|
+
try {
|
|
97
|
+
const dir = process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
|
|
98
|
+
// ponytail: async write so the tool_call hot path never blocks. Never rejects.
|
|
99
|
+
return mkdir(dir, { recursive: true })
|
|
100
|
+
.then(() => appendFile(join(dir, "classifier.log"), JSON.stringify({ ts: Date.now(), pid: process.pid, ...entry }) + "\n", { mode: 0o600 }))
|
|
101
|
+
.catch(() => {});
|
|
102
|
+
} catch {
|
|
103
|
+
return Promise.resolve(); // logging must never break the command
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Ask Jev via the registry: resolve the router decision model (settings
|
|
108
|
+
* override → first available) and classify. Returns answers, throws with a
|
|
109
|
+
* remediation hint when nothing is configured — callers fail safe around it. */
|
|
110
|
+
/** Cooldown for the cold-start forced refresh: a persistently unresolvable
|
|
111
|
+
* model (endpoint down, no creds) must not make every bash command pay a
|
|
112
|
+
* network attempt. Recovery still works — the next miss after the window
|
|
113
|
+
* retries. */
|
|
114
|
+
let lastForcedRefresh = 0;
|
|
115
|
+
|
|
116
|
+
/** Test hook: clear the cold-start cooldown (module state outlives a test). */
|
|
117
|
+
export function resetClassifierRefreshCooldown(): void {
|
|
118
|
+
lastForcedRefresh = 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function askJev(ctx: ExtensionContext, state: Record<string, unknown>, questions: Record<string, unknown>, signal?: AbortSignal): Promise<Record<string, unknown>> {
|
|
122
|
+
const resolve = async () => {
|
|
123
|
+
const s = getClassifierSettings();
|
|
124
|
+
let model = s.model ? ctx.modelRegistry.findOfType("classifier", "router", s.model) : undefined;
|
|
125
|
+
if (!model && s.model) {
|
|
126
|
+
// Settings may name a model from another provider (openrouter ~typesafe/…): match by id suffix.
|
|
127
|
+
model = ctx.modelRegistry.getModelsOfType("classifier").find((m) => m.id === s.model || m.id.endsWith("/" + s.model));
|
|
128
|
+
}
|
|
129
|
+
if (!model) {
|
|
130
|
+
const available = await ctx.modelRegistry.getAvailableOfType("classifier", "router");
|
|
131
|
+
model = available[0];
|
|
132
|
+
}
|
|
133
|
+
return model;
|
|
134
|
+
};
|
|
135
|
+
let model = await resolve();
|
|
136
|
+
if (!model) {
|
|
137
|
+
// Cold start: the router catalog's network pull races session startup, so
|
|
138
|
+
// the restored snapshot can still be chat-only. One forced pull + retry;
|
|
139
|
+
// the regular path is untouched (this only runs on a resolution miss).
|
|
140
|
+
if (Date.now() - lastForcedRefresh > 60_000) {
|
|
141
|
+
lastForcedRefresh = Date.now();
|
|
142
|
+
try {
|
|
143
|
+
await ctx.modelRegistry.refresh({ providers: ["router"], force: true });
|
|
144
|
+
} catch {
|
|
145
|
+
/* offline/endpoint down — the remediation error below still fires */
|
|
146
|
+
}
|
|
147
|
+
model = await resolve();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!model) {
|
|
151
|
+
throw new Error("no classifier model — configure the router provider (router.baseUrl + /login router) or set classifier.model");
|
|
152
|
+
}
|
|
153
|
+
const result = await ctx.modelRegistry.classify(model, { state, questions } as Parameters<typeof ctx.modelRegistry.classify>[1], { signal });
|
|
154
|
+
if (result.stopReason !== "stop") throw new Error(result.errorMessage ?? `classifier failed (${result.stopReason})`);
|
|
155
|
+
return result.answers as unknown as Record<string, unknown>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export default function (pi: ExtensionAPI) {
|
|
159
|
+
// The /config contribution reads discovered decision models at open time;
|
|
160
|
+
// config factories get no ctx, so the module stashes the live registry
|
|
161
|
+
// here (the panel always opens after a session exists). Cleared on shutdown
|
|
162
|
+
// so a stale registry never survives session replacement (router's pattern).
|
|
163
|
+
pi.on("session_start", (_event, ctx) => {
|
|
164
|
+
setClassifierRegistry(ctx.modelRegistry);
|
|
165
|
+
});
|
|
166
|
+
pi.on("session_shutdown", () => {
|
|
167
|
+
setClassifierRegistry(undefined);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ── 1. classify tool ────────────────────────────────────────────────────
|
|
171
|
+
const stateSchema = Type.Any({ description: "Everything Jev should judge: transcript, records, policy — as JSON." });
|
|
172
|
+
const questionsSchema = Type.Array(
|
|
173
|
+
Type.Object({
|
|
174
|
+
id: Type.String({ description: "Answer key, e.g. 'is_urgent'" }),
|
|
175
|
+
type: Type.Union([Type.Literal("noul"), Type.Literal("choice"), Type.Literal("score")]),
|
|
176
|
+
instructions: Type.String({ description: "The question about the state." }),
|
|
177
|
+
criteria: Type.Optional(Type.Any({ description: "choice: {option: description} · score: [levels] · noul: {yes,no}" })),
|
|
178
|
+
}),
|
|
179
|
+
{ description: "One entry per independent judgment. They run in parallel and cannot see each other's answers." },
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
pi.registerTool({
|
|
183
|
+
name: "classify",
|
|
184
|
+
label: "Classify",
|
|
185
|
+
// Per-tool kill-switch (ceulen.disabledTools / /config tool rows).
|
|
186
|
+
defaultActive: !readDisabledTools().has("classify"),
|
|
187
|
+
description:
|
|
188
|
+
"Ask a System One decision model (TypeSafe Jev) typed questions about a state and get calibrated answers: " +
|
|
189
|
+
"noul (probability of yes), choice (option + per-option probabilities + confidence), score (weighted position + confidence). " +
|
|
190
|
+
"Use for routing, verification, and gating decisions where a predictable typed answer beats generated prose. " +
|
|
191
|
+
"Not for open-ended questions — decisions only, no explanations.",
|
|
192
|
+
parameters: Type.Object({ state: stateSchema, questions: questionsSchema }),
|
|
193
|
+
async execute(_id, params, signal, _onUpdate, ctx) {
|
|
194
|
+
const qs: Record<string, unknown> = {};
|
|
195
|
+
for (const q of params.questions ?? []) {
|
|
196
|
+
let criteria = q.criteria as unknown;
|
|
197
|
+
// score criteria must be a LIST upstream — an object-shaped criteria
|
|
198
|
+
// (easy to produce from a JSON-schema mindset) gets 422 from Jev, so
|
|
199
|
+
// coerce {"0":"low",...} to ["low",...] before sending.
|
|
200
|
+
if (q.type === "score" && criteria && !Array.isArray(criteria) && typeof criteria === "object") {
|
|
201
|
+
criteria = Object.keys(criteria as Record<string, unknown>).sort((a, b) => Number(a) - Number(b)).map((k) => (criteria as Record<string, unknown>)[k]);
|
|
202
|
+
}
|
|
203
|
+
qs[q.id] = { type: q.type, instructions: q.instructions, ...(criteria !== undefined ? { criteria } : {}) };
|
|
204
|
+
}
|
|
205
|
+
const answers = await askJev(ctx, params.state as Record<string, unknown>, qs, signal ?? undefined);
|
|
206
|
+
return {
|
|
207
|
+
content: [{ type: "text", text: JSON.stringify(answers, null, 2) }],
|
|
208
|
+
details: { answers },
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// ── 2. permission auto-approve hook (ported from pi-classifier) ─────────
|
|
214
|
+
let lastTask = "";
|
|
215
|
+
pi.on("message_end", (event) => {
|
|
216
|
+
const msg = event.message;
|
|
217
|
+
if (msg?.role !== "user") return;
|
|
218
|
+
if (typeof msg.content === "string") lastTask = msg.content.slice(0, 4000);
|
|
219
|
+
// Array-shaped content: join the text parts (images etc. contribute nothing).
|
|
220
|
+
else if (Array.isArray(msg.content)) {
|
|
221
|
+
lastTask = (msg.content as { type?: string; text?: unknown }[])
|
|
222
|
+
.filter((p) => p?.type === "text" && typeof p.text === "string")
|
|
223
|
+
.map((p) => p.text as string)
|
|
224
|
+
.join("\n")
|
|
225
|
+
.slice(0, 4000);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const cache = createVerdictCache();
|
|
230
|
+
|
|
231
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
232
|
+
if (event.toolName !== "bash") return undefined;
|
|
233
|
+
const command = String(event.input?.command || "");
|
|
234
|
+
if (!command) return undefined;
|
|
235
|
+
|
|
236
|
+
const s = getClassifierSettings();
|
|
237
|
+
if (!s.permission.enabled) return undefined;
|
|
238
|
+
|
|
239
|
+
// static list first — credential-touching / irreversible commands never
|
|
240
|
+
// reach Jev and never leave the normal prompt
|
|
241
|
+
if (segments(command).some(isRisky)) return undefined;
|
|
242
|
+
|
|
243
|
+
const cacheKey = `${command}\u0000${ctx.cwd}\u0000${(lastTask || "").slice(0, 200)}`;
|
|
244
|
+
const cached = cache.get(cacheKey) as { approve: boolean; reversible: number; serves_task: number } | undefined;
|
|
245
|
+
|
|
246
|
+
const decide = async () => {
|
|
247
|
+
const s = getClassifierSettings();
|
|
248
|
+
const state: Record<string, unknown> = {
|
|
249
|
+
command,
|
|
250
|
+
project_path: ctx.cwd,
|
|
251
|
+
...(lastTask ? { task: lastTask } : {}),
|
|
252
|
+
};
|
|
253
|
+
const questions: Record<string, unknown> = {
|
|
254
|
+
reversible: { type: "bool", instructions: "Can this shell command be undone — its effects reversed or discarded without lasting harm?" },
|
|
255
|
+
...(state.task
|
|
256
|
+
? {
|
|
257
|
+
serves_task: {
|
|
258
|
+
type: "bool",
|
|
259
|
+
instructions: "Does this command plausibly serve the task the user asked for?",
|
|
260
|
+
criteria: { yes: "A reasonable step toward the user's stated task.", no: "Unrelated to the task, or only a step the task never needed." },
|
|
261
|
+
},
|
|
262
|
+
}
|
|
263
|
+
: {}),
|
|
264
|
+
};
|
|
265
|
+
const started = Date.now();
|
|
266
|
+
try {
|
|
267
|
+
const answers = await askJev(ctx, state, questions);
|
|
268
|
+
const rev = noul(answers, "reversible");
|
|
269
|
+
const serves = state.task ? noul(answers, "serves_task") : rev; // no task → reversibility only
|
|
270
|
+
const ok = rev >= s.permission.threshold && serves >= s.permission.threshold;
|
|
271
|
+
const decision = { approve: ok, reversible: rev, serves_task: serves };
|
|
272
|
+
cache.set(cacheKey, decision);
|
|
273
|
+
await audit({ command, ...decision, ms: Date.now() - started, model: s.model || "(auto)" });
|
|
274
|
+
return decision;
|
|
275
|
+
} catch (e) {
|
|
276
|
+
await audit({ command, error: String(e instanceof Error ? e.message : e), ms: Date.now() - started, model: s.model || "(auto)" });
|
|
277
|
+
return null; // fail-safe: fall back to the normal prompt
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const decision = cached !== undefined ? cached : await decide();
|
|
282
|
+
|
|
283
|
+
// Both modes only annotate; neither changes execution (pi 1.0.0 has no
|
|
284
|
+
// approval prompt for tool_call to skip — see module docstring). Enforce
|
|
285
|
+
// surfaces confident verdicts in the transcript so a human reviewing the
|
|
286
|
+
// session sees the classifier vouched for the command; observe stays
|
|
287
|
+
// log-only. NEVER blocks, NEVER denies.
|
|
288
|
+
if (s.permission.mode === "enforce" && decision?.approve) {
|
|
289
|
+
try {
|
|
290
|
+
ctx.ui.notify(`classifier verdict: safe (${command.slice(0, 80)})`, "info");
|
|
291
|
+
} catch {
|
|
292
|
+
/* non-tui */
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return undefined;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// classifier settings — global agent dir only, same contract as pi-classifier:
|
|
2
|
+
// `classifier` section of ~/.pi/agent/settings.json (the Bearer key follows the
|
|
3
|
+
// ROUTER credential via the provider, never this file — nothing secret here).
|
|
4
|
+
//
|
|
5
|
+
// "classifier": {
|
|
6
|
+
// "model": "combo/jev", // empty/unset = first available
|
|
7
|
+
// "permission": {
|
|
8
|
+
// "enabled": true, // default on (owner decision)
|
|
9
|
+
// "mode": "observe" | "enforce", // default enforce
|
|
10
|
+
// "threshold": 0.9 // both nouls must clear it
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// `planGate` in the file is left untouched (pi-plan's key; no consumer in
|
|
15
|
+
// ceulen until the pi-plan port).
|
|
16
|
+
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
|
|
21
|
+
export interface ClassifierSettings {
|
|
22
|
+
/** Model id on the router provider; empty = first available classifier model. */
|
|
23
|
+
model: string;
|
|
24
|
+
permission: {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
mode: "observe" | "enforce";
|
|
27
|
+
threshold: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function agentDir(): string {
|
|
32
|
+
return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function settingsPath(): string {
|
|
36
|
+
return join(agentDir(), "settings.json");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Read the `classifier` settings. Global only — a repo file must not flip
|
|
40
|
+
* verdict behavior. Defaults match pi-classifier (enabled/enforce/0.9 since
|
|
41
|
+
* the 0.2.0 live audit). Exported for tests. */
|
|
42
|
+
export function getClassifierSettings(): ClassifierSettings {
|
|
43
|
+
let raw: Record<string, unknown> = {};
|
|
44
|
+
try {
|
|
45
|
+
if (existsSync(settingsPath())) {
|
|
46
|
+
raw = JSON.parse(readFileSync(settingsPath(), "utf8")) as Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
raw = {}; // unreadable → defaults below
|
|
50
|
+
}
|
|
51
|
+
const c = raw.classifier && typeof raw.classifier === "object" ? (raw.classifier as Record<string, unknown>) : {};
|
|
52
|
+
const perm = c.permission && typeof c.permission === "object" ? (c.permission as Record<string, unknown>) : {};
|
|
53
|
+
return {
|
|
54
|
+
model: typeof c.model === "string" ? c.model.trim() : "",
|
|
55
|
+
permission: {
|
|
56
|
+
// Explicit enabled:false wins; default ON per owner decision after a
|
|
57
|
+
// 102-verdict live audit (0 dangerous approvals). No-op until the
|
|
58
|
+
// router provider is configured: classify errors fall back to the prompt.
|
|
59
|
+
enabled: perm.enabled !== false,
|
|
60
|
+
mode: perm.mode === "observe" ? "observe" : "enforce",
|
|
61
|
+
threshold: typeof perm.threshold === "number" && perm.threshold > 0 && perm.threshold < 1 ? perm.threshold : 0.9,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Read-modify-write non-secret `classifier` fields into the GLOBAL
|
|
67
|
+
* settings.json (merge, never clobber; atomic tmp+rename; a corrupt file
|
|
68
|
+
* refuses to clobber). Exported for tests. */
|
|
69
|
+
export function writeClassifierSection(patch: { model?: string; enabled?: boolean; mode?: "observe" | "enforce"; threshold?: number }): void {
|
|
70
|
+
let settings: Record<string, unknown>;
|
|
71
|
+
try {
|
|
72
|
+
settings = existsSync(settingsPath())
|
|
73
|
+
? (JSON.parse(readFileSync(settingsPath(), "utf8")) as Record<string, unknown>)
|
|
74
|
+
: {};
|
|
75
|
+
} catch {
|
|
76
|
+
// Corrupt ≠ missing: writing here would replace the whole file with ONLY
|
|
77
|
+
// the classifier section — bail instead.
|
|
78
|
+
throw new Error(`${settingsPath()} is not valid JSON — fix or remove it before saving.`);
|
|
79
|
+
}
|
|
80
|
+
const c = (settings.classifier ?? {}) as Record<string, unknown>;
|
|
81
|
+
const perm = (c.permission ?? {}) as Record<string, unknown>;
|
|
82
|
+
if (patch.model !== undefined) c.model = String(patch.model).trim();
|
|
83
|
+
if (patch.enabled !== undefined) perm.enabled = patch.enabled === true;
|
|
84
|
+
if (patch.mode !== undefined) perm.mode = patch.mode === "enforce" ? "enforce" : "observe";
|
|
85
|
+
if (patch.threshold !== undefined) {
|
|
86
|
+
const t = Number(patch.threshold);
|
|
87
|
+
perm.threshold = t > 0 && t < 1 ? t : 0.9;
|
|
88
|
+
}
|
|
89
|
+
c.permission = perm;
|
|
90
|
+
settings.classifier = c;
|
|
91
|
+
mkdirSync(dirname(settingsPath()), { recursive: true });
|
|
92
|
+
const tmp = settingsPath() + ".tmp";
|
|
93
|
+
writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
|
|
94
|
+
renameSync(tmp, settingsPath());
|
|
95
|
+
}
|