@glasstrace/sdk 0.19.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.
- package/README.md +79 -0
- package/dist/{chunk-XNDHQN4S.js → chunk-6JRI4OGB.js} +286 -54
- package/dist/chunk-6JRI4OGB.js.map +1 -0
- package/dist/cli/init.cjs +481 -152
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +48 -2
- package/dist/cli/init.d.ts +48 -2
- package/dist/cli/init.js +104 -4
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.js +1 -1
- package/dist/cli/uninit.cjs +172 -54
- package/dist/cli/uninit.cjs.map +1 -1
- package/dist/cli/uninit.d.cts +2 -0
- package/dist/cli/uninit.d.ts +2 -0
- package/dist/cli/uninit.js +2 -1
- package/dist/index.cjs +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XNDHQN4S.js.map +0 -1
package/dist/cli/uninit.cjs
CHANGED
|
@@ -45,9 +45,9 @@ __export(uninit_exports, {
|
|
|
45
45
|
writeShutdownMarker: () => writeShutdownMarker
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(uninit_exports);
|
|
48
|
-
var
|
|
48
|
+
var fs2 = __toESM(require("node:fs"), 1);
|
|
49
49
|
var os = __toESM(require("node:os"), 1);
|
|
50
|
-
var
|
|
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 =
|
|
382
|
-
if (!
|
|
470
|
+
const dirPath = path2.join(projectRoot, ".glasstrace");
|
|
471
|
+
if (!fs2.existsSync(dirPath)) {
|
|
383
472
|
return false;
|
|
384
473
|
}
|
|
385
|
-
const markerPath =
|
|
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
|
-
|
|
478
|
+
fs2.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
|
|
390
479
|
try {
|
|
391
|
-
|
|
480
|
+
fs2.chmodSync(tmpPath, 384);
|
|
392
481
|
} catch {
|
|
393
482
|
}
|
|
394
|
-
|
|
483
|
+
fs2.renameSync(tmpPath, markerPath);
|
|
395
484
|
return true;
|
|
396
485
|
} catch {
|
|
397
486
|
try {
|
|
398
|
-
|
|
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 =
|
|
440
|
-
if (
|
|
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 =
|
|
453
|
-
if (!
|
|
541
|
+
const configPath = path2.join(projectRoot, name);
|
|
542
|
+
if (!fs2.existsSync(configPath)) {
|
|
454
543
|
continue;
|
|
455
544
|
}
|
|
456
|
-
const content =
|
|
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
|
-
|
|
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 =
|
|
488
|
-
if (
|
|
489
|
-
const content =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
516
|
-
if (
|
|
604
|
+
const glasstraceDir = path2.join(projectRoot, ".glasstrace");
|
|
605
|
+
if (fs2.existsSync(glasstraceDir)) {
|
|
517
606
|
if (!dryRun) {
|
|
518
|
-
|
|
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
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
592
|
-
if (
|
|
593
|
-
const content =
|
|
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
|
-
|
|
727
|
+
fs2.unlinkSync(gitignorePath);
|
|
610
728
|
}
|
|
611
729
|
summary.push(`${prefix}Deleted .gitignore (no remaining entries)`);
|
|
612
730
|
} else {
|
|
613
731
|
if (!dryRun) {
|
|
614
|
-
|
|
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 =
|
|
628
|
-
if (!
|
|
745
|
+
const configPath = path2.join(projectRoot, configFile);
|
|
746
|
+
if (!fs2.existsSync(configPath)) {
|
|
629
747
|
continue;
|
|
630
748
|
}
|
|
631
|
-
const content =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
646
|
-
if (
|
|
647
|
-
const content =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
779
|
+
const hasWindsurfMarkers = fs2.existsSync(path2.join(projectRoot, ".windsurfrules")) || fs2.existsSync(path2.join(projectRoot, ".windsurf"));
|
|
662
780
|
if (hasWindsurfMarkers) {
|
|
663
|
-
const windsurfConfigPath =
|
|
781
|
+
const windsurfConfigPath = path2.join(
|
|
664
782
|
os.homedir(),
|
|
665
783
|
".codeium",
|
|
666
784
|
"windsurf",
|
|
667
785
|
"mcp_config.json"
|
|
668
786
|
);
|
|
669
|
-
if (
|
|
670
|
-
const content =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
699
|
-
if (!
|
|
816
|
+
const filePath = path2.join(projectRoot, infoFile);
|
|
817
|
+
if (!fs2.existsSync(filePath)) {
|
|
700
818
|
continue;
|
|
701
819
|
}
|
|
702
|
-
const content =
|
|
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
|
-
|
|
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
|
-
|
|
830
|
+
fs2.writeFileSync(filePath, result.content, "utf-8");
|
|
713
831
|
}
|
|
714
832
|
summary.push(`${prefix}Removed Glasstrace section from ${infoFile}`);
|
|
715
833
|
}
|