github-router 0.3.330 → 0.3.331
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/dist/{attribution-settings-DepziZU8.js → attribution-settings-7dFpObGh.js} +4 -4
- package/dist/{attribution-settings-DepziZU8.js.map → attribution-settings-7dFpObGh.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{claude-Dw4V8o8l.js → claude-C3-yBGzw.js} +7 -7
- package/dist/{claude-Dw4V8o8l.js.map → claude-C3-yBGzw.js.map} +1 -1
- package/dist/{codex-CXOpv4WP.js → codex-C3hcVSOm.js} +5 -5
- package/dist/{codex-CXOpv4WP.js.map → codex-C3hcVSOm.js.map} +1 -1
- package/dist/engine-CPdWX70n.js +2 -0
- package/dist/{gate-discovery-BGqS7R2g.js → gate-discovery-BUhtwkyE.js} +2 -2
- package/dist/{gate-discovery-BGqS7R2g.js.map → gate-discovery-BUhtwkyE.js.map} +1 -1
- package/dist/index-cmd-k3oWl0n4.js +330 -0
- package/dist/index-cmd-k3oWl0n4.js.map +1 -0
- package/dist/{internal-stop-hook-CH9SKjZ9.js → internal-stop-hook-DBrlosd0.js} +2 -2
- package/dist/{internal-stop-hook-CH9SKjZ9.js.map → internal-stop-hook-DBrlosd0.js.map} +1 -1
- package/dist/main.js +6 -6
- package/dist/{peer-mcp-personas-CnYMTizo.js → peer-mcp-personas-Dztywua2.js} +2 -2
- package/dist/{peer-mcp-personas-CnYMTizo.js.map → peer-mcp-personas-Dztywua2.js.map} +1 -1
- package/dist/{provision-D5KOOw6n.js → provision-CjBt5wEK.js} +3 -3
- package/dist/{provision-D5KOOw6n.js.map → provision-CjBt5wEK.js.map} +1 -1
- package/dist/{serve-fJWhiivo.js → serve-C3LCkM-o.js} +6 -6
- package/dist/{serve-fJWhiivo.js.map → serve-C3LCkM-o.js.map} +1 -1
- package/dist/{server-setup-DHMPOXKT.js → server-setup-DrSUlFZ_.js} +4 -4
- package/dist/{server-setup-DHMPOXKT.js.map → server-setup-DrSUlFZ_.js.map} +1 -1
- package/dist/{service-backend-DYEPoszR.js → service-backend-ByT0gUc8.js} +405 -19
- package/dist/{service-backend-DYEPoszR.js.map → service-backend-ByT0gUc8.js.map} +1 -1
- package/dist/{start-Gs4jAwUR.js → start-CY1nnbB4.js} +4 -4
- package/dist/{start-Gs4jAwUR.js.map → start-CY1nnbB4.js.map} +1 -1
- package/package.json +1 -1
- package/dist/engine-CYba_zi7.js +0 -2
- package/dist/index-cmd-DUjQs9zw.js +0 -182
- package/dist/index-cmd-DUjQs9zw.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { R as runSelfUpdate, a as sharedServerArgs, i as setupAndServe, n as getCodexEnvVars, r as parseSharedArgs, s as startKeepAwake, t as getClaudeCodeEnvVars } from "./server-setup-
|
|
3
|
-
import { an as colbertDegradedWarning, on as provisionAndIndexColbert, pt as browserToolsEnabled, rn as provisionBrowserAssets } from "./peer-mcp-personas-
|
|
1
|
+
import { N as warmTreeSitterPool } from "./service-backend-ByT0gUc8.js";
|
|
2
|
+
import { R as runSelfUpdate, a as sharedServerArgs, i as setupAndServe, n as getCodexEnvVars, r as parseSharedArgs, s as startKeepAwake, t as getClaudeCodeEnvVars } from "./server-setup-DrSUlFZ_.js";
|
|
3
|
+
import { an as colbertDegradedWarning, on as provisionAndIndexColbert, pt as browserToolsEnabled, rn as provisionBrowserAssets } from "./peer-mcp-personas-Dztywua2.js";
|
|
4
4
|
import { defineCommand } from "citty";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import process$1 from "node:process";
|
|
@@ -130,4 +130,4 @@ const start = defineCommand({
|
|
|
130
130
|
//#endregion
|
|
131
131
|
export { start };
|
|
132
132
|
|
|
133
|
-
//# sourceMappingURL=start-
|
|
133
|
+
//# sourceMappingURL=start-CY1nnbB4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-Gs4jAwUR.js","names":["process"],"sources":["../src/lib/shell.ts","../src/start.ts"],"sourcesContent":["import process from \"node:process\"\n\ntype ShellName = \"bash\" | \"zsh\" | \"fish\" | \"powershell\" | \"cmd\" | \"sh\"\ntype EnvVars = Record<string, string | undefined>\n\nfunction getShell(): ShellName {\n const { platform, env } = process\n\n if (platform === \"win32\") {\n // Git Bash / MSYS2 / Cygwin set SHELL even on Windows\n if (env.SHELL) {\n if (env.SHELL.endsWith(\"zsh\")) return \"zsh\"\n if (env.SHELL.endsWith(\"fish\")) return \"fish\"\n if (env.SHELL.endsWith(\"bash\")) return \"bash\"\n return \"sh\"\n }\n\n // Windows PowerShell 5.x sets this\n if (env.POWERSHELL_DISTRIBUTION_CHANNEL) return \"powershell\"\n\n // PowerShell (both 5.x and 7+/pwsh) adds user-scoped module paths\n // at runtime. The system-level PSModulePath in CMD lacks these paths.\n if (env.PSModulePath) {\n const lower = env.PSModulePath.toLowerCase()\n if (\n lower.includes(\"documents\\\\powershell\")\n || lower.includes(\"documents\\\\windowspowershell\")\n ) {\n return \"powershell\"\n }\n }\n\n return \"cmd\"\n }\n\n const shellPath = env.SHELL\n if (shellPath) {\n if (shellPath.endsWith(\"zsh\")) return \"zsh\"\n if (shellPath.endsWith(\"fish\")) return \"fish\"\n if (shellPath.endsWith(\"bash\")) return \"bash\"\n }\n\n return \"sh\"\n}\n\nfunction quotePosixValue(value: string): string {\n return `'${value.replace(/'/g, \"'\\\\''\")}'`\n}\n\nfunction quotePowerShellValue(value: string): string {\n return `'${value.replace(/'/g, \"''\")}'`\n}\n\n/**\n * Generates a copy-pasteable script to set multiple environment variables\n * and run a subsequent command.\n * @param {EnvVars} envVars - An object of environment variables to set.\n * @param {string} commandToRun - The command to run after setting the variables.\n * @returns {string} The formatted script string.\n */\nexport function generateEnvScript(\n envVars: EnvVars,\n commandToRun: string = \"\",\n): string {\n const shell = getShell()\n const filteredEnvVars = Object.entries(envVars).filter(\n ([, value]) => value !== undefined,\n ) as Array<[string, string]>\n\n let commandBlock: string\n\n switch (shell) {\n case \"powershell\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `$env:${key} = ${quotePowerShellValue(value)}`)\n .join(\"; \")\n break\n }\n case \"cmd\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `set \"${key}=${value}\"`)\n .join(\" & \")\n break\n }\n case \"fish\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `set -gx ${key} ${quotePosixValue(value)}`)\n .join(\"; \")\n break\n }\n default: {\n // bash, zsh, sh\n const assignments = filteredEnvVars\n .map(([key, value]) => `${key}=${quotePosixValue(value)}`)\n .join(\" \")\n commandBlock = filteredEnvVars.length > 0 ? `export ${assignments}` : \"\"\n break\n }\n }\n\n if (commandBlock && commandToRun) {\n const separator =\n shell === \"cmd\" ? \" & \" : shell === \"powershell\" ? \"; \" : \" && \"\n return `${commandBlock}${separator}${commandToRun}`\n }\n\n return commandBlock || commandToRun\n}\n","#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\nimport clipboard from \"clipboardy\"\nimport consola from \"consola\"\n\nimport { generateEnvScript } from \"./lib/shell\"\nimport { DEFAULT_CODEX_MODEL, DEFAULT_PORT } from \"./lib/port\"\nimport { provisionBrowserAssets } from \"./lib/browser-mcp/provision\"\nimport { browserToolsEnabled } from \"./lib/mcp-capabilities\"\nimport { colbertDegradedWarning, provisionAndIndexColbert } from \"./lib/colbert\"\nimport { startKeepAwake } from \"./lib/keep-awake\"\nimport { warmTreeSitterPool } from \"./lib/tree-sitter-pool/pool\"\nimport {\n getClaudeCodeEnvVars,\n getCodexEnvVars,\n parseSharedArgs,\n setupAndServe,\n sharedServerArgs,\n} from \"./lib/server-setup\"\nimport { runSelfUpdate } from \"./lib/self-update\"\n\nfunction printAndCopyCommand(command: string, label: string): void {\n consola.box(`${label}\\n\\n${command}`)\n try {\n clipboard.writeSync(command)\n consola.success(`Copied ${label} command to clipboard!`)\n } catch {\n consola.warn(\"Failed to copy to clipboard. Copy the command above manually.\")\n }\n}\n\nfunction generateClaudeCodeCommand(serverUrl: string, model?: string) {\n const envVars = getClaudeCodeEnvVars(serverUrl, model)\n const command = generateEnvScript(envVars, \"claude --dangerously-skip-permissions\")\n printAndCopyCommand(command, \"Claude Code\")\n}\n\nfunction generateCodexCommand(serverUrl: string, model?: string) {\n const codexModel = model ?? DEFAULT_CODEX_MODEL\n const envVars = getCodexEnvVars(serverUrl)\n const command = generateEnvScript(envVars, `codex -m ${codexModel}`)\n printAndCopyCommand(command, \"Codex CLI\")\n}\n\nexport const start = defineCommand({\n meta: {\n name: \"start\",\n description: \"Start the github-router server\",\n },\n args: {\n ...sharedServerArgs,\n cc: {\n type: \"boolean\",\n default: false,\n description:\n \"Generate a command to launch Claude Code with Copilot API config\",\n },\n cx: {\n type: \"boolean\",\n default: false,\n description:\n \"Generate a command to launch Codex CLI with Copilot API config\",\n },\n model: {\n alias: \"m\",\n type: \"string\",\n description: \"Override the default model (used with --cc or --cx)\",\n },\n },\n async run({ args }) {\n const parsed = parseSharedArgs(args as unknown as Record<string, unknown>)\n\n const { serverUrl } = await setupAndServe({\n ...parsed,\n port: parsed.port ?? DEFAULT_PORT,\n silent: false,\n })\n\n // Best-effort self-update (detached, applies next launch). Runs\n // after the server is listening so the bounded probe can't delay it.\n void runSelfUpdate({ selfUpdate: args[\"self-update\"] !== false })\n\n // Best-effort ColBERT semantic-search provision + background index of\n // the launch cwd (if a git repo). Opt-IN via --search (no-op otherwise);\n // never blocks launch, never throws.\n void provisionAndIndexColbert()\n\n // Surface a terminally-failed semantic index to the HUMAN (see the note\n // in claude.ts). Fire-and-forget; lexical search still works.\n void colbertDegradedWarning()\n .then((warning) => {\n if (warning) process.stderr.write(`${warning}\\n`)\n })\n .catch(() => {})\n\n // Ready one tree-sitter worker in the background so the first code search\n // avoids WASM/grammar initialization. One worker keeps launch CPU bounded;\n // demand grows the pool lazily. Opt out with GH_ROUTER_DISABLE_TS_POOL_WARMUP=1.\n void warmTreeSitterPool()\n\n // Best-effort: keep the machine awake while the proxy serves (win32\n // default-on; opt out with GH_ROUTER_DISABLE_KEEP_AWAKE=1). Holds a\n // SetThreadExecutionState assertion via a persistent PowerShell\n // helper. Self-registers its own SIGINT/SIGTERM/exit reaper — load-\n // bearing here, because `start` has no launchChild/onShutdown.\n startKeepAwake()\n\n // Best-effort: materialize the browser extension + bridge into the\n // stable app-dir and stamp the running version, so a one-time \"Load\n // unpacked\" survives npx/bunx upgrades. Gated on --browse; never\n // blocks launch, never throws.\n if (browserToolsEnabled()) {\n void provisionBrowserAssets().catch((err) =>\n consola.debug(\"Browser extension provisioning failed:\", err),\n )\n }\n\n if (args.cc) generateClaudeCodeCommand(serverUrl, args.model)\n if (args.cx) generateCodexCommand(serverUrl, args.model)\n\n consola.box(\n `🌐 Usage Viewer: https://animeshkundu.github.io/github-router/dashboard.html?endpoint=${serverUrl}/usage`,\n )\n },\n})\n"],"mappings":";;;;;;;;AAKA,SAAS,WAAsB;CAC7B,MAAM,EAAE,UAAU,QAAQA;CAE1B,IAAI,aAAa,SAAS;EAExB,IAAI,IAAI,OAAO;GACb,IAAI,IAAI,MAAM,SAAS,KAAK,GAAG,OAAO;GACtC,IAAI,IAAI,MAAM,SAAS,MAAM,GAAG,OAAO;GACvC,IAAI,IAAI,MAAM,SAAS,MAAM,GAAG,OAAO;GACvC,OAAO;EACT;EAGA,IAAI,IAAI,iCAAiC,OAAO;EAIhD,IAAI,IAAI,cAAc;GACpB,MAAM,QAAQ,IAAI,aAAa,YAAY;GAC3C,IACE,MAAM,SAAS,uBAAuB,KACnC,MAAM,SAAS,8BAA8B,GAEhD,OAAO;EAEX;EAEA,OAAO;CACT;CAEA,MAAM,YAAY,IAAI;CACtB,IAAI,WAAW;EACb,IAAI,UAAU,SAAS,KAAK,GAAG,OAAO;EACtC,IAAI,UAAU,SAAS,MAAM,GAAG,OAAO;EACvC,IAAI,UAAU,SAAS,MAAM,GAAG,OAAO;CACzC;CAEA,OAAO;AACT;AAEA,SAAS,gBAAgB,OAAuB;CAC9C,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CAGpE,oBADgB,kBADA,qBAAqB,WAAW,KACd,GAAS,uCACjB,GAAG,aAAa;AAC5C;AAEA,SAAS,qBAAqB,WAAmB,OAAgB;CAC/D,MAAM,aAAa,SAAA;CAGnB,oBADgB,kBADA,gBAAgB,SACE,GAAS,YAAY,YAC7B,GAAG,WAAW;AAC1C;AAEA,MAAa,QAAQ,cAAc;CACjC,MAAM;EACJ,MAAM;EACN,aAAa;CACf;CACA,MAAM;EACJ,GAAG;EACH,IAAI;GACF,MAAM;GACN,SAAS;GACT,aACE;EACJ;EACA,IAAI;GACF,MAAM;GACN,SAAS;GACT,aACE;EACJ;EACA,OAAO;GACL,OAAO;GACP,MAAM;GACN,aAAa;EACf;CACF;CACA,MAAM,IAAI,EAAE,QAAQ;EAClB,MAAM,SAAS,gBAAgB,IAA0C;EAEzE,MAAM,EAAE,cAAc,MAAM,cAAc;GACxC,GAAG;GACH,MAAM,OAAO,QAAA;GACb,QAAQ;EACV,CAAC;EAID,cAAmB,EAAE,YAAY,KAAK,mBAAmB,MAAM,CAAC;EAKhE,yBAA8B;EAI9B,uBAA4B,CAAC,CAC1B,MAAM,YAAY;GACjB,IAAI,SAAS,QAAQ,OAAO,MAAM,GAAG,QAAQ,GAAG;EAClD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAKjB,mBAAwB;EAOxB,eAAe;EAMf,IAAI,oBAAoB,GACtB,uBAA4B,CAAC,CAAC,OAAO,QACnC,QAAQ,MAAM,0CAA0C,GAAG,CAC7D;EAGF,IAAI,KAAK,IAAI,0BAA0B,WAAW,KAAK,KAAK;EAC5D,IAAI,KAAK,IAAI,qBAAqB,WAAW,KAAK,KAAK;EAEvD,QAAQ,IACN,yFAAyF,UAAU,OACrG;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"start-CY1nnbB4.js","names":["process"],"sources":["../src/lib/shell.ts","../src/start.ts"],"sourcesContent":["import process from \"node:process\"\n\ntype ShellName = \"bash\" | \"zsh\" | \"fish\" | \"powershell\" | \"cmd\" | \"sh\"\ntype EnvVars = Record<string, string | undefined>\n\nfunction getShell(): ShellName {\n const { platform, env } = process\n\n if (platform === \"win32\") {\n // Git Bash / MSYS2 / Cygwin set SHELL even on Windows\n if (env.SHELL) {\n if (env.SHELL.endsWith(\"zsh\")) return \"zsh\"\n if (env.SHELL.endsWith(\"fish\")) return \"fish\"\n if (env.SHELL.endsWith(\"bash\")) return \"bash\"\n return \"sh\"\n }\n\n // Windows PowerShell 5.x sets this\n if (env.POWERSHELL_DISTRIBUTION_CHANNEL) return \"powershell\"\n\n // PowerShell (both 5.x and 7+/pwsh) adds user-scoped module paths\n // at runtime. The system-level PSModulePath in CMD lacks these paths.\n if (env.PSModulePath) {\n const lower = env.PSModulePath.toLowerCase()\n if (\n lower.includes(\"documents\\\\powershell\")\n || lower.includes(\"documents\\\\windowspowershell\")\n ) {\n return \"powershell\"\n }\n }\n\n return \"cmd\"\n }\n\n const shellPath = env.SHELL\n if (shellPath) {\n if (shellPath.endsWith(\"zsh\")) return \"zsh\"\n if (shellPath.endsWith(\"fish\")) return \"fish\"\n if (shellPath.endsWith(\"bash\")) return \"bash\"\n }\n\n return \"sh\"\n}\n\nfunction quotePosixValue(value: string): string {\n return `'${value.replace(/'/g, \"'\\\\''\")}'`\n}\n\nfunction quotePowerShellValue(value: string): string {\n return `'${value.replace(/'/g, \"''\")}'`\n}\n\n/**\n * Generates a copy-pasteable script to set multiple environment variables\n * and run a subsequent command.\n * @param {EnvVars} envVars - An object of environment variables to set.\n * @param {string} commandToRun - The command to run after setting the variables.\n * @returns {string} The formatted script string.\n */\nexport function generateEnvScript(\n envVars: EnvVars,\n commandToRun: string = \"\",\n): string {\n const shell = getShell()\n const filteredEnvVars = Object.entries(envVars).filter(\n ([, value]) => value !== undefined,\n ) as Array<[string, string]>\n\n let commandBlock: string\n\n switch (shell) {\n case \"powershell\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `$env:${key} = ${quotePowerShellValue(value)}`)\n .join(\"; \")\n break\n }\n case \"cmd\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `set \"${key}=${value}\"`)\n .join(\" & \")\n break\n }\n case \"fish\": {\n commandBlock = filteredEnvVars\n .map(([key, value]) => `set -gx ${key} ${quotePosixValue(value)}`)\n .join(\"; \")\n break\n }\n default: {\n // bash, zsh, sh\n const assignments = filteredEnvVars\n .map(([key, value]) => `${key}=${quotePosixValue(value)}`)\n .join(\" \")\n commandBlock = filteredEnvVars.length > 0 ? `export ${assignments}` : \"\"\n break\n }\n }\n\n if (commandBlock && commandToRun) {\n const separator =\n shell === \"cmd\" ? \" & \" : shell === \"powershell\" ? \"; \" : \" && \"\n return `${commandBlock}${separator}${commandToRun}`\n }\n\n return commandBlock || commandToRun\n}\n","#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\nimport clipboard from \"clipboardy\"\nimport consola from \"consola\"\n\nimport { generateEnvScript } from \"./lib/shell\"\nimport { DEFAULT_CODEX_MODEL, DEFAULT_PORT } from \"./lib/port\"\nimport { provisionBrowserAssets } from \"./lib/browser-mcp/provision\"\nimport { browserToolsEnabled } from \"./lib/mcp-capabilities\"\nimport { colbertDegradedWarning, provisionAndIndexColbert } from \"./lib/colbert\"\nimport { startKeepAwake } from \"./lib/keep-awake\"\nimport { warmTreeSitterPool } from \"./lib/tree-sitter-pool/pool\"\nimport {\n getClaudeCodeEnvVars,\n getCodexEnvVars,\n parseSharedArgs,\n setupAndServe,\n sharedServerArgs,\n} from \"./lib/server-setup\"\nimport { runSelfUpdate } from \"./lib/self-update\"\n\nfunction printAndCopyCommand(command: string, label: string): void {\n consola.box(`${label}\\n\\n${command}`)\n try {\n clipboard.writeSync(command)\n consola.success(`Copied ${label} command to clipboard!`)\n } catch {\n consola.warn(\"Failed to copy to clipboard. Copy the command above manually.\")\n }\n}\n\nfunction generateClaudeCodeCommand(serverUrl: string, model?: string) {\n const envVars = getClaudeCodeEnvVars(serverUrl, model)\n const command = generateEnvScript(envVars, \"claude --dangerously-skip-permissions\")\n printAndCopyCommand(command, \"Claude Code\")\n}\n\nfunction generateCodexCommand(serverUrl: string, model?: string) {\n const codexModel = model ?? DEFAULT_CODEX_MODEL\n const envVars = getCodexEnvVars(serverUrl)\n const command = generateEnvScript(envVars, `codex -m ${codexModel}`)\n printAndCopyCommand(command, \"Codex CLI\")\n}\n\nexport const start = defineCommand({\n meta: {\n name: \"start\",\n description: \"Start the github-router server\",\n },\n args: {\n ...sharedServerArgs,\n cc: {\n type: \"boolean\",\n default: false,\n description:\n \"Generate a command to launch Claude Code with Copilot API config\",\n },\n cx: {\n type: \"boolean\",\n default: false,\n description:\n \"Generate a command to launch Codex CLI with Copilot API config\",\n },\n model: {\n alias: \"m\",\n type: \"string\",\n description: \"Override the default model (used with --cc or --cx)\",\n },\n },\n async run({ args }) {\n const parsed = parseSharedArgs(args as unknown as Record<string, unknown>)\n\n const { serverUrl } = await setupAndServe({\n ...parsed,\n port: parsed.port ?? DEFAULT_PORT,\n silent: false,\n })\n\n // Best-effort self-update (detached, applies next launch). Runs\n // after the server is listening so the bounded probe can't delay it.\n void runSelfUpdate({ selfUpdate: args[\"self-update\"] !== false })\n\n // Best-effort ColBERT semantic-search provision + background index of\n // the launch cwd (if a git repo). Opt-IN via --search (no-op otherwise);\n // never blocks launch, never throws.\n void provisionAndIndexColbert()\n\n // Surface a terminally-failed semantic index to the HUMAN (see the note\n // in claude.ts). Fire-and-forget; lexical search still works.\n void colbertDegradedWarning()\n .then((warning) => {\n if (warning) process.stderr.write(`${warning}\\n`)\n })\n .catch(() => {})\n\n // Ready one tree-sitter worker in the background so the first code search\n // avoids WASM/grammar initialization. One worker keeps launch CPU bounded;\n // demand grows the pool lazily. Opt out with GH_ROUTER_DISABLE_TS_POOL_WARMUP=1.\n void warmTreeSitterPool()\n\n // Best-effort: keep the machine awake while the proxy serves (win32\n // default-on; opt out with GH_ROUTER_DISABLE_KEEP_AWAKE=1). Holds a\n // SetThreadExecutionState assertion via a persistent PowerShell\n // helper. Self-registers its own SIGINT/SIGTERM/exit reaper — load-\n // bearing here, because `start` has no launchChild/onShutdown.\n startKeepAwake()\n\n // Best-effort: materialize the browser extension + bridge into the\n // stable app-dir and stamp the running version, so a one-time \"Load\n // unpacked\" survives npx/bunx upgrades. Gated on --browse; never\n // blocks launch, never throws.\n if (browserToolsEnabled()) {\n void provisionBrowserAssets().catch((err) =>\n consola.debug(\"Browser extension provisioning failed:\", err),\n )\n }\n\n if (args.cc) generateClaudeCodeCommand(serverUrl, args.model)\n if (args.cx) generateCodexCommand(serverUrl, args.model)\n\n consola.box(\n `🌐 Usage Viewer: https://animeshkundu.github.io/github-router/dashboard.html?endpoint=${serverUrl}/usage`,\n )\n },\n})\n"],"mappings":";;;;;;;;AAKA,SAAS,WAAsB;CAC7B,MAAM,EAAE,UAAU,QAAQA;CAE1B,IAAI,aAAa,SAAS;EAExB,IAAI,IAAI,OAAO;GACb,IAAI,IAAI,MAAM,SAAS,KAAK,GAAG,OAAO;GACtC,IAAI,IAAI,MAAM,SAAS,MAAM,GAAG,OAAO;GACvC,IAAI,IAAI,MAAM,SAAS,MAAM,GAAG,OAAO;GACvC,OAAO;EACT;EAGA,IAAI,IAAI,iCAAiC,OAAO;EAIhD,IAAI,IAAI,cAAc;GACpB,MAAM,QAAQ,IAAI,aAAa,YAAY;GAC3C,IACE,MAAM,SAAS,uBAAuB,KACnC,MAAM,SAAS,8BAA8B,GAEhD,OAAO;EAEX;EAEA,OAAO;CACT;CAEA,MAAM,YAAY,IAAI;CACtB,IAAI,WAAW;EACb,IAAI,UAAU,SAAS,KAAK,GAAG,OAAO;EACtC,IAAI,UAAU,SAAS,MAAM,GAAG,OAAO;EACvC,IAAI,UAAU,SAAS,MAAM,GAAG,OAAO;CACzC;CAEA,OAAO;AACT;AAEA,SAAS,gBAAgB,OAAuB;CAC9C,OAAO,IAAI,MAAM,QAAQ,MAAM,OAAO,EAAE;AAC1C;AAEA,SAAS,qBAAqB,OAAuB;CACnD,OAAO,IAAI,MAA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OAAgB;CAC/D,MAAM,aAAa,SAAA;CAGnB,oBADgB,kBADA,gBAAgB,SACE,GAAS,YAAY,YAC7B,GAAG,WAAW;AAC1C;AAEA,MAAa,QAAQ,cAAc;CACjC,MAAM;EACJ,MAAM;EACN,aAAa;CACf;CACA,MAAM;EACJ,GAAG;EACH,IAAI;GACF,MAAM;GACN,SAAS;GACT,aACE;EACJ;EACA,IAAI;GACF,MAAM;GACN,SAAS;GACT,aACE;EACJ;EACA,OAAO;GACL,OAAO;GACP,MAAM;GACN,aAAa;EACf;CACF;CACA,MAAM,IAAI,EAAE,QAAQ;EAClB,MAAM,SAAS,gBAAgB,IAA0C;EAEzE,MAAM,EAAE,cAAc,MAAM,cAAc;GACxC,GAAG;GACH,MAAM,OAAO,QAAA;GACb,QAAQ;EACV,CAAC;EAID,cAAmB,EAAE,YAAY,KAAK,mBAAmB,MAAM,CAAC;EAKhE,yBAA8B;EAI9B,uBAA4B,CAAC,CAC1B,MAAM,YAAY;GACjB,IAAI,SAAS,QAAQ,OAAO,MAAM,GAAG,QAAQ,GAAG;EAClD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAKjB,mBAAwB;EAOxB,eAAe;EAMf,IAAI,oBAAoB,GACtB,uBAA4B,CAAC,CAAC,OAAO,QACnC,QAAQ,MAAM,0CAA0C,GAAG,CAC7D;EAGF,IAAI,KAAK,IAAI,0BAA0B,WAAW,KAAK,KAAK;EAC5D,IAAI,KAAK,IAAI,qBAAqB,WAAW,KAAK,KAAK;EAEvD,QAAQ,IACN,yFAAyF,UAAU,OACrG;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
package/dist/engine-CYba_zi7.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { a as kickBackgroundInit, c as waitForInit, d as freshnessVerdict, h as validateIndexIntegrity, l as colbertProjectDir, m as readColbertMeta, n as selectServerVariant, p as indexDirSignature, r as semanticBackend, u as completedIndexOnDisk, v as provisionColbert, w as validateWorkspace, y as provisionNextPlaidServer } from "./service-backend-DYEPoszR.js";
|
|
2
|
-
import { t as PATHS } from "./paths-P5ajjpzU.js";
|
|
3
|
-
import { i as parseBoolEnv } from "./exec-COUT4QsS.js";
|
|
4
|
-
import { r as registerColbertExitHandlers } from "./lifecycle-D8vQXfeC.js";
|
|
5
|
-
import { defineCommand } from "citty";
|
|
6
|
-
import consola from "consola";
|
|
7
|
-
import * as os$1 from "node:os";
|
|
8
|
-
import process from "node:process";
|
|
9
|
-
//#region src/index-cmd.ts
|
|
10
|
-
/**
|
|
11
|
-
* `github-router index` — build the semantic code-search index in the
|
|
12
|
-
* foreground, without starting the proxy (`start`/`claude`/`codex`).
|
|
13
|
-
*
|
|
14
|
-
* Phase 4a: drives the CURRENT colbert backend (foreground `init` with
|
|
15
|
-
* progress). The explicit invocation IS the opt-in — `--search` is not
|
|
16
|
-
* required — but `GH_ROUTER_DISABLE_SEMANTIC_SEARCH=1` still hard-disables
|
|
17
|
-
* (building an index that can never be served is pointless). With
|
|
18
|
-
* `GH_ROUTER_SEMANTIC_BACKEND=service`, the command additionally
|
|
19
|
-
* pre-pulls the server binary for the auto-detected variant (GPU→cuda,
|
|
20
|
-
* else cpu); the CLI surface (workspace/status/timeout/exit codes) stays
|
|
21
|
-
* stable across backends.
|
|
22
|
-
*
|
|
23
|
-
* Exit codes: 0 = fresh or successfully built; 1 = provision/build
|
|
24
|
-
* failure; 2 = usage error (bad workspace, hard-disabled).
|
|
25
|
-
*/
|
|
26
|
-
const POLL_MS = 1e4;
|
|
27
|
-
function cpuCount() {
|
|
28
|
-
try {
|
|
29
|
-
const n = os$1.cpus().length;
|
|
30
|
-
return Number.isSafeInteger(n) && n > 0 ? n : 4;
|
|
31
|
-
} catch {
|
|
32
|
-
return 4;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async function collectStatus(workspace) {
|
|
36
|
-
const { verdict, head, dirty } = await freshnessVerdict(workspace);
|
|
37
|
-
const status = {
|
|
38
|
-
workspace,
|
|
39
|
-
verdict,
|
|
40
|
-
indexOnDisk: await completedIndexOnDisk(workspace)
|
|
41
|
-
};
|
|
42
|
-
const projectDir = await colbertProjectDir(workspace);
|
|
43
|
-
if (projectDir) {
|
|
44
|
-
const integrity = validateIndexIntegrity(`${projectDir}/index`);
|
|
45
|
-
if (integrity.verdict === "coherent") {
|
|
46
|
-
status.shards = integrity.shardCount;
|
|
47
|
-
status.embeddings = integrity.embeddingCount;
|
|
48
|
-
} else status.integrity = integrity.verdict;
|
|
49
|
-
}
|
|
50
|
-
const meta = await readColbertMeta(workspace);
|
|
51
|
-
if (meta?.lastIndexedAt) status.lastIndexedAt = meta.lastIndexedAt;
|
|
52
|
-
if (head !== void 0) status.head = head.slice(0, 12);
|
|
53
|
-
if (dirty !== void 0) status.dirty = dirty;
|
|
54
|
-
return status;
|
|
55
|
-
}
|
|
56
|
-
function printStatus(s) {
|
|
57
|
-
consola.info(`workspace: ${s.workspace}`);
|
|
58
|
-
consola.info(`verdict: ${s.verdict}`);
|
|
59
|
-
consola.info(`index: ${s.indexOnDisk ? "present" : "absent"}`);
|
|
60
|
-
if (s.shards !== void 0) consola.info(`shards: ${s.shards} (${s.embeddings ?? 0} embeddings)`);
|
|
61
|
-
if (s.integrity && s.integrity !== "not-built") consola.info(`integrity: ${s.integrity}`);
|
|
62
|
-
if (s.head !== void 0) consola.info(`head: ${s.head}${s.dirty ? " (dirty)" : ""}`);
|
|
63
|
-
if (s.lastIndexedAt) consola.info(`indexed: ${s.lastIndexedAt}`);
|
|
64
|
-
}
|
|
65
|
-
function sleep(ms) {
|
|
66
|
-
return new Promise((resolve) => {
|
|
67
|
-
setTimeout(resolve, ms).unref?.();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const indexCmd = defineCommand({
|
|
71
|
-
meta: {
|
|
72
|
-
name: "index",
|
|
73
|
-
description: "Build the semantic code-search index for a workspace in the foreground (no proxy needed)"
|
|
74
|
-
},
|
|
75
|
-
args: {
|
|
76
|
-
workspace: {
|
|
77
|
-
alias: "w",
|
|
78
|
-
type: "string",
|
|
79
|
-
description: "Absolute path to the repo to index (default: cwd)"
|
|
80
|
-
},
|
|
81
|
-
status: {
|
|
82
|
-
type: "boolean",
|
|
83
|
-
default: false,
|
|
84
|
-
description: "Print index status and exit (no build)"
|
|
85
|
-
},
|
|
86
|
-
timeout: {
|
|
87
|
-
type: "string",
|
|
88
|
-
description: "Max minutes to wait for the build (0 = none, default 0)"
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
async run({ args }) {
|
|
92
|
-
const rawWorkspace = typeof args.workspace === "string" && args.workspace.length > 0 ? args.workspace : process.cwd();
|
|
93
|
-
const ws = validateWorkspace(rawWorkspace);
|
|
94
|
-
if (!ws.ok || !ws.canonical) {
|
|
95
|
-
consola.error(`index: ${ws.error ?? "workspace validation failed"}`);
|
|
96
|
-
process.exitCode = 2;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const workspace = ws.canonical;
|
|
100
|
-
if (parseBoolEnv(process.env.GH_ROUTER_DISABLE_SEMANTIC_SEARCH) === true) {
|
|
101
|
-
consola.error("index: semantic search is hard-disabled (GH_ROUTER_DISABLE_SEMANTIC_SEARCH=1); nothing to build");
|
|
102
|
-
process.exitCode = 2;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (args.status === true) {
|
|
106
|
-
printStatus(await collectStatus(workspace));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const timeoutMin = args.timeout === void 0 ? 0 : Number(args.timeout);
|
|
110
|
-
if (args.timeout !== void 0 && !(Number.isFinite(timeoutMin) && timeoutMin >= 0)) {
|
|
111
|
-
consola.error("index: --timeout must be a non-negative number of minutes");
|
|
112
|
-
process.exitCode = 2;
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const deadlineMs = timeoutMin > 0 ? Date.now() + timeoutMin * 6e4 : Number.POSITIVE_INFINITY;
|
|
116
|
-
if (process.env.GH_ROUTER_COLBERT_PARALLEL === void 0) {
|
|
117
|
-
process.env.GH_ROUTER_COLBERT_PARALLEL = String(cpuCount());
|
|
118
|
-
consola.debug(`index: parallelism defaulted to ${cpuCount()} sessions (override with GH_ROUTER_COLBERT_PARALLEL)`);
|
|
119
|
-
}
|
|
120
|
-
registerColbertExitHandlers();
|
|
121
|
-
consola.info(`Provisioning semantic-search artifacts into ${PATHS.COLBERT_INDICES_DIR}…`);
|
|
122
|
-
try {
|
|
123
|
-
const result = await provisionColbert();
|
|
124
|
-
if (result.status !== "ready") {
|
|
125
|
-
consola.error(`index: provision ${result.status}${result.reason ? ` (${result.reason})` : ""}`);
|
|
126
|
-
process.exitCode = 1;
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
} catch (err) {
|
|
130
|
-
consola.error("index: provision threw:", err);
|
|
131
|
-
process.exitCode = 1;
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (semanticBackend() === "service") try {
|
|
135
|
-
const variant = await selectServerVariant();
|
|
136
|
-
const server = await provisionNextPlaidServer(variant);
|
|
137
|
-
if (server.path) consola.info(`index: service backend ready (${variant}: ${server.path})`);
|
|
138
|
-
else consola.warn(`index: service binary unavailable (${server.reason ?? "unknown"}) — first query provisions on demand`);
|
|
139
|
-
} catch (err) {
|
|
140
|
-
consola.warn("index: service provision skipped:", err);
|
|
141
|
-
}
|
|
142
|
-
const first = await freshnessVerdict(workspace);
|
|
143
|
-
if (first.verdict === "fresh") {
|
|
144
|
-
consola.success("index is already fresh — nothing to build");
|
|
145
|
-
printStatus(await collectStatus(workspace));
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (first.verdict === "failed") consola.warn("index: last build failed; starting one bounded rebuild attempt");
|
|
149
|
-
consola.info(`Building semantic index for ${workspace} (freshness: ${first.verdict})…`);
|
|
150
|
-
kickBackgroundInit(workspace);
|
|
151
|
-
const startMs = Date.now();
|
|
152
|
-
for (;;) {
|
|
153
|
-
if (Date.now() > deadlineMs) {
|
|
154
|
-
consola.error(`index: timed out after ${timeoutMin}min — the background build continues; retry or raise --timeout`);
|
|
155
|
-
process.exitCode = 1;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
await waitForInit(workspace).catch(() => {});
|
|
159
|
-
const v = await freshnessVerdict(workspace);
|
|
160
|
-
const elapsedS = Math.round((Date.now() - startMs) / 1e3);
|
|
161
|
-
if (v.verdict === "fresh") {
|
|
162
|
-
consola.success(`index ready in ${elapsedS}s`);
|
|
163
|
-
printStatus(await collectStatus(workspace));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (v.verdict === "failed" || v.verdict === "crashed" || v.verdict === "corrupt") {
|
|
167
|
-
consola.error(`index: build ended ${v.verdict} — lexical code search still works; see the proxy error log for the failure class`);
|
|
168
|
-
process.exitCode = 1;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const sig = indexDirSignature(workspace);
|
|
172
|
-
const progress = sig.kind === "observed" ? ` [${sig.signature}]` : " [starting…]";
|
|
173
|
-
consola.info(`… ${elapsedS}s elapsed (freshness: ${v.verdict})${progress}`);
|
|
174
|
-
await sleep(POLL_MS);
|
|
175
|
-
kickBackgroundInit(workspace);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
//#endregion
|
|
180
|
-
export { indexCmd };
|
|
181
|
-
|
|
182
|
-
//# sourceMappingURL=index-cmd-DUjQs9zw.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-cmd-DUjQs9zw.js","names":["os"],"sources":["../src/index-cmd.ts"],"sourcesContent":["/**\n * `github-router index` — build the semantic code-search index in the\n * foreground, without starting the proxy (`start`/`claude`/`codex`).\n *\n * Phase 4a: drives the CURRENT colbert backend (foreground `init` with\n * progress). The explicit invocation IS the opt-in — `--search` is not\n * required — but `GH_ROUTER_DISABLE_SEMANTIC_SEARCH=1` still hard-disables\n * (building an index that can never be served is pointless). With\n * `GH_ROUTER_SEMANTIC_BACKEND=service`, the command additionally\n * pre-pulls the server binary for the auto-detected variant (GPU→cuda,\n * else cpu); the CLI surface (workspace/status/timeout/exit codes) stays\n * stable across backends.\n *\n * Exit codes: 0 = fresh or successfully built; 1 = provision/build\n * failure; 2 = usage error (bad workspace, hard-disabled).\n */\n\nimport { defineCommand } from \"citty\";\nimport consola from \"consola\";\nimport * as os from \"node:os\";\nimport process from \"node:process\";\n\nimport { validateWorkspace } from \"~/lib/code-search\";\nimport {\n colbertProjectDir,\n completedIndexOnDisk,\n freshnessVerdict,\n indexDirSignature,\n readColbertMeta,\n validateIndexIntegrity,\n} from \"~/lib/colbert/index-store\";\nimport { registerColbertExitHandlers } from \"~/lib/colbert/lifecycle\";\nimport { provisionColbert, provisionNextPlaidServer } from \"~/lib/colbert/provision\";\nimport { kickBackgroundInit, waitForInit } from \"~/lib/colbert/runner\";\nimport {\n selectServerVariant,\n semanticBackend,\n} from \"~/lib/colbert/service-backend\";\nimport { PATHS } from \"~/lib/paths\";\nimport { parseBoolEnv } from \"~/lib/exec\";\n\nconst POLL_MS = 10_000;\n\nfunction cpuCount(): number {\n try {\n const n = os.cpus().length;\n return Number.isSafeInteger(n) && n > 0 ? n : 4;\n } catch {\n return 4;\n }\n}\n\ninterface IndexStatus {\n workspace: string;\n verdict: string;\n indexOnDisk: boolean;\n shards?: number;\n embeddings?: number;\n integrity?: string;\n head?: string;\n dirty?: boolean;\n lastIndexedAt?: string;\n}\n\nasync function collectStatus(workspace: string): Promise<IndexStatus> {\n const { verdict, head, dirty } = await freshnessVerdict(workspace);\n const onDisk = await completedIndexOnDisk(workspace);\n const status: IndexStatus = {\n workspace,\n verdict,\n indexOnDisk: onDisk,\n };\n const projectDir = await colbertProjectDir(workspace);\n if (projectDir) {\n const integrity = validateIndexIntegrity(`${projectDir}/index`);\n if (integrity.verdict === \"coherent\") {\n status.shards = integrity.shardCount;\n status.embeddings = integrity.embeddingCount;\n } else {\n status.integrity = integrity.verdict;\n }\n }\n const meta = await readColbertMeta(workspace);\n if (meta?.lastIndexedAt) status.lastIndexedAt = meta.lastIndexedAt;\n if (head !== undefined) status.head = head.slice(0, 12);\n if (dirty !== undefined) status.dirty = dirty;\n return status;\n}\n\nfunction printStatus(s: IndexStatus): void {\n consola.info(`workspace: ${s.workspace}`);\n consola.info(`verdict: ${s.verdict}`);\n consola.info(`index: ${s.indexOnDisk ? \"present\" : \"absent\"}`);\n if (s.shards !== undefined) {\n consola.info(`shards: ${s.shards} (${s.embeddings ?? 0} embeddings)`);\n }\n if (s.integrity && s.integrity !== \"not-built\") {\n consola.info(`integrity: ${s.integrity}`);\n }\n if (s.head !== undefined)\n consola.info(`head: ${s.head}${s.dirty ? \" (dirty)\" : \"\"}`);\n if (s.lastIndexedAt) consola.info(`indexed: ${s.lastIndexedAt}`);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => {\n const t = setTimeout(resolve, ms);\n t.unref?.();\n });\n}\n\nexport const indexCmd = defineCommand({\n meta: {\n name: \"index\",\n description:\n \"Build the semantic code-search index for a workspace in the foreground (no proxy needed)\",\n },\n args: {\n workspace: {\n alias: \"w\",\n type: \"string\",\n description: \"Absolute path to the repo to index (default: cwd)\",\n },\n status: {\n type: \"boolean\",\n default: false,\n description: \"Print index status and exit (no build)\",\n },\n timeout: {\n type: \"string\",\n description: \"Max minutes to wait for the build (0 = none, default 0)\",\n },\n },\n async run({ args }) {\n const rawWorkspace =\n typeof args.workspace === \"string\" && args.workspace.length > 0\n ? args.workspace\n : process.cwd();\n const ws = validateWorkspace(rawWorkspace);\n if (!ws.ok || !ws.canonical) {\n consola.error(`index: ${ws.error ?? \"workspace validation failed\"}`);\n process.exitCode = 2;\n return;\n }\n const workspace = ws.canonical;\n\n if (parseBoolEnv(process.env.GH_ROUTER_DISABLE_SEMANTIC_SEARCH) === true) {\n consola.error(\n \"index: semantic search is hard-disabled (GH_ROUTER_DISABLE_SEMANTIC_SEARCH=1); nothing to build\",\n );\n process.exitCode = 2;\n return;\n }\n\n if (args.status === true) {\n printStatus(await collectStatus(workspace));\n return;\n }\n\n const timeoutMin = args.timeout === undefined ? 0 : Number(args.timeout);\n if (\n args.timeout !== undefined &&\n !(Number.isFinite(timeoutMin) && timeoutMin >= 0)\n ) {\n consola.error(\n \"index: --timeout must be a non-negative number of minutes\",\n );\n process.exitCode = 2;\n return;\n }\n const deadlineMs =\n timeoutMin > 0\n ? Date.now() + timeoutMin * 60_000\n : Number.POSITIVE_INFINITY;\n\n // Foreground dedicated build: use all cores unless the operator capped\n // explicitly. Background auto-indexing stays at 25% (the colbert\n // default); an explicit `index` invocation expects speed.\n if (process.env.GH_ROUTER_COLBERT_PARALLEL === undefined) {\n process.env.GH_ROUTER_COLBERT_PARALLEL = String(cpuCount());\n consola.debug(\n `index: parallelism defaulted to ${cpuCount()} sessions (override with GH_ROUTER_COLBERT_PARALLEL)`,\n );\n }\n\n registerColbertExitHandlers();\n\n consola.info(\n `Provisioning semantic-search artifacts into ${PATHS.COLBERT_INDICES_DIR}…`,\n );\n try {\n const result = await provisionColbert();\n if (result.status !== \"ready\") {\n consola.error(\n `index: provision ${result.status}${result.reason ? ` (${result.reason})` : \"\"}`,\n );\n process.exitCode = 1;\n return;\n }\n } catch (err) {\n consola.error(\"index: provision threw:\", err);\n process.exitCode = 1;\n return;\n }\n\n // Service backend selected: pre-pull the server binary for the\n // auto-detected variant now, so the first query doesn't pay the\n // download + cold start. Best-effort — a miss just defers to the\n // lazy provision on first query (or the colgrep/lexical fallback).\n if (semanticBackend() === \"service\") {\n try {\n const variant = await selectServerVariant();\n const server = await provisionNextPlaidServer(variant);\n if (server.path) {\n consola.info(`index: service backend ready (${variant}: ${server.path})`);\n } else {\n consola.warn(\n `index: service binary unavailable (${server.reason ?? \"unknown\"}) — first query provisions on demand`,\n );\n }\n } catch (err) {\n consola.warn(\"index: service provision skipped:\", err);\n }\n }\n\n const first = await freshnessVerdict(workspace);\n if (first.verdict === \"fresh\") {\n consola.success(\"index is already fresh — nothing to build\");\n printStatus(await collectStatus(workspace));\n return;\n }\n if (first.verdict === \"failed\") {\n consola.warn(\n \"index: last build failed; starting one bounded rebuild attempt\",\n );\n }\n\n consola.info(\n `Building semantic index for ${workspace} (freshness: ${first.verdict})…`,\n );\n kickBackgroundInit(workspace);\n const startMs = Date.now();\n\n for (;;) {\n if (Date.now() > deadlineMs) {\n consola.error(\n `index: timed out after ${timeoutMin}min — the background build continues; retry or raise --timeout`,\n );\n process.exitCode = 1;\n return;\n }\n // Wait for this process's tracked build; resolves immediately when\n // another proxy owns it, in which case the sleep below paces polling.\n await waitForInit(workspace).catch(() => {});\n const v = await freshnessVerdict(workspace);\n const elapsedS = Math.round((Date.now() - startMs) / 1000);\n if (v.verdict === \"fresh\") {\n consola.success(`index ready in ${elapsedS}s`);\n printStatus(await collectStatus(workspace));\n return;\n }\n if (\n v.verdict === \"failed\" ||\n v.verdict === \"crashed\" ||\n v.verdict === \"corrupt\"\n ) {\n consola.error(\n `index: build ended ${v.verdict} — lexical code search still works; see the proxy error log for the failure class`,\n );\n process.exitCode = 1;\n return;\n }\n // building | stale | absent: report progress, keep waiting. colgrep\n // is silent on pipes during encode, so disk growth is the signal.\n const sig = indexDirSignature(workspace);\n const progress =\n sig.kind === \"observed\" ? ` [${sig.signature}]` : \" [starting…]\";\n consola.info(\n `… ${elapsedS}s elapsed (freshness: ${v.verdict})${progress}`,\n );\n await sleep(POLL_MS);\n // Re-kick if nothing owns the build (crash between kick and track).\n kickBackgroundInit(workspace);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,UAAU;AAEhB,SAAS,WAAmB;CAC1B,IAAI;EACF,MAAM,IAAIA,KAAG,KAAK,CAAC,CAAC;EACpB,OAAO,OAAO,cAAc,CAAC,KAAK,IAAI,IAAI,IAAI;CAChD,QAAQ;EACN,OAAO;CACT;AACF;AAcA,eAAe,cAAc,WAAyC;CACpE,MAAM,EAAE,SAAS,MAAM,UAAU,MAAM,iBAAiB,SAAS;C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