@glasstrace/sdk 0.15.1 → 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 (78) 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-ZNOD6FC7.js → chunk-CTJI2YKA.js} +8 -15
  13. package/dist/{chunk-ZNOD6FC7.js.map → chunk-CTJI2YKA.js.map} +1 -1
  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-A2AZL6MZ.js → chunk-O63DJKIJ.js} +169 -18
  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-ROFOJQWN.js → chunk-XNDHQN4S.js} +7 -11
  28. package/dist/{chunk-ROFOJQWN.js.map → chunk-XNDHQN4S.js.map} +1 -1
  29. package/dist/cli/init.cjs +673 -161
  30. package/dist/cli/init.cjs.map +1 -1
  31. package/dist/cli/init.d.cts +54 -1
  32. package/dist/cli/init.d.ts +54 -1
  33. package/dist/cli/init.js +146 -37
  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 +10 -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 +56 -59
  43. package/dist/cli/uninit.cjs.map +1 -1
  44. package/dist/cli/uninit.js +4 -4
  45. package/dist/cli/validate.cjs +2 -2
  46. package/dist/cli/validate.js +3 -6
  47. package/dist/cli/validate.js.map +1 -1
  48. package/dist/{esm-MDK7CZID.js → esm-KBPHCVB4.js} +3 -3
  49. package/dist/{getMachineId-bsd-4NIRBWME.js → getMachineId-bsd-345PYXFX.js} +4 -7
  50. package/dist/{getMachineId-bsd-4NIRBWME.js.map → getMachineId-bsd-345PYXFX.js.map} +1 -1
  51. package/dist/{getMachineId-darwin-2XNOCCJQ.js → getMachineId-darwin-5L2D25AD.js} +4 -7
  52. package/dist/{getMachineId-darwin-2XNOCCJQ.js.map → getMachineId-darwin-5L2D25AD.js.map} +1 -1
  53. package/dist/{getMachineId-linux-V6YSQEY7.js → getMachineId-linux-KJR4P5HN.js} +3 -6
  54. package/dist/{getMachineId-linux-V6YSQEY7.js.map → getMachineId-linux-KJR4P5HN.js.map} +1 -1
  55. package/dist/{getMachineId-unsupported-4FKBJNVO.js → getMachineId-unsupported-NDNXDYDY.js} +3 -6
  56. package/dist/{getMachineId-unsupported-4FKBJNVO.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +1 -1
  57. package/dist/{getMachineId-win-WLRZBKVG.js → getMachineId-win-T7PJNJXG.js} +4 -7
  58. package/dist/{getMachineId-win-WLRZBKVG.js.map → getMachineId-win-T7PJNJXG.js.map} +1 -1
  59. package/dist/index.cjs +449 -461
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +38 -3
  62. package/dist/index.d.ts +38 -3
  63. package/dist/index.js +195 -701
  64. package/dist/index.js.map +1 -1
  65. package/dist/{monorepo-YILKGQXQ.js → monorepo-N5Z63XP7.js} +4 -4
  66. package/dist/{source-map-uploader-3GWUQDTS.js → source-map-uploader-MUZPI2S5.js} +5 -4
  67. package/dist/source-map-uploader-MUZPI2S5.js.map +1 -0
  68. package/package.json +1 -1
  69. package/dist/chunk-2LDBR3F3.js.map +0 -1
  70. package/dist/chunk-A2AZL6MZ.js.map +0 -1
  71. package/dist/chunk-BGZ7J74D.js.map +0 -1
  72. package/dist/chunk-UPS5BGER.js +0 -182
  73. package/dist/chunk-UPS5BGER.js.map +0 -1
  74. package/dist/chunk-WK7MPK2T.js.map +0 -1
  75. package/dist/chunk-YMEXDDTA.js.map +0 -1
  76. /package/dist/{esm-MDK7CZID.js.map → chunk-NSBPE2FW.js.map} +0 -0
  77. /package/dist/{monorepo-YILKGQXQ.js.map → esm-KBPHCVB4.js.map} +0 -0
  78. /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
  }
@@ -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 };
143
273
  }
144
- const result = injectRegisterGlasstrace(existing);
145
- if (result.injected) {
146
- fs.writeFileSync(filePath, result.content, "utf-8");
147
- return { action: "injected" };
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
+ }
148
282
  }
149
- return { action: "unrecognized" };
283
+ const injectResult = injectRegisterGlasstrace(existing);
284
+ if (injectResult.injected) {
285
+ fs.writeFileSync(filePath, injectResult.content, "utf-8");
286
+ return { action: "injected", filePath, layout };
287
+ }
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;
@@ -345,15 +486,19 @@ async function scaffoldMcpMarker(projectRoot, anonKey) {
345
486
  fs.chmodSync(markerPath, 384);
346
487
  return true;
347
488
  }
348
- var import_node_crypto, fs, path;
489
+ var import_node_crypto, fs, path, INSTRUMENTATION_FILENAMES;
349
490
  var init_scaffolder = __esm({
350
491
  "src/cli/scaffolder.ts"() {
351
492
  "use strict";
352
- init_cjs_shims();
353
- import_node_crypto = require("crypto");
354
- fs = __toESM(require("fs"), 1);
355
- 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);
356
496
  init_constants();
497
+ INSTRUMENTATION_FILENAMES = [
498
+ "instrumentation.ts",
499
+ "instrumentation.js",
500
+ "instrumentation.mjs"
501
+ ];
357
502
  }
358
503
  });
359
504
 
@@ -419,7 +564,6 @@ var NEVER, $brand, $ZodAsyncError, $ZodEncodeError, globalConfig;
419
564
  var init_core = __esm({
420
565
  "../../node_modules/zod/v4/core/core.js"() {
421
566
  "use strict";
422
- init_cjs_shims();
423
567
  NEVER = Object.freeze({
424
568
  status: "aborted"
425
569
  });
@@ -1045,7 +1189,6 @@ var EVALUATING, captureStackTrace, allowsEval, getParsedType, propertyKeyTypes,
1045
1189
  var init_util = __esm({
1046
1190
  "../../node_modules/zod/v4/core/util.js"() {
1047
1191
  "use strict";
1048
- init_cjs_shims();
1049
1192
  EVALUATING = /* @__PURE__ */ Symbol("evaluating");
1050
1193
  captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
1051
1194
  };
@@ -1246,7 +1389,6 @@ var initializer, $ZodError, $ZodRealError;
1246
1389
  var init_errors = __esm({
1247
1390
  "../../node_modules/zod/v4/core/errors.js"() {
1248
1391
  "use strict";
1249
- init_cjs_shims();
1250
1392
  init_core();
1251
1393
  init_util();
1252
1394
  initializer = (inst, def) => {
@@ -1275,7 +1417,6 @@ var _parse, parse, _parseAsync, parseAsync, _safeParse, safeParse, _safeParseAsy
1275
1417
  var init_parse = __esm({
1276
1418
  "../../node_modules/zod/v4/core/parse.js"() {
1277
1419
  "use strict";
1278
- init_cjs_shims();
1279
1420
  init_core();
1280
1421
  init_errors();
1281
1422
  init_util();
@@ -1461,7 +1602,6 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, extendedDuration, guid, uui
1461
1602
  var init_regexes = __esm({
1462
1603
  "../../node_modules/zod/v4/core/regexes.js"() {
1463
1604
  "use strict";
1464
- init_cjs_shims();
1465
1605
  init_util();
1466
1606
  cuid = /^[cC][^\s-]{8,}$/;
1467
1607
  cuid2 = /^[0-9a-z]+$/;
@@ -1543,7 +1683,6 @@ var $ZodCheck, numericOriginMap, $ZodCheckLessThan, $ZodCheckGreaterThan, $ZodCh
1543
1683
  var init_checks = __esm({
1544
1684
  "../../node_modules/zod/v4/core/checks.js"() {
1545
1685
  "use strict";
1546
- init_cjs_shims();
1547
1686
  init_core();
1548
1687
  init_regexes();
1549
1688
  init_util();
@@ -2096,7 +2235,6 @@ var Doc;
2096
2235
  var init_doc = __esm({
2097
2236
  "../../node_modules/zod/v4/core/doc.js"() {
2098
2237
  "use strict";
2099
- init_cjs_shims();
2100
2238
  Doc = class {
2101
2239
  constructor(args = []) {
2102
2240
  this.content = [];
@@ -2139,7 +2277,6 @@ var version;
2139
2277
  var init_versions = __esm({
2140
2278
  "../../node_modules/zod/v4/core/versions.js"() {
2141
2279
  "use strict";
2142
- init_cjs_shims();
2143
2280
  version = {
2144
2281
  major: 4,
2145
2282
  minor: 3,
@@ -2510,7 +2647,6 @@ var $ZodType, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, $ZodU
2510
2647
  var init_schemas = __esm({
2511
2648
  "../../node_modules/zod/v4/core/schemas.js"() {
2512
2649
  "use strict";
2513
- init_cjs_shims();
2514
2650
  init_checks();
2515
2651
  init_core();
2516
2652
  init_doc();
@@ -4144,7 +4280,6 @@ var error;
4144
4280
  var init_ar = __esm({
4145
4281
  "../../node_modules/zod/v4/locales/ar.js"() {
4146
4282
  "use strict";
4147
- init_cjs_shims();
4148
4283
  init_util();
4149
4284
  error = () => {
4150
4285
  const Sizable = {
@@ -4259,7 +4394,6 @@ var error2;
4259
4394
  var init_az = __esm({
4260
4395
  "../../node_modules/zod/v4/locales/az.js"() {
4261
4396
  "use strict";
4262
- init_cjs_shims();
4263
4397
  init_util();
4264
4398
  error2 = () => {
4265
4399
  const Sizable = {
@@ -4388,7 +4522,6 @@ var error3;
4388
4522
  var init_be = __esm({
4389
4523
  "../../node_modules/zod/v4/locales/be.js"() {
4390
4524
  "use strict";
4391
- init_cjs_shims();
4392
4525
  init_util();
4393
4526
  error3 = () => {
4394
4527
  const Sizable = {
@@ -4538,7 +4671,6 @@ var error4;
4538
4671
  var init_bg = __esm({
4539
4672
  "../../node_modules/zod/v4/locales/bg.js"() {
4540
4673
  "use strict";
4541
- init_cjs_shims();
4542
4674
  init_util();
4543
4675
  error4 = () => {
4544
4676
  const Sizable = {
@@ -4667,7 +4799,6 @@ var error5;
4667
4799
  var init_ca = __esm({
4668
4800
  "../../node_modules/zod/v4/locales/ca.js"() {
4669
4801
  "use strict";
4670
- init_cjs_shims();
4671
4802
  init_util();
4672
4803
  error5 = () => {
4673
4804
  const Sizable = {
@@ -4784,7 +4915,6 @@ var error6;
4784
4915
  var init_cs = __esm({
4785
4916
  "../../node_modules/zod/v4/locales/cs.js"() {
4786
4917
  "use strict";
4787
- init_cjs_shims();
4788
4918
  init_util();
4789
4919
  error6 = () => {
4790
4920
  const Sizable = {
@@ -4904,7 +5034,6 @@ var error7;
4904
5034
  var init_da = __esm({
4905
5035
  "../../node_modules/zod/v4/locales/da.js"() {
4906
5036
  "use strict";
4907
- init_cjs_shims();
4908
5037
  init_util();
4909
5038
  error7 = () => {
4910
5039
  const Sizable = {
@@ -5028,7 +5157,6 @@ var error8;
5028
5157
  var init_de = __esm({
5029
5158
  "../../node_modules/zod/v4/locales/de.js"() {
5030
5159
  "use strict";
5031
- init_cjs_shims();
5032
5160
  init_util();
5033
5161
  error8 = () => {
5034
5162
  const Sizable = {
@@ -5145,7 +5273,6 @@ var error9;
5145
5273
  var init_en = __esm({
5146
5274
  "../../node_modules/zod/v4/locales/en.js"() {
5147
5275
  "use strict";
5148
- init_cjs_shims();
5149
5276
  init_util();
5150
5277
  error9 = () => {
5151
5278
  const Sizable = {
@@ -5262,7 +5389,6 @@ var error10;
5262
5389
  var init_eo = __esm({
5263
5390
  "../../node_modules/zod/v4/locales/eo.js"() {
5264
5391
  "use strict";
5265
- init_cjs_shims();
5266
5392
  init_util();
5267
5393
  error10 = () => {
5268
5394
  const Sizable = {
@@ -5380,7 +5506,6 @@ var error11;
5380
5506
  var init_es = __esm({
5381
5507
  "../../node_modules/zod/v4/locales/es.js"() {
5382
5508
  "use strict";
5383
- init_cjs_shims();
5384
5509
  init_util();
5385
5510
  error11 = () => {
5386
5511
  const Sizable = {
@@ -5521,7 +5646,6 @@ var error12;
5521
5646
  var init_fa = __esm({
5522
5647
  "../../node_modules/zod/v4/locales/fa.js"() {
5523
5648
  "use strict";
5524
- init_cjs_shims();
5525
5649
  init_util();
5526
5650
  error12 = () => {
5527
5651
  const Sizable = {
@@ -5644,7 +5768,6 @@ var error13;
5644
5768
  var init_fi = __esm({
5645
5769
  "../../node_modules/zod/v4/locales/fi.js"() {
5646
5770
  "use strict";
5647
- init_cjs_shims();
5648
5771
  init_util();
5649
5772
  error13 = () => {
5650
5773
  const Sizable = {
@@ -5765,7 +5888,6 @@ var error14;
5765
5888
  var init_fr = __esm({
5766
5889
  "../../node_modules/zod/v4/locales/fr.js"() {
5767
5890
  "use strict";
5768
- init_cjs_shims();
5769
5891
  init_util();
5770
5892
  error14 = () => {
5771
5893
  const Sizable = {
@@ -5882,7 +6004,6 @@ var error15;
5882
6004
  var init_fr_CA = __esm({
5883
6005
  "../../node_modules/zod/v4/locales/fr-CA.js"() {
5884
6006
  "use strict";
5885
- init_cjs_shims();
5886
6007
  init_util();
5887
6008
  error15 = () => {
5888
6009
  const Sizable = {
@@ -5998,7 +6119,6 @@ var error16;
5998
6119
  var init_he = __esm({
5999
6120
  "../../node_modules/zod/v4/locales/he.js"() {
6000
6121
  "use strict";
6001
- init_cjs_shims();
6002
6122
  init_util();
6003
6123
  error16 = () => {
6004
6124
  const TypeNames = {
@@ -6201,7 +6321,6 @@ var error17;
6201
6321
  var init_hu = __esm({
6202
6322
  "../../node_modules/zod/v4/locales/hu.js"() {
6203
6323
  "use strict";
6204
- init_cjs_shims();
6205
6324
  init_util();
6206
6325
  error17 = () => {
6207
6326
  const Sizable = {
@@ -6328,7 +6447,6 @@ var error18;
6328
6447
  var init_hy = __esm({
6329
6448
  "../../node_modules/zod/v4/locales/hy.js"() {
6330
6449
  "use strict";
6331
- init_cjs_shims();
6332
6450
  init_util();
6333
6451
  error18 = () => {
6334
6452
  const Sizable = {
@@ -6474,7 +6592,6 @@ var error19;
6474
6592
  var init_id = __esm({
6475
6593
  "../../node_modules/zod/v4/locales/id.js"() {
6476
6594
  "use strict";
6477
- init_cjs_shims();
6478
6595
  init_util();
6479
6596
  error19 = () => {
6480
6597
  const Sizable = {
@@ -6589,7 +6706,6 @@ var error20;
6589
6706
  var init_is = __esm({
6590
6707
  "../../node_modules/zod/v4/locales/is.js"() {
6591
6708
  "use strict";
6592
- init_cjs_shims();
6593
6709
  init_util();
6594
6710
  error20 = () => {
6595
6711
  const Sizable = {
@@ -6707,7 +6823,6 @@ var error21;
6707
6823
  var init_it = __esm({
6708
6824
  "../../node_modules/zod/v4/locales/it.js"() {
6709
6825
  "use strict";
6710
- init_cjs_shims();
6711
6826
  init_util();
6712
6827
  error21 = () => {
6713
6828
  const Sizable = {
@@ -6824,7 +6939,6 @@ var error22;
6824
6939
  var init_ja = __esm({
6825
6940
  "../../node_modules/zod/v4/locales/ja.js"() {
6826
6941
  "use strict";
6827
- init_cjs_shims();
6828
6942
  init_util();
6829
6943
  error22 = () => {
6830
6944
  const Sizable = {
@@ -6940,7 +7054,6 @@ var error23;
6940
7054
  var init_ka = __esm({
6941
7055
  "../../node_modules/zod/v4/locales/ka.js"() {
6942
7056
  "use strict";
6943
- init_cjs_shims();
6944
7057
  init_util();
6945
7058
  error23 = () => {
6946
7059
  const Sizable = {
@@ -7061,7 +7174,6 @@ var error24;
7061
7174
  var init_km = __esm({
7062
7175
  "../../node_modules/zod/v4/locales/km.js"() {
7063
7176
  "use strict";
7064
- init_cjs_shims();
7065
7177
  init_util();
7066
7178
  error24 = () => {
7067
7179
  const Sizable = {
@@ -7177,7 +7289,6 @@ function kh_default() {
7177
7289
  var init_kh = __esm({
7178
7290
  "../../node_modules/zod/v4/locales/kh.js"() {
7179
7291
  "use strict";
7180
- init_cjs_shims();
7181
7292
  init_km();
7182
7293
  }
7183
7294
  });
@@ -7192,7 +7303,6 @@ var error25;
7192
7303
  var init_ko = __esm({
7193
7304
  "../../node_modules/zod/v4/locales/ko.js"() {
7194
7305
  "use strict";
7195
- init_cjs_shims();
7196
7306
  init_util();
7197
7307
  error25 = () => {
7198
7308
  const Sizable = {
@@ -7322,7 +7432,6 @@ var capitalizeFirstCharacter, error26;
7322
7432
  var init_lt = __esm({
7323
7433
  "../../node_modules/zod/v4/locales/lt.js"() {
7324
7434
  "use strict";
7325
- init_cjs_shims();
7326
7435
  init_util();
7327
7436
  capitalizeFirstCharacter = (text) => {
7328
7437
  return text.charAt(0).toUpperCase() + text.slice(1);
@@ -7524,7 +7633,6 @@ var error27;
7524
7633
  var init_mk = __esm({
7525
7634
  "../../node_modules/zod/v4/locales/mk.js"() {
7526
7635
  "use strict";
7527
- init_cjs_shims();
7528
7636
  init_util();
7529
7637
  error27 = () => {
7530
7638
  const Sizable = {
@@ -7642,7 +7750,6 @@ var error28;
7642
7750
  var init_ms = __esm({
7643
7751
  "../../node_modules/zod/v4/locales/ms.js"() {
7644
7752
  "use strict";
7645
- init_cjs_shims();
7646
7753
  init_util();
7647
7754
  error28 = () => {
7648
7755
  const Sizable = {
@@ -7758,7 +7865,6 @@ var error29;
7758
7865
  var init_nl = __esm({
7759
7866
  "../../node_modules/zod/v4/locales/nl.js"() {
7760
7867
  "use strict";
7761
- init_cjs_shims();
7762
7868
  init_util();
7763
7869
  error29 = () => {
7764
7870
  const Sizable = {
@@ -7877,7 +7983,6 @@ var error30;
7877
7983
  var init_no = __esm({
7878
7984
  "../../node_modules/zod/v4/locales/no.js"() {
7879
7985
  "use strict";
7880
- init_cjs_shims();
7881
7986
  init_util();
7882
7987
  error30 = () => {
7883
7988
  const Sizable = {
@@ -7994,7 +8099,6 @@ var error31;
7994
8099
  var init_ota = __esm({
7995
8100
  "../../node_modules/zod/v4/locales/ota.js"() {
7996
8101
  "use strict";
7997
- init_cjs_shims();
7998
8102
  init_util();
7999
8103
  error31 = () => {
8000
8104
  const Sizable = {
@@ -8112,7 +8216,6 @@ var error32;
8112
8216
  var init_ps = __esm({
8113
8217
  "../../node_modules/zod/v4/locales/ps.js"() {
8114
8218
  "use strict";
8115
- init_cjs_shims();
8116
8219
  init_util();
8117
8220
  error32 = () => {
8118
8221
  const Sizable = {
@@ -8235,7 +8338,6 @@ var error33;
8235
8338
  var init_pl = __esm({
8236
8339
  "../../node_modules/zod/v4/locales/pl.js"() {
8237
8340
  "use strict";
8238
- init_cjs_shims();
8239
8341
  init_util();
8240
8342
  error33 = () => {
8241
8343
  const Sizable = {
@@ -8353,7 +8455,6 @@ var error34;
8353
8455
  var init_pt = __esm({
8354
8456
  "../../node_modules/zod/v4/locales/pt.js"() {
8355
8457
  "use strict";
8356
- init_cjs_shims();
8357
8458
  init_util();
8358
8459
  error34 = () => {
8359
8460
  const Sizable = {
@@ -8485,7 +8586,6 @@ var error35;
8485
8586
  var init_ru = __esm({
8486
8587
  "../../node_modules/zod/v4/locales/ru.js"() {
8487
8588
  "use strict";
8488
- init_cjs_shims();
8489
8589
  init_util();
8490
8590
  error35 = () => {
8491
8591
  const Sizable = {
@@ -8635,7 +8735,6 @@ var error36;
8635
8735
  var init_sl = __esm({
8636
8736
  "../../node_modules/zod/v4/locales/sl.js"() {
8637
8737
  "use strict";
8638
- init_cjs_shims();
8639
8738
  init_util();
8640
8739
  error36 = () => {
8641
8740
  const Sizable = {
@@ -8753,7 +8852,6 @@ var error37;
8753
8852
  var init_sv = __esm({
8754
8853
  "../../node_modules/zod/v4/locales/sv.js"() {
8755
8854
  "use strict";
8756
- init_cjs_shims();
8757
8855
  init_util();
8758
8856
  error37 = () => {
8759
8857
  const Sizable = {
@@ -8872,7 +8970,6 @@ var error38;
8872
8970
  var init_ta = __esm({
8873
8971
  "../../node_modules/zod/v4/locales/ta.js"() {
8874
8972
  "use strict";
8875
- init_cjs_shims();
8876
8973
  init_util();
8877
8974
  error38 = () => {
8878
8975
  const Sizable = {
@@ -8991,7 +9088,6 @@ var error39;
8991
9088
  var init_th = __esm({
8992
9089
  "../../node_modules/zod/v4/locales/th.js"() {
8993
9090
  "use strict";
8994
- init_cjs_shims();
8995
9091
  init_util();
8996
9092
  error39 = () => {
8997
9093
  const Sizable = {
@@ -9110,7 +9206,6 @@ var error40;
9110
9206
  var init_tr = __esm({
9111
9207
  "../../node_modules/zod/v4/locales/tr.js"() {
9112
9208
  "use strict";
9113
- init_cjs_shims();
9114
9209
  init_util();
9115
9210
  error40 = () => {
9116
9211
  const Sizable = {
@@ -9224,7 +9319,6 @@ var error41;
9224
9319
  var init_uk = __esm({
9225
9320
  "../../node_modules/zod/v4/locales/uk.js"() {
9226
9321
  "use strict";
9227
- init_cjs_shims();
9228
9322
  init_util();
9229
9323
  error41 = () => {
9230
9324
  const Sizable = {
@@ -9338,7 +9432,6 @@ function ua_default() {
9338
9432
  var init_ua = __esm({
9339
9433
  "../../node_modules/zod/v4/locales/ua.js"() {
9340
9434
  "use strict";
9341
- init_cjs_shims();
9342
9435
  init_uk();
9343
9436
  }
9344
9437
  });
@@ -9353,7 +9446,6 @@ var error42;
9353
9446
  var init_ur = __esm({
9354
9447
  "../../node_modules/zod/v4/locales/ur.js"() {
9355
9448
  "use strict";
9356
- init_cjs_shims();
9357
9449
  init_util();
9358
9450
  error42 = () => {
9359
9451
  const Sizable = {
@@ -9472,7 +9564,6 @@ var error43;
9472
9564
  var init_uz = __esm({
9473
9565
  "../../node_modules/zod/v4/locales/uz.js"() {
9474
9566
  "use strict";
9475
- init_cjs_shims();
9476
9567
  init_util();
9477
9568
  error43 = () => {
9478
9569
  const Sizable = {
@@ -9590,7 +9681,6 @@ var error44;
9590
9681
  var init_vi = __esm({
9591
9682
  "../../node_modules/zod/v4/locales/vi.js"() {
9592
9683
  "use strict";
9593
- init_cjs_shims();
9594
9684
  init_util();
9595
9685
  error44 = () => {
9596
9686
  const Sizable = {
@@ -9707,7 +9797,6 @@ var error45;
9707
9797
  var init_zh_CN = __esm({
9708
9798
  "../../node_modules/zod/v4/locales/zh-CN.js"() {
9709
9799
  "use strict";
9710
- init_cjs_shims();
9711
9800
  init_util();
9712
9801
  error45 = () => {
9713
9802
  const Sizable = {
@@ -9825,7 +9914,6 @@ var error46;
9825
9914
  var init_zh_TW = __esm({
9826
9915
  "../../node_modules/zod/v4/locales/zh-TW.js"() {
9827
9916
  "use strict";
9828
- init_cjs_shims();
9829
9917
  init_util();
9830
9918
  error46 = () => {
9831
9919
  const Sizable = {
@@ -9941,7 +10029,6 @@ var error47;
9941
10029
  var init_yo = __esm({
9942
10030
  "../../node_modules/zod/v4/locales/yo.js"() {
9943
10031
  "use strict";
9944
- init_cjs_shims();
9945
10032
  init_util();
9946
10033
  error47 = () => {
9947
10034
  const Sizable = {
@@ -10103,7 +10190,6 @@ __export(locales_exports, {
10103
10190
  var init_locales = __esm({
10104
10191
  "../../node_modules/zod/v4/locales/index.js"() {
10105
10192
  "use strict";
10106
- init_cjs_shims();
10107
10193
  init_ar();
10108
10194
  init_az();
10109
10195
  init_be();
@@ -10164,7 +10250,6 @@ var _a, $output, $input, $ZodRegistry, globalRegistry;
10164
10250
  var init_registries = __esm({
10165
10251
  "../../node_modules/zod/v4/core/registries.js"() {
10166
10252
  "use strict";
10167
- init_cjs_shims();
10168
10253
  $output = /* @__PURE__ */ Symbol("ZodOutput");
10169
10254
  $input = /* @__PURE__ */ Symbol("ZodInput");
10170
10255
  $ZodRegistry = class {
@@ -11247,7 +11332,6 @@ var TimePrecision;
11247
11332
  var init_api = __esm({
11248
11333
  "../../node_modules/zod/v4/core/api.js"() {
11249
11334
  "use strict";
11250
- init_cjs_shims();
11251
11335
  init_checks();
11252
11336
  init_registries();
11253
11337
  init_schemas();
@@ -11604,7 +11688,6 @@ var createToJSONSchemaMethod, createStandardJSONSchemaMethod;
11604
11688
  var init_to_json_schema = __esm({
11605
11689
  "../../node_modules/zod/v4/core/to-json-schema.js"() {
11606
11690
  "use strict";
11607
- init_cjs_shims();
11608
11691
  init_registries();
11609
11692
  createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
11610
11693
  const ctx = initializeContext({ ...params, processors });
@@ -11661,7 +11744,6 @@ var formatMap, stringProcessor, numberProcessor, booleanProcessor, bigintProcess
11661
11744
  var init_json_schema_processors = __esm({
11662
11745
  "../../node_modules/zod/v4/core/json-schema-processors.js"() {
11663
11746
  "use strict";
11664
- init_cjs_shims();
11665
11747
  init_to_json_schema();
11666
11748
  init_util();
11667
11749
  formatMap = {
@@ -12187,7 +12269,6 @@ var JSONSchemaGenerator;
12187
12269
  var init_json_schema_generator = __esm({
12188
12270
  "../../node_modules/zod/v4/core/json-schema-generator.js"() {
12189
12271
  "use strict";
12190
- init_cjs_shims();
12191
12272
  init_json_schema_processors();
12192
12273
  init_to_json_schema();
12193
12274
  JSONSchemaGenerator = class {
@@ -12271,7 +12352,6 @@ var json_schema_exports = {};
12271
12352
  var init_json_schema = __esm({
12272
12353
  "../../node_modules/zod/v4/core/json-schema.js"() {
12273
12354
  "use strict";
12274
- init_cjs_shims();
12275
12355
  }
12276
12356
  });
12277
12357
 
@@ -12555,7 +12635,6 @@ __export(core_exports2, {
12555
12635
  var init_core2 = __esm({
12556
12636
  "../../node_modules/zod/v4/core/index.js"() {
12557
12637
  "use strict";
12558
- init_cjs_shims();
12559
12638
  init_core();
12560
12639
  init_parse();
12561
12640
  init_errors();
@@ -12611,7 +12690,6 @@ __export(checks_exports2, {
12611
12690
  var init_checks2 = __esm({
12612
12691
  "../../node_modules/zod/v4/classic/checks.js"() {
12613
12692
  "use strict";
12614
- init_cjs_shims();
12615
12693
  init_core2();
12616
12694
  }
12617
12695
  });
@@ -12644,7 +12722,6 @@ var ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration;
12644
12722
  var init_iso = __esm({
12645
12723
  "../../node_modules/zod/v4/classic/iso.js"() {
12646
12724
  "use strict";
12647
- init_cjs_shims();
12648
12725
  init_core2();
12649
12726
  init_schemas2();
12650
12727
  ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
@@ -12671,7 +12748,6 @@ var initializer2, ZodError, ZodRealError;
12671
12748
  var init_errors2 = __esm({
12672
12749
  "../../node_modules/zod/v4/classic/errors.js"() {
12673
12750
  "use strict";
12674
- init_cjs_shims();
12675
12751
  init_core2();
12676
12752
  init_core2();
12677
12753
  init_util();
@@ -12721,7 +12797,6 @@ var parse2, parseAsync2, safeParse2, safeParseAsync2, encode2, decode2, encodeAs
12721
12797
  var init_parse2 = __esm({
12722
12798
  "../../node_modules/zod/v4/classic/parse.js"() {
12723
12799
  "use strict";
12724
- init_cjs_shims();
12725
12800
  init_core2();
12726
12801
  init_errors2();
12727
12802
  parse2 = /* @__PURE__ */ _parse(ZodRealError);
@@ -13365,7 +13440,6 @@ var ZodType, _ZodString, ZodString, ZodStringFormat, ZodEmail, ZodGUID, ZodUUID,
13365
13440
  var init_schemas2 = __esm({
13366
13441
  "../../node_modules/zod/v4/classic/schemas.js"() {
13367
13442
  "use strict";
13368
- init_cjs_shims();
13369
13443
  init_core2();
13370
13444
  init_core2();
13371
13445
  init_json_schema_processors();
@@ -14012,7 +14086,6 @@ var ZodIssueCode, ZodFirstPartyTypeKind;
14012
14086
  var init_compat = __esm({
14013
14087
  "../../node_modules/zod/v4/classic/compat.js"() {
14014
14088
  "use strict";
14015
- init_cjs_shims();
14016
14089
  init_core2();
14017
14090
  init_core2();
14018
14091
  ZodIssueCode = {
@@ -14434,7 +14507,6 @@ var z, RECOGNIZED_KEYS;
14434
14507
  var init_from_json_schema = __esm({
14435
14508
  "../../node_modules/zod/v4/classic/from-json-schema.js"() {
14436
14509
  "use strict";
14437
- init_cjs_shims();
14438
14510
  init_registries();
14439
14511
  init_checks2();
14440
14512
  init_iso();
@@ -14545,7 +14617,6 @@ function date4(params) {
14545
14617
  var init_coerce = __esm({
14546
14618
  "../../node_modules/zod/v4/classic/coerce.js"() {
14547
14619
  "use strict";
14548
- init_cjs_shims();
14549
14620
  init_core2();
14550
14621
  init_schemas2();
14551
14622
  }
@@ -14794,7 +14865,6 @@ __export(external_exports, {
14794
14865
  var init_external = __esm({
14795
14866
  "../../node_modules/zod/v4/classic/external.js"() {
14796
14867
  "use strict";
14797
- init_cjs_shims();
14798
14868
  init_core2();
14799
14869
  init_schemas2();
14800
14870
  init_checks2();
@@ -14818,7 +14888,6 @@ var init_external = __esm({
14818
14888
  var init_zod = __esm({
14819
14889
  "../../node_modules/zod/index.js"() {
14820
14890
  "use strict";
14821
- init_cjs_shims();
14822
14891
  init_external();
14823
14892
  init_external();
14824
14893
  }
@@ -14840,7 +14909,6 @@ var DevApiKeySchema, AnonApiKeySchema, SessionIdSchema, BuildHashSchema, SdkDiag
14840
14909
  var init_dist = __esm({
14841
14910
  "../protocol/dist/index.js"() {
14842
14911
  "use strict";
14843
- init_cjs_shims();
14844
14912
  init_zod();
14845
14913
  init_zod();
14846
14914
  init_zod();
@@ -14977,8 +15045,8 @@ async function loadFsPath() {
14977
15045
  if (fsPathCache !== void 0) return fsPathCache;
14978
15046
  try {
14979
15047
  const [fs9, path9] = await Promise.all([
14980
- import("fs/promises"),
14981
- import("path")
15048
+ import("node:fs/promises"),
15049
+ import("node:path")
14982
15050
  ]);
14983
15051
  fsPathCache = { fs: fs9, path: path9 };
14984
15052
  return fsPathCache;
@@ -15059,7 +15127,6 @@ var GLASSTRACE_DIR, ANON_KEY_FILE, fsPathCache, ephemeralKeyCache;
15059
15127
  var init_anon_key = __esm({
15060
15128
  "src/anon-key.ts"() {
15061
15129
  "use strict";
15062
- init_cjs_shims();
15063
15130
  init_dist();
15064
15131
  GLASSTRACE_DIR = ".glasstrace";
15065
15132
  ANON_KEY_FILE = "anon_key";
@@ -15176,12 +15243,11 @@ var import_node_child_process, import_promises, import_node_path, import_node_os
15176
15243
  var init_detect = __esm({
15177
15244
  "src/agent-detection/detect.ts"() {
15178
15245
  "use strict";
15179
- init_cjs_shims();
15180
- import_node_child_process = require("child_process");
15181
- import_promises = require("fs/promises");
15182
- import_node_path = require("path");
15183
- import_node_os = require("os");
15184
- 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");
15185
15251
  AGENT_RULES = [
15186
15252
  {
15187
15253
  name: "claude",
@@ -15391,7 +15457,6 @@ ${content}${m.end}
15391
15457
  var init_configs = __esm({
15392
15458
  "src/agent-detection/configs.ts"() {
15393
15459
  "use strict";
15394
- init_cjs_shims();
15395
15460
  }
15396
15461
  });
15397
15462
 
@@ -15569,9 +15634,8 @@ var import_promises2, import_node_path2, HTML_START, HTML_END, HASH_START, HASH_
15569
15634
  var init_inject = __esm({
15570
15635
  "src/agent-detection/inject.ts"() {
15571
15636
  "use strict";
15572
- init_cjs_shims();
15573
- import_promises2 = require("fs/promises");
15574
- import_node_path2 = require("path");
15637
+ import_promises2 = require("node:fs/promises");
15638
+ import_node_path2 = require("node:path");
15575
15639
  HTML_START = "<!-- glasstrace:mcp:start -->";
15576
15640
  HTML_END = "<!-- glasstrace:mcp:end -->";
15577
15641
  HASH_START = "# glasstrace:mcp:start";
@@ -15818,9 +15882,8 @@ var fs3, path3;
15818
15882
  var init_monorepo = __esm({
15819
15883
  "src/cli/monorepo.ts"() {
15820
15884
  "use strict";
15821
- init_cjs_shims();
15822
- fs3 = __toESM(require("fs"), 1);
15823
- path3 = __toESM(require("path"), 1);
15885
+ fs3 = __toESM(require("node:fs"), 1);
15886
+ path3 = __toESM(require("node:path"), 1);
15824
15887
  init_constants();
15825
15888
  }
15826
15889
  });
@@ -16167,7 +16230,7 @@ function writeShutdownMarker(projectRoot) {
16167
16230
  }
16168
16231
  async function defaultPrompt(question, defaultValue) {
16169
16232
  if (!process.stdin.isTTY) return defaultValue;
16170
- const readline2 = await import("readline");
16233
+ const readline2 = await import("node:readline");
16171
16234
  const rl = readline2.createInterface({
16172
16235
  input: process.stdin,
16173
16236
  output: process.stdout
@@ -16493,10 +16556,9 @@ var fs4, os, path4, MCP_CONFIG_FILES, AGENT_INFO_FILES;
16493
16556
  var init_uninit = __esm({
16494
16557
  "src/cli/uninit.ts"() {
16495
16558
  "use strict";
16496
- init_cjs_shims();
16497
- fs4 = __toESM(require("fs"), 1);
16498
- os = __toESM(require("os"), 1);
16499
- 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);
16500
16562
  init_constants();
16501
16563
  init_scaffolder();
16502
16564
  MCP_CONFIG_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json"];
@@ -16724,11 +16786,10 @@ var import_node_child_process2, fs5, path5, import_node_util, execFileAsync;
16724
16786
  var init_mcp_add = __esm({
16725
16787
  "src/cli/mcp-add.ts"() {
16726
16788
  "use strict";
16727
- init_cjs_shims();
16728
- import_node_child_process2 = require("child_process");
16729
- fs5 = __toESM(require("fs"), 1);
16730
- path5 = __toESM(require("path"), 1);
16731
- 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");
16732
16793
  init_anon_key();
16733
16794
  init_detect();
16734
16795
  init_configs();
@@ -16833,9 +16894,8 @@ var fs6, path6, MCP_CONFIG_CANDIDATES;
16833
16894
  var init_validate = __esm({
16834
16895
  "src/cli/validate.ts"() {
16835
16896
  "use strict";
16836
- init_cjs_shims();
16837
- fs6 = __toESM(require("fs"), 1);
16838
- path6 = __toESM(require("path"), 1);
16897
+ fs6 = __toESM(require("node:fs"), 1);
16898
+ path6 = __toESM(require("node:path"), 1);
16839
16899
  MCP_CONFIG_CANDIDATES = [
16840
16900
  ".mcp.json",
16841
16901
  ".cursor/mcp.json",
@@ -17017,9 +17077,8 @@ var fs7, path7, MCP_JSON_FILES, MCP_TOML_FILES, AGENT_INFO_FILES2, INSTRUMENTATI
17017
17077
  var init_status = __esm({
17018
17078
  "src/cli/status.ts"() {
17019
17079
  "use strict";
17020
- init_cjs_shims();
17021
- fs7 = __toESM(require("fs"), 1);
17022
- path7 = __toESM(require("path"), 1);
17080
+ fs7 = __toESM(require("node:fs"), 1);
17081
+ path7 = __toESM(require("node:path"), 1);
17023
17082
  init_constants();
17024
17083
  MCP_JSON_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json", ".glasstrace/mcp.json"];
17025
17084
  MCP_TOML_FILES = [".codex/config.toml"];
@@ -17046,21 +17105,20 @@ __export(init_exports, {
17046
17105
  decideMcpConfigAction: () => decideMcpConfigAction,
17047
17106
  meetsNodeVersion: () => meetsNodeVersion,
17048
17107
  rollbackSteps: () => rollbackSteps,
17049
- runInit: () => runInit
17108
+ runInit: () => runInit,
17109
+ verifyAnonKeyRegistration: () => verifyAnonKeyRegistration
17050
17110
  });
17051
17111
  module.exports = __toCommonJS(init_exports);
17052
- init_cjs_shims();
17053
- var fs8 = __toESM(require("fs"), 1);
17054
- var path8 = __toESM(require("path"), 1);
17055
- 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);
17056
17115
  init_scaffolder();
17057
17116
 
17058
17117
  // src/import-graph.ts
17059
- init_cjs_shims();
17060
- var fs2 = __toESM(require("fs/promises"), 1);
17061
- var fsSync = __toESM(require("fs"), 1);
17062
- var path2 = __toESM(require("path"), 1);
17063
- 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);
17064
17122
  init_dist();
17065
17123
  var MAX_TEST_FILES = 5e3;
17066
17124
  var EXCLUDED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".next", ".git", "dist", ".turbo"]);
@@ -17233,6 +17291,353 @@ init_inject();
17233
17291
  init_constants();
17234
17292
  init_monorepo();
17235
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
17236
17641
  function meetsNodeVersion(minMajor) {
17237
17642
  const [major] = process.versions.node.split(".").map(Number);
17238
17643
  return major >= minMajor;
@@ -17291,7 +17696,7 @@ async function rollbackSteps(steps, projectRoot, state) {
17291
17696
  try {
17292
17697
  switch (step) {
17293
17698
  case "instrumentation": {
17294
- const instrPath = path8.join(projectRoot, "instrumentation.ts");
17699
+ const instrPath = state?.instrumentationPath ?? path8.join(projectRoot, "instrumentation.ts");
17295
17700
  if (fs8.existsSync(instrPath)) {
17296
17701
  const content = fs8.readFileSync(instrPath, "utf-8");
17297
17702
  if (isInitCreatedInstrumentation(content)) {
@@ -17394,32 +17799,76 @@ async function runInit(options) {
17394
17799
  }
17395
17800
  const rollbackState = { steps: [] };
17396
17801
  try {
17397
- const instrPath = path8.join(projectRoot, "instrumentation.ts");
17398
- if (fs8.existsSync(instrPath)) {
17399
- rollbackState.originalInstrumentationContent = fs8.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
+ }
17811
+ }
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;
17400
17820
  }
17401
- const instrResult = await scaffoldInstrumentation(projectRoot);
17821
+ const relativePath = instrResult.filePath !== void 0 ? path8.relative(projectRoot, instrResult.filePath) : "instrumentation.ts";
17402
17822
  switch (instrResult.action) {
17403
17823
  case "created":
17404
- summary.push("Created instrumentation.ts");
17824
+ summary.push(`Created ${relativePath}`);
17405
17825
  rollbackState.steps.push("instrumentation");
17406
17826
  break;
17407
17827
  case "injected":
17408
- 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
+ );
17409
17835
  rollbackState.steps.push("instrumentation");
17410
17836
  break;
17411
17837
  case "already-registered":
17412
- summary.push("Skipped instrumentation.ts (registerGlasstrace already present)");
17838
+ summary.push(`Skipped ${relativePath} (registerGlasstrace already present)`);
17839
+ break;
17840
+ case "skipped":
17841
+ warnings.push(
17842
+ `Preserved ${relativePath} (merge declined; re-run with --force to apply the merge without prompting)`
17843
+ );
17413
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
+ }
17414
17855
  case "unrecognized":
17415
17856
  warnings.push(
17416
- '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
+ `
17417
17866
  );
17418
17867
  break;
17419
17868
  }
17420
17869
  } catch (err) {
17421
17870
  await rollbackSteps(rollbackState.steps, projectRoot, rollbackState);
17422
- 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)}`);
17423
17872
  return { exitCode: 1, summary, warnings, errors };
17424
17873
  }
17425
17874
  try {
@@ -17612,8 +18061,64 @@ async function runInit(options) {
17612
18061
  warnings.push(`Import graph scan failed: ${err instanceof Error ? err.message : String(err)}. You can run it later.`);
17613
18062
  }
17614
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
+ }
17615
18077
  return { exitCode: 0, summary, warnings, errors };
17616
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
+ }
17617
18122
  function parseArgs(argv) {
17618
18123
  const args = argv.slice(2);
17619
18124
  let yes = false;
@@ -17721,19 +18226,25 @@ Usage: glasstrace mcp add [--force] [--dry-run]
17721
18226
  }
17722
18227
  }
17723
18228
  if (result.summary.length > 0) {
17724
- process.stderr.write("\nGlasstrace initialized successfully!\n\n");
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
+ }
17725
18234
  for (const line of result.summary) {
17726
18235
  process.stderr.write(` - ${line}
17727
18236
  `);
17728
18237
  }
17729
- process.stderr.write("\nNext steps:\n");
17730
- process.stderr.write(" 1. Start your Next.js dev server\n");
17731
- process.stderr.write(
17732
- " 2. Glasstrace works immediately in anonymous mode\n"
17733
- );
17734
- process.stderr.write(
17735
- " 3. To link to your account, set GLASSTRACE_API_KEY in .env.local\n\n"
17736
- );
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
+ }
17737
18248
  }
17738
18249
  process.exit(result.exitCode);
17739
18250
  }).catch((err) => {
@@ -17836,6 +18347,7 @@ Usage:
17836
18347
  decideMcpConfigAction,
17837
18348
  meetsNodeVersion,
17838
18349
  rollbackSteps,
17839
- runInit
18350
+ runInit,
18351
+ verifyAnonKeyRegistration
17840
18352
  });
17841
18353
  //# sourceMappingURL=init.cjs.map