@glasstrace/sdk 0.14.2 → 0.16.0

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 (84) hide show
  1. package/README.md +84 -1
  2. package/dist/adapters/drizzle.js +2 -5
  3. package/dist/adapters/drizzle.js.map +1 -1
  4. package/dist/{chunk-PD2SKFQQ.js → chunk-55FBXXER.js} +4 -8
  5. package/dist/{chunk-PD2SKFQQ.js.map → chunk-55FBXXER.js.map} +1 -1
  6. package/dist/chunk-5C2TJFLB.js +851 -0
  7. package/dist/chunk-5C2TJFLB.js.map +1 -0
  8. package/dist/{chunk-YMEXDDTA.js → chunk-7JBKXSBU.js} +3 -99
  9. package/dist/chunk-7JBKXSBU.js.map +1 -0
  10. package/dist/{chunk-2LDBR3F3.js → chunk-BANTDXUT.js} +15 -74
  11. package/dist/chunk-BANTDXUT.js.map +1 -0
  12. package/dist/{chunk-WV3NIPWJ.js → chunk-CTJI2YKA.js} +23 -288
  13. package/dist/chunk-CTJI2YKA.js.map +1 -0
  14. package/dist/{chunk-WK7MPK2T.js → chunk-DQ25VOKK.js} +1 -89
  15. package/dist/chunk-DQ25VOKK.js.map +1 -0
  16. package/dist/{chunk-BL3YDC6V.js → chunk-DXRZKKSO.js} +1 -6
  17. package/dist/{chunk-BL3YDC6V.js.map → chunk-DXRZKKSO.js.map} +1 -1
  18. package/dist/{chunk-BGZ7J74D.js → chunk-NSBPE2FW.js} +2 -16
  19. package/dist/chunk-O63DJKIJ.js +460 -0
  20. package/dist/chunk-O63DJKIJ.js.map +1 -0
  21. package/dist/{chunk-ECEN724Y.js → chunk-TM5NKZTO.js} +4 -8
  22. package/dist/{chunk-ECEN724Y.js.map → chunk-TM5NKZTO.js.map} +1 -1
  23. package/dist/chunk-VUZCLMIX.js +57 -0
  24. package/dist/chunk-VUZCLMIX.js.map +1 -0
  25. package/dist/{chunk-OSXIUKD5.js → chunk-WZXVS2EO.js} +1 -6
  26. package/dist/{chunk-OSXIUKD5.js.map → chunk-WZXVS2EO.js.map} +1 -1
  27. package/dist/{chunk-ARAOZCZT.js → chunk-XNDHQN4S.js} +122 -24
  28. package/dist/chunk-XNDHQN4S.js.map +1 -0
  29. package/dist/cli/init.cjs +1110 -255
  30. package/dist/cli/init.cjs.map +1 -1
  31. package/dist/cli/init.d.cts +86 -1
  32. package/dist/cli/init.d.ts +86 -1
  33. package/dist/cli/init.js +277 -66
  34. package/dist/cli/init.js.map +1 -1
  35. package/dist/cli/mcp-add.cjs +16 -16
  36. package/dist/cli/mcp-add.cjs.map +1 -1
  37. package/dist/cli/mcp-add.js +12 -13
  38. package/dist/cli/mcp-add.js.map +1 -1
  39. package/dist/cli/status.cjs +2 -2
  40. package/dist/cli/status.js +4 -7
  41. package/dist/cli/status.js.map +1 -1
  42. package/dist/cli/uninit.cjs +138 -20
  43. package/dist/cli/uninit.cjs.map +1 -1
  44. package/dist/cli/uninit.d.cts +38 -8
  45. package/dist/cli/uninit.d.ts +38 -8
  46. package/dist/cli/uninit.js +8 -5
  47. package/dist/cli/validate.cjs +135 -0
  48. package/dist/cli/validate.cjs.map +1 -0
  49. package/dist/cli/validate.d.cts +60 -0
  50. package/dist/cli/validate.d.ts +60 -0
  51. package/dist/cli/validate.js +100 -0
  52. package/dist/cli/validate.js.map +1 -0
  53. package/dist/{esm-MDK7CZID.js → esm-KBPHCVB4.js} +3 -3
  54. package/dist/{getMachineId-bsd-4NIRBWME.js → getMachineId-bsd-345PYXFX.js} +4 -7
  55. package/dist/{getMachineId-bsd-4NIRBWME.js.map → getMachineId-bsd-345PYXFX.js.map} +1 -1
  56. package/dist/{getMachineId-darwin-2XNOCCJQ.js → getMachineId-darwin-5L2D25AD.js} +4 -7
  57. package/dist/{getMachineId-darwin-2XNOCCJQ.js.map → getMachineId-darwin-5L2D25AD.js.map} +1 -1
  58. package/dist/{getMachineId-linux-V6YSQEY7.js → getMachineId-linux-KJR4P5HN.js} +3 -6
  59. package/dist/{getMachineId-linux-V6YSQEY7.js.map → getMachineId-linux-KJR4P5HN.js.map} +1 -1
  60. package/dist/{getMachineId-unsupported-4FKBJNVO.js → getMachineId-unsupported-NDNXDYDY.js} +3 -6
  61. package/dist/{getMachineId-unsupported-4FKBJNVO.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +1 -1
  62. package/dist/{getMachineId-win-WLRZBKVG.js → getMachineId-win-T7PJNJXG.js} +4 -7
  63. package/dist/{getMachineId-win-WLRZBKVG.js.map → getMachineId-win-T7PJNJXG.js.map} +1 -1
  64. package/dist/index.cjs +519 -494
  65. package/dist/index.cjs.map +1 -1
  66. package/dist/index.d.cts +47 -6
  67. package/dist/index.d.ts +47 -6
  68. package/dist/index.js +250 -719
  69. package/dist/index.js.map +1 -1
  70. package/dist/{monorepo-YILKGQXQ.js → monorepo-N5Z63XP7.js} +4 -4
  71. package/dist/{source-map-uploader-3GWUQDTS.js → source-map-uploader-MUZPI2S5.js} +5 -4
  72. package/dist/source-map-uploader-MUZPI2S5.js.map +1 -0
  73. package/package.json +6 -4
  74. package/dist/chunk-2LDBR3F3.js.map +0 -1
  75. package/dist/chunk-ARAOZCZT.js.map +0 -1
  76. package/dist/chunk-BGZ7J74D.js.map +0 -1
  77. package/dist/chunk-UPS5BGER.js +0 -182
  78. package/dist/chunk-UPS5BGER.js.map +0 -1
  79. package/dist/chunk-WK7MPK2T.js.map +0 -1
  80. package/dist/chunk-WV3NIPWJ.js.map +0 -1
  81. package/dist/chunk-YMEXDDTA.js.map +0 -1
  82. /package/dist/{esm-MDK7CZID.js.map → chunk-NSBPE2FW.js.map} +0 -0
  83. /package/dist/{monorepo-YILKGQXQ.js.map → esm-KBPHCVB4.js.map} +0 -0
  84. /package/dist/{source-map-uploader-3GWUQDTS.js.map → monorepo-N5Z63XP7.js.map} +0 -0
package/dist/cli/init.cjs CHANGED
@@ -31,13 +31,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  ));
32
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
33
 
34
- // ../../node_modules/tsup/assets/cjs_shims.js
35
- var init_cjs_shims = __esm({
36
- "../../node_modules/tsup/assets/cjs_shims.js"() {
37
- "use strict";
38
- }
39
- });
40
-
41
34
  // src/cli/constants.ts
42
35
  function formatAgentName(name) {
43
36
  const displayNames = {
@@ -54,7 +47,6 @@ var MCP_ENDPOINT, NEXT_CONFIG_NAMES;
54
47
  var init_constants = __esm({
55
48
  "src/cli/constants.ts"() {
56
49
  "use strict";
57
- init_cjs_shims();
58
50
  MCP_ENDPOINT = "https://api.glasstrace.dev/mcp";
59
51
  NEXT_CONFIG_NAMES = ["next.config.ts", "next.config.js", "next.config.mjs"];
60
52
  }
@@ -83,14 +75,14 @@ function injectRegisterGlasstrace(content) {
83
75
  const indentMatch = /\n([ \t]+)/.exec(afterBrace);
84
76
  const indent = indentMatch ? indentMatch[1] : " ";
85
77
  const importLine = 'import { registerGlasstrace } from "@glasstrace/sdk";\n';
86
- const hasGlasstraceImport = content.includes("@glasstrace/sdk");
78
+ const hasGlasstraceImport2 = content.includes("@glasstrace/sdk");
87
79
  const insertPoint = match.index + match[0].length;
88
80
  const callInjection = `
89
81
  ${indent}// Glasstrace must be registered before other instrumentation
90
82
  ${indent}registerGlasstrace();
91
83
  `;
92
84
  let modified;
93
- if (hasGlasstraceImport) {
85
+ if (hasGlasstraceImport2) {
94
86
  const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']@glasstrace\/sdk["']/;
95
87
  const importMatch = importRegex.exec(content);
96
88
  if (importMatch) {
@@ -122,8 +114,145 @@ ${indent}registerGlasstrace();
122
114
  }
123
115
  return { injected: true, content: modified };
124
116
  }
125
- async function scaffoldInstrumentation(projectRoot) {
126
- const filePath = path.join(projectRoot, "instrumentation.ts");
117
+ function resolveInstrumentationTarget(projectRoot) {
118
+ const rootExisting = [];
119
+ const srcExisting = [];
120
+ for (const name of INSTRUMENTATION_FILENAMES) {
121
+ const rootPath = path.join(projectRoot, name);
122
+ if (isRegularFile(rootPath)) {
123
+ rootExisting.push(rootPath);
124
+ }
125
+ const srcPath = path.join(projectRoot, "src", name);
126
+ if (isRegularFile(srcPath)) {
127
+ srcExisting.push(srcPath);
128
+ }
129
+ }
130
+ const existing = [...rootExisting, ...srcExisting];
131
+ if (rootExisting.length > 0 && srcExisting.length > 0) {
132
+ return {
133
+ target: null,
134
+ layout: null,
135
+ existing,
136
+ rootExisting,
137
+ srcExisting,
138
+ conflict: true
139
+ };
140
+ }
141
+ if (srcExisting.length > 0) {
142
+ return {
143
+ target: srcExisting[0],
144
+ layout: "src",
145
+ existing,
146
+ rootExisting,
147
+ srcExisting,
148
+ conflict: false
149
+ };
150
+ }
151
+ if (rootExisting.length > 0) {
152
+ return {
153
+ target: rootExisting[0],
154
+ layout: "root",
155
+ existing,
156
+ rootExisting,
157
+ srcExisting,
158
+ conflict: false
159
+ };
160
+ }
161
+ const srcDir = path.join(projectRoot, "src");
162
+ const layout = isDirectory(srcDir) ? "src" : "root";
163
+ const target = layout === "src" ? path.join(projectRoot, "src", "instrumentation.ts") : path.join(projectRoot, "instrumentation.ts");
164
+ return {
165
+ target,
166
+ layout,
167
+ existing,
168
+ rootExisting,
169
+ srcExisting,
170
+ conflict: false
171
+ };
172
+ }
173
+ function isDirectory(p) {
174
+ try {
175
+ return fs.statSync(p).isDirectory();
176
+ } catch {
177
+ return false;
178
+ }
179
+ }
180
+ function isRegularFile(p) {
181
+ try {
182
+ const stat2 = fs.lstatSync(p);
183
+ if (stat2.isSymbolicLink()) {
184
+ return fs.statSync(p).isFile();
185
+ }
186
+ return stat2.isFile();
187
+ } catch {
188
+ return false;
189
+ }
190
+ }
191
+ function appendRegisterFunction(content) {
192
+ const importLine = 'import { registerGlasstrace } from "@glasstrace/sdk";\n';
193
+ const functionBlock = "\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";
194
+ let withImport = content;
195
+ const hasGlasstraceImport2 = content.includes("@glasstrace/sdk");
196
+ if (!hasGlasstraceImport2) {
197
+ withImport = importLine + content;
198
+ } else {
199
+ const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']@glasstrace\/sdk["']/;
200
+ const importMatch = importRegex.exec(content);
201
+ if (importMatch) {
202
+ const specifiers = importMatch[1];
203
+ const alreadyImported = specifiers.split(",").some((s) => s.trim() === "registerGlasstrace");
204
+ if (!alreadyImported) {
205
+ const existingImports = specifiers.trimEnd();
206
+ const separator = existingImports.endsWith(",") ? " " : ", ";
207
+ const updatedImport = `import { ${existingImports.trim()}${separator}registerGlasstrace } from "@glasstrace/sdk"`;
208
+ withImport = content.replace(importMatch[0], updatedImport);
209
+ }
210
+ } else {
211
+ withImport = importLine + content;
212
+ }
213
+ }
214
+ const trailingNewline = withImport.endsWith("\n") ? "" : "\n";
215
+ return withImport + trailingNewline + functionBlock;
216
+ }
217
+ async function defaultInstrumentationPrompt(question, defaultValue) {
218
+ if (!process.stdin.isTTY) return defaultValue;
219
+ const readline2 = await import("node:readline");
220
+ const rl = readline2.createInterface({
221
+ input: process.stdin,
222
+ output: process.stdout
223
+ });
224
+ return new Promise((resolve2) => {
225
+ const suffix = defaultValue ? " [Y/n] " : " [y/N] ";
226
+ rl.question(question + suffix, (answer) => {
227
+ rl.close();
228
+ const trimmed = answer.trim().toLowerCase();
229
+ if (trimmed === "") {
230
+ resolve2(defaultValue);
231
+ return;
232
+ }
233
+ resolve2(trimmed === "y" || trimmed === "yes");
234
+ });
235
+ });
236
+ }
237
+ async function scaffoldInstrumentation(projectRoot, options = {}) {
238
+ const target = resolveInstrumentationTarget(projectRoot);
239
+ if (target.conflict) {
240
+ return {
241
+ action: "conflict",
242
+ // Point the user at the `src/` variant — modern Next.js apps with a
243
+ // `src/` directory load from there, so that's the merge target. The
244
+ // competing path is reported separately for the error message.
245
+ filePath: target.srcExisting[0],
246
+ conflictingPath: target.rootExisting[0]
247
+ };
248
+ }
249
+ const filePath = target.target;
250
+ const layout = target.layout;
251
+ if (filePath === null || layout === null) {
252
+ return { action: "unrecognized" };
253
+ }
254
+ const force = options.force === true;
255
+ const prompt = options.prompt ?? defaultInstrumentationPrompt;
127
256
  if (!fs.existsSync(filePath)) {
128
257
  const content = `import { registerGlasstrace } from "@glasstrace/sdk";
129
258
 
@@ -134,19 +263,31 @@ export async function register() {
134
263
  registerGlasstrace();
135
264
  }
136
265
  `;
266
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
137
267
  fs.writeFileSync(filePath, content, "utf-8");
138
- return { action: "created" };
268
+ return { action: "created", filePath, layout };
139
269
  }
140
270
  const existing = fs.readFileSync(filePath, "utf-8");
141
271
  if (hasRegisterGlasstraceCall(existing)) {
142
- return { action: "already-registered" };
272
+ return { action: "already-registered", filePath, layout };
273
+ }
274
+ if (!force) {
275
+ const approved = await prompt(
276
+ `Merge registerGlasstrace() into ${path.relative(projectRoot, filePath)}?`,
277
+ false
278
+ );
279
+ if (!approved) {
280
+ return { action: "skipped", filePath, layout };
281
+ }
143
282
  }
144
- const result = injectRegisterGlasstrace(existing);
145
- if (result.injected) {
146
- fs.writeFileSync(filePath, result.content, "utf-8");
147
- return { action: "injected" };
283
+ const injectResult = injectRegisterGlasstrace(existing);
284
+ if (injectResult.injected) {
285
+ fs.writeFileSync(filePath, injectResult.content, "utf-8");
286
+ return { action: "injected", filePath, layout };
148
287
  }
149
- return { action: "unrecognized" };
288
+ const appended = appendRegisterFunction(existing);
289
+ fs.writeFileSync(filePath, appended, "utf-8");
290
+ return { action: "appended", filePath, layout };
150
291
  }
151
292
  async function scaffoldNextConfig(projectRoot) {
152
293
  let configPath;
@@ -230,6 +371,23 @@ function wrapCJSExport(content) {
230
371
  wrapped: true
231
372
  };
232
373
  }
374
+ function readEnvLocalApiKey(content) {
375
+ let last = null;
376
+ const regex = /^\s*GLASSTRACE_API_KEY\s*=\s*(.*)$/gm;
377
+ let match;
378
+ while ((match = regex.exec(content)) !== null) {
379
+ const raw = match[1].trim();
380
+ if (raw === "") continue;
381
+ const unquoted = raw.replace(/^(['"])(.*)\1$/, "$2");
382
+ if (unquoted === "" || unquoted === "your_key_here") continue;
383
+ last = unquoted;
384
+ }
385
+ return last;
386
+ }
387
+ function isDevApiKey(value) {
388
+ if (value === null || value === void 0) return false;
389
+ return value.trim().startsWith("gt_dev_");
390
+ }
233
391
  async function scaffoldEnvLocal(projectRoot) {
234
392
  const filePath = path.join(projectRoot, ".env.local");
235
393
  if (fs.existsSync(filePath)) {
@@ -281,6 +439,30 @@ async function scaffoldGitignore(projectRoot) {
281
439
  fs.writeFileSync(filePath, ".glasstrace/\n", "utf-8");
282
440
  return true;
283
441
  }
442
+ function mcpConfigMatches(existingContent, expectedContent) {
443
+ const trimmedExpected = expectedContent.trim();
444
+ try {
445
+ const existingParsed = JSON.parse(existingContent);
446
+ const expectedParsed = JSON.parse(trimmedExpected);
447
+ return JSON.stringify(canonicalize(existingParsed)) === JSON.stringify(canonicalize(expectedParsed));
448
+ } catch {
449
+ }
450
+ return existingContent.trim() === trimmedExpected;
451
+ }
452
+ function canonicalize(value) {
453
+ if (Array.isArray(value)) {
454
+ return value.map(canonicalize);
455
+ }
456
+ if (value !== null && typeof value === "object") {
457
+ const obj = value;
458
+ const sorted = {};
459
+ for (const key of Object.keys(obj).sort()) {
460
+ sorted[key] = canonicalize(obj[key]);
461
+ }
462
+ return sorted;
463
+ }
464
+ return value;
465
+ }
284
466
  async function scaffoldMcpMarker(projectRoot, anonKey) {
285
467
  const dirPath = path.join(projectRoot, ".glasstrace");
286
468
  const markerPath = path.join(dirPath, "mcp-connected");
@@ -304,15 +486,19 @@ async function scaffoldMcpMarker(projectRoot, anonKey) {
304
486
  fs.chmodSync(markerPath, 384);
305
487
  return true;
306
488
  }
307
- var import_node_crypto, fs, path;
489
+ var import_node_crypto, fs, path, INSTRUMENTATION_FILENAMES;
308
490
  var init_scaffolder = __esm({
309
491
  "src/cli/scaffolder.ts"() {
310
492
  "use strict";
311
- init_cjs_shims();
312
- import_node_crypto = require("crypto");
313
- fs = __toESM(require("fs"), 1);
314
- path = __toESM(require("path"), 1);
493
+ import_node_crypto = require("node:crypto");
494
+ fs = __toESM(require("node:fs"), 1);
495
+ path = __toESM(require("node:path"), 1);
315
496
  init_constants();
497
+ INSTRUMENTATION_FILENAMES = [
498
+ "instrumentation.ts",
499
+ "instrumentation.js",
500
+ "instrumentation.mjs"
501
+ ];
316
502
  }
317
503
  });
318
504
 
@@ -378,7 +564,6 @@ var NEVER, $brand, $ZodAsyncError, $ZodEncodeError, globalConfig;
378
564
  var init_core = __esm({
379
565
  "../../node_modules/zod/v4/core/core.js"() {
380
566
  "use strict";
381
- init_cjs_shims();
382
567
  NEVER = Object.freeze({
383
568
  status: "aborted"
384
569
  });
@@ -570,10 +755,10 @@ function mergeDefs(...defs) {
570
755
  function cloneDef(schema) {
571
756
  return mergeDefs(schema._zod.def);
572
757
  }
573
- function getElementAtPath(obj, path8) {
574
- if (!path8)
758
+ function getElementAtPath(obj, path9) {
759
+ if (!path9)
575
760
  return obj;
576
- return path8.reduce((acc, key) => acc?.[key], obj);
761
+ return path9.reduce((acc, key) => acc?.[key], obj);
577
762
  }
578
763
  function promiseAllObject(promisesObj) {
579
764
  const keys = Object.keys(promisesObj);
@@ -885,11 +1070,11 @@ function aborted(x, startIndex = 0) {
885
1070
  }
886
1071
  return false;
887
1072
  }
888
- function prefixIssues(path8, issues) {
1073
+ function prefixIssues(path9, issues) {
889
1074
  return issues.map((iss) => {
890
1075
  var _a2;
891
1076
  (_a2 = iss).path ?? (_a2.path = []);
892
- iss.path.unshift(path8);
1077
+ iss.path.unshift(path9);
893
1078
  return iss;
894
1079
  });
895
1080
  }
@@ -1004,7 +1189,6 @@ var EVALUATING, captureStackTrace, allowsEval, getParsedType, propertyKeyTypes,
1004
1189
  var init_util = __esm({
1005
1190
  "../../node_modules/zod/v4/core/util.js"() {
1006
1191
  "use strict";
1007
- init_cjs_shims();
1008
1192
  EVALUATING = /* @__PURE__ */ Symbol("evaluating");
1009
1193
  captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
1010
1194
  };
@@ -1133,7 +1317,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
1133
1317
  }
1134
1318
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
1135
1319
  const result = { errors: [] };
1136
- const processError = (error49, path8 = []) => {
1320
+ const processError = (error49, path9 = []) => {
1137
1321
  var _a2, _b;
1138
1322
  for (const issue2 of error49.issues) {
1139
1323
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -1143,7 +1327,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
1143
1327
  } else if (issue2.code === "invalid_element") {
1144
1328
  processError({ issues: issue2.issues }, issue2.path);
1145
1329
  } else {
1146
- const fullpath = [...path8, ...issue2.path];
1330
+ const fullpath = [...path9, ...issue2.path];
1147
1331
  if (fullpath.length === 0) {
1148
1332
  result.errors.push(mapper(issue2));
1149
1333
  continue;
@@ -1175,8 +1359,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
1175
1359
  }
1176
1360
  function toDotPath(_path) {
1177
1361
  const segs = [];
1178
- const path8 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1179
- for (const seg of path8) {
1362
+ const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1363
+ for (const seg of path9) {
1180
1364
  if (typeof seg === "number")
1181
1365
  segs.push(`[${seg}]`);
1182
1366
  else if (typeof seg === "symbol")
@@ -1205,7 +1389,6 @@ var initializer, $ZodError, $ZodRealError;
1205
1389
  var init_errors = __esm({
1206
1390
  "../../node_modules/zod/v4/core/errors.js"() {
1207
1391
  "use strict";
1208
- init_cjs_shims();
1209
1392
  init_core();
1210
1393
  init_util();
1211
1394
  initializer = (inst, def) => {
@@ -1234,7 +1417,6 @@ var _parse, parse, _parseAsync, parseAsync, _safeParse, safeParse, _safeParseAsy
1234
1417
  var init_parse = __esm({
1235
1418
  "../../node_modules/zod/v4/core/parse.js"() {
1236
1419
  "use strict";
1237
- init_cjs_shims();
1238
1420
  init_core();
1239
1421
  init_errors();
1240
1422
  init_util();
@@ -1420,7 +1602,6 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, extendedDuration, guid, uui
1420
1602
  var init_regexes = __esm({
1421
1603
  "../../node_modules/zod/v4/core/regexes.js"() {
1422
1604
  "use strict";
1423
- init_cjs_shims();
1424
1605
  init_util();
1425
1606
  cuid = /^[cC][^\s-]{8,}$/;
1426
1607
  cuid2 = /^[0-9a-z]+$/;
@@ -1502,7 +1683,6 @@ var $ZodCheck, numericOriginMap, $ZodCheckLessThan, $ZodCheckGreaterThan, $ZodCh
1502
1683
  var init_checks = __esm({
1503
1684
  "../../node_modules/zod/v4/core/checks.js"() {
1504
1685
  "use strict";
1505
- init_cjs_shims();
1506
1686
  init_core();
1507
1687
  init_regexes();
1508
1688
  init_util();
@@ -2055,7 +2235,6 @@ var Doc;
2055
2235
  var init_doc = __esm({
2056
2236
  "../../node_modules/zod/v4/core/doc.js"() {
2057
2237
  "use strict";
2058
- init_cjs_shims();
2059
2238
  Doc = class {
2060
2239
  constructor(args = []) {
2061
2240
  this.content = [];
@@ -2098,7 +2277,6 @@ var version;
2098
2277
  var init_versions = __esm({
2099
2278
  "../../node_modules/zod/v4/core/versions.js"() {
2100
2279
  "use strict";
2101
- init_cjs_shims();
2102
2280
  version = {
2103
2281
  major: 4,
2104
2282
  minor: 3,
@@ -2469,7 +2647,6 @@ var $ZodType, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, $ZodU
2469
2647
  var init_schemas = __esm({
2470
2648
  "../../node_modules/zod/v4/core/schemas.js"() {
2471
2649
  "use strict";
2472
- init_cjs_shims();
2473
2650
  init_checks();
2474
2651
  init_core();
2475
2652
  init_doc();
@@ -4103,7 +4280,6 @@ var error;
4103
4280
  var init_ar = __esm({
4104
4281
  "../../node_modules/zod/v4/locales/ar.js"() {
4105
4282
  "use strict";
4106
- init_cjs_shims();
4107
4283
  init_util();
4108
4284
  error = () => {
4109
4285
  const Sizable = {
@@ -4218,7 +4394,6 @@ var error2;
4218
4394
  var init_az = __esm({
4219
4395
  "../../node_modules/zod/v4/locales/az.js"() {
4220
4396
  "use strict";
4221
- init_cjs_shims();
4222
4397
  init_util();
4223
4398
  error2 = () => {
4224
4399
  const Sizable = {
@@ -4347,7 +4522,6 @@ var error3;
4347
4522
  var init_be = __esm({
4348
4523
  "../../node_modules/zod/v4/locales/be.js"() {
4349
4524
  "use strict";
4350
- init_cjs_shims();
4351
4525
  init_util();
4352
4526
  error3 = () => {
4353
4527
  const Sizable = {
@@ -4497,7 +4671,6 @@ var error4;
4497
4671
  var init_bg = __esm({
4498
4672
  "../../node_modules/zod/v4/locales/bg.js"() {
4499
4673
  "use strict";
4500
- init_cjs_shims();
4501
4674
  init_util();
4502
4675
  error4 = () => {
4503
4676
  const Sizable = {
@@ -4626,7 +4799,6 @@ var error5;
4626
4799
  var init_ca = __esm({
4627
4800
  "../../node_modules/zod/v4/locales/ca.js"() {
4628
4801
  "use strict";
4629
- init_cjs_shims();
4630
4802
  init_util();
4631
4803
  error5 = () => {
4632
4804
  const Sizable = {
@@ -4743,7 +4915,6 @@ var error6;
4743
4915
  var init_cs = __esm({
4744
4916
  "../../node_modules/zod/v4/locales/cs.js"() {
4745
4917
  "use strict";
4746
- init_cjs_shims();
4747
4918
  init_util();
4748
4919
  error6 = () => {
4749
4920
  const Sizable = {
@@ -4863,7 +5034,6 @@ var error7;
4863
5034
  var init_da = __esm({
4864
5035
  "../../node_modules/zod/v4/locales/da.js"() {
4865
5036
  "use strict";
4866
- init_cjs_shims();
4867
5037
  init_util();
4868
5038
  error7 = () => {
4869
5039
  const Sizable = {
@@ -4987,7 +5157,6 @@ var error8;
4987
5157
  var init_de = __esm({
4988
5158
  "../../node_modules/zod/v4/locales/de.js"() {
4989
5159
  "use strict";
4990
- init_cjs_shims();
4991
5160
  init_util();
4992
5161
  error8 = () => {
4993
5162
  const Sizable = {
@@ -5104,7 +5273,6 @@ var error9;
5104
5273
  var init_en = __esm({
5105
5274
  "../../node_modules/zod/v4/locales/en.js"() {
5106
5275
  "use strict";
5107
- init_cjs_shims();
5108
5276
  init_util();
5109
5277
  error9 = () => {
5110
5278
  const Sizable = {
@@ -5221,7 +5389,6 @@ var error10;
5221
5389
  var init_eo = __esm({
5222
5390
  "../../node_modules/zod/v4/locales/eo.js"() {
5223
5391
  "use strict";
5224
- init_cjs_shims();
5225
5392
  init_util();
5226
5393
  error10 = () => {
5227
5394
  const Sizable = {
@@ -5339,7 +5506,6 @@ var error11;
5339
5506
  var init_es = __esm({
5340
5507
  "../../node_modules/zod/v4/locales/es.js"() {
5341
5508
  "use strict";
5342
- init_cjs_shims();
5343
5509
  init_util();
5344
5510
  error11 = () => {
5345
5511
  const Sizable = {
@@ -5480,7 +5646,6 @@ var error12;
5480
5646
  var init_fa = __esm({
5481
5647
  "../../node_modules/zod/v4/locales/fa.js"() {
5482
5648
  "use strict";
5483
- init_cjs_shims();
5484
5649
  init_util();
5485
5650
  error12 = () => {
5486
5651
  const Sizable = {
@@ -5603,7 +5768,6 @@ var error13;
5603
5768
  var init_fi = __esm({
5604
5769
  "../../node_modules/zod/v4/locales/fi.js"() {
5605
5770
  "use strict";
5606
- init_cjs_shims();
5607
5771
  init_util();
5608
5772
  error13 = () => {
5609
5773
  const Sizable = {
@@ -5724,7 +5888,6 @@ var error14;
5724
5888
  var init_fr = __esm({
5725
5889
  "../../node_modules/zod/v4/locales/fr.js"() {
5726
5890
  "use strict";
5727
- init_cjs_shims();
5728
5891
  init_util();
5729
5892
  error14 = () => {
5730
5893
  const Sizable = {
@@ -5841,7 +6004,6 @@ var error15;
5841
6004
  var init_fr_CA = __esm({
5842
6005
  "../../node_modules/zod/v4/locales/fr-CA.js"() {
5843
6006
  "use strict";
5844
- init_cjs_shims();
5845
6007
  init_util();
5846
6008
  error15 = () => {
5847
6009
  const Sizable = {
@@ -5957,7 +6119,6 @@ var error16;
5957
6119
  var init_he = __esm({
5958
6120
  "../../node_modules/zod/v4/locales/he.js"() {
5959
6121
  "use strict";
5960
- init_cjs_shims();
5961
6122
  init_util();
5962
6123
  error16 = () => {
5963
6124
  const TypeNames = {
@@ -6160,7 +6321,6 @@ var error17;
6160
6321
  var init_hu = __esm({
6161
6322
  "../../node_modules/zod/v4/locales/hu.js"() {
6162
6323
  "use strict";
6163
- init_cjs_shims();
6164
6324
  init_util();
6165
6325
  error17 = () => {
6166
6326
  const Sizable = {
@@ -6287,7 +6447,6 @@ var error18;
6287
6447
  var init_hy = __esm({
6288
6448
  "../../node_modules/zod/v4/locales/hy.js"() {
6289
6449
  "use strict";
6290
- init_cjs_shims();
6291
6450
  init_util();
6292
6451
  error18 = () => {
6293
6452
  const Sizable = {
@@ -6433,7 +6592,6 @@ var error19;
6433
6592
  var init_id = __esm({
6434
6593
  "../../node_modules/zod/v4/locales/id.js"() {
6435
6594
  "use strict";
6436
- init_cjs_shims();
6437
6595
  init_util();
6438
6596
  error19 = () => {
6439
6597
  const Sizable = {
@@ -6548,7 +6706,6 @@ var error20;
6548
6706
  var init_is = __esm({
6549
6707
  "../../node_modules/zod/v4/locales/is.js"() {
6550
6708
  "use strict";
6551
- init_cjs_shims();
6552
6709
  init_util();
6553
6710
  error20 = () => {
6554
6711
  const Sizable = {
@@ -6666,7 +6823,6 @@ var error21;
6666
6823
  var init_it = __esm({
6667
6824
  "../../node_modules/zod/v4/locales/it.js"() {
6668
6825
  "use strict";
6669
- init_cjs_shims();
6670
6826
  init_util();
6671
6827
  error21 = () => {
6672
6828
  const Sizable = {
@@ -6783,7 +6939,6 @@ var error22;
6783
6939
  var init_ja = __esm({
6784
6940
  "../../node_modules/zod/v4/locales/ja.js"() {
6785
6941
  "use strict";
6786
- init_cjs_shims();
6787
6942
  init_util();
6788
6943
  error22 = () => {
6789
6944
  const Sizable = {
@@ -6899,7 +7054,6 @@ var error23;
6899
7054
  var init_ka = __esm({
6900
7055
  "../../node_modules/zod/v4/locales/ka.js"() {
6901
7056
  "use strict";
6902
- init_cjs_shims();
6903
7057
  init_util();
6904
7058
  error23 = () => {
6905
7059
  const Sizable = {
@@ -7020,7 +7174,6 @@ var error24;
7020
7174
  var init_km = __esm({
7021
7175
  "../../node_modules/zod/v4/locales/km.js"() {
7022
7176
  "use strict";
7023
- init_cjs_shims();
7024
7177
  init_util();
7025
7178
  error24 = () => {
7026
7179
  const Sizable = {
@@ -7136,7 +7289,6 @@ function kh_default() {
7136
7289
  var init_kh = __esm({
7137
7290
  "../../node_modules/zod/v4/locales/kh.js"() {
7138
7291
  "use strict";
7139
- init_cjs_shims();
7140
7292
  init_km();
7141
7293
  }
7142
7294
  });
@@ -7151,7 +7303,6 @@ var error25;
7151
7303
  var init_ko = __esm({
7152
7304
  "../../node_modules/zod/v4/locales/ko.js"() {
7153
7305
  "use strict";
7154
- init_cjs_shims();
7155
7306
  init_util();
7156
7307
  error25 = () => {
7157
7308
  const Sizable = {
@@ -7281,7 +7432,6 @@ var capitalizeFirstCharacter, error26;
7281
7432
  var init_lt = __esm({
7282
7433
  "../../node_modules/zod/v4/locales/lt.js"() {
7283
7434
  "use strict";
7284
- init_cjs_shims();
7285
7435
  init_util();
7286
7436
  capitalizeFirstCharacter = (text) => {
7287
7437
  return text.charAt(0).toUpperCase() + text.slice(1);
@@ -7483,7 +7633,6 @@ var error27;
7483
7633
  var init_mk = __esm({
7484
7634
  "../../node_modules/zod/v4/locales/mk.js"() {
7485
7635
  "use strict";
7486
- init_cjs_shims();
7487
7636
  init_util();
7488
7637
  error27 = () => {
7489
7638
  const Sizable = {
@@ -7601,7 +7750,6 @@ var error28;
7601
7750
  var init_ms = __esm({
7602
7751
  "../../node_modules/zod/v4/locales/ms.js"() {
7603
7752
  "use strict";
7604
- init_cjs_shims();
7605
7753
  init_util();
7606
7754
  error28 = () => {
7607
7755
  const Sizable = {
@@ -7717,7 +7865,6 @@ var error29;
7717
7865
  var init_nl = __esm({
7718
7866
  "../../node_modules/zod/v4/locales/nl.js"() {
7719
7867
  "use strict";
7720
- init_cjs_shims();
7721
7868
  init_util();
7722
7869
  error29 = () => {
7723
7870
  const Sizable = {
@@ -7836,7 +7983,6 @@ var error30;
7836
7983
  var init_no = __esm({
7837
7984
  "../../node_modules/zod/v4/locales/no.js"() {
7838
7985
  "use strict";
7839
- init_cjs_shims();
7840
7986
  init_util();
7841
7987
  error30 = () => {
7842
7988
  const Sizable = {
@@ -7953,7 +8099,6 @@ var error31;
7953
8099
  var init_ota = __esm({
7954
8100
  "../../node_modules/zod/v4/locales/ota.js"() {
7955
8101
  "use strict";
7956
- init_cjs_shims();
7957
8102
  init_util();
7958
8103
  error31 = () => {
7959
8104
  const Sizable = {
@@ -8071,7 +8216,6 @@ var error32;
8071
8216
  var init_ps = __esm({
8072
8217
  "../../node_modules/zod/v4/locales/ps.js"() {
8073
8218
  "use strict";
8074
- init_cjs_shims();
8075
8219
  init_util();
8076
8220
  error32 = () => {
8077
8221
  const Sizable = {
@@ -8194,7 +8338,6 @@ var error33;
8194
8338
  var init_pl = __esm({
8195
8339
  "../../node_modules/zod/v4/locales/pl.js"() {
8196
8340
  "use strict";
8197
- init_cjs_shims();
8198
8341
  init_util();
8199
8342
  error33 = () => {
8200
8343
  const Sizable = {
@@ -8312,7 +8455,6 @@ var error34;
8312
8455
  var init_pt = __esm({
8313
8456
  "../../node_modules/zod/v4/locales/pt.js"() {
8314
8457
  "use strict";
8315
- init_cjs_shims();
8316
8458
  init_util();
8317
8459
  error34 = () => {
8318
8460
  const Sizable = {
@@ -8444,7 +8586,6 @@ var error35;
8444
8586
  var init_ru = __esm({
8445
8587
  "../../node_modules/zod/v4/locales/ru.js"() {
8446
8588
  "use strict";
8447
- init_cjs_shims();
8448
8589
  init_util();
8449
8590
  error35 = () => {
8450
8591
  const Sizable = {
@@ -8594,7 +8735,6 @@ var error36;
8594
8735
  var init_sl = __esm({
8595
8736
  "../../node_modules/zod/v4/locales/sl.js"() {
8596
8737
  "use strict";
8597
- init_cjs_shims();
8598
8738
  init_util();
8599
8739
  error36 = () => {
8600
8740
  const Sizable = {
@@ -8712,7 +8852,6 @@ var error37;
8712
8852
  var init_sv = __esm({
8713
8853
  "../../node_modules/zod/v4/locales/sv.js"() {
8714
8854
  "use strict";
8715
- init_cjs_shims();
8716
8855
  init_util();
8717
8856
  error37 = () => {
8718
8857
  const Sizable = {
@@ -8831,7 +8970,6 @@ var error38;
8831
8970
  var init_ta = __esm({
8832
8971
  "../../node_modules/zod/v4/locales/ta.js"() {
8833
8972
  "use strict";
8834
- init_cjs_shims();
8835
8973
  init_util();
8836
8974
  error38 = () => {
8837
8975
  const Sizable = {
@@ -8950,7 +9088,6 @@ var error39;
8950
9088
  var init_th = __esm({
8951
9089
  "../../node_modules/zod/v4/locales/th.js"() {
8952
9090
  "use strict";
8953
- init_cjs_shims();
8954
9091
  init_util();
8955
9092
  error39 = () => {
8956
9093
  const Sizable = {
@@ -9069,7 +9206,6 @@ var error40;
9069
9206
  var init_tr = __esm({
9070
9207
  "../../node_modules/zod/v4/locales/tr.js"() {
9071
9208
  "use strict";
9072
- init_cjs_shims();
9073
9209
  init_util();
9074
9210
  error40 = () => {
9075
9211
  const Sizable = {
@@ -9183,7 +9319,6 @@ var error41;
9183
9319
  var init_uk = __esm({
9184
9320
  "../../node_modules/zod/v4/locales/uk.js"() {
9185
9321
  "use strict";
9186
- init_cjs_shims();
9187
9322
  init_util();
9188
9323
  error41 = () => {
9189
9324
  const Sizable = {
@@ -9297,7 +9432,6 @@ function ua_default() {
9297
9432
  var init_ua = __esm({
9298
9433
  "../../node_modules/zod/v4/locales/ua.js"() {
9299
9434
  "use strict";
9300
- init_cjs_shims();
9301
9435
  init_uk();
9302
9436
  }
9303
9437
  });
@@ -9312,7 +9446,6 @@ var error42;
9312
9446
  var init_ur = __esm({
9313
9447
  "../../node_modules/zod/v4/locales/ur.js"() {
9314
9448
  "use strict";
9315
- init_cjs_shims();
9316
9449
  init_util();
9317
9450
  error42 = () => {
9318
9451
  const Sizable = {
@@ -9431,7 +9564,6 @@ var error43;
9431
9564
  var init_uz = __esm({
9432
9565
  "../../node_modules/zod/v4/locales/uz.js"() {
9433
9566
  "use strict";
9434
- init_cjs_shims();
9435
9567
  init_util();
9436
9568
  error43 = () => {
9437
9569
  const Sizable = {
@@ -9549,7 +9681,6 @@ var error44;
9549
9681
  var init_vi = __esm({
9550
9682
  "../../node_modules/zod/v4/locales/vi.js"() {
9551
9683
  "use strict";
9552
- init_cjs_shims();
9553
9684
  init_util();
9554
9685
  error44 = () => {
9555
9686
  const Sizable = {
@@ -9666,7 +9797,6 @@ var error45;
9666
9797
  var init_zh_CN = __esm({
9667
9798
  "../../node_modules/zod/v4/locales/zh-CN.js"() {
9668
9799
  "use strict";
9669
- init_cjs_shims();
9670
9800
  init_util();
9671
9801
  error45 = () => {
9672
9802
  const Sizable = {
@@ -9784,7 +9914,6 @@ var error46;
9784
9914
  var init_zh_TW = __esm({
9785
9915
  "../../node_modules/zod/v4/locales/zh-TW.js"() {
9786
9916
  "use strict";
9787
- init_cjs_shims();
9788
9917
  init_util();
9789
9918
  error46 = () => {
9790
9919
  const Sizable = {
@@ -9900,7 +10029,6 @@ var error47;
9900
10029
  var init_yo = __esm({
9901
10030
  "../../node_modules/zod/v4/locales/yo.js"() {
9902
10031
  "use strict";
9903
- init_cjs_shims();
9904
10032
  init_util();
9905
10033
  error47 = () => {
9906
10034
  const Sizable = {
@@ -10062,7 +10190,6 @@ __export(locales_exports, {
10062
10190
  var init_locales = __esm({
10063
10191
  "../../node_modules/zod/v4/locales/index.js"() {
10064
10192
  "use strict";
10065
- init_cjs_shims();
10066
10193
  init_ar();
10067
10194
  init_az();
10068
10195
  init_be();
@@ -10123,7 +10250,6 @@ var _a, $output, $input, $ZodRegistry, globalRegistry;
10123
10250
  var init_registries = __esm({
10124
10251
  "../../node_modules/zod/v4/core/registries.js"() {
10125
10252
  "use strict";
10126
- init_cjs_shims();
10127
10253
  $output = /* @__PURE__ */ Symbol("ZodOutput");
10128
10254
  $input = /* @__PURE__ */ Symbol("ZodInput");
10129
10255
  $ZodRegistry = class {
@@ -11206,7 +11332,6 @@ var TimePrecision;
11206
11332
  var init_api = __esm({
11207
11333
  "../../node_modules/zod/v4/core/api.js"() {
11208
11334
  "use strict";
11209
- init_cjs_shims();
11210
11335
  init_checks();
11211
11336
  init_registries();
11212
11337
  init_schemas();
@@ -11563,7 +11688,6 @@ var createToJSONSchemaMethod, createStandardJSONSchemaMethod;
11563
11688
  var init_to_json_schema = __esm({
11564
11689
  "../../node_modules/zod/v4/core/to-json-schema.js"() {
11565
11690
  "use strict";
11566
- init_cjs_shims();
11567
11691
  init_registries();
11568
11692
  createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
11569
11693
  const ctx = initializeContext({ ...params, processors });
@@ -11620,7 +11744,6 @@ var formatMap, stringProcessor, numberProcessor, booleanProcessor, bigintProcess
11620
11744
  var init_json_schema_processors = __esm({
11621
11745
  "../../node_modules/zod/v4/core/json-schema-processors.js"() {
11622
11746
  "use strict";
11623
- init_cjs_shims();
11624
11747
  init_to_json_schema();
11625
11748
  init_util();
11626
11749
  formatMap = {
@@ -12146,7 +12269,6 @@ var JSONSchemaGenerator;
12146
12269
  var init_json_schema_generator = __esm({
12147
12270
  "../../node_modules/zod/v4/core/json-schema-generator.js"() {
12148
12271
  "use strict";
12149
- init_cjs_shims();
12150
12272
  init_json_schema_processors();
12151
12273
  init_to_json_schema();
12152
12274
  JSONSchemaGenerator = class {
@@ -12230,7 +12352,6 @@ var json_schema_exports = {};
12230
12352
  var init_json_schema = __esm({
12231
12353
  "../../node_modules/zod/v4/core/json-schema.js"() {
12232
12354
  "use strict";
12233
- init_cjs_shims();
12234
12355
  }
12235
12356
  });
12236
12357
 
@@ -12514,7 +12635,6 @@ __export(core_exports2, {
12514
12635
  var init_core2 = __esm({
12515
12636
  "../../node_modules/zod/v4/core/index.js"() {
12516
12637
  "use strict";
12517
- init_cjs_shims();
12518
12638
  init_core();
12519
12639
  init_parse();
12520
12640
  init_errors();
@@ -12570,7 +12690,6 @@ __export(checks_exports2, {
12570
12690
  var init_checks2 = __esm({
12571
12691
  "../../node_modules/zod/v4/classic/checks.js"() {
12572
12692
  "use strict";
12573
- init_cjs_shims();
12574
12693
  init_core2();
12575
12694
  }
12576
12695
  });
@@ -12603,7 +12722,6 @@ var ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration;
12603
12722
  var init_iso = __esm({
12604
12723
  "../../node_modules/zod/v4/classic/iso.js"() {
12605
12724
  "use strict";
12606
- init_cjs_shims();
12607
12725
  init_core2();
12608
12726
  init_schemas2();
12609
12727
  ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
@@ -12630,7 +12748,6 @@ var initializer2, ZodError, ZodRealError;
12630
12748
  var init_errors2 = __esm({
12631
12749
  "../../node_modules/zod/v4/classic/errors.js"() {
12632
12750
  "use strict";
12633
- init_cjs_shims();
12634
12751
  init_core2();
12635
12752
  init_core2();
12636
12753
  init_util();
@@ -12680,7 +12797,6 @@ var parse2, parseAsync2, safeParse2, safeParseAsync2, encode2, decode2, encodeAs
12680
12797
  var init_parse2 = __esm({
12681
12798
  "../../node_modules/zod/v4/classic/parse.js"() {
12682
12799
  "use strict";
12683
- init_cjs_shims();
12684
12800
  init_core2();
12685
12801
  init_errors2();
12686
12802
  parse2 = /* @__PURE__ */ _parse(ZodRealError);
@@ -13324,7 +13440,6 @@ var ZodType, _ZodString, ZodString, ZodStringFormat, ZodEmail, ZodGUID, ZodUUID,
13324
13440
  var init_schemas2 = __esm({
13325
13441
  "../../node_modules/zod/v4/classic/schemas.js"() {
13326
13442
  "use strict";
13327
- init_cjs_shims();
13328
13443
  init_core2();
13329
13444
  init_core2();
13330
13445
  init_json_schema_processors();
@@ -13971,7 +14086,6 @@ var ZodIssueCode, ZodFirstPartyTypeKind;
13971
14086
  var init_compat = __esm({
13972
14087
  "../../node_modules/zod/v4/classic/compat.js"() {
13973
14088
  "use strict";
13974
- init_cjs_shims();
13975
14089
  init_core2();
13976
14090
  init_core2();
13977
14091
  ZodIssueCode = {
@@ -14010,13 +14124,13 @@ function resolveRef(ref, ctx) {
14010
14124
  if (!ref.startsWith("#")) {
14011
14125
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14012
14126
  }
14013
- const path8 = ref.slice(1).split("/").filter(Boolean);
14014
- if (path8.length === 0) {
14127
+ const path9 = ref.slice(1).split("/").filter(Boolean);
14128
+ if (path9.length === 0) {
14015
14129
  return ctx.rootSchema;
14016
14130
  }
14017
14131
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14018
- if (path8[0] === defsKey) {
14019
- const key = path8[1];
14132
+ if (path9[0] === defsKey) {
14133
+ const key = path9[1];
14020
14134
  if (!key || !ctx.defs[key]) {
14021
14135
  throw new Error(`Reference not found: ${ref}`);
14022
14136
  }
@@ -14393,7 +14507,6 @@ var z, RECOGNIZED_KEYS;
14393
14507
  var init_from_json_schema = __esm({
14394
14508
  "../../node_modules/zod/v4/classic/from-json-schema.js"() {
14395
14509
  "use strict";
14396
- init_cjs_shims();
14397
14510
  init_registries();
14398
14511
  init_checks2();
14399
14512
  init_iso();
@@ -14504,7 +14617,6 @@ function date4(params) {
14504
14617
  var init_coerce = __esm({
14505
14618
  "../../node_modules/zod/v4/classic/coerce.js"() {
14506
14619
  "use strict";
14507
- init_cjs_shims();
14508
14620
  init_core2();
14509
14621
  init_schemas2();
14510
14622
  }
@@ -14753,7 +14865,6 @@ __export(external_exports, {
14753
14865
  var init_external = __esm({
14754
14866
  "../../node_modules/zod/v4/classic/external.js"() {
14755
14867
  "use strict";
14756
- init_cjs_shims();
14757
14868
  init_core2();
14758
14869
  init_schemas2();
14759
14870
  init_checks2();
@@ -14777,7 +14888,6 @@ var init_external = __esm({
14777
14888
  var init_zod = __esm({
14778
14889
  "../../node_modules/zod/index.js"() {
14779
14890
  "use strict";
14780
- init_cjs_shims();
14781
14891
  init_external();
14782
14892
  init_external();
14783
14893
  }
@@ -14799,7 +14909,6 @@ var DevApiKeySchema, AnonApiKeySchema, SessionIdSchema, BuildHashSchema, SdkDiag
14799
14909
  var init_dist = __esm({
14800
14910
  "../protocol/dist/index.js"() {
14801
14911
  "use strict";
14802
- init_cjs_shims();
14803
14912
  init_zod();
14804
14913
  init_zod();
14805
14914
  init_zod();
@@ -14935,11 +15044,11 @@ var init_dist = __esm({
14935
15044
  async function loadFsPath() {
14936
15045
  if (fsPathCache !== void 0) return fsPathCache;
14937
15046
  try {
14938
- const [fs8, path8] = await Promise.all([
14939
- import("fs/promises"),
14940
- import("path")
15047
+ const [fs9, path9] = await Promise.all([
15048
+ import("node:fs/promises"),
15049
+ import("node:path")
14941
15050
  ]);
14942
- fsPathCache = { fs: fs8, path: path8 };
15051
+ fsPathCache = { fs: fs9, path: path9 };
14943
15052
  return fsPathCache;
14944
15053
  } catch {
14945
15054
  fsPathCache = null;
@@ -15018,7 +15127,6 @@ var GLASSTRACE_DIR, ANON_KEY_FILE, fsPathCache, ephemeralKeyCache;
15018
15127
  var init_anon_key = __esm({
15019
15128
  "src/anon-key.ts"() {
15020
15129
  "use strict";
15021
- init_cjs_shims();
15022
15130
  init_dist();
15023
15131
  GLASSTRACE_DIR = ".glasstrace";
15024
15132
  ANON_KEY_FILE = "anon_key";
@@ -15027,9 +15135,9 @@ var init_anon_key = __esm({
15027
15135
  });
15028
15136
 
15029
15137
  // src/agent-detection/detect.ts
15030
- async function pathExists(path8, mode = import_node_fs.constants.R_OK) {
15138
+ async function pathExists(path9, mode = import_node_fs.constants.R_OK) {
15031
15139
  try {
15032
- await (0, import_promises.access)(path8, mode);
15140
+ await (0, import_promises.access)(path9, mode);
15033
15141
  return true;
15034
15142
  } catch {
15035
15143
  return false;
@@ -15135,12 +15243,11 @@ var import_node_child_process, import_promises, import_node_path, import_node_os
15135
15243
  var init_detect = __esm({
15136
15244
  "src/agent-detection/detect.ts"() {
15137
15245
  "use strict";
15138
- init_cjs_shims();
15139
- import_node_child_process = require("child_process");
15140
- import_promises = require("fs/promises");
15141
- import_node_path = require("path");
15142
- import_node_os = require("os");
15143
- import_node_fs = require("fs");
15246
+ import_node_child_process = require("node:child_process");
15247
+ import_promises = require("node:fs/promises");
15248
+ import_node_path = require("node:path");
15249
+ import_node_os = require("node:os");
15250
+ import_node_fs = require("node:fs");
15144
15251
  AGENT_RULES = [
15145
15252
  {
15146
15253
  name: "claude",
@@ -15350,7 +15457,6 @@ ${content}${m.end}
15350
15457
  var init_configs = __esm({
15351
15458
  "src/agent-detection/configs.ts"() {
15352
15459
  "use strict";
15353
- init_cjs_shims();
15354
15460
  }
15355
15461
  });
15356
15462
 
@@ -15528,9 +15634,8 @@ var import_promises2, import_node_path2, HTML_START, HTML_END, HASH_START, HASH_
15528
15634
  var init_inject = __esm({
15529
15635
  "src/agent-detection/inject.ts"() {
15530
15636
  "use strict";
15531
- init_cjs_shims();
15532
- import_promises2 = require("fs/promises");
15533
- import_node_path2 = require("path");
15637
+ import_promises2 = require("node:fs/promises");
15638
+ import_node_path2 = require("node:path");
15534
15639
  HTML_START = "<!-- glasstrace:mcp:start -->";
15535
15640
  HTML_END = "<!-- glasstrace:mcp:end -->";
15536
15641
  HASH_START = "# glasstrace:mcp:start";
@@ -15777,9 +15882,8 @@ var fs3, path3;
15777
15882
  var init_monorepo = __esm({
15778
15883
  "src/cli/monorepo.ts"() {
15779
15884
  "use strict";
15780
- init_cjs_shims();
15781
- fs3 = __toESM(require("fs"), 1);
15782
- path3 = __toESM(require("path"), 1);
15885
+ fs3 = __toESM(require("node:fs"), 1);
15886
+ path3 = __toESM(require("node:path"), 1);
15783
15887
  init_constants();
15784
15888
  }
15785
15889
  });
@@ -15798,7 +15902,8 @@ __export(uninit_exports, {
15798
15902
  runUninit: () => runUninit,
15799
15903
  skipString: () => skipString,
15800
15904
  unwrapCJSExport: () => unwrapCJSExport,
15801
- unwrapExport: () => unwrapExport
15905
+ unwrapExport: () => unwrapExport,
15906
+ writeShutdownMarker: () => writeShutdownMarker
15802
15907
  });
15803
15908
  function skipString(text, start, quote) {
15804
15909
  let i = start + 1;
@@ -16099,12 +16204,75 @@ function processTomlMcpConfig(content) {
16099
16204
  }
16100
16205
  return { action: "removed-section", content: result + "\n" };
16101
16206
  }
16207
+ function writeShutdownMarker(projectRoot) {
16208
+ const dirPath = path4.join(projectRoot, ".glasstrace");
16209
+ if (!fs4.existsSync(dirPath)) {
16210
+ return false;
16211
+ }
16212
+ const markerPath = path4.join(dirPath, "shutdown-requested");
16213
+ const tmpPath = `${markerPath}.tmp`;
16214
+ const body = JSON.stringify({ requestedAt: (/* @__PURE__ */ new Date()).toISOString() });
16215
+ try {
16216
+ fs4.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
16217
+ try {
16218
+ fs4.chmodSync(tmpPath, 384);
16219
+ } catch {
16220
+ }
16221
+ fs4.renameSync(tmpPath, markerPath);
16222
+ return true;
16223
+ } catch {
16224
+ try {
16225
+ fs4.unlinkSync(tmpPath);
16226
+ } catch {
16227
+ }
16228
+ return false;
16229
+ }
16230
+ }
16231
+ async function defaultPrompt(question, defaultValue) {
16232
+ if (!process.stdin.isTTY) return defaultValue;
16233
+ const readline2 = await import("node:readline");
16234
+ const rl = readline2.createInterface({
16235
+ input: process.stdin,
16236
+ output: process.stdout
16237
+ });
16238
+ return new Promise((resolve2) => {
16239
+ const suffix = defaultValue ? " [Y/n] " : " [y/N] ";
16240
+ rl.question(question + suffix, (answer) => {
16241
+ rl.close();
16242
+ const trimmed = answer.trim().toLowerCase();
16243
+ if (trimmed === "") {
16244
+ resolve2(defaultValue);
16245
+ return;
16246
+ }
16247
+ resolve2(trimmed === "y" || trimmed === "yes");
16248
+ });
16249
+ });
16250
+ }
16102
16251
  async function runUninit(options) {
16103
16252
  const { projectRoot, dryRun } = options;
16253
+ const force = options.force === true;
16254
+ const prompt = options.prompt ?? defaultPrompt;
16104
16255
  const summary = [];
16105
16256
  const warnings = [];
16106
16257
  const errors = [];
16107
16258
  const prefix = dryRun ? "[dry run] " : "";
16259
+ try {
16260
+ if (!dryRun) {
16261
+ const markerWritten = writeShutdownMarker(projectRoot);
16262
+ if (markerWritten) {
16263
+ summary.push("Wrote .glasstrace/shutdown-requested marker");
16264
+ }
16265
+ } else {
16266
+ const dirPath = path4.join(projectRoot, ".glasstrace");
16267
+ if (fs4.existsSync(dirPath)) {
16268
+ summary.push(`${prefix}Would write .glasstrace/shutdown-requested marker`);
16269
+ }
16270
+ }
16271
+ } catch (err) {
16272
+ warnings.push(
16273
+ `Shutdown marker write failed: ${err instanceof Error ? err.message : String(err)}`
16274
+ );
16275
+ }
16108
16276
  try {
16109
16277
  let configHandled = false;
16110
16278
  for (const name of NEXT_CONFIG_NAMES) {
@@ -16187,23 +16355,57 @@ async function runUninit(options) {
16187
16355
  const envPath = path4.join(projectRoot, ".env.local");
16188
16356
  if (fs4.existsSync(envPath)) {
16189
16357
  const content = fs4.readFileSync(envPath, "utf-8");
16190
- const lines = content.split("\n");
16191
- const filtered = lines.filter((line) => {
16192
- const trimmed = line.trim();
16193
- return !(/^\s*#?\s*GLASSTRACE_API_KEY\s*=/.test(trimmed) || /^\s*#?\s*GLASSTRACE_COVERAGE_MAP\s*=/.test(trimmed));
16194
- });
16195
- if (filtered.length !== lines.length) {
16196
- const result = filtered.join("\n");
16197
- if (result.trim().length === 0) {
16198
- if (!dryRun) {
16199
- fs4.unlinkSync(envPath);
16200
- }
16201
- summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
16358
+ const existingKey = readEnvLocalApiKey(content);
16359
+ const hasDevKey = isDevApiKey(existingKey);
16360
+ let proceed = true;
16361
+ let devKeyPath = "none";
16362
+ if (hasDevKey) {
16363
+ if (dryRun) {
16364
+ devKeyPath = "dry-run-preview";
16365
+ } else if (force) {
16366
+ devKeyPath = "force-bypass";
16202
16367
  } else {
16203
- if (!dryRun) {
16204
- fs4.writeFileSync(envPath, result, "utf-8");
16368
+ const confirmed = await prompt(
16369
+ ".env.local contains a claimed Glasstrace developer API key (gt_dev_...). Removing it will require you to re-authenticate. Continue?",
16370
+ false
16371
+ );
16372
+ proceed = confirmed;
16373
+ if (confirmed) devKeyPath = "interactive-confirmed";
16374
+ }
16375
+ }
16376
+ if (!proceed) {
16377
+ warnings.push(
16378
+ "Preserved GLASSTRACE_API_KEY in .env.local (claimed dev key; re-run with --force to remove)"
16379
+ );
16380
+ } else {
16381
+ const lines = content.split("\n");
16382
+ const filtered = lines.filter((line) => {
16383
+ const trimmed = line.trim();
16384
+ return !(/^\s*#?\s*GLASSTRACE_API_KEY\s*=/.test(trimmed) || /^\s*#?\s*GLASSTRACE_COVERAGE_MAP\s*=/.test(trimmed));
16385
+ });
16386
+ if (filtered.length !== lines.length) {
16387
+ const result = filtered.join("\n");
16388
+ if (result.trim().length === 0) {
16389
+ if (!dryRun) {
16390
+ fs4.unlinkSync(envPath);
16391
+ }
16392
+ summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
16393
+ } else {
16394
+ if (!dryRun) {
16395
+ fs4.writeFileSync(envPath, result, "utf-8");
16396
+ }
16397
+ let devKeyAnnotation = "";
16398
+ if (devKeyPath === "interactive-confirmed") {
16399
+ devKeyAnnotation = " (dev key confirmed)";
16400
+ } else if (devKeyPath === "force-bypass") {
16401
+ devKeyAnnotation = " (dev key removed via --force)";
16402
+ } else if (devKeyPath === "dry-run-preview") {
16403
+ devKeyAnnotation = " (dev key would be removed; real run would require confirmation)";
16404
+ }
16405
+ summary.push(
16406
+ `${prefix}Removed GLASSTRACE entries from .env.local${devKeyAnnotation}`
16407
+ );
16205
16408
  }
16206
- summary.push(`${prefix}Removed GLASSTRACE entries from .env.local`);
16207
16409
  }
16208
16410
  }
16209
16411
  }
@@ -16354,11 +16556,11 @@ var fs4, os, path4, MCP_CONFIG_FILES, AGENT_INFO_FILES;
16354
16556
  var init_uninit = __esm({
16355
16557
  "src/cli/uninit.ts"() {
16356
16558
  "use strict";
16357
- init_cjs_shims();
16358
- fs4 = __toESM(require("fs"), 1);
16359
- os = __toESM(require("os"), 1);
16360
- path4 = __toESM(require("path"), 1);
16559
+ fs4 = __toESM(require("node:fs"), 1);
16560
+ os = __toESM(require("node:os"), 1);
16561
+ path4 = __toESM(require("node:path"), 1);
16361
16562
  init_constants();
16563
+ init_scaffolder();
16362
16564
  MCP_CONFIG_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json"];
16363
16565
  AGENT_INFO_FILES = [
16364
16566
  "CLAUDE.md",
@@ -16584,11 +16786,10 @@ var import_node_child_process2, fs5, path5, import_node_util, execFileAsync;
16584
16786
  var init_mcp_add = __esm({
16585
16787
  "src/cli/mcp-add.ts"() {
16586
16788
  "use strict";
16587
- init_cjs_shims();
16588
- import_node_child_process2 = require("child_process");
16589
- fs5 = __toESM(require("fs"), 1);
16590
- path5 = __toESM(require("path"), 1);
16591
- import_node_util = require("util");
16789
+ import_node_child_process2 = require("node:child_process");
16790
+ fs5 = __toESM(require("node:fs"), 1);
16791
+ path5 = __toESM(require("node:path"), 1);
16792
+ import_node_util = require("node:util");
16592
16793
  init_anon_key();
16593
16794
  init_detect();
16594
16795
  init_configs();
@@ -16599,6 +16800,111 @@ var init_mcp_add = __esm({
16599
16800
  }
16600
16801
  });
16601
16802
 
16803
+ // src/cli/validate.ts
16804
+ var validate_exports = {};
16805
+ __export(validate_exports, {
16806
+ hasGlasstraceImport: () => hasGlasstraceImport,
16807
+ hasRegisterGlasstraceImport: () => hasRegisterGlasstraceImport,
16808
+ runValidate: () => runValidate
16809
+ });
16810
+ function hasGlasstraceImport(content) {
16811
+ return /@glasstrace\/sdk/.test(content);
16812
+ }
16813
+ function hasRegisterGlasstraceImport(content) {
16814
+ const match = /import\s*\{([^}]+)\}\s*from\s*["']@glasstrace\/sdk["']/;
16815
+ const importMatch = match.exec(content);
16816
+ if (!importMatch) return false;
16817
+ return importMatch[1].split(",").map((s) => s.trim()).includes("registerGlasstrace");
16818
+ }
16819
+ function runValidate(options) {
16820
+ const { projectRoot } = options;
16821
+ const issues = [];
16822
+ const glasstraceDir = path6.join(projectRoot, ".glasstrace");
16823
+ const instrumentationPath = path6.join(projectRoot, "instrumentation.ts");
16824
+ const markerPath = path6.join(glasstraceDir, "mcp-connected");
16825
+ const glasstraceDirExists = isDirectorySafe(glasstraceDir);
16826
+ const instrumentationExists = fs6.existsSync(instrumentationPath);
16827
+ const instrumentationContent = instrumentationExists ? safeReadFile(instrumentationPath) : null;
16828
+ const markerExists = fs6.existsSync(markerPath);
16829
+ const mcpConfigsPresent = MCP_CONFIG_CANDIDATES.filter(
16830
+ (rel) => fs6.existsSync(path6.join(projectRoot, rel))
16831
+ );
16832
+ if (glasstraceDirExists) {
16833
+ if (instrumentationContent === null || !hasRegisterGlasstraceImport(instrumentationContent)) {
16834
+ issues.push({
16835
+ code: "glasstrace-dir-without-register-import",
16836
+ message: ".glasstrace/ exists but instrumentation.ts is missing the registerGlasstrace import.",
16837
+ fix: "Run `npx glasstrace init` to re-scaffold instrumentation.ts, or remove .glasstrace/ if the SDK is no longer in use."
16838
+ });
16839
+ }
16840
+ }
16841
+ if (!glasstraceDirExists && instrumentationContent !== null) {
16842
+ if (hasGlasstraceImport(instrumentationContent)) {
16843
+ issues.push({
16844
+ code: "sdk-import-without-glasstrace-dir",
16845
+ message: "instrumentation.ts imports from @glasstrace/sdk but .glasstrace/ is missing.",
16846
+ fix: "Run `npx glasstrace init` to recreate .glasstrace/, or `npx glasstrace uninit` to fully remove the SDK."
16847
+ });
16848
+ }
16849
+ }
16850
+ if (markerExists && mcpConfigsPresent.length === 0) {
16851
+ issues.push({
16852
+ code: "mcp-marker-without-configs",
16853
+ message: ".glasstrace/mcp-connected marker is present but no MCP config files were found.",
16854
+ fix: "Run `npx glasstrace mcp add --force` to regenerate MCP configs, or delete .glasstrace/mcp-connected."
16855
+ });
16856
+ }
16857
+ if (!markerExists && mcpConfigsPresent.length > 0) {
16858
+ issues.push({
16859
+ code: "mcp-configs-without-marker",
16860
+ message: `MCP config files exist (${mcpConfigsPresent.join(", ")}) but .glasstrace/mcp-connected marker is missing.`,
16861
+ fix: "Run `npx glasstrace init` to re-register the marker, or `npx glasstrace uninit` to fully remove MCP configuration."
16862
+ });
16863
+ }
16864
+ const summary = [];
16865
+ if (issues.length === 0) {
16866
+ summary.push("Glasstrace install state is consistent.");
16867
+ } else {
16868
+ summary.push(
16869
+ `Detected ${issues.length} inconsistenc${issues.length === 1 ? "y" : "ies"} in Glasstrace install state:`
16870
+ );
16871
+ }
16872
+ return {
16873
+ exitCode: issues.length > 0 ? 1 : 0,
16874
+ summary,
16875
+ issues
16876
+ };
16877
+ }
16878
+ function safeReadFile(filePath) {
16879
+ try {
16880
+ return fs6.readFileSync(filePath, "utf-8");
16881
+ } catch {
16882
+ return null;
16883
+ }
16884
+ }
16885
+ function isDirectorySafe(dirPath) {
16886
+ try {
16887
+ if (!fs6.existsSync(dirPath)) return false;
16888
+ return fs6.statSync(dirPath).isDirectory();
16889
+ } catch {
16890
+ return false;
16891
+ }
16892
+ }
16893
+ var fs6, path6, MCP_CONFIG_CANDIDATES;
16894
+ var init_validate = __esm({
16895
+ "src/cli/validate.ts"() {
16896
+ "use strict";
16897
+ fs6 = __toESM(require("node:fs"), 1);
16898
+ path6 = __toESM(require("node:path"), 1);
16899
+ MCP_CONFIG_CANDIDATES = [
16900
+ ".mcp.json",
16901
+ ".cursor/mcp.json",
16902
+ ".gemini/settings.json",
16903
+ ".codex/config.toml"
16904
+ ];
16905
+ }
16906
+ });
16907
+
16602
16908
  // src/cli/status.ts
16603
16909
  var status_exports = {};
16604
16910
  __export(status_exports, {
@@ -16619,8 +16925,8 @@ function runStatus(options) {
16619
16925
  }
16620
16926
  function checkInstalled(root) {
16621
16927
  try {
16622
- const pkgPath = path6.join(root, "package.json");
16623
- const content = fs6.readFileSync(pkgPath, "utf-8");
16928
+ const pkgPath = path7.join(root, "package.json");
16929
+ const content = fs7.readFileSync(pkgPath, "utf-8");
16624
16930
  const pkg = JSON.parse(content);
16625
16931
  const deps = pkg["dependencies"];
16626
16932
  const devDeps = pkg["devDependencies"];
@@ -16631,7 +16937,7 @@ function checkInstalled(root) {
16631
16937
  }
16632
16938
  function checkInitialized(root) {
16633
16939
  try {
16634
- return fs6.statSync(path6.join(root, ".glasstrace")).isDirectory();
16940
+ return fs7.statSync(path7.join(root, ".glasstrace")).isDirectory();
16635
16941
  } catch {
16636
16942
  return false;
16637
16943
  }
@@ -16639,7 +16945,7 @@ function checkInitialized(root) {
16639
16945
  function checkInstrumentation(root) {
16640
16946
  for (const name of INSTRUMENTATION_FILES) {
16641
16947
  try {
16642
- const content = fs6.readFileSync(path6.join(root, name), "utf-8");
16948
+ const content = fs7.readFileSync(path7.join(root, name), "utf-8");
16643
16949
  if (content.includes("registerGlasstrace")) {
16644
16950
  return true;
16645
16951
  }
@@ -16651,7 +16957,7 @@ function checkInstrumentation(root) {
16651
16957
  function checkConfigWrapped(root) {
16652
16958
  for (const name of NEXT_CONFIG_NAMES) {
16653
16959
  try {
16654
- const content = fs6.readFileSync(path6.join(root, name), "utf-8");
16960
+ const content = fs7.readFileSync(path7.join(root, name), "utf-8");
16655
16961
  if (content.includes("withGlasstraceConfig")) {
16656
16962
  return true;
16657
16963
  }
@@ -16662,7 +16968,7 @@ function checkConfigWrapped(root) {
16662
16968
  }
16663
16969
  function checkAnonKey(root) {
16664
16970
  try {
16665
- return fs6.statSync(path6.join(root, ".glasstrace", "anon_key")).isFile();
16971
+ return fs7.statSync(path7.join(root, ".glasstrace", "anon_key")).isFile();
16666
16972
  } catch {
16667
16973
  return false;
16668
16974
  }
@@ -16670,7 +16976,7 @@ function checkAnonKey(root) {
16670
16976
  function checkMcpConfigured(root) {
16671
16977
  for (const name of MCP_JSON_FILES) {
16672
16978
  try {
16673
- const content = fs6.readFileSync(path6.join(root, name), "utf-8");
16979
+ const content = fs7.readFileSync(path7.join(root, name), "utf-8");
16674
16980
  const parsed = JSON.parse(content);
16675
16981
  const mcpServers = parsed["mcpServers"];
16676
16982
  if (mcpServers && typeof mcpServers === "object" && "glasstrace" in mcpServers) {
@@ -16681,7 +16987,7 @@ function checkMcpConfigured(root) {
16681
16987
  }
16682
16988
  for (const name of MCP_TOML_FILES) {
16683
16989
  try {
16684
- const content = fs6.readFileSync(path6.join(root, name), "utf-8");
16990
+ const content = fs7.readFileSync(path7.join(root, name), "utf-8");
16685
16991
  if (content.includes("[mcp_servers.glasstrace]")) {
16686
16992
  return true;
16687
16993
  }
@@ -16694,7 +17000,7 @@ function checkAgents(root) {
16694
17000
  const found = [];
16695
17001
  for (const name of AGENT_INFO_FILES2) {
16696
17002
  try {
16697
- const content = fs6.readFileSync(path6.join(root, name), "utf-8");
17003
+ const content = fs7.readFileSync(path7.join(root, name), "utf-8");
16698
17004
  const hasHtmlMarkers = content.includes("<!-- glasstrace:mcp:start -->") && content.includes("<!-- glasstrace:mcp:end -->");
16699
17005
  const hasHashMarkers = content.includes("# glasstrace:mcp:start") && content.includes("# glasstrace:mcp:end");
16700
17006
  if (hasHtmlMarkers || hasHashMarkers) {
@@ -16717,8 +17023,8 @@ function readRuntimeState(root) {
16717
17023
  pid: null
16718
17024
  };
16719
17025
  try {
16720
- const filePath = path6.join(root, ".glasstrace", "runtime-state.json");
16721
- const content = fs6.readFileSync(filePath, "utf-8");
17026
+ const filePath = path7.join(root, ".glasstrace", "runtime-state.json");
17027
+ const content = fs7.readFileSync(filePath, "utf-8");
16722
17028
  const parsed = JSON.parse(content);
16723
17029
  const updatedAt = typeof parsed.updatedAt === "string" ? parsed.updatedAt : null;
16724
17030
  const pid = typeof parsed.pid === "number" ? parsed.pid : null;
@@ -16767,13 +17073,12 @@ function readRuntimeState(root) {
16767
17073
  return empty;
16768
17074
  }
16769
17075
  }
16770
- var fs6, path6, MCP_JSON_FILES, MCP_TOML_FILES, AGENT_INFO_FILES2, INSTRUMENTATION_FILES, STALE_THRESHOLD_MS;
17076
+ var fs7, path7, MCP_JSON_FILES, MCP_TOML_FILES, AGENT_INFO_FILES2, INSTRUMENTATION_FILES, STALE_THRESHOLD_MS;
16771
17077
  var init_status = __esm({
16772
17078
  "src/cli/status.ts"() {
16773
17079
  "use strict";
16774
- init_cjs_shims();
16775
- fs6 = __toESM(require("fs"), 1);
16776
- path6 = __toESM(require("path"), 1);
17080
+ fs7 = __toESM(require("node:fs"), 1);
17081
+ path7 = __toESM(require("node:path"), 1);
16777
17082
  init_constants();
16778
17083
  MCP_JSON_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json", ".glasstrace/mcp.json"];
16779
17084
  MCP_TOML_FILES = [".codex/config.toml"];
@@ -16797,23 +17102,23 @@ var init_status = __esm({
16797
17102
  // src/cli/init.ts
16798
17103
  var init_exports = {};
16799
17104
  __export(init_exports, {
17105
+ decideMcpConfigAction: () => decideMcpConfigAction,
16800
17106
  meetsNodeVersion: () => meetsNodeVersion,
16801
17107
  rollbackSteps: () => rollbackSteps,
16802
- runInit: () => runInit
17108
+ runInit: () => runInit,
17109
+ verifyAnonKeyRegistration: () => verifyAnonKeyRegistration
16803
17110
  });
16804
17111
  module.exports = __toCommonJS(init_exports);
16805
- init_cjs_shims();
16806
- var fs7 = __toESM(require("fs"), 1);
16807
- var path7 = __toESM(require("path"), 1);
16808
- var readline = __toESM(require("readline"), 1);
17112
+ var fs8 = __toESM(require("node:fs"), 1);
17113
+ var path8 = __toESM(require("node:path"), 1);
17114
+ var readline = __toESM(require("node:readline"), 1);
16809
17115
  init_scaffolder();
16810
17116
 
16811
17117
  // src/import-graph.ts
16812
- init_cjs_shims();
16813
- var fs2 = __toESM(require("fs/promises"), 1);
16814
- var fsSync = __toESM(require("fs"), 1);
16815
- var path2 = __toESM(require("path"), 1);
16816
- var crypto2 = __toESM(require("crypto"), 1);
17118
+ var fs2 = __toESM(require("node:fs/promises"), 1);
17119
+ var fsSync = __toESM(require("node:fs"), 1);
17120
+ var path2 = __toESM(require("node:path"), 1);
17121
+ var crypto2 = __toESM(require("node:crypto"), 1);
16817
17122
  init_dist();
16818
17123
  var MAX_TEST_FILES = 5e3;
16819
17124
  var EXCLUDED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".next", ".git", "dist", ".turbo"]);
@@ -16986,10 +17291,382 @@ init_inject();
16986
17291
  init_constants();
16987
17292
  init_monorepo();
16988
17293
  init_uninit();
17294
+
17295
+ // src/init-client.ts
17296
+ init_dist();
17297
+
17298
+ // src/https-transport.ts
17299
+ var import_node_https = require("node:https");
17300
+ var import_node_http = require("node:http");
17301
+ var import_node_url = require("node:url");
17302
+ var HttpsTransportError = class extends Error {
17303
+ kind = "transport";
17304
+ cause;
17305
+ constructor(message, cause) {
17306
+ super(message);
17307
+ this.name = "HttpsTransportError";
17308
+ this.cause = cause;
17309
+ }
17310
+ };
17311
+ var HttpsStatusError = class extends Error {
17312
+ kind = "status";
17313
+ status;
17314
+ /** Raw response body text (may be truncated by caller if large). */
17315
+ body;
17316
+ constructor(status, body) {
17317
+ super(`Server returned HTTP ${status}`);
17318
+ this.name = "HttpsStatusError";
17319
+ this.status = status;
17320
+ this.body = body;
17321
+ }
17322
+ };
17323
+ var HttpsBodyParseError = class extends Error {
17324
+ kind = "parse";
17325
+ status;
17326
+ cause;
17327
+ constructor(status, cause) {
17328
+ super(`Server returned malformed response (HTTP ${status})`);
17329
+ this.name = "HttpsBodyParseError";
17330
+ this.status = status;
17331
+ this.cause = cause;
17332
+ }
17333
+ };
17334
+ var DEFAULT_TIMEOUT_MS = 1e4;
17335
+ var DEFAULT_RETRY_DELAYS_MS = [500, 1500];
17336
+ var DEFAULT_TOTAL_DEADLINE_MS = 2e4;
17337
+ async function httpsPostJson(url2, jsonBody, options) {
17338
+ const parsed = new import_node_url.URL(url2);
17339
+ const isHttps = parsed.protocol === "https:";
17340
+ const isHttp = parsed.protocol === "http:";
17341
+ if (!isHttps && !isHttp) {
17342
+ throw new HttpsTransportError(
17343
+ `Unsupported protocol: ${parsed.protocol} (expected http: or https:)`
17344
+ );
17345
+ }
17346
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
17347
+ const maxAttempts = options.maxAttempts ?? 3;
17348
+ const retryDelaysMs = options.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS;
17349
+ const totalDeadlineMs = options.totalDeadlineMs ?? DEFAULT_TOTAL_DEADLINE_MS;
17350
+ const scheduler = options.scheduler ?? ((fn, ms) => setTimeout(fn, ms));
17351
+ const requestImpl = isHttps ? options.requestImpl ?? import_node_https.request : options.httpRequestImpl ?? import_node_http.request;
17352
+ let payload;
17353
+ try {
17354
+ payload = JSON.stringify(jsonBody);
17355
+ } catch (err) {
17356
+ throw new HttpsTransportError(
17357
+ `Failed to serialize request body: ${err instanceof Error ? err.message : String(err)}`,
17358
+ err
17359
+ );
17360
+ }
17361
+ const payloadBuffer = Buffer.from(payload, "utf-8");
17362
+ const startedAt = Date.now();
17363
+ let lastError;
17364
+ for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
17365
+ if (options.signal?.aborted) {
17366
+ throw new HttpsTransportError("Request aborted");
17367
+ }
17368
+ const elapsed = Date.now() - startedAt;
17369
+ if (elapsed >= totalDeadlineMs) {
17370
+ break;
17371
+ }
17372
+ const remainingBudget = totalDeadlineMs - elapsed;
17373
+ const attemptTimeoutMs = Math.min(timeoutMs, remainingBudget);
17374
+ try {
17375
+ return await sendSingleRequest(
17376
+ parsed,
17377
+ payloadBuffer,
17378
+ options.headers,
17379
+ attemptTimeoutMs,
17380
+ options.signal,
17381
+ requestImpl
17382
+ );
17383
+ } catch (err) {
17384
+ lastError = err;
17385
+ if (err instanceof HttpsStatusError || err instanceof HttpsBodyParseError) {
17386
+ throw err;
17387
+ }
17388
+ const isLast = attempt === maxAttempts - 1;
17389
+ if (isLast) break;
17390
+ const delayMs = retryDelaysMs[attempt] ?? retryDelaysMs[retryDelaysMs.length - 1] ?? 0;
17391
+ const elapsedBeforeSleep = Date.now() - startedAt;
17392
+ const remaining = totalDeadlineMs - elapsedBeforeSleep;
17393
+ if (remaining <= 0) break;
17394
+ const actualDelayMs = Math.min(delayMs, remaining);
17395
+ await sleep(actualDelayMs, scheduler, options.signal);
17396
+ }
17397
+ }
17398
+ if (lastError instanceof HttpsTransportError) throw lastError;
17399
+ throw new HttpsTransportError(
17400
+ lastError instanceof Error ? lastError.message : "Request failed",
17401
+ lastError
17402
+ );
17403
+ }
17404
+ function sendSingleRequest(url2, payload, headers, timeoutMs, signal, requestImpl) {
17405
+ return new Promise((resolve2, reject) => {
17406
+ const finalHeaders = {
17407
+ ...headers,
17408
+ "Content-Length": payload.byteLength
17409
+ };
17410
+ const reqOptions = {
17411
+ method: "POST",
17412
+ hostname: url2.hostname,
17413
+ port: url2.port === "" ? void 0 : Number(url2.port),
17414
+ path: `${url2.pathname}${url2.search}`,
17415
+ headers: finalHeaders,
17416
+ // Explicit timeout at the socket level. Still complemented by a
17417
+ // manual timer below because `timeout` only fires when the socket
17418
+ // is idle — it does not cover "TLS handshake hangs forever".
17419
+ timeout: timeoutMs
17420
+ };
17421
+ let settled = false;
17422
+ let cleanup = () => {
17423
+ };
17424
+ const settle = (fn) => {
17425
+ if (settled) return;
17426
+ settled = true;
17427
+ cleanup();
17428
+ fn();
17429
+ };
17430
+ const req = requestImpl(reqOptions, (res) => {
17431
+ const chunks = [];
17432
+ res.on("data", (chunk) => {
17433
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk, "utf-8") : chunk);
17434
+ });
17435
+ res.on("end", () => {
17436
+ const raw = Buffer.concat(chunks).toString("utf-8");
17437
+ const status = res.statusCode ?? 0;
17438
+ if (status < 200 || status >= 300) {
17439
+ settle(() => reject(new HttpsStatusError(status, raw)));
17440
+ return;
17441
+ }
17442
+ if (status === 204 || raw.length === 0) {
17443
+ settle(() => resolve2({ status, body: void 0, raw }));
17444
+ return;
17445
+ }
17446
+ try {
17447
+ const parsed = JSON.parse(raw);
17448
+ settle(() => resolve2({ status, body: parsed, raw }));
17449
+ } catch (err) {
17450
+ settle(() => reject(new HttpsBodyParseError(status, err)));
17451
+ }
17452
+ });
17453
+ res.on("error", (err) => {
17454
+ settle(() => reject(new HttpsTransportError(`Response stream error: ${err.message}`, err)));
17455
+ });
17456
+ });
17457
+ const timer = setTimeout(() => {
17458
+ settle(() => {
17459
+ req.destroy(new Error("Request timed out"));
17460
+ reject(new HttpsTransportError(`Request timed out after ${timeoutMs}ms`));
17461
+ });
17462
+ }, timeoutMs);
17463
+ if (typeof timer.unref === "function") timer.unref();
17464
+ const onAbort = () => {
17465
+ settle(() => {
17466
+ req.destroy(new Error("Aborted"));
17467
+ reject(new HttpsTransportError("Request aborted"));
17468
+ });
17469
+ };
17470
+ cleanup = () => {
17471
+ clearTimeout(timer);
17472
+ if (signal !== void 0) {
17473
+ signal.removeEventListener("abort", onAbort);
17474
+ }
17475
+ };
17476
+ req.on("error", (err) => {
17477
+ settle(() => reject(new HttpsTransportError(`fetch failed: ${err.message}`, err)));
17478
+ });
17479
+ req.on("timeout", () => {
17480
+ settle(() => {
17481
+ req.destroy(new Error("Request timed out"));
17482
+ reject(new HttpsTransportError(`Request timed out after ${timeoutMs}ms`));
17483
+ });
17484
+ });
17485
+ if (signal !== void 0) {
17486
+ if (signal.aborted) {
17487
+ req.destroy(new Error("Aborted"));
17488
+ settle(() => reject(new HttpsTransportError("Request aborted")));
17489
+ return;
17490
+ }
17491
+ signal.addEventListener("abort", onAbort, { once: true });
17492
+ }
17493
+ req.end(payload);
17494
+ });
17495
+ }
17496
+ function sleep(ms, scheduler, signal) {
17497
+ return new Promise((resolve2, reject) => {
17498
+ let settled = false;
17499
+ let cleanup = () => {
17500
+ };
17501
+ const settle = (fn) => {
17502
+ if (settled) return;
17503
+ settled = true;
17504
+ cleanup();
17505
+ fn();
17506
+ };
17507
+ const onAbort = () => {
17508
+ settle(() => reject(new HttpsTransportError("Request aborted")));
17509
+ };
17510
+ const timer = scheduler(() => {
17511
+ settle(resolve2);
17512
+ }, ms);
17513
+ if (typeof timer.unref === "function") timer.unref();
17514
+ cleanup = () => {
17515
+ clearTimeout(timer);
17516
+ if (signal !== void 0) {
17517
+ signal.removeEventListener("abort", onAbort);
17518
+ }
17519
+ };
17520
+ if (signal !== void 0) {
17521
+ if (signal.aborted) {
17522
+ onAbort();
17523
+ return;
17524
+ }
17525
+ signal.addEventListener("abort", onAbort, { once: true });
17526
+ }
17527
+ });
17528
+ }
17529
+
17530
+ // src/init-client.ts
17531
+ var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
17532
+ var INIT_TIMEOUT_MS = 1e4;
17533
+ var transportOverride = null;
17534
+ async function sendInitRequest(config2, anonKey, sdkVersion, importGraph, healthReport, diagnostics, signal) {
17535
+ const effectiveKey = config2.apiKey || anonKey;
17536
+ if (!effectiveKey) {
17537
+ throw new Error("No API key available for init request");
17538
+ }
17539
+ const payload = {
17540
+ sdkVersion
17541
+ };
17542
+ if (config2.apiKey && anonKey) {
17543
+ payload.anonKey = anonKey;
17544
+ }
17545
+ if (config2.environment) {
17546
+ payload.environment = config2.environment;
17547
+ }
17548
+ if (importGraph) {
17549
+ payload.importGraph = importGraph;
17550
+ }
17551
+ if (healthReport) {
17552
+ payload.healthReport = healthReport;
17553
+ }
17554
+ if (diagnostics) {
17555
+ payload.diagnostics = diagnostics;
17556
+ }
17557
+ const url2 = `${config2.endpoint}/v1/sdk/init`;
17558
+ const transport = transportOverride ?? httpsPostJson;
17559
+ let result;
17560
+ try {
17561
+ result = await transport(url2, payload, {
17562
+ headers: {
17563
+ "Content-Type": "application/json",
17564
+ Authorization: `Bearer ${effectiveKey}`
17565
+ },
17566
+ timeoutMs: INIT_TIMEOUT_MS,
17567
+ signal
17568
+ });
17569
+ } catch (err) {
17570
+ if (err instanceof HttpsStatusError) {
17571
+ const error48 = new Error(`Init request failed with status ${err.status}`);
17572
+ error48.status = err.status;
17573
+ throw error48;
17574
+ }
17575
+ if (err instanceof HttpsBodyParseError) {
17576
+ const cause = err.cause;
17577
+ if (cause instanceof SyntaxError) throw cause;
17578
+ throw err;
17579
+ }
17580
+ if (err instanceof HttpsTransportError) {
17581
+ throw err;
17582
+ }
17583
+ throw err;
17584
+ }
17585
+ return SdkInitResponseSchema.parse(result.body);
17586
+ }
17587
+ async function verifyInitReachable(config2, anonKey, sdkVersion) {
17588
+ try {
17589
+ const response = await sendInitRequest(config2, anonKey, sdkVersion);
17590
+ return { ok: true, response };
17591
+ } catch (err) {
17592
+ const status = err.status;
17593
+ if (typeof status === "number") {
17594
+ return {
17595
+ ok: false,
17596
+ reason: "rejected",
17597
+ status,
17598
+ detail: `server returned HTTP ${status}`
17599
+ };
17600
+ }
17601
+ if (err instanceof Error && (err.name === "ZodError" || err.name === "SyntaxError")) {
17602
+ return {
17603
+ ok: false,
17604
+ reason: "malformed",
17605
+ detail: "server returned malformed response"
17606
+ };
17607
+ }
17608
+ const rawMessage = err instanceof Error ? err.message : String(err);
17609
+ const detail = rawMessage.startsWith("fetch failed: ") ? rawMessage.slice("fetch failed: ".length) : rawMessage;
17610
+ return { ok: false, reason: "transport", detail };
17611
+ }
17612
+ }
17613
+
17614
+ // src/env-detection.ts
17615
+ var DEFAULT_ENDPOINT = "https://api.glasstrace.dev";
17616
+ function readEnvVars() {
17617
+ return {
17618
+ GLASSTRACE_API_KEY: process.env.GLASSTRACE_API_KEY?.trim() || void 0,
17619
+ GLASSTRACE_FORCE_ENABLE: process.env.GLASSTRACE_FORCE_ENABLE,
17620
+ GLASSTRACE_ENV: process.env.GLASSTRACE_ENV,
17621
+ GLASSTRACE_COVERAGE_MAP: process.env.GLASSTRACE_COVERAGE_MAP,
17622
+ NODE_ENV: process.env.NODE_ENV,
17623
+ VERCEL_ENV: process.env.VERCEL_ENV
17624
+ };
17625
+ }
17626
+ function resolveConfig(options) {
17627
+ const env = readEnvVars();
17628
+ return {
17629
+ apiKey: options?.apiKey ?? env.GLASSTRACE_API_KEY,
17630
+ endpoint: options?.endpoint ?? DEFAULT_ENDPOINT,
17631
+ forceEnable: options?.forceEnable ?? env.GLASSTRACE_FORCE_ENABLE === "true",
17632
+ verbose: options?.verbose ?? false,
17633
+ environment: env.GLASSTRACE_ENV,
17634
+ coverageMapEnabled: env.GLASSTRACE_COVERAGE_MAP === "true",
17635
+ nodeEnv: env.NODE_ENV,
17636
+ vercelEnv: env.VERCEL_ENV
17637
+ };
17638
+ }
17639
+
17640
+ // src/cli/init.ts
16989
17641
  function meetsNodeVersion(minMajor) {
16990
17642
  const [major] = process.versions.node.split(".").map(Number);
16991
17643
  return major >= minMajor;
16992
17644
  }
17645
+ async function decideMcpConfigAction(options) {
17646
+ const { configPath, expectedContent, force } = options;
17647
+ if (configPath === null) return "write";
17648
+ const exists = options.existsSync ?? fs8.existsSync;
17649
+ const read = options.readFile ?? ((p) => fs8.readFileSync(p, "utf-8"));
17650
+ const prompt = options.prompt ?? promptYesNo;
17651
+ if (!exists(configPath)) return "write";
17652
+ let existingContent;
17653
+ try {
17654
+ existingContent = read(configPath);
17655
+ } catch {
17656
+ return "write";
17657
+ }
17658
+ if (mcpConfigMatches(existingContent, expectedContent)) {
17659
+ return "write";
17660
+ }
17661
+ if (force) {
17662
+ return "force-overwrite";
17663
+ }
17664
+ const answer = await prompt(
17665
+ `Existing MCP config at ${configPath} differs from Glasstrace's template. Overwrite?`,
17666
+ false
17667
+ );
17668
+ return answer ? "force-overwrite" : "skip";
17669
+ }
16993
17670
  async function promptYesNo(question, defaultValue) {
16994
17671
  if (!process.stdin.isTTY) {
16995
17672
  return defaultValue;
@@ -17019,17 +17696,17 @@ async function rollbackSteps(steps, projectRoot, state) {
17019
17696
  try {
17020
17697
  switch (step) {
17021
17698
  case "instrumentation": {
17022
- const instrPath = path7.join(projectRoot, "instrumentation.ts");
17023
- if (fs7.existsSync(instrPath)) {
17024
- const content = fs7.readFileSync(instrPath, "utf-8");
17699
+ const instrPath = state?.instrumentationPath ?? path8.join(projectRoot, "instrumentation.ts");
17700
+ if (fs8.existsSync(instrPath)) {
17701
+ const content = fs8.readFileSync(instrPath, "utf-8");
17025
17702
  if (isInitCreatedInstrumentation(content)) {
17026
- fs7.unlinkSync(instrPath);
17703
+ fs8.unlinkSync(instrPath);
17027
17704
  } else if (state?.originalInstrumentationContent !== void 0) {
17028
- fs7.writeFileSync(instrPath, state.originalInstrumentationContent, "utf-8");
17705
+ fs8.writeFileSync(instrPath, state.originalInstrumentationContent, "utf-8");
17029
17706
  } else {
17030
17707
  const cleaned = removeRegisterGlasstrace(content);
17031
17708
  if (cleaned !== content) {
17032
- fs7.writeFileSync(instrPath, cleaned, "utf-8");
17709
+ fs8.writeFileSync(instrPath, cleaned, "utf-8");
17033
17710
  }
17034
17711
  }
17035
17712
  }
@@ -17037,11 +17714,11 @@ async function rollbackSteps(steps, projectRoot, state) {
17037
17714
  }
17038
17715
  case "next-config": {
17039
17716
  for (const name of NEXT_CONFIG_NAMES) {
17040
- const configPath = path7.join(projectRoot, name);
17041
- if (!fs7.existsSync(configPath)) {
17717
+ const configPath = path8.join(projectRoot, name);
17718
+ if (!fs8.existsSync(configPath)) {
17042
17719
  continue;
17043
17720
  }
17044
- const content = fs7.readFileSync(configPath, "utf-8");
17721
+ const content = fs8.readFileSync(configPath, "utf-8");
17045
17722
  if (!content.includes("withGlasstraceConfig")) {
17046
17723
  continue;
17047
17724
  }
@@ -17049,16 +17726,16 @@ async function rollbackSteps(steps, projectRoot, state) {
17049
17726
  const unwrapResult = isESM ? unwrapExport(content) : unwrapCJSExport(content);
17050
17727
  if (unwrapResult.unwrapped) {
17051
17728
  const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
17052
- fs7.writeFileSync(configPath, cleanLeadingBlankLines2(cleaned), "utf-8");
17729
+ fs8.writeFileSync(configPath, cleanLeadingBlankLines2(cleaned), "utf-8");
17053
17730
  }
17054
17731
  break;
17055
17732
  }
17056
17733
  break;
17057
17734
  }
17058
17735
  case "env-local": {
17059
- const envPath = path7.join(projectRoot, ".env.local");
17060
- if (fs7.existsSync(envPath)) {
17061
- const content = fs7.readFileSync(envPath, "utf-8");
17736
+ const envPath = path8.join(projectRoot, ".env.local");
17737
+ if (fs8.existsSync(envPath)) {
17738
+ const content = fs8.readFileSync(envPath, "utf-8");
17062
17739
  const lines = content.split("\n");
17063
17740
  const filtered = lines.filter((line) => {
17064
17741
  const trimmed = line.trim();
@@ -17067,18 +17744,18 @@ async function rollbackSteps(steps, projectRoot, state) {
17067
17744
  if (filtered.length !== lines.length) {
17068
17745
  const result = filtered.join("\n");
17069
17746
  if (result.trim().length === 0) {
17070
- fs7.unlinkSync(envPath);
17747
+ fs8.unlinkSync(envPath);
17071
17748
  } else {
17072
- fs7.writeFileSync(envPath, result, "utf-8");
17749
+ fs8.writeFileSync(envPath, result, "utf-8");
17073
17750
  }
17074
17751
  }
17075
17752
  }
17076
17753
  break;
17077
17754
  }
17078
17755
  case "gitignore": {
17079
- const gitignorePath = path7.join(projectRoot, ".gitignore");
17080
- if (fs7.existsSync(gitignorePath)) {
17081
- const content = fs7.readFileSync(gitignorePath, "utf-8");
17756
+ const gitignorePath = path8.join(projectRoot, ".gitignore");
17757
+ if (fs8.existsSync(gitignorePath)) {
17758
+ const content = fs8.readFileSync(gitignorePath, "utf-8");
17082
17759
  const lines = content.split("\n");
17083
17760
  const filtered = lines.filter(
17084
17761
  (line) => line.trim() !== ".glasstrace/"
@@ -17086,9 +17763,9 @@ async function rollbackSteps(steps, projectRoot, state) {
17086
17763
  if (filtered.length !== lines.length) {
17087
17764
  const result = filtered.join("\n");
17088
17765
  if (result.trim().length === 0) {
17089
- fs7.unlinkSync(gitignorePath);
17766
+ fs8.unlinkSync(gitignorePath);
17090
17767
  } else {
17091
- fs7.writeFileSync(gitignorePath, result, "utf-8");
17768
+ fs8.writeFileSync(gitignorePath, result, "utf-8");
17092
17769
  }
17093
17770
  }
17094
17771
  }
@@ -17115,39 +17792,83 @@ async function runInit(options) {
17115
17792
  errors.push(err instanceof Error ? err.message : String(err));
17116
17793
  return { exitCode: 1, summary, warnings, errors };
17117
17794
  }
17118
- const packageJsonPath = path7.join(projectRoot, "package.json");
17119
- if (!fs7.existsSync(packageJsonPath)) {
17795
+ const packageJsonPath = path8.join(projectRoot, "package.json");
17796
+ if (!fs8.existsSync(packageJsonPath)) {
17120
17797
  errors.push("No package.json found. Run this command from a Node.js project root.");
17121
17798
  return { exitCode: 1, summary, warnings, errors };
17122
17799
  }
17123
17800
  const rollbackState = { steps: [] };
17124
17801
  try {
17125
- const instrPath = path7.join(projectRoot, "instrumentation.ts");
17126
- if (fs7.existsSync(instrPath)) {
17127
- rollbackState.originalInstrumentationContent = fs7.readFileSync(instrPath, "utf-8");
17802
+ const preResolved = resolveInstrumentationTarget(projectRoot);
17803
+ if (!preResolved.conflict && preResolved.target !== null) {
17804
+ rollbackState.instrumentationPath = preResolved.target;
17805
+ if (fs8.existsSync(preResolved.target)) {
17806
+ rollbackState.originalInstrumentationContent = fs8.readFileSync(
17807
+ preResolved.target,
17808
+ "utf-8"
17809
+ );
17810
+ }
17128
17811
  }
17129
- const instrResult = await scaffoldInstrumentation(projectRoot);
17812
+ const instrResult = await scaffoldInstrumentation(projectRoot, {
17813
+ // `--yes` implies non-interactive automation and must not hang on a
17814
+ // merge confirmation prompt. `--force` skips the prompt explicitly
17815
+ // (DISC-1247 Scenario 2c parity).
17816
+ force: options.force === true || options.yes
17817
+ });
17818
+ if (instrResult.filePath !== void 0) {
17819
+ rollbackState.instrumentationPath = instrResult.filePath;
17820
+ }
17821
+ const relativePath = instrResult.filePath !== void 0 ? path8.relative(projectRoot, instrResult.filePath) : "instrumentation.ts";
17130
17822
  switch (instrResult.action) {
17131
17823
  case "created":
17132
- summary.push("Created instrumentation.ts");
17824
+ summary.push(`Created ${relativePath}`);
17133
17825
  rollbackState.steps.push("instrumentation");
17134
17826
  break;
17135
17827
  case "injected":
17136
- summary.push("Added registerGlasstrace() to existing instrumentation.ts");
17828
+ summary.push(`Added registerGlasstrace() to existing ${relativePath}`);
17829
+ rollbackState.steps.push("instrumentation");
17830
+ break;
17831
+ case "appended":
17832
+ summary.push(
17833
+ `Appended register() with registerGlasstrace() to ${relativePath}`
17834
+ );
17137
17835
  rollbackState.steps.push("instrumentation");
17138
17836
  break;
17139
17837
  case "already-registered":
17140
- summary.push("Skipped instrumentation.ts (registerGlasstrace already present)");
17838
+ summary.push(`Skipped ${relativePath} (registerGlasstrace already present)`);
17141
17839
  break;
17840
+ case "skipped":
17841
+ warnings.push(
17842
+ `Preserved ${relativePath} (merge declined; re-run with --force to apply the merge without prompting)`
17843
+ );
17844
+ break;
17845
+ case "conflict": {
17846
+ const primary = instrResult.filePath !== void 0 ? path8.relative(projectRoot, instrResult.filePath) : "src/instrumentation.ts";
17847
+ const competing = instrResult.conflictingPath !== void 0 ? path8.relative(projectRoot, instrResult.conflictingPath) : "instrumentation.ts";
17848
+ await rollbackSteps(rollbackState.steps, projectRoot, rollbackState);
17849
+ errors.push(
17850
+ `Both ${primary} and ${competing} exist. Next.js's loader behavior is undefined when both are present.
17851
+ Merge your instrumentation into ${primary} and remove ${competing}, then re-run init.`
17852
+ );
17853
+ return { exitCode: 1, summary, warnings, errors };
17854
+ }
17142
17855
  case "unrecognized":
17143
17856
  warnings.push(
17144
- 'instrumentation.ts exists but has no recognizable register() function.\nAdd this import at the top of your file:\n\n import { registerGlasstrace } from "@glasstrace/sdk";\n\nThen add this as the first statement in your register() function:\n\n registerGlasstrace();\n'
17857
+ `${relativePath} exists but has no recognizable register() function.
17858
+ Add this import at the top of your file:
17859
+
17860
+ import { registerGlasstrace } from "@glasstrace/sdk";
17861
+
17862
+ Then add this as the first statement in your register() function:
17863
+
17864
+ registerGlasstrace();
17865
+ `
17145
17866
  );
17146
17867
  break;
17147
17868
  }
17148
17869
  } catch (err) {
17149
17870
  await rollbackSteps(rollbackState.steps, projectRoot, rollbackState);
17150
- errors.push(`Failed to write instrumentation.ts: ${err instanceof Error ? err.message : String(err)}`);
17871
+ errors.push(`Failed to write instrumentation file: ${err instanceof Error ? err.message : String(err)}`);
17151
17872
  return { exitCode: 1, summary, warnings, errors };
17152
17873
  }
17153
17874
  try {
@@ -17170,10 +17891,20 @@ async function runInit(options) {
17170
17891
  return { exitCode: 1, summary, warnings, errors };
17171
17892
  }
17172
17893
  try {
17894
+ const envPathForCheck = path8.join(projectRoot, ".env.local");
17895
+ let existingDevKey = false;
17896
+ if (fs8.existsSync(envPathForCheck)) {
17897
+ const existingContent = fs8.readFileSync(envPathForCheck, "utf-8");
17898
+ existingDevKey = isDevApiKey(readEnvLocalApiKey(existingContent));
17899
+ }
17173
17900
  const envCreated = await scaffoldEnvLocal(projectRoot);
17174
17901
  if (envCreated) {
17175
17902
  summary.push("Updated .env.local with Glasstrace configuration");
17176
17903
  rollbackState.steps.push("env-local");
17904
+ } else if (existingDevKey) {
17905
+ summary.push(
17906
+ "Preserved existing .env.local (GLASSTRACE_API_KEY contains a claimed dev key)"
17907
+ );
17177
17908
  } else {
17178
17909
  summary.push("Skipped .env.local (GLASSTRACE_API_KEY already configured)");
17179
17910
  }
@@ -17198,19 +17929,30 @@ async function runInit(options) {
17198
17929
  const ciEnv = process.env["CI"];
17199
17930
  const isCI = typeof ciEnv === "string" && ciEnv.trim() !== "" && ciEnv.toLowerCase() !== "false" && ciEnv.trim() !== "0" || process.env["GITHUB_ACTIONS"] === "true";
17200
17931
  try {
17932
+ const preExistingAnonKey = await readAnonKey(projectRoot);
17201
17933
  const anonKey = await getOrCreateAnonKey(projectRoot);
17934
+ if (preExistingAnonKey !== null) {
17935
+ summary.push("Preserved existing .glasstrace/anon_key");
17936
+ }
17202
17937
  let anyConfigWritten = false;
17203
17938
  if (isCI) {
17204
17939
  const genericAgent = {
17205
17940
  name: "generic",
17206
- mcpConfigPath: path7.join(projectRoot, ".glasstrace", "mcp.json"),
17941
+ mcpConfigPath: path8.join(projectRoot, ".glasstrace", "mcp.json"),
17207
17942
  infoFilePath: null,
17208
17943
  cliAvailable: false,
17209
17944
  registrationCommand: null
17210
17945
  };
17211
17946
  const genericConfig = generateMcpConfig(genericAgent, MCP_ENDPOINT, anonKey);
17212
- await writeMcpConfig(genericAgent, genericConfig, projectRoot);
17213
- if (genericAgent.mcpConfigPath !== null && fs7.existsSync(genericAgent.mcpConfigPath)) {
17947
+ const decision = await decideMcpConfigAction({
17948
+ configPath: genericAgent.mcpConfigPath,
17949
+ expectedContent: genericConfig,
17950
+ force: true
17951
+ });
17952
+ if (decision !== "skip") {
17953
+ await writeMcpConfig(genericAgent, genericConfig, projectRoot);
17954
+ }
17955
+ if (genericAgent.mcpConfigPath !== null && fs8.existsSync(genericAgent.mcpConfigPath)) {
17214
17956
  anyConfigWritten = true;
17215
17957
  summary.push("Created .glasstrace/mcp.json (CI mode)");
17216
17958
  }
@@ -17224,14 +17966,14 @@ async function runInit(options) {
17224
17966
  );
17225
17967
  const genericAgent = {
17226
17968
  name: "generic",
17227
- mcpConfigPath: path7.join(projectRoot, ".glasstrace", "mcp.json"),
17969
+ mcpConfigPath: path8.join(projectRoot, ".glasstrace", "mcp.json"),
17228
17970
  infoFilePath: null,
17229
17971
  cliAvailable: false,
17230
17972
  registrationCommand: null
17231
17973
  };
17232
17974
  const genericConfig = generateMcpConfig(genericAgent, MCP_ENDPOINT, anonKey);
17233
17975
  await writeMcpConfig(genericAgent, genericConfig, projectRoot);
17234
- if (genericAgent.mcpConfigPath !== null && fs7.existsSync(genericAgent.mcpConfigPath)) {
17976
+ if (genericAgent.mcpConfigPath !== null && fs8.existsSync(genericAgent.mcpConfigPath)) {
17235
17977
  anyConfigWritten = true;
17236
17978
  }
17237
17979
  agents = [];
@@ -17240,8 +17982,22 @@ async function runInit(options) {
17240
17982
  for (const agent of agents) {
17241
17983
  try {
17242
17984
  const configContent = generateMcpConfig(agent, MCP_ENDPOINT, anonKey);
17985
+ const decision = await decideMcpConfigAction({
17986
+ configPath: agent.mcpConfigPath,
17987
+ expectedContent: configContent,
17988
+ force: options.force === true || options.yes
17989
+ });
17990
+ if (decision === "skip") {
17991
+ summary.push(
17992
+ `Preserved existing ${agent.mcpConfigPath ?? agent.name} (user declined overwrite)`
17993
+ );
17994
+ if (agent.mcpConfigPath !== null && fs8.existsSync(agent.mcpConfigPath)) {
17995
+ anyConfigWritten = true;
17996
+ }
17997
+ continue;
17998
+ }
17243
17999
  await writeMcpConfig(agent, configContent, projectRoot);
17244
- const configExists = agent.mcpConfigPath !== null && fs7.existsSync(agent.mcpConfigPath);
18000
+ const configExists = agent.mcpConfigPath !== null && fs8.existsSync(agent.mcpConfigPath);
17245
18001
  if (!configExists) {
17246
18002
  continue;
17247
18003
  }
@@ -17305,17 +18061,76 @@ async function runInit(options) {
17305
18061
  warnings.push(`Import graph scan failed: ${err instanceof Error ? err.message : String(err)}. You can run it later.`);
17306
18062
  }
17307
18063
  }
18064
+ const skipVerify = process.env["GLASSTRACE_SKIP_INIT_VERIFY"] === "1" || process.env["GLASSTRACE_SKIP_INIT_VERIFY"] === "true" || process.env["VITEST"] === "true";
18065
+ if (!skipVerify && !isCI) {
18066
+ const verifyResult = await verifyAnonKeyRegistration(projectRoot);
18067
+ if (verifyResult.outcome === "failed") {
18068
+ errors.push(verifyResult.error);
18069
+ return { exitCode: 2, summary, warnings, errors };
18070
+ }
18071
+ if (verifyResult.outcome === "verified") {
18072
+ summary.push("Verified anon key registration with Glasstrace API");
18073
+ } else {
18074
+ summary.push("Skipped anon key verification (no anon key on disk)");
18075
+ }
18076
+ }
17308
18077
  return { exitCode: 0, summary, warnings, errors };
17309
18078
  }
18079
+ async function verifyAnonKeyRegistration(projectRoot) {
18080
+ const anonKey = await readAnonKey(projectRoot);
18081
+ if (anonKey === null) {
18082
+ return { outcome: "skipped" };
18083
+ }
18084
+ let devKey;
18085
+ try {
18086
+ const envPath = path8.join(projectRoot, ".env.local");
18087
+ if (fs8.existsSync(envPath)) {
18088
+ const envContent = fs8.readFileSync(envPath, "utf-8");
18089
+ const effective = readEnvLocalApiKey(envContent);
18090
+ if (effective !== null && isDevApiKey(effective)) {
18091
+ devKey = effective;
18092
+ }
18093
+ }
18094
+ } catch {
18095
+ }
18096
+ const baseConfig = resolveConfig({ apiKey: devKey });
18097
+ const config2 = { ...baseConfig, apiKey: devKey };
18098
+ const sdkVersion = true ? "0.16.0" : "0.0.0-dev";
18099
+ const result = await verifyInitReachable(config2, anonKey, sdkVersion);
18100
+ if (result.ok) {
18101
+ return { outcome: "verified" };
18102
+ }
18103
+ const hint = "Run 'npx glasstrace status' or 'npx glasstrace doctor' to diagnose.";
18104
+ switch (result.reason) {
18105
+ case "transport":
18106
+ return {
18107
+ outcome: "failed",
18108
+ error: `Glasstrace init verification failed: fetch failed: ${result.detail}. ${hint}`
18109
+ };
18110
+ case "rejected":
18111
+ return {
18112
+ outcome: "failed",
18113
+ error: `Glasstrace init verification failed: server rejected the key (HTTP ${result.status}). ${hint}`
18114
+ };
18115
+ case "malformed":
18116
+ return {
18117
+ outcome: "failed",
18118
+ error: `Glasstrace init verification failed: server returned malformed response. ${hint}`
18119
+ };
18120
+ }
18121
+ }
17310
18122
  function parseArgs(argv) {
17311
18123
  const args = argv.slice(2);
17312
18124
  let yes = false;
17313
18125
  let coverageMap = false;
18126
+ let force = false;
17314
18127
  for (const arg of args) {
17315
18128
  if (arg === "--yes" || arg === "-y") {
17316
18129
  yes = true;
17317
18130
  } else if (arg === "--coverage-map") {
17318
18131
  coverageMap = true;
18132
+ } else if (arg === "--force") {
18133
+ force = true;
17319
18134
  }
17320
18135
  }
17321
18136
  if (!process.stdin.isTTY) {
@@ -17324,11 +18139,12 @@ function parseArgs(argv) {
17324
18139
  return {
17325
18140
  projectRoot: process.cwd(),
17326
18141
  yes,
17327
- coverageMap
18142
+ coverageMap,
18143
+ force
17328
18144
  };
17329
18145
  }
17330
18146
  var scriptPath = typeof process !== "undefined" && process.argv[1] !== void 0 ? process.argv[1].replace(/\\/g, "/") : void 0;
17331
- var scriptBasename = scriptPath !== void 0 ? path7.basename(scriptPath) : void 0;
18147
+ var scriptBasename = scriptPath !== void 0 ? path8.basename(scriptPath) : void 0;
17332
18148
  var isDirectExecution = scriptPath !== void 0 && (scriptPath.endsWith("/cli/init.js") || scriptPath.endsWith("/cli/init.ts") || scriptBasename === "glasstrace");
17333
18149
  if (isDirectExecution) {
17334
18150
  if (!meetsNodeVersion(20)) {
@@ -17366,47 +18182,84 @@ Usage: glasstrace mcp add [--force] [--dry-run]
17366
18182
  process.exit(1);
17367
18183
  }
17368
18184
  } else if (subcommand === void 0 || subcommand === "init" || subcommand.startsWith("-")) {
17369
- const options = parseArgs(process.argv);
17370
- runInit(options).then((result) => {
17371
- if (result.errors.length > 0) {
17372
- for (const err of result.errors) {
17373
- process.stderr.write(`Error: ${err}
17374
- `);
17375
- }
18185
+ const forwardedArgs = process.argv.slice(subcommand === "init" ? 3 : 2);
18186
+ if (forwardedArgs.includes("--validate")) {
18187
+ let validateProjectRoot = process.cwd();
18188
+ try {
18189
+ validateProjectRoot = resolveProjectRoot(validateProjectRoot).projectRoot;
18190
+ } catch {
17376
18191
  }
17377
- if (result.warnings.length > 0) {
17378
- for (const warn of result.warnings) {
17379
- process.stderr.write(`Warning: ${warn}
18192
+ Promise.resolve().then(() => (init_validate(), validate_exports)).then(({ runValidate: runValidate2 }) => runValidate2({ projectRoot: validateProjectRoot })).then((result) => {
18193
+ for (const line of result.summary) {
18194
+ process.stderr.write(`${line}
17380
18195
  `);
17381
18196
  }
17382
- }
17383
- if (result.summary.length > 0) {
17384
- process.stderr.write("\nGlasstrace initialized successfully!\n\n");
17385
- for (const line of result.summary) {
17386
- process.stderr.write(` - ${line}
18197
+ for (const issue2 of result.issues) {
18198
+ process.stderr.write(` - ${issue2.message}
17387
18199
  `);
18200
+ if (issue2.fix) {
18201
+ process.stderr.write(` Fix: ${issue2.fix}
18202
+ `);
18203
+ }
17388
18204
  }
17389
- process.stderr.write("\nNext steps:\n");
17390
- process.stderr.write(" 1. Start your Next.js dev server\n");
18205
+ process.exit(result.exitCode);
18206
+ }).catch((err) => {
17391
18207
  process.stderr.write(
17392
- " 2. Glasstrace works immediately in anonymous mode\n"
18208
+ `Fatal error: ${err instanceof Error ? err.message : String(err)}
18209
+ `
17393
18210
  );
18211
+ process.exit(1);
18212
+ });
18213
+ } else {
18214
+ const options = parseArgs(process.argv);
18215
+ runInit(options).then((result) => {
18216
+ if (result.errors.length > 0) {
18217
+ for (const err of result.errors) {
18218
+ process.stderr.write(`Error: ${err}
18219
+ `);
18220
+ }
18221
+ }
18222
+ if (result.warnings.length > 0) {
18223
+ for (const warn of result.warnings) {
18224
+ process.stderr.write(`Warning: ${warn}
18225
+ `);
18226
+ }
18227
+ }
18228
+ if (result.summary.length > 0) {
18229
+ if (result.exitCode === 0) {
18230
+ process.stderr.write("\nGlasstrace initialized successfully!\n\n");
18231
+ } else {
18232
+ process.stderr.write("\nGlasstrace init completed with errors.\n\n");
18233
+ }
18234
+ for (const line of result.summary) {
18235
+ process.stderr.write(` - ${line}
18236
+ `);
18237
+ }
18238
+ if (result.exitCode === 0) {
18239
+ process.stderr.write("\nNext steps:\n");
18240
+ process.stderr.write(" 1. Start your Next.js dev server\n");
18241
+ process.stderr.write(
18242
+ " 2. Glasstrace works immediately in anonymous mode\n"
18243
+ );
18244
+ process.stderr.write(
18245
+ " 3. To link to your account, set GLASSTRACE_API_KEY in .env.local\n\n"
18246
+ );
18247
+ }
18248
+ }
18249
+ process.exit(result.exitCode);
18250
+ }).catch((err) => {
17394
18251
  process.stderr.write(
17395
- " 3. To link to your account, set GLASSTRACE_API_KEY in .env.local\n\n"
17396
- );
17397
- }
17398
- process.exit(result.exitCode);
17399
- }).catch((err) => {
17400
- process.stderr.write(
17401
- `Fatal error: ${err instanceof Error ? err.message : String(err)}
18252
+ `Fatal error: ${err instanceof Error ? err.message : String(err)}
17402
18253
  `
17403
- );
17404
- process.exit(1);
17405
- });
18254
+ );
18255
+ process.exit(1);
18256
+ });
18257
+ }
17406
18258
  } else if (subcommand === "uninit") {
17407
18259
  const remainingArgs = process.argv.slice(3);
17408
18260
  const dryRun = remainingArgs.includes("--dry-run");
17409
- Promise.resolve().then(() => (init_uninit(), uninit_exports)).then(({ runUninit: runUninit2 }) => runUninit2({ projectRoot: process.cwd(), dryRun })).then((result) => {
18261
+ const force = remainingArgs.includes("--force");
18262
+ Promise.resolve().then(() => (init_uninit(), uninit_exports)).then(({ runUninit: runUninit2 }) => runUninit2({ projectRoot: process.cwd(), dryRun, force })).then((result) => {
17410
18263
  if (result.errors.length > 0) {
17411
18264
  for (const err of result.errors) {
17412
18265
  process.stderr.write(`Error: ${err}
@@ -17480,8 +18333,8 @@ Usage: glasstrace mcp add [--force] [--dry-run]
17480
18333
  `Unknown command: ${subcommand}
17481
18334
 
17482
18335
  Usage:
17483
- glasstrace init [--yes] [--coverage-map]
17484
- glasstrace uninit [--dry-run]
18336
+ glasstrace init [--yes] [--coverage-map] [--force] [--validate]
18337
+ glasstrace uninit [--dry-run] [--force]
17485
18338
  glasstrace status [--json]
17486
18339
  glasstrace mcp add [--force] [--dry-run]
17487
18340
  `
@@ -17491,8 +18344,10 @@ Usage:
17491
18344
  }
17492
18345
  // Annotate the CommonJS export names for ESM import in node:
17493
18346
  0 && (module.exports = {
18347
+ decideMcpConfigAction,
17494
18348
  meetsNodeVersion,
17495
18349
  rollbackSteps,
17496
- runInit
18350
+ runInit,
18351
+ verifyAnonKeyRegistration
17497
18352
  });
17498
18353
  //# sourceMappingURL=init.cjs.map