@glasstrace/sdk 0.10.0 → 0.12.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/dist/adapters/drizzle.js +1 -1
- package/dist/{chunk-ZRNG36LU.js → chunk-6GRNJ722.js} +38 -17
- package/dist/chunk-6GRNJ722.js.map +1 -0
- package/dist/chunk-IPGOKORJ.js +580 -0
- package/dist/chunk-IPGOKORJ.js.map +1 -0
- package/dist/{chunk-5MAHIPFH.js → chunk-LW7DPKBA.js} +2 -2
- package/dist/{chunk-KOYJ2UQE.js → chunk-MSMOH6IH.js} +108 -38
- package/dist/chunk-MSMOH6IH.js.map +1 -0
- package/dist/chunk-NSBPE2FW.js +17 -0
- package/dist/{chunk-O3Y45VGV.js → chunk-OKIP4SRG.js} +5 -3
- package/dist/{chunk-O3Y45VGV.js.map → chunk-OKIP4SRG.js.map} +1 -1
- package/dist/cli/init.cjs +457 -330
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +25 -1
- package/dist/cli/init.d.ts +25 -1
- package/dist/cli/init.js +114 -4
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.cjs +63 -47
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/uninit.js +15 -564
- package/dist/cli/uninit.js.map +1 -1
- package/dist/{esm-POMEQPKL.js → esm-KBPHCVB4.js} +2 -2
- package/dist/{getMachineId-bsd-TC3JSTY5.js → getMachineId-bsd-345PYXFX.js} +2 -2
- package/dist/{getMachineId-darwin-2SUKQCE6.js → getMachineId-darwin-5L2D25AD.js} +2 -2
- package/dist/{getMachineId-linux-PNAFHLXH.js → getMachineId-linux-KJR4P5HN.js} +2 -2
- package/dist/{getMachineId-unsupported-L2MNYW3W.js → getMachineId-unsupported-NDNXDYDY.js} +2 -2
- package/dist/{getMachineId-win-D6D42WOQ.js → getMachineId-win-T7PJNJXG.js} +2 -2
- package/dist/index.cjs +327 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -11
- package/dist/index.d.ts +75 -11
- package/dist/index.js +159 -82
- package/dist/index.js.map +1 -1
- package/dist/{source-map-uploader-OA5NCDOK.js → source-map-uploader-ZFCYOURS.js} +6 -4
- package/package.json +1 -1
- package/dist/chunk-KOYJ2UQE.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-ZRNG36LU.js.map +0 -1
- /package/dist/{chunk-5MAHIPFH.js.map → chunk-LW7DPKBA.js.map} +0 -0
- /package/dist/{chunk-PZ5AY32C.js.map → chunk-NSBPE2FW.js.map} +0 -0
- /package/dist/{esm-POMEQPKL.js.map → esm-KBPHCVB4.js.map} +0 -0
- /package/dist/{getMachineId-bsd-TC3JSTY5.js.map → getMachineId-bsd-345PYXFX.js.map} +0 -0
- /package/dist/{getMachineId-darwin-2SUKQCE6.js.map → getMachineId-darwin-5L2D25AD.js.map} +0 -0
- /package/dist/{getMachineId-linux-PNAFHLXH.js.map → getMachineId-linux-KJR4P5HN.js.map} +0 -0
- /package/dist/{getMachineId-unsupported-L2MNYW3W.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +0 -0
- /package/dist/{getMachineId-win-D6D42WOQ.js.map → getMachineId-win-T7PJNJXG.js.map} +0 -0
- /package/dist/{source-map-uploader-OA5NCDOK.js.map → source-map-uploader-ZFCYOURS.js.map} +0 -0
package/dist/cli/mcp-add.js
CHANGED
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
} from "../chunk-4NDQPWDJ.js";
|
|
10
10
|
import {
|
|
11
11
|
readAnonKey
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-6GRNJ722.js";
|
|
13
|
+
import "../chunk-OKIP4SRG.js";
|
|
14
14
|
import {
|
|
15
15
|
MCP_ENDPOINT,
|
|
16
16
|
formatAgentName
|
|
17
17
|
} from "../chunk-DXRZKKSO.js";
|
|
18
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-NSBPE2FW.js";
|
|
19
19
|
|
|
20
20
|
// src/cli/mcp-add.ts
|
|
21
21
|
import { execFile as execFileCb } from "child_process";
|
package/dist/cli/uninit.js
CHANGED
|
@@ -1,568 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let i = start + 1;
|
|
18
|
-
while (i < text.length) {
|
|
19
|
-
if (text[i] === "\\") {
|
|
20
|
-
i += 2;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (text[i] === quote) {
|
|
24
|
-
return i + 1;
|
|
25
|
-
}
|
|
26
|
-
i++;
|
|
27
|
-
}
|
|
28
|
-
return text.length;
|
|
29
|
-
}
|
|
30
|
-
function findMatchingDelimiter(text, openPos, openChar, closeChar) {
|
|
31
|
-
let depth = 0;
|
|
32
|
-
let i = openPos;
|
|
33
|
-
while (i < text.length) {
|
|
34
|
-
const ch = text[i];
|
|
35
|
-
if (ch === '"' || ch === "'" || ch === "`") {
|
|
36
|
-
i = skipString(text, i, ch);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (ch === "/" && text[i + 1] === "/") {
|
|
40
|
-
const newline = text.indexOf("\n", i);
|
|
41
|
-
if (newline === -1) {
|
|
42
|
-
return -1;
|
|
43
|
-
}
|
|
44
|
-
i = newline + 1;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (ch === "/" && text[i + 1] === "*") {
|
|
48
|
-
const end = text.indexOf("*/", i + 2);
|
|
49
|
-
if (end === -1) {
|
|
50
|
-
return -1;
|
|
51
|
-
}
|
|
52
|
-
i = end + 2;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (ch === openChar) {
|
|
56
|
-
depth++;
|
|
57
|
-
} else if (ch === closeChar) {
|
|
58
|
-
depth--;
|
|
59
|
-
if (depth === 0) {
|
|
60
|
-
return i;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
i++;
|
|
64
|
-
}
|
|
65
|
-
return -1;
|
|
66
|
-
}
|
|
67
|
-
function findMatchingParen(text, openPos) {
|
|
68
|
-
return findMatchingDelimiter(text, openPos, "(", ")");
|
|
69
|
-
}
|
|
70
|
-
function unwrapExport(content) {
|
|
71
|
-
const pattern = /export\s+default\s+withGlasstraceConfig\s*\(/;
|
|
72
|
-
const match = pattern.exec(content);
|
|
73
|
-
if (!match) {
|
|
74
|
-
return { content, unwrapped: false };
|
|
75
|
-
}
|
|
76
|
-
const openParenIdx = match.index + match[0].length - 1;
|
|
77
|
-
const closeParenIdx = findMatchingParen(content, openParenIdx);
|
|
78
|
-
if (closeParenIdx === -1) {
|
|
79
|
-
return { content, unwrapped: false };
|
|
80
|
-
}
|
|
81
|
-
const innerExpr = content.slice(openParenIdx + 1, closeParenIdx).trim();
|
|
82
|
-
if (innerExpr.length === 0) {
|
|
83
|
-
return { content, unwrapped: false };
|
|
84
|
-
}
|
|
85
|
-
const before = content.slice(0, match.index);
|
|
86
|
-
const afterClose = content.slice(closeParenIdx + 1);
|
|
87
|
-
const trailing = afterClose.replace(/^;?\s*/, "");
|
|
88
|
-
const result = before + `export default ${innerExpr};
|
|
89
|
-
` + trailing;
|
|
90
|
-
return { content: result, unwrapped: true };
|
|
91
|
-
}
|
|
92
|
-
function unwrapCJSExport(content) {
|
|
93
|
-
const pattern = /module\.exports\s*=\s*withGlasstraceConfig\s*\(/;
|
|
94
|
-
const match = pattern.exec(content);
|
|
95
|
-
if (!match) {
|
|
96
|
-
return { content, unwrapped: false };
|
|
97
|
-
}
|
|
98
|
-
const openParenIdx = match.index + match[0].length - 1;
|
|
99
|
-
const closeParenIdx = findMatchingParen(content, openParenIdx);
|
|
100
|
-
if (closeParenIdx === -1) {
|
|
101
|
-
return { content, unwrapped: false };
|
|
102
|
-
}
|
|
103
|
-
const innerExpr = content.slice(openParenIdx + 1, closeParenIdx).trim();
|
|
104
|
-
if (innerExpr.length === 0) {
|
|
105
|
-
return { content, unwrapped: false };
|
|
106
|
-
}
|
|
107
|
-
const before = content.slice(0, match.index);
|
|
108
|
-
const afterClose = content.slice(closeParenIdx + 1);
|
|
109
|
-
const trailing = afterClose.replace(/^;?\s*/, "");
|
|
110
|
-
const result = before + `module.exports = ${innerExpr};
|
|
111
|
-
` + trailing;
|
|
112
|
-
return { content: result, unwrapped: true };
|
|
113
|
-
}
|
|
114
|
-
function removeGlasstraceConfigImport(content) {
|
|
115
|
-
const esmSoleImport = /import\s*\{\s*withGlasstraceConfig\s*\}\s*from\s*["']@glasstrace\/sdk["']\s*;?\s*\n?/;
|
|
116
|
-
if (esmSoleImport.test(content)) {
|
|
117
|
-
return content.replace(esmSoleImport, "");
|
|
118
|
-
}
|
|
119
|
-
const esmMultiImport = /import\s*\{([^}]*)\}\s*from\s*["']@glasstrace\/sdk["']/;
|
|
120
|
-
const multiMatch = esmMultiImport.exec(content);
|
|
121
|
-
if (multiMatch) {
|
|
122
|
-
const specifiers = multiMatch[1].split(",").map((s) => s.trim()).filter((s) => s !== "" && s !== "withGlasstraceConfig");
|
|
123
|
-
if (specifiers.length === 0) {
|
|
124
|
-
return content.replace(
|
|
125
|
-
/import\s*\{[^}]*\}\s*from\s*["']@glasstrace\/sdk["']\s*;?\s*\n?/,
|
|
126
|
-
""
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
const newImport = `import { ${specifiers.join(", ")} } from "@glasstrace/sdk"`;
|
|
130
|
-
return content.replace(multiMatch[0], newImport);
|
|
131
|
-
}
|
|
132
|
-
const cjsSoleRequire = /const\s*\{\s*withGlasstraceConfig\s*\}\s*=\s*require\s*\(\s*["']@glasstrace\/sdk["']\s*\)\s*;?\s*\n?/;
|
|
133
|
-
if (cjsSoleRequire.test(content)) {
|
|
134
|
-
return content.replace(cjsSoleRequire, "");
|
|
135
|
-
}
|
|
136
|
-
const cjsMultiRequire = /const\s*\{([^}]*)\}\s*=\s*require\s*\(\s*["']@glasstrace\/sdk["']\s*\)/;
|
|
137
|
-
const cjsMultiMatch = cjsMultiRequire.exec(content);
|
|
138
|
-
if (cjsMultiMatch) {
|
|
139
|
-
const specifiers = cjsMultiMatch[1].split(",").map((s) => s.trim()).filter((s) => s !== "" && s !== "withGlasstraceConfig");
|
|
140
|
-
if (specifiers.length === 0) {
|
|
141
|
-
return content.replace(
|
|
142
|
-
/const\s*\{[^}]*\}\s*=\s*require\s*\(\s*["']@glasstrace\/sdk["']\s*\)\s*;?\s*\n?/,
|
|
143
|
-
""
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
const newRequire = `const { ${specifiers.join(", ")} } = require("@glasstrace/sdk")`;
|
|
147
|
-
return content.replace(cjsMultiMatch[0], newRequire);
|
|
148
|
-
}
|
|
149
|
-
return content;
|
|
150
|
-
}
|
|
151
|
-
function cleanLeadingBlankLines(content) {
|
|
152
|
-
return content.replace(/^\n{2,}/, "\n");
|
|
153
|
-
}
|
|
154
|
-
function isInitCreatedInstrumentation(content) {
|
|
155
|
-
const lines = content.split("\n");
|
|
156
|
-
const importLines = lines.filter(
|
|
157
|
-
(l) => /^\s*import\s/.test(l) && !l.trim().startsWith("//")
|
|
158
|
-
);
|
|
159
|
-
const nonGlasstraceImports = importLines.filter(
|
|
160
|
-
(l) => !l.includes("@glasstrace/sdk")
|
|
161
|
-
);
|
|
162
|
-
if (nonGlasstraceImports.length > 0) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
const registerFnRegex = /export\s+(?:async\s+)?function\s+register\s*\([^)]*\)\s*\{/;
|
|
166
|
-
const match = registerFnRegex.exec(content);
|
|
167
|
-
if (!match) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
const afterBrace = content.slice(match.index + match[0].length);
|
|
171
|
-
const closingBraceIdx = findMatchingBrace(content, match.index + match[0].length - 1);
|
|
172
|
-
if (closingBraceIdx === -1) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
const body = afterBrace.slice(0, closingBraceIdx - (match.index + match[0].length));
|
|
176
|
-
const bodyLines = body.split("\n");
|
|
177
|
-
const statements = bodyLines.filter((l) => {
|
|
178
|
-
const trimmed = l.trim();
|
|
179
|
-
return trimmed !== "" && !trimmed.startsWith("//");
|
|
180
|
-
});
|
|
181
|
-
if (statements.length !== 1) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
if (!/^\s*registerGlasstrace\s*\(\s*\)\s*;?\s*$/.test(statements[0])) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
const beforeFn = content.slice(0, match.index);
|
|
188
|
-
const afterFn = content.slice(closingBraceIdx + 1);
|
|
189
|
-
const topLevelBefore = beforeFn.split("\n").filter((l) => {
|
|
190
|
-
const trimmed = l.trim();
|
|
191
|
-
return trimmed !== "" && !trimmed.startsWith("//") && !trimmed.startsWith("import ") && !trimmed.startsWith("import{");
|
|
192
|
-
});
|
|
193
|
-
const topLevelAfter = afterFn.split("\n").filter((l) => {
|
|
194
|
-
const trimmed = l.trim();
|
|
195
|
-
return trimmed !== "" && !trimmed.startsWith("//");
|
|
196
|
-
});
|
|
197
|
-
return topLevelBefore.length === 0 && topLevelAfter.length === 0;
|
|
198
|
-
}
|
|
199
|
-
function findMatchingBrace(text, openPos) {
|
|
200
|
-
return findMatchingDelimiter(text, openPos, "{", "}");
|
|
201
|
-
}
|
|
202
|
-
function removeRegisterGlasstrace(content) {
|
|
203
|
-
let result = content;
|
|
204
|
-
result = result.replace(
|
|
205
|
-
/[ \t]*\/\/\s*Glasstrace must be registered[^\n]*\n(?:[ \t]*\/\/[^\n]*\n)*[ \t]*registerGlasstrace\s*\(\s*\)\s*;?\s*\n?/g,
|
|
206
|
-
""
|
|
207
|
-
);
|
|
208
|
-
result = result.replace(
|
|
209
|
-
/[ \t]*registerGlasstrace\s*\(\s*\)\s*;?\s*\n?/g,
|
|
210
|
-
""
|
|
211
|
-
);
|
|
212
|
-
const soleImportPattern = /import\s*\{\s*registerGlasstrace\s*\}\s*from\s*["']@glasstrace\/sdk["']\s*;?\s*\n?/;
|
|
213
|
-
if (soleImportPattern.test(result)) {
|
|
214
|
-
result = result.replace(soleImportPattern, "");
|
|
215
|
-
} else {
|
|
216
|
-
const multiImportPattern = /import\s*\{([^}]*)\}\s*from\s*["']@glasstrace\/sdk["']/;
|
|
217
|
-
const multiMatch = multiImportPattern.exec(result);
|
|
218
|
-
if (multiMatch) {
|
|
219
|
-
const specifiers = multiMatch[1].split(",").map((s) => s.trim()).filter((s) => s !== "" && s !== "registerGlasstrace");
|
|
220
|
-
if (specifiers.length === 0) {
|
|
221
|
-
result = result.replace(
|
|
222
|
-
/import\s*\{[^}]*\}\s*from\s*["']@glasstrace\/sdk["']\s*;?\s*\n?/,
|
|
223
|
-
""
|
|
224
|
-
);
|
|
225
|
-
} else {
|
|
226
|
-
const newImport = `import { ${specifiers.join(", ")} } from "@glasstrace/sdk"`;
|
|
227
|
-
result = result.replace(multiMatch[0], newImport);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return cleanLeadingBlankLines(result);
|
|
232
|
-
}
|
|
233
|
-
function removeMarkerSection(content) {
|
|
234
|
-
const lines = content.split("\n");
|
|
235
|
-
let startIdx = -1;
|
|
236
|
-
let endIdx = -1;
|
|
237
|
-
for (let i = 0; i < lines.length; i++) {
|
|
238
|
-
const trimmed = lines[i].trim();
|
|
239
|
-
if (trimmed === "<!-- glasstrace:mcp:start -->" || trimmed === "# glasstrace:mcp:start") {
|
|
240
|
-
startIdx = i;
|
|
241
|
-
} else if ((trimmed === "<!-- glasstrace:mcp:end -->" || trimmed === "# glasstrace:mcp:end") && startIdx !== -1) {
|
|
242
|
-
endIdx = i;
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (startIdx === -1 || endIdx === -1) {
|
|
247
|
-
return { content, removed: false };
|
|
248
|
-
}
|
|
249
|
-
const before = lines.slice(0, startIdx);
|
|
250
|
-
const after = lines.slice(endIdx + 1);
|
|
251
|
-
while (before.length > 0 && before[before.length - 1].trim() === "") {
|
|
252
|
-
before.pop();
|
|
253
|
-
}
|
|
254
|
-
const result = [...before, ...after].join("\n");
|
|
255
|
-
const trimmedResult = result.trimEnd();
|
|
256
|
-
return {
|
|
257
|
-
content: trimmedResult.length > 0 ? trimmedResult + "\n" : "",
|
|
258
|
-
removed: true
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function processJsonMcpConfig(content) {
|
|
262
|
-
let parsed;
|
|
263
|
-
try {
|
|
264
|
-
parsed = JSON.parse(content);
|
|
265
|
-
} catch {
|
|
266
|
-
return { action: "skipped" };
|
|
267
|
-
}
|
|
268
|
-
const mcpServers = parsed["mcpServers"];
|
|
269
|
-
if (!mcpServers || typeof mcpServers !== "object" || !("glasstrace" in mcpServers)) {
|
|
270
|
-
return { action: "skipped" };
|
|
271
|
-
}
|
|
272
|
-
const remainingServers = Object.keys(mcpServers).filter((k) => k !== "glasstrace");
|
|
273
|
-
const otherTopLevelKeys = Object.keys(parsed).filter((k) => k !== "mcpServers");
|
|
274
|
-
if (remainingServers.length === 0 && otherTopLevelKeys.length === 0) {
|
|
275
|
-
return { action: "deleted" };
|
|
276
|
-
}
|
|
277
|
-
const { glasstrace: _, ...rest } = mcpServers;
|
|
278
|
-
void _;
|
|
279
|
-
if (remainingServers.length > 0) {
|
|
280
|
-
parsed["mcpServers"] = rest;
|
|
281
|
-
} else {
|
|
282
|
-
delete parsed["mcpServers"];
|
|
283
|
-
}
|
|
284
|
-
return { action: "removed-key", content: JSON.stringify(parsed, null, 2) + "\n" };
|
|
285
|
-
}
|
|
286
|
-
function processTomlMcpConfig(content) {
|
|
287
|
-
if (!content.includes("[mcp_servers.glasstrace]")) {
|
|
288
|
-
return { action: "skipped" };
|
|
289
|
-
}
|
|
290
|
-
const lines = content.split("\n");
|
|
291
|
-
const startIdx = lines.findIndex(
|
|
292
|
-
(l) => l.trim() === "[mcp_servers.glasstrace]"
|
|
293
|
-
);
|
|
294
|
-
if (startIdx === -1) {
|
|
295
|
-
return { action: "skipped" };
|
|
296
|
-
}
|
|
297
|
-
let endIdx = lines.length;
|
|
298
|
-
for (let i = startIdx + 1; i < lines.length; i++) {
|
|
299
|
-
if (/^\s*\[/.test(lines[i])) {
|
|
300
|
-
endIdx = i;
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const before = lines.slice(0, startIdx);
|
|
305
|
-
const after = lines.slice(endIdx);
|
|
306
|
-
while (before.length > 0 && before[before.length - 1].trim() === "") {
|
|
307
|
-
before.pop();
|
|
308
|
-
}
|
|
309
|
-
const result = [...before, ...after].join("\n").trimEnd();
|
|
310
|
-
if (result.trim().length === 0) {
|
|
311
|
-
return { action: "deleted" };
|
|
312
|
-
}
|
|
313
|
-
return { action: "removed-section", content: result + "\n" };
|
|
314
|
-
}
|
|
315
|
-
async function runUninit(options) {
|
|
316
|
-
const { projectRoot, dryRun } = options;
|
|
317
|
-
const summary = [];
|
|
318
|
-
const warnings = [];
|
|
319
|
-
const errors = [];
|
|
320
|
-
const prefix = dryRun ? "[dry run] " : "";
|
|
321
|
-
try {
|
|
322
|
-
let configHandled = false;
|
|
323
|
-
for (const name of NEXT_CONFIG_NAMES) {
|
|
324
|
-
const configPath = path.join(projectRoot, name);
|
|
325
|
-
if (!fs.existsSync(configPath)) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
const content = fs.readFileSync(configPath, "utf-8");
|
|
329
|
-
if (!content.includes("withGlasstraceConfig")) {
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
const isESM = name.endsWith(".ts") || name.endsWith(".mjs");
|
|
333
|
-
const unwrapResult = isESM ? unwrapExport(content) : unwrapCJSExport(content);
|
|
334
|
-
if (unwrapResult.unwrapped) {
|
|
335
|
-
const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
|
|
336
|
-
const final = cleanLeadingBlankLines(cleaned);
|
|
337
|
-
if (!dryRun) {
|
|
338
|
-
fs.writeFileSync(configPath, final, "utf-8");
|
|
339
|
-
}
|
|
340
|
-
summary.push(`${prefix}Unwrapped withGlasstraceConfig from ${name}`);
|
|
341
|
-
configHandled = true;
|
|
342
|
-
break;
|
|
343
|
-
} else {
|
|
344
|
-
warnings.push(
|
|
345
|
-
`${name} contains withGlasstraceConfig but could not be automatically unwrapped. Please remove withGlasstraceConfig() manually.`
|
|
346
|
-
);
|
|
347
|
-
configHandled = true;
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (!configHandled) {
|
|
352
|
-
}
|
|
353
|
-
} catch (err) {
|
|
354
|
-
errors.push(
|
|
355
|
-
`Failed to process next.config: ${err instanceof Error ? err.message : String(err)}`
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
try {
|
|
359
|
-
const instrPath = path.join(projectRoot, "instrumentation.ts");
|
|
360
|
-
if (fs.existsSync(instrPath)) {
|
|
361
|
-
const content = fs.readFileSync(instrPath, "utf-8");
|
|
362
|
-
if (content.includes("registerGlasstrace") || content.includes("@glasstrace/sdk")) {
|
|
363
|
-
if (isInitCreatedInstrumentation(content)) {
|
|
364
|
-
if (!dryRun) {
|
|
365
|
-
fs.unlinkSync(instrPath);
|
|
366
|
-
}
|
|
367
|
-
summary.push(`${prefix}Deleted instrumentation.ts (init-created)`);
|
|
368
|
-
} else {
|
|
369
|
-
const cleaned = removeRegisterGlasstrace(content);
|
|
370
|
-
if (cleaned !== content) {
|
|
371
|
-
if (!dryRun) {
|
|
372
|
-
fs.writeFileSync(instrPath, cleaned, "utf-8");
|
|
373
|
-
}
|
|
374
|
-
summary.push(
|
|
375
|
-
`${prefix}Removed registerGlasstrace() from instrumentation.ts`
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
} catch (err) {
|
|
382
|
-
errors.push(
|
|
383
|
-
`Failed to process instrumentation.ts: ${err instanceof Error ? err.message : String(err)}`
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
try {
|
|
387
|
-
const glasstraceDir = path.join(projectRoot, ".glasstrace");
|
|
388
|
-
if (fs.existsSync(glasstraceDir)) {
|
|
389
|
-
if (!dryRun) {
|
|
390
|
-
fs.rmSync(glasstraceDir, { recursive: true, force: true });
|
|
391
|
-
}
|
|
392
|
-
summary.push(`${prefix}Removed .glasstrace/ directory`);
|
|
393
|
-
}
|
|
394
|
-
} catch (err) {
|
|
395
|
-
errors.push(
|
|
396
|
-
`Failed to remove .glasstrace/: ${err instanceof Error ? err.message : String(err)}`
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
try {
|
|
400
|
-
const envPath = path.join(projectRoot, ".env.local");
|
|
401
|
-
if (fs.existsSync(envPath)) {
|
|
402
|
-
const content = fs.readFileSync(envPath, "utf-8");
|
|
403
|
-
const lines = content.split("\n");
|
|
404
|
-
const filtered = lines.filter((line) => {
|
|
405
|
-
const trimmed = line.trim();
|
|
406
|
-
return !(/^\s*#?\s*GLASSTRACE_API_KEY\s*=/.test(trimmed) || /^\s*#?\s*GLASSTRACE_COVERAGE_MAP\s*=/.test(trimmed));
|
|
407
|
-
});
|
|
408
|
-
if (filtered.length !== lines.length) {
|
|
409
|
-
const result = filtered.join("\n");
|
|
410
|
-
if (result.trim().length === 0) {
|
|
411
|
-
if (!dryRun) {
|
|
412
|
-
fs.unlinkSync(envPath);
|
|
413
|
-
}
|
|
414
|
-
summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
|
|
415
|
-
} else {
|
|
416
|
-
if (!dryRun) {
|
|
417
|
-
fs.writeFileSync(envPath, result, "utf-8");
|
|
418
|
-
}
|
|
419
|
-
summary.push(`${prefix}Removed GLASSTRACE entries from .env.local`);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
} catch (err) {
|
|
424
|
-
errors.push(
|
|
425
|
-
`Failed to process .env.local: ${err instanceof Error ? err.message : String(err)}`
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
try {
|
|
429
|
-
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
430
|
-
if (fs.existsSync(gitignorePath)) {
|
|
431
|
-
const content = fs.readFileSync(gitignorePath, "utf-8");
|
|
432
|
-
const lines = content.split("\n");
|
|
433
|
-
const mcpGitignoreEntries = /* @__PURE__ */ new Set([
|
|
434
|
-
".glasstrace/",
|
|
435
|
-
".mcp.json",
|
|
436
|
-
".cursor/mcp.json",
|
|
437
|
-
".gemini/settings.json",
|
|
438
|
-
".codex/config.toml"
|
|
439
|
-
]);
|
|
440
|
-
const filtered = lines.filter(
|
|
441
|
-
(line) => !mcpGitignoreEntries.has(line.trim())
|
|
442
|
-
);
|
|
443
|
-
if (filtered.length !== lines.length) {
|
|
444
|
-
const result = filtered.join("\n");
|
|
445
|
-
if (result.trim().length === 0) {
|
|
446
|
-
if (!dryRun) {
|
|
447
|
-
fs.unlinkSync(gitignorePath);
|
|
448
|
-
}
|
|
449
|
-
summary.push(`${prefix}Deleted .gitignore (no remaining entries)`);
|
|
450
|
-
} else {
|
|
451
|
-
if (!dryRun) {
|
|
452
|
-
fs.writeFileSync(gitignorePath, result, "utf-8");
|
|
453
|
-
}
|
|
454
|
-
summary.push(`${prefix}Removed Glasstrace entries from .gitignore`);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
} catch (err) {
|
|
459
|
-
errors.push(
|
|
460
|
-
`Failed to process .gitignore: ${err instanceof Error ? err.message : String(err)}`
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
try {
|
|
464
|
-
for (const configFile of MCP_CONFIG_FILES) {
|
|
465
|
-
const configPath = path.join(projectRoot, configFile);
|
|
466
|
-
if (!fs.existsSync(configPath)) {
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
const content = fs.readFileSync(configPath, "utf-8");
|
|
470
|
-
const result = processJsonMcpConfig(content);
|
|
471
|
-
if (result.action === "deleted") {
|
|
472
|
-
if (!dryRun) {
|
|
473
|
-
fs.unlinkSync(configPath);
|
|
474
|
-
}
|
|
475
|
-
summary.push(`${prefix}Deleted ${configFile}`);
|
|
476
|
-
} else if (result.action === "removed-key" && result.content !== void 0) {
|
|
477
|
-
if (!dryRun) {
|
|
478
|
-
fs.writeFileSync(configPath, result.content, "utf-8");
|
|
479
|
-
}
|
|
480
|
-
summary.push(`${prefix}Removed glasstrace from ${configFile}`);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
const codexConfigPath = path.join(projectRoot, ".codex", "config.toml");
|
|
484
|
-
if (fs.existsSync(codexConfigPath)) {
|
|
485
|
-
const content = fs.readFileSync(codexConfigPath, "utf-8");
|
|
486
|
-
const tomlResult = processTomlMcpConfig(content);
|
|
487
|
-
if (tomlResult.action === "deleted") {
|
|
488
|
-
if (!dryRun) {
|
|
489
|
-
fs.unlinkSync(codexConfigPath);
|
|
490
|
-
}
|
|
491
|
-
summary.push(`${prefix}Deleted .codex/config.toml`);
|
|
492
|
-
} else if (tomlResult.action === "removed-section" && tomlResult.content !== void 0) {
|
|
493
|
-
if (!dryRun) {
|
|
494
|
-
fs.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
|
|
495
|
-
}
|
|
496
|
-
summary.push(`${prefix}Removed glasstrace from .codex/config.toml`);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
const hasWindsurfMarkers = fs.existsSync(path.join(projectRoot, ".windsurfrules")) || fs.existsSync(path.join(projectRoot, ".windsurf"));
|
|
500
|
-
if (hasWindsurfMarkers) {
|
|
501
|
-
const windsurfConfigPath = path.join(
|
|
502
|
-
os.homedir(),
|
|
503
|
-
".codeium",
|
|
504
|
-
"windsurf",
|
|
505
|
-
"mcp_config.json"
|
|
506
|
-
);
|
|
507
|
-
if (fs.existsSync(windsurfConfigPath)) {
|
|
508
|
-
const content = fs.readFileSync(windsurfConfigPath, "utf-8");
|
|
509
|
-
const windsurfResult = processJsonMcpConfig(content);
|
|
510
|
-
const home = os.homedir();
|
|
511
|
-
const displayPath = windsurfConfigPath.startsWith(home) ? "~" + windsurfConfigPath.slice(home.length) : windsurfConfigPath;
|
|
512
|
-
if (windsurfResult.action === "deleted") {
|
|
513
|
-
if (!dryRun) {
|
|
514
|
-
fs.unlinkSync(windsurfConfigPath);
|
|
515
|
-
}
|
|
516
|
-
summary.push(
|
|
517
|
-
`${prefix}Deleted global Windsurf config (${displayPath})`
|
|
518
|
-
);
|
|
519
|
-
} else if (windsurfResult.action === "removed-key" && windsurfResult.content !== void 0) {
|
|
520
|
-
if (!dryRun) {
|
|
521
|
-
fs.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
|
|
522
|
-
}
|
|
523
|
-
summary.push(
|
|
524
|
-
`${prefix}Removed glasstrace from global Windsurf config (${displayPath})`
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
} catch (err) {
|
|
530
|
-
errors.push(
|
|
531
|
-
`Failed to process MCP config: ${err instanceof Error ? err.message : String(err)}`
|
|
532
|
-
);
|
|
533
|
-
}
|
|
534
|
-
try {
|
|
535
|
-
for (const infoFile of AGENT_INFO_FILES) {
|
|
536
|
-
const filePath = path.join(projectRoot, infoFile);
|
|
537
|
-
if (!fs.existsSync(filePath)) {
|
|
538
|
-
continue;
|
|
539
|
-
}
|
|
540
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
541
|
-
const result = removeMarkerSection(content);
|
|
542
|
-
if (result.removed) {
|
|
543
|
-
if (result.content.trim().length === 0) {
|
|
544
|
-
if (!dryRun) {
|
|
545
|
-
fs.unlinkSync(filePath);
|
|
546
|
-
}
|
|
547
|
-
summary.push(`${prefix}Deleted ${infoFile} (only contained Glasstrace section)`);
|
|
548
|
-
} else {
|
|
549
|
-
if (!dryRun) {
|
|
550
|
-
fs.writeFileSync(filePath, result.content, "utf-8");
|
|
551
|
-
}
|
|
552
|
-
summary.push(`${prefix}Removed Glasstrace section from ${infoFile}`);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
} catch (err) {
|
|
557
|
-
errors.push(
|
|
558
|
-
`Failed to process agent info files: ${err instanceof Error ? err.message : String(err)}`
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
if (summary.length === 0 && errors.length === 0) {
|
|
562
|
-
summary.push("No Glasstrace artifacts found \u2014 nothing to do.");
|
|
563
|
-
}
|
|
564
|
-
return { exitCode: errors.length > 0 ? 1 : 0, summary, warnings, errors };
|
|
565
|
-
}
|
|
2
|
+
findMatchingDelimiter,
|
|
3
|
+
findMatchingParen,
|
|
4
|
+
isInitCreatedInstrumentation,
|
|
5
|
+
processJsonMcpConfig,
|
|
6
|
+
processTomlMcpConfig,
|
|
7
|
+
removeGlasstraceConfigImport,
|
|
8
|
+
removeMarkerSection,
|
|
9
|
+
removeRegisterGlasstrace,
|
|
10
|
+
runUninit,
|
|
11
|
+
skipString,
|
|
12
|
+
unwrapCJSExport,
|
|
13
|
+
unwrapExport
|
|
14
|
+
} from "../chunk-IPGOKORJ.js";
|
|
15
|
+
import "../chunk-DXRZKKSO.js";
|
|
16
|
+
import "../chunk-NSBPE2FW.js";
|
|
566
17
|
export {
|
|
567
18
|
findMatchingDelimiter,
|
|
568
19
|
findMatchingParen,
|