diff --git a/.kit.toml b/.kit.toml index c76096ed..f6d0faaf 100644 --- a/.kit.toml +++ b/.kit.toml @@ -35,10 +35,6 @@ registry = "clawhub" [skills.optional] "discord" = "*" -[web.search] -provider = "searxng" -url = "http://localhost:8080" - [governance] enabled = true environment = "dev" # dev, staging, prod (auto-detected from git branch if not set) diff --git a/README.md b/README.md index 71a27f6e..5c44bce4 100644 --- a/README.md +++ b/README.md @@ -469,15 +469,6 @@ kit add vercel/hosting # Link repository to Vercel kit add expo/eas ``` -- **searxng/instance**: Privacy-respecting search engine - - Requires: `docker` and `docker-compose` - - Provisions: Local SearXNG instance - - Secrets: `SEARXNG_URL`, `SEARXNG_SECRET` - - Example: - ```bash - kit add searxng/instance - ``` - The full adapter set (each provisions/reuses the relevant keys; run `kit add `): | Service | Purpose | @@ -502,7 +493,6 @@ The full adapter set (each provisions/reuses the relevant keys; run `kit add ` (see [docs/PLUGIN_DEVELOPMENT.md](./docs/PLUGIN_DEVELOPMENT.md)). diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 85fb8c4d..084e8e91 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -7,7 +7,6 @@ import { stripePaymentsAdapter } from "./stripe-payments.js"; import { supabaseDbAdapter } from "./supabase-db.js"; import { vercelHostingAdapter } from "./vercel-hosting.js"; import { expoEasAdapter } from "./expo-eas.js"; -import { searxngInstanceAdapter } from "./searxng-instance.js"; import { neonDbAdapter } from "./neon-db.js"; import { clerkAuthAdapter } from "./clerk-auth.js"; import { upstashRedisAdapter } from "./upstash-redis.js"; @@ -30,7 +29,6 @@ export const adapters: AdapterRegistry = { "supabase/db": supabaseDbAdapter, "vercel/hosting": vercelHostingAdapter, "expo/eas": expoEasAdapter, - "searxng/instance": searxngInstanceAdapter, "neon/db": neonDbAdapter, "clerk/auth": clerkAuthAdapter, "upstash/redis": upstashRedisAdapter, diff --git a/src/adapters/searxng-instance.ts b/src/adapters/searxng-instance.ts deleted file mode 100644 index b0a288ca..00000000 --- a/src/adapters/searxng-instance.ts +++ /dev/null @@ -1,248 +0,0 @@ -import type { ServiceAdapter, AdapterContext, ProvisionResult } from "./types.js"; -import { exec } from "../utils/exec.js"; - - -/** - * Helper to fetch with timeout using AbortController - */ -async function fetchWithTimeout( - url: string, - timeoutMs: number = 5000, -): Promise { - const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), timeoutMs); - try { - return await fetch(url, { signal: controller.signal }); - } finally { - clearTimeout(timeout); - } -} - -/** - * SearXNG Instance Adapter - * Sets up a self-hosted SearXNG search instance for agents - */ -export const searxngInstanceAdapter: ServiceAdapter = { - name: "searxng/instance", - description: "Self-hosted SearXNG search engine", - - getRequiredTools(): string[] { - return ["docker"]; - }, - - async check(context: AdapterContext): Promise { - try { - // Check if SearXNG environment variables are configured - if (context.existingEnv.SEARXNG_URL) { - // Try to ping the health check endpoint - try { - const url = context.existingEnv.SEARXNG_URL; - const response = await fetchWithTimeout(`${url}/health`); - return response.ok; - } catch { - // URL exists but endpoint unreachable - return false; - } - } - - // Check if SearXNG is running in Docker on localhost:8080 - try { - const { stdout } = await exec("docker", [ - "ps", - "--filter", - "name=searxng", - "--format", - "{{.Status}}", - ], { - timeout: 10_000, - }); - - if (stdout.includes("Up")) { - // Try to verify it's responding - try { - const response = await fetchWithTimeout("http://localhost:8080/health"); - return response.ok; - } catch { - return false; - } - } - } catch { - // Docker command failed - } - - return false; - } catch { - return false; - } - }, - - async provision(context: AdapterContext): Promise { - try { - // Check if Docker is installed - try { - await exec("docker", ["--version"], { timeout: 10_000 }); - } catch { - return { - success: false, - error: "Docker not installed", - message: "SearXNG requires Docker. Please install Docker and try again.", - }; - } - - // Check if SearXNG container already exists and is running - try { - const { stdout } = await exec("docker", [ - "ps", - "-a", - "--filter", - "name=searxng", - "--format", - "{{.Names}}", - ], { - timeout: 10_000, - }); - - if (stdout.includes("searxng")) { - // Container exists, check if it's running - const { stdout: statusOutput } = await exec("docker", [ - "ps", - "--filter", - "name=searxng", - "--format", - "{{.Status}}", - ], { - timeout: 10_000, - }); - - if (statusOutput.includes("Up")) { - // Already running, verify it's healthy - try { - const response = await fetchWithTimeout("http://localhost:8080/health"); - if (response.ok) { - return { - success: true, - message: "SearXNG is already running", - secrets: { - SEARXNG_URL: "http://localhost:8080", - }, - config: { - service: "searxng/instance", - container: "searxng", - port: 8080, - }, - }; - } - } catch { - // Container is running but not responding, will restart below - } - } - - // Container exists but not running, start it - try { - await exec("docker", ["start", "searxng"], { - timeout: 30_000, - }); - - // Wait a bit for container to start - await new Promise((resolve) => setTimeout(resolve, 2000)); - - // Verify it's responding - try { - const response = await fetchWithTimeout("http://localhost:8080/health"); - if (response.ok) { - return { - success: true, - message: "SearXNG container started successfully", - secrets: { - SEARXNG_URL: "http://localhost:8080", - }, - config: { - service: "searxng/instance", - container: "searxng", - port: 8080, - }, - }; - } - } catch (e) { - return { - success: false, - error: "SearXNG container started but health check failed", - message: "Container is running but not responding to health checks", - }; - } - } catch (e) { - return { - success: false, - error: e instanceof Error ? e.message : "Failed to start container", - message: "Could not start existing SearXNG container", - }; - } - } - } catch { - // Container doesn't exist, continue to creation - } - - // Create and start SearXNG container - try { - await exec("docker", [ - "run", - "-d", - "--name", - "searxng", - "-p", - "8080:8080", - "-e", - "SEARXNG_PORT=8080", - "searxng/searxng:latest", - ], { - timeout: 120_000, // 2 minutes for image pull and container creation - }); - - // Wait for container to be healthy - let attempts = 0; - const maxAttempts = 30; - while (attempts < maxAttempts) { - try { - const response = await fetchWithTimeout("http://localhost:8080/health"); - if (response.ok) { - return { - success: true, - message: "SearXNG container created and started successfully", - secrets: { - SEARXNG_URL: "http://localhost:8080", - }, - config: { - service: "searxng/instance", - container: "searxng", - port: 8080, - }, - }; - } - } catch { - // Not ready yet, wait and retry - await new Promise((resolve) => setTimeout(resolve, 1000)); - attempts++; - } - } - - return { - success: false, - error: "SearXNG container started but health check failed after timeout", - message: "Container started but did not become healthy within timeout period", - }; - } catch (error) { - return { - success: false, - error: error instanceof Error ? error.message : "Unknown error", - message: "Failed to create and start SearXNG container", - }; - } - } catch (error: unknown) { - return { - success: false, - error: error instanceof Error ? error.message : "Unknown error", - message: "Failed to provision SearXNG instance", - }; - } - }, -}; diff --git a/src/check-web-search.test.ts b/src/check-web-search.test.ts deleted file mode 100644 index 6cab3af9..00000000 --- a/src/check-web-search.test.ts +++ /dev/null @@ -1,212 +0,0 @@ -import { describe, it, afterEach, mock } from "node:test"; -import assert from "node:assert/strict"; -import { checkWebSearch } from "./check-web-search.js"; - -describe("checkWebSearch - no config", () => { - it("returns not configured when no config provided", async () => { - const result = await checkWebSearch(undefined); - assert.equal(result.configured, false); - assert.equal(result.healthy, false); - assert.equal(result.provider, "none"); - }); - - it("returns not configured when provider is missing", async () => { - const result = await checkWebSearch({} as any); - assert.equal(result.configured, false); - assert.equal(result.provider, "none"); - }); -}); - -describe("checkWebSearch - searxng", () => { - afterEach(() => mock.restoreAll()); - - it("returns not configured when URL is missing", async () => { - const result = await checkWebSearch({ provider: "searxng" }); - assert.equal(result.configured, false); - assert.ok(result.error?.includes("URL not configured")); - }); - - it("returns healthy when server responds with 200", async () => { - mock.method(globalThis, "fetch", async () => - new Response("", { status: 200 }), - ); - - const result = await checkWebSearch({ - provider: "searxng", - url: "http://localhost:8080", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, true); - assert.equal(result.url, "http://localhost:8080"); - }); - - it("returns unhealthy when server returns non-ok status", async () => { - mock.method(globalThis, "fetch", async () => - new Response("", { status: 503 }), - ); - - const result = await checkWebSearch({ - provider: "searxng", - url: "http://localhost:8080", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("503")); - }); - - it("returns unhealthy when server is unreachable", async () => { - mock.method(globalThis, "fetch", async () => { - throw new Error("ECONNREFUSED"); - }); - - const result = await checkWebSearch({ - provider: "searxng", - url: "http://localhost:8080", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("ECONNREFUSED")); - }); -}); - -describe("checkWebSearch - brave", () => { - afterEach(() => mock.restoreAll()); - - it("returns not configured when API key is missing", async () => { - const result = await checkWebSearch({ provider: "brave" }); - assert.equal(result.configured, false); - assert.ok(result.error?.includes("API key not configured")); - }); - - it("returns healthy when API key is valid (200 response)", async () => { - mock.method(globalThis, "fetch", async () => - new Response(JSON.stringify({ results: [] }), { status: 200 }), - ); - - const result = await checkWebSearch({ - provider: "brave", - apiKey: "valid-key-123", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, true); - }); - - it("returns unhealthy on 401 (invalid key)", async () => { - mock.method(globalThis, "fetch", async () => - new Response("Unauthorized", { status: 401 }), - ); - - const result = await checkWebSearch({ - provider: "brave", - apiKey: "bad-key", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("Invalid")); - }); - - it("returns unhealthy on 403 (forbidden)", async () => { - mock.method(globalThis, "fetch", async () => - new Response("Forbidden", { status: 403 }), - ); - - const result = await checkWebSearch({ - provider: "brave", - apiKey: "bad-key", - }); - - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("Invalid")); - }); -}); - -describe("checkWebSearch - google", () => { - afterEach(() => mock.restoreAll()); - - it("returns not configured without apiKey + cx", async () => { - const result = await checkWebSearch({ provider: "google" }); - assert.equal(result.configured, false); - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("cx")); - }); - - it("returns healthy with valid apiKey + cx (200 response)", async () => { - mock.method(globalThis, "fetch", async () => - new Response(JSON.stringify({ items: [] }), { status: 200 }), - ); - const result = await checkWebSearch({ provider: "google", apiKey: "k", cx: "engine-id" }); - assert.equal(result.configured, true); - assert.equal(result.healthy, true); - }); - - it("returns unhealthy on 403 (invalid key or cx)", async () => { - mock.method(globalThis, "fetch", async () => new Response("Forbidden", { status: 403 })); - const result = await checkWebSearch({ provider: "google", apiKey: "k", cx: "x" }); - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("Invalid")); - }); -}); - -describe("checkWebSearch - custom", () => { - afterEach(() => mock.restoreAll()); - - it("returns not configured when URL is missing", async () => { - const result = await checkWebSearch({ provider: "custom" }); - assert.equal(result.configured, false); - assert.ok(result.error?.includes("URL not configured")); - }); - - it("returns healthy on 200", async () => { - mock.method(globalThis, "fetch", async () => - new Response("", { status: 200 }), - ); - - const result = await checkWebSearch({ - provider: "custom", - url: "http://my-search.local", - }); - - assert.equal(result.healthy, true); - }); - - it("returns healthy on 404 (custom endpoints may lack health endpoint)", async () => { - mock.method(globalThis, "fetch", async () => - new Response("Not Found", { status: 404 }), - ); - - const result = await checkWebSearch({ - provider: "custom", - url: "http://my-search.local", - }); - - assert.equal(result.configured, true); - assert.equal(result.healthy, true); - }); - - it("returns unhealthy on 500", async () => { - mock.method(globalThis, "fetch", async () => - new Response("Error", { status: 500 }), - ); - - const result = await checkWebSearch({ - provider: "custom", - url: "http://my-search.local", - }); - - assert.equal(result.healthy, false); - assert.ok(result.error?.includes("500")); - }); -}); - -describe("checkWebSearch - unknown provider", () => { - it("returns error for unknown provider", async () => { - const result = await checkWebSearch({ provider: "bing" as any }); - assert.equal(result.configured, false); - assert.ok(result.error?.includes("Unknown provider")); - }); -}); diff --git a/src/check-web-search.ts b/src/check-web-search.ts deleted file mode 100644 index f6ee9e06..00000000 --- a/src/check-web-search.ts +++ /dev/null @@ -1,222 +0,0 @@ -import type { WebSearchConfig } from "./config.js"; - -/** - * Helper to fetch with timeout using AbortController - */ -async function fetchWithTimeout( - url: string, - init?: RequestInit & { timeout?: number }, -): Promise { - const { timeout: timeoutMs = 5000, ...fetchInit } = init || {}; - const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), timeoutMs); - try { - return await fetch(url, { ...fetchInit, signal: controller.signal }); - } finally { - clearTimeout(timeoutId); - } -} - -export interface WebSearchStatus { - provider: string; - configured: boolean; - healthy: boolean; - url?: string; - error?: string; -} - -/** - * Check the status of a web search provider - */ -export async function checkWebSearch(config?: WebSearchConfig): Promise { - if (!config || !config.provider) { - return { - provider: "none", - configured: false, - healthy: false, - error: "No web search provider configured", - }; - } - - const provider = config.provider; - const url = config.url; - - // Check provider-specific requirements - switch (provider) { - case "searxng": - if (!url) { - return { - provider, - configured: false, - healthy: false, - error: "SearXNG URL not configured (web.search.url required)", - }; - } - - try { - // SearXNG doesn't have a /health endpoint, so check the root - const response = await fetchWithTimeout(url); - if (response.ok) { - return { - provider, - configured: true, - healthy: true, - url, - }; - } - return { - provider, - configured: true, - healthy: false, - url, - error: `Server returned status ${response.status}`, - }; - } catch (err) { - return { - provider, - configured: true, - healthy: false, - url, - error: err instanceof Error ? err.message : "Server unreachable", - }; - } - - case "brave": - if (!config.apiKey) { - return { - provider, - configured: false, - healthy: false, - error: "Brave Search API key not configured (web.search.apiKey required)", - }; - } - - try { - // Test Brave Search API - const response = await fetchWithTimeout( - "https://api.search.brave.com/res/v1/web/search?q=test", - { - headers: { - "Accept": "application/json", - "X-Subscription-Token": config.apiKey, - }, - } as RequestInit, - ); - - if (response.ok) { - return { - provider, - configured: true, - healthy: true, - }; - } - if (response.status === 401 || response.status === 403) { - return { - provider, - configured: true, - healthy: false, - error: "Invalid Brave Search API key (authentication failed)", - }; - } - return { - provider, - configured: true, - healthy: false, - error: `API returned status ${response.status}`, - }; - } catch (err) { - return { - provider, - configured: true, - healthy: false, - error: err instanceof Error ? err.message : "API check failed", - }; - } - - case "google": - if (!config.apiKey || !config.cx) { - return { - provider, - configured: false, - healthy: false, - error: "Google Custom Search needs web.search.apiKey + web.search.cx (Programmable Search engine id)", - }; - } - try { - // Custom Search JSON API — key + cx are query params by design. - const response = await fetchWithTimeout( - `https://www.googleapis.com/customsearch/v1?key=${encodeURIComponent(config.apiKey)}&cx=${encodeURIComponent(config.cx)}&q=test&num=1`, - ); - if (response.ok) { - return { provider, configured: true, healthy: true }; - } - if (response.status === 400 || response.status === 401 || response.status === 403) { - return { - provider, - configured: true, - healthy: false, - error: "Invalid Google API key or cx (request rejected)", - }; - } - return { - provider, - configured: true, - healthy: false, - error: `API returned status ${response.status}`, - }; - } catch (err) { - return { - provider, - configured: true, - healthy: false, - error: err instanceof Error ? err.message : "API check failed", - }; - } - - case "custom": - if (!url) { - return { - provider, - configured: false, - healthy: false, - error: "Custom search URL not configured (web.search.url required)", - }; - } - - try { - const response = await fetchWithTimeout(url); - if (response.ok || response.status === 404) { - // 404 is OK for custom URLs that might not have a health endpoint - return { - provider, - configured: true, - healthy: true, - url, - }; - } - return { - provider, - configured: true, - healthy: false, - url, - error: `URL returned status ${response.status}`, - }; - } catch (err) { - return { - provider, - configured: true, - healthy: false, - url, - error: err instanceof Error ? err.message : "URL check failed", - }; - } - - default: - return { - provider, - configured: false, - healthy: false, - error: `Unknown provider: ${provider}`, - }; - } -} diff --git a/src/cli.ts b/src/cli.ts index 9501bdb1..102da871 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,7 +10,6 @@ import { checkServices } from "./check-services.js"; import { checkSecrets } from "./check-secrets.js"; import { checkSecurity } from "./check-security.js"; import { syncSecurityFindings } from "./findings-track.js"; -import { checkWebSearch } from "./check-web-search.js"; import { installTools } from "./install.js"; import { loginServices } from "./login.js"; import { check1PasswordStatus, detect1PasswordMode } from "./onepassword.js"; @@ -76,7 +75,6 @@ import { printServicesTable, printSecretsTable, printSkillsTable, - printWebSearchStatus, printSecurityTable, printLockTable, printSummary, @@ -239,9 +237,6 @@ async function cmdCheck(): Promise { config.hooks && isGitRepository() ? await step("git hooks", () => checkHooks(config.hooks!)) : []; - const webSearchResult = config.web?.search - ? await step("web search", () => checkWebSearch(config.web!.search!)) - : null; const securityResults = await step("security scan", () => checkSecurity()); const lockResults = await step("lock files", () => checkLockFiles(config)); @@ -318,16 +313,6 @@ async function cmdCheck(): Promise { detail: h.detail, category: "hooks", })), - ...(webSearchResult - ? [ - { - name: webSearchResult.provider, - status: (webSearchResult.healthy ? "pass" : "fail") as JsonCheck["status"], - detail: webSearchResult.error ?? (webSearchResult.healthy ? "healthy" : "unhealthy"), - category: "web-search", - }, - ] - : []), ...lockResults.map((l) => ({ name: l.category === "skills-lock" ? "skills-lock.json" : "cli-lock.json", status: (l.inSync ? "pass" : l.exists ? "warn" : "fail") as JsonCheck["status"], @@ -368,7 +353,6 @@ async function cmdCheck(): Promise { printServicesTable(serviceResults); printSecretsTable(secretResults.templateExists, secretResults.keys); printSkillsTable(skillResults); - printWebSearchStatus(webSearchResult); printLockTable(lockResults); // Print hooks status if configured diff --git a/src/completions.ts b/src/completions.ts index 93ce6738..e316b2d5 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -12,7 +12,7 @@ const COMMANDS = [ const ADAPTERS = [ "stripe/payments", "supabase/db", "vercel/hosting", "expo/eas", - "searxng/instance", "neon/db", "clerk/auth", "upstash/redis", + "neon/db", "clerk/auth", "upstash/redis", "cloudflare/r2", "resend/email", "planetscale/db", "loops/email", "liveblocks/realtime", "trigger/background", "inngest/background", "flagsmith/flags", "sentry/monitoring", "tinybird/analytics", "posthog/analytics", diff --git a/src/config.ts b/src/config.ts index 569a5ee9..03bcd789 100644 --- a/src/config.ts +++ b/src/config.ts @@ -73,18 +73,6 @@ export interface SkillsConfig { optional?: Record; } -/** - * Web search provider configuration - * Allows agents to use local or alternative search providers - */ -export interface WebSearchConfig { - provider?: "brave" | "searxng" | "google" | "custom"; - url?: string; - apiKey?: string; - /** Google Programmable Search engine id (cx) — required for the google provider. */ - cx?: string; -} - /** * Environment-specific access permissions * Parsed from [governance.access.dev], [governance.access.staging], [governance.access.prod] @@ -284,9 +272,6 @@ export interface kitConfig { hooks?: HooksConfig; /** Per-project CLI context lock (account+project per tool). */ context?: ContextConfig; - web?: { - search?: WebSearchConfig; - }; /** Named environment overrides: [env.staging.*], [env.production.*] */ env?: Record; /** Declared MCP-server connections. See McpConfig + src/mcp-orchestrator.ts. */ @@ -455,24 +440,9 @@ const GovernanceConfigSchema = z const HooksConfigSchema = z.record(z.string(), z.array(z.string()).optional()).optional(); -const WebConfigSchema = z - .object({ - search: z - .object({ - provider: z.enum(["brave", "searxng", "google", "custom"]).optional(), - url: z.string().optional(), - apiKey: z.string().optional(), - cx: z.string().optional(), - }) - .passthrough() - .optional(), - }) - .passthrough() - .optional(); - // Known top-level section names — used to detect typos const KNOWN_SECTIONS = new Set([ - "tools", "services", "secrets", "skills", "governance", "hooks", "web", "setup", "env", "context", "memory", "update", + "tools", "services", "secrets", "skills", "governance", "hooks", "setup", "env", "context", "memory", "update", ]); const kitConfigSchema = z @@ -507,7 +477,6 @@ const kitConfigSchema = z }) .passthrough() .optional(), - web: WebConfigSchema, setup: z .object({ install: z.string().optional(), diff --git a/src/mcp-server.ts b/src/mcp-server.ts index eb23eb10..eacf2103 100644 --- a/src/mcp-server.ts +++ b/src/mcp-server.ts @@ -12,7 +12,6 @@ import { checkLockFiles } from "./check-lock.js"; import { installTools } from "./install.js"; import { loginServices } from "./login.js"; import { generateSecrets } from "./secrets.js"; -import { checkWebSearch } from "./check-web-search.js"; import { checkHooks, isGitRepository } from "./check-hooks.js"; import { readSkillsLock, @@ -88,7 +87,6 @@ function register_kit_check(server: McpServer): void { const skillResults = config.skills ? await checkSkills(config.skills) : []; const hookResults = config.hooks && isGitRepository() ? await checkHooks(config.hooks) : []; - const webSearchResult = config.web?.search ? await checkWebSearch(config.web.search) : null; const securityResults = await checkSecurity(); const lockResults = await checkLockFiles(config); @@ -114,7 +112,6 @@ function register_kit_check(server: McpServer): void { secrets: secretResults.keys, skills: skillResults, hooks: hookResults, - webSearch: webSearchResult, security: securityResults, locks: lockResults, }, diff --git a/src/output.ts b/src/output.ts index 825d6a59..fd12913f 100644 --- a/src/output.ts +++ b/src/output.ts @@ -4,7 +4,6 @@ import type { SecretStatus } from "./check-secrets.js"; import type { SkillCheckResult } from "./check-skills.js"; import type { SecurityCheckResult } from "./check-security.js"; import type { LockCheckResult } from "./check-lock.js"; -import type { WebSearchStatus } from "./check-web-search.js"; import { safeStatusLine } from "./utils/redactSecrets.js"; // ANSI color codes @@ -199,23 +198,6 @@ export function printSkillsTable(skills: SkillCheckResult[]): void { } } - export function printWebSearchStatus(status: WebSearchStatus | null): void { - if (!status) return; - - header("Web Search"); - - const icon = status.healthy ? CHECK : CROSS; - const name = pad(status.provider, 14); - const configured = status.configured ? `${c.green}configured${c.reset}` : `${c.yellow}not configured${c.reset}`; - const health = status.healthy ? `${c.green}healthy${c.reset}` : `${c.red}unhealthy${c.reset}`; - const detail = status.error ? `${c.gray}${status.error}${c.reset}` : status.url ? `${c.gray}${status.url}${c.reset}` : ""; - - console.log(` ${icon} ${name} ${configured} ${health}`); - if (detail) { - console.log(` ${detail}`); - } - } - export function printSecurityTable(results: SecurityCheckResult[]): void { if (results.length === 0) return; diff --git a/src/plugin-registry.test.ts b/src/plugin-registry.test.ts deleted file mode 100644 index e7c371bb..00000000 --- a/src/plugin-registry.test.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { describe, it } from "node:test"; -import assert from "node:assert/strict"; -import { - PluginRegistry, - createRegistryFromSkillsLock, - getValidWebSearchProviders, - type PluginManifest, -} from "./plugin-registry.js"; -import type { SkillsLockFile } from "./skills.js"; - -function manifest(name: string, capabilities: PluginManifest["capabilities"]): PluginManifest { - return { name, version: "1.0.0", capabilities }; -} - -describe("PluginRegistry", () => { - it("registerPlugin + getWebSearchProviders surfaces only matching type", () => { - const r = new PluginRegistry(); - r.registerPlugin( - manifest("searxng-plugin", [ - { name: "searxng", type: "web_search_provider", version: "1.0.0" }, - { name: "other", type: "tool", version: "1.0.0" }, - ]), - ); - const providers = r.getWebSearchProviders(); - assert.equal(providers.size, 1); - assert.ok(providers.has("searxng")); - }); - - it("getCapabilitiesByType filters across plugins", () => { - const r = new PluginRegistry(); - r.registerPlugin( - manifest("a", [{ name: "x", type: "secret_store", version: "1.0.0" }]), - ); - r.registerPlugin( - manifest("b", [{ name: "y", type: "secret_store", version: "1.0.0" }]), - ); - r.registerPlugin( - manifest("c", [{ name: "z", type: "tool", version: "1.0.0" }]), - ); - const stores = r.getCapabilitiesByType("secret_store"); - assert.equal(stores.size, 2); - assert.ok(stores.has("x")); - assert.ok(stores.has("y")); - assert.ok(!stores.has("z")); - }); - - it("hasProvider + getProvider return correct values", () => { - const r = new PluginRegistry(); - r.registerPlugin( - manifest("p", [ - { name: "searxng", type: "web_search_provider", version: "1.0.0" }, - ]), - ); - assert.equal(r.hasProvider("searxng"), true); - assert.equal(r.hasProvider("brave"), false); - const cap = r.getProvider("searxng"); - assert.equal(cap?.type, "web_search_provider"); - assert.equal(r.getProvider("missing"), undefined); - }); - - it("re-registering same plugin@version replaces capabilities", () => { - const r = new PluginRegistry(); - r.registerPlugin(manifest("p", [{ name: "old", type: "tool", version: "1.0.0" }])); - r.registerPlugin(manifest("p", [{ name: "new", type: "tool", version: "1.0.0" }])); - const tools = r.getCapabilitiesByType("tool"); - assert.equal(tools.size, 1); - assert.ok(tools.has("new")); - assert.ok(!tools.has("old")); - }); - - it("clear() empties the registry", () => { - const r = new PluginRegistry(); - r.registerPlugin(manifest("p", [{ name: "x", type: "tool", version: "1.0.0" }])); - r.clear(); - assert.equal(r.getCapabilitiesByType("tool").size, 0); - }); -}); - -describe("createRegistryFromSkillsLock", () => { - it("registers searxng as a web_search_provider", () => { - const lock: SkillsLockFile = { - version: 1, - generated: "2026-01-01T00:00:00Z", - skills: { - searxng: { version: "1.0.0", source: "claude-skills" } as never, - }, - } as unknown as SkillsLockFile; - const r = createRegistryFromSkillsLock(lock); - assert.equal(r.hasProvider("searxng"), true); - const cap = r.getProvider("searxng"); - assert.equal(cap?.type, "web_search_provider"); - assert.equal((cap?.config as { url: string }).url, "http://localhost:8080"); - }); - - it("ignores skills that aren't searxng", () => { - const lock: SkillsLockFile = { - version: 1, - generated: "2026-01-01T00:00:00Z", - skills: { - "some-other-skill": { version: "1.0.0", source: "claude-skills" } as never, - }, - } as unknown as SkillsLockFile; - const r = createRegistryFromSkillsLock(lock); - assert.equal(r.getWebSearchProviders().size, 0); - }); - - it("matches skill names that contain 'searxng' (path-prefixed)", () => { - const lock: SkillsLockFile = { - version: 1, - generated: "2026-01-01T00:00:00Z", - skills: { - "anthropics/searxng-skill": { version: "2.0.0", source: "claude-skills" } as never, - }, - } as unknown as SkillsLockFile; - const r = createRegistryFromSkillsLock(lock); - assert.equal(r.hasProvider("searxng"), true); - }); -}); - -describe("getValidWebSearchProviders", () => { - it("returns the built-in set when no registry passed", () => { - const providers = getValidWebSearchProviders(); - assert.deepEqual(providers.sort(), ["brave", "custom", "google", "searxng"]); - }); - - it("merges built-ins with plugin-registered providers (deduped)", () => { - const r = new PluginRegistry(); - r.registerPlugin( - manifest("p", [ - // Already in built-ins — should not duplicate. - { name: "searxng", type: "web_search_provider", version: "1.0.0" }, - // Net-new from plugin. - { name: "kagi", type: "web_search_provider", version: "1.0.0" }, - ]), - ); - const providers = getValidWebSearchProviders(r); - assert.deepEqual(providers.sort(), ["brave", "custom", "google", "kagi", "searxng"]); - }); -}); diff --git a/src/plugin-registry.ts b/src/plugin-registry.ts deleted file mode 100644 index 4fbf0408..00000000 --- a/src/plugin-registry.ts +++ /dev/null @@ -1,147 +0,0 @@ -import type { SkillsLockFile } from "./skills.js"; - -/** - * Capability metadata that a plugin can expose - */ -export interface PluginCapability { - name: string; - type: "web_search_provider" | "tool" | "secret_store" | "service" | string; - version: string; - config?: Record; - metadata?: Record; -} - -/** - * Plugin manifest that describes what a plugin provides - */ -export interface PluginManifest { - name: string; - version: string; - capabilities: PluginCapability[]; -} - -/** - * Registry for dynamically discovering plugin capabilities - */ -export class PluginRegistry { - private capabilities: Map = new Map(); - - /** - * Register a plugin with its capabilities - */ - registerPlugin(plugin: PluginManifest): void { - const key = `${plugin.name}@${plugin.version}`; - this.capabilities.set(key, plugin.capabilities); - } - - /** - * Get all web_search providers from registered plugins - */ - getWebSearchProviders(): Map { - const providers = new Map(); - - for (const capabilities of this.capabilities.values()) { - for (const capability of capabilities) { - if (capability.type === "web_search_provider") { - providers.set(capability.name, capability); - } - } - } - - return providers; - } - - /** - * Get all capabilities of a specific type - */ - getCapabilitiesByType(type: string): Map { - const result = new Map(); - - for (const capabilities of this.capabilities.values()) { - for (const capability of capabilities) { - if (capability.type === type) { - result.set(capability.name, capability); - } - } - } - - return result; - } - - /** - * Check if a provider is registered - */ - hasProvider(name: string): boolean { - const providers = this.getWebSearchProviders(); - return providers.has(name); - } - - /** - * Get a specific provider capability - */ - getProvider(name: string): PluginCapability | undefined { - const providers = this.getWebSearchProviders(); - return providers.get(name); - } - - /** - * Clear all registered capabilities - */ - clear(): void { - this.capabilities.clear(); - } -} - -/** - * Create a plugin registry from a skills lock file - * This discovers plugin capabilities from the skills-lock.json - */ -export function createRegistryFromSkillsLock(skillsLock: SkillsLockFile): PluginRegistry { - const registry = new PluginRegistry(); - - // For now, we'll create a basic registry structure. - // In a real implementation, this would: - // 1. Load plugin manifests from the ClawhHub registry - // 2. Parse plugin capability declarations - // 3. Register them with the registry - - // As a starting point, we'll support some known plugin patterns: - // - searxng skill as a web_search_provider - - for (const [skillName, skillEntry] of Object.entries(skillsLock.skills)) { - if (skillName.includes("searxng")) { - // Register SearXNG as a web_search_provider if it's in the skills - const plugin: PluginManifest = { - name: skillName, - version: skillEntry.version, - capabilities: [ - { - name: "searxng", - type: "web_search_provider", - version: skillEntry.version, - config: { - url: "http://localhost:8080", - }, - }, - ], - }; - registry.registerPlugin(plugin); - } - } - - return registry; -} - -/** - * Get all valid web_search provider names (both built-in and plugin-registered) - */ -export function getValidWebSearchProviders(registry?: PluginRegistry): string[] { - const builtIn = ["brave", "google", "searxng", "custom"]; - - if (!registry) { - return builtIn; - } - - const pluginProviders = Array.from(registry.getWebSearchProviders().keys()); - return Array.from(new Set([...builtIn, ...pluginProviders])); -} diff --git a/src/validation/dynamic-schema.ts b/src/validation/dynamic-schema.ts deleted file mode 100644 index 03df43d5..00000000 --- a/src/validation/dynamic-schema.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { z } from "zod"; -import type { PluginRegistry } from "../plugin-registry.js"; - -/** - * Create a dynamic Zod schema for web_search provider validation - * that includes both built-in and plugin-registered providers - */ -export function createWebSearchProviderSchema( - registry?: PluginRegistry, -): z.ZodType { - const builtInProviders = ["brave", "google", "searxng", "custom"]; - - let providers = builtInProviders; - - if (registry) { - const pluginProviders = Array.from(registry.getWebSearchProviders().keys()); - providers = Array.from(new Set([...builtInProviders, ...pluginProviders])); - } - - return z.enum(providers as [string, ...string[]]); -} - -/** - * Create a dynamic schema for web search configuration - * that validates provider names against registered plugins - */ -export function createWebSearchConfigSchema( - registry?: PluginRegistry, -): z.ZodType<{ provider?: string; url?: string; apiKey?: string }> { - const providerSchema = createWebSearchProviderSchema(registry); - - return z - .object({ - provider: providerSchema.optional(), - url: z.string().url().optional(), - apiKey: z.string().optional(), - }) - .strict() - .refine( - (data) => { - // If provider is set, validate it makes sense - if (!data.provider) { - return true; - } - - // SearXNG requires a URL - if (data.provider === "searxng" && !data.url) { - return false; - } - - // Brave requires an API key - if (data.provider === "brave" && !data.apiKey) { - return false; - } - - return true; - }, - { - message: - "SearXNG requires 'url' and Brave requires 'apiKey' configuration", - }, - ); -} - -/** - * Validate web search configuration - * Returns validation result with error messages if validation fails - */ -export interface ValidationResult { - valid: boolean; - errors?: string[]; -} - -export function validateWebSearchConfig( - config: unknown, - registry?: PluginRegistry, -): ValidationResult { - const schema = createWebSearchConfigSchema(registry); - - try { - schema.parse(config); - return { valid: true }; - } catch (err) { - if (err instanceof z.ZodError) { - return { - valid: false, - errors: err.issues.map( - (issue) => `${issue.path.join(".")}: ${issue.message}`, - ), - }; - } - return { - valid: false, - errors: [err instanceof Error ? err.message : "Unknown validation error"], - }; - } -} - -/** - * Get all valid provider names as a string list - */ -export function getValidProviderNames(registry?: PluginRegistry): string[] { - const builtInProviders = ["brave", "google", "searxng", "custom"]; - - if (!registry) { - return builtInProviders; - } - - const pluginProviders = Array.from(registry.getWebSearchProviders().keys()); - return Array.from(new Set([...builtInProviders, ...pluginProviders])); -}