@inspecto-dev/plugin 0.3.6 → 0.3.8
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/README.md +2 -1
- package/dist/astro.cjs +2243 -0
- package/dist/astro.cjs.map +1 -0
- package/dist/astro.d.cts +17 -0
- package/dist/astro.d.ts +17 -0
- package/dist/astro.js +2212 -0
- package/dist/astro.js.map +1 -0
- package/dist/index.cjs +430 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +428 -17
- package/dist/index.js.map +1 -1
- package/dist/legacy/rspack/index.cjs +33 -21
- package/dist/legacy/rspack/index.cjs.map +1 -1
- package/dist/legacy/rspack/index.js +33 -21
- package/dist/legacy/rspack/index.js.map +1 -1
- package/dist/legacy/rspack/loader.cjs +404 -3
- package/dist/legacy/rspack/loader.cjs.map +1 -1
- package/dist/legacy/rspack/loader.js +400 -3
- package/dist/legacy/rspack/loader.js.map +1 -1
- package/dist/legacy/webpack4/index.cjs +22 -10
- package/dist/legacy/webpack4/index.cjs.map +1 -1
- package/dist/legacy/webpack4/index.js +22 -10
- package/dist/legacy/webpack4/index.js.map +1 -1
- package/dist/legacy/webpack4/loader.cjs +404 -3
- package/dist/legacy/webpack4/loader.cjs.map +1 -1
- package/dist/legacy/webpack4/loader.js +400 -3
- package/dist/legacy/webpack4/loader.js.map +1 -1
- package/dist/rollup.cjs +430 -17
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +428 -17
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +430 -17
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.js +428 -17
- package/dist/rspack.js.map +1 -1
- package/dist/vite.cjs +430 -17
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +428 -17
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +430 -17
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +428 -17
- package/dist/webpack.js.map +1 -1
- package/package.json +10 -3
|
@@ -5,7 +5,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.
|
|
8
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.10_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js
|
|
9
9
|
import path from "path";
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
11
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
@@ -293,7 +293,7 @@ function readJsonSafely(filePath) {
|
|
|
293
293
|
}
|
|
294
294
|
return null;
|
|
295
295
|
}
|
|
296
|
-
function resolveTargetTool(config,
|
|
296
|
+
function resolveTargetTool(config, _ide = "vscode") {
|
|
297
297
|
const defaultProvider = config["provider.default"];
|
|
298
298
|
if (defaultProvider) {
|
|
299
299
|
const tool = defaultProvider.split(".")[0];
|
|
@@ -445,7 +445,7 @@ function watchConfig(onReload, cwd = process.cwd(), gitRoot) {
|
|
|
445
445
|
});
|
|
446
446
|
watcher.unref();
|
|
447
447
|
watchers.push(watcher);
|
|
448
|
-
} catch (
|
|
448
|
+
} catch (_e) {
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
}
|
|
@@ -486,6 +486,9 @@ function launchURI(uri) {
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
// src/server/dispatch-runtime.ts
|
|
489
|
+
function normalizeIdeToken(value) {
|
|
490
|
+
return (value ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
491
|
+
}
|
|
489
492
|
function resolvePromptDispatchRuntime(state) {
|
|
490
493
|
const userConfig = loadUserConfigSync(false, state.cwd, state.projectRoot);
|
|
491
494
|
const resolvedTarget = resolveTargetTool(userConfig);
|
|
@@ -527,7 +530,11 @@ function dispatchPromptThroughIde(runtime, payload) {
|
|
|
527
530
|
};
|
|
528
531
|
}
|
|
529
532
|
function resolveFinalIde(configuredIde, activeIde, activeIdeScheme) {
|
|
530
|
-
|
|
533
|
+
const configuredIdeMatchesActiveScheme = Boolean(configuredIde) && Boolean(activeIdeScheme) && normalizeIdeToken(configuredIde) === normalizeIdeToken(activeIdeScheme);
|
|
534
|
+
if (configuredIdeMatchesActiveScheme) {
|
|
535
|
+
return activeIdeScheme;
|
|
536
|
+
}
|
|
537
|
+
if (configuredIde && activeIdeScheme && normalizeIdeToken(activeIdeScheme).includes(normalizeIdeToken(configuredIde)) === false) {
|
|
531
538
|
return configuredIde;
|
|
532
539
|
}
|
|
533
540
|
return configuredIde || activeIdeScheme || activeIde || "vscode";
|
|
@@ -792,15 +799,15 @@ function getAnnotationDispatchErrorCode(error) {
|
|
|
792
799
|
}
|
|
793
800
|
|
|
794
801
|
// src/server/client-config.ts
|
|
795
|
-
async function buildClientConfig(
|
|
796
|
-
const userConfig = loadUserConfigSync(false,
|
|
797
|
-
const promptsConfig = await loadPromptsConfig(false,
|
|
802
|
+
async function buildClientConfig(serverState2) {
|
|
803
|
+
const userConfig = loadUserConfigSync(false, serverState2.cwd, serverState2.configRoot);
|
|
804
|
+
const promptsConfig = await loadPromptsConfig(false, serverState2.cwd, serverState2.configRoot);
|
|
798
805
|
const effectiveIde = userConfig.ide ?? "vscode";
|
|
799
806
|
let info;
|
|
800
|
-
if (!
|
|
807
|
+
if (!serverState2.ideInfo) {
|
|
801
808
|
info = { ide: effectiveIde };
|
|
802
809
|
} else {
|
|
803
|
-
const { scheme: _scheme, ...rest } =
|
|
810
|
+
const { scheme: _scheme, ...rest } = serverState2.ideInfo;
|
|
804
811
|
info = rest;
|
|
805
812
|
}
|
|
806
813
|
return {
|
|
@@ -837,17 +844,22 @@ var VSCODE_FAMILY_SCHEMES = [
|
|
|
837
844
|
"vscodium",
|
|
838
845
|
"codebuddy",
|
|
839
846
|
"codebuddy-cn",
|
|
847
|
+
"codebuddycn",
|
|
840
848
|
"antigravity"
|
|
841
849
|
];
|
|
842
|
-
function
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
850
|
+
function normalizeIdeToken2(value) {
|
|
851
|
+
return (value ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
852
|
+
}
|
|
853
|
+
function handleOpenFileRequest(body, serverState2) {
|
|
854
|
+
const absolutePath = resolveWorkspacePath(body.file, serverState2.cwd);
|
|
855
|
+
assertPathWithinIdeOpenScope(absolutePath, serverState2.projectRoot);
|
|
856
|
+
const userConfig = loadUserConfigSync(false, serverState2.cwd, serverState2.configRoot);
|
|
846
857
|
const configuredIde = userConfig.ide;
|
|
847
|
-
const activeIde =
|
|
848
|
-
const activeIdeScheme =
|
|
849
|
-
const
|
|
850
|
-
|
|
858
|
+
const activeIde = serverState2.ideInfo?.ide;
|
|
859
|
+
const activeIdeScheme = serverState2.ideInfo?.scheme;
|
|
860
|
+
const configuredIdeMatchesActiveScheme = Boolean(configuredIde) && Boolean(activeIdeScheme) && normalizeIdeToken2(configuredIde) === normalizeIdeToken2(activeIdeScheme);
|
|
861
|
+
const rawEditorHint = configuredIdeMatchesActiveScheme ? activeIdeScheme : configuredIde || activeIde || activeIdeScheme || "code";
|
|
862
|
+
if (configuredIde && activeIdeScheme && normalizeIdeToken2(activeIdeScheme).includes(normalizeIdeToken2(configuredIde)) === false) {
|
|
851
863
|
serverLogger2.warn(
|
|
852
864
|
`Active IDE is ${activeIdeScheme}, but config forces ${configuredIde}. Using configured IDE.`
|
|
853
865
|
);
|
|
@@ -992,14 +1004,14 @@ async function startServer() {
|
|
|
992
1004
|
if (fs5.existsSync(portFile)) {
|
|
993
1005
|
try {
|
|
994
1006
|
portData = JSON.parse(fs5.readFileSync(portFile, "utf-8"));
|
|
995
|
-
} catch (
|
|
1007
|
+
} catch (_e) {
|
|
996
1008
|
}
|
|
997
1009
|
}
|
|
998
1010
|
const rootHash = crypto2.createHash("md5").update(serverState.projectRoot).digest("hex");
|
|
999
1011
|
portData[rootHash] = port;
|
|
1000
1012
|
fs5.writeFileSync(portFile, JSON.stringify(portData, null, 2), "utf-8");
|
|
1001
|
-
} catch (
|
|
1002
|
-
serverLogger4.warn("Failed to write port file:",
|
|
1013
|
+
} catch (_e) {
|
|
1014
|
+
serverLogger4.warn("Failed to write port file:", _e);
|
|
1003
1015
|
}
|
|
1004
1016
|
process.once("exit", () => {
|
|
1005
1017
|
try {
|
|
@@ -1072,7 +1084,7 @@ async function handleRequest(url, req, res) {
|
|
|
1072
1084
|
let body;
|
|
1073
1085
|
try {
|
|
1074
1086
|
body = JSON.parse(await readBody(req));
|
|
1075
|
-
} catch (
|
|
1087
|
+
} catch (_e) {
|
|
1076
1088
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1077
1089
|
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
1078
1090
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.9_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js","../../../src/server/index.ts","../../../src/server/snippet.ts","../../../src/config.ts","../../../src/utils/logger.ts","../../../src/server/dispatch-transport.ts","../../../src/server/dispatch-runtime.ts","../../../src/server/path-guards.ts","../../../src/server/annotation-dispatch.ts","../../../src/server/client-config.ts","../../../src/server/open-file.ts","../../../src/server/project-root.ts","../../../src/injectors/utils.ts","../../../src/injectors/webpack.ts","../../../src/legacy/rspack/index.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import http from 'node:http'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport os from 'node:os'\nimport crypto from 'node:crypto'\nimport portfinder from 'portfinder'\nimport type {\n ServerState,\n OpenFileRequest,\n SendToAiRequest,\n SendToAiResponse,\n SendAnnotationsToAiRequest,\n SendAnnotationsToAiResponse,\n} from '@inspecto-dev/types'\nimport { INSPECTO_API_PATHS } from '@inspecto-dev/types'\nimport { extractSnippet } from './snippet.js'\nimport { dispatchAnnotationsToAi } from './annotation-dispatch.js'\nimport { readTicket } from './dispatch-transport.js'\nimport { dispatchPromptThroughIde, resolvePromptDispatchRuntime } from './dispatch-runtime.js'\nimport { assertPathWithinProject, resolveWorkspacePath } from './path-guards.js'\nimport { buildClientConfig } from './client-config.js'\nimport { handleOpenFileRequest } from './open-file.js'\nimport { resolveProjectRoot } from './project-root.js'\nimport { watchConfig, unwatchConfig, getGlobalLogLevel } from '../config.js'\nimport { createLogger } from '../utils/logger.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nexport const serverState: ServerState = {\n port: null,\n running: false,\n projectRoot: '',\n configRoot: '',\n cwd: process.cwd(),\n}\n\nlet serverInstance: http.Server | null = null\n\nexport async function startServer(): Promise<number> {\n if (serverState.running && serverState.port !== null) {\n return serverState.port\n }\n\n // Resolve project root at server start time so process.cwd() reflects the\n // actual project directory, not the module load-time cwd.\n serverState.projectRoot = resolveProjectRoot()\n serverState.configRoot = serverState.projectRoot\n serverState.cwd = process.cwd()\n\n portfinder.basePort = 5678\n const port = await portfinder.getPortPromise()\n\n // Watch for user config changes to trigger hot-reloads internally if needed\n watchConfig(\n () => {\n serverLogger.info('user config reloaded.')\n },\n serverState.cwd,\n serverState.configRoot,\n )\n\n serverInstance = http.createServer((req, res) => {\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type')\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204)\n res.end()\n return\n }\n\n const url = new URL(req.url ?? '/', `http://localhost:${port}`)\n handleRequest(url, req, res).catch(err => {\n serverLogger.error('server error:', err)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(err) }))\n })\n })\n\n await new Promise<void>((resolve, reject) => {\n serverInstance!.listen(port, '127.0.0.1', () => {\n serverInstance!.unref() // Allow process to exit\n resolve()\n })\n serverInstance!.once('error', reject)\n })\n\n // Add persistent error handler after successful startup\n serverInstance!.on('error', err => {\n serverLogger.error('persistent server error:', err)\n })\n\n serverState.port = port\n serverState.running = true\n\n // Write port file so the IDE extension can discover the server without scanning ports\n const portFile = path.join(os.tmpdir(), 'inspecto.port.json')\n try {\n let portData: Record<string, number> = {}\n if (fs.existsSync(portFile)) {\n try {\n portData = JSON.parse(fs.readFileSync(portFile, 'utf-8'))\n } catch (e) {\n // Invalid JSON, start fresh\n }\n }\n // Hash the project root to avoid invalid keys or paths in JSON\n const rootHash = crypto.createHash('md5').update(serverState.projectRoot).digest('hex')\n portData[rootHash] = port\n fs.writeFileSync(portFile, JSON.stringify(portData, null, 2), 'utf-8')\n } catch (e) {\n serverLogger.warn('Failed to write port file:', e)\n /* non-fatal — extension will fall back to scanning */\n }\n // Clean up on process exit (Vite terminates the process, not stopServer)\n process.once('exit', () => {\n try {\n if (fs.existsSync(portFile)) {\n const portData = JSON.parse(fs.readFileSync(portFile, 'utf-8'))\n const rootHash = crypto.createHash('md5').update(serverState.projectRoot).digest('hex')\n delete portData[rootHash]\n if (Object.keys(portData).length === 0) {\n fs.unlinkSync(portFile)\n } else {\n fs.writeFileSync(portFile, JSON.stringify(portData, null, 2), 'utf-8')\n }\n }\n } catch {\n /* ignore */\n }\n })\n\n serverLogger.info(`server running at http://127.0.0.1:${port}`)\n\n return port\n}\n\nexport function stopServer(): void {\n if (serverInstance) {\n serverInstance.close()\n serverInstance = null\n }\n unwatchConfig()\n serverState.running = false\n serverState.port = null\n try {\n fs.unlinkSync(path.join(os.tmpdir(), 'inspecto.port'))\n } catch {\n /* ignore */\n }\n}\n\nasync function readBody(req: http.IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = []\n req.on('data', (chunk: Buffer) => chunks.push(chunk))\n req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))\n req.on('error', reject)\n })\n}\n\nexport async function handleRequest(\n url: URL,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n): Promise<void> {\n const pathname = url.pathname\n\n // Health check - root or /inspecto/api/v1/health\n if ((pathname === '/health' || pathname === INSPECTO_API_PATHS.HEALTH) && req.method === 'GET') {\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ ok: true, port: serverState.port }))\n return\n }\n\n // Browser Client requests\n if (pathname === INSPECTO_API_PATHS.CLIENT_CONFIG && req.method === 'GET') {\n const config = await buildClientConfig(serverState)\n\n // Omit providers from the response sent to the client\n delete config.providers\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(config))\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.IDE_INFO && req.method === 'POST') {\n try {\n const body = JSON.parse(await readBody(req))\n\n // Workspace matching defense mechanism against multiple IDE connections\n const ideWorkspace = body.workspaceRoot || ''\n const serverProjectRoot = serverState.projectRoot || ''\n\n const normalizedIdeRoot = ideWorkspace ? path.resolve(ideWorkspace) : ''\n const normalizedServerRoot = serverProjectRoot ? path.resolve(serverProjectRoot) : ''\n\n const isSameProject =\n !normalizedIdeRoot ||\n !normalizedServerRoot ||\n normalizedIdeRoot === normalizedServerRoot ||\n normalizedServerRoot.startsWith(normalizedIdeRoot + path.sep) ||\n normalizedIdeRoot.startsWith(normalizedServerRoot + path.sep)\n\n if (isSameProject) {\n serverState.ideInfo = body\n serverLogger.debug(\n `Accepted IDE info from matched workspace (ide-${body.ide} / schema-${body.scheme})`,\n )\n } else {\n serverLogger.debug(\n `Ignored IDE info from unrelated workspace (IDE Workspace: ${ideWorkspace}, Server: ${serverProjectRoot}, Scheme: ${body.scheme}, IDE: ${body.ide})`,\n )\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: true }))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.IDE_INFO} POST request:`, e)\n res.writeHead(400, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Invalid JSON body' }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.IDE_OPEN && req.method === 'POST') {\n let body: OpenFileRequest\n try {\n body = JSON.parse(await readBody(req)) as OpenFileRequest\n } catch (e) {\n res.writeHead(400, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Invalid JSON body' }))\n return\n }\n\n try {\n handleOpenFileRequest(body, serverState)\n } catch (err: any) {\n serverLogger.warn(\n `Security: Blocked path traversal attempt in IDE_OPEN: ${body.file}. Reason: ${err.message}`,\n )\n res.writeHead(403, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Access denied: File is outside of project workspace' }))\n return\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: true }))\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.PROJECT_SNIPPET && req.method === 'GET') {\n const file = url.searchParams.get('file') ?? ''\n const line = parseInt(url.searchParams.get('line') ?? '1', 10)\n const column = parseInt(url.searchParams.get('column') ?? '1', 10)\n const maxLines = parseInt(url.searchParams.get('maxLines') ?? '100', 10)\n\n try {\n const absolutePath = resolveWorkspacePath(file, serverState.cwd)\n\n // Security: Prevent path traversal attacks\n try {\n assertPathWithinProject(absolutePath, serverState.projectRoot)\n } catch (err: any) {\n serverLogger.warn(\n `Security: Blocked path traversal attempt in PROJECT_SNIPPET: ${file}. Reason: ${err.message}`,\n )\n res.writeHead(403, { 'Content-Type': 'application/json' })\n res.end(\n JSON.stringify({\n success: false,\n error: 'Access denied: File is outside of project workspace',\n errorCode: 'FORBIDDEN',\n }),\n )\n return\n }\n\n const result = await extractSnippet({ file: absolutePath, line, column, maxLines })\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n } catch (err: any) {\n const message = String(err.message || err)\n const errorCode = message.startsWith('FILE_NOT_FOUND') ? 'FILE_NOT_FOUND' : 'UNKNOWN'\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: message, errorCode }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.AI_DISPATCH && req.method === 'POST') {\n try {\n const rawBody = await readBody(req)\n const body = JSON.parse(rawBody) as SendToAiRequest\n const result = await dispatchToAi(body)\n res.writeHead(result.success ? 200 : 500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.AI_DISPATCH} request:`, e)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(e), errorCode: 'INTERNAL_ERROR' }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.AI_BATCH_DISPATCH && req.method === 'POST') {\n try {\n const rawBody = await readBody(req)\n const body = JSON.parse(rawBody) as SendAnnotationsToAiRequest\n const result = await dispatchAnnotationsToAi(body, serverState)\n res.writeHead(getBatchDispatchStatusCode(result.errorCode, result.success), {\n 'Content-Type': 'application/json',\n })\n res.end(JSON.stringify(result))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.AI_BATCH_DISPATCH} request:`, e)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(e), errorCode: 'INTERNAL_ERROR' }))\n }\n return\n }\n\n // Handle IDE payload ticket retrieval\n if (pathname.startsWith(`${INSPECTO_API_PATHS.AI_TICKET}/`) && req.method === 'GET') {\n const ticketId = pathname.substring(INSPECTO_API_PATHS.AI_TICKET.length + 1)\n const payloadStr = readTicket(ticketId)\n\n if (!payloadStr) {\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: 'Ticket not found or expired' }))\n return\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(payloadStr)\n return\n }\n\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'not found' }))\n}\n\nasync function dispatchToAi(\n req: SendToAiRequest,\n): Promise<SendToAiResponse & { fallbackPayload?: { prompt: string; file: string } }> {\n const { location, snippet, prompt, screenshotContext } = req\n\n const formattedPrompt =\n prompt ??\n `Please help me with this code from \\`${location.file}\\` (line ${location.line}):\\n\\n\\`\\`\\`\\n${snippet}\\n\\`\\`\\`\\n`\n const runtime = resolvePromptDispatchRuntime(serverState)\n return dispatchPromptThroughIde(runtime, {\n prompt: formattedPrompt,\n filePath: location.file,\n line: location.line,\n column: location.column,\n snippet,\n ...(screenshotContext ? { screenshotContext } : {}),\n }) as SendToAiResponse & { fallbackPayload?: { prompt: string; file: string } }\n}\n\nfunction getBatchDispatchStatusCode(\n errorCode: SendAnnotationsToAiResponse['errorCode'],\n success: boolean,\n): number {\n if (success) return 200\n if (errorCode === 'INVALID_REQUEST') return 400\n if (errorCode === 'FORBIDDEN_PATH') return 403\n return 500\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport * as parser from '@babel/parser'\nimport traverse_ from '@babel/traverse'\n// Support both ESM default and CommonJS module.exports\nconst traverse =\n typeof traverse_ === 'function' ? traverse_ : (traverse_ as any).default || traverse_\nimport type { NodePath } from '@babel/traverse'\nimport type { Node } from '@babel/types'\nimport type { SnippetRequest, SnippetResponse } from '@inspecto-dev/types'\n\ninterface CacheEntry {\n mtime: number\n /** The full parsed source lines */\n lines: string[]\n}\n\n/** In-memory cache keyed by absolute file path */\nconst snippetCache = new Map<string, CacheEntry>()\n\nconst DEFAULT_MAX_LINES = 100\nconst DEFAULT_CONTEXT_LINES_BEFORE = 5\n\nexport async function extractSnippet(req: SnippetRequest): Promise<SnippetResponse> {\n const { file, line, column, maxLines = DEFAULT_MAX_LINES } = req\n\n const absolutePath = path.resolve(file)\n\n let stat: fs.Stats\n try {\n stat = await fs.promises.stat(absolutePath)\n } catch {\n throw new Error(`FILE_NOT_FOUND: ${absolutePath}`)\n }\n\n const mtime = stat.mtimeMs\n\n let lines: string[]\n const cached = snippetCache.get(absolutePath)\n if (cached && cached.mtime === mtime) {\n lines = cached.lines\n } else {\n const source = await fs.promises.readFile(absolutePath, 'utf-8')\n lines = source.split('\\n')\n snippetCache.set(absolutePath, { mtime, lines })\n }\n\n let snippetLines: string[]\n let startLine: number\n let componentName: string | undefined\n\n try {\n const result = extractComponentBoundary(lines.join('\\n'), line, column, maxLines)\n snippetLines = result.lines\n startLine = result.startLine\n componentName = result.name\n } catch {\n const before = Math.max(0, line - 1 - DEFAULT_CONTEXT_LINES_BEFORE)\n const after = Math.min(lines.length, before + maxLines)\n snippetLines = lines.slice(before, after)\n startLine = before + 1\n }\n\n if (snippetLines.length > maxLines) {\n snippetLines = snippetLines.slice(0, maxLines)\n }\n\n return {\n snippet: snippetLines.join('\\n'),\n startLine,\n file: absolutePath,\n ...(componentName ? { name: componentName } : {}),\n }\n}\n\ninterface BoundaryResult {\n lines: string[]\n startLine: number\n name?: string\n}\n\nfunction extractComponentBoundary(\n source: string,\n targetLine: number,\n _targetColumn: number,\n maxLines: number,\n): BoundaryResult {\n const ast = parser.parse(source, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript', 'decorators-legacy', 'classProperties'],\n errorRecovery: true,\n })\n\n const allLines = source.split('\\n')\n\n let bestStart = 0\n let bestEnd = allLines.length - 1\n let bestName: string | undefined\n\n traverse(ast, {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ClassMethod'(\n nodePath: NodePath<Node>,\n ) {\n const node = nodePath.node\n if (!node.loc) return\n\n const nodeStart = node.loc.start.line\n const nodeEnd = node.loc.end.line\n\n if (targetLine < nodeStart || targetLine > nodeEnd) return\n\n if (nodeEnd - nodeStart < bestEnd - bestStart) {\n bestStart = nodeStart - 1\n bestEnd = nodeEnd - 1\n bestName = extractFunctionName(nodePath)\n }\n },\n })\n\n let sliceStart = bestStart\n let sliceEnd = bestEnd + 1\n\n if (sliceEnd - sliceStart > maxLines) {\n const targetIdx = targetLine - 1\n sliceStart = Math.max(bestStart, targetIdx - Math.floor(maxLines / 3))\n sliceEnd = sliceStart + maxLines\n if (sliceEnd > bestEnd + 1) {\n sliceEnd = bestEnd + 1\n sliceStart = Math.max(0, sliceEnd - maxLines)\n }\n }\n\n return {\n lines: allLines.slice(sliceStart, sliceEnd),\n startLine: sliceStart + 1,\n ...(bestName ? { name: bestName } : {}),\n }\n}\n\nfunction extractFunctionName(nodePath: NodePath<Node>): string | undefined {\n const node = nodePath.node\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n return node.id.name\n }\n\n const parent = nodePath.parent\n if (\n (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&\n parent.type === 'VariableDeclarator' &&\n parent.id.type === 'Identifier'\n ) {\n return parent.id.name\n }\n\n if (node.type === 'ClassMethod' && node.key.type === 'Identifier') {\n return node.key.name\n }\n\n return undefined\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport os from 'node:os'\nimport { createDefu } from 'defu'\nimport type {\n InspectoSettings,\n InspectoPromptsConfig,\n Provider,\n ProviderMode,\n ToolOverrides,\n IdeType,\n LogLevel,\n} from '@inspecto-dev/types'\nimport {\n DEFAULT_PROVIDER_MODE,\n VALID_MODES,\n DEFAULT_INTENTS,\n IntentConfig,\n} from '@inspecto-dev/types'\nimport { createLogger, setLoggerGlobalLevel } from './utils/logger.js'\n\nconst configLogger = createLogger('inspecto:config')\n\nlet loadedConfig: InspectoSettings | null = null\nlet loadedPrompts: InspectoPromptsConfig | null = null\nlet globalLogLevel: LogLevel = 'warn'\nlet isWatching = false\n\n// Custom array merge behavior for defu: overwrite arrays instead of concatenating them\nconst arrayReplaceMerge = createDefu((obj, key, val) => {\n if (Array.isArray(val)) {\n obj[key] = val\n return true\n }\n})\n\nexport function setGlobalLogLevel(level?: LogLevel) {\n if (level) {\n globalLogLevel = level\n setLoggerGlobalLevel(level)\n }\n}\n\nexport function getGlobalLogLevel() {\n return globalLogLevel\n}\n\n/**\n * Walk from cwd up to gitRoot (inclusive), collecting directories that contain\n * a .inspecto/ subdirectory. Returns them ordered highest-priority first\n * (closest to cwd first).\n *\n * If cwd is not under gitRoot, only cwd itself is checked.\n */\nexport function resolveConfigRoots(cwd: string, gitRoot: string): string[] {\n const roots: string[] = []\n let current = cwd\n\n // Ensure we don't walk past gitRoot (handles cwd above gitRoot case)\n const isUnderOrEqual = current === gitRoot || current.startsWith(gitRoot + path.sep)\n if (!isUnderOrEqual) {\n // cwd is not under gitRoot — only check cwd\n if (fs.existsSync(path.join(cwd, '.inspecto'))) roots.push(cwd)\n return roots\n }\n\n while (true) {\n if (fs.existsSync(path.join(current, '.inspecto'))) {\n roots.push(current)\n }\n if (current === gitRoot) break\n const parent = path.dirname(current)\n if (parent === current) break // filesystem root guard\n current = parent\n }\n\n return roots\n}\n\n/**\n * Load and merge user config from all discovered .inspecto/ layers:\n *\n * Priority (highest → lowest):\n * <cwd>/.inspecto/settings.local.json\n * <cwd>/.inspecto/settings.json\n * ...intermediate dirs...\n * <gitRoot>/.inspecto/settings.local.json\n * <gitRoot>/.inspecto/settings.json\n * ~/.inspecto/settings.json\n *\n * @param force Bust cache and re-read from disk\n * @param cwd Working directory to start resolution from (default: process.cwd())\n * @param gitRoot Git repository root — upward traversal stops here (optional)\n */\nexport function loadUserConfigSync(\n force = false,\n cwd = process.cwd(),\n gitRoot?: string,\n): InspectoSettings {\n if (loadedConfig && !force) return loadedConfig\n loadedConfig = null // force clear\n\n const layers: Partial<InspectoSettings>[] = []\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n\n for (const root of roots) {\n layers.push(readJsonSafely(path.join(root, '.inspecto', 'settings.local.json')))\n layers.push(readJsonSafely(path.join(root, '.inspecto', 'settings.json')))\n }\n\n layers.push(readJsonSafely(path.join(os.homedir(), '.inspecto', 'settings.json')))\n layers.push({})\n\n const validLayers = layers.filter(l => l !== null)\n loadedConfig = arrayReplaceMerge(...(validLayers as [object, ...object[]])) as InspectoSettings\n return loadedConfig\n}\n\n/**\n * Load and merge prompts config from all discovered .inspecto/ layers:\n *\n * Priority (highest → lowest):\n * <cwd>/.inspecto/prompts.local.json\n * <cwd>/.inspecto/prompts.json\n * ...intermediate dirs...\n * <gitRoot>/.inspecto/prompts.local.json\n * <gitRoot>/.inspecto/prompts.json\n * ~/.inspecto/prompts.json\n *\n * Arrays in custom configurations are replaced instead of merged.\n */\nexport async function loadPromptsConfig(\n force = false,\n cwd = process.cwd(),\n gitRoot?: string,\n): Promise<InspectoPromptsConfig> {\n if (loadedPrompts && !force) return loadedPrompts\n\n const layers: any[] = []\n\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n for (const root of roots) {\n const localPath = path.join(root, '.inspecto', 'prompts.local.json')\n const jsonPath = path.join(root, '.inspecto', 'prompts.json')\n layers.push(readJsonSafely(localPath))\n layers.push(readJsonSafely(jsonPath))\n }\n\n layers.push(readJsonSafely(path.join(os.homedir(), '.inspecto', 'prompts.json')))\n\n // Find the first layer that contains a valid prompts config (array or $replace object).\n // Highest-priority layer wins — no merging across layers for prompts.\n let finalPrompts: any = []\n for (const layer of layers) {\n if (Array.isArray(layer) && layer.length > 0) {\n finalPrompts = layer\n break\n }\n if (\n layer &&\n typeof layer === 'object' &&\n layer.$replace === true &&\n Array.isArray(layer.items)\n ) {\n finalPrompts = layer\n break\n }\n }\n\n loadedPrompts = finalPrompts as InspectoPromptsConfig\n return loadedPrompts\n}\n\nfunction readJsonSafely(filePath: string): any {\n try {\n if (fs.existsSync(filePath)) {\n const content = fs.readFileSync(filePath, 'utf-8').trim()\n if (!content) return null // Return null instead of [] so we know it's empty\n const parsed = JSON.parse(content)\n // Transition helper: if user still has {\"prompts\": [...]}, extract it\n if (!Array.isArray(parsed) && parsed.prompts && Array.isArray(parsed.prompts)) {\n return parsed.prompts\n }\n return parsed\n }\n } catch (e) {\n // Ignore JSON parsing errors for empty or malformed files during watch\n if (e instanceof SyntaxError) {\n configLogger.warn(`Failed to parse config at ${filePath}: Invalid JSON`)\n } else {\n configLogger.warn(`Failed to read config at ${filePath}:`, e)\n }\n }\n return null\n}\n\n/**\n * Resolve the exact target tool to dispatch to based on user config.\n */\nexport function resolveTargetTool(config: InspectoSettings, ide: IdeType = 'vscode'): Provider {\n // Support \"provider.default\" (e.g., \"claude-code.extension\")\n const defaultProvider = config['provider.default'] as string | undefined\n if (defaultProvider) {\n const tool = defaultProvider.split('.')[0]\n return tool as Provider\n }\n\n // Fallback\n return 'copilot'\n}\n\n/**\n * Resolve the effective mode/type for a tool in the context of an IDE.\n */\nexport function resolveProviderMode(\n tool: Provider,\n ide: IdeType,\n config: InspectoSettings,\n): ProviderMode {\n let requestedType: ProviderMode | undefined = undefined\n\n // V2 format: check provider.default for \"tool.mode\"\n const defaultProvider = config['provider.default'] as string | undefined\n if (defaultProvider && defaultProvider.startsWith(`${tool}.`)) {\n const mode = defaultProvider.split('.')[1]\n if (mode === 'extension') requestedType = 'extension'\n if (mode === 'cli') requestedType = 'cli'\n }\n\n requestedType = requestedType ?? DEFAULT_PROVIDER_MODE[tool]\n const valid = VALID_MODES[tool] || [DEFAULT_PROVIDER_MODE[tool]]\n return requestedType && valid.includes(requestedType) ? requestedType : valid[0]!\n}\n\n/**\n * Extract ToolOverrides (binaryPath, args, etc) for Extension consumption.\n */\nexport function extractToolOverrides(\n ide: IdeType,\n config: InspectoSettings,\n): Partial<Record<Provider, ToolOverrides>> {\n const result: Partial<Record<Provider, ToolOverrides>> = {}\n\n if (!config) return result\n\n // Parse new flat `provider.*` format\n for (const [key, value] of Object.entries(config)) {\n if (!key.startsWith('provider.')) continue\n\n // We only process tool specific overrides, ignore `.default`\n if (key === 'provider.default') continue\n\n // Handle `provider.[tool].[mode]`\n const toolIndex = 1\n const modeIndex = 2\n const propIndex = 3\n\n const parts = key.split('.')\n\n if (parts.length >= propIndex + 1) {\n const tool = parts[toolIndex] as Provider\n const mode = parts[modeIndex] as ProviderMode\n const prop = parts[propIndex]\n\n if (!result[tool]) {\n result[tool] = { type: mode }\n }\n\n const overrides = result[tool]!\n\n // If we see config for a mode that differs from what we've initialized,\n // it means both modes have config. In v2, mode is determined by provider.default.\n // We will just accumulate the settings for now and let resolveProviderMode decide the active type.\n\n if (prop === 'bin') overrides.binaryPath = value as string\n if (prop === 'args') overrides.args = value as string[]\n if (prop === 'cwd') overrides.cwd = value as string\n if (prop === 'coldStartDelay') overrides.coldStartDelay = value as number\n }\n }\n\n return result\n}\n\nexport function resolveIntents(serverPrompts?: InspectoPromptsConfig): IntentConfig[] {\n // Start with DEFAULT_INTENTS as base\n const baseMap = new Map<string, IntentConfig>()\n for (const intent of DEFAULT_INTENTS) {\n baseMap.set(intent.id, { ...intent } as IntentConfig)\n }\n\n const defaults = () => Array.from(baseMap.values())\n\n if (!serverPrompts) return defaults()\n\n const isReplace =\n !Array.isArray(serverPrompts) &&\n typeof serverPrompts === 'object' &&\n serverPrompts.$replace === true\n const promptsArray = Array.isArray(serverPrompts)\n ? serverPrompts\n : isReplace\n ? serverPrompts.items\n : []\n\n if (!promptsArray || promptsArray.length === 0) return defaults()\n\n if (isReplace) {\n // $replace: true — exact list, user controls everything\n const result: IntentConfig[] = []\n for (const item of promptsArray) {\n if (typeof item === 'string') {\n if (baseMap.has(item)) {\n result.push(baseMap.get(item)!)\n } else {\n configLogger.warn(\n `Unknown built-in intent id: \"${item}\". Available: ${[...baseMap.keys()].join(', ')}`,\n )\n }\n } else if (typeof item === 'object') {\n if (!item.id) {\n configLogger.warn('Intent object missing required \"id\" field, skipping.')\n continue\n }\n if (item.enabled === false) {\n configLogger.warn(\n `Intent \"${item.id}\" is listed in $replace but has enabled:false — it will be excluded.`,\n )\n continue\n }\n if (!item.aiIntent) {\n configLogger.warn(`Intent \"${item.id}\" is missing required \"aiIntent\".`)\n continue\n }\n result.push(\n (baseMap.has(item.id) ? { ...baseMap.get(item.id)!, ...item } : item) as IntentConfig,\n )\n }\n }\n return result\n }\n\n // Default: append / override mode.\n // - Objects with known id: merge over built-in (or remove if enabled:false)\n // - Objects with unknown id: append as new intent\n // - Strings: not meaningful in append mode (order is fixed to built-in order + appended)\n const merged = Array.from(baseMap.values())\n\n for (const item of promptsArray) {\n if (typeof item === 'string') {\n if (!baseMap.has(item)) {\n configLogger.warn(\n `Unknown built-in intent id: \"${item}\". In append mode, strings have no effect on ordering — use $replace to control order.`,\n )\n }\n // Known string ids are already in merged — nothing to do\n continue\n }\n\n if (typeof item === 'object') {\n if (!item.id) {\n configLogger.warn('Intent object missing required \"id\" field, skipping.')\n continue\n }\n if (!item.aiIntent) {\n configLogger.warn(`Intent \"${item.id}\" is missing required \"aiIntent\".`)\n continue\n }\n const existingIdx = merged.findIndex(i => i.id === item.id)\n if (existingIdx !== -1) {\n if (item.enabled === false) {\n merged.splice(existingIdx, 1)\n } else {\n merged[existingIdx] = { ...merged[existingIdx], ...item } as IntentConfig\n }\n } else {\n if (item.enabled !== false) {\n merged.push(item as IntentConfig)\n }\n }\n }\n }\n\n return merged\n}\n\nlet watchers: fs.FSWatcher[] = []\n\nexport function watchConfig(onReload: () => void, cwd = process.cwd(), gitRoot?: string): void {\n if (isWatching) return\n isWatching = true\n\n // Watch .inspecto/ directories rather than individual files so that newly\n // created files (e.g. prompts.local.json added after server start) are picked up.\n const watchDirs: string[] = [path.join(os.homedir(), '.inspecto')]\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n for (const root of roots) {\n watchDirs.push(path.join(root, '.inspecto'))\n }\n\n const CONFIG_FILES = new Set([\n 'settings.json',\n 'settings.local.json',\n 'prompts.json',\n 'prompts.local.json',\n ])\n\n for (const dir of watchDirs) {\n if (!fs.existsSync(dir)) continue\n try {\n const watcher = fs.watch(dir, async (eventType, filename) => {\n if (!filename || !CONFIG_FILES.has(filename)) return\n loadedConfig = null\n loadedPrompts = null\n loadUserConfigSync(true, cwd, gitRoot)\n await loadPromptsConfig(true, cwd, gitRoot)\n onReload()\n })\n watcher.unref()\n watchers.push(watcher)\n } catch (e) {\n // ignore watch errors (e.g. unsupported fs)\n }\n }\n}\n\nexport function unwatchConfig(): void {\n for (const watcher of watchers) {\n watcher.close()\n }\n watchers = []\n isWatching = false\n}\n","import type { LogLevel } from '@inspecto-dev/types'\n\nexport interface Logger {\n info(msg: string, ...args: any[]): void\n warn(msg: string, ...args: any[]): void\n error(msg: string, ...args: any[]): void\n debug(msg: string, ...args: any[]): void\n setLevel?(level: LogLevel): void\n}\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n}\n\n// Very simple implementation of a DEBUG matching string.\n// Supports `DEBUG=inspecto:*` or `DEBUG=inspecto:server,inspecto:ast`\nfunction isDebugEnabled(namespace: string): boolean {\n if (typeof process === 'undefined' || !process.env) return false\n const debugEnv = process.env.DEBUG\n if (!debugEnv) return false\n\n const namespaces = debugEnv.split(',').map(s => s.trim())\n for (const ns of namespaces) {\n if (ns === '*') return true\n if (ns.endsWith('*')) {\n const prefix = ns.slice(0, -1)\n if (namespace.startsWith(prefix)) return true\n } else if (ns === namespace) {\n return true\n }\n }\n return false\n}\n\n// Store global level locally to avoid circular dependency with config.ts\nlet globalLevel: LogLevel = 'warn'\nconst registeredLoggers: Set<Logger> = new Set()\n\nexport function setLoggerGlobalLevel(level: LogLevel) {\n globalLevel = level\n for (const logger of registeredLoggers) {\n if (logger.setLevel) {\n logger.setLevel(level)\n }\n }\n}\n\nexport function createLogger(namespace: string, options?: { logLevel?: LogLevel }): Logger {\n let currentLevel = options?.logLevel ?? globalLevel\n let numericLevel = LOG_LEVELS[currentLevel] ?? 2\n const debugEnabled = isDebugEnabled(namespace)\n\n const logger: Logger = {\n setLevel(level: LogLevel) {\n currentLevel = level\n numericLevel = LOG_LEVELS[level] ?? 2\n },\n info(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.info) {\n console.log(`\\x1b[36m[inspecto]\\x1b[0m ${msg}`, ...args)\n }\n },\n warn(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.warn) {\n console.warn(`\\x1b[33m[inspecto] WARN:\\x1b[0m ${msg}`, ...args)\n }\n },\n error(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.error) {\n console.error(`\\x1b[31m[inspecto] ERROR:\\x1b[0m ${msg}`, ...args)\n }\n },\n debug(msg: string, ...args: any[]) {\n if (debugEnabled) {\n console.log(`\\x1b[90m[${namespace}]\\x1b[0m ${msg}`, ...args)\n }\n },\n }\n\n registeredLoggers.add(logger)\n\n return logger\n}\n","import crypto from 'node:crypto'\nimport { execFileSync } from 'node:child_process'\nimport { launchIDE } from 'launch-ide'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nconst payloadTickets = new Map<string, string>()\n\nexport function createTicket(payload: unknown): string {\n const ticketId = crypto.randomUUID()\n payloadTickets.set(ticketId, JSON.stringify(payload))\n\n setTimeout(\n () => {\n payloadTickets.delete(ticketId)\n },\n 5 * 60 * 1000,\n )\n\n return ticketId\n}\n\nexport function readTicket(ticketId: string): string | undefined {\n return payloadTickets.get(ticketId)\n}\n\nexport function launchURI(uri: string): void {\n try {\n if (process.platform === 'darwin') {\n execFileSync('open', [uri])\n } else if (process.platform === 'win32') {\n execFileSync('cmd', ['/c', 'start', '\"\"', uri])\n } else {\n execFileSync('xdg-open', [uri])\n }\n } catch (e) {\n serverLogger.error('Failed to launch URI via execFileSync, falling back to launchIDE:', e)\n launchIDE({ file: uri })\n }\n}\n","import type {\n IdeType,\n Provider,\n ProviderMode,\n ScreenshotContext,\n ServerState,\n ToolOverrides,\n} from '@inspecto-dev/types'\nimport {\n extractToolOverrides,\n loadUserConfigSync,\n resolveProviderMode,\n resolveTargetTool,\n} from '../config.js'\nimport { createTicket, launchURI } from './dispatch-transport.js'\n\nexport interface PromptDispatchRuntime {\n resolvedTarget: Provider\n finalIde: string\n mode: ProviderMode\n overrides?: ToolOverrides\n autoSend?: boolean\n}\n\nexport interface PromptDispatchPayload {\n prompt: string\n filePath?: string\n line?: number\n column?: number\n snippet?: string\n screenshotContext?: ScreenshotContext\n}\n\nexport interface PromptDispatchResult {\n success: true\n fallbackPayload: {\n prompt: string\n file?: string\n }\n}\n\nexport function resolvePromptDispatchRuntime(\n state: Pick<ServerState, 'projectRoot' | 'cwd' | 'ideInfo'>,\n): PromptDispatchRuntime {\n const userConfig = loadUserConfigSync(false, state.cwd, state.projectRoot)\n const resolvedTarget = resolveTargetTool(userConfig)\n const finalIde = resolveFinalIde(userConfig.ide, state.ideInfo?.ide, state.ideInfo?.scheme)\n const mode = resolveProviderMode(resolvedTarget, finalIde as IdeType, userConfig)\n const overrides =\n extractToolOverrides(finalIde as IdeType, userConfig)[resolvedTarget] || undefined\n\n return {\n resolvedTarget,\n finalIde,\n mode,\n ...(hasOverrides(overrides) ? { overrides } : {}),\n ...(userConfig['prompt.autoSend'] !== undefined\n ? { autoSend: Boolean(userConfig['prompt.autoSend']) }\n : {}),\n }\n}\n\nexport function dispatchPromptThroughIde(\n runtime: PromptDispatchRuntime,\n payload: PromptDispatchPayload,\n): PromptDispatchResult {\n const ticketId = createTicket({\n ide: runtime.finalIde,\n target: runtime.resolvedTarget,\n targetType: runtime.mode,\n prompt: payload.prompt,\n filePath: payload.filePath,\n line: payload.line,\n column: payload.column,\n snippet: payload.snippet,\n ...(payload.screenshotContext ? { screenshotContext: payload.screenshotContext } : {}),\n overrides: runtime.overrides,\n autoSend: runtime.autoSend,\n })\n\n const params = new URLSearchParams()\n params.set('ticket', ticketId)\n params.set('target', runtime.resolvedTarget)\n\n launchURI(`${runtime.finalIde}://inspecto.inspecto/send?${params.toString()}`)\n\n return {\n success: true,\n fallbackPayload: {\n prompt: payload.prompt,\n ...(payload.filePath ? { file: payload.filePath } : {}),\n },\n }\n}\n\nfunction resolveFinalIde(\n configuredIde: string | undefined,\n activeIde: string | undefined,\n activeIdeScheme: string | undefined,\n): string {\n if (configuredIde && activeIdeScheme && !activeIdeScheme.includes(configuredIde)) {\n return configuredIde\n }\n\n return configuredIde || activeIdeScheme || activeIde || 'vscode'\n}\n\nfunction hasOverrides(overrides: ToolOverrides | undefined): overrides is ToolOverrides {\n return Boolean(overrides && Object.keys(overrides).length > 0)\n}\n","import path from 'node:path'\nimport fs from 'node:fs'\n\nfunction isWindowsAbsolutePath(file: string): boolean {\n return /^[a-zA-Z]:[\\\\/]/.test(file) || /^\\\\\\\\[^\\\\]+\\\\[^\\\\]+/.test(file)\n}\n\nexport function resolveWorkspacePath(file: string, cwd: string): string {\n if (isWindowsAbsolutePath(file)) {\n return path.win32.normalize(file)\n }\n return path.isAbsolute(file) ? path.resolve(file) : path.resolve(cwd, file)\n}\n\nexport function assertPathWithinProject(file: string, projectRoot: string): void {\n let realFile = file\n let realProjectRoot = projectRoot\n try {\n if (fs.existsSync(file)) {\n realFile = fs.realpathSync(file)\n }\n } catch {\n // ignore\n }\n\n try {\n if (fs.existsSync(projectRoot)) {\n realProjectRoot = fs.realpathSync(projectRoot)\n }\n } catch {\n // ignore\n }\n\n if (isWithinPath(file, projectRoot) || isWithinPath(realFile, realProjectRoot)) {\n return\n }\n\n throw new Error(\n `Access denied: File ${normalizeForComparison(realFile)} is outside of project workspace ${normalizeForComparison(realProjectRoot)}`,\n )\n}\n\nfunction tryReadPackageName(packageRoot: string): string | undefined {\n try {\n const packageJsonPath = path.join(packageRoot, 'package.json')\n if (!fs.existsSync(packageJsonPath)) return undefined\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string }\n return typeof packageJson.name === 'string' ? packageJson.name : undefined\n } catch {\n return undefined\n }\n}\n\nfunction findNearestPackageRoot(file: string): string | undefined {\n let current = path.dirname(file)\n\n while (true) {\n if (fs.existsSync(path.join(current, 'package.json'))) {\n return current\n }\n const parent = path.dirname(current)\n if (parent === current) {\n return undefined\n }\n current = parent\n }\n}\n\nfunction normalizeForComparison(file: string): string {\n return isWindowsAbsolutePath(file) ? path.win32.normalize(file) : path.normalize(file)\n}\n\nfunction pathSeparatorFor(file: string): string {\n return isWindowsAbsolutePath(file) ? path.win32.sep : path.sep\n}\n\nfunction isWithinPath(file: string, root: string): boolean {\n const normalizedFile = normalizeForComparison(file)\n const normalizedRoot = normalizeForComparison(root)\n const separator = pathSeparatorFor(normalizedRoot)\n const rootWithSep = normalizedRoot.endsWith(separator)\n ? normalizedRoot\n : normalizedRoot + separator\n return normalizedFile === normalizedRoot || normalizedFile.startsWith(rootWithSep)\n}\n\nfunction resolveLinkedDependencyEntry(\n projectRoot: string,\n packageName: string,\n): string | undefined {\n const packageSegments = packageName.split('/')\n const dependencyPath = path.join(projectRoot, 'node_modules', ...packageSegments)\n if (!fs.existsSync(dependencyPath)) return undefined\n\n try {\n return fs.realpathSync(dependencyPath)\n } catch {\n return dependencyPath\n }\n}\n\nfunction isLinkedDependencyPath(file: string, projectRoot: string, packageName: string): boolean {\n const linkedDependencyRoot = resolveLinkedDependencyEntry(projectRoot, packageName)\n if (!linkedDependencyRoot) return false\n\n return isWithinPath(file, linkedDependencyRoot)\n}\n\nfunction isLinkedDependencySourcePath(file: string, projectRoot: string): boolean {\n const packageRoot = findNearestPackageRoot(file)\n if (!packageRoot) return false\n\n const packageName = tryReadPackageName(packageRoot)\n if (!packageName) return false\n\n return isLinkedDependencyPath(file, projectRoot, packageName)\n}\n\nexport function assertPathWithinIdeOpenScope(file: string, projectRoot: string): void {\n try {\n assertPathWithinProject(file, projectRoot)\n return\n } catch {\n if (isLinkedDependencySourcePath(file, projectRoot)) {\n return\n }\n throw new Error(`Access denied: File is outside of project workspace`)\n }\n}\n","import type {\n AnnotationIntent,\n AiErrorCode,\n RuntimeContextEnvelope,\n RuntimeEvidenceRecord,\n ScreenshotContext,\n SendAnnotationsToAiRequest,\n SendAnnotationsToAiResponse,\n ServerState,\n} from '@inspecto-dev/types'\nimport { dispatchPromptThroughIde, resolvePromptDispatchRuntime } from './dispatch-runtime.js'\nimport { assertPathWithinProject, resolveWorkspacePath } from './path-guards.js'\n\nexport interface NormalizedAnnotationTarget {\n file: string\n line: number\n column: number\n label?: string\n selector?: string\n snippet?: string\n}\n\nexport interface NormalizedAnnotation {\n index: number\n note: string\n intent: AnnotationIntent\n targets: NormalizedAnnotationTarget[]\n}\n\nexport interface NormalizedAnnotationBatch {\n instruction: string\n responseMode: 'unified' | 'per-annotation'\n annotations: NormalizedAnnotation[]\n runtimeContext?: RuntimeContextEnvelope\n screenshotContext?: ScreenshotContext\n cssContextPrompt?: string\n}\n\nclass AnnotationDispatchError extends Error {\n readonly errorCode: AiErrorCode\n\n constructor(message: string, errorCode: AiErrorCode) {\n super(message)\n this.name = 'AnnotationDispatchError'\n this.errorCode = errorCode\n }\n}\n\nexport async function dispatchAnnotationsToAi(\n req: SendAnnotationsToAiRequest,\n state: Pick<ServerState, 'projectRoot' | 'cwd' | 'ideInfo'>,\n): Promise<SendAnnotationsToAiResponse> {\n try {\n validateAnnotationDispatchRequest(req, state)\n const batch = normalizeAnnotationBatch(req)\n const prompt = buildAnnotationBatchPrompt(batch)\n const representativeTarget = batch.annotations[0]?.targets[0]\n const runtime = resolvePromptDispatchRuntime(state)\n\n return dispatchPromptThroughIde(runtime, {\n prompt,\n ...(representativeTarget?.file ? { filePath: representativeTarget.file } : {}),\n ...(representativeTarget?.line ? { line: representativeTarget.line } : {}),\n ...(representativeTarget?.column ? { column: representativeTarget.column } : {}),\n ...(batch.screenshotContext ? { screenshotContext: batch.screenshotContext } : {}),\n })\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n errorCode: getAnnotationDispatchErrorCode(error),\n }\n }\n}\n\nexport function validateAnnotationDispatchRequest(\n req: SendAnnotationsToAiRequest,\n state: Pick<ServerState, 'projectRoot' | 'cwd'>,\n): void {\n if (!req.annotations.length) {\n throw new AnnotationDispatchError('At least one annotation is required.', 'INVALID_REQUEST')\n }\n\n for (const annotation of req.annotations) {\n if (!annotation.targets.length) {\n throw new AnnotationDispatchError(\n 'Each annotation must include at least one target.',\n 'INVALID_REQUEST',\n )\n }\n\n for (const target of annotation.targets) {\n const absolutePath = resolveWorkspacePath(target.location.file, state.cwd)\n assertPathWithinProject(absolutePath, state.projectRoot)\n }\n }\n}\n\nexport function normalizeAnnotationBatch(\n req: SendAnnotationsToAiRequest,\n): NormalizedAnnotationBatch {\n return {\n instruction: req.instruction?.trim() ?? '',\n responseMode: req.responseMode ?? 'unified',\n ...(req.runtimeContext ? { runtimeContext: req.runtimeContext } : {}),\n ...(req.screenshotContext ? { screenshotContext: req.screenshotContext } : {}),\n ...(req.cssContextPrompt?.trim() ? { cssContextPrompt: req.cssContextPrompt.trim() } : {}),\n annotations: req.annotations.map((annotation, index) => ({\n index: index + 1,\n note: annotation.note.trim(),\n intent: annotation.intent,\n targets: annotation.targets.map(target => ({\n file: target.location.file,\n line: target.location.line,\n column: target.location.column,\n ...(target.label ? { label: target.label } : {}),\n ...(target.selector ? { selector: target.selector } : {}),\n ...(target.snippet ? { snippet: target.snippet } : {}),\n })),\n })),\n }\n}\n\nexport function buildAnnotationBatchPrompt(batch: NormalizedAnnotationBatch): string {\n const body = buildSelectedElementsPrompt(batch.annotations)\n const prompt = batch.instruction ? `${batch.instruction}\\n\\n${body}` : body\n\n return appendScreenshotContextSection(\n appendCssContextSection(\n appendRuntimeContextSection(prompt, batch.runtimeContext),\n batch.cssContextPrompt,\n ),\n batch.screenshotContext,\n )\n}\n\nfunction appendCssContextSection(prompt: string, cssContextPrompt: string | undefined): string {\n if (!cssContextPrompt) return prompt\n return `${prompt}\\n\\n${cssContextPrompt}`\n}\n\nfunction buildSelectedElementsPrompt(annotations: NormalizedAnnotation[]): string {\n const lines = ['Selected elements:']\n\n for (const annotation of annotations) {\n const trimmedNote = annotation.note.trim()\n for (const target of annotation.targets) {\n const targetLabel = (target.label || 'Unknown target').trim() || 'Unknown target'\n lines.push(`- ${targetLabel}`)\n lines.push(`file=${target.file}:${target.line}:${target.column}`)\n if (trimmedNote) {\n lines.push(`note=${trimmedNote}`)\n }\n }\n }\n\n if (lines.length === 1) {\n lines.push('- None')\n }\n\n return lines.join('\\n')\n}\n\nfunction appendScreenshotContextSection(\n prompt: string,\n screenshotContext: ScreenshotContext | undefined,\n): string {\n if (!screenshotContext || (!screenshotContext.imageDataUrl && !screenshotContext.imageAssetId)) {\n return prompt\n }\n\n const lines = [\n 'Visual screenshot context attached:',\n `- capturedAt=${screenshotContext.capturedAt}`,\n `- mimeType=${screenshotContext.mimeType}`,\n ...(screenshotContext.imageAssetId ? [`- imageAssetId=${screenshotContext.imageAssetId}`] : []),\n ]\n\n return `${prompt}\\n\\n${lines.join('\\n')}`\n}\n\nfunction appendRuntimeContextSection(\n prompt: string,\n runtimeContext: RuntimeContextEnvelope | undefined,\n): string {\n if (!runtimeContext?.records.length) {\n return prompt\n }\n\n return `${prompt}\\n\\n${buildRuntimeContextSection(runtimeContext.records)}`\n}\n\nfunction buildRuntimeContextSection(records: RuntimeEvidenceRecord[]): string {\n return ['Relevant runtime context:', ...records.map(formatRuntimeRecord)].join('\\n')\n}\n\nfunction formatRuntimeRecord(record: RuntimeEvidenceRecord): string {\n const requestSummary =\n record.kind === 'failed-request'\n ? `request=${record.request?.method ?? 'GET'} ${record.request?.pathname ?? record.request?.url ?? 'unknown'} status=${record.request?.status ?? 'unknown'}`\n : `occurrences=${record.occurrenceCount}`\n const reasonSummary = record.relevanceReasons.length\n ? record.relevanceReasons.join('; ')\n : 'timing-based'\n const stackSummary = record.stack\n ? `\\n stack=${record.stack.split('\\n').slice(0, 5).join(' | ')}`\n : ''\n\n return [\n `- [${record.kind}] ${record.message}`,\n ` relevance=${record.relevanceLevel} (${reasonSummary})`,\n ` ${requestSummary}`,\n stackSummary,\n ]\n .filter(Boolean)\n .join('\\n')\n}\n\nfunction getAnnotationDispatchErrorCode(error: unknown): AiErrorCode {\n if (error instanceof AnnotationDispatchError) return error.errorCode\n if (error instanceof Error && error.message.includes('outside of project workspace')) {\n return 'FORBIDDEN_PATH'\n }\n return 'UNKNOWN'\n}\n","import type { IdeType, InspectoConfig, ServerState } from '@inspecto-dev/types'\nimport { loadPromptsConfig, loadUserConfigSync, resolveIntents } from '../config.js'\n\nexport async function buildClientConfig(\n serverState: ServerState,\n): Promise<InspectoConfig & { autoSend: boolean }> {\n const userConfig = loadUserConfigSync(false, serverState.cwd, serverState.configRoot)\n const promptsConfig = await loadPromptsConfig(false, serverState.cwd, serverState.configRoot)\n const effectiveIde = (userConfig.ide ?? 'vscode') as IdeType\n\n let info: any\n if (!serverState.ideInfo) {\n info = { ide: effectiveIde }\n } else {\n const { scheme: _scheme, ...rest } = serverState.ideInfo as any\n info = rest\n }\n\n return {\n ...info,\n prompts: resolveIntents(promptsConfig),\n hotKeys: userConfig['inspector.hotKey'] ?? 'alt',\n theme: userConfig['inspector.theme'] ?? 'auto',\n includeSnippet: userConfig['prompt.includeSnippet'] ?? false,\n runtimeContext: {\n enabled: true,\n preview: true,\n maxRuntimeErrors: 3,\n maxFailedRequests: 2,\n },\n screenshotContext: {\n enabled: false,\n },\n annotationResponseMode: userConfig['prompt.annotationResponseMode'] ?? 'unified',\n autoSend: userConfig['prompt.autoSend'] ?? false,\n }\n}\n","import { execFileSync } from 'node:child_process'\nimport { Editor, launchIDE } from 'launch-ide'\nimport type { OpenFileRequest, ServerState } from '@inspecto-dev/types'\nimport { loadUserConfigSync } from '../config.js'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\nimport { assertPathWithinIdeOpenScope, resolveWorkspacePath } from './path-guards.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nconst VSCODE_FAMILY_SCHEMES = [\n 'vscode',\n 'vscode-insiders',\n 'cursor',\n 'windsurf',\n 'trae',\n 'trae-cn',\n 'vscodium',\n 'codebuddy',\n 'codebuddy-cn',\n 'antigravity',\n]\n\nexport function handleOpenFileRequest(\n body: OpenFileRequest,\n serverState: ServerState,\n): { success: true } {\n const absolutePath = resolveWorkspacePath(body.file, serverState.cwd)\n\n assertPathWithinIdeOpenScope(absolutePath, serverState.projectRoot)\n\n const userConfig = loadUserConfigSync(false, serverState.cwd, serverState.configRoot)\n const configuredIde = userConfig.ide\n const activeIde = serverState.ideInfo?.ide\n const activeIdeScheme = serverState.ideInfo?.scheme\n\n const rawEditorHint = configuredIde || activeIde || activeIdeScheme || 'code'\n\n if (configuredIde && activeIdeScheme && !activeIdeScheme.includes(configuredIde)) {\n serverLogger.warn(\n `Active IDE is ${activeIdeScheme}, but config forces ${configuredIde}. Using configured IDE.`,\n )\n }\n\n let editorHint = rawEditorHint\n if (rawEditorHint === 'vscode') editorHint = 'code'\n else if (rawEditorHint === 'vscode-insiders') editorHint = 'code-insiders'\n else if (rawEditorHint === 'vscodium') editorHint = 'codium'\n else if (rawEditorHint === 'trae-cn' || rawEditorHint === 'trae') editorHint = 'trae'\n\n serverLogger.debug(\n `IDE_OPEN: activeIde=${activeIde}, activeIdeScheme=${activeIdeScheme}, configuredIde=${configuredIde} -> rawEditorHint=${rawEditorHint}, finalEditorHint=${editorHint}`,\n )\n\n if (VSCODE_FAMILY_SCHEMES.includes(rawEditorHint)) {\n let normalizedPath = absolutePath.replace(/\\\\/g, '/')\n if (!normalizedPath.startsWith('/')) {\n normalizedPath = '/' + normalizedPath\n }\n const encodedPath = encodeURI(normalizedPath)\n const uri = `${rawEditorHint}://file${encodedPath}:${body.line}:${body.column}`\n serverLogger.debug(`IDE_OPEN: Bypassing launchIDE, using URI scheme directly: ${uri}`)\n\n try {\n if (process.platform === 'darwin') {\n execFileSync('open', [uri])\n } else if (process.platform === 'win32') {\n execFileSync('cmd', ['/c', 'start', '\"\"', uri])\n } else {\n execFileSync('xdg-open', [uri])\n }\n } catch (e) {\n serverLogger.error(`Failed to launch URI for IDE_OPEN (${uri}):`, e)\n launchIDE({\n file: absolutePath,\n line: body.line,\n column: body.column,\n editor: editorHint as Editor,\n type: process.platform === 'darwin' ? 'open' : 'exec',\n })\n }\n } else {\n launchIDE({\n file: absolutePath,\n line: body.line,\n column: body.column,\n editor: editorHint as Editor,\n type: process.platform === 'darwin' ? 'open' : 'exec',\n })\n }\n\n return { success: true }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport { execSync } from 'node:child_process'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nexport function resolveProjectRoot(): string {\n const cwd = process.cwd()\n let gitRoot: string\n try {\n gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim()\n } catch (e) {\n serverLogger.warn('Failed to resolve git root via git rev-parse:', e)\n gitRoot = cwd\n }\n\n const visited = new Set<string>()\n const search = (start: string, stop: string) => {\n let current = start\n while (!visited.has(current)) {\n visited.add(current)\n if (fs.existsSync(path.join(current, '.inspecto'))) return current\n if (current === stop) break\n const parent = path.dirname(current)\n if (parent === current) break\n current = parent\n }\n return null\n }\n\n const cwdMatch = search(cwd, path.parse(cwd).root)\n if (cwdMatch) return cwdMatch\n\n const repoMatch = search(gitRoot, path.parse(gitRoot).root)\n if (repoMatch) return repoMatch\n\n return gitRoot\n}\n","import { createRequire } from 'node:module'\n\n// Safely resolve the client module without breaking ESM/CJS or bundling\nexport const resolveClientModule = () => {\n try {\n return createRequire(import.meta.url).resolve('@inspecto-dev/core')\n } catch {\n try {\n return require.resolve('@inspecto-dev/core')\n } catch {\n console.warn(\n '[inspecto] Could not resolve @inspecto-dev/core — falling back to bare specifier',\n )\n return '@inspecto-dev/core'\n }\n }\n}\n","export function getWebpackHtmlScript(serverPort: number) {\n return `\nwindow.__AI_INSPECTOR_PORT__ = ${serverPort};\nwindow.addEventListener('load', () => {\n if (window.InspectoClient) {\n window.InspectoClient.mountInspector({\n serverUrl: 'http://127.0.0.1:' + window.__AI_INSPECTOR_PORT__,\n });\n }\n});\n`\n}\n\nexport function getWebpackAssetScript(serverPort: number) {\n return `\nif (typeof window !== 'undefined') {\n window.__AI_INSPECTOR_PORT__ = ${serverPort};\n const _initInspecto = () => {\n if (window.InspectoClient) {\n window.InspectoClient.mountInspector({\n serverUrl: 'http://127.0.0.1:' + window.__AI_INSPECTOR_PORT__,\n });\n } else {\n setTimeout(_initInspecto, 100);\n }\n };\n if (document.readyState === 'complete') {\n _initInspecto();\n } else {\n window.addEventListener('load', _initInspecto);\n }\n}\n`\n}\n\nexport function injectWebpack(\n compiler: any,\n serverPortFn: () => Promise<number>,\n resolveClientModule: () => string,\n) {\n const inspectoClientPath = resolveClientModule()\n\n // Inject the client logic directly using the absolute path\n if (compiler.webpack && compiler.webpack.EntryPlugin) {\n // Webpack 5+\n new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {\n name: undefined,\n }).apply(compiler)\n }\n\n compiler.hooks.compilation.tap('inspecto-overlay', (compilation: any) => {\n // Find HtmlWebpackPlugin (standard Webpack)\n const HtmlWebpackPlugin = compiler.options.plugins.find(\n (p: any) => p && p.constructor && p.constructor.name === 'HtmlWebpackPlugin',\n )\n if (HtmlWebpackPlugin) {\n const hooks = (HtmlWebpackPlugin.constructor as any).getHooks(compilation)\n hooks.alterAssetTagGroups.tapPromise('inspecto-overlay', async (data: any) => {\n const port = await serverPortFn()\n data.headTags.unshift({\n tagName: 'script',\n voidTag: false,\n meta: { plugin: 'inspecto-overlay' },\n innerHTML: getWebpackHtmlScript(port),\n })\n return data\n })\n } else {\n // Fallback for frameworks like Next.js that don't use HtmlWebpackPlugin\n if (compilation.hooks.processAssets) {\n // Webpack 5+\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'inspecto-overlay',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n async (assets: any) => {\n const port = await serverPortFn()\n\n // Only inject into the main client entry chunks (e.g. main-app, main.js, umi.js)\n const mainAssetKey = Object.keys(assets).find(\n key =>\n key.endsWith('.js') &&\n (key.includes('main') || key.includes('app') || key.includes('umi')),\n )\n if (!mainAssetKey) return\n\n const originalSource = assets[mainAssetKey].source()\n assets[mainAssetKey] = new compiler.webpack.sources.RawSource(\n getWebpackAssetScript(port) + '\\n' + originalSource,\n )\n },\n )\n }\n }\n })\n}\n","import type { UnpluginOptions } from '@inspecto-dev/types'\nimport { startServer, serverState } from '../../server/index.js'\nimport { resolveClientModule } from '../../injectors/utils.js'\nimport { getWebpackHtmlScript } from '../../injectors/webpack.js'\nimport path from 'node:path'\n\n// Get current directory securely in both ESM and CJS via tsup shims\nconst _dirname = typeof __dirname !== 'undefined' ? __dirname : __dirname\n\nconst DEFAULT_OPTIONS: Required<UnpluginOptions> = {\n include: [],\n exclude: [],\n escapeTags: [],\n pathType: 'absolute',\n attributeName: 'data-inspecto',\n logLevel: 'warn',\n}\n\nlet serverPort: number | null = null\n\nconst ensureServer = async () => {\n if (serverPort === null) {\n serverPort = await startServer()\n }\n return serverPort\n}\n\nexport class InspectoRspackLegacyPlugin {\n options: Required<UnpluginOptions>\n\n constructor(options: UnpluginOptions = {}) {\n this.options = { ...DEFAULT_OPTIONS, ...options }\n }\n\n apply(compiler: any) {\n if (process.env['NODE_ENV'] === 'production') return\n\n // Ensure server starts\n compiler.hooks.beforeCompile.tapPromise('inspecto-overlay', async () => {\n await ensureServer().catch(console.error)\n })\n\n // 1. Inject client module\n const clientPath = resolveClientModule()\n new compiler.webpack.EntryPlugin(compiler.context, clientPath, {}).apply(compiler)\n\n // 2. Inject HTML\n compiler.hooks.compilation.tap('inspecto-overlay', (compilation: any) => {\n // First try HtmlRspackPlugin (modern)\n const HtmlRspackPlugin = compiler.options.plugins.find(\n (p: any) => p && p.constructor && p.constructor.name === 'HtmlRspackPlugin',\n )\n\n if (HtmlRspackPlugin && HtmlRspackPlugin.constructor.getHooks) {\n const hooks = HtmlRspackPlugin.constructor.getHooks(compilation)\n hooks.alterAssetTagGroups.tapPromise('inspecto-overlay', async (data: any) => {\n const port = await ensureServer()\n\n data.headTags.unshift({\n tagName: 'script',\n voidTag: false,\n meta: { plugin: 'inspecto-overlay' },\n innerHTML: getWebpackHtmlScript(port),\n })\n return data\n })\n } else {\n // Fallback for Rspack 0.3.x with builtins.html\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'inspecto-overlay',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,\n },\n async (assets: any) => {\n const port = await ensureServer()\n const scriptTag = `<script>${getWebpackHtmlScript(port)}</script>`\n\n for (const filename of Object.keys(assets)) {\n if (filename.endsWith('.html')) {\n const source = assets[filename].source()\n if (typeof source === 'string') {\n const newSource = source.replace('</head>', `${scriptTag}</head>`)\n assets[filename] = new compiler.webpack.sources.RawSource(newSource)\n } else if (Buffer.isBuffer(source)) {\n const sourceStr = source.toString('utf-8')\n const newSource = sourceStr.replace('</head>', `${scriptTag}</head>`)\n assets[filename] = new compiler.webpack.sources.RawSource(newSource)\n }\n }\n }\n },\n )\n }\n })\n\n // 3. Inject AST Transform Loader\n const loaderPath = path.resolve(_dirname, './loader.cjs')\n compiler.options.module.rules.push({\n test: /\\.[jt]sx?$/,\n use: [\n {\n loader: loaderPath,\n options: this.options,\n },\n ],\n })\n }\n}\n\nexport const rspackPlugin = (options?: UnpluginOptions) => new InspectoRspackLegacyPlugin(options)\nexport default rspackPlugin\n"],"mappings":";;;;;;;;AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,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D,aAAS,QAAQ,OAAO,MAAM,KAAK;AAAA,MACjC,MAAM;AAAA,MACN,KAAK;AAAA,QACH;AAAA,UACE,QAAQ;AAAA,UACR,SAAS,KAAK;AAAA,QAChB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,IAAM,eAAe,CAAC,YAA8B,IAAI,2BAA2B,OAAO;AACjG,IAAO,iBAAQ;","names":["fs","path","os","crypto","path","fs","path","path","fs","path","fs","serverState","execFileSync","launchIDE","serverLogger","serverState","execFileSync","launchIDE","fs","path","serverLogger","fs","path","serverLogger","resolve","path","os","fs","crypto","resolve","path","serverLogger","serverPort","path"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.10_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js","../../../src/server/index.ts","../../../src/server/snippet.ts","../../../src/config.ts","../../../src/utils/logger.ts","../../../src/server/dispatch-transport.ts","../../../src/server/dispatch-runtime.ts","../../../src/server/path-guards.ts","../../../src/server/annotation-dispatch.ts","../../../src/server/client-config.ts","../../../src/server/open-file.ts","../../../src/server/project-root.ts","../../../src/injectors/utils.ts","../../../src/injectors/webpack.ts","../../../src/legacy/rspack/index.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import http from 'node:http'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport os from 'node:os'\nimport crypto from 'node:crypto'\nimport portfinder from 'portfinder'\nimport type {\n ServerState,\n OpenFileRequest,\n SendToAiRequest,\n SendToAiResponse,\n SendAnnotationsToAiRequest,\n SendAnnotationsToAiResponse,\n} from '@inspecto-dev/types'\nimport { INSPECTO_API_PATHS } from '@inspecto-dev/types'\nimport { extractSnippet } from './snippet.js'\nimport { dispatchAnnotationsToAi } from './annotation-dispatch.js'\nimport { readTicket } from './dispatch-transport.js'\nimport { dispatchPromptThroughIde, resolvePromptDispatchRuntime } from './dispatch-runtime.js'\nimport { assertPathWithinProject, resolveWorkspacePath } from './path-guards.js'\nimport { buildClientConfig } from './client-config.js'\nimport { handleOpenFileRequest } from './open-file.js'\nimport { resolveProjectRoot } from './project-root.js'\nimport { watchConfig, unwatchConfig, getGlobalLogLevel } from '../config.js'\nimport { createLogger } from '../utils/logger.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nexport const serverState: ServerState = {\n port: null,\n running: false,\n projectRoot: '',\n configRoot: '',\n cwd: process.cwd(),\n}\n\nlet serverInstance: http.Server | null = null\n\nexport async function startServer(): Promise<number> {\n if (serverState.running && serverState.port !== null) {\n return serverState.port\n }\n\n // Resolve project root at server start time so process.cwd() reflects the\n // actual project directory, not the module load-time cwd.\n serverState.projectRoot = resolveProjectRoot()\n serverState.configRoot = serverState.projectRoot\n serverState.cwd = process.cwd()\n\n portfinder.basePort = 5678\n const port = await portfinder.getPortPromise()\n\n // Watch for user config changes to trigger hot-reloads internally if needed\n watchConfig(\n () => {\n serverLogger.info('user config reloaded.')\n },\n serverState.cwd,\n serverState.configRoot,\n )\n\n serverInstance = http.createServer((req, res) => {\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type')\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204)\n res.end()\n return\n }\n\n const url = new URL(req.url ?? '/', `http://localhost:${port}`)\n handleRequest(url, req, res).catch(err => {\n serverLogger.error('server error:', err)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(err) }))\n })\n })\n\n await new Promise<void>((resolve, reject) => {\n serverInstance!.listen(port, '127.0.0.1', () => {\n serverInstance!.unref() // Allow process to exit\n resolve()\n })\n serverInstance!.once('error', reject)\n })\n\n // Add persistent error handler after successful startup\n serverInstance!.on('error', err => {\n serverLogger.error('persistent server error:', err)\n })\n\n serverState.port = port\n serverState.running = true\n\n // Write port file so the IDE extension can discover the server without scanning ports\n const portFile = path.join(os.tmpdir(), 'inspecto.port.json')\n try {\n let portData: Record<string, number> = {}\n if (fs.existsSync(portFile)) {\n try {\n portData = JSON.parse(fs.readFileSync(portFile, 'utf-8'))\n } catch (_e) {\n // Invalid JSON, start fresh\n }\n }\n // Hash the project root to avoid invalid keys or paths in JSON\n const rootHash = crypto.createHash('md5').update(serverState.projectRoot).digest('hex')\n portData[rootHash] = port\n fs.writeFileSync(portFile, JSON.stringify(portData, null, 2), 'utf-8')\n } catch (_e) {\n serverLogger.warn('Failed to write port file:', _e)\n /* non-fatal — extension will fall back to scanning */\n }\n // Clean up on process exit (Vite terminates the process, not stopServer)\n process.once('exit', () => {\n try {\n if (fs.existsSync(portFile)) {\n const portData = JSON.parse(fs.readFileSync(portFile, 'utf-8'))\n const rootHash = crypto.createHash('md5').update(serverState.projectRoot).digest('hex')\n delete portData[rootHash]\n if (Object.keys(portData).length === 0) {\n fs.unlinkSync(portFile)\n } else {\n fs.writeFileSync(portFile, JSON.stringify(portData, null, 2), 'utf-8')\n }\n }\n } catch {\n /* ignore */\n }\n })\n\n serverLogger.info(`server running at http://127.0.0.1:${port}`)\n\n return port\n}\n\nexport function stopServer(): void {\n if (serverInstance) {\n serverInstance.close()\n serverInstance = null\n }\n unwatchConfig()\n serverState.running = false\n serverState.port = null\n try {\n fs.unlinkSync(path.join(os.tmpdir(), 'inspecto.port'))\n } catch {\n /* ignore */\n }\n}\n\nasync function readBody(req: http.IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = []\n req.on('data', (chunk: Buffer) => chunks.push(chunk))\n req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))\n req.on('error', reject)\n })\n}\n\nexport async function handleRequest(\n url: URL,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n): Promise<void> {\n const pathname = url.pathname\n\n // Health check - root or /inspecto/api/v1/health\n if ((pathname === '/health' || pathname === INSPECTO_API_PATHS.HEALTH) && req.method === 'GET') {\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ ok: true, port: serverState.port }))\n return\n }\n\n // Browser Client requests\n if (pathname === INSPECTO_API_PATHS.CLIENT_CONFIG && req.method === 'GET') {\n const config = await buildClientConfig(serverState)\n\n // Omit providers from the response sent to the client\n delete config.providers\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(config))\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.IDE_INFO && req.method === 'POST') {\n try {\n const body = JSON.parse(await readBody(req))\n\n // Workspace matching defense mechanism against multiple IDE connections\n const ideWorkspace = body.workspaceRoot || ''\n const serverProjectRoot = serverState.projectRoot || ''\n\n const normalizedIdeRoot = ideWorkspace ? path.resolve(ideWorkspace) : ''\n const normalizedServerRoot = serverProjectRoot ? path.resolve(serverProjectRoot) : ''\n\n const isSameProject =\n !normalizedIdeRoot ||\n !normalizedServerRoot ||\n normalizedIdeRoot === normalizedServerRoot ||\n normalizedServerRoot.startsWith(normalizedIdeRoot + path.sep) ||\n normalizedIdeRoot.startsWith(normalizedServerRoot + path.sep)\n\n if (isSameProject) {\n serverState.ideInfo = body\n serverLogger.debug(\n `Accepted IDE info from matched workspace (ide-${body.ide} / schema-${body.scheme})`,\n )\n } else {\n serverLogger.debug(\n `Ignored IDE info from unrelated workspace (IDE Workspace: ${ideWorkspace}, Server: ${serverProjectRoot}, Scheme: ${body.scheme}, IDE: ${body.ide})`,\n )\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: true }))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.IDE_INFO} POST request:`, e)\n res.writeHead(400, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Invalid JSON body' }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.IDE_OPEN && req.method === 'POST') {\n let body: OpenFileRequest\n try {\n body = JSON.parse(await readBody(req)) as OpenFileRequest\n } catch (_e) {\n res.writeHead(400, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Invalid JSON body' }))\n return\n }\n\n try {\n handleOpenFileRequest(body, serverState)\n } catch (err: any) {\n serverLogger.warn(\n `Security: Blocked path traversal attempt in IDE_OPEN: ${body.file}. Reason: ${err.message}`,\n )\n res.writeHead(403, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'Access denied: File is outside of project workspace' }))\n return\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: true }))\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.PROJECT_SNIPPET && req.method === 'GET') {\n const file = url.searchParams.get('file') ?? ''\n const line = parseInt(url.searchParams.get('line') ?? '1', 10)\n const column = parseInt(url.searchParams.get('column') ?? '1', 10)\n const maxLines = parseInt(url.searchParams.get('maxLines') ?? '100', 10)\n\n try {\n const absolutePath = resolveWorkspacePath(file, serverState.cwd)\n\n // Security: Prevent path traversal attacks\n try {\n assertPathWithinProject(absolutePath, serverState.projectRoot)\n } catch (err: any) {\n serverLogger.warn(\n `Security: Blocked path traversal attempt in PROJECT_SNIPPET: ${file}. Reason: ${err.message}`,\n )\n res.writeHead(403, { 'Content-Type': 'application/json' })\n res.end(\n JSON.stringify({\n success: false,\n error: 'Access denied: File is outside of project workspace',\n errorCode: 'FORBIDDEN',\n }),\n )\n return\n }\n\n const result = await extractSnippet({ file: absolutePath, line, column, maxLines })\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n } catch (err: any) {\n const message = String(err.message || err)\n const errorCode = message.startsWith('FILE_NOT_FOUND') ? 'FILE_NOT_FOUND' : 'UNKNOWN'\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: message, errorCode }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.AI_DISPATCH && req.method === 'POST') {\n try {\n const rawBody = await readBody(req)\n const body = JSON.parse(rawBody) as SendToAiRequest\n const result = await dispatchToAi(body)\n res.writeHead(result.success ? 200 : 500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.AI_DISPATCH} request:`, e)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(e), errorCode: 'INTERNAL_ERROR' }))\n }\n return\n }\n\n if (pathname === INSPECTO_API_PATHS.AI_BATCH_DISPATCH && req.method === 'POST') {\n try {\n const rawBody = await readBody(req)\n const body = JSON.parse(rawBody) as SendAnnotationsToAiRequest\n const result = await dispatchAnnotationsToAi(body, serverState)\n res.writeHead(getBatchDispatchStatusCode(result.errorCode, result.success), {\n 'Content-Type': 'application/json',\n })\n res.end(JSON.stringify(result))\n } catch (e) {\n serverLogger.error(`Error parsing ${INSPECTO_API_PATHS.AI_BATCH_DISPATCH} request:`, e)\n res.writeHead(500, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: String(e), errorCode: 'INTERNAL_ERROR' }))\n }\n return\n }\n\n // Handle IDE payload ticket retrieval\n if (pathname.startsWith(`${INSPECTO_API_PATHS.AI_TICKET}/`) && req.method === 'GET') {\n const ticketId = pathname.substring(INSPECTO_API_PATHS.AI_TICKET.length + 1)\n const payloadStr = readTicket(ticketId)\n\n if (!payloadStr) {\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ success: false, error: 'Ticket not found or expired' }))\n return\n }\n\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(payloadStr)\n return\n }\n\n res.writeHead(404, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify({ error: 'not found' }))\n}\n\nasync function dispatchToAi(\n req: SendToAiRequest,\n): Promise<SendToAiResponse & { fallbackPayload?: { prompt: string; file: string } }> {\n const { location, snippet, prompt, screenshotContext } = req\n\n const formattedPrompt =\n prompt ??\n `Please help me with this code from \\`${location.file}\\` (line ${location.line}):\\n\\n\\`\\`\\`\\n${snippet}\\n\\`\\`\\`\\n`\n const runtime = resolvePromptDispatchRuntime(serverState)\n return dispatchPromptThroughIde(runtime, {\n prompt: formattedPrompt,\n filePath: location.file,\n line: location.line,\n column: location.column,\n snippet,\n ...(screenshotContext ? { screenshotContext } : {}),\n }) as SendToAiResponse & { fallbackPayload?: { prompt: string; file: string } }\n}\n\nfunction getBatchDispatchStatusCode(\n errorCode: SendAnnotationsToAiResponse['errorCode'],\n success: boolean,\n): number {\n if (success) return 200\n if (errorCode === 'INVALID_REQUEST') return 400\n if (errorCode === 'FORBIDDEN_PATH') return 403\n return 500\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport * as parser from '@babel/parser'\nimport traverse_ from '@babel/traverse'\n// Support both ESM default and CommonJS module.exports\nconst traverse =\n typeof traverse_ === 'function' ? traverse_ : (traverse_ as any).default || traverse_\nimport type { NodePath } from '@babel/traverse'\nimport type { Node } from '@babel/types'\nimport type { SnippetRequest, SnippetResponse } from '@inspecto-dev/types'\n\ninterface CacheEntry {\n mtime: number\n /** The full parsed source lines */\n lines: string[]\n}\n\n/** In-memory cache keyed by absolute file path */\nconst snippetCache = new Map<string, CacheEntry>()\n\nconst DEFAULT_MAX_LINES = 100\nconst DEFAULT_CONTEXT_LINES_BEFORE = 5\n\nexport async function extractSnippet(req: SnippetRequest): Promise<SnippetResponse> {\n const { file, line, column, maxLines = DEFAULT_MAX_LINES } = req\n\n const absolutePath = path.resolve(file)\n\n let stat: fs.Stats\n try {\n stat = await fs.promises.stat(absolutePath)\n } catch {\n throw new Error(`FILE_NOT_FOUND: ${absolutePath}`)\n }\n\n const mtime = stat.mtimeMs\n\n let lines: string[]\n const cached = snippetCache.get(absolutePath)\n if (cached && cached.mtime === mtime) {\n lines = cached.lines\n } else {\n const source = await fs.promises.readFile(absolutePath, 'utf-8')\n lines = source.split('\\n')\n snippetCache.set(absolutePath, { mtime, lines })\n }\n\n let snippetLines: string[]\n let startLine: number\n let componentName: string | undefined\n\n try {\n const result = extractComponentBoundary(lines.join('\\n'), line, column, maxLines)\n snippetLines = result.lines\n startLine = result.startLine\n componentName = result.name\n } catch {\n const before = Math.max(0, line - 1 - DEFAULT_CONTEXT_LINES_BEFORE)\n const after = Math.min(lines.length, before + maxLines)\n snippetLines = lines.slice(before, after)\n startLine = before + 1\n }\n\n if (snippetLines.length > maxLines) {\n snippetLines = snippetLines.slice(0, maxLines)\n }\n\n return {\n snippet: snippetLines.join('\\n'),\n startLine,\n file: absolutePath,\n ...(componentName ? { name: componentName } : {}),\n }\n}\n\ninterface BoundaryResult {\n lines: string[]\n startLine: number\n name?: string\n}\n\nfunction extractComponentBoundary(\n source: string,\n targetLine: number,\n _targetColumn: number,\n maxLines: number,\n): BoundaryResult {\n const ast = parser.parse(source, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript', 'decorators-legacy', 'classProperties'],\n errorRecovery: true,\n })\n\n const allLines = source.split('\\n')\n\n let bestStart = 0\n let bestEnd = allLines.length - 1\n let bestName: string | undefined\n\n traverse(ast, {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ClassMethod'(\n nodePath: NodePath<Node>,\n ) {\n const node = nodePath.node\n if (!node.loc) return\n\n const nodeStart = node.loc.start.line\n const nodeEnd = node.loc.end.line\n\n if (targetLine < nodeStart || targetLine > nodeEnd) return\n\n if (nodeEnd - nodeStart < bestEnd - bestStart) {\n bestStart = nodeStart - 1\n bestEnd = nodeEnd - 1\n bestName = extractFunctionName(nodePath)\n }\n },\n })\n\n let sliceStart = bestStart\n let sliceEnd = bestEnd + 1\n\n if (sliceEnd - sliceStart > maxLines) {\n const targetIdx = targetLine - 1\n sliceStart = Math.max(bestStart, targetIdx - Math.floor(maxLines / 3))\n sliceEnd = sliceStart + maxLines\n if (sliceEnd > bestEnd + 1) {\n sliceEnd = bestEnd + 1\n sliceStart = Math.max(0, sliceEnd - maxLines)\n }\n }\n\n return {\n lines: allLines.slice(sliceStart, sliceEnd),\n startLine: sliceStart + 1,\n ...(bestName ? { name: bestName } : {}),\n }\n}\n\nfunction extractFunctionName(nodePath: NodePath<Node>): string | undefined {\n const node = nodePath.node\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n return node.id.name\n }\n\n const parent = nodePath.parent\n if (\n (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&\n parent.type === 'VariableDeclarator' &&\n parent.id.type === 'Identifier'\n ) {\n return parent.id.name\n }\n\n if (node.type === 'ClassMethod' && node.key.type === 'Identifier') {\n return node.key.name\n }\n\n return undefined\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport os from 'node:os'\nimport { createDefu } from 'defu'\nimport type {\n InspectoSettings,\n InspectoPromptsConfig,\n Provider,\n ProviderMode,\n ToolOverrides,\n IdeType,\n LogLevel,\n} from '@inspecto-dev/types'\nimport {\n DEFAULT_PROVIDER_MODE,\n VALID_MODES,\n DEFAULT_INTENTS,\n IntentConfig,\n} from '@inspecto-dev/types'\nimport { createLogger, setLoggerGlobalLevel } from './utils/logger.js'\n\nconst configLogger = createLogger('inspecto:config')\n\nlet loadedConfig: InspectoSettings | null = null\nlet loadedPrompts: InspectoPromptsConfig | null = null\nlet globalLogLevel: LogLevel = 'warn'\nlet isWatching = false\n\n// Custom array merge behavior for defu: overwrite arrays instead of concatenating them\nconst arrayReplaceMerge = createDefu((obj, key, val) => {\n if (Array.isArray(val)) {\n obj[key] = val\n return true\n }\n})\n\nexport function setGlobalLogLevel(level?: LogLevel) {\n if (level) {\n globalLogLevel = level\n setLoggerGlobalLevel(level)\n }\n}\n\nexport function getGlobalLogLevel() {\n return globalLogLevel\n}\n\n/**\n * Walk from cwd up to gitRoot (inclusive), collecting directories that contain\n * a .inspecto/ subdirectory. Returns them ordered highest-priority first\n * (closest to cwd first).\n *\n * If cwd is not under gitRoot, only cwd itself is checked.\n */\nexport function resolveConfigRoots(cwd: string, gitRoot: string): string[] {\n const roots: string[] = []\n let current = cwd\n\n // Ensure we don't walk past gitRoot (handles cwd above gitRoot case)\n const isUnderOrEqual = current === gitRoot || current.startsWith(gitRoot + path.sep)\n if (!isUnderOrEqual) {\n // cwd is not under gitRoot — only check cwd\n if (fs.existsSync(path.join(cwd, '.inspecto'))) roots.push(cwd)\n return roots\n }\n\n while (true) {\n if (fs.existsSync(path.join(current, '.inspecto'))) {\n roots.push(current)\n }\n if (current === gitRoot) break\n const parent = path.dirname(current)\n if (parent === current) break // filesystem root guard\n current = parent\n }\n\n return roots\n}\n\n/**\n * Load and merge user config from all discovered .inspecto/ layers:\n *\n * Priority (highest → lowest):\n * <cwd>/.inspecto/settings.local.json\n * <cwd>/.inspecto/settings.json\n * ...intermediate dirs...\n * <gitRoot>/.inspecto/settings.local.json\n * <gitRoot>/.inspecto/settings.json\n * ~/.inspecto/settings.json\n *\n * @param force Bust cache and re-read from disk\n * @param cwd Working directory to start resolution from (default: process.cwd())\n * @param gitRoot Git repository root — upward traversal stops here (optional)\n */\nexport function loadUserConfigSync(\n force = false,\n cwd = process.cwd(),\n gitRoot?: string,\n): InspectoSettings {\n if (loadedConfig && !force) return loadedConfig\n loadedConfig = null // force clear\n\n const layers: Partial<InspectoSettings>[] = []\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n\n for (const root of roots) {\n layers.push(readJsonSafely(path.join(root, '.inspecto', 'settings.local.json')))\n layers.push(readJsonSafely(path.join(root, '.inspecto', 'settings.json')))\n }\n\n layers.push(readJsonSafely(path.join(os.homedir(), '.inspecto', 'settings.json')))\n layers.push({})\n\n const validLayers = layers.filter(l => l !== null)\n loadedConfig = arrayReplaceMerge(...(validLayers as [object, ...object[]])) as InspectoSettings\n return loadedConfig\n}\n\n/**\n * Load and merge prompts config from all discovered .inspecto/ layers:\n *\n * Priority (highest → lowest):\n * <cwd>/.inspecto/prompts.local.json\n * <cwd>/.inspecto/prompts.json\n * ...intermediate dirs...\n * <gitRoot>/.inspecto/prompts.local.json\n * <gitRoot>/.inspecto/prompts.json\n * ~/.inspecto/prompts.json\n *\n * Arrays in custom configurations are replaced instead of merged.\n */\nexport async function loadPromptsConfig(\n force = false,\n cwd = process.cwd(),\n gitRoot?: string,\n): Promise<InspectoPromptsConfig> {\n if (loadedPrompts && !force) return loadedPrompts\n\n const layers: any[] = []\n\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n for (const root of roots) {\n const localPath = path.join(root, '.inspecto', 'prompts.local.json')\n const jsonPath = path.join(root, '.inspecto', 'prompts.json')\n layers.push(readJsonSafely(localPath))\n layers.push(readJsonSafely(jsonPath))\n }\n\n layers.push(readJsonSafely(path.join(os.homedir(), '.inspecto', 'prompts.json')))\n\n // Find the first layer that contains a valid prompts config (array or $replace object).\n // Highest-priority layer wins — no merging across layers for prompts.\n let finalPrompts: any = []\n for (const layer of layers) {\n if (Array.isArray(layer) && layer.length > 0) {\n finalPrompts = layer\n break\n }\n if (\n layer &&\n typeof layer === 'object' &&\n layer.$replace === true &&\n Array.isArray(layer.items)\n ) {\n finalPrompts = layer\n break\n }\n }\n\n loadedPrompts = finalPrompts as InspectoPromptsConfig\n return loadedPrompts\n}\n\nfunction readJsonSafely(filePath: string): any {\n try {\n if (fs.existsSync(filePath)) {\n const content = fs.readFileSync(filePath, 'utf-8').trim()\n if (!content) return null // Return null instead of [] so we know it's empty\n const parsed = JSON.parse(content)\n // Transition helper: if user still has {\"prompts\": [...]}, extract it\n if (!Array.isArray(parsed) && parsed.prompts && Array.isArray(parsed.prompts)) {\n return parsed.prompts\n }\n return parsed\n }\n } catch (e) {\n // Ignore JSON parsing errors for empty or malformed files during watch\n if (e instanceof SyntaxError) {\n configLogger.warn(`Failed to parse config at ${filePath}: Invalid JSON`)\n } else {\n configLogger.warn(`Failed to read config at ${filePath}:`, e)\n }\n }\n return null\n}\n\n/**\n * Resolve the exact target tool to dispatch to based on user config.\n */\nexport function resolveTargetTool(config: InspectoSettings, _ide: IdeType = 'vscode'): Provider {\n // Support \"provider.default\" (e.g., \"claude-code.extension\")\n const defaultProvider = config['provider.default'] as string | undefined\n if (defaultProvider) {\n const tool = defaultProvider.split('.')[0]\n return tool as Provider\n }\n\n // Fallback\n return 'copilot'\n}\n\n/**\n * Resolve the effective mode/type for a tool in the context of an IDE.\n */\nexport function resolveProviderMode(\n tool: Provider,\n ide: IdeType,\n config: InspectoSettings,\n): ProviderMode {\n let requestedType: ProviderMode | undefined = undefined\n\n // V2 format: check provider.default for \"tool.mode\"\n const defaultProvider = config['provider.default'] as string | undefined\n if (defaultProvider && defaultProvider.startsWith(`${tool}.`)) {\n const mode = defaultProvider.split('.')[1]\n if (mode === 'extension') requestedType = 'extension'\n if (mode === 'cli') requestedType = 'cli'\n }\n\n requestedType = requestedType ?? DEFAULT_PROVIDER_MODE[tool]\n const valid = VALID_MODES[tool] || [DEFAULT_PROVIDER_MODE[tool]]\n return requestedType && valid.includes(requestedType) ? requestedType : valid[0]!\n}\n\n/**\n * Extract ToolOverrides (binaryPath, args, etc) for Extension consumption.\n */\nexport function extractToolOverrides(\n ide: IdeType,\n config: InspectoSettings,\n): Partial<Record<Provider, ToolOverrides>> {\n const result: Partial<Record<Provider, ToolOverrides>> = {}\n\n if (!config) return result\n\n // Parse new flat `provider.*` format\n for (const [key, value] of Object.entries(config)) {\n if (!key.startsWith('provider.')) continue\n\n // We only process tool specific overrides, ignore `.default`\n if (key === 'provider.default') continue\n\n // Handle `provider.[tool].[mode]`\n const toolIndex = 1\n const modeIndex = 2\n const propIndex = 3\n\n const parts = key.split('.')\n\n if (parts.length >= propIndex + 1) {\n const tool = parts[toolIndex] as Provider\n const mode = parts[modeIndex] as ProviderMode\n const prop = parts[propIndex]\n\n if (!result[tool]) {\n result[tool] = { type: mode }\n }\n\n const overrides = result[tool]!\n\n // If we see config for a mode that differs from what we've initialized,\n // it means both modes have config. In v2, mode is determined by provider.default.\n // We will just accumulate the settings for now and let resolveProviderMode decide the active type.\n\n if (prop === 'bin') overrides.binaryPath = value as string\n if (prop === 'args') overrides.args = value as string[]\n if (prop === 'cwd') overrides.cwd = value as string\n if (prop === 'coldStartDelay') overrides.coldStartDelay = value as number\n }\n }\n\n return result\n}\n\nexport function resolveIntents(serverPrompts?: InspectoPromptsConfig): IntentConfig[] {\n // Start with DEFAULT_INTENTS as base\n const baseMap = new Map<string, IntentConfig>()\n for (const intent of DEFAULT_INTENTS) {\n baseMap.set(intent.id, { ...intent } as IntentConfig)\n }\n\n const defaults = () => Array.from(baseMap.values())\n\n if (!serverPrompts) return defaults()\n\n const isReplace =\n !Array.isArray(serverPrompts) &&\n typeof serverPrompts === 'object' &&\n serverPrompts.$replace === true\n const promptsArray = Array.isArray(serverPrompts)\n ? serverPrompts\n : isReplace\n ? serverPrompts.items\n : []\n\n if (!promptsArray || promptsArray.length === 0) return defaults()\n\n if (isReplace) {\n // $replace: true — exact list, user controls everything\n const result: IntentConfig[] = []\n for (const item of promptsArray) {\n if (typeof item === 'string') {\n if (baseMap.has(item)) {\n result.push(baseMap.get(item)!)\n } else {\n configLogger.warn(\n `Unknown built-in intent id: \"${item}\". Available: ${[...baseMap.keys()].join(', ')}`,\n )\n }\n } else if (typeof item === 'object') {\n if (!item.id) {\n configLogger.warn('Intent object missing required \"id\" field, skipping.')\n continue\n }\n if (item.enabled === false) {\n configLogger.warn(\n `Intent \"${item.id}\" is listed in $replace but has enabled:false — it will be excluded.`,\n )\n continue\n }\n if (!item.aiIntent) {\n configLogger.warn(`Intent \"${item.id}\" is missing required \"aiIntent\".`)\n continue\n }\n result.push(\n (baseMap.has(item.id) ? { ...baseMap.get(item.id)!, ...item } : item) as IntentConfig,\n )\n }\n }\n return result\n }\n\n // Default: append / override mode.\n // - Objects with known id: merge over built-in (or remove if enabled:false)\n // - Objects with unknown id: append as new intent\n // - Strings: not meaningful in append mode (order is fixed to built-in order + appended)\n const merged = Array.from(baseMap.values())\n\n for (const item of promptsArray) {\n if (typeof item === 'string') {\n if (!baseMap.has(item)) {\n configLogger.warn(\n `Unknown built-in intent id: \"${item}\". In append mode, strings have no effect on ordering — use $replace to control order.`,\n )\n }\n // Known string ids are already in merged — nothing to do\n continue\n }\n\n if (typeof item === 'object') {\n if (!item.id) {\n configLogger.warn('Intent object missing required \"id\" field, skipping.')\n continue\n }\n if (!item.aiIntent) {\n configLogger.warn(`Intent \"${item.id}\" is missing required \"aiIntent\".`)\n continue\n }\n const existingIdx = merged.findIndex(i => i.id === item.id)\n if (existingIdx !== -1) {\n if (item.enabled === false) {\n merged.splice(existingIdx, 1)\n } else {\n merged[existingIdx] = { ...merged[existingIdx], ...item } as IntentConfig\n }\n } else {\n if (item.enabled !== false) {\n merged.push(item as IntentConfig)\n }\n }\n }\n }\n\n return merged\n}\n\nlet watchers: fs.FSWatcher[] = []\n\nexport function watchConfig(onReload: () => void, cwd = process.cwd(), gitRoot?: string): void {\n if (isWatching) return\n isWatching = true\n\n // Watch .inspecto/ directories rather than individual files so that newly\n // created files (e.g. prompts.local.json added after server start) are picked up.\n const watchDirs: string[] = [path.join(os.homedir(), '.inspecto')]\n const roots = resolveConfigRoots(cwd, gitRoot ?? cwd)\n for (const root of roots) {\n watchDirs.push(path.join(root, '.inspecto'))\n }\n\n const CONFIG_FILES = new Set([\n 'settings.json',\n 'settings.local.json',\n 'prompts.json',\n 'prompts.local.json',\n ])\n\n for (const dir of watchDirs) {\n if (!fs.existsSync(dir)) continue\n try {\n const watcher = fs.watch(dir, async (eventType, filename) => {\n if (!filename || !CONFIG_FILES.has(filename)) return\n loadedConfig = null\n loadedPrompts = null\n loadUserConfigSync(true, cwd, gitRoot)\n await loadPromptsConfig(true, cwd, gitRoot)\n onReload()\n })\n watcher.unref()\n watchers.push(watcher)\n } catch (_e) {\n // ignore watch errors (e.g. unsupported fs)\n }\n }\n}\n\nexport function unwatchConfig(): void {\n for (const watcher of watchers) {\n watcher.close()\n }\n watchers = []\n isWatching = false\n}\n","import type { LogLevel } from '@inspecto-dev/types'\n\nexport interface Logger {\n info(msg: string, ...args: any[]): void\n warn(msg: string, ...args: any[]): void\n error(msg: string, ...args: any[]): void\n debug(msg: string, ...args: any[]): void\n setLevel?(level: LogLevel): void\n}\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n}\n\n// Very simple implementation of a DEBUG matching string.\n// Supports `DEBUG=inspecto:*` or `DEBUG=inspecto:server,inspecto:ast`\nfunction isDebugEnabled(namespace: string): boolean {\n if (typeof process === 'undefined' || !process.env) return false\n const debugEnv = process.env.DEBUG\n if (!debugEnv) return false\n\n const namespaces = debugEnv.split(',').map(s => s.trim())\n for (const ns of namespaces) {\n if (ns === '*') return true\n if (ns.endsWith('*')) {\n const prefix = ns.slice(0, -1)\n if (namespace.startsWith(prefix)) return true\n } else if (ns === namespace) {\n return true\n }\n }\n return false\n}\n\n// Store global level locally to avoid circular dependency with config.ts\nlet globalLevel: LogLevel = 'warn'\nconst registeredLoggers: Set<Logger> = new Set()\n\nexport function setLoggerGlobalLevel(level: LogLevel) {\n globalLevel = level\n for (const logger of registeredLoggers) {\n if (logger.setLevel) {\n logger.setLevel(level)\n }\n }\n}\n\nexport function createLogger(namespace: string, options?: { logLevel?: LogLevel }): Logger {\n let currentLevel = options?.logLevel ?? globalLevel\n let numericLevel = LOG_LEVELS[currentLevel] ?? 2\n const debugEnabled = isDebugEnabled(namespace)\n\n const logger: Logger = {\n setLevel(level: LogLevel) {\n currentLevel = level\n numericLevel = LOG_LEVELS[level] ?? 2\n },\n info(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.info) {\n console.log(`\\x1b[36m[inspecto]\\x1b[0m ${msg}`, ...args)\n }\n },\n warn(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.warn) {\n console.warn(`\\x1b[33m[inspecto] WARN:\\x1b[0m ${msg}`, ...args)\n }\n },\n error(msg: string, ...args: any[]) {\n if (numericLevel >= LOG_LEVELS.error) {\n console.error(`\\x1b[31m[inspecto] ERROR:\\x1b[0m ${msg}`, ...args)\n }\n },\n debug(msg: string, ...args: any[]) {\n if (debugEnabled) {\n console.log(`\\x1b[90m[${namespace}]\\x1b[0m ${msg}`, ...args)\n }\n },\n }\n\n registeredLoggers.add(logger)\n\n return logger\n}\n","import crypto from 'node:crypto'\nimport { execFileSync } from 'node:child_process'\nimport { launchIDE } from 'launch-ide'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nconst payloadTickets = new Map<string, string>()\n\nexport function createTicket(payload: unknown): string {\n const ticketId = crypto.randomUUID()\n payloadTickets.set(ticketId, JSON.stringify(payload))\n\n setTimeout(\n () => {\n payloadTickets.delete(ticketId)\n },\n 5 * 60 * 1000,\n )\n\n return ticketId\n}\n\nexport function readTicket(ticketId: string): string | undefined {\n return payloadTickets.get(ticketId)\n}\n\nexport function launchURI(uri: string): void {\n try {\n if (process.platform === 'darwin') {\n execFileSync('open', [uri])\n } else if (process.platform === 'win32') {\n execFileSync('cmd', ['/c', 'start', '\"\"', uri])\n } else {\n execFileSync('xdg-open', [uri])\n }\n } catch (e) {\n serverLogger.error('Failed to launch URI via execFileSync, falling back to launchIDE:', e)\n launchIDE({ file: uri })\n }\n}\n","import type {\n IdeType,\n Provider,\n ProviderMode,\n ScreenshotContext,\n ServerState,\n ToolOverrides,\n} from '@inspecto-dev/types'\nimport {\n extractToolOverrides,\n loadUserConfigSync,\n resolveProviderMode,\n resolveTargetTool,\n} from '../config.js'\nimport { createTicket, launchURI } from './dispatch-transport.js'\n\nexport interface PromptDispatchRuntime {\n resolvedTarget: Provider\n finalIde: string\n mode: ProviderMode\n overrides?: ToolOverrides\n autoSend?: boolean\n}\n\nexport interface PromptDispatchPayload {\n prompt: string\n filePath?: string\n line?: number\n column?: number\n snippet?: string\n screenshotContext?: ScreenshotContext\n}\n\nexport interface PromptDispatchResult {\n success: true\n fallbackPayload: {\n prompt: string\n file?: string\n }\n}\n\nfunction normalizeIdeToken(value: string | undefined): string {\n return (value ?? '').toLowerCase().replace(/[^a-z0-9]/g, '')\n}\n\nexport function resolvePromptDispatchRuntime(\n state: Pick<ServerState, 'projectRoot' | 'cwd' | 'ideInfo'>,\n): PromptDispatchRuntime {\n const userConfig = loadUserConfigSync(false, state.cwd, state.projectRoot)\n const resolvedTarget = resolveTargetTool(userConfig)\n const finalIde = resolveFinalIde(userConfig.ide, state.ideInfo?.ide, state.ideInfo?.scheme)\n const mode = resolveProviderMode(resolvedTarget, finalIde as IdeType, userConfig)\n const overrides =\n extractToolOverrides(finalIde as IdeType, userConfig)[resolvedTarget] || undefined\n\n return {\n resolvedTarget,\n finalIde,\n mode,\n ...(hasOverrides(overrides) ? { overrides } : {}),\n ...(userConfig['prompt.autoSend'] !== undefined\n ? { autoSend: Boolean(userConfig['prompt.autoSend']) }\n : {}),\n }\n}\n\nexport function dispatchPromptThroughIde(\n runtime: PromptDispatchRuntime,\n payload: PromptDispatchPayload,\n): PromptDispatchResult {\n const ticketId = createTicket({\n ide: runtime.finalIde,\n target: runtime.resolvedTarget,\n targetType: runtime.mode,\n prompt: payload.prompt,\n filePath: payload.filePath,\n line: payload.line,\n column: payload.column,\n snippet: payload.snippet,\n ...(payload.screenshotContext ? { screenshotContext: payload.screenshotContext } : {}),\n overrides: runtime.overrides,\n autoSend: runtime.autoSend,\n })\n\n const params = new URLSearchParams()\n params.set('ticket', ticketId)\n params.set('target', runtime.resolvedTarget)\n\n launchURI(`${runtime.finalIde}://inspecto.inspecto/send?${params.toString()}`)\n\n return {\n success: true,\n fallbackPayload: {\n prompt: payload.prompt,\n ...(payload.filePath ? { file: payload.filePath } : {}),\n },\n }\n}\n\nfunction resolveFinalIde(\n configuredIde: string | undefined,\n activeIde: string | undefined,\n activeIdeScheme: string | undefined,\n): string {\n const configuredIdeMatchesActiveScheme =\n Boolean(configuredIde) &&\n Boolean(activeIdeScheme) &&\n normalizeIdeToken(configuredIde) === normalizeIdeToken(activeIdeScheme)\n\n if (configuredIdeMatchesActiveScheme) {\n return activeIdeScheme!\n }\n\n if (\n configuredIde &&\n activeIdeScheme &&\n normalizeIdeToken(activeIdeScheme).includes(normalizeIdeToken(configuredIde)) === false\n ) {\n return configuredIde\n }\n\n return configuredIde || activeIdeScheme || activeIde || 'vscode'\n}\n\nfunction hasOverrides(overrides: ToolOverrides | undefined): overrides is ToolOverrides {\n return Boolean(overrides && Object.keys(overrides).length > 0)\n}\n","import path from 'node:path'\nimport fs from 'node:fs'\n\nfunction isWindowsAbsolutePath(file: string): boolean {\n return /^[a-zA-Z]:[\\\\/]/.test(file) || /^\\\\\\\\[^\\\\]+\\\\[^\\\\]+/.test(file)\n}\n\nexport function resolveWorkspacePath(file: string, cwd: string): string {\n if (isWindowsAbsolutePath(file)) {\n return path.win32.normalize(file)\n }\n return path.isAbsolute(file) ? path.resolve(file) : path.resolve(cwd, file)\n}\n\nexport function assertPathWithinProject(file: string, projectRoot: string): void {\n let realFile = file\n let realProjectRoot = projectRoot\n try {\n if (fs.existsSync(file)) {\n realFile = fs.realpathSync(file)\n }\n } catch {\n // ignore\n }\n\n try {\n if (fs.existsSync(projectRoot)) {\n realProjectRoot = fs.realpathSync(projectRoot)\n }\n } catch {\n // ignore\n }\n\n if (isWithinPath(file, projectRoot) || isWithinPath(realFile, realProjectRoot)) {\n return\n }\n\n throw new Error(\n `Access denied: File ${normalizeForComparison(realFile)} is outside of project workspace ${normalizeForComparison(realProjectRoot)}`,\n )\n}\n\nfunction tryReadPackageName(packageRoot: string): string | undefined {\n try {\n const packageJsonPath = path.join(packageRoot, 'package.json')\n if (!fs.existsSync(packageJsonPath)) return undefined\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string }\n return typeof packageJson.name === 'string' ? packageJson.name : undefined\n } catch {\n return undefined\n }\n}\n\nfunction findNearestPackageRoot(file: string): string | undefined {\n let current = path.dirname(file)\n\n while (true) {\n if (fs.existsSync(path.join(current, 'package.json'))) {\n return current\n }\n const parent = path.dirname(current)\n if (parent === current) {\n return undefined\n }\n current = parent\n }\n}\n\nfunction normalizeForComparison(file: string): string {\n return isWindowsAbsolutePath(file) ? path.win32.normalize(file) : path.normalize(file)\n}\n\nfunction pathSeparatorFor(file: string): string {\n return isWindowsAbsolutePath(file) ? path.win32.sep : path.sep\n}\n\nfunction isWithinPath(file: string, root: string): boolean {\n const normalizedFile = normalizeForComparison(file)\n const normalizedRoot = normalizeForComparison(root)\n const separator = pathSeparatorFor(normalizedRoot)\n const rootWithSep = normalizedRoot.endsWith(separator)\n ? normalizedRoot\n : normalizedRoot + separator\n return normalizedFile === normalizedRoot || normalizedFile.startsWith(rootWithSep)\n}\n\nfunction resolveLinkedDependencyEntry(\n projectRoot: string,\n packageName: string,\n): string | undefined {\n const packageSegments = packageName.split('/')\n const dependencyPath = path.join(projectRoot, 'node_modules', ...packageSegments)\n if (!fs.existsSync(dependencyPath)) return undefined\n\n try {\n return fs.realpathSync(dependencyPath)\n } catch {\n return dependencyPath\n }\n}\n\nfunction isLinkedDependencyPath(file: string, projectRoot: string, packageName: string): boolean {\n const linkedDependencyRoot = resolveLinkedDependencyEntry(projectRoot, packageName)\n if (!linkedDependencyRoot) return false\n\n return isWithinPath(file, linkedDependencyRoot)\n}\n\nfunction isLinkedDependencySourcePath(file: string, projectRoot: string): boolean {\n const packageRoot = findNearestPackageRoot(file)\n if (!packageRoot) return false\n\n const packageName = tryReadPackageName(packageRoot)\n if (!packageName) return false\n\n return isLinkedDependencyPath(file, projectRoot, packageName)\n}\n\nexport function assertPathWithinIdeOpenScope(file: string, projectRoot: string): void {\n try {\n assertPathWithinProject(file, projectRoot)\n return\n } catch {\n if (isLinkedDependencySourcePath(file, projectRoot)) {\n return\n }\n throw new Error(`Access denied: File is outside of project workspace`)\n }\n}\n","import type {\n AnnotationIntent,\n AiErrorCode,\n RuntimeContextEnvelope,\n RuntimeEvidenceRecord,\n ScreenshotContext,\n SendAnnotationsToAiRequest,\n SendAnnotationsToAiResponse,\n ServerState,\n} from '@inspecto-dev/types'\nimport { dispatchPromptThroughIde, resolvePromptDispatchRuntime } from './dispatch-runtime.js'\nimport { assertPathWithinProject, resolveWorkspacePath } from './path-guards.js'\n\nexport interface NormalizedAnnotationTarget {\n file: string\n line: number\n column: number\n label?: string\n selector?: string\n snippet?: string\n}\n\nexport interface NormalizedAnnotation {\n index: number\n note: string\n intent: AnnotationIntent\n targets: NormalizedAnnotationTarget[]\n}\n\nexport interface NormalizedAnnotationBatch {\n instruction: string\n responseMode: 'unified' | 'per-annotation'\n annotations: NormalizedAnnotation[]\n runtimeContext?: RuntimeContextEnvelope\n screenshotContext?: ScreenshotContext\n cssContextPrompt?: string\n}\n\nclass AnnotationDispatchError extends Error {\n readonly errorCode: AiErrorCode\n\n constructor(message: string, errorCode: AiErrorCode) {\n super(message)\n this.name = 'AnnotationDispatchError'\n this.errorCode = errorCode\n }\n}\n\nexport async function dispatchAnnotationsToAi(\n req: SendAnnotationsToAiRequest,\n state: Pick<ServerState, 'projectRoot' | 'cwd' | 'ideInfo'>,\n): Promise<SendAnnotationsToAiResponse> {\n try {\n validateAnnotationDispatchRequest(req, state)\n const batch = normalizeAnnotationBatch(req)\n const prompt = buildAnnotationBatchPrompt(batch)\n const representativeTarget = batch.annotations[0]?.targets[0]\n const runtime = resolvePromptDispatchRuntime(state)\n\n return dispatchPromptThroughIde(runtime, {\n prompt,\n ...(representativeTarget?.file ? { filePath: representativeTarget.file } : {}),\n ...(representativeTarget?.line ? { line: representativeTarget.line } : {}),\n ...(representativeTarget?.column ? { column: representativeTarget.column } : {}),\n ...(batch.screenshotContext ? { screenshotContext: batch.screenshotContext } : {}),\n })\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n errorCode: getAnnotationDispatchErrorCode(error),\n }\n }\n}\n\nexport function validateAnnotationDispatchRequest(\n req: SendAnnotationsToAiRequest,\n state: Pick<ServerState, 'projectRoot' | 'cwd'>,\n): void {\n if (!req.annotations.length) {\n throw new AnnotationDispatchError('At least one annotation is required.', 'INVALID_REQUEST')\n }\n\n for (const annotation of req.annotations) {\n if (!annotation.targets.length) {\n throw new AnnotationDispatchError(\n 'Each annotation must include at least one target.',\n 'INVALID_REQUEST',\n )\n }\n\n for (const target of annotation.targets) {\n const absolutePath = resolveWorkspacePath(target.location.file, state.cwd)\n assertPathWithinProject(absolutePath, state.projectRoot)\n }\n }\n}\n\nexport function normalizeAnnotationBatch(\n req: SendAnnotationsToAiRequest,\n): NormalizedAnnotationBatch {\n return {\n instruction: req.instruction?.trim() ?? '',\n responseMode: req.responseMode ?? 'unified',\n ...(req.runtimeContext ? { runtimeContext: req.runtimeContext } : {}),\n ...(req.screenshotContext ? { screenshotContext: req.screenshotContext } : {}),\n ...(req.cssContextPrompt?.trim() ? { cssContextPrompt: req.cssContextPrompt.trim() } : {}),\n annotations: req.annotations.map((annotation, index) => ({\n index: index + 1,\n note: annotation.note.trim(),\n intent: annotation.intent,\n targets: annotation.targets.map(target => ({\n file: target.location.file,\n line: target.location.line,\n column: target.location.column,\n ...(target.label ? { label: target.label } : {}),\n ...(target.selector ? { selector: target.selector } : {}),\n ...(target.snippet ? { snippet: target.snippet } : {}),\n })),\n })),\n }\n}\n\nexport function buildAnnotationBatchPrompt(batch: NormalizedAnnotationBatch): string {\n const body = buildSelectedElementsPrompt(batch.annotations)\n const prompt = batch.instruction ? `${batch.instruction}\\n\\n${body}` : body\n\n return appendScreenshotContextSection(\n appendCssContextSection(\n appendRuntimeContextSection(prompt, batch.runtimeContext),\n batch.cssContextPrompt,\n ),\n batch.screenshotContext,\n )\n}\n\nfunction appendCssContextSection(prompt: string, cssContextPrompt: string | undefined): string {\n if (!cssContextPrompt) return prompt\n return `${prompt}\\n\\n${cssContextPrompt}`\n}\n\nfunction buildSelectedElementsPrompt(annotations: NormalizedAnnotation[]): string {\n const lines = ['Selected elements:']\n\n for (const annotation of annotations) {\n const trimmedNote = annotation.note.trim()\n for (const target of annotation.targets) {\n const targetLabel = (target.label || 'Unknown target').trim() || 'Unknown target'\n lines.push(`- ${targetLabel}`)\n lines.push(`file=${target.file}:${target.line}:${target.column}`)\n if (trimmedNote) {\n lines.push(`note=${trimmedNote}`)\n }\n }\n }\n\n if (lines.length === 1) {\n lines.push('- None')\n }\n\n return lines.join('\\n')\n}\n\nfunction appendScreenshotContextSection(\n prompt: string,\n screenshotContext: ScreenshotContext | undefined,\n): string {\n if (!screenshotContext || (!screenshotContext.imageDataUrl && !screenshotContext.imageAssetId)) {\n return prompt\n }\n\n const lines = [\n 'Visual screenshot context attached:',\n `- capturedAt=${screenshotContext.capturedAt}`,\n `- mimeType=${screenshotContext.mimeType}`,\n ...(screenshotContext.imageAssetId ? [`- imageAssetId=${screenshotContext.imageAssetId}`] : []),\n ]\n\n return `${prompt}\\n\\n${lines.join('\\n')}`\n}\n\nfunction appendRuntimeContextSection(\n prompt: string,\n runtimeContext: RuntimeContextEnvelope | undefined,\n): string {\n if (!runtimeContext?.records.length) {\n return prompt\n }\n\n return `${prompt}\\n\\n${buildRuntimeContextSection(runtimeContext.records)}`\n}\n\nfunction buildRuntimeContextSection(records: RuntimeEvidenceRecord[]): string {\n return ['Relevant runtime context:', ...records.map(formatRuntimeRecord)].join('\\n')\n}\n\nfunction formatRuntimeRecord(record: RuntimeEvidenceRecord): string {\n const requestSummary =\n record.kind === 'failed-request'\n ? `request=${record.request?.method ?? 'GET'} ${record.request?.pathname ?? record.request?.url ?? 'unknown'} status=${record.request?.status ?? 'unknown'}`\n : `occurrences=${record.occurrenceCount}`\n const reasonSummary = record.relevanceReasons.length\n ? record.relevanceReasons.join('; ')\n : 'timing-based'\n const stackSummary = record.stack\n ? `\\n stack=${record.stack.split('\\n').slice(0, 5).join(' | ')}`\n : ''\n\n return [\n `- [${record.kind}] ${record.message}`,\n ` relevance=${record.relevanceLevel} (${reasonSummary})`,\n ` ${requestSummary}`,\n stackSummary,\n ]\n .filter(Boolean)\n .join('\\n')\n}\n\nfunction getAnnotationDispatchErrorCode(error: unknown): AiErrorCode {\n if (error instanceof AnnotationDispatchError) return error.errorCode\n if (error instanceof Error && error.message.includes('outside of project workspace')) {\n return 'FORBIDDEN_PATH'\n }\n return 'UNKNOWN'\n}\n","import type { IdeType, InspectoConfig, ServerState } from '@inspecto-dev/types'\nimport { loadPromptsConfig, loadUserConfigSync, resolveIntents } from '../config.js'\n\nexport async function buildClientConfig(\n serverState: ServerState,\n): Promise<InspectoConfig & { autoSend: boolean }> {\n const userConfig = loadUserConfigSync(false, serverState.cwd, serverState.configRoot)\n const promptsConfig = await loadPromptsConfig(false, serverState.cwd, serverState.configRoot)\n const effectiveIde = (userConfig.ide ?? 'vscode') as IdeType\n\n let info: any\n if (!serverState.ideInfo) {\n info = { ide: effectiveIde }\n } else {\n const { scheme: _scheme, ...rest } = serverState.ideInfo as any\n info = rest\n }\n\n return {\n ...info,\n prompts: resolveIntents(promptsConfig),\n hotKeys: userConfig['inspector.hotKey'] ?? 'alt',\n theme: userConfig['inspector.theme'] ?? 'auto',\n includeSnippet: userConfig['prompt.includeSnippet'] ?? false,\n runtimeContext: {\n enabled: true,\n preview: true,\n maxRuntimeErrors: 3,\n maxFailedRequests: 2,\n },\n screenshotContext: {\n enabled: false,\n },\n annotationResponseMode: userConfig['prompt.annotationResponseMode'] ?? 'unified',\n autoSend: userConfig['prompt.autoSend'] ?? false,\n }\n}\n","import { execFileSync } from 'node:child_process'\nimport { Editor, launchIDE } from 'launch-ide'\nimport type { OpenFileRequest, ServerState } from '@inspecto-dev/types'\nimport { loadUserConfigSync } from '../config.js'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\nimport { assertPathWithinIdeOpenScope, resolveWorkspacePath } from './path-guards.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nconst VSCODE_FAMILY_SCHEMES = [\n 'vscode',\n 'vscode-insiders',\n 'cursor',\n 'windsurf',\n 'trae',\n 'trae-cn',\n 'vscodium',\n 'codebuddy',\n 'codebuddy-cn',\n 'codebuddycn',\n 'antigravity',\n]\n\nfunction normalizeIdeToken(value: string | undefined): string {\n return (value ?? '').toLowerCase().replace(/[^a-z0-9]/g, '')\n}\n\nexport function handleOpenFileRequest(\n body: OpenFileRequest,\n serverState: ServerState,\n): { success: true } {\n const absolutePath = resolveWorkspacePath(body.file, serverState.cwd)\n\n assertPathWithinIdeOpenScope(absolutePath, serverState.projectRoot)\n\n const userConfig = loadUserConfigSync(false, serverState.cwd, serverState.configRoot)\n const configuredIde = userConfig.ide\n const activeIde = serverState.ideInfo?.ide\n const activeIdeScheme = serverState.ideInfo?.scheme\n\n const configuredIdeMatchesActiveScheme =\n Boolean(configuredIde) &&\n Boolean(activeIdeScheme) &&\n normalizeIdeToken(configuredIde) === normalizeIdeToken(activeIdeScheme)\n\n const rawEditorHint = configuredIdeMatchesActiveScheme\n ? activeIdeScheme!\n : configuredIde || activeIde || activeIdeScheme || 'code'\n\n if (\n configuredIde &&\n activeIdeScheme &&\n normalizeIdeToken(activeIdeScheme).includes(normalizeIdeToken(configuredIde)) === false\n ) {\n serverLogger.warn(\n `Active IDE is ${activeIdeScheme}, but config forces ${configuredIde}. Using configured IDE.`,\n )\n }\n\n let editorHint = rawEditorHint\n if (rawEditorHint === 'vscode') editorHint = 'code'\n else if (rawEditorHint === 'vscode-insiders') editorHint = 'code-insiders'\n else if (rawEditorHint === 'vscodium') editorHint = 'codium'\n else if (rawEditorHint === 'trae-cn' || rawEditorHint === 'trae') editorHint = 'trae'\n\n serverLogger.debug(\n `IDE_OPEN: activeIde=${activeIde}, activeIdeScheme=${activeIdeScheme}, configuredIde=${configuredIde} -> rawEditorHint=${rawEditorHint}, finalEditorHint=${editorHint}`,\n )\n\n if (VSCODE_FAMILY_SCHEMES.includes(rawEditorHint)) {\n let normalizedPath = absolutePath.replace(/\\\\/g, '/')\n if (!normalizedPath.startsWith('/')) {\n normalizedPath = '/' + normalizedPath\n }\n const encodedPath = encodeURI(normalizedPath)\n const uri = `${rawEditorHint}://file${encodedPath}:${body.line}:${body.column}`\n serverLogger.debug(`IDE_OPEN: Bypassing launchIDE, using URI scheme directly: ${uri}`)\n\n try {\n if (process.platform === 'darwin') {\n execFileSync('open', [uri])\n } else if (process.platform === 'win32') {\n execFileSync('cmd', ['/c', 'start', '\"\"', uri])\n } else {\n execFileSync('xdg-open', [uri])\n }\n } catch (e) {\n serverLogger.error(`Failed to launch URI for IDE_OPEN (${uri}):`, e)\n launchIDE({\n file: absolutePath,\n line: body.line,\n column: body.column,\n editor: editorHint as Editor,\n type: process.platform === 'darwin' ? 'open' : 'exec',\n })\n }\n } else {\n launchIDE({\n file: absolutePath,\n line: body.line,\n column: body.column,\n editor: editorHint as Editor,\n type: process.platform === 'darwin' ? 'open' : 'exec',\n })\n }\n\n return { success: true }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport { execSync } from 'node:child_process'\nimport { createLogger } from '../utils/logger.js'\nimport { getGlobalLogLevel } from '../config.js'\n\nconst serverLogger = createLogger('inspecto:server', { logLevel: getGlobalLogLevel() })\n\nexport function resolveProjectRoot(): string {\n const cwd = process.cwd()\n let gitRoot: string\n try {\n gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim()\n } catch (e) {\n serverLogger.warn('Failed to resolve git root via git rev-parse:', e)\n gitRoot = cwd\n }\n\n const visited = new Set<string>()\n const search = (start: string, stop: string) => {\n let current = start\n while (!visited.has(current)) {\n visited.add(current)\n if (fs.existsSync(path.join(current, '.inspecto'))) return current\n if (current === stop) break\n const parent = path.dirname(current)\n if (parent === current) break\n current = parent\n }\n return null\n }\n\n const cwdMatch = search(cwd, path.parse(cwd).root)\n if (cwdMatch) return cwdMatch\n\n const repoMatch = search(gitRoot, path.parse(gitRoot).root)\n if (repoMatch) return repoMatch\n\n return gitRoot\n}\n","import { createRequire } from 'node:module'\n\n// Safely resolve the client module without breaking ESM/CJS or bundling\nexport const resolveClientModule = () => {\n try {\n return createRequire(import.meta.url).resolve('@inspecto-dev/core')\n } catch {\n try {\n return require.resolve('@inspecto-dev/core')\n } catch {\n console.warn(\n '[inspecto] Could not resolve @inspecto-dev/core — falling back to bare specifier',\n )\n return '@inspecto-dev/core'\n }\n }\n}\n","export function getWebpackHtmlScript(serverPort: number) {\n return `\nwindow.__AI_INSPECTOR_PORT__ = ${serverPort};\nwindow.addEventListener('load', () => {\n if (window.InspectoClient) {\n window.InspectoClient.mountInspector({\n serverUrl: 'http://127.0.0.1:' + window.__AI_INSPECTOR_PORT__,\n });\n }\n});\n`\n}\n\nexport function getWebpackAssetScript(serverPort: number) {\n return `\nif (typeof window !== 'undefined') {\n window.__AI_INSPECTOR_PORT__ = ${serverPort};\n const _initInspecto = () => {\n if (window.InspectoClient) {\n window.InspectoClient.mountInspector({\n serverUrl: 'http://127.0.0.1:' + window.__AI_INSPECTOR_PORT__,\n });\n } else {\n setTimeout(_initInspecto, 100);\n }\n };\n if (document.readyState === 'complete') {\n _initInspecto();\n } else {\n window.addEventListener('load', _initInspecto);\n }\n}\n`\n}\n\nexport function injectWebpack(\n compiler: any,\n serverPortFn: () => Promise<number>,\n resolveClientModule: () => string,\n) {\n const inspectoClientPath = resolveClientModule()\n\n // Inject the client logic directly using the absolute path\n if (compiler.webpack && compiler.webpack.EntryPlugin) {\n // Webpack 5+\n new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {\n name: undefined,\n }).apply(compiler)\n }\n\n compiler.hooks.compilation.tap('inspecto-overlay', (compilation: any) => {\n // Find HtmlWebpackPlugin (standard Webpack)\n const HtmlWebpackPlugin = compiler.options.plugins.find(\n (p: any) => p && p.constructor && p.constructor.name === 'HtmlWebpackPlugin',\n )\n if (HtmlWebpackPlugin) {\n const hooks = (HtmlWebpackPlugin.constructor as any).getHooks(compilation)\n hooks.alterAssetTagGroups.tapPromise('inspecto-overlay', async (data: any) => {\n const port = await serverPortFn()\n data.headTags.unshift({\n tagName: 'script',\n voidTag: false,\n meta: { plugin: 'inspecto-overlay' },\n innerHTML: getWebpackHtmlScript(port),\n })\n return data\n })\n } else {\n // Fallback for frameworks like Next.js that don't use HtmlWebpackPlugin\n if (compilation.hooks.processAssets) {\n // Webpack 5+\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'inspecto-overlay',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n async (assets: any) => {\n const port = await serverPortFn()\n\n // Only inject into the main client entry chunks (e.g. main-app, main.js, umi.js)\n const mainAssetKey = Object.keys(assets).find(\n key =>\n key.endsWith('.js') &&\n (key.includes('main') || key.includes('app') || key.includes('umi')),\n )\n if (!mainAssetKey) return\n\n const originalSource = assets[mainAssetKey].source()\n assets[mainAssetKey] = new compiler.webpack.sources.RawSource(\n getWebpackAssetScript(port) + '\\n' + originalSource,\n )\n },\n )\n }\n }\n })\n}\n","import type { UnpluginOptions } from '@inspecto-dev/types'\nimport { startServer } from '../../server/index.js'\nimport { resolveClientModule } from '../../injectors/utils.js'\nimport { getWebpackHtmlScript } from '../../injectors/webpack.js'\nimport path from 'node:path'\n\n// Get current directory securely in both ESM and CJS via tsup shims\nconst _dirname = typeof __dirname !== 'undefined' ? __dirname : __dirname\n\nconst DEFAULT_OPTIONS: Required<UnpluginOptions> = {\n include: [],\n exclude: [],\n escapeTags: [],\n pathType: 'absolute',\n attributeName: 'data-inspecto',\n logLevel: 'warn',\n}\n\nlet serverPort: number | null = null\n\nconst ensureServer = async () => {\n if (serverPort === null) {\n serverPort = await startServer()\n }\n return serverPort\n}\n\nexport class InspectoRspackLegacyPlugin {\n options: Required<UnpluginOptions>\n\n constructor(options: UnpluginOptions = {}) {\n this.options = { ...DEFAULT_OPTIONS, ...options }\n }\n\n apply(compiler: any) {\n if (process.env['NODE_ENV'] === 'production') return\n\n // Ensure server starts\n compiler.hooks.beforeCompile.tapPromise('inspecto-overlay', async () => {\n await ensureServer().catch(console.error)\n })\n\n // 1. Inject client module\n const clientPath = resolveClientModule()\n new compiler.webpack.EntryPlugin(compiler.context, clientPath, {}).apply(compiler)\n\n // 2. Inject HTML\n compiler.hooks.compilation.tap('inspecto-overlay', (compilation: any) => {\n // First try HtmlRspackPlugin (modern)\n const HtmlRspackPlugin = compiler.options.plugins.find(\n (p: any) => p && p.constructor && p.constructor.name === 'HtmlRspackPlugin',\n )\n\n if (HtmlRspackPlugin && HtmlRspackPlugin.constructor.getHooks) {\n const hooks = HtmlRspackPlugin.constructor.getHooks(compilation)\n hooks.alterAssetTagGroups.tapPromise('inspecto-overlay', async (data: any) => {\n const port = await ensureServer()\n\n data.headTags.unshift({\n tagName: 'script',\n voidTag: false,\n meta: { plugin: 'inspecto-overlay' },\n innerHTML: getWebpackHtmlScript(port),\n })\n return data\n })\n } else {\n // Fallback for Rspack 0.3.x with builtins.html\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'inspecto-overlay',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,\n },\n async (assets: any) => {\n const port = await ensureServer()\n const scriptTag = `<script>${getWebpackHtmlScript(port)}</script>`\n\n for (const filename of Object.keys(assets)) {\n if (filename.endsWith('.html')) {\n const source = assets[filename].source()\n if (typeof source === 'string') {\n const newSource = source.replace('</head>', `${scriptTag}</head>`)\n assets[filename] = new compiler.webpack.sources.RawSource(newSource)\n } else if (Buffer.isBuffer(source)) {\n const sourceStr = source.toString('utf-8')\n const newSource = sourceStr.replace('</head>', `${scriptTag}</head>`)\n assets[filename] = new compiler.webpack.sources.RawSource(newSource)\n }\n }\n }\n },\n )\n }\n })\n\n // 3. Inject AST Transform Loader\n const loaderPath = path.resolve(_dirname, './loader.cjs')\n compiler.options.module.rules.push({\n test: /\\.[jt]sx?$/,\n use: [\n {\n loader: loaderPath,\n options: this.options,\n },\n ],\n })\n }\n}\n\nexport const rspackPlugin = (options?: UnpluginOptions) => new InspectoRspackLegacyPlugin(options)\nexport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,YAAY,WAAW,qBAAqB,IAAI,CAAC;AAEvD,uBAAW,YAAY,OAAO,KAAK,MAAM,GAAG;AAC1C,kBAAI,SAAS,SAAS,OAAO,GAAG;AAC9B,sBAAM,SAAS,OAAO,QAAQ,EAAE,OAAO;AACvC,oBAAI,OAAO,WAAW,UAAU;AAC9B,wBAAM,YAAY,OAAO,QAAQ,WAAW,GAAG,SAAS,SAAS;AACjE,yBAAO,QAAQ,IAAI,IAAI,SAAS,QAAQ,QAAQ,UAAU,SAAS;AAAA,gBACrE,WAAW,OAAO,SAAS,MAAM,GAAG;AAClC,wBAAM,YAAY,OAAO,SAAS,OAAO;AACzC,wBAAM,YAAY,UAAU,QAAQ,WAAW,GAAG,SAAS,SAAS;AACpE,yBAAO,QAAQ,IAAI,IAAI,SAAS,QAAQ,QAAQ,UAAU,SAAS;AAAA,gBACrE;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,aAAaA,MAAK,QAAQ,UAAU,cAAc;AACxD,aAAS,QAAQ,OAAO,MAAM,KAAK;AAAA,MACjC,MAAM;AAAA,MACN,KAAK;AAAA,QACH;AAAA,UACE,QAAQ;AAAA,UACR,SAAS,KAAK;AAAA,QAChB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,IAAM,eAAe,CAAC,YAA8B,IAAI,2BAA2B,OAAO;AACjG,IAAO,iBAAQ;","names":["fs","path","os","crypto","path","fs","path","path","fs","path","fs","serverState","execFileSync","launchIDE","serverLogger","normalizeIdeToken","serverState","execFileSync","launchIDE","fs","path","serverLogger","fs","path","serverLogger","resolve","path","os","fs","crypto","resolve","path","serverLogger","serverPort","path"]}
|