@glasstrace/sdk 1.1.0 → 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 (66) hide show
  1. package/README.md +78 -1
  2. package/dist/{chunk-55FBXXER.js → chunk-2M57EO6U.js} +2 -2
  3. package/dist/chunk-3LILTM3T.js +384 -0
  4. package/dist/chunk-3LILTM3T.js.map +1 -0
  5. package/dist/{chunk-KE7MCPO5.js → chunk-4EZ6JTDG.js} +2 -2
  6. package/dist/{chunk-67RIOAXV.js → chunk-6RNBUUBR.js} +2 -2
  7. package/dist/{chunk-DO2YPMQ5.js → chunk-C567H5EQ.js} +23 -5
  8. package/dist/chunk-C567H5EQ.js.map +1 -0
  9. package/dist/{chunk-UGJ3X4CT.js → chunk-DST4UBXU.js} +2 -2
  10. package/dist/{chunk-DXRZKKSO.js → chunk-NB7GJE4S.js} +2 -4
  11. package/dist/chunk-NB7GJE4S.js.map +1 -0
  12. package/dist/{chunk-HAU66QBQ.js → chunk-P4OYPFQ5.js} +9 -9
  13. package/dist/chunk-P4OYPFQ5.js.map +1 -0
  14. package/dist/{chunk-LU3PPAOQ.js → chunk-UJ2JC7PZ.js} +4 -4
  15. package/dist/chunk-UJ2JC7PZ.js.map +1 -0
  16. package/dist/{chunk-TQ54WLCZ.js → chunk-X5MAXP5T.js} +2 -1
  17. package/dist/{chunk-ZBTC5QIQ.js → chunk-Z35HKVSO.js} +137 -10
  18. package/dist/chunk-Z35HKVSO.js.map +1 -0
  19. package/dist/cli/init.cjs +1313 -1118
  20. package/dist/cli/init.cjs.map +1 -1
  21. package/dist/cli/init.js +456 -72
  22. package/dist/cli/init.js.map +1 -1
  23. package/dist/cli/mcp-add.cjs +257 -85
  24. package/dist/cli/mcp-add.cjs.map +1 -1
  25. package/dist/cli/mcp-add.d.cts +35 -4
  26. package/dist/cli/mcp-add.d.ts +35 -4
  27. package/dist/cli/mcp-add.js +61 -25
  28. package/dist/cli/mcp-add.js.map +1 -1
  29. package/dist/cli/status.cjs.map +1 -1
  30. package/dist/cli/status.js +1 -1
  31. package/dist/cli/uninit.cjs +1 -1
  32. package/dist/cli/uninit.cjs.map +1 -1
  33. package/dist/cli/uninit.js +4 -4
  34. package/dist/cli/validate.cjs +14162 -2
  35. package/dist/cli/validate.cjs.map +1 -1
  36. package/dist/cli/validate.d.cts +7 -3
  37. package/dist/cli/validate.d.ts +7 -3
  38. package/dist/cli/validate.js +25 -2
  39. package/dist/cli/validate.js.map +1 -1
  40. package/dist/edge-entry.js +2 -2
  41. package/dist/index.cjs +423 -12
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.js +5 -5
  44. package/dist/{monorepo-N5Z63XP7.js → monorepo-PFVNPQ6X.js} +3 -3
  45. package/dist/node-entry.cjs +423 -12
  46. package/dist/node-entry.cjs.map +1 -1
  47. package/dist/node-entry.js +7 -7
  48. package/dist/node-subpath.js +3 -3
  49. package/dist/{source-map-uploader-BJIXRLJ6.js → source-map-uploader-DPUUCLNW.js} +3 -3
  50. package/package.json +1 -1
  51. package/dist/chunk-DO2YPMQ5.js.map +0 -1
  52. package/dist/chunk-DXRZKKSO.js.map +0 -1
  53. package/dist/chunk-HAU66QBQ.js.map +0 -1
  54. package/dist/chunk-IP4NMDJK.js +0 -98
  55. package/dist/chunk-IP4NMDJK.js.map +0 -1
  56. package/dist/chunk-LU3PPAOQ.js.map +0 -1
  57. package/dist/chunk-O63DJKIJ.js +0 -460
  58. package/dist/chunk-O63DJKIJ.js.map +0 -1
  59. package/dist/chunk-ZBTC5QIQ.js.map +0 -1
  60. /package/dist/{chunk-55FBXXER.js.map → chunk-2M57EO6U.js.map} +0 -0
  61. /package/dist/{chunk-KE7MCPO5.js.map → chunk-4EZ6JTDG.js.map} +0 -0
  62. /package/dist/{chunk-67RIOAXV.js.map → chunk-6RNBUUBR.js.map} +0 -0
  63. /package/dist/{chunk-UGJ3X4CT.js.map → chunk-DST4UBXU.js.map} +0 -0
  64. /package/dist/{chunk-TQ54WLCZ.js.map → chunk-X5MAXP5T.js.map} +0 -0
  65. /package/dist/{monorepo-N5Z63XP7.js.map → monorepo-PFVNPQ6X.js.map} +0 -0
  66. /package/dist/{source-map-uploader-BJIXRLJ6.js.map → source-map-uploader-DPUUCLNW.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli/scaffolder.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { NEXT_CONFIG_NAMES } from \"./constants.js\";\n\n/**\n * Computes a stable identity fingerprint for deduplication purposes.\n * This is NOT password hashing — the input is an opaque token used\n * as a marker identity, not a credential stored for authentication.\n *\n * @internal Exported for unit testing only.\n */\nexport function identityFingerprint(token: string): string {\n return `sha256:${createHash(\"sha256\").update(token).digest(\"hex\")}`;\n}\n\n/**\n * Checks whether `content` contains a real (non-commented) `registerGlasstrace()` call.\n *\n * Strips single-line `// ...` comments before matching so that\n * `// registerGlasstrace()` is not treated as a real invocation.\n * Block comments are not stripped — block-commenting a function call\n * while keeping it syntactically valid is extremely unlikely in practice.\n *\n * @internal Exported for unit testing only.\n */\nexport function hasRegisterGlasstraceCall(content: string): boolean {\n return content.split(\"\\n\").some((line) => {\n const uncommented = line.replace(/\\/\\/.*$/, \"\");\n return /\\bregisterGlasstrace\\s*\\(/.test(uncommented);\n });\n}\n\n/** Result of attempting to inject registerGlasstrace into an existing file. */\nexport interface InjectResult {\n content: string;\n injected: boolean;\n}\n\n/** Result of the instrumentation.ts scaffolding step. */\nexport type InstrumentationAction =\n | \"created\"\n | \"injected\"\n | \"appended\"\n | \"already-registered\"\n | \"skipped\"\n | \"unrecognized\"\n | \"conflict\";\n\n/**\n * Layout detected by {@link resolveInstrumentationTarget}. `root` means\n * the project has no `src/` directory so instrumentation lives at the\n * project root; `src` means Next.js expects `src/instrumentation.ts`.\n */\nexport type InstrumentationLayout = \"root\" | \"src\";\n\n/** Structured result from scaffoldInstrumentation. */\nexport interface ScaffoldInstrumentationResult {\n action: InstrumentationAction;\n /**\n * The instrumentation file path this scaffold step targeted. Absolute\n * path (e.g., `/abs/project/instrumentation.ts` or\n * `/abs/project/src/instrumentation.ts`). Present for every successful\n * action so callers (init.ts summary lines, rollback state) can report\n * and unwind without re-detecting the layout.\n *\n * For `\"conflict\"`, this is the recommended merge target — the `src/`\n * variant when both exist, because that's where Next.js loads from on\n * modern `src/`-layout projects. The competing path is available via\n * {@link ScaffoldInstrumentationResult.conflictingPath}.\n */\n filePath?: string;\n /** Layout the resolver chose. Always set for non-conflict actions. */\n layout?: InstrumentationLayout;\n /**\n * When `action === \"conflict\"`, the path of the other instrumentation\n * file whose presence Next.js treats as undefined. The recommended merge\n * target is {@link ScaffoldInstrumentationResult.filePath}.\n */\n conflictingPath?: string;\n}\n\n/** Options for {@link scaffoldInstrumentation}. */\nexport interface ScaffoldInstrumentationOptions {\n /**\n * When `true`, skip the merge-confirmation prompt and write changes\n * without asking. Matches the DISC-1247 Scenario 2c `--force` behavior\n * already used for MCP config overwrites. Defaults to `false`.\n */\n force?: boolean;\n /**\n * Interactive prompt callback. When omitted, `scaffoldInstrumentation`\n * uses a TTY readline prompt and defaults to `false` (skip the change)\n * in non-interactive shells — the same pattern `decideMcpConfigAction`\n * follows. Exposed for testing.\n */\n prompt?: (question: string, defaultValue: boolean) => Promise<boolean>;\n}\n\n/** Result of attempting to wrap next.config with withGlasstraceConfig. */\nexport interface ScaffoldNextConfigResult {\n modified: boolean;\n reason?: \"already-wrapped\" | \"empty-file\" | \"no-export\";\n}\n\n/**\n * Injects `registerGlasstrace()` into an existing instrumentation.ts file.\n *\n * Strategy:\n * 1. If the file already contains a real `registerGlasstrace()` call — no-op\n * (commented-out calls are ignored)\n * 2. Find `export [async] function register()` pattern\n * 3. Add `import { registerGlasstrace } from \"@glasstrace/sdk\"` at top\n * (or extend existing `@glasstrace/sdk` import, skipping if already imported)\n * 4. Insert `registerGlasstrace()` as the first statement in the function body\n *\n * @param content - The existing file content\n * @returns The modified content if injection succeeded, or the original content\n * with `injected: false` if the pattern was not recognized\n */\nexport function injectRegisterGlasstrace(content: string): InjectResult {\n // Already has a registerGlasstrace() call — no-op.\n // Uses a helper that strips single-line comments before matching\n // so that `// registerGlasstrace()` is not treated as a real call.\n if (hasRegisterGlasstraceCall(content)) {\n return { injected: false, content };\n }\n\n // Find the register() function: export [async] function register(...) {\n const registerFnRegex = /export\\s+(?:async\\s+)?function\\s+register\\s*\\([^)]*\\)\\s*\\{/;\n const match = registerFnRegex.exec(content);\n\n if (!match) {\n return { injected: false, content };\n }\n\n // Determine indentation from the function body by looking at the first\n // indented line after the opening brace. Only capture spaces and tabs\n // (not newlines) to avoid blank lines corrupting the detected indent.\n // Default to 2-space indent (matches the scaffolded template).\n const afterBrace = content.slice(match.index + match[0].length);\n const indentMatch = /\\n([ \\t]+)/.exec(afterBrace);\n const indent = indentMatch ? indentMatch[1] : \" \";\n\n // Build the import line\n const importLine = 'import { registerGlasstrace } from \"@glasstrace/sdk\";\\n';\n\n // Check if the file already imports from @glasstrace/sdk\n const hasGlasstraceImport = content.includes(\"@glasstrace/sdk\");\n\n // Insert registerGlasstrace() as the first statement in the function body\n const insertPoint = match.index + match[0].length;\n const callInjection = `\\n${indent}// Glasstrace must be registered before other instrumentation\\n${indent}registerGlasstrace();\\n`;\n\n let modified: string;\n if (hasGlasstraceImport) {\n // File already imports from @glasstrace/sdk — check whether registerGlasstrace\n // is already among the specifiers to avoid producing a duplicate like\n // `import { registerGlasstrace, registerGlasstrace }`.\n const importRegex = /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']@glasstrace\\/sdk[\"']/;\n const importMatch = importRegex.exec(content);\n if (importMatch) {\n const specifiers = importMatch[1];\n const alreadyImported = specifiers\n .split(\",\")\n .some((s) => s.trim() === \"registerGlasstrace\");\n\n if (alreadyImported) {\n // Import already has registerGlasstrace — only inject the call\n modified = content.slice(0, insertPoint) + callInjection + content.slice(insertPoint);\n } else {\n // Add registerGlasstrace to existing import specifiers\n const existingImports = specifiers.trimEnd();\n const separator = existingImports.endsWith(\",\") ? \" \" : \", \";\n const updatedImport = `import { ${existingImports.trim()}${separator}registerGlasstrace } from \"@glasstrace/sdk\"`;\n modified = content.replace(importMatch[0], updatedImport);\n // Re-find the function in the shifted content and inject the call\n const newMatch = registerFnRegex.exec(modified);\n if (newMatch) {\n const newInsertPoint = newMatch.index + newMatch[0].length;\n modified = modified.slice(0, newInsertPoint) + callInjection + modified.slice(newInsertPoint);\n }\n }\n } else {\n // Non-destructured import (e.g., import * as sdk) — add a separate import\n modified = importLine + content;\n // Re-find the function in the shifted content and inject the call\n const newMatch = registerFnRegex.exec(modified);\n if (newMatch) {\n const newInsertPoint = newMatch.index + newMatch[0].length;\n modified = modified.slice(0, newInsertPoint) + callInjection + modified.slice(newInsertPoint);\n }\n }\n } else {\n // Add import at the top of the file and the call in the function body\n modified = importLine + content.slice(0, insertPoint) + callInjection + content.slice(insertPoint);\n }\n\n return { injected: true, content: modified };\n}\n\n/** Instrumentation filename variants Next.js recognizes, in priority order. */\nconst INSTRUMENTATION_FILENAMES = [\n \"instrumentation.ts\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n] as const;\n\n/**\n * Result of {@link resolveInstrumentationTarget}. When the project has no\n * conflict, `target` identifies the file the scaffolder should create or\n * merge into. When both root and `src/` variants already exist, `target`\n * is `null` and both detected paths are returned so the caller can surface\n * a clear error — Next.js's loader behavior is undefined in that state\n * (DISC-493 Issue 1).\n */\nexport interface InstrumentationTarget {\n /** Absolute path of the chosen file, or null when a conflict exists. */\n target: string | null;\n /** Which layout was chosen. Null mirrors `target === null`. */\n layout: InstrumentationLayout | null;\n /**\n * Absolute paths of any existing instrumentation files detected. Includes\n * the chosen `target` when it exists, plus the competing file when there\n * is a conflict. Empty when the project has no instrumentation file yet.\n */\n existing: string[];\n /**\n * Absolute paths of root-level instrumentation files (e.g.,\n * `{projectRoot}/instrumentation.ts`). Tracked separately from `existing`\n * so callers can distinguish root from `src/` without string matching on\n * paths that may legitimately contain `src` elsewhere in their ancestry\n * (e.g., `/home/user/src/project/`).\n */\n rootExisting: string[];\n /**\n * Absolute paths of `src/`-level instrumentation files (e.g.,\n * `{projectRoot}/src/instrumentation.ts`). See `rootExisting` for the\n * rationale for tracking these separately.\n */\n srcExisting: string[];\n /**\n * When both a root and `src/` instrumentation file are present, Next.js's\n * behavior is not defined. The scaffolder refuses to create a third\n * competing file and asks the user to merge manually into the preferred\n * target (the `src/` variant when the project uses `src/` layout).\n */\n conflict: boolean;\n}\n\n/**\n * Detects whether the project uses Next.js's `src/` directory layout and\n * picks the instrumentation file path the scaffolder should create or\n * merge into.\n *\n * Selection rules (DISC-493 Issue 1):\n *\n * 1. Prefer an existing file. If `src/instrumentation.{ts,js,mjs}` exists,\n * it wins; otherwise the root variant wins. This preserves user intent\n * (they already chose a location) and matches what Next.js loads.\n * 2. When no instrumentation file exists yet, use `src/` when the project\n * has a `src/` directory at its root — the common Next.js convention.\n * 3. When both a root and a `src/` instrumentation file exist, return\n * `conflict: true`. Next.js's loader behavior is undefined in that\n * state and scaffolding a third write would mask whichever file Next.js\n * ultimately ignores.\n *\n * The resolver is pure: it reads the filesystem but writes nothing and\n * never throws. Callers can invoke it repeatedly (e.g., for validation).\n *\n * @param projectRoot - Absolute path to the project root directory.\n */\nexport function resolveInstrumentationTarget(\n projectRoot: string,\n): InstrumentationTarget {\n const rootExisting: string[] = [];\n const srcExisting: string[] = [];\n\n for (const name of INSTRUMENTATION_FILENAMES) {\n const rootPath = path.join(projectRoot, name);\n if (isRegularFile(rootPath)) {\n rootExisting.push(rootPath);\n }\n const srcPath = path.join(projectRoot, \"src\", name);\n if (isRegularFile(srcPath)) {\n srcExisting.push(srcPath);\n }\n }\n\n const existing = [...rootExisting, ...srcExisting];\n\n // Conflict: a file from each layout exists. Next.js's behavior is\n // undefined (DISC-493 Issue 1). The caller surfaces an error.\n if (rootExisting.length > 0 && srcExisting.length > 0) {\n return {\n target: null,\n layout: null,\n existing,\n rootExisting,\n srcExisting,\n conflict: true,\n };\n }\n\n // Prefer whichever layout already has an instrumentation file — the\n // user has already committed to that location and Next.js loads from it.\n if (srcExisting.length > 0) {\n return {\n target: srcExisting[0],\n layout: \"src\",\n existing,\n rootExisting,\n srcExisting,\n conflict: false,\n };\n }\n if (rootExisting.length > 0) {\n return {\n target: rootExisting[0],\n layout: \"root\",\n existing,\n rootExisting,\n srcExisting,\n conflict: false,\n };\n }\n\n // No file exists yet — default to `src/` when a `src/` directory is\n // present. Many Next.js apps use this layout and the bug in\n // DISC-493 was scaffolding to the root when Next.js ignores it.\n const srcDir = path.join(projectRoot, \"src\");\n const layout: InstrumentationLayout = isDirectory(srcDir) ? \"src\" : \"root\";\n const target = layout === \"src\"\n ? path.join(projectRoot, \"src\", \"instrumentation.ts\")\n : path.join(projectRoot, \"instrumentation.ts\");\n\n return {\n target,\n layout,\n existing,\n rootExisting,\n srcExisting,\n conflict: false,\n };\n}\n\n/** Returns true when `p` is a directory. Never throws. */\nfunction isDirectory(p: string): boolean {\n try {\n return fs.statSync(p).isDirectory();\n } catch {\n return false;\n }\n}\n\n/**\n * Returns true when `p` is a regular file (not a directory, not missing).\n * Uses `lstatSync` so symlinks are evaluated as-is — a symlink to a file\n * counts, a symlink to a directory does not. Never throws.\n */\nfunction isRegularFile(p: string): boolean {\n try {\n const stat = fs.lstatSync(p);\n if (stat.isSymbolicLink()) {\n // Follow the symlink so we correctly classify links to real files.\n return fs.statSync(p).isFile();\n }\n return stat.isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Appends a new `export async function register()` to a file that has no\n * recognizable register function. Used when `src/instrumentation.ts`\n * exists (e.g., Sentry scaffolded it with only a top-level side-effect\n * import) but has no register hook yet.\n *\n * @internal Exported for unit testing only.\n */\nexport function appendRegisterFunction(content: string): string {\n const importLine = 'import { registerGlasstrace } from \"@glasstrace/sdk\";\\n';\n const functionBlock =\n \"\\n\" +\n \"export async function register() {\\n\" +\n \" // Glasstrace must be registered before Prisma instrumentation\\n\" +\n \" // to ensure all ORM spans are captured correctly.\\n\" +\n \" // If you use @prisma/instrumentation, import it after this call.\\n\" +\n \" registerGlasstrace();\\n\" +\n \"}\\n\";\n\n // Avoid a duplicate import if the file already pulls from @glasstrace/sdk.\n // When multiple specifiers are imported, splice registerGlasstrace in\n // rather than adding a second import line (mirrors injectRegisterGlasstrace).\n let withImport = content;\n const hasGlasstraceImport = content.includes(\"@glasstrace/sdk\");\n if (!hasGlasstraceImport) {\n withImport = importLine + content;\n } else {\n const importRegex = /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']@glasstrace\\/sdk[\"']/;\n const importMatch = importRegex.exec(content);\n if (importMatch) {\n const specifiers = importMatch[1];\n const alreadyImported = specifiers\n .split(\",\")\n .some((s) => s.trim() === \"registerGlasstrace\");\n if (!alreadyImported) {\n const existingImports = specifiers.trimEnd();\n const separator = existingImports.endsWith(\",\") ? \" \" : \", \";\n const updatedImport = `import { ${existingImports.trim()}${separator}registerGlasstrace } from \"@glasstrace/sdk\"`;\n withImport = content.replace(importMatch[0], updatedImport);\n }\n } else {\n // Non-destructured `import * as sdk from \"@glasstrace/sdk\"` form —\n // add a separate destructured import for registerGlasstrace so we\n // never depend on reading the namespace alias.\n withImport = importLine + content;\n }\n }\n\n // Ensure the file ends with a single newline before appending.\n const trailingNewline = withImport.endsWith(\"\\n\") ? \"\" : \"\\n\";\n return withImport + trailingNewline + functionBlock;\n}\n\n/**\n * Default `confirm`-style prompt used when `scaffoldInstrumentation` is\n * called without a `prompt` callback. Mirrors `init.ts#promptYesNo`:\n * returns the default value when stdin is not a TTY so non-interactive\n * shells do not hang.\n */\nasync function defaultInstrumentationPrompt(\n question: string,\n defaultValue: boolean,\n): Promise<boolean> {\n if (!process.stdin.isTTY) return defaultValue;\n const readline = await import(\"node:readline\");\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise<boolean>((resolve) => {\n const suffix = defaultValue ? \" [Y/n] \" : \" [y/N] \";\n rl.question(question + suffix, (answer) => {\n rl.close();\n const trimmed = answer.trim().toLowerCase();\n if (trimmed === \"\") {\n resolve(defaultValue);\n return;\n }\n resolve(trimmed === \"y\" || trimmed === \"yes\");\n });\n });\n}\n\n/**\n * Ensures an instrumentation file exists and contains a `registerGlasstrace()`\n * call, merging into the user's existing file rather than overwriting it.\n *\n * Behavior (DISC-493 Issue 1):\n *\n * - Detects `src/`-layout projects via {@link resolveInstrumentationTarget}\n * and targets `src/instrumentation.ts` instead of the root when a `src/`\n * directory is present.\n * - When both `instrumentation.ts` and `src/instrumentation.ts` already\n * exist, returns `action: \"conflict\"` so the caller can emit a clear\n * error. Next.js's loader behavior is undefined in that state and\n * writing a third file would silently mask the one Next.js ignores.\n * - When the target does not exist, creates it with the standard template.\n * - When the target exists but has no `registerGlasstrace()` call:\n * - If it exposes an `export function register()`, injects the call as\n * the first statement (and imports `registerGlasstrace` if needed).\n * - If it has no register function, appends a new `export async function\n * register()` that calls `registerGlasstrace()` — this matches the\n * Sentry / Datadog / custom-instrumentation case where `register()`\n * hasn't been created yet.\n * - Before either mutation, prompts the user unless `force: true` is\n * passed (DISC-1247 Scenario 2c re-init safety).\n * - When the target already contains `registerGlasstrace()`, returns\n * `action: \"already-registered\"` (idempotent).\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @param options - Prompt and force flags for merge-safe re-init.\n */\nexport async function scaffoldInstrumentation(\n projectRoot: string,\n options: ScaffoldInstrumentationOptions = {},\n): Promise<ScaffoldInstrumentationResult> {\n const target = resolveInstrumentationTarget(projectRoot);\n\n if (target.conflict) {\n return {\n action: \"conflict\",\n // Point the user at the `src/` variant — modern Next.js apps with a\n // `src/` directory load from there, so that's the merge target. The\n // competing path is reported separately for the error message.\n filePath: target.srcExisting[0],\n conflictingPath: target.rootExisting[0],\n };\n }\n\n const filePath = target.target;\n const layout = target.layout;\n // Defensive: resolver always sets these in the non-conflict path.\n if (filePath === null || layout === null) {\n return { action: \"unrecognized\" };\n }\n\n const force = options.force === true;\n const prompt = options.prompt ?? defaultInstrumentationPrompt;\n\n if (!fs.existsSync(filePath)) {\n const content = `import { registerGlasstrace } from \"@glasstrace/sdk\";\n\nexport async function register() {\n // Glasstrace must be registered before Prisma instrumentation\n // to ensure all ORM spans are captured correctly.\n // If you use @prisma/instrumentation, import it after this call.\n registerGlasstrace();\n}\n`;\n // Ensure the target directory exists (e.g., `src/` when the project\n // has the `src/` layout but no src/ folder somehow — defensive).\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, content, \"utf-8\");\n return { action: \"created\", filePath, layout };\n }\n\n // File exists — check whether registerGlasstrace() is already called.\n // Uses a helper that strips single-line comments before matching\n // so that `// registerGlasstrace()` is not treated as a real call.\n const existing = fs.readFileSync(filePath, \"utf-8\");\n\n if (hasRegisterGlasstraceCall(existing)) {\n return { action: \"already-registered\", filePath, layout };\n }\n\n // The file is going to change. Before writing, confirm with the user\n // unless --force was passed — otherwise a second init on a custom\n // instrumentation file would silently rewrite it. Non-interactive\n // shells (no TTY) skip the merge by default; pass `force: true` to\n // proceed without prompting, which the CLI does for `--yes`/`--force`.\n if (!force) {\n const approved = await prompt(\n `Merge registerGlasstrace() into ${path.relative(projectRoot, filePath)}?`,\n false,\n );\n if (!approved) {\n return { action: \"skipped\", filePath, layout };\n }\n }\n\n // Attempt injection into the existing register() function first.\n const injectResult = injectRegisterGlasstrace(existing);\n if (injectResult.injected) {\n fs.writeFileSync(filePath, injectResult.content, \"utf-8\");\n return { action: \"injected\", filePath, layout };\n }\n\n // No register() function present — append a fresh one. This is the\n // Sentry/Datadog case where `src/instrumentation.ts` exists with only\n // a top-level import or empty body.\n const appended = appendRegisterFunction(existing);\n fs.writeFileSync(filePath, appended, \"utf-8\");\n return { action: \"appended\", filePath, layout };\n}\n\n/**\n * Detects `next.config.js`, `next.config.ts`, or `next.config.mjs` and wraps\n * with `withGlasstraceConfig()`. If the config already contains\n * `withGlasstraceConfig`, the file is not modified.\n *\n * For CJS `.js` configs, adds a `require()` call and wraps `module.exports`.\n * The SDK ships dual ESM/CJS builds via tsup + conditional exports, so\n * `require(\"@glasstrace/sdk\")` resolves to the CJS entrypoint natively.\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @returns A result object describing what happened, or `null` if no config\n * file was found at all.\n */\nexport async function scaffoldNextConfig(\n projectRoot: string,\n): Promise<ScaffoldNextConfigResult | null> {\n let configPath: string | undefined;\n let configName: string | undefined;\n\n for (const name of NEXT_CONFIG_NAMES) {\n const candidate = path.join(projectRoot, name);\n if (fs.existsSync(candidate)) {\n configPath = candidate;\n configName = name;\n break;\n }\n }\n\n if (configPath === undefined || configName === undefined) {\n return null;\n }\n\n const existing = fs.readFileSync(configPath, \"utf-8\");\n\n // Guard: empty or whitespace-only files have no export to wrap\n if (existing.trim().length === 0) {\n return { modified: false, reason: \"empty-file\" };\n }\n\n // Already wrapped — skip even in force mode to avoid double-wrapping\n if (existing.includes(\"withGlasstraceConfig\")) {\n return { modified: false, reason: \"already-wrapped\" };\n }\n\n const isESM = configName.endsWith(\".ts\") || configName.endsWith(\".mjs\");\n\n if (isESM) {\n // ESM: static import at top of file, wrap the export\n const importLine = 'import { withGlasstraceConfig } from \"@glasstrace/sdk\";\\n';\n const wrapResult = wrapExport(existing);\n if (!wrapResult.wrapped) {\n return { modified: false, reason: \"no-export\" };\n }\n const modified = importLine + \"\\n\" + wrapResult.content;\n fs.writeFileSync(configPath, modified, \"utf-8\");\n return { modified: true };\n }\n\n // CJS (.js): require() the SDK (resolves to the CJS dist build) and\n // wrap the module.exports expression in place — no file renaming needed.\n const requireLine = 'const { withGlasstraceConfig } = require(\"@glasstrace/sdk\");\\n';\n const wrapResult = wrapCJSExport(existing);\n if (!wrapResult.wrapped) {\n return { modified: false, reason: \"no-export\" };\n }\n const modified = requireLine + \"\\n\" + wrapResult.content;\n fs.writeFileSync(configPath, modified, \"utf-8\");\n return { modified: true };\n}\n\n/** @internal Exported for unit testing only. */\nexport interface WrapResult {\n content: string;\n wrapped: boolean;\n}\n\n/**\n * Wraps an ESM `export default` expression with `withGlasstraceConfig()`.\n *\n * Strategy: find the last `export default` in the file. Everything from\n * that statement to EOF is the exported expression. Strip optional trailing\n * semicolons/whitespace and wrap with `withGlasstraceConfig(...)`.\n *\n * @param content - The full file content containing an ESM default export.\n * @returns `{ wrapped: true, content }` on success, or `{ wrapped: false }` if\n * no recognizable export pattern was found (content returned unchanged).\n * @internal Exported for unit testing only.\n */\nexport function wrapExport(content: string): WrapResult {\n // Find the last `export default` — use lastIndexOf for robustness\n const marker = \"export default\";\n const idx = content.lastIndexOf(marker);\n if (idx === -1) {\n return { content, wrapped: false };\n }\n\n const preamble = content.slice(0, idx);\n const exprRaw = content.slice(idx + marker.length);\n // Trim leading whitespace; strip trailing semicolon + whitespace\n const expr = exprRaw.trim().replace(/;?\\s*$/, \"\");\n if (expr.length === 0) {\n return { content, wrapped: false };\n }\n\n return {\n content: preamble + `export default withGlasstraceConfig(${expr});\\n`,\n wrapped: true,\n };\n}\n\n/**\n * Wraps a CJS `module.exports = expr` with `withGlasstraceConfig()`.\n *\n * Strategy: find the last `module.exports =` in the file. Everything from\n * that statement to EOF is the exported expression. Strip optional trailing\n * semicolons/whitespace and wrap with `module.exports = withGlasstraceConfig(...)`.\n *\n * @param content - The full CJS file content containing `module.exports = ...`.\n * @returns `{ wrapped: true, content }` on success, or `{ wrapped: false }` if\n * no recognizable `module.exports` pattern was found (content returned unchanged).\n * @internal Exported for unit testing only.\n */\nexport function wrapCJSExport(content: string): WrapResult {\n const cjsMarker = \"module.exports\";\n const cjsIdx = content.lastIndexOf(cjsMarker);\n if (cjsIdx === -1) {\n return { content, wrapped: false };\n }\n\n const preamble = content.slice(0, cjsIdx);\n const afterMarker = content.slice(cjsIdx + cjsMarker.length);\n const eqMatch = /^\\s*=\\s*/.exec(afterMarker);\n if (!eqMatch) {\n return { content, wrapped: false };\n }\n\n const exprRaw = afterMarker.slice(eqMatch[0].length);\n const expr = exprRaw.trim().replace(/;?\\s*$/, \"\");\n if (expr.length === 0) {\n return { content, wrapped: false };\n }\n\n return {\n content: preamble + `module.exports = withGlasstraceConfig(${expr});\\n`,\n wrapped: true,\n };\n}\n\n/**\n * Extracts the value of `GLASSTRACE_API_KEY` from a `.env.local`-style\n * string. Returns the raw (unquoted) value, or `null` if the key is\n * absent, commented out, or empty.\n *\n * Only uncommented assignments are considered — a `# GLASSTRACE_API_KEY=...`\n * placeholder is treated as if the key is not set.\n *\n * When multiple uncommented assignments are present, the **last**\n * effective value wins — matching typical `.env` override semantics\n * (later lines override earlier ones when loaded by dotenv-style\n * loaders). Placeholder values (empty or `your_key_here`) are skipped\n * so a trailing placeholder does not mask a real earlier value.\n *\n * @internal Exported for unit testing only.\n */\nexport function readEnvLocalApiKey(content: string): string | null {\n let last: string | null = null;\n const regex = /^\\s*GLASSTRACE_API_KEY\\s*=\\s*(.*)$/gm;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(content)) !== null) {\n const raw = match[1].trim();\n if (raw === \"\") continue;\n const unquoted = raw.replace(/^(['\"])(.*)\\1$/, \"$2\");\n if (unquoted === \"\" || unquoted === \"your_key_here\") continue;\n last = unquoted;\n }\n return last;\n}\n\n/**\n * Returns true when the given API key value is a claimed developer key\n * (prefix `gt_dev_`). Defensive against leading/trailing whitespace.\n *\n * @internal Exported for unit testing only.\n */\nexport function isDevApiKey(value: string | null | undefined): boolean {\n if (value === null || value === undefined) return false;\n return value.trim().startsWith(\"gt_dev_\");\n}\n\n/**\n * Creates `.env.local` with `GLASSTRACE_API_KEY=` placeholder, or appends\n * to an existing file if it does not already contain `GLASSTRACE_API_KEY`.\n *\n * Preservation behavior (DISC-1247 Scenario 6): if an existing `.env.local`\n * already defines a developer key (`gt_dev_*`), the file is left untouched\n * so re-running `init` after an account claim does not overwrite the\n * claimed dev key.\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @returns True if the file was created or modified, false if already configured.\n */\nexport async function scaffoldEnvLocal(projectRoot: string): Promise<boolean> {\n const filePath = path.join(projectRoot, \".env.local\");\n\n if (fs.existsSync(filePath)) {\n const existing = fs.readFileSync(filePath, \"utf-8\");\n if (/^\\s*#?\\s*GLASSTRACE_API_KEY\\s*=/m.test(existing)) {\n return false;\n }\n // Append with a newline separator if needed\n const separator = existing.endsWith(\"\\n\") ? \"\" : \"\\n\";\n fs.writeFileSync(filePath, existing + separator + \"# GLASSTRACE_API_KEY=your_key_here\\n\", \"utf-8\");\n return true;\n }\n\n fs.writeFileSync(filePath, \"# GLASSTRACE_API_KEY=your_key_here\\n\", \"utf-8\");\n return true;\n}\n\n/**\n * Adds `GLASSTRACE_COVERAGE_MAP=true` to `.env.local`.\n * Creates the file if it does not exist. If the key is already present\n * with a value other than `true`, it is updated in place.\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @returns True if the file was created or modified, false if already set to `true`.\n */\nexport async function addCoverageMapEnv(projectRoot: string): Promise<boolean> {\n const filePath = path.join(projectRoot, \".env.local\");\n\n if (!fs.existsSync(filePath)) {\n fs.writeFileSync(filePath, \"GLASSTRACE_COVERAGE_MAP=true\\n\", \"utf-8\");\n return true;\n }\n\n const existing = fs.readFileSync(filePath, \"utf-8\");\n const keyRegex = /^(\\s*GLASSTRACE_COVERAGE_MAP\\s*=\\s*)(.*)$/m;\n const keyMatch = keyRegex.exec(existing);\n\n if (keyMatch) {\n const currentValue = keyMatch[2].trim();\n if (currentValue === \"true\") {\n // Already set to true — nothing to do\n return false;\n }\n // Key exists but is not `true` — update in place\n const updated = existing.replace(keyRegex, `${keyMatch[1]}true`);\n fs.writeFileSync(filePath, updated, \"utf-8\");\n return true;\n }\n\n const separator = existing.endsWith(\"\\n\") ? \"\" : \"\\n\";\n fs.writeFileSync(filePath, existing + separator + \"GLASSTRACE_COVERAGE_MAP=true\\n\", \"utf-8\");\n return true;\n}\n\n/**\n * Adds `.glasstrace/` to `.gitignore`, or creates `.gitignore` if missing.\n * Does not add duplicate entries.\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @returns True if the file was created or modified, false if already configured.\n */\nexport async function scaffoldGitignore(projectRoot: string): Promise<boolean> {\n const filePath = path.join(projectRoot, \".gitignore\");\n\n if (fs.existsSync(filePath)) {\n const existing = fs.readFileSync(filePath, \"utf-8\");\n // Check line-by-line to avoid false positive partial matches\n const lines = existing.split(\"\\n\").map((l) => l.trim());\n if (lines.includes(\".glasstrace/\")) {\n return false;\n }\n const separator = existing.endsWith(\"\\n\") ? \"\" : \"\\n\";\n fs.writeFileSync(filePath, existing + separator + \".glasstrace/\\n\", \"utf-8\");\n return true;\n }\n\n fs.writeFileSync(filePath, \".glasstrace/\\n\", \"utf-8\");\n return true;\n}\n\n/**\n * Compares an existing MCP config file against the content init would\n * write. Returns `true` when they are semantically equal (JSON configs\n * are parsed and compared deeply; TOML configs use trimmed string\n * comparison). Returns `false` on parse errors or mismatch.\n *\n * Used by `init` to detect manually-edited MCP configs before\n * overwriting them (DISC-1247 Scenario 2c).\n *\n * @internal Exported for unit testing only.\n */\nexport function mcpConfigMatches(\n existingContent: string,\n expectedContent: string,\n): boolean {\n const trimmedExpected = expectedContent.trim();\n\n // Attempt JSON comparison first — init writes JSON for most agents.\n try {\n const existingParsed: unknown = JSON.parse(existingContent);\n const expectedParsed: unknown = JSON.parse(trimmedExpected);\n return JSON.stringify(canonicalize(existingParsed)) === JSON.stringify(canonicalize(expectedParsed));\n } catch {\n // Fall through to text comparison for TOML and other non-JSON formats.\n }\n\n return existingContent.trim() === trimmedExpected;\n}\n\n/**\n * Sorts object keys recursively to produce a canonical form suitable\n * for structural equality comparison via JSON.stringify.\n */\nfunction canonicalize(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(canonicalize);\n }\n if (value !== null && typeof value === \"object\") {\n const obj = value as Record<string, unknown>;\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n sorted[key] = canonicalize(obj[key]);\n }\n return sorted;\n }\n return value;\n}\n\n/**\n * Creates the `.glasstrace/mcp-connected` marker file, or overwrites it\n * if the key has changed (key rotation).\n *\n * The marker file records a SHA-256 fingerprint of the anonymous key and\n * the ISO 8601 timestamp when it was written. It is used by the nudge\n * system to suppress \"MCP not configured\" prompts.\n *\n * If the marker already exists with the same key fingerprint, this is a\n * no-op (the timestamp is NOT refreshed).\n *\n * @param projectRoot - Absolute path to the project root directory.\n * @param anonKey - The anonymous API key to fingerprint.\n * @returns True if the marker was created or updated, false if it already\n * exists with the same key fingerprint.\n */\nexport async function scaffoldMcpMarker(\n projectRoot: string,\n anonKey: string,\n): Promise<boolean> {\n const dirPath = path.join(projectRoot, \".glasstrace\");\n const markerPath = path.join(dirPath, \"mcp-connected\");\n const keyHash = identityFingerprint(anonKey);\n\n // Check if marker already exists with the same key hash\n if (fs.existsSync(markerPath)) {\n try {\n const existing = JSON.parse(fs.readFileSync(markerPath, \"utf-8\")) as {\n keyHash?: string;\n };\n if (existing.keyHash === keyHash) {\n return false;\n }\n } catch {\n // Corrupted marker — overwrite\n }\n }\n\n // Create directory with restricted permissions\n fs.mkdirSync(dirPath, { recursive: true, mode: 0o700 });\n\n const marker = JSON.stringify(\n { keyHash, configuredAt: new Date().toISOString() },\n null,\n 2,\n );\n\n fs.writeFileSync(markerPath, marker, { mode: 0o600 });\n\n // Ensure permissions even if file pre-existed (writeFile mode only\n // applies on creation on some platforms)\n fs.chmodSync(markerPath, 0o600);\n\n return true;\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AAC3B,YAAY,QAAQ;AACpB,YAAY,UAAU;AAUf,SAAS,oBAAoB,OAAuB;AACzD,SAAO,UAAU,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;AACnE;AAYO,SAAS,0BAA0B,SAA0B;AAClE,SAAO,QAAQ,MAAM,IAAI,EAAE,KAAK,CAAC,SAAS;AACxC,UAAM,cAAc,KAAK,QAAQ,WAAW,EAAE;AAC9C,WAAO,4BAA4B,KAAK,WAAW;AAAA,EACrD,CAAC;AACH;AAyFO,SA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