@glasstrace/sdk 0.18.0 → 0.20.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 (36) hide show
  1. package/README.md +79 -0
  2. package/dist/{chunk-GSGX76Q5.js → chunk-5N2IR4EO.js} +146 -3
  3. package/dist/chunk-5N2IR4EO.js.map +1 -0
  4. package/dist/{chunk-XNDHQN4S.js → chunk-6JRI4OGB.js} +286 -54
  5. package/dist/chunk-6JRI4OGB.js.map +1 -0
  6. package/dist/{chunk-IOPCSX6C.js → chunk-F2TZRBEH.js} +2 -2
  7. package/dist/{chunk-E33Y7BQH.js → chunk-VN3GZDV6.js} +2 -2
  8. package/dist/{chunk-J5BW7V2D.js → chunk-YPXW2TN3.js} +2 -2
  9. package/dist/cli/init.cjs +548 -153
  10. package/dist/cli/init.cjs.map +1 -1
  11. package/dist/cli/init.d.cts +48 -2
  12. package/dist/cli/init.d.ts +48 -2
  13. package/dist/cli/init.js +106 -6
  14. package/dist/cli/init.js.map +1 -1
  15. package/dist/cli/mcp-add.cjs +66 -0
  16. package/dist/cli/mcp-add.cjs.map +1 -1
  17. package/dist/cli/mcp-add.js +2 -2
  18. package/dist/cli/uninit.cjs +172 -54
  19. package/dist/cli/uninit.cjs.map +1 -1
  20. package/dist/cli/uninit.d.cts +2 -0
  21. package/dist/cli/uninit.d.ts +2 -0
  22. package/dist/cli/uninit.js +2 -1
  23. package/dist/index.cjs +157 -34
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +43 -12
  26. package/dist/index.d.ts +43 -12
  27. package/dist/index.js +19 -39
  28. package/dist/index.js.map +1 -1
  29. package/dist/{source-map-uploader-26QPRSCG.js → source-map-uploader-VPDZWWM2.js} +3 -3
  30. package/package.json +1 -1
  31. package/dist/chunk-GSGX76Q5.js.map +0 -1
  32. package/dist/chunk-XNDHQN4S.js.map +0 -1
  33. /package/dist/{chunk-IOPCSX6C.js.map → chunk-F2TZRBEH.js.map} +0 -0
  34. /package/dist/{chunk-E33Y7BQH.js.map → chunk-VN3GZDV6.js.map} +0 -0
  35. /package/dist/{chunk-J5BW7V2D.js.map → chunk-YPXW2TN3.js.map} +0 -0
  36. /package/dist/{source-map-uploader-26QPRSCG.js.map → source-map-uploader-VPDZWWM2.js.map} +0 -0
@@ -8,11 +8,11 @@ import {
8
8
  } from "../chunk-HAU66QBQ.js";
9
9
  import {
10
10
  readAnonKey
11
- } from "../chunk-J5BW7V2D.js";
12
- import "../chunk-GSGX76Q5.js";
11
+ } from "../chunk-YPXW2TN3.js";
13
12
  import {
14
13
  scaffoldMcpMarker
15
14
  } from "../chunk-O63DJKIJ.js";
15
+ import "../chunk-5N2IR4EO.js";
16
16
  import {
17
17
  MCP_ENDPOINT,
18
18
  formatAgentName
@@ -45,9 +45,9 @@ __export(uninit_exports, {
45
45
  writeShutdownMarker: () => writeShutdownMarker
46
46
  });
47
47
  module.exports = __toCommonJS(uninit_exports);
48
- var fs = __toESM(require("node:fs"), 1);
48
+ var fs2 = __toESM(require("node:fs"), 1);
49
49
  var os = __toESM(require("node:os"), 1);
50
- var path = __toESM(require("node:path"), 1);
50
+ var path2 = __toESM(require("node:path"), 1);
51
51
 
52
52
  // src/cli/constants.ts
53
53
  var NEXT_CONFIG_NAMES = ["next.config.ts", "next.config.js", "next.config.mjs"];
@@ -71,6 +71,95 @@ function isDevApiKey(value) {
71
71
  return value.trim().startsWith("gt_dev_");
72
72
  }
73
73
 
74
+ // src/cli/discovery-file.ts
75
+ var fs = __toESM(require("node:fs"), 1);
76
+ var path = __toESM(require("node:path"), 1);
77
+ function resolveStaticRoot(projectRoot) {
78
+ if (isSvelteKitProject(projectRoot)) {
79
+ return {
80
+ absolutePath: path.join(projectRoot, "static"),
81
+ layout: "static"
82
+ };
83
+ }
84
+ return {
85
+ absolutePath: path.join(projectRoot, "public"),
86
+ layout: "public"
87
+ };
88
+ }
89
+ function isSvelteKitProject(projectRoot) {
90
+ const pkgPath = path.join(projectRoot, "package.json");
91
+ let isEsm = false;
92
+ try {
93
+ const pkgContent = fs.readFileSync(pkgPath, "utf-8");
94
+ const parsed = JSON.parse(pkgContent);
95
+ isEsm = parsed.type === "module";
96
+ } catch {
97
+ return false;
98
+ }
99
+ if (!isEsm) return false;
100
+ const svelteConfigJs = path.join(projectRoot, "svelte.config.js");
101
+ const svelteConfigTs = path.join(projectRoot, "svelte.config.ts");
102
+ const appHtml = path.join(projectRoot, "src", "app.html");
103
+ return fs.existsSync(svelteConfigJs) || fs.existsSync(svelteConfigTs) || fs.existsSync(appHtml);
104
+ }
105
+ function relativeDiscoveryPath(layout) {
106
+ return layout === "static" ? "static/.well-known/glasstrace.json" : "public/.well-known/glasstrace.json";
107
+ }
108
+ function removeDiscoveryFile(projectRoot) {
109
+ const { layout: inferredLayout } = resolveStaticRoot(projectRoot);
110
+ const layouts = ["public", "static"];
111
+ const outcomes = [];
112
+ for (const layout of layouts) {
113
+ const staticRoot = path.join(projectRoot, layout);
114
+ const wellKnownDir = path.join(staticRoot, ".well-known");
115
+ const filePath = path.join(wellKnownDir, "glasstrace.json");
116
+ let removed = false;
117
+ try {
118
+ if (fs.existsSync(filePath)) {
119
+ fs.unlinkSync(filePath);
120
+ removed = true;
121
+ }
122
+ } catch (err) {
123
+ return {
124
+ action: "failed",
125
+ filePath,
126
+ layout,
127
+ directoryRemoved: false,
128
+ error: err instanceof Error ? err.message : String(err)
129
+ };
130
+ }
131
+ let directoryRemoved = false;
132
+ if (removed) {
133
+ try {
134
+ if (fs.existsSync(wellKnownDir)) {
135
+ const entries = fs.readdirSync(wellKnownDir);
136
+ if (entries.length === 0) {
137
+ fs.rmdirSync(wellKnownDir);
138
+ directoryRemoved = true;
139
+ }
140
+ }
141
+ } catch {
142
+ }
143
+ }
144
+ outcomes.push({ layout, filePath, removed, directoryRemoved });
145
+ }
146
+ const removals = outcomes.filter((o) => o.removed);
147
+ const chosen = (() => {
148
+ if (removals.length === 0) {
149
+ return outcomes.find((o) => o.layout === inferredLayout) ?? outcomes[0];
150
+ }
151
+ if (removals.length === 1) return removals[0];
152
+ return removals.find((o) => o.layout === inferredLayout) ?? removals[0];
153
+ })();
154
+ const anyDirectoryRemoved = outcomes.some((o) => o.directoryRemoved);
155
+ return {
156
+ action: removals.length > 0 ? "removed" : "not-found",
157
+ filePath: chosen.filePath,
158
+ layout: chosen.layout,
159
+ directoryRemoved: chosen.directoryRemoved || anyDirectoryRemoved
160
+ };
161
+ }
162
+
74
163
  // src/cli/uninit.ts
75
164
  var MCP_CONFIG_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json"];
76
165
  var AGENT_INFO_FILES = [
@@ -378,24 +467,24 @@ function processTomlMcpConfig(content) {
378
467
  return { action: "removed-section", content: result + "\n" };
379
468
  }
380
469
  function writeShutdownMarker(projectRoot) {
381
- const dirPath = path.join(projectRoot, ".glasstrace");
382
- if (!fs.existsSync(dirPath)) {
470
+ const dirPath = path2.join(projectRoot, ".glasstrace");
471
+ if (!fs2.existsSync(dirPath)) {
383
472
  return false;
384
473
  }
385
- const markerPath = path.join(dirPath, "shutdown-requested");
474
+ const markerPath = path2.join(dirPath, "shutdown-requested");
386
475
  const tmpPath = `${markerPath}.tmp`;
387
476
  const body = JSON.stringify({ requestedAt: (/* @__PURE__ */ new Date()).toISOString() });
388
477
  try {
389
- fs.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
478
+ fs2.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
390
479
  try {
391
- fs.chmodSync(tmpPath, 384);
480
+ fs2.chmodSync(tmpPath, 384);
392
481
  } catch {
393
482
  }
394
- fs.renameSync(tmpPath, markerPath);
483
+ fs2.renameSync(tmpPath, markerPath);
395
484
  return true;
396
485
  } catch {
397
486
  try {
398
- fs.unlinkSync(tmpPath);
487
+ fs2.unlinkSync(tmpPath);
399
488
  } catch {
400
489
  }
401
490
  return false;
@@ -436,8 +525,8 @@ async function runUninit(options) {
436
525
  summary.push("Wrote .glasstrace/shutdown-requested marker");
437
526
  }
438
527
  } else {
439
- const dirPath = path.join(projectRoot, ".glasstrace");
440
- if (fs.existsSync(dirPath)) {
528
+ const dirPath = path2.join(projectRoot, ".glasstrace");
529
+ if (fs2.existsSync(dirPath)) {
441
530
  summary.push(`${prefix}Would write .glasstrace/shutdown-requested marker`);
442
531
  }
443
532
  }
@@ -449,11 +538,11 @@ async function runUninit(options) {
449
538
  try {
450
539
  let configHandled = false;
451
540
  for (const name of NEXT_CONFIG_NAMES) {
452
- const configPath = path.join(projectRoot, name);
453
- if (!fs.existsSync(configPath)) {
541
+ const configPath = path2.join(projectRoot, name);
542
+ if (!fs2.existsSync(configPath)) {
454
543
  continue;
455
544
  }
456
- const content = fs.readFileSync(configPath, "utf-8");
545
+ const content = fs2.readFileSync(configPath, "utf-8");
457
546
  if (!content.includes("withGlasstraceConfig")) {
458
547
  continue;
459
548
  }
@@ -463,7 +552,7 @@ async function runUninit(options) {
463
552
  const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
464
553
  const final = cleanLeadingBlankLines(cleaned);
465
554
  if (!dryRun) {
466
- fs.writeFileSync(configPath, final, "utf-8");
555
+ fs2.writeFileSync(configPath, final, "utf-8");
467
556
  }
468
557
  summary.push(`${prefix}Unwrapped withGlasstraceConfig from ${name}`);
469
558
  configHandled = true;
@@ -484,20 +573,20 @@ async function runUninit(options) {
484
573
  );
485
574
  }
486
575
  try {
487
- const instrPath = path.join(projectRoot, "instrumentation.ts");
488
- if (fs.existsSync(instrPath)) {
489
- const content = fs.readFileSync(instrPath, "utf-8");
576
+ const instrPath = path2.join(projectRoot, "instrumentation.ts");
577
+ if (fs2.existsSync(instrPath)) {
578
+ const content = fs2.readFileSync(instrPath, "utf-8");
490
579
  if (content.includes("registerGlasstrace") || content.includes("@glasstrace/sdk")) {
491
580
  if (isInitCreatedInstrumentation(content)) {
492
581
  if (!dryRun) {
493
- fs.unlinkSync(instrPath);
582
+ fs2.unlinkSync(instrPath);
494
583
  }
495
584
  summary.push(`${prefix}Deleted instrumentation.ts (init-created)`);
496
585
  } else {
497
586
  const cleaned = removeRegisterGlasstrace(content);
498
587
  if (cleaned !== content) {
499
588
  if (!dryRun) {
500
- fs.writeFileSync(instrPath, cleaned, "utf-8");
589
+ fs2.writeFileSync(instrPath, cleaned, "utf-8");
501
590
  }
502
591
  summary.push(
503
592
  `${prefix}Removed registerGlasstrace() from instrumentation.ts`
@@ -512,10 +601,10 @@ async function runUninit(options) {
512
601
  );
513
602
  }
514
603
  try {
515
- const glasstraceDir = path.join(projectRoot, ".glasstrace");
516
- if (fs.existsSync(glasstraceDir)) {
604
+ const glasstraceDir = path2.join(projectRoot, ".glasstrace");
605
+ if (fs2.existsSync(glasstraceDir)) {
517
606
  if (!dryRun) {
518
- fs.rmSync(glasstraceDir, { recursive: true, force: true });
607
+ fs2.rmSync(glasstraceDir, { recursive: true, force: true });
519
608
  }
520
609
  summary.push(`${prefix}Removed .glasstrace/ directory`);
521
610
  }
@@ -525,9 +614,38 @@ async function runUninit(options) {
525
614
  );
526
615
  }
527
616
  try {
528
- const envPath = path.join(projectRoot, ".env.local");
529
- if (fs.existsSync(envPath)) {
530
- const content = fs.readFileSync(envPath, "utf-8");
617
+ if (dryRun) {
618
+ for (const previewLayout of ["public", "static"]) {
619
+ const relPath = relativeDiscoveryPath(previewLayout);
620
+ const absPath = path2.join(projectRoot, relPath);
621
+ if (fs2.existsSync(absPath)) {
622
+ summary.push(`${prefix}Would remove ${relPath}`);
623
+ }
624
+ }
625
+ } else {
626
+ const result = removeDiscoveryFile(projectRoot);
627
+ if (result.action === "removed") {
628
+ const relPath = relativeDiscoveryPath(result.layout);
629
+ summary.push(`Removed ${relPath}`);
630
+ if (result.directoryRemoved) {
631
+ const dirRel = relPath.replace(/\/glasstrace\.json$/, "/");
632
+ summary.push(`Removed empty ${dirRel}`);
633
+ }
634
+ } else if (result.action === "failed") {
635
+ warnings.push(
636
+ `Failed to remove ${relativeDiscoveryPath(result.layout)}${result.error !== void 0 ? `: ${result.error}` : ""}`
637
+ );
638
+ }
639
+ }
640
+ } catch (err) {
641
+ warnings.push(
642
+ `Failed to remove discovery file: ${err instanceof Error ? err.message : String(err)}`
643
+ );
644
+ }
645
+ try {
646
+ const envPath = path2.join(projectRoot, ".env.local");
647
+ if (fs2.existsSync(envPath)) {
648
+ const content = fs2.readFileSync(envPath, "utf-8");
531
649
  const existingKey = readEnvLocalApiKey(content);
532
650
  const hasDevKey = isDevApiKey(existingKey);
533
651
  let proceed = true;
@@ -560,12 +678,12 @@ async function runUninit(options) {
560
678
  const result = filtered.join("\n");
561
679
  if (result.trim().length === 0) {
562
680
  if (!dryRun) {
563
- fs.unlinkSync(envPath);
681
+ fs2.unlinkSync(envPath);
564
682
  }
565
683
  summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
566
684
  } else {
567
685
  if (!dryRun) {
568
- fs.writeFileSync(envPath, result, "utf-8");
686
+ fs2.writeFileSync(envPath, result, "utf-8");
569
687
  }
570
688
  let devKeyAnnotation = "";
571
689
  if (devKeyPath === "interactive-confirmed") {
@@ -588,9 +706,9 @@ async function runUninit(options) {
588
706
  );
589
707
  }
590
708
  try {
591
- const gitignorePath = path.join(projectRoot, ".gitignore");
592
- if (fs.existsSync(gitignorePath)) {
593
- const content = fs.readFileSync(gitignorePath, "utf-8");
709
+ const gitignorePath = path2.join(projectRoot, ".gitignore");
710
+ if (fs2.existsSync(gitignorePath)) {
711
+ const content = fs2.readFileSync(gitignorePath, "utf-8");
594
712
  const lines = content.split("\n");
595
713
  const mcpGitignoreEntries = /* @__PURE__ */ new Set([
596
714
  ".glasstrace/",
@@ -606,12 +724,12 @@ async function runUninit(options) {
606
724
  const result = filtered.join("\n");
607
725
  if (result.trim().length === 0) {
608
726
  if (!dryRun) {
609
- fs.unlinkSync(gitignorePath);
727
+ fs2.unlinkSync(gitignorePath);
610
728
  }
611
729
  summary.push(`${prefix}Deleted .gitignore (no remaining entries)`);
612
730
  } else {
613
731
  if (!dryRun) {
614
- fs.writeFileSync(gitignorePath, result, "utf-8");
732
+ fs2.writeFileSync(gitignorePath, result, "utf-8");
615
733
  }
616
734
  summary.push(`${prefix}Removed Glasstrace entries from .gitignore`);
617
735
  }
@@ -624,63 +742,63 @@ async function runUninit(options) {
624
742
  }
625
743
  try {
626
744
  for (const configFile of MCP_CONFIG_FILES) {
627
- const configPath = path.join(projectRoot, configFile);
628
- if (!fs.existsSync(configPath)) {
745
+ const configPath = path2.join(projectRoot, configFile);
746
+ if (!fs2.existsSync(configPath)) {
629
747
  continue;
630
748
  }
631
- const content = fs.readFileSync(configPath, "utf-8");
749
+ const content = fs2.readFileSync(configPath, "utf-8");
632
750
  const result = processJsonMcpConfig(content);
633
751
  if (result.action === "deleted") {
634
752
  if (!dryRun) {
635
- fs.unlinkSync(configPath);
753
+ fs2.unlinkSync(configPath);
636
754
  }
637
755
  summary.push(`${prefix}Deleted ${configFile}`);
638
756
  } else if (result.action === "removed-key" && result.content !== void 0) {
639
757
  if (!dryRun) {
640
- fs.writeFileSync(configPath, result.content, "utf-8");
758
+ fs2.writeFileSync(configPath, result.content, "utf-8");
641
759
  }
642
760
  summary.push(`${prefix}Removed glasstrace from ${configFile}`);
643
761
  }
644
762
  }
645
- const codexConfigPath = path.join(projectRoot, ".codex", "config.toml");
646
- if (fs.existsSync(codexConfigPath)) {
647
- const content = fs.readFileSync(codexConfigPath, "utf-8");
763
+ const codexConfigPath = path2.join(projectRoot, ".codex", "config.toml");
764
+ if (fs2.existsSync(codexConfigPath)) {
765
+ const content = fs2.readFileSync(codexConfigPath, "utf-8");
648
766
  const tomlResult = processTomlMcpConfig(content);
649
767
  if (tomlResult.action === "deleted") {
650
768
  if (!dryRun) {
651
- fs.unlinkSync(codexConfigPath);
769
+ fs2.unlinkSync(codexConfigPath);
652
770
  }
653
771
  summary.push(`${prefix}Deleted .codex/config.toml`);
654
772
  } else if (tomlResult.action === "removed-section" && tomlResult.content !== void 0) {
655
773
  if (!dryRun) {
656
- fs.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
774
+ fs2.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
657
775
  }
658
776
  summary.push(`${prefix}Removed glasstrace from .codex/config.toml`);
659
777
  }
660
778
  }
661
- const hasWindsurfMarkers = fs.existsSync(path.join(projectRoot, ".windsurfrules")) || fs.existsSync(path.join(projectRoot, ".windsurf"));
779
+ const hasWindsurfMarkers = fs2.existsSync(path2.join(projectRoot, ".windsurfrules")) || fs2.existsSync(path2.join(projectRoot, ".windsurf"));
662
780
  if (hasWindsurfMarkers) {
663
- const windsurfConfigPath = path.join(
781
+ const windsurfConfigPath = path2.join(
664
782
  os.homedir(),
665
783
  ".codeium",
666
784
  "windsurf",
667
785
  "mcp_config.json"
668
786
  );
669
- if (fs.existsSync(windsurfConfigPath)) {
670
- const content = fs.readFileSync(windsurfConfigPath, "utf-8");
787
+ if (fs2.existsSync(windsurfConfigPath)) {
788
+ const content = fs2.readFileSync(windsurfConfigPath, "utf-8");
671
789
  const windsurfResult = processJsonMcpConfig(content);
672
790
  const home = os.homedir();
673
791
  const displayPath = windsurfConfigPath.startsWith(home) ? "~" + windsurfConfigPath.slice(home.length) : windsurfConfigPath;
674
792
  if (windsurfResult.action === "deleted") {
675
793
  if (!dryRun) {
676
- fs.unlinkSync(windsurfConfigPath);
794
+ fs2.unlinkSync(windsurfConfigPath);
677
795
  }
678
796
  summary.push(
679
797
  `${prefix}Deleted global Windsurf config (${displayPath})`
680
798
  );
681
799
  } else if (windsurfResult.action === "removed-key" && windsurfResult.content !== void 0) {
682
800
  if (!dryRun) {
683
- fs.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
801
+ fs2.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
684
802
  }
685
803
  summary.push(
686
804
  `${prefix}Removed glasstrace from global Windsurf config (${displayPath})`
@@ -695,21 +813,21 @@ async function runUninit(options) {
695
813
  }
696
814
  try {
697
815
  for (const infoFile of AGENT_INFO_FILES) {
698
- const filePath = path.join(projectRoot, infoFile);
699
- if (!fs.existsSync(filePath)) {
816
+ const filePath = path2.join(projectRoot, infoFile);
817
+ if (!fs2.existsSync(filePath)) {
700
818
  continue;
701
819
  }
702
- const content = fs.readFileSync(filePath, "utf-8");
820
+ const content = fs2.readFileSync(filePath, "utf-8");
703
821
  const result = removeMarkerSection(content);
704
822
  if (result.removed) {
705
823
  if (result.content.trim().length === 0) {
706
824
  if (!dryRun) {
707
- fs.unlinkSync(filePath);
825
+ fs2.unlinkSync(filePath);
708
826
  }
709
827
  summary.push(`${prefix}Deleted ${infoFile} (only contained Glasstrace section)`);
710
828
  } else {
711
829
  if (!dryRun) {
712
- fs.writeFileSync(filePath, result.content, "utf-8");
830
+ fs2.writeFileSync(filePath, result.content, "utf-8");
713
831
  }
714
832
  summary.push(`${prefix}Removed Glasstrace section from ${infoFile}`);
715
833
  }