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