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,218 @@
|
|
|
1
|
+
// ponytail: vendored from @kalera/munin-sdk 1.5.0 (dist/{client,errors,capabilities}.js +
|
|
2
|
+
// types.d.ts) — 152 lines, zero deps, so the bundle keeps its no-runtime-deps rule.
|
|
3
|
+
// Local changes vs upstream: capabilities cache is keyed by `${baseUrl}|${apiKey}`
|
|
4
|
+
// (upstream cached one global `globalThis.__munin_caps`, which went stale when a
|
|
5
|
+
// user switched munin servers per project), and fetchCapabilities arms a timeout
|
|
6
|
+
// like invoke() (upstream could hang forever on a dead server).
|
|
7
|
+
// Upgrade = re-vendor this one file.
|
|
8
|
+
|
|
9
|
+
export type MuninAction = "store" | "retrieve" | "search" | "list" | "recent" | "share" | "versions" | "rollback" | "encrypt" | "decrypt" | "diff" | "delete" | "acknowledge_setup";
|
|
10
|
+
|
|
11
|
+
export interface MuninActionEnvelope<TPayload = Record<string, unknown>> {
|
|
12
|
+
action: MuninAction;
|
|
13
|
+
project: string;
|
|
14
|
+
payload: TPayload;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
client?: {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MuninCapabilities {
|
|
23
|
+
specVersion: string;
|
|
24
|
+
actions: {
|
|
25
|
+
core: string[];
|
|
26
|
+
optional: string[];
|
|
27
|
+
};
|
|
28
|
+
features: Record<string, {
|
|
29
|
+
supported: boolean;
|
|
30
|
+
reason?: string;
|
|
31
|
+
}>;
|
|
32
|
+
metadata: {
|
|
33
|
+
serverVersion: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MuninError {
|
|
40
|
+
code: "AUTH_INVALID" | "FEATURE_DISABLED" | "NOT_FOUND" | "RATE_LIMITED" | "VALIDATION_ERROR" | "INTERNAL_ERROR" | "ERR_STALE_PROTOCOL";
|
|
41
|
+
message: string;
|
|
42
|
+
details?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface MuninResponse<TData = unknown> {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
data?: TData;
|
|
48
|
+
error?: MuninError;
|
|
49
|
+
requestId?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface MuninClientConfig {
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
fetchImpl?: typeof fetch;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class MuninSdkError extends Error {
|
|
60
|
+
code: MuninError["code"] | string;
|
|
61
|
+
details?: Record<string, unknown>;
|
|
62
|
+
constructor(error: MuninError) {
|
|
63
|
+
super(error.message);
|
|
64
|
+
this.name = "MuninSdkError";
|
|
65
|
+
this.code = error.code;
|
|
66
|
+
this.details = error.details;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class MuninTransportError extends Error {
|
|
71
|
+
constructor(message: string) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "MuninTransportError";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function fetchCapabilities(baseUrl: string, apiKey: string | undefined, fetchImpl: typeof fetch = fetch, timeoutMs = DEFAULT_TIMEOUT_MS): Promise<MuninCapabilities> {
|
|
78
|
+
const response = await fetchImpl(`${baseUrl}/api/mcp/capabilities`, {
|
|
79
|
+
method: "GET",
|
|
80
|
+
headers: {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
83
|
+
},
|
|
84
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
85
|
+
}).catch((error) => {
|
|
86
|
+
throw new MuninTransportError(`Failed to call capabilities endpoint: ${String(error)}`);
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new MuninTransportError(`Capabilities request failed with status ${response.status}`);
|
|
90
|
+
}
|
|
91
|
+
const body = (await response.json()) as MuninResponse<MuninCapabilities>;
|
|
92
|
+
if (!body.ok || !body.data) {
|
|
93
|
+
throw new MuninSdkError(body.error ?? {
|
|
94
|
+
code: "INTERNAL_ERROR",
|
|
95
|
+
message: "Capabilities response missing data",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return body.data;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function isActionSupported(capabilities: MuninCapabilities, action: string): boolean {
|
|
102
|
+
return capabilities.actions.core.includes(action) ||
|
|
103
|
+
capabilities.actions.optional.includes(action);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
107
|
+
|
|
108
|
+
export class MuninClient {
|
|
109
|
+
baseUrl: string;
|
|
110
|
+
apiKey: string | undefined;
|
|
111
|
+
timeoutMs: number;
|
|
112
|
+
fetchImpl: typeof fetch;
|
|
113
|
+
constructor(config?: MuninClientConfig) {
|
|
114
|
+
this.baseUrl = (config?.baseUrl || "https://munin.kalera.dev").replace(/\/$/, "");
|
|
115
|
+
this.apiKey = config?.apiKey;
|
|
116
|
+
this.timeoutMs = config?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
117
|
+
this.fetchImpl = config?.fetchImpl ?? fetch;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async capabilities(forceRefresh = false): Promise<MuninCapabilities> {
|
|
121
|
+
const cacheKey = `${this.baseUrl}|${this.apiKey ?? ""}`;
|
|
122
|
+
if (!forceRefresh && globalThis.__munin_caps?.key === cacheKey) {
|
|
123
|
+
return globalThis.__munin_caps.caps;
|
|
124
|
+
}
|
|
125
|
+
const caps = await fetchCapabilities(this.baseUrl, this.apiKey, this.fetchImpl, this.timeoutMs);
|
|
126
|
+
globalThis.__munin_caps = { key: cacheKey, caps };
|
|
127
|
+
return caps;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async invoke(projectId: string, action: string, payload: Record<string, unknown> = {}, options?: { ensureCapability?: boolean; requestId?: string }): Promise<unknown> {
|
|
131
|
+
if (options?.ensureCapability) {
|
|
132
|
+
const caps = await this.capabilities();
|
|
133
|
+
if (!isActionSupported(caps, action)) {
|
|
134
|
+
throw new MuninSdkError({
|
|
135
|
+
code: "FEATURE_DISABLED",
|
|
136
|
+
message: `Action '${action}' is not supported by current server capabilities`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const controller = new AbortController();
|
|
141
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
142
|
+
const response = await this.fetchImpl(`${this.baseUrl}/api/mcp/action`, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify({
|
|
148
|
+
apiKey: this.apiKey,
|
|
149
|
+
project: projectId,
|
|
150
|
+
projectId, // Fallback for un-restarted server
|
|
151
|
+
action,
|
|
152
|
+
payload,
|
|
153
|
+
requestId: options?.requestId,
|
|
154
|
+
client: {
|
|
155
|
+
name: "@kalera/munin-sdk",
|
|
156
|
+
version: "1.5.0",
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
signal: controller.signal,
|
|
160
|
+
}).catch((error) => {
|
|
161
|
+
clearTimeout(timeout);
|
|
162
|
+
throw new MuninTransportError(`Request failed for action '${action}': ${String(error)}`);
|
|
163
|
+
});
|
|
164
|
+
clearTimeout(timeout);
|
|
165
|
+
const body = (await response.json()) as MuninResponse & { success?: boolean };
|
|
166
|
+
if (!response.ok || (body.ok === false) || (body.success === false)) {
|
|
167
|
+
let errObj: MuninError | undefined = body.error;
|
|
168
|
+
if (typeof errObj === "string") {
|
|
169
|
+
// The server may return `error` as a bare string code
|
|
170
|
+
// (e.g. "ERR_STALE_PROTOCOL"); use it as both the code and message
|
|
171
|
+
// instead of flattening every string error into INTERNAL_ERROR.
|
|
172
|
+
errObj = { code: errObj as MuninError["code"], message: errObj };
|
|
173
|
+
}
|
|
174
|
+
if (!errObj) {
|
|
175
|
+
errObj = {
|
|
176
|
+
code: "INTERNAL_ERROR",
|
|
177
|
+
message: `Unexpected failure invoking action '${action}'`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// A top-level `remediation` (sent alongside the error envelope, e.g. for
|
|
181
|
+
// ERR_STALE_PROTOCOL) is folded into `details` so callers can read it via
|
|
182
|
+
// MuninSdkError.details without losing any existing structured details.
|
|
183
|
+
const remediation = (body as { remediation?: unknown }).remediation;
|
|
184
|
+
if (remediation !== undefined) {
|
|
185
|
+
errObj = {
|
|
186
|
+
...errObj,
|
|
187
|
+
details: { ...(errObj.details ?? {}), remediation },
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
throw new MuninSdkError(errObj);
|
|
191
|
+
}
|
|
192
|
+
return body;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async store(projectId: string, payload: Record<string, unknown> = {}): Promise<unknown> {
|
|
196
|
+
return this.invoke(projectId, "store", payload, { ensureCapability: true });
|
|
197
|
+
}
|
|
198
|
+
async retrieve(projectId: string, payload: Record<string, unknown> = {}): Promise<unknown> {
|
|
199
|
+
return this.invoke(projectId, "retrieve", payload, { ensureCapability: true });
|
|
200
|
+
}
|
|
201
|
+
async search(projectId: string, payload: Record<string, unknown> = {}): Promise<unknown> {
|
|
202
|
+
return this.invoke(projectId, "search", payload, { ensureCapability: true });
|
|
203
|
+
}
|
|
204
|
+
async list(projectId: string, payload: Record<string, unknown> = {}): Promise<unknown> {
|
|
205
|
+
return this.invoke(projectId, "list", payload, { ensureCapability: true });
|
|
206
|
+
}
|
|
207
|
+
async recent(projectId: string, payload: Record<string, unknown> = {}): Promise<unknown> {
|
|
208
|
+
return this.invoke(projectId, "recent", payload, { ensureCapability: true });
|
|
209
|
+
}
|
|
210
|
+
async share(projectId: string, memoryIds: string[], targetProjectIds: string[]): Promise<unknown> {
|
|
211
|
+
return this.invoke(projectId, "share", { memoryIds, targetProjectIds }, { ensureCapability: true });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare global {
|
|
216
|
+
// eslint-disable-next-line no-var
|
|
217
|
+
var __munin_caps: { key: string; caps: MuninCapabilities } | undefined;
|
|
218
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// NEW for the ceulen port — covers the settings.json-based config resolution
|
|
2
|
+
// (env > trusted project file > global file > default), the untrusted-project
|
|
3
|
+
// gate, and writeMuninSection's atomic merge semantics.
|
|
4
|
+
|
|
5
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import {
|
|
11
|
+
getMuninConfig,
|
|
12
|
+
projectSettingsPath,
|
|
13
|
+
readMuninSection,
|
|
14
|
+
writeMuninSection,
|
|
15
|
+
} from "../lib/helpers.js";
|
|
16
|
+
|
|
17
|
+
const ENV_KEYS = ["MUNIN_API_KEY", "MUNIN_PROJECT", "MUNIN_BASE_URL", "PI_CODING_AGENT_DIR", "HOME"] as const;
|
|
18
|
+
|
|
19
|
+
describe("munin settings resolution", () => {
|
|
20
|
+
let dirs: string[];
|
|
21
|
+
let originalEnv: Record<string, string | undefined>;
|
|
22
|
+
let cwd: string;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
dirs = [];
|
|
26
|
+
originalEnv = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
27
|
+
for (const key of ENV_KEYS) delete process.env[key];
|
|
28
|
+
cwd = mkdtempSync(join(tmpdir(), "munin-cwd-"));
|
|
29
|
+
dirs.push(cwd);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
for (const key of ENV_KEYS) {
|
|
34
|
+
if (originalEnv[key] === undefined) delete process.env[key];
|
|
35
|
+
else process.env[key] = originalEnv[key];
|
|
36
|
+
}
|
|
37
|
+
for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function agentDir(): string {
|
|
41
|
+
const dir = mkdtempSync(join(tmpdir(), "munin-agent-"));
|
|
42
|
+
dirs.push(dir);
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function writeJson(file: string, json: unknown): void {
|
|
47
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
48
|
+
writeFileSync(file, JSON.stringify(json, null, 2));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
it("resolves env over project over global over default", () => {
|
|
52
|
+
const agent = agentDir();
|
|
53
|
+
writeJson(projectSettingsPath(cwd), { munin: { apiKey: "proj-key", project: "proj-id", baseUrl: "https://proj.example.test" } });
|
|
54
|
+
writeJson(join(agent, "settings.json"), { munin: { apiKey: "global-key", project: "global-id", baseUrl: "https://global.example.test" } });
|
|
55
|
+
|
|
56
|
+
// All three fields from project (trusted).
|
|
57
|
+
const fromProject = getMuninConfig({}, cwd, true, { agentDirs: [agent] });
|
|
58
|
+
assert.deepEqual(fromProject.sources, { apiKey: "project", projectId: "project", baseUrl: "project" });
|
|
59
|
+
assert.equal(fromProject.apiKey, "proj-key");
|
|
60
|
+
|
|
61
|
+
// Env wins per-field.
|
|
62
|
+
process.env.MUNIN_API_KEY = "env-key";
|
|
63
|
+
const withEnv = getMuninConfig({}, cwd, true, { agentDirs: [agent] });
|
|
64
|
+
assert.equal(withEnv.apiKey, "env-key");
|
|
65
|
+
assert.equal(withEnv.projectId, "proj-id");
|
|
66
|
+
assert.equal(withEnv.sources.apiKey, "env");
|
|
67
|
+
delete process.env.MUNIN_API_KEY;
|
|
68
|
+
|
|
69
|
+
// Untrusted project → global used instead (no env in play).
|
|
70
|
+
const untrusted = getMuninConfig({}, cwd, false, { agentDirs: [agent] });
|
|
71
|
+
assert.deepEqual(untrusted.sources, { apiKey: "global", projectId: "global", baseUrl: "global" });
|
|
72
|
+
assert.equal(untrusted.apiKey, "global-key");
|
|
73
|
+
|
|
74
|
+
// Nothing anywhere → defaults error with pointers (baseUrl would default).
|
|
75
|
+
assert.throws(() => getMuninConfig({}, cwd, false, { agentDirs: [agentDir()] }), /\/config → Memory/);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("project file is ignored entirely when untrusted (credential-safety)", () => {
|
|
79
|
+
const agent = agentDir();
|
|
80
|
+
writeJson(projectSettingsPath(cwd), { munin: { apiKey: "evil-key", project: "evil-id", baseUrl: "https://evil.example.test" } });
|
|
81
|
+
writeJson(join(agent, "settings.json"), { munin: { apiKey: "safe-key", project: "safe-id" } });
|
|
82
|
+
const cfg = getMuninConfig({}, cwd, false, { agentDirs: [agent] });
|
|
83
|
+
// Project file values are invisible; the global file fills the gap instead.
|
|
84
|
+
assert.equal(cfg.projectId, "safe-id");
|
|
85
|
+
assert.equal(cfg.apiKey, "safe-key");
|
|
86
|
+
assert.notEqual(cfg.baseUrl, "https://evil.example.test");
|
|
87
|
+
assert.throws(
|
|
88
|
+
() => getMuninConfig({}, cwd, false, { agentDirs: [agentDir()] }),
|
|
89
|
+
/Munin API key is not configured/,
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("explicit params beat every layer; base_url still requires api_key", () => {
|
|
94
|
+
const agent = agentDir();
|
|
95
|
+
writeJson(projectSettingsPath(cwd), { munin: { apiKey: "proj-key", project: "proj-id" } });
|
|
96
|
+
const cfg = getMuninConfig({ project: "param-id" }, cwd, true, { agentDirs: [agent] });
|
|
97
|
+
assert.equal(cfg.projectId, "param-id");
|
|
98
|
+
assert.equal(cfg.sources.projectId, "param");
|
|
99
|
+
assert.equal(cfg.sources.apiKey, "project");
|
|
100
|
+
assert.throws(() => getMuninConfig({ base_url: "https://x.test", project: "p" }, cwd, true, { agentDirs: [agent] }), /explicit api_key/);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("global file alone fills unconfigured fields", () => {
|
|
104
|
+
const agent = agentDir();
|
|
105
|
+
writeJson(join(agent, "settings.json"), { munin: { apiKey: "g-key", project: "g-id" } });
|
|
106
|
+
const cfg = getMuninConfig({}, cwd, false, { agentDirs: [agent] });
|
|
107
|
+
assert.deepEqual(cfg.sources, { apiKey: "global", projectId: "global", baseUrl: "default" });
|
|
108
|
+
assert.equal(cfg.baseUrl, "https://munin.kalera.ai");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("readMuninSection tolerates missing/malformed files and non-string values", () => {
|
|
112
|
+
assert.equal(readMuninSection(join(cwd, "missing.json")), null);
|
|
113
|
+
writeFileSync(join(cwd, "bad.json"), "{not json");
|
|
114
|
+
assert.equal(readMuninSection(join(cwd, "bad.json")), null);
|
|
115
|
+
writeJson(join(cwd, "ok.json"), { other: 1, munin: { apiKey: 123, project: "p", baseUrl: "" } });
|
|
116
|
+
assert.deepEqual(readMuninSection(join(cwd, "ok.json")), { project: "p" });
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("writeMuninSection", () => {
|
|
121
|
+
let dir: string;
|
|
122
|
+
let dirs: string[];
|
|
123
|
+
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
dirs = [];
|
|
126
|
+
dir = mkdtempSync(join(tmpdir(), "munin-write-"));
|
|
127
|
+
dirs.push(dir);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
afterEach(() => {
|
|
131
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("creates the file and preserves sibling keys on merge", () => {
|
|
135
|
+
const file = join(dir, ".pi", "settings.json");
|
|
136
|
+
writeMuninSection({ apiKey: "k", project: "p" }, file);
|
|
137
|
+
writeMuninSection({ baseUrl: "https://x.test" }, file);
|
|
138
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
139
|
+
assert.deepEqual(json.munin, { apiKey: "k", project: "p", baseUrl: "https://x.test" });
|
|
140
|
+
// No tmp residue.
|
|
141
|
+
assert.equal(existsSync(file + ".tmp"), false);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("never clobbers other top-level sections", () => {
|
|
145
|
+
const file = join(dir, "settings.json");
|
|
146
|
+
writeFileSync(file, JSON.stringify({ ceulen: { disabled: ["rtk"] }, router: { baseUrl: "http://r" } }));
|
|
147
|
+
writeMuninSection({ project: "p" }, file);
|
|
148
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
149
|
+
assert.deepEqual(json.ceulen, { disabled: ["rtk"] });
|
|
150
|
+
assert.deepEqual(json.router, { baseUrl: "http://r" });
|
|
151
|
+
assert.equal(json.munin.project, "p");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("empty-string patch clears the field", () => {
|
|
155
|
+
const file = join(dir, "settings.json");
|
|
156
|
+
writeMuninSection({ project: "p" }, file);
|
|
157
|
+
writeMuninSection({ project: "" }, file);
|
|
158
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
159
|
+
assert.deepEqual(json.munin, {});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("refuses to overwrite a corrupt file", () => {
|
|
163
|
+
const file = join(dir, "settings.json");
|
|
164
|
+
writeFileSync(file, "{corrupt");
|
|
165
|
+
assert.throws(() => writeMuninSection({ project: "p" }, file), /not valid JSON/);
|
|
166
|
+
assert.equal(readFileSync(file, "utf8"), "{corrupt");
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// NEW for the ceulen port — panel groups shape, effective-value display, and
|
|
2
|
+
// the project-level save path (write target, patch diffing, trust + env notes).
|
|
3
|
+
|
|
4
|
+
import { mkdtempSync, mkdirSync, realpathSync, rmSync, writeFileSync, readFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { projectSettingsPath } from "../lib/helpers.js";
|
|
10
|
+
import { buildMuninGroups, muninConfig, readMuninSettings, type MuninSettings } from "../configPanel.js";
|
|
11
|
+
|
|
12
|
+
const ENV_KEYS = ["MUNIN_API_KEY", "MUNIN_PROJECT", "MUNIN_BASE_URL", "PI_CODING_AGENT_DIR"] as const;
|
|
13
|
+
|
|
14
|
+
describe("buildMuninGroups", () => {
|
|
15
|
+
it("renders the Memory tab with masked apiKey row", () => {
|
|
16
|
+
const cfg: MuninSettings = { project: "p", baseUrl: "https://x.test", apiKey: "k" };
|
|
17
|
+
const groups = buildMuninGroups(cfg);
|
|
18
|
+
assert.equal(groups.length, 1);
|
|
19
|
+
assert.equal(groups[0]!.tab, "Memory");
|
|
20
|
+
assert.equal(groups[0]!.label, "Munin");
|
|
21
|
+
assert.deepEqual(groups[0]!.rows.map((r) => r.key), ["munin.project", "munin.baseUrl", "munin.apiKey"]);
|
|
22
|
+
const keyRow = groups[0]!.rows[2]!;
|
|
23
|
+
assert.equal(keyRow.mask, true);
|
|
24
|
+
assert.match(keyRow.warning ?? "", /\.gitignore/);
|
|
25
|
+
assert.equal(groups[0]!.rows[1]!.defaultValue, "https://munin.kalera.ai");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("row setters mutate the working copy", () => {
|
|
29
|
+
const cfg: MuninSettings = { project: "", baseUrl: "https://munin.kalera.ai", apiKey: "" };
|
|
30
|
+
const groups = buildMuninGroups(cfg);
|
|
31
|
+
groups[0]!.rows[0]!.set("new-project");
|
|
32
|
+
groups[0]!.rows[2]!.set(" new-key ");
|
|
33
|
+
assert.equal(cfg.project, "new-project");
|
|
34
|
+
assert.equal(cfg.apiKey, "new-key");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("readMuninSettings", () => {
|
|
39
|
+
let dirs: string[];
|
|
40
|
+
let originalEnv: Record<string, string | undefined>;
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
dirs = [];
|
|
44
|
+
originalEnv = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
45
|
+
for (const key of ENV_KEYS) delete process.env[key];
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
for (const key of ENV_KEYS) {
|
|
50
|
+
if (originalEnv[key] === undefined) delete process.env[key];
|
|
51
|
+
else process.env[key] = originalEnv[key];
|
|
52
|
+
}
|
|
53
|
+
for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("returns effective values (env beats project file) and defaults when unconfigured", () => {
|
|
57
|
+
const cwd = mkdtempSync(join(tmpdir(), "munin-panel-"));
|
|
58
|
+
dirs.push(cwd);
|
|
59
|
+
mkdirSync(join(cwd, ".pi"), { recursive: true });
|
|
60
|
+
writeFileSync(projectSettingsPath(cwd), JSON.stringify({ munin: { apiKey: "pk", project: "pp" } }));
|
|
61
|
+
process.env.MUNIN_PROJECT = "env-project";
|
|
62
|
+
const eff = readMuninSettings(cwd, true);
|
|
63
|
+
assert.equal(eff.project, "env-project");
|
|
64
|
+
assert.equal(eff.apiKey, "pk");
|
|
65
|
+
assert.equal(eff.baseUrl, "https://munin.kalera.ai");
|
|
66
|
+
|
|
67
|
+
process.env.MUNIN_PROJECT = undefined;
|
|
68
|
+
const none = readMuninSettings(join(cwd, "nowhere"), false);
|
|
69
|
+
assert.deepEqual(none, { project: "", baseUrl: "https://munin.kalera.ai", apiKey: "" });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("muninConfig resolves the trust flag itself (no phantom project values untrusted)", () => {
|
|
73
|
+
// The factory gets no ctx, so the baseline must resolve trust through the
|
|
74
|
+
// shared helper — a hardcoded `true` shows a trusted-project value in an
|
|
75
|
+
// UNTRUSTED checkout (the phantom-value bug class).
|
|
76
|
+
const agentDir = mkdtempSync(join(tmpdir(), "munin-agent-"));
|
|
77
|
+
const cwd = mkdtempSync(join(tmpdir(), "munin-trust-"));
|
|
78
|
+
dirs.push(agentDir, cwd);
|
|
79
|
+
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
80
|
+
process.env.MUNIN_API_KEY = "env-key"; // keep getMuninConfig from throwing
|
|
81
|
+
process.env.MUNIN_PROJECT = "env-id";
|
|
82
|
+
mkdirSync(join(cwd, ".pi"), { recursive: true });
|
|
83
|
+
writeFileSync(projectSettingsPath(cwd), JSON.stringify({ munin: { baseUrl: "https://project.test" } }));
|
|
84
|
+
const prevCwd = process.cwd();
|
|
85
|
+
process.chdir(cwd);
|
|
86
|
+
const baseUrlRow = () => muninConfig().groups()[0]!.rows[1]!.value;
|
|
87
|
+
try {
|
|
88
|
+
writeFileSync(join(agentDir, "trust.json"), JSON.stringify({ [process.cwd()]: true }));
|
|
89
|
+
assert.equal(baseUrlRow(), "https://project.test", "trusted → project value shown");
|
|
90
|
+
writeFileSync(join(agentDir, "trust.json"), JSON.stringify({ [process.cwd()]: false }));
|
|
91
|
+
assert.equal(baseUrlRow(), "https://munin.kalera.ai", "untrusted → project value ignored");
|
|
92
|
+
} finally {
|
|
93
|
+
process.chdir(prevCwd);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("muninConfig save", () => {
|
|
99
|
+
let dirs: string[];
|
|
100
|
+
let originalEnv: Record<string, string | undefined>;
|
|
101
|
+
let cwd: string;
|
|
102
|
+
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
dirs = [];
|
|
105
|
+
originalEnv = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
106
|
+
for (const key of ENV_KEYS) delete process.env[key];
|
|
107
|
+
cwd = mkdtempSync(join(tmpdir(), "munin-save-"));
|
|
108
|
+
dirs.push(cwd);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
afterEach(() => {
|
|
112
|
+
for (const key of ENV_KEYS) {
|
|
113
|
+
if (originalEnv[key] === undefined) delete process.env[key];
|
|
114
|
+
else process.env[key] = originalEnv[key];
|
|
115
|
+
}
|
|
116
|
+
for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function saveCtx(trusted: boolean, notify?: (m: string, l?: string) => void) {
|
|
120
|
+
return {
|
|
121
|
+
isProjectTrusted: () => trusted,
|
|
122
|
+
cwd,
|
|
123
|
+
ui: { notify: notify ?? (() => {}) },
|
|
124
|
+
} as any;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
it("no-ops without owned keys", async () => {
|
|
128
|
+
const contrib = muninConfig();
|
|
129
|
+
const foreign = new Set<string>(["router.baseUrl"]);
|
|
130
|
+
await contrib.save(foreign, saveCtx(true));
|
|
131
|
+
assert.equal(readFileSyncSafe(projectSettingsPath(cwd)), null);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("writes changed fields to the project file; untrusted save warns", async () => {
|
|
135
|
+
const notes: { message: string; level?: string }[] = [];
|
|
136
|
+
const contrib = muninConfig();
|
|
137
|
+
// Simulate the panel edit: mutate the working copy the rows close over.
|
|
138
|
+
const groups = contrib.groups();
|
|
139
|
+
groups[0]!.rows[0]!.set("saved-project");
|
|
140
|
+
groups[0]!.rows[1]!.set("https://saved.example.test");
|
|
141
|
+
groups[0]!.rows[2]!.set("saved-key");
|
|
142
|
+
await contrib.save(new Set(["munin.project"]), saveCtx(false, (message, level) => notes.push({ message, level })));
|
|
143
|
+
|
|
144
|
+
const json = JSON.parse(readFileSync(projectSettingsPath(cwd), "utf8"));
|
|
145
|
+
assert.equal(json.munin.project, "saved-project");
|
|
146
|
+
assert.equal(json.munin.baseUrl, "https://saved.example.test");
|
|
147
|
+
assert.equal(json.munin.apiKey, "saved-key");
|
|
148
|
+
const note = notes[0]!;
|
|
149
|
+
assert.match(note.message, /saved to .*\.pi\/settings\.json/);
|
|
150
|
+
assert.match(note.message, /NOT trusted/);
|
|
151
|
+
assert.equal(note.level, "warning");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("trusted save notifies info and preserves sibling settings", async () => {
|
|
155
|
+
const notes: string[] = [];
|
|
156
|
+
mkdirSync(join(cwd, ".pi"), { recursive: true });
|
|
157
|
+
writeFileSync(projectSettingsPath(cwd), JSON.stringify({ ceulen: { disabled: ["rtk"] } }));
|
|
158
|
+
const contrib = muninConfig();
|
|
159
|
+
const groups = contrib.groups();
|
|
160
|
+
groups[0]!.rows[0]!.set("tp");
|
|
161
|
+
await contrib.save(new Set(["munin.project"]), saveCtx(true, (m) => notes.push(m)));
|
|
162
|
+
const json = JSON.parse(readFileSync(projectSettingsPath(cwd), "utf8"));
|
|
163
|
+
assert.deepEqual(json.ceulen, { disabled: ["rtk"] });
|
|
164
|
+
assert.equal(json.munin.project, "tp");
|
|
165
|
+
assert.match(notes[0]!, /saved to/);
|
|
166
|
+
assert.doesNotMatch(notes[0]!, /NOT trusted/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("env presence appends the override caveat", async () => {
|
|
170
|
+
const notes: string[] = [];
|
|
171
|
+
process.env.MUNIN_API_KEY = "env-key";
|
|
172
|
+
const contrib = muninConfig();
|
|
173
|
+
const groups = contrib.groups();
|
|
174
|
+
groups[0]!.rows[2]!.set("saved-key");
|
|
175
|
+
await contrib.save(new Set(["munin.apiKey"]), saveCtx(true, (m) => notes.push(m)));
|
|
176
|
+
assert.match(notes[0]!, /MUNIN_\* env vars override/);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
function readFileSyncSafe(file: string): string | null {
|
|
180
|
+
try {
|
|
181
|
+
return readFileSync(file, "utf8");
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|