@glasstrace/sdk 1.1.1 → 1.1.2

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.
Files changed (46) hide show
  1. package/README.md +78 -1
  2. package/dist/{chunk-DIM4JRXM.js → chunk-2M57EO6U.js} +2 -2
  3. package/dist/{chunk-P22UQ2OJ.js → chunk-3LILTM3T.js} +1 -1
  4. package/dist/chunk-3LILTM3T.js.map +1 -0
  5. package/dist/{chunk-MXDZHFJQ.js → chunk-C567H5EQ.js} +2 -2
  6. package/dist/{chunk-7SZQN6IU.js → chunk-NB7GJE4S.js} +2 -2
  7. package/dist/chunk-NB7GJE4S.js.map +1 -0
  8. package/dist/{chunk-ZRDQ6ZKI.js → chunk-UJ2JC7PZ.js} +92 -473
  9. package/dist/chunk-UJ2JC7PZ.js.map +1 -0
  10. package/dist/{chunk-Y26HJUPD.js → chunk-Z35HKVSO.js} +135 -8
  11. package/dist/chunk-Z35HKVSO.js.map +1 -0
  12. package/dist/cli/init.cjs +463 -440
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +434 -63
  15. package/dist/cli/init.js.map +1 -1
  16. package/dist/cli/mcp-add.cjs +14 -2
  17. package/dist/cli/mcp-add.cjs.map +1 -1
  18. package/dist/cli/mcp-add.js +17 -5
  19. package/dist/cli/mcp-add.js.map +1 -1
  20. package/dist/cli/status.cjs.map +1 -1
  21. package/dist/cli/status.js +1 -3
  22. package/dist/cli/status.js.map +1 -1
  23. package/dist/cli/uninit.cjs +3 -3
  24. package/dist/cli/uninit.cjs.map +1 -1
  25. package/dist/cli/uninit.js +3 -3
  26. package/dist/cli/validate.cjs +14162 -2
  27. package/dist/cli/validate.cjs.map +1 -1
  28. package/dist/cli/validate.d.cts +7 -3
  29. package/dist/cli/validate.d.ts +7 -3
  30. package/dist/cli/validate.js +25 -2
  31. package/dist/cli/validate.js.map +1 -1
  32. package/dist/index.cjs +134 -5
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.js +3 -3
  35. package/dist/{monorepo-GSL6JD3G.js → monorepo-PFVNPQ6X.js} +3 -5
  36. package/dist/node-entry.cjs +134 -5
  37. package/dist/node-entry.cjs.map +1 -1
  38. package/dist/node-entry.js +3 -3
  39. package/package.json +1 -1
  40. package/dist/chunk-7SZQN6IU.js.map +0 -1
  41. package/dist/chunk-P22UQ2OJ.js.map +0 -1
  42. package/dist/chunk-Y26HJUPD.js.map +0 -1
  43. package/dist/chunk-ZRDQ6ZKI.js.map +0 -1
  44. /package/dist/{chunk-DIM4JRXM.js.map → chunk-2M57EO6U.js.map} +0 -0
  45. /package/dist/{chunk-MXDZHFJQ.js.map → chunk-C567H5EQ.js.map} +0 -0
  46. /package/dist/{monorepo-GSL6JD3G.js.map → monorepo-PFVNPQ6X.js.map} +0 -0
@@ -6,9 +6,6 @@ import {
6
6
  updateGitignore,
7
7
  writeMcpConfig
8
8
  } from "../chunk-P4OYPFQ5.js";
9
- import {
10
- formatAgentName
11
- } from "../chunk-7SZQN6IU.js";
12
9
  import {
13
10
  MCP_ENDPOINT,
14
11
  identityFingerprint,
@@ -16,8 +13,11 @@ import {
16
13
  readMcpMarker,
17
14
  resolveEffectiveMcpCredential,
18
15
  writeMcpMarker
19
- } from "../chunk-P22UQ2OJ.js";
16
+ } from "../chunk-3LILTM3T.js";
20
17
  import "../chunk-X5MAXP5T.js";
18
+ import {
19
+ formatAgentName
20
+ } from "../chunk-NB7GJE4S.js";
21
21
  import "../chunk-NSBPE2FW.js";
22
22
 
23
23
  // src/cli/mcp-add.ts
@@ -134,7 +134,8 @@ async function mcpAdd(options) {
134
134
  }
135
135
  const agents = await detectAgents(projectRoot);
136
136
  const detectedNonGeneric = agents.filter((a) => a.name !== "generic");
137
- const targetAgents = detectedNonGeneric.length > 0 ? detectedNonGeneric : agents.filter((a) => a.name === "generic");
137
+ const genericAgent = agents.find((a) => a.name === "generic");
138
+ const targetAgents = genericAgent ? [...detectedNonGeneric, genericAgent] : detectedNonGeneric;
138
139
  if (dryRun) {
139
140
  messages.push("Dry run: would perform the following actions:", "");
140
141
  for (const agent of targetAgents) {
@@ -243,6 +244,17 @@ async function mcpAdd(options) {
243
244
  " No agents detected. Place agent marker files (e.g., CLAUDE.md, .cursor/) in your project."
244
245
  );
245
246
  }
247
+ const detectedNonGenericResults = results.filter(
248
+ (r) => detectedNonGeneric.some((a) => a.name === r.agent)
249
+ );
250
+ const allDetectedNonGenericFailed = detectedNonGeneric.length > 0 && !detectedNonGenericResults.some((r) => r.success);
251
+ if (allDetectedNonGenericFailed) {
252
+ messages.push(
253
+ "",
254
+ "All detected agent registrations failed. Check errors above."
255
+ );
256
+ return { exitCode: 1, results, messages };
257
+ }
246
258
  if (!anySuccess && results.length > 0) {
247
259
  messages.push(
248
260
  "",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/mcp-add.ts"],"sourcesContent":["import { execFile as execFileCb } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport {\n isAnonApiKey,\n identityFingerprint,\n readMcpMarker,\n resolveEffectiveMcpCredential,\n writeMcpMarker,\n type EffectiveMcpCredential,\n} from \"../mcp-runtime.js\";\nimport { detectAgents } from \"../agent-detection/detect.js\";\nimport { generateMcpConfig, generateInfoSection } from \"../agent-detection/configs.js\";\nimport {\n writeMcpConfig,\n injectInfoSection,\n updateGitignore,\n} from \"../agent-detection/inject.js\";\nimport type { DetectedAgent } from \"../agent-detection/detect.js\";\nimport { MCP_ENDPOINT, formatAgentName } from \"./constants.js\";\n\nconst execFileAsync = promisify(execFileCb);\n\n/** Options for the mcp add command. */\nexport interface McpAddOptions {\n force?: boolean;\n dryRun?: boolean;\n}\n\n/** Result of the mcp add command. */\nexport interface McpAddResult {\n exitCode: number;\n results: AgentResult[];\n messages: string[];\n}\n\n/**\n * Result of a single agent registration attempt.\n */\ninterface AgentResult {\n agent: DetectedAgent[\"name\"];\n success: boolean;\n method: \"cli\" | \"file\" | \"skipped\";\n message: string;\n}\n\n/**\n * Attempts CLI-based MCP registration for agents that support it.\n * Returns true if the CLI command succeeded.\n *\n * **Anon keys only, by design.** This path passes the bearer token to\n * vendor CLIs (Claude, Gemini) as a process argument; on multi-user\n * hosts, process arguments are visible via `ps` and `/proc`. Anon keys\n * are non-secret project identifiers — exposing one in a process\n * listing is acceptable. A claimed dev/account key absolutely is not.\n *\n * Two layers of enforcement:\n *\n * 1. The `bearer` parameter is typed `string` rather than `AnonApiKey`\n * only because the function is called through CLI plumbing where\n * the brand is erased; callers must verify the source upstream.\n * 2. A runtime `isAnonApiKey` guard at the top of the function\n * short-circuits with `false` if the value fails strict\n * `AnonApiKeySchema` validation. This defends against accidental\n * `string`-typed paths that erase the brand and against any\n * future caller that forgets the upstream check.\n *\n * Codex's CLI registration does not embed the bearer (it writes\n * `bearer_token_env_var = \"GLASSTRACE_API_KEY\"` and reads the\n * actual token from the environment), so it is unaffected by this\n * constraint.\n */\n/** @internal Exported for unit testing of the runtime anon-only guard. */\nexport async function registerViaCli(\n agent: DetectedAgent,\n bearer: string,\n): Promise<boolean> {\n if (!agent.cliAvailable) {\n return false;\n }\n\n // Layer 2: runtime guard. If the bearer is not a strictly-valid\n // anon key, refuse to put it in process arguments. The caller is\n // expected to fall through to the file-config path, which writes\n // 0o600 files and never exposes the bearer to other processes.\n if (agent.name !== \"codex\" && !isAnonApiKey(bearer)) {\n return false;\n }\n\n try {\n switch (agent.name) {\n case \"claude\": {\n const payload = JSON.stringify({\n type: \"http\",\n url: MCP_ENDPOINT,\n headers: { Authorization: `Bearer ${bearer}` },\n });\n await execFileAsync(\"claude\", [\n \"mcp\",\n \"add-json\",\n \"glasstrace\",\n payload,\n \"--scope\",\n \"project\",\n ]);\n return true;\n }\n\n case \"codex\": {\n await execFileAsync(\"codex\", [\n \"mcp\",\n \"add\",\n \"glasstrace\",\n \"--url\",\n MCP_ENDPOINT,\n ]);\n // Ensure .codex/config.toml has bearer_token_env_var\n const configPath = agent.mcpConfigPath;\n if (configPath !== null && fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, \"utf-8\");\n if (!content.includes(\"bearer_token_env_var\")) {\n const appendContent =\n content.endsWith(\"\\n\") ? \"\" : \"\\n\";\n fs.writeFileSync(\n configPath,\n content +\n appendContent +\n 'bearer_token_env_var = \"GLASSTRACE_API_KEY\"\\n',\n \"utf-8\",\n );\n }\n }\n process.stderr.write(\n \" Note: Set GLASSTRACE_API_KEY environment variable for Codex authentication.\\n\",\n );\n return true;\n }\n\n case \"gemini\": {\n await execFileAsync(\"gemini\", [\n \"mcp\",\n \"add\",\n \"--transport\",\n \"http\",\n \"--header\",\n `Authorization: Bearer ${bearer}`,\n \"glasstrace\",\n MCP_ENDPOINT,\n ]);\n return true;\n }\n\n default:\n return false;\n }\n } catch {\n return false;\n }\n}\n\n/**\n * Returns whether the on-disk marker describes the same underlying\n * credential as the resolver's effective credential.\n *\n * Compares on `credentialHash` only — the credential identity, not\n * the on-disk *source* it was loaded from. The source can shift\n * without the key actually changing (e.g., a user copies the same\n * key from `.glasstrace/claimed-key` into `.env.local`, or vice\n * versa), and treating that shift as a credential change would\n * falsely trigger the claim-transition refresh on a project whose\n * `mcp.json` already embeds the correct bearer.\n *\n * Treats `unknown-version` and `corrupted` markers as not-matching\n * (forces a re-run that overwrites them with v2). Treats `absent`\n * markers as not-matching too — the caller's existing\n * `fs.existsSync(markerPath)` short-circuit catches that case before\n * calling here, so this branch only fires when a marker read itself\n * failed.\n */\nasync function markerMatchesEffective(\n projectRoot: string,\n effective: EffectiveMcpCredential,\n): Promise<boolean> {\n const state = await readMcpMarker(projectRoot);\n if (state.status !== \"valid\") return false;\n return state.credentialHash === identityFingerprint(effective.key);\n}\n\n/**\n * Registers the Glasstrace MCP server with detected AI coding agents.\n *\n * For each agent, attempts native CLI registration first (anon keys\n * only, see {@link registerViaCli}), then falls back to file-based\n * configuration. The marker file at `.glasstrace/mcp-connected`\n * records the effective credential's source and identity fingerprint\n * so a later run can detect a project that has transitioned from\n * anon to account/dev-key and prompt a refresh.\n *\n * Returns a structured result instead of calling process.exit(), so the\n * CLI entry point can decide how to handle the outcome.\n *\n * @param options - Control flags for force and dry-run modes.\n */\nexport async function mcpAdd(options?: McpAddOptions): Promise<McpAddResult> {\n const force = options?.force ?? false;\n const dryRun = options?.dryRun ?? false;\n const projectRoot = process.cwd();\n const messages: string[] = [];\n\n // Step 1: Resolve the effective credential. Replaces the prior\n // anon-only `readAnonKey` path; dev-key-only projects (no\n // .glasstrace/anon_key on disk) now run too.\n const resolved = await resolveEffectiveMcpCredential(projectRoot);\n if (resolved.effective === null) {\n return {\n exitCode: 1,\n results: [],\n messages: [\"Error: Run `glasstrace init` first to generate an API key.\"],\n };\n }\n\n // Optional: surface the claimed-key-only warning so the user knows\n // to copy the key into .env.local for normal use.\n if (resolved.warnings.includes(\"claimed-key-only\")) {\n messages.push(\n \"Note: dev key was loaded from .glasstrace/claimed-key. Copy it into .env.local so your app and Codex pick it up automatically.\",\n );\n }\n\n // Step 2: Marker check.\n //\n // Two short-circuits:\n // - Marker absent and not --force: the legacy \"MCP already\n // configured\" message is no longer applicable here, but absence\n // of the marker means we proceed to register. (The original\n // behaviour was to short-circuit if the marker existed; the\n // short-circuit now also requires the marker to actually match\n // the effective credential.)\n // - Marker present, matches effective credential, and not --force:\n // already configured for this credential, no work to do.\n // - Marker present, mismatches effective credential, regardless of\n // --force: the project has transitioned credentials; treat as\n // unconfigured and re-register.\n const markerPath = path.join(projectRoot, \".glasstrace\", \"mcp-connected\");\n if (fs.existsSync(markerPath) && !force) {\n if (await markerMatchesEffective(projectRoot, resolved.effective)) {\n return {\n exitCode: 0,\n results: [],\n messages: [\"MCP already configured. Use --force to reconfigure.\"],\n };\n }\n // Mismatch: project has transitioned credentials. Fall through to\n // re-register so MCP queries see the same scope as ingestion.\n messages.push(\n \"Detected a credential change since MCP was last configured. Refreshing MCP config so queries use the current account credential.\",\n );\n }\n\n // Step 3: Detect agents\n const agents = await detectAgents(projectRoot);\n const detectedNonGeneric = agents.filter((a) => a.name !== \"generic\");\n\n // If no specific agents found, include the generic fallback so the command\n // still produces a usable .glasstrace/mcp.json (matching init behavior).\n const targetAgents =\n detectedNonGeneric.length > 0\n ? detectedNonGeneric\n : agents.filter((a) => a.name === \"generic\");\n\n if (dryRun) {\n messages.push(\"Dry run: would perform the following actions:\", \"\");\n for (const agent of targetAgents) {\n const name = formatAgentName(agent.name);\n if (agent.cliAvailable && resolved.effective.source === \"anon\") {\n messages.push(\n ` ${name}: Register via CLI (${agent.name} mcp add)`,\n );\n } else if (agent.mcpConfigPath !== null) {\n messages.push(\n ` ${name}: Write config to ${agent.mcpConfigPath}`,\n );\n }\n if (agent.infoFilePath !== null) {\n messages.push(\n ` ${name}: Inject info section into ${agent.infoFilePath}`,\n );\n }\n }\n messages.push(\n \"\",\n \" Update .gitignore with MCP config paths\",\n \" Create .glasstrace/mcp-connected marker\",\n );\n return { exitCode: 0, results: [], messages };\n }\n\n // Step 4: Register with each agent. The bearer used in the embedded\n // configs and in vendor CLI invocations is the resolver's effective\n // credential. registerViaCli is anon-only by design (see its\n // docstring); when the effective credential is a dev key, that path\n // returns false and the file-config branch takes over.\n const results: AgentResult[] = [];\n const bearer = resolved.effective.key;\n\n for (const agent of targetAgents) {\n const name = formatAgentName(agent.name);\n\n // Try CLI registration first (not applicable for generic)\n if (agent.name !== \"generic\") {\n const cliSuccess = await registerViaCli(agent, bearer);\n if (cliSuccess) {\n // Still inject info section if applicable\n const infoContent = generateInfoSection(agent, MCP_ENDPOINT);\n if (infoContent !== \"\") {\n await injectInfoSection(agent, infoContent, projectRoot);\n }\n results.push({\n agent: agent.name,\n success: true,\n method: \"cli\",\n message: `${name}: Registered via CLI`,\n });\n continue;\n }\n }\n\n // Fall back to file-based config\n if (agent.mcpConfigPath !== null) {\n try {\n const configContent = generateMcpConfig(agent, MCP_ENDPOINT, bearer);\n await writeMcpConfig(agent, configContent, projectRoot);\n\n // Verify the config was written (writeMcpConfig swallows permission errors)\n if (fs.existsSync(agent.mcpConfigPath)) {\n const infoContent = generateInfoSection(agent, MCP_ENDPOINT);\n if (infoContent !== \"\") {\n await injectInfoSection(agent, infoContent, projectRoot);\n }\n results.push({\n agent: agent.name,\n success: true,\n method: \"file\",\n message: `${name}: Configured via ${agent.mcpConfigPath}`,\n });\n continue;\n }\n\n // writeMcpConfig returned without throwing but file doesn't exist\n // (permission denied handled gracefully inside writeMcpConfig)\n results.push({\n agent: agent.name,\n success: false,\n method: \"file\",\n message: `${name}: Failed to write config to ${agent.mcpConfigPath} (permission denied)`,\n });\n continue;\n } catch (err) {\n results.push({\n agent: agent.name,\n success: false,\n method: \"file\",\n message: `${name}: Failed - ${err instanceof Error ? err.message : String(err)}`,\n });\n continue;\n }\n }\n\n results.push({\n agent: agent.name,\n success: false,\n method: \"skipped\",\n message: `${name}: No registration method available`,\n });\n }\n\n // Step 5: Update gitignore\n await updateGitignore(\n [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".codex/config.toml\"],\n projectRoot,\n );\n\n // Step 6: Update marker if at least one succeeded. Marker records\n // the effective credential's source and fingerprint (raw key never\n // touches disk via this path), so a later run can detect a\n // credential change.\n const anySuccess = results.some((r) => r.success);\n\n if (anySuccess) {\n await writeMcpMarker(projectRoot, {\n credentialSource: resolved.effective.source,\n credentialHash: identityFingerprint(resolved.effective.key),\n });\n }\n\n // Step 7: Build summary messages\n messages.push(\"\", \"MCP registration summary:\");\n for (const result of results) {\n const icon = result.success ? \"+\" : \"-\";\n messages.push(` [${icon}] ${result.message}`);\n }\n\n if (results.length === 0) {\n messages.push(\n \" No agents detected. Place agent marker files (e.g., CLAUDE.md, .cursor/) in your project.\",\n );\n }\n\n if (!anySuccess && results.length > 0) {\n messages.push(\n \"\",\n \"All agent registrations failed. Check errors above.\",\n );\n return { exitCode: 1, results, messages };\n }\n\n if (anySuccess) {\n messages.push(\"\", \"MCP registration complete.\");\n }\n\n return { exitCode: 0, results, messages };\n}\n"],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AAW,GAAG;AACxB,aAAS;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,cAAc,QAAQ,SAAS,GAAG;AACrC,aAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AACA,WAAO,EAAE,UAAU,GAAG,SAAS,SAAS;AAAA,EAC1C;AAEA,MAAI,YAAY;AACd,aAAS,KAAK,IAAI,4BAA4B;AAAA,EAChD;AAEA,SAAO,EAAE,UAAU,GAAG,SAAS,SAAS;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../src/cli/mcp-add.ts"],"sourcesContent":["import { execFile as execFileCb } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport {\n isAnonApiKey,\n identityFingerprint,\n MCP_ENDPOINT,\n readMcpMarker,\n resolveEffectiveMcpCredential,\n writeMcpMarker,\n type EffectiveMcpCredential,\n} from \"../mcp-runtime.js\";\nimport { detectAgents } from \"../agent-detection/detect.js\";\nimport { generateMcpConfig, generateInfoSection } from \"../agent-detection/configs.js\";\nimport {\n writeMcpConfig,\n injectInfoSection,\n updateGitignore,\n} from \"../agent-detection/inject.js\";\nimport type { DetectedAgent } from \"../agent-detection/detect.js\";\nimport { formatAgentName } from \"./constants.js\";\n\nconst execFileAsync = promisify(execFileCb);\n\n/** Options for the mcp add command. */\nexport interface McpAddOptions {\n force?: boolean;\n dryRun?: boolean;\n}\n\n/** Result of the mcp add command. */\nexport interface McpAddResult {\n exitCode: number;\n results: AgentResult[];\n messages: string[];\n}\n\n/**\n * Result of a single agent registration attempt.\n */\ninterface AgentResult {\n agent: DetectedAgent[\"name\"];\n success: boolean;\n method: \"cli\" | \"file\" | \"skipped\";\n message: string;\n}\n\n/**\n * Attempts CLI-based MCP registration for agents that support it.\n * Returns true if the CLI command succeeded.\n *\n * **Anon keys only, by design.** This path passes the bearer token to\n * vendor CLIs (Claude, Gemini) as a process argument; on multi-user\n * hosts, process arguments are visible via `ps` and `/proc`. Anon keys\n * are non-secret project identifiers — exposing one in a process\n * listing is acceptable. A claimed dev/account key absolutely is not.\n *\n * Two layers of enforcement:\n *\n * 1. The `bearer` parameter is typed `string` rather than `AnonApiKey`\n * only because the function is called through CLI plumbing where\n * the brand is erased; callers must verify the source upstream.\n * 2. A runtime `isAnonApiKey` guard at the top of the function\n * short-circuits with `false` if the value fails strict\n * `AnonApiKeySchema` validation. This defends against accidental\n * `string`-typed paths that erase the brand and against any\n * future caller that forgets the upstream check.\n *\n * Codex's CLI registration does not embed the bearer (it writes\n * `bearer_token_env_var = \"GLASSTRACE_API_KEY\"` and reads the\n * actual token from the environment), so it is unaffected by this\n * constraint.\n */\n/** @internal Exported for unit testing of the runtime anon-only guard. */\nexport async function registerViaCli(\n agent: DetectedAgent,\n bearer: string,\n): Promise<boolean> {\n if (!agent.cliAvailable) {\n return false;\n }\n\n // Layer 2: runtime guard. If the bearer is not a strictly-valid\n // anon key, refuse to put it in process arguments. The caller is\n // expected to fall through to the file-config path, which writes\n // 0o600 files and never exposes the bearer to other processes.\n if (agent.name !== \"codex\" && !isAnonApiKey(bearer)) {\n return false;\n }\n\n try {\n switch (agent.name) {\n case \"claude\": {\n const payload = JSON.stringify({\n type: \"http\",\n url: MCP_ENDPOINT,\n headers: { Authorization: `Bearer ${bearer}` },\n });\n await execFileAsync(\"claude\", [\n \"mcp\",\n \"add-json\",\n \"glasstrace\",\n payload,\n \"--scope\",\n \"project\",\n ]);\n return true;\n }\n\n case \"codex\": {\n await execFileAsync(\"codex\", [\n \"mcp\",\n \"add\",\n \"glasstrace\",\n \"--url\",\n MCP_ENDPOINT,\n ]);\n // Ensure .codex/config.toml has bearer_token_env_var\n const configPath = agent.mcpConfigPath;\n if (configPath !== null && fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, \"utf-8\");\n if (!content.includes(\"bearer_token_env_var\")) {\n const appendContent =\n content.endsWith(\"\\n\") ? \"\" : \"\\n\";\n fs.writeFileSync(\n configPath,\n content +\n appendContent +\n 'bearer_token_env_var = \"GLASSTRACE_API_KEY\"\\n',\n \"utf-8\",\n );\n }\n }\n process.stderr.write(\n \" Note: Set GLASSTRACE_API_KEY environment variable for Codex authentication.\\n\",\n );\n return true;\n }\n\n case \"gemini\": {\n await execFileAsync(\"gemini\", [\n \"mcp\",\n \"add\",\n \"--transport\",\n \"http\",\n \"--header\",\n `Authorization: Bearer ${bearer}`,\n \"glasstrace\",\n MCP_ENDPOINT,\n ]);\n return true;\n }\n\n default:\n return false;\n }\n } catch {\n return false;\n }\n}\n\n/**\n * Returns whether the on-disk marker describes the same underlying\n * credential as the resolver's effective credential.\n *\n * Compares on `credentialHash` only — the credential identity, not\n * the on-disk *source* it was loaded from. The source can shift\n * without the key actually changing (e.g., a user copies the same\n * key from `.glasstrace/claimed-key` into `.env.local`, or vice\n * versa), and treating that shift as a credential change would\n * falsely trigger the claim-transition refresh on a project whose\n * `mcp.json` already embeds the correct bearer.\n *\n * Treats `unknown-version` and `corrupted` markers as not-matching\n * (forces a re-run that overwrites them with v2). Treats `absent`\n * markers as not-matching too — the caller's existing\n * `fs.existsSync(markerPath)` short-circuit catches that case before\n * calling here, so this branch only fires when a marker read itself\n * failed.\n */\nasync function markerMatchesEffective(\n projectRoot: string,\n effective: EffectiveMcpCredential,\n): Promise<boolean> {\n const state = await readMcpMarker(projectRoot);\n if (state.status !== \"valid\") return false;\n return state.credentialHash === identityFingerprint(effective.key);\n}\n\n/**\n * Registers the Glasstrace MCP server with detected AI coding agents.\n *\n * For each agent, attempts native CLI registration first (anon keys\n * only, see {@link registerViaCli}), then falls back to file-based\n * configuration. The marker file at `.glasstrace/mcp-connected`\n * records the effective credential's source and identity fingerprint\n * so a later run can detect a project that has transitioned from\n * anon to account/dev-key and prompt a refresh.\n *\n * Returns a structured result instead of calling process.exit(), so the\n * CLI entry point can decide how to handle the outcome.\n *\n * @param options - Control flags for force and dry-run modes.\n */\nexport async function mcpAdd(options?: McpAddOptions): Promise<McpAddResult> {\n const force = options?.force ?? false;\n const dryRun = options?.dryRun ?? false;\n const projectRoot = process.cwd();\n const messages: string[] = [];\n\n // Step 1: Resolve the effective credential. Replaces the prior\n // anon-only `readAnonKey` path; dev-key-only projects (no\n // .glasstrace/anon_key on disk) now run too.\n const resolved = await resolveEffectiveMcpCredential(projectRoot);\n if (resolved.effective === null) {\n return {\n exitCode: 1,\n results: [],\n messages: [\"Error: Run `glasstrace init` first to generate an API key.\"],\n };\n }\n\n // Optional: surface the claimed-key-only warning so the user knows\n // to copy the key into .env.local for normal use.\n if (resolved.warnings.includes(\"claimed-key-only\")) {\n messages.push(\n \"Note: dev key was loaded from .glasstrace/claimed-key. Copy it into .env.local so your app and Codex pick it up automatically.\",\n );\n }\n\n // Step 2: Marker check.\n //\n // Two short-circuits:\n // - Marker absent and not --force: the legacy \"MCP already\n // configured\" message is no longer applicable here, but absence\n // of the marker means we proceed to register. (The original\n // behaviour was to short-circuit if the marker existed; the\n // short-circuit now also requires the marker to actually match\n // the effective credential.)\n // - Marker present, matches effective credential, and not --force:\n // already configured for this credential, no work to do.\n // - Marker present, mismatches effective credential, regardless of\n // --force: the project has transitioned credentials; treat as\n // unconfigured and re-register.\n const markerPath = path.join(projectRoot, \".glasstrace\", \"mcp-connected\");\n if (fs.existsSync(markerPath) && !force) {\n if (await markerMatchesEffective(projectRoot, resolved.effective)) {\n return {\n exitCode: 0,\n results: [],\n messages: [\"MCP already configured. Use --force to reconfigure.\"],\n };\n }\n // Mismatch: project has transitioned credentials. Fall through to\n // re-register so MCP queries see the same scope as ingestion.\n messages.push(\n \"Detected a credential change since MCP was last configured. Refreshing MCP config so queries use the current account credential.\",\n );\n }\n\n // Step 3: Detect agents\n const agents = await detectAgents(projectRoot);\n const detectedNonGeneric = agents.filter((a) => a.name !== \"generic\");\n\n // The generic helper backs `.glasstrace/mcp.json`, the file\n // validation/debug tooling reads directly. ALWAYS include it in the\n // target list — when non-generic agents like Claude/Cursor are\n // detected, the helper used to be silently dropped, which left the\n // generic config stale after a credential change. `detectAgents`\n // contract guarantees the generic entry is always appended last\n // (see `agent-detection/detect.ts`), so we rely on that here rather\n // than synthesising a fallback.\n const genericAgent = agents.find((a) => a.name === \"generic\");\n const targetAgents: DetectedAgent[] = genericAgent\n ? [...detectedNonGeneric, genericAgent]\n : detectedNonGeneric;\n\n if (dryRun) {\n messages.push(\"Dry run: would perform the following actions:\", \"\");\n for (const agent of targetAgents) {\n const name = formatAgentName(agent.name);\n if (agent.cliAvailable && resolved.effective.source === \"anon\") {\n messages.push(\n ` ${name}: Register via CLI (${agent.name} mcp add)`,\n );\n } else if (agent.mcpConfigPath !== null) {\n messages.push(\n ` ${name}: Write config to ${agent.mcpConfigPath}`,\n );\n }\n if (agent.infoFilePath !== null) {\n messages.push(\n ` ${name}: Inject info section into ${agent.infoFilePath}`,\n );\n }\n }\n messages.push(\n \"\",\n \" Update .gitignore with MCP config paths\",\n \" Create .glasstrace/mcp-connected marker\",\n );\n return { exitCode: 0, results: [], messages };\n }\n\n // Step 4: Register with each agent. The bearer used in the embedded\n // configs and in vendor CLI invocations is the resolver's effective\n // credential. registerViaCli is anon-only by design (see its\n // docstring); when the effective credential is a dev key, that path\n // returns false and the file-config branch takes over.\n const results: AgentResult[] = [];\n const bearer = resolved.effective.key;\n\n for (const agent of targetAgents) {\n const name = formatAgentName(agent.name);\n\n // Try CLI registration first (not applicable for generic)\n if (agent.name !== \"generic\") {\n const cliSuccess = await registerViaCli(agent, bearer);\n if (cliSuccess) {\n // Still inject info section if applicable\n const infoContent = generateInfoSection(agent, MCP_ENDPOINT);\n if (infoContent !== \"\") {\n await injectInfoSection(agent, infoContent, projectRoot);\n }\n results.push({\n agent: agent.name,\n success: true,\n method: \"cli\",\n message: `${name}: Registered via CLI`,\n });\n continue;\n }\n }\n\n // Fall back to file-based config\n if (agent.mcpConfigPath !== null) {\n try {\n const configContent = generateMcpConfig(agent, MCP_ENDPOINT, bearer);\n await writeMcpConfig(agent, configContent, projectRoot);\n\n // Verify the config was written (writeMcpConfig swallows permission errors)\n if (fs.existsSync(agent.mcpConfigPath)) {\n const infoContent = generateInfoSection(agent, MCP_ENDPOINT);\n if (infoContent !== \"\") {\n await injectInfoSection(agent, infoContent, projectRoot);\n }\n results.push({\n agent: agent.name,\n success: true,\n method: \"file\",\n message: `${name}: Configured via ${agent.mcpConfigPath}`,\n });\n continue;\n }\n\n // writeMcpConfig returned without throwing but file doesn't exist\n // (permission denied handled gracefully inside writeMcpConfig)\n results.push({\n agent: agent.name,\n success: false,\n method: \"file\",\n message: `${name}: Failed to write config to ${agent.mcpConfigPath} (permission denied)`,\n });\n continue;\n } catch (err) {\n results.push({\n agent: agent.name,\n success: false,\n method: \"file\",\n message: `${name}: Failed - ${err instanceof Error ? err.message : String(err)}`,\n });\n continue;\n }\n }\n\n results.push({\n agent: agent.name,\n success: false,\n method: \"skipped\",\n message: `${name}: No registration method available`,\n });\n }\n\n // Step 5: Update gitignore\n await updateGitignore(\n [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".codex/config.toml\"],\n projectRoot,\n );\n\n // Step 6: Update marker if at least one succeeded. Marker records\n // the effective credential's source and fingerprint (raw key never\n // touches disk via this path), so a later run can detect a\n // credential change.\n const anySuccess = results.some((r) => r.success);\n\n if (anySuccess) {\n await writeMcpMarker(projectRoot, {\n credentialSource: resolved.effective.source,\n credentialHash: identityFingerprint(resolved.effective.key),\n });\n }\n\n // Step 7: Build summary messages\n messages.push(\"\", \"MCP registration summary:\");\n for (const result of results) {\n const icon = result.success ? \"+\" : \"-\";\n messages.push(` [${icon}] ${result.message}`);\n }\n\n if (results.length === 0) {\n messages.push(\n \" No agents detected. Place agent marker files (e.g., CLAUDE.md, .cursor/) in your project.\",\n );\n }\n\n // Exit code reflects whether the originally-detected non-generic\n // agents succeeded. The generic helper is always in `results` now —\n // letting its success alone mask a complete failure of the agents\n // the user actually has installed would silently break automation\n // that bisects on `mcp add` exit code. Preserves the pre-fix\n // contract: a run where Claude/Cursor failed still exits non-zero,\n // even when the generic helper write succeeded.\n const detectedNonGenericResults = results.filter((r) =>\n detectedNonGeneric.some((a) => a.name === r.agent),\n );\n const allDetectedNonGenericFailed =\n detectedNonGeneric.length > 0 &&\n !detectedNonGenericResults.some((r) => r.success);\n\n if (allDetectedNonGenericFailed) {\n messages.push(\n \"\",\n \"All detected agent registrations failed. Check errors above.\",\n );\n return { exitCode: 1, results, messages };\n }\n\n if (!anySuccess && results.length > 0) {\n messages.push(\n \"\",\n \"All agent registrations failed. Check errors above.\",\n );\n return { exitCode: 1, results, messages };\n }\n\n if (anySuccess) {\n messages.push(\"\", \"MCP registration complete.\");\n }\n\n return { exitCode: 0, results, messages };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,kBAAkB;AACvC,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,iBAAiB;AAoB1B,IAAM,gBAAgB,UAAU,UAAU;AAoD1C,eAAsB,eACpB,OACA,QACkB;AAClB,MAAI,CAAC,MAAM,cAAc;AACvB,WAAO;AAAA,EACT;AAMA,MAAI,MAAM,SAAS,WAAW,CAAC,aAAa,MAAM,GAAG;AACnD,WAAO;AAAA,EACT;AAEA,MAAI;AACF,YAAQ,MAAM,MAAM;AAAA,MAClB,KAAK,UAAU;AACb,cAAM,UAAU,KAAK,UAAU;AAAA,UAC7B,MAAM;AAAA,UACN,KAAK;AAAA,UACL,SAAS,EAAE,eAAe,UAAU,MAAM,GAAG;AAAA,QAC/C,CAAC;AACD,cAAM,cAAc,UAAU;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,MAEA,KAAK,SAAS;AACZ,cAAM,cAAc,SAAS;AAAA,UAC3B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AAED,cAAM,aAAa,MAAM;AACzB,YAAI,eAAe,QAAW,cAAW,UAAU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AAC,aAAa,oBAAoB,yBAAyB,oBAAoB;AAAA,IAC/E;AAAA,EACF;AAMA,QAAM,aAAa,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO;AAEhD,MAAI,YAAY;AACd,UAAM,eAAe,aAAa;AAAA,MAChC,kBAAkB,SAAS,UAAU;AAAA,MACrC,gBAAgB,oBAAoB,SAAS,UAAU,GAAG;AAAA,IAC5D,CAAC;AAAA,EACH;AAGA,WAAS,KAAK,IAAI,2BAA2B;AAC7C,aAAW,UAAU,SAAS;AAC5B,UAAM,OAAO,OAAO,UAAU,MAAM;AACpC,aAAS,KAAK,MAAM,IAAI,KAAK,OAAO,OAAO,EAAE;AAAA,EAC/C;AAEA,MAAI,QAAQ,WAAW,GAAG;AACxB,aAAS;AAAA,MACP;AAAA,IACF;AAAA,EACF;AASA,QAAM,4BAA4B,QAAQ;AAAA,IAAO,CAAC,MAChD,mBAAmB,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK;AAAA,EACnD;AACA,QAAM,8BACJ,mBAAmB,SAAS,KAC5B,CAAC,0BAA0B,KAAK,CAAC,MAAM,EAAE,OAAO;AAElD,MAAI,6BAA6B;AAC/B,aAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AACA,WAAO,EAAE,UAAU,GAAG,SAAS,SAAS;AAAA,EAC1C;AAEA,MAAI,CAAC,cAAc,QAAQ,SAAS,GAAG;AACrC,aAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AACA,WAAO,EAAE,UAAU,GAAG,SAAS,SAAS;AAAA,EAC1C;AAEA,MAAI,YAAY;AACd,aAAS,KAAK,IAAI,4BAA4B;AAAA,EAChD;AAEA,SAAO,EAAE,UAAU,GAAG,SAAS,SAAS;AAC1C;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/status.ts","../../src/cli/constants.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { NEXT_CONFIG_NAMES } from \"./constants.js\";\n\n/**\n * JSON-based MCP config files that init may create.\n * Includes .glasstrace/mcp.json (CI/generic fallback) in addition to the\n * agent-specific files that uninit.ts handles.\n */\nconst MCP_JSON_FILES = [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".glasstrace/mcp.json\"] as const;\n\n/**\n * TOML-based MCP config files (Codex uses this format).\n */\nconst MCP_TOML_FILES = [\".codex/config.toml\"] as const;\n\n/**\n * Agent info files that may contain glasstrace marker sections.\n */\nconst AGENT_INFO_FILES = [\n \"CLAUDE.md\",\n \"codex.md\",\n \".cursorrules\",\n] as const;\n\n/**\n * Instrumentation file names in priority order.\n */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n] as const;\n\n/**\n * Machine-readable SDK configuration state.\n * This interface is the public contract for AI agents — fields may be added\n * but never removed or renamed without a major version bump.\n */\n/** Runtime state snapshot read from .glasstrace/runtime-state.json. */\nexport interface RuntimeStateSnapshot {\n /** Whether the runtime state file exists and was readable. */\n available: boolean;\n /** Whether the process that wrote the state is likely still running. */\n stale: boolean;\n /** Core lifecycle state (e.g., \"ACTIVE\", \"KEY_PENDING\", \"SHUTDOWN\"). */\n coreState: string | null;\n /** Auth lifecycle state (e.g., \"ANONYMOUS\", \"AUTHENTICATED\"). */\n authState: string | null;\n /** OTel coexistence state (e.g., \"OWNS_PROVIDER\", \"AUTO_ATTACHED\"). */\n otelState: string | null;\n /** OTel scenario (e.g., \"A\", \"B-auto\"). */\n otelScenario: string | null;\n /** When the state was last written. */\n updatedAt: string | null;\n /** PID of the process that wrote the state. */\n pid: number | null;\n}\n\nexport interface StatusResult {\n /** Whether @glasstrace/sdk is in package.json dependencies or devDependencies. */\n installed: boolean;\n /** Whether the .glasstrace/ directory exists. */\n initialized: boolean;\n /** Whether an instrumentation file exists with registerGlasstrace(). */\n instrumentation: boolean;\n /** Whether next.config is wrapped with withGlasstraceConfig(). */\n configWrapped: boolean;\n /** Whether .glasstrace/anon_key exists. */\n anonKey: boolean;\n /** Whether any MCP config file has a glasstrace server entry. */\n mcpConfigured: boolean;\n /** Which agent info files have glasstrace marker sections. */\n agents: string[];\n /** Runtime state from the running SDK process (if available). */\n runtime: RuntimeStateSnapshot;\n}\n\n/**\n * Options for the status command.\n */\nexport interface StatusOptions {\n projectRoot: string;\n}\n\n/**\n * Checks SDK configuration state by reading filesystem markers.\n * This function is read-only — it never modifies files or creates directories.\n */\nexport function runStatus(options: StatusOptions): StatusResult {\n const root = options.projectRoot;\n\n return {\n installed: checkInstalled(root),\n initialized: checkInitialized(root),\n instrumentation: checkInstrumentation(root),\n configWrapped: checkConfigWrapped(root),\n anonKey: checkAnonKey(root),\n mcpConfigured: checkMcpConfigured(root),\n agents: checkAgents(root),\n runtime: readRuntimeState(root),\n };\n}\n\nfunction checkInstalled(root: string): boolean {\n try {\n const pkgPath = path.join(root, \"package.json\");\n const content = fs.readFileSync(pkgPath, \"utf-8\");\n const pkg = JSON.parse(content) as Record<string, unknown>;\n const deps = pkg[\"dependencies\"] as Record<string, unknown> | undefined;\n const devDeps = pkg[\"devDependencies\"] as Record<string, unknown> | undefined;\n return (\n (deps != null && \"@glasstrace/sdk\" in deps) ||\n (devDeps != null && \"@glasstrace/sdk\" in devDeps)\n );\n } catch {\n return false;\n }\n}\n\nfunction checkInitialized(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\")).isDirectory();\n } catch {\n return false;\n }\n}\n\nfunction checkInstrumentation(root: string): boolean {\n for (const name of INSTRUMENTATION_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"registerGlasstrace\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkConfigWrapped(root: string): boolean {\n for (const name of NEXT_CONFIG_NAMES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"withGlasstraceConfig\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkAnonKey(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\", \"anon_key\")).isFile();\n } catch {\n return false;\n }\n}\n\nfunction checkMcpConfigured(root: string): boolean {\n // Check JSON-based MCP config files\n for (const name of MCP_JSON_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n const mcpServers = parsed[\"mcpServers\"] as Record<string, unknown> | undefined;\n if (mcpServers && typeof mcpServers === \"object\" && \"glasstrace\" in mcpServers) {\n return true;\n }\n } catch {\n // File doesn't exist, is unreadable, or has invalid JSON — try next\n }\n }\n\n // Check TOML-based MCP config files (Codex)\n for (const name of MCP_TOML_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"[mcp_servers.glasstrace]\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n\n return false;\n}\n\nfunction checkAgents(root: string): string[] {\n const found: string[] = [];\n for (const name of AGENT_INFO_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const hasHtmlMarkers =\n content.includes(\"<!-- glasstrace:mcp:start -->\") &&\n content.includes(\"<!-- glasstrace:mcp:end -->\");\n const hasHashMarkers =\n content.includes(\"# glasstrace:mcp:start\") &&\n content.includes(\"# glasstrace:mcp:end\");\n if (hasHtmlMarkers || hasHashMarkers) {\n found.push(name);\n }\n } catch {\n // File doesn't exist or is unreadable — skip\n }\n }\n return found;\n}\n\nconst STALE_THRESHOLD_MS = 30_000; // 30 seconds\n\nfunction readRuntimeState(root: string): RuntimeStateSnapshot {\n const empty: RuntimeStateSnapshot = {\n available: false,\n stale: false,\n coreState: null,\n authState: null,\n otelState: null,\n otelScenario: null,\n updatedAt: null,\n pid: null,\n };\n\n try {\n const filePath = path.join(root, \".glasstrace\", \"runtime-state.json\");\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n\n const updatedAt = typeof parsed.updatedAt === \"string\" ? parsed.updatedAt : null;\n const pid = typeof parsed.pid === \"number\" ? parsed.pid : null;\n const core = parsed.core as Record<string, unknown> | undefined;\n const auth = parsed.auth as Record<string, unknown> | undefined;\n const otel = parsed.otel as Record<string, unknown> | undefined;\n\n const coreState = typeof core?.state === \"string\" ? core.state : null;\n const authState = typeof auth?.state === \"string\" ? auth.state : null;\n const otelState = typeof otel?.state === \"string\" ? otel.state : null;\n const otelScenario = typeof otel?.scenario === \"string\" ? otel.scenario : null;\n\n // Staleness detection\n let stale = false;\n if (coreState === \"SHUTDOWN\") {\n stale = false; // Clean shutdown — not stale, just finished\n } else if (updatedAt) {\n const updatedMs = new Date(updatedAt).getTime();\n const age = Number.isFinite(updatedMs) ? Date.now() - updatedMs : Infinity;\n if (age > STALE_THRESHOLD_MS) {\n // Check if the process is still running\n if (pid && pid > 0) {\n try {\n process.kill(pid, 0); // Signal 0 = existence check\n // If we get here, process exists. EPERM would also throw,\n // but with code \"EPERM\" — meaning the process exists but\n // we lack permission. Both mean \"not stale.\"\n stale = false;\n } catch (err: unknown) {\n const code = (err as { code?: string })?.code;\n if (code === \"EPERM\") {\n stale = false; // Process exists, we just can't signal it\n } else {\n stale = true; // ESRCH or other — process gone\n }\n }\n } else {\n stale = true; // No valid PID — can't verify\n }\n }\n }\n\n return {\n available: true,\n stale,\n coreState,\n authState,\n otelState,\n otelScenario,\n updatedAt,\n pid,\n };\n } catch {\n return empty;\n }\n}\n","import type { DetectedAgent } from \"../agent-detection/detect.js\";\n\n// MCP_ENDPOINT moved to `../mcp-runtime.ts` so the runtime claim-refresh\n// path can reach it without crossing the runtime/CLI boundary.\n//\n// TODO(remove-after-next-stable-release): drop this re-export once\n// internal CLI callers migrate to `../mcp-runtime.js`.\nexport { MCP_ENDPOINT } from \"../mcp-runtime.js\";\n\n/** Next.js config file names in priority order. */\nexport const NEXT_CONFIG_NAMES = [\"next.config.ts\", \"next.config.js\", \"next.config.mjs\"] as const;\n\n/** Maps internal agent name to a human-readable display name. */\nexport function formatAgentName(name: DetectedAgent[\"name\"]): string {\n const displayNames: Record<DetectedAgent[\"name\"], string> = {\n claude: \"Claude Code\",\n codex: \"Codex\",\n gemini: \"Gemini\",\n cursor: \"Cursor\",\n windsurf: \"Windsurf\",\n generic: \"Generic\",\n };\n return displayNames[name];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;;;ACSf,IAAM,oBAAoB,CAAC,kBAAkB,kBAAkB,iBAAiB;;;ADDvF,IAAM,iBAAiB,CAAC,aAAa,oBAAoB,yBAAyB,sBAAsB;AAKxG,IAAM,iBAAiB,CAAC,oBAAoB;AAK5C,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAyDO,SAAS,UAAU,SAAsC;AAC9D,QAAM,OAAO,QAAQ;AAErB,SAAO;AAAA,IACL,WAAW,eAAe,IAAI;AAAA,IAC9B,aAAa,iBAAiB,IAAI;AAAA,IAClC,iBAAiB,qBAAqB,IAAI;AAAA,IAC1C,eAAe,mBAAmB,IAAI;AAAA,IACtC,SAAS,aAAa,IAAI;AAAA,IAC1B,eAAe,mBAAmB,IAAI;AAAA,IACtC,QAAQ,YAAY,IAAI;AAAA,IACxB,SAAS,iBAAiB,IAAI;AAAA,EAChC;AACF;AAEA,SAAS,eAAe,MAAuB;AAC7C,MAAI;AACF,UAAM,UAAe,UAAK,MAAM,cAAc;AAC9C,UAAM,UAAa,gBAAa,SAAS,OAAO;AAChD,UAAM,MAAM,KAAK,MAAM,OAAO;AAC9B,UAAM,OAAO,IAA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UAAU,WAAW,KAAK,QAAQ;AACjE,UAAM,YAAY,OAAO,MAAM,UAAU,WAAW,KAAK,QAAQ;AACjE,UAAM,eAAe,OAAO,MAAM,aAAa,WAAW,KAAK,WAAW;AAG1E,QAAI,QAAQ;AACZ,QAAI,cAAc,YAAY;AAC5B,cAAQ;AAAA,IACV,WAAW,WAAW;AACpB,YAAM,YAAY,IAAI,KAAK,SAAS,EAAE,QAAQ;AAC9C,YAAM,MAAM,OAAO,SAAS,SAAS,IAAI,KAAK,IAAI,IAAI,YAAY;AAClE,UAAI,MAAM,oBAAoB;AAE5B,YAAI,OAAO,MAAM,GAAG;AAClB,cAAI;AACF,oBAAQ,KAAK,KAAK,CAAC;AAInB,oBAAQ;AAAA,UACV,SAAS,KAAc;AACrB,kBAAM,OAAQ,KAA2B;AACzC,gBAAI,SAAS,SAAS;AACpB,sBAAQ;AAAA,YACV,OAAO;AACL,sBAAQ;AAAA,YACV;AAAA,UACF;AAAA,QACF,OAAO;AACL,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/cli/status.ts","../../src/cli/constants.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { NEXT_CONFIG_NAMES } from \"./constants.js\";\n\n/**\n * JSON-based MCP config files that init may create.\n * Includes .glasstrace/mcp.json (CI/generic fallback) in addition to the\n * agent-specific files that uninit.ts handles.\n */\nconst MCP_JSON_FILES = [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".glasstrace/mcp.json\"] as const;\n\n/**\n * TOML-based MCP config files (Codex uses this format).\n */\nconst MCP_TOML_FILES = [\".codex/config.toml\"] as const;\n\n/**\n * Agent info files that may contain glasstrace marker sections.\n */\nconst AGENT_INFO_FILES = [\n \"CLAUDE.md\",\n \"codex.md\",\n \".cursorrules\",\n] as const;\n\n/**\n * Instrumentation file names in priority order.\n */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n] as const;\n\n/**\n * Machine-readable SDK configuration state.\n * This interface is the public contract for AI agents — fields may be added\n * but never removed or renamed without a major version bump.\n */\n/** Runtime state snapshot read from .glasstrace/runtime-state.json. */\nexport interface RuntimeStateSnapshot {\n /** Whether the runtime state file exists and was readable. */\n available: boolean;\n /** Whether the process that wrote the state is likely still running. */\n stale: boolean;\n /** Core lifecycle state (e.g., \"ACTIVE\", \"KEY_PENDING\", \"SHUTDOWN\"). */\n coreState: string | null;\n /** Auth lifecycle state (e.g., \"ANONYMOUS\", \"AUTHENTICATED\"). */\n authState: string | null;\n /** OTel coexistence state (e.g., \"OWNS_PROVIDER\", \"AUTO_ATTACHED\"). */\n otelState: string | null;\n /** OTel scenario (e.g., \"A\", \"B-auto\"). */\n otelScenario: string | null;\n /** When the state was last written. */\n updatedAt: string | null;\n /** PID of the process that wrote the state. */\n pid: number | null;\n}\n\nexport interface StatusResult {\n /** Whether @glasstrace/sdk is in package.json dependencies or devDependencies. */\n installed: boolean;\n /** Whether the .glasstrace/ directory exists. */\n initialized: boolean;\n /** Whether an instrumentation file exists with registerGlasstrace(). */\n instrumentation: boolean;\n /** Whether next.config is wrapped with withGlasstraceConfig(). */\n configWrapped: boolean;\n /** Whether .glasstrace/anon_key exists. */\n anonKey: boolean;\n /** Whether any MCP config file has a glasstrace server entry. */\n mcpConfigured: boolean;\n /** Which agent info files have glasstrace marker sections. */\n agents: string[];\n /** Runtime state from the running SDK process (if available). */\n runtime: RuntimeStateSnapshot;\n}\n\n/**\n * Options for the status command.\n */\nexport interface StatusOptions {\n projectRoot: string;\n}\n\n/**\n * Checks SDK configuration state by reading filesystem markers.\n * This function is read-only — it never modifies files or creates directories.\n */\nexport function runStatus(options: StatusOptions): StatusResult {\n const root = options.projectRoot;\n\n return {\n installed: checkInstalled(root),\n initialized: checkInitialized(root),\n instrumentation: checkInstrumentation(root),\n configWrapped: checkConfigWrapped(root),\n anonKey: checkAnonKey(root),\n mcpConfigured: checkMcpConfigured(root),\n agents: checkAgents(root),\n runtime: readRuntimeState(root),\n };\n}\n\nfunction checkInstalled(root: string): boolean {\n try {\n const pkgPath = path.join(root, \"package.json\");\n const content = fs.readFileSync(pkgPath, \"utf-8\");\n const pkg = JSON.parse(content) as Record<string, unknown>;\n const deps = pkg[\"dependencies\"] as Record<string, unknown> | undefined;\n const devDeps = pkg[\"devDependencies\"] as Record<string, unknown> | undefined;\n return (\n (deps != null && \"@glasstrace/sdk\" in deps) ||\n (devDeps != null && \"@glasstrace/sdk\" in devDeps)\n );\n } catch {\n return false;\n }\n}\n\nfunction checkInitialized(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\")).isDirectory();\n } catch {\n return false;\n }\n}\n\nfunction checkInstrumentation(root: string): boolean {\n for (const name of INSTRUMENTATION_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"registerGlasstrace\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkConfigWrapped(root: string): boolean {\n for (const name of NEXT_CONFIG_NAMES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"withGlasstraceConfig\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkAnonKey(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\", \"anon_key\")).isFile();\n } catch {\n return false;\n }\n}\n\nfunction checkMcpConfigured(root: string): boolean {\n // Check JSON-based MCP config files\n for (const name of MCP_JSON_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n const mcpServers = parsed[\"mcpServers\"] as Record<string, unknown> | undefined;\n if (mcpServers && typeof mcpServers === \"object\" && \"glasstrace\" in mcpServers) {\n return true;\n }\n } catch {\n // File doesn't exist, is unreadable, or has invalid JSON — try next\n }\n }\n\n // Check TOML-based MCP config files (Codex)\n for (const name of MCP_TOML_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"[mcp_servers.glasstrace]\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n\n return false;\n}\n\nfunction checkAgents(root: string): string[] {\n const found: string[] = [];\n for (const name of AGENT_INFO_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const hasHtmlMarkers =\n content.includes(\"<!-- glasstrace:mcp:start -->\") &&\n content.includes(\"<!-- glasstrace:mcp:end -->\");\n const hasHashMarkers =\n content.includes(\"# glasstrace:mcp:start\") &&\n content.includes(\"# glasstrace:mcp:end\");\n if (hasHtmlMarkers || hasHashMarkers) {\n found.push(name);\n }\n } catch {\n // File doesn't exist or is unreadable — skip\n }\n }\n return found;\n}\n\nconst STALE_THRESHOLD_MS = 30_000; // 30 seconds\n\nfunction readRuntimeState(root: string): RuntimeStateSnapshot {\n const empty: RuntimeStateSnapshot = {\n available: false,\n stale: false,\n coreState: null,\n authState: null,\n otelState: null,\n otelScenario: null,\n updatedAt: null,\n pid: null,\n };\n\n try {\n const filePath = path.join(root, \".glasstrace\", \"runtime-state.json\");\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n\n const updatedAt = typeof parsed.updatedAt === \"string\" ? parsed.updatedAt : null;\n const pid = typeof parsed.pid === \"number\" ? parsed.pid : null;\n const core = parsed.core as Record<string, unknown> | undefined;\n const auth = parsed.auth as Record<string, unknown> | undefined;\n const otel = parsed.otel as Record<string, unknown> | undefined;\n\n const coreState = typeof core?.state === \"string\" ? core.state : null;\n const authState = typeof auth?.state === \"string\" ? auth.state : null;\n const otelState = typeof otel?.state === \"string\" ? otel.state : null;\n const otelScenario = typeof otel?.scenario === \"string\" ? otel.scenario : null;\n\n // Staleness detection\n let stale = false;\n if (coreState === \"SHUTDOWN\") {\n stale = false; // Clean shutdown — not stale, just finished\n } else if (updatedAt) {\n const updatedMs = new Date(updatedAt).getTime();\n const age = Number.isFinite(updatedMs) ? Date.now() - updatedMs : Infinity;\n if (age > STALE_THRESHOLD_MS) {\n // Check if the process is still running\n if (pid && pid > 0) {\n try {\n process.kill(pid, 0); // Signal 0 = existence check\n // If we get here, process exists. EPERM would also throw,\n // but with code \"EPERM\" — meaning the process exists but\n // we lack permission. Both mean \"not stale.\"\n stale = false;\n } catch (err: unknown) {\n const code = (err as { code?: string })?.code;\n if (code === \"EPERM\") {\n stale = false; // Process exists, we just can't signal it\n } else {\n stale = true; // ESRCH or other — process gone\n }\n }\n } else {\n stale = true; // No valid PID — can't verify\n }\n }\n }\n\n return {\n available: true,\n stale,\n coreState,\n authState,\n otelState,\n otelScenario,\n updatedAt,\n pid,\n };\n } catch {\n return empty;\n }\n}\n","import type { DetectedAgent } from \"../agent-detection/detect.js\";\n\n/** Next.js config file names in priority order. */\nexport const NEXT_CONFIG_NAMES = [\"next.config.ts\", \"next.config.js\", \"next.config.mjs\"] as const;\n\n/** Maps internal agent name to a human-readable display name. */\nexport function formatAgentName(name: DetectedAgent[\"name\"]): string {\n const displayNames: Record<DetectedAgent[\"name\"], string> = {\n claude: \"Claude Code\",\n codex: \"Codex\",\n gemini: \"Gemini\",\n cursor: \"Cursor\",\n windsurf: \"Windsurf\",\n generic: \"Generic helper\",\n };\n return displayNames[name];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;;;ACEf,IAAM,oBAAoB,CAAC,kBAAkB,kBAAk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SAAS,KAAc;AACrB,kBAAM,OAAQ,KAA2B;AACzC,gBAAI,SAAS,SAAS;AACpB,sBAAQ;AAAA,YACV,OAAO;AACL,sBAAQ;AAAA,YACV;AAAA,UACF;AAAA,QACF,OAAO;AACL,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  NEXT_CONFIG_NAMES
3
- } from "../chunk-7SZQN6IU.js";
4
- import "../chunk-P22UQ2OJ.js";
5
- import "../chunk-X5MAXP5T.js";
3
+ } from "../chunk-NB7GJE4S.js";
6
4
  import "../chunk-NSBPE2FW.js";
7
5
 
8
6
  // src/cli/status.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/status.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { NEXT_CONFIG_NAMES } from \"./constants.js\";\n\n/**\n * JSON-based MCP config files that init may create.\n * Includes .glasstrace/mcp.json (CI/generic fallback) in addition to the\n * agent-specific files that uninit.ts handles.\n */\nconst MCP_JSON_FILES = [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".glasstrace/mcp.json\"] as const;\n\n/**\n * TOML-based MCP config files (Codex uses this format).\n */\nconst MCP_TOML_FILES = [\".codex/config.toml\"] as const;\n\n/**\n * Agent info files that may contain glasstrace marker sections.\n */\nconst AGENT_INFO_FILES = [\n \"CLAUDE.md\",\n \"codex.md\",\n \".cursorrules\",\n] as const;\n\n/**\n * Instrumentation file names in priority order.\n */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n] as const;\n\n/**\n * Machine-readable SDK configuration state.\n * This interface is the public contract for AI agents — fields may be added\n * but never removed or renamed without a major version bump.\n */\n/** Runtime state snapshot read from .glasstrace/runtime-state.json. */\nexport interface RuntimeStateSnapshot {\n /** Whether the runtime state file exists and was readable. */\n available: boolean;\n /** Whether the process that wrote the state is likely still running. */\n stale: boolean;\n /** Core lifecycle state (e.g., \"ACTIVE\", \"KEY_PENDING\", \"SHUTDOWN\"). */\n coreState: string | null;\n /** Auth lifecycle state (e.g., \"ANONYMOUS\", \"AUTHENTICATED\"). */\n authState: string | null;\n /** OTel coexistence state (e.g., \"OWNS_PROVIDER\", \"AUTO_ATTACHED\"). */\n otelState: string | null;\n /** OTel scenario (e.g., \"A\", \"B-auto\"). */\n otelScenario: string | null;\n /** When the state was last written. */\n updatedAt: string | null;\n /** PID of the process that wrote the state. */\n pid: number | null;\n}\n\nexport interface StatusResult {\n /** Whether @glasstrace/sdk is in package.json dependencies or devDependencies. */\n installed: boolean;\n /** Whether the .glasstrace/ directory exists. */\n initialized: boolean;\n /** Whether an instrumentation file exists with registerGlasstrace(). */\n instrumentation: boolean;\n /** Whether next.config is wrapped with withGlasstraceConfig(). */\n configWrapped: boolean;\n /** Whether .glasstrace/anon_key exists. */\n anonKey: boolean;\n /** Whether any MCP config file has a glasstrace server entry. */\n mcpConfigured: boolean;\n /** Which agent info files have glasstrace marker sections. */\n agents: string[];\n /** Runtime state from the running SDK process (if available). */\n runtime: RuntimeStateSnapshot;\n}\n\n/**\n * Options for the status command.\n */\nexport interface StatusOptions {\n projectRoot: string;\n}\n\n/**\n * Checks SDK configuration state by reading filesystem markers.\n * This function is read-only — it never modifies files or creates directories.\n */\nexport function runStatus(options: StatusOptions): StatusResult {\n const root = options.projectRoot;\n\n return {\n installed: checkInstalled(root),\n initialized: checkInitialized(root),\n instrumentation: checkInstrumentation(root),\n configWrapped: checkConfigWrapped(root),\n anonKey: checkAnonKey(root),\n mcpConfigured: checkMcpConfigured(root),\n agents: checkAgents(root),\n runtime: readRuntimeState(root),\n };\n}\n\nfunction checkInstalled(root: string): boolean {\n try {\n const pkgPath = path.join(root, \"package.json\");\n const content = fs.readFileSync(pkgPath, \"utf-8\");\n const pkg = JSON.parse(content) as Record<string, unknown>;\n const deps = pkg[\"dependencies\"] as Record<string, unknown> | undefined;\n const devDeps = pkg[\"devDependencies\"] as Record<string, unknown> | undefined;\n return (\n (deps != null && \"@glasstrace/sdk\" in deps) ||\n (devDeps != null && \"@glasstrace/sdk\" in devDeps)\n );\n } catch {\n return false;\n }\n}\n\nfunction checkInitialized(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\")).isDirectory();\n } catch {\n return false;\n }\n}\n\nfunction checkInstrumentation(root: string): boolean {\n for (const name of INSTRUMENTATION_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"registerGlasstrace\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkConfigWrapped(root: string): boolean {\n for (const name of NEXT_CONFIG_NAMES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"withGlasstraceConfig\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkAnonKey(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\", \"anon_key\")).isFile();\n } catch {\n return false;\n }\n}\n\nfunction checkMcpConfigured(root: string): boolean {\n // Check JSON-based MCP config files\n for (const name of MCP_JSON_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n const mcpServers = parsed[\"mcpServers\"] as Record<string, unknown> | undefined;\n if (mcpServers && typeof mcpServers === \"object\" && \"glasstrace\" in mcpServers) {\n return true;\n }\n } catch {\n // File doesn't exist, is unreadable, or has invalid JSON — try next\n }\n }\n\n // Check TOML-based MCP config files (Codex)\n for (const name of MCP_TOML_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"[mcp_servers.glasstrace]\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n\n return false;\n}\n\nfunction checkAgents(root: string): string[] {\n const found: string[] = [];\n for (const name of AGENT_INFO_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const hasHtmlMarkers =\n content.includes(\"<!-- glasstrace:mcp:start -->\") &&\n content.includes(\"<!-- glasstrace:mcp:end -->\");\n const hasHashMarkers =\n content.includes(\"# glasstrace:mcp:start\") &&\n content.includes(\"# glasstrace:mcp:end\");\n if (hasHtmlMarkers || hasHashMarkers) {\n found.push(name);\n }\n } catch {\n // File doesn't exist or is unreadable — skip\n }\n }\n return found;\n}\n\nconst STALE_THRESHOLD_MS = 30_000; // 30 seconds\n\nfunction readRuntimeState(root: string): RuntimeStateSnapshot {\n const empty: RuntimeStateSnapshot = {\n available: false,\n stale: false,\n coreState: null,\n authState: null,\n otelState: null,\n otelScenario: null,\n updatedAt: null,\n pid: null,\n };\n\n try {\n const filePath = path.join(root, \".glasstrace\", \"runtime-state.json\");\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n\n const updatedAt = typeof parsed.updatedAt === \"string\" ? parsed.updatedAt : null;\n const pid = typeof parsed.pid === \"number\" ? parsed.pid : null;\n const core = parsed.core as Record<string, unknown> | undefined;\n const auth = parsed.auth as Record<string, unknown> | undefined;\n const otel = parsed.otel as Record<string, unknown> | undefined;\n\n const coreState = typeof core?.state === \"string\" ? core.state : null;\n const authState = typeof auth?.state === \"string\" ? auth.state : null;\n const otelState = typeof otel?.state === \"string\" ? otel.state : null;\n const otelScenario = typeof otel?.scenario === \"string\" ? otel.scenario : null;\n\n // Staleness detection\n let stale = false;\n if (coreState === \"SHUTDOWN\") {\n stale = false; // Clean shutdown — not stale, just finished\n } else if (updatedAt) {\n const updatedMs = new Date(updatedAt).getTime();\n const age = Number.isFinite(updatedMs) ? Date.now() - updatedMs : Infinity;\n if (age > STALE_THRESHOLD_MS) {\n // Check if the process is still running\n if (pid && pid > 0) {\n try {\n process.kill(pid, 0); // Signal 0 = existence check\n // If we get here, process exists. EPERM would also throw,\n // but with code \"EPERM\" — meaning the process exists but\n // we lack permission. Both mean \"not stale.\"\n stale = false;\n } catch (err: unknown) {\n const code = (err as { code?: string })?.code;\n if (code === \"EPERM\") {\n stale = false; // Process exists, we just can't signal it\n } else {\n stale = true; // ESRCH or other — process gone\n }\n }\n } else {\n stale = true; // No valid PID — can't verify\n }\n }\n }\n\n return {\n available: true,\n stale,\n coreState,\n authState,\n otelState,\n otelScenario,\n updatedAt,\n pid,\n };\n } catch {\n return empty;\n }\n}\n"],"mappings":";;;;;;;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;AAQtB,IAAM,iBAAiB,CAAC,aAAa,oBAAoB,yBAAyB,sBAAsB;AAKxG,IAAM,iBAAiB,CAAC,oBAAoB;AAK5C,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAyDO,SAAS,UAAU,SAAsC;AAC9D,QAAM,OAAO,QAAQ;AAErB,SAAO;AAAA,IACL,WAAW,eAAe,IAAI;AAAA,IAC9B,aAAa,iBAAiB,IAAI;AAAA,IAClC,iBAAiB,qBAAqB,IAAI;AAAA,IAC1C,eAAe,mBAAmB,IAAI;AAAA,IACtC,SAAS,aAAa,IAAI;AAAA,IAC1B,eAAe,mBAAmB,IAAI;AAAA,IACtC,QAAQ,YAAY,IAAI;AAAA,IACxB,SAAS,iBAAiB,IAAI;AAAA,EAChC;AACF;AAEA,SAAS,eAAe,MAAuB;AAC7C,MAAI;AACF,UAAM,UAAe,UAAK,MAAM,cAAc;AAC9C,UAAM,UAA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,UAAM,YAAY,OAAO,MAAM,UAAU,WAAW,KAAK,QAAQ;AACjE,UAAM,YAAY,OAAO,MAAM,UAAU,WAAW,KAAK,QAAQ;AACjE,UAAM,YAAY,OAAO,MAAM,UAAU,WAAW,KAAK,QAAQ;AACjE,UAAM,eAAe,OAAO,MAAM,aAAa,WAAW,KAAK,WAAW;AAG1E,QAAI,QAAQ;AACZ,QAAI,cAAc,YAAY;AAC5B,cAAQ;AAAA,IACV,WAAW,WAAW;AACpB,YAAM,YAAY,IAAI,KAAK,SAAS,EAAE,QAAQ;AAC9C,YAAM,MAAM,OAAO,SAAS,SAAS,IAAI,KAAK,IAAI,IAAI,YAAY;AAClE,UAAI,MAAM,oBAAoB;AAE5B,YAAI,OAAO,MAAM,GAAG;AAClB,cAAI;AACF,oBAAQ,KAAK,KAAK,CAAC;AAInB,oBAAQ;AAAA,UACV,SAAS,KAAc;AACrB,kBAAM,OAAQ,KAA2B;AACzC,gBAAI,SAAS,SAAS;AACpB,sBAAQ;AAAA,YACV,OAAO;AACL,sBAAQ;AAAA,YACV;AAAA,UACF;AAAA,QACF,OAAO;AACL,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/cli/status.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { NEXT_CONFIG_NAMES } from \"./constants.js\";\n\n/**\n * JSON-based MCP config files that init may create.\n * Includes .glasstrace/mcp.json (CI/generic fallback) in addition to the\n * agent-specific files that uninit.ts handles.\n */\nconst MCP_JSON_FILES = [\".mcp.json\", \".cursor/mcp.json\", \".gemini/settings.json\", \".glasstrace/mcp.json\"] as const;\n\n/**\n * TOML-based MCP config files (Codex uses this format).\n */\nconst MCP_TOML_FILES = [\".codex/config.toml\"] as const;\n\n/**\n * Agent info files that may contain glasstrace marker sections.\n */\nconst AGENT_INFO_FILES = [\n \"CLAUDE.md\",\n \"codex.md\",\n \".cursorrules\",\n] as const;\n\n/**\n * Instrumentation file names in priority order.\n */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n] as const;\n\n/**\n * Machine-readable SDK configuration state.\n * This interface is the public contract for AI agents — fields may be added\n * but never removed or renamed without a major version bump.\n */\n/** Runtime state snapshot read from .glasstrace/runtime-state.json. */\nexport interface RuntimeStateSnapshot {\n /** Whether the runtime state file exists and was readable. */\n available: boolean;\n /** Whether the process that wrote the state is likely still running. */\n stale: boolean;\n /** Core lifecycle state (e.g., \"ACTIVE\", \"KEY_PENDING\", \"SHUTDOWN\"). */\n coreState: string | null;\n /** Auth lifecycle state (e.g., \"ANONYMOUS\", \"AUTHENTICATED\"). */\n authState: string | null;\n /** OTel coexistence state (e.g., \"OWNS_PROVIDER\", \"AUTO_ATTACHED\"). */\n otelState: string | null;\n /** OTel scenario (e.g., \"A\", \"B-auto\"). */\n otelScenario: string | null;\n /** When the state was last written. */\n updatedAt: string | null;\n /** PID of the process that wrote the state. */\n pid: number | null;\n}\n\nexport interface StatusResult {\n /** Whether @glasstrace/sdk is in package.json dependencies or devDependencies. */\n installed: boolean;\n /** Whether the .glasstrace/ directory exists. */\n initialized: boolean;\n /** Whether an instrumentation file exists with registerGlasstrace(). */\n instrumentation: boolean;\n /** Whether next.config is wrapped with withGlasstraceConfig(). */\n configWrapped: boolean;\n /** Whether .glasstrace/anon_key exists. */\n anonKey: boolean;\n /** Whether any MCP config file has a glasstrace server entry. */\n mcpConfigured: boolean;\n /** Which agent info files have glasstrace marker sections. */\n agents: string[];\n /** Runtime state from the running SDK process (if available). */\n runtime: RuntimeStateSnapshot;\n}\n\n/**\n * Options for the status command.\n */\nexport interface StatusOptions {\n projectRoot: string;\n}\n\n/**\n * Checks SDK configuration state by reading filesystem markers.\n * This function is read-only — it never modifies files or creates directories.\n */\nexport function runStatus(options: StatusOptions): StatusResult {\n const root = options.projectRoot;\n\n return {\n installed: checkInstalled(root),\n initialized: checkInitialized(root),\n instrumentation: checkInstrumentation(root),\n configWrapped: checkConfigWrapped(root),\n anonKey: checkAnonKey(root),\n mcpConfigured: checkMcpConfigured(root),\n agents: checkAgents(root),\n runtime: readRuntimeState(root),\n };\n}\n\nfunction checkInstalled(root: string): boolean {\n try {\n const pkgPath = path.join(root, \"package.json\");\n const content = fs.readFileSync(pkgPath, \"utf-8\");\n const pkg = JSON.parse(content) as Record<string, unknown>;\n const deps = pkg[\"dependencies\"] as Record<string, unknown> | undefined;\n const devDeps = pkg[\"devDependencies\"] as Record<string, unknown> | undefined;\n return (\n (deps != null && \"@glasstrace/sdk\" in deps) ||\n (devDeps != null && \"@glasstrace/sdk\" in devDeps)\n );\n } catch {\n return false;\n }\n}\n\nfunction checkInitialized(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\")).isDirectory();\n } catch {\n return false;\n }\n}\n\nfunction checkInstrumentation(root: string): boolean {\n for (const name of INSTRUMENTATION_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"registerGlasstrace\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkConfigWrapped(root: string): boolean {\n for (const name of NEXT_CONFIG_NAMES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"withGlasstraceConfig\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n return false;\n}\n\nfunction checkAnonKey(root: string): boolean {\n try {\n return fs.statSync(path.join(root, \".glasstrace\", \"anon_key\")).isFile();\n } catch {\n return false;\n }\n}\n\nfunction checkMcpConfigured(root: string): boolean {\n // Check JSON-based MCP config files\n for (const name of MCP_JSON_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n const mcpServers = parsed[\"mcpServers\"] as Record<string, unknown> | undefined;\n if (mcpServers && typeof mcpServers === \"object\" && \"glasstrace\" in mcpServers) {\n return true;\n }\n } catch {\n // File doesn't exist, is unreadable, or has invalid JSON — try next\n }\n }\n\n // Check TOML-based MCP config files (Codex)\n for (const name of MCP_TOML_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n if (content.includes(\"[mcp_servers.glasstrace]\")) {\n return true;\n }\n } catch {\n // File doesn't exist or is unreadable — try next\n }\n }\n\n return false;\n}\n\nfunction checkAgents(root: string): string[] {\n const found: string[] = [];\n for (const name of AGENT_INFO_FILES) {\n try {\n const content = fs.readFileSync(path.join(root, name), \"utf-8\");\n const hasHtmlMarkers =\n content.includes(\"<!-- glasstrace:mcp:start -->\") &&\n content.includes(\"<!-- glasstrace:mcp:end -->\");\n const hasHashMarkers =\n content.includes(\"# glasstrace:mcp:start\") &&\n content.includes(\"# glasstrace:mcp:end\");\n if (hasHtmlMarkers || hasHashMarkers) {\n found.push(name);\n }\n } catch {\n // File doesn't exist or is unreadable — skip\n }\n }\n return found;\n}\n\nconst STALE_THRESHOLD_MS = 30_000; // 30 seconds\n\nfunction readRuntimeState(root: string): RuntimeStateSnapshot {\n const empty: RuntimeStateSnapshot = {\n available: false,\n stale: false,\n coreState: null,\n authState: null,\n otelState: null,\n otelScenario: null,\n updatedAt: null,\n pid: null,\n };\n\n try {\n const filePath = path.join(root, \".glasstrace\", \"runtime-state.json\");\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = JSON.parse(content) as Record<string, unknown>;\n\n const updatedAt = typeof parsed.updatedAt === \"string\" ? parsed.updatedAt : null;\n const pid = typeof parsed.pid === \"number\" ? parsed.pid : null;\n const core = parsed.core as Record<string, unknown> | undefined;\n const auth = parsed.auth as Record<string, unknown> | undefined;\n const otel = parsed.otel as Record<string, unknown> | undefined;\n\n const coreState = typeof core?.state === \"string\" ? core.state : null;\n const authState = typeof auth?.state === \"string\" ? auth.state : null;\n const otelState = typeof otel?.state === \"string\" ? otel.state : null;\n const otelScenario = typeof otel?.scenario === \"string\" ? otel.scenario : null;\n\n // Staleness detection\n let stale = false;\n if (coreState === \"SHUTDOWN\") {\n stale = false; // Clean shutdown — not stale, just finished\n } else if (updatedAt) {\n const updatedMs = new Date(updatedAt).getTime();\n const age = Number.isFinite(updatedMs) ? Date.now() - updatedMs : Infinity;\n if (age > STALE_THRESHOLD_MS) {\n // Check if the process is still running\n if (pid && pid > 0) {\n try {\n process.kill(pid, 0); // Signal 0 = existence check\n // If we get here, process exists. EPERM would also throw,\n // but with code \"EPERM\" — meaning the process exists but\n // we lack permission. Both mean \"not stale.\"\n stale = false;\n } catch (err: unknown) {\n const code = (err as { code?: string })?.code;\n if (code === \"EPERM\") {\n stale = false; // Process exists, we just can't signal it\n } else {\n stale = true; // ESRCH or other — process gone\n }\n }\n } else {\n stale = true; // No valid PID — can't verify\n }\n }\n }\n\n return {\n available: true,\n stale,\n coreState,\n authState,\n otelState,\n otelScenario,\n updatedAt,\n pid,\n };\n } catch {\n return empty;\n }\n}\n"],"mappings":";;;;;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;AAQtB,IAAM,iBAAiB,CAAC,aAAa,oBAAoB,yBAAyB,sBAAsB;AAKxG,IAAM,iBAAiB,CAAC,oBAAoB;AAK5C,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAyDO,SAAS,UAAU,SAAsC;AAC9D,QAAM,OAAO,QAAQ;AAErB,SAAO;AAAA,IACL,WAAW,eAAe,IAAI;AAAA,IAC9B,aAAa,iBAAiB,IAAI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= __toESM(require("node:fs"), 1);
49
49
  var os = __toESM(require("node:os"), 1);
50
50
  var path2 = __toESM(require("node:path"), 1);
51
51
 
52
+ // src/cli/constants.ts
53
+ var NEXT_CONFIG_NAMES = ["next.config.ts", "next.config.js", "next.config.mjs"];
54
+
52
55
  // src/mcp-runtime.ts
53
56
  function readEnvLocalApiKey(content) {
54
57
  let last = null;
@@ -68,9 +71,6 @@ function isDevApiKey(value) {
68
71
  return value.trim().startsWith("gt_dev_");
69
72
  }
70
73
 
71
- // src/cli/constants.ts
72
- var NEXT_CONFIG_NAMES = ["next.config.ts", "next.config.js", "next.config.mjs"];
73
-
74
74
  // src/cli/discovery-file.ts
75
75
  var fs = __toESM(require("node:fs"), 1);
76
76
  var path = __toESM(require("node:path"), 1);