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,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for web_crawl light-mode poll loop deadline handling.
|
|
3
|
+
*
|
|
4
|
+
* The loop must honor timeout_ms (stop polling + report incomplete state)
|
|
5
|
+
* instead of always running its full 60×2s iteration cap.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import piWebExtension from "../index";
|
|
11
|
+
|
|
12
|
+
// The web settings layer reads the agent-dir settings.json — isolate the
|
|
13
|
+
// agent dir so a host `web` section never leaks into these tests.
|
|
14
|
+
process.env.PI_CODING_AGENT_DIR = "/nonexistent-pi-agent-dir-for-web-tests";
|
|
15
|
+
|
|
16
|
+
// chai-compat helpers (assert-based)
|
|
17
|
+
function includes(haystack: unknown, needle: unknown): boolean {
|
|
18
|
+
if (typeof haystack === "string") return haystack.includes(String(needle));
|
|
19
|
+
if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
|
|
20
|
+
if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
|
|
21
|
+
if (v === needle) return true;
|
|
22
|
+
// chai's to.include on an array does DEEP membership for objects.
|
|
23
|
+
if (v && needle && typeof v === "object" && typeof needle === "object") {
|
|
24
|
+
try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
// chai's to.include on an OBJECT target: needle's properties are a subset.
|
|
29
|
+
if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
|
|
30
|
+
return deepIncludes(haystack, needle as Record<string, unknown>);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
function lengthOf(v: unknown): number {
|
|
35
|
+
if (Array.isArray(v)) return v.length;
|
|
36
|
+
if (typeof v === "string") return v.length;
|
|
37
|
+
if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
|
|
38
|
+
if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
|
|
39
|
+
throw new Error("lengthOf: value has no length/size");
|
|
40
|
+
}
|
|
41
|
+
/** Deep "includes" — every own key of `part` must exist on `obj` with a
|
|
42
|
+
* deep-equal value (chai's to.deep.include for object subjects). */
|
|
43
|
+
function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
|
|
44
|
+
if (Array.isArray(obj)) return includes(obj, part); // deep membership
|
|
45
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
46
|
+
return Object.entries(part).every(([k, v]) => {
|
|
47
|
+
try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function harness(): Record<string, any> {
|
|
52
|
+
const tools: Record<string, any> = {};
|
|
53
|
+
const pi: any = {
|
|
54
|
+
registerTool(tool: any) { tools[tool.name] = tool; },
|
|
55
|
+
on() {},
|
|
56
|
+
};
|
|
57
|
+
piWebExtension(pi);
|
|
58
|
+
return tools;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function jsonResponse(body: unknown, status = 200): Response {
|
|
62
|
+
return new Response(JSON.stringify(body), {
|
|
63
|
+
status,
|
|
64
|
+
headers: { "content-type": "application/json" },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("web_crawl light-mode poll loop", () => {
|
|
69
|
+
const ORIGINAL_FETCH = globalThis.fetch;
|
|
70
|
+
const SAVED_URL = process.env.FIRECRAWL_API_URL;
|
|
71
|
+
const SAVED_KEY = process.env.FIRECRAWL_API_KEY;
|
|
72
|
+
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
process.env.FIRECRAWL_API_URL = "http://firecrawl.test/v2";
|
|
75
|
+
process.env.FIRECRAWL_API_KEY = "test-key";
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
globalThis.fetch = ORIGINAL_FETCH;
|
|
80
|
+
if (SAVED_URL === undefined) delete process.env.FIRECRAWL_API_URL;
|
|
81
|
+
else process.env.FIRECRAWL_API_URL = SAVED_URL;
|
|
82
|
+
if (SAVED_KEY === undefined) delete process.env.FIRECRAWL_API_KEY;
|
|
83
|
+
else process.env.FIRECRAWL_API_KEY = SAVED_KEY;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("stops polling at timeout_ms and returns an honest incomplete-state note", async () => {
|
|
87
|
+
let getCalls = 0;
|
|
88
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
89
|
+
const url = String(input);
|
|
90
|
+
if (init?.method === "POST" && url.endsWith("/crawl")) return jsonResponse({ id: "c1" });
|
|
91
|
+
if (url.endsWith("/crawl/c1")) {
|
|
92
|
+
getCalls += 1;
|
|
93
|
+
return jsonResponse({ status: "scraping" });
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`unexpected fetch ${url}`);
|
|
96
|
+
}) as typeof fetch;
|
|
97
|
+
|
|
98
|
+
const tools = harness();
|
|
99
|
+
const res = await tools.web_crawl.execute(
|
|
100
|
+
"t1",
|
|
101
|
+
{ url: "https://example.com", mode: "light", poll: true, timeout_ms: 1000 },
|
|
102
|
+
new AbortController().signal,
|
|
103
|
+
undefined,
|
|
104
|
+
{},
|
|
105
|
+
);
|
|
106
|
+
// Exited on the deadline after one poll, not the 60-iteration cap.
|
|
107
|
+
assert.equal(getCalls, 1);
|
|
108
|
+
assert.ok(includes(res.content[0].text, "timeout_ms"));
|
|
109
|
+
assert.ok(includes(res.content[0].text, "scraping"));
|
|
110
|
+
assert.ok(includes(res.content[0].text, "incomplete"));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("still returns immediately when the crawl is already completed (no timeout_ms)", async () => {
|
|
114
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
115
|
+
const url = String(input);
|
|
116
|
+
if (init?.method === "POST" && url.endsWith("/crawl")) return jsonResponse({ id: "c2" });
|
|
117
|
+
if (url.endsWith("/crawl/c2")) {
|
|
118
|
+
return jsonResponse({ status: "completed", data: [{ markdown: "# Page", url: "https://example.com" }] });
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`unexpected fetch ${url}`);
|
|
121
|
+
}) as typeof fetch;
|
|
122
|
+
|
|
123
|
+
const tools = harness();
|
|
124
|
+
const res = await tools.web_crawl.execute(
|
|
125
|
+
"t2",
|
|
126
|
+
{ url: "https://example.com", mode: "light", poll: true },
|
|
127
|
+
new AbortController().signal,
|
|
128
|
+
undefined,
|
|
129
|
+
{},
|
|
130
|
+
);
|
|
131
|
+
assert.ok(!includes(res.content[0].text, "incomplete"));
|
|
132
|
+
assert.ok(includes(res.content[0].text, "Page"));
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for pi-web Crawl4AI client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { HttpError } from "../lib/retry";
|
|
8
|
+
|
|
9
|
+
describe("HttpError", () => {
|
|
10
|
+
it("formats error message with status and text", () => {
|
|
11
|
+
const err = new HttpError(401, "Unauthorized", '{"detail":"bad token"}');
|
|
12
|
+
assert.equal(err.status, 401);
|
|
13
|
+
assert.ok(includes(err.message, "HTTP 401: Unauthorized"));
|
|
14
|
+
assert.ok(includes(err.message, '{"detail":"bad token"}'));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("handles empty response text", () => {
|
|
18
|
+
const err = new HttpError(500, "Internal Server Error", "");
|
|
19
|
+
assert.equal(err.status, 500);
|
|
20
|
+
assert.equal(err.message, "HTTP 500: Internal Server Error");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("is instance of Error", () => {
|
|
24
|
+
const err = new HttpError(403, "Forbidden", "rate limit");
|
|
25
|
+
assert.ok(err instanceof Error);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Config + format integration: verify imported functions exist with correct sigs
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
import type { Crawl4aiConfig } from "../lib/config";
|
|
34
|
+
|
|
35
|
+
describe("Crawl4aiConfig interface", () => {
|
|
36
|
+
it("has expected shape", () => {
|
|
37
|
+
const config: Crawl4aiConfig = {
|
|
38
|
+
baseUrl: "http://localhost:11235",
|
|
39
|
+
apiToken: "token123",
|
|
40
|
+
timeoutMs: 30000,
|
|
41
|
+
};
|
|
42
|
+
assert.equal(config.baseUrl, "http://localhost:11235");
|
|
43
|
+
assert.equal(config.apiToken, "token123");
|
|
44
|
+
assert.equal(config.timeoutMs, 30000);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Verify client exports exist
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
import {
|
|
53
|
+
fetchCrawl4aiMarkdown,
|
|
54
|
+
fetchCrawl4aiCrawl,
|
|
55
|
+
fetchCrawl4aiScreenshot,
|
|
56
|
+
fetchCrawl4aiPdf,
|
|
57
|
+
fetchCrawl4aiHealth,
|
|
58
|
+
crawl4aiRequest,
|
|
59
|
+
} from "../lib/crawl4ai";
|
|
60
|
+
|
|
61
|
+
// chai-compat helpers (assert-based)
|
|
62
|
+
function includes(haystack: unknown, needle: unknown): boolean {
|
|
63
|
+
if (typeof haystack === "string") return haystack.includes(String(needle));
|
|
64
|
+
if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
|
|
65
|
+
if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
|
|
66
|
+
if (v === needle) return true;
|
|
67
|
+
// chai's to.include on an array does DEEP membership for objects.
|
|
68
|
+
if (v && needle && typeof v === "object" && typeof needle === "object") {
|
|
69
|
+
try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
});
|
|
73
|
+
// chai's to.include on an OBJECT target: needle's properties are a subset.
|
|
74
|
+
if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
|
|
75
|
+
return deepIncludes(haystack, needle as Record<string, unknown>);
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
function lengthOf(v: unknown): number {
|
|
80
|
+
if (Array.isArray(v)) return v.length;
|
|
81
|
+
if (typeof v === "string") return v.length;
|
|
82
|
+
if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
|
|
83
|
+
if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
|
|
84
|
+
throw new Error("lengthOf: value has no length/size");
|
|
85
|
+
}
|
|
86
|
+
/** Deep "includes" — every own key of `part` must exist on `obj` with a
|
|
87
|
+
* deep-equal value (chai's to.deep.include for object subjects). */
|
|
88
|
+
function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
|
|
89
|
+
if (Array.isArray(obj)) return includes(obj, part); // deep membership
|
|
90
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
91
|
+
return Object.entries(part).every(([k, v]) => {
|
|
92
|
+
try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe("Crawl4AI client exports", () => {
|
|
97
|
+
it("exports all expected functions", () => {
|
|
98
|
+
assert.equal(typeof fetchCrawl4aiMarkdown, 'function');
|
|
99
|
+
assert.equal(typeof fetchCrawl4aiCrawl, 'function');
|
|
100
|
+
assert.equal(typeof fetchCrawl4aiScreenshot, 'function');
|
|
101
|
+
assert.equal(typeof fetchCrawl4aiPdf, 'function');
|
|
102
|
+
assert.equal(typeof fetchCrawl4aiHealth, 'function');
|
|
103
|
+
assert.equal(typeof crawl4aiRequest, 'function');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// ceulen integration contract: per-tool kill-switch (ceulen.disabledTools →
|
|
2
|
+
// defaultActive:false), skill contributed via resources_discover, and the
|
|
3
|
+
// before_agent_start guidance hook gated on active web_* tools.
|
|
4
|
+
|
|
5
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
import webExtension from "../index";
|
|
12
|
+
|
|
13
|
+
const ALL_TOOLS = [
|
|
14
|
+
"web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf",
|
|
15
|
+
"web_interact", "web_research", "web_image", "web_chat", "web_status",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
function harness(opts: { disabledTools?: string[]; activeTools?: string[] } = {}) {
|
|
19
|
+
const tools: Record<string, { name: string; defaultActive?: boolean }> = {};
|
|
20
|
+
const handlers: Record<string, Function[]> = {};
|
|
21
|
+
const discoverResults: { skillPaths: string[] }[] = [];
|
|
22
|
+
const pi: any = {
|
|
23
|
+
registerTool(tool: any) { tools[tool.name] = tool; },
|
|
24
|
+
on(name: string, handler: Function) {
|
|
25
|
+
(handlers[name] ??= []).push(handler);
|
|
26
|
+
},
|
|
27
|
+
getActiveTools: () => opts.activeTools ?? [],
|
|
28
|
+
};
|
|
29
|
+
// Intercept resources_discover results (munin harness pattern).
|
|
30
|
+
const realOn = pi.on.bind(pi);
|
|
31
|
+
pi.on = (name: string, handler: Function) => {
|
|
32
|
+
if (name === "resources_discover") {
|
|
33
|
+
return realOn(name, (...args: unknown[]) => {
|
|
34
|
+
const r = (handler as (...a: unknown[]) => { skillPaths: string[] })(...args);
|
|
35
|
+
discoverResults.push(r);
|
|
36
|
+
return r;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return realOn(name, handler);
|
|
40
|
+
};
|
|
41
|
+
const oldDisabled = process.env.CEULEN_TEST_DISABLED_TOOLS;
|
|
42
|
+
// readDisabledTools reads the settings file — shield via PI_CODING_AGENT_DIR
|
|
43
|
+
// + a settings file carrying the disabled list.
|
|
44
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "web-ext-"));
|
|
45
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
46
|
+
if (opts.disabledTools?.length) {
|
|
47
|
+
fs.writeFileSync(path.join(dir, "settings.json"), JSON.stringify({ ceulen: { disabledTools: opts.disabledTools } }));
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
webExtension(pi);
|
|
51
|
+
} finally {
|
|
52
|
+
if (oldDisabled === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
53
|
+
else process.env.PI_CODING_AGENT_DIR = oldDisabled;
|
|
54
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
return { tools, handlers, discoverResults };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function callGuidance(handlers: Record<string, Function[]>, selectedTools?: string[]) {
|
|
60
|
+
return await handlers.before_agent_start[0]({ systemPrompt: "BASE", systemPromptOptions: { selectedTools } });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe("web module ceulen contract", () => {
|
|
64
|
+
let oldAgentDir: string | undefined;
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
oldAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
68
|
+
});
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
if (oldAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
71
|
+
else process.env.PI_CODING_AGENT_DIR = oldAgentDir;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("registers exactly the eleven web_* tools", () => {
|
|
75
|
+
const { tools } = harness();
|
|
76
|
+
assert.deepEqual(Object.keys(tools).sort(), [...ALL_TOOLS].sort());
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ceulen.disabledTools → defaultActive:false (inactive at registration)", () => {
|
|
80
|
+
const { tools } = harness({ disabledTools: ["web_search", "web_image"] });
|
|
81
|
+
assert.equal(tools.web_search!.defaultActive, false);
|
|
82
|
+
assert.equal(tools.web_image!.defaultActive, false);
|
|
83
|
+
assert.equal(tools.web_extract!.defaultActive, true);
|
|
84
|
+
assert.equal(tools.web_status!.defaultActive, true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("all tools default-active when the kill-switch list is empty", () => {
|
|
88
|
+
const { tools } = harness();
|
|
89
|
+
for (const name of ALL_TOOLS) assert.equal(tools[name]!.defaultActive, true, name);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("contributes exactly one skill: skills/web (kill-switch gated by factory load)", () => {
|
|
93
|
+
const { handlers } = harness();
|
|
94
|
+
// resources_discover is a subscription — invoke the handler as pi would.
|
|
95
|
+
const discoverResults = [handlers.resources_discover![0]!()];
|
|
96
|
+
assert.equal(discoverResults.length, 1);
|
|
97
|
+
assert.equal(discoverResults[0]!.skillPaths.length, 1);
|
|
98
|
+
assert.ok(discoverResults[0]!.skillPaths[0]!.endsWith(path.join("skills", "web")));
|
|
99
|
+
assert.ok(fs.existsSync(path.join(discoverResults[0]!.skillPaths[0]!, "SKILL.md")));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("guidance injects only when a web_* tool is active (selectedTools)", async () => {
|
|
103
|
+
const { handlers } = harness();
|
|
104
|
+
const hit = await callGuidance(handlers, ["read", "web_search"]);
|
|
105
|
+
assert.ok(String(hit?.systemPrompt).includes("BASE"));
|
|
106
|
+
assert.ok(String(hit?.systemPrompt).includes("Web Tool Routing"));
|
|
107
|
+
const miss = await callGuidance(handlers, ["read", "bash", "grep"]);
|
|
108
|
+
assert.equal(miss, undefined);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("guidance falls back to pi.getActiveTools() when selectedTools is undefined", async () => {
|
|
112
|
+
const { handlers } = harness({ activeTools: ["read", "web_extract"] });
|
|
113
|
+
const hit = await callGuidance(handlers);
|
|
114
|
+
assert.ok(String(hit?.systemPrompt).includes("Web Tool Routing"));
|
|
115
|
+
const quiet = harness({ activeTools: ["read", "bash"] });
|
|
116
|
+
assert.equal(await callGuidance(quiet.handlers), undefined);
|
|
117
|
+
});
|
|
118
|
+
});
|