@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.
- package/README.md +79 -0
- package/dist/{chunk-GSGX76Q5.js → chunk-5N2IR4EO.js} +146 -3
- package/dist/chunk-5N2IR4EO.js.map +1 -0
- package/dist/{chunk-XNDHQN4S.js → chunk-6JRI4OGB.js} +286 -54
- package/dist/chunk-6JRI4OGB.js.map +1 -0
- package/dist/{chunk-IOPCSX6C.js → chunk-F2TZRBEH.js} +2 -2
- package/dist/{chunk-E33Y7BQH.js → chunk-VN3GZDV6.js} +2 -2
- package/dist/{chunk-J5BW7V2D.js → chunk-YPXW2TN3.js} +2 -2
- package/dist/cli/init.cjs +548 -153
- 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 +106 -6
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.cjs +66 -0
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +2 -2
- 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 +157 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -12
- package/dist/index.d.ts +43 -12
- package/dist/index.js +19 -39
- package/dist/index.js.map +1 -1
- package/dist/{source-map-uploader-26QPRSCG.js → source-map-uploader-VPDZWWM2.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-GSGX76Q5.js.map +0 -1
- package/dist/chunk-XNDHQN4S.js.map +0 -1
- /package/dist/{chunk-IOPCSX6C.js.map → chunk-F2TZRBEH.js.map} +0 -0
- /package/dist/{chunk-E33Y7BQH.js.map → chunk-VN3GZDV6.js.map} +0 -0
- /package/dist/{chunk-J5BW7V2D.js.map → chunk-YPXW2TN3.js.map} +0 -0
- /package/dist/{source-map-uploader-26QPRSCG.js.map → source-map-uploader-VPDZWWM2.js.map} +0 -0
package/dist/cli/init.cjs
CHANGED
|
@@ -755,10 +755,10 @@ function mergeDefs(...defs) {
|
|
|
755
755
|
function cloneDef(schema) {
|
|
756
756
|
return mergeDefs(schema._zod.def);
|
|
757
757
|
}
|
|
758
|
-
function getElementAtPath(obj,
|
|
759
|
-
if (!
|
|
758
|
+
function getElementAtPath(obj, path10) {
|
|
759
|
+
if (!path10)
|
|
760
760
|
return obj;
|
|
761
|
-
return
|
|
761
|
+
return path10.reduce((acc, key) => acc?.[key], obj);
|
|
762
762
|
}
|
|
763
763
|
function promiseAllObject(promisesObj) {
|
|
764
764
|
const keys = Object.keys(promisesObj);
|
|
@@ -1070,11 +1070,11 @@ function aborted(x, startIndex = 0) {
|
|
|
1070
1070
|
}
|
|
1071
1071
|
return false;
|
|
1072
1072
|
}
|
|
1073
|
-
function prefixIssues(
|
|
1073
|
+
function prefixIssues(path10, issues) {
|
|
1074
1074
|
return issues.map((iss) => {
|
|
1075
1075
|
var _a2;
|
|
1076
1076
|
(_a2 = iss).path ?? (_a2.path = []);
|
|
1077
|
-
iss.path.unshift(
|
|
1077
|
+
iss.path.unshift(path10);
|
|
1078
1078
|
return iss;
|
|
1079
1079
|
});
|
|
1080
1080
|
}
|
|
@@ -1317,7 +1317,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
|
|
|
1317
1317
|
}
|
|
1318
1318
|
function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
1319
1319
|
const result = { errors: [] };
|
|
1320
|
-
const processError = (error49,
|
|
1320
|
+
const processError = (error49, path10 = []) => {
|
|
1321
1321
|
var _a2, _b;
|
|
1322
1322
|
for (const issue2 of error49.issues) {
|
|
1323
1323
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -1327,7 +1327,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
1327
1327
|
} else if (issue2.code === "invalid_element") {
|
|
1328
1328
|
processError({ issues: issue2.issues }, issue2.path);
|
|
1329
1329
|
} else {
|
|
1330
|
-
const fullpath = [...
|
|
1330
|
+
const fullpath = [...path10, ...issue2.path];
|
|
1331
1331
|
if (fullpath.length === 0) {
|
|
1332
1332
|
result.errors.push(mapper(issue2));
|
|
1333
1333
|
continue;
|
|
@@ -1359,8 +1359,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
1359
1359
|
}
|
|
1360
1360
|
function toDotPath(_path) {
|
|
1361
1361
|
const segs = [];
|
|
1362
|
-
const
|
|
1363
|
-
for (const seg of
|
|
1362
|
+
const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1363
|
+
for (const seg of path10) {
|
|
1364
1364
|
if (typeof seg === "number")
|
|
1365
1365
|
segs.push(`[${seg}]`);
|
|
1366
1366
|
else if (typeof seg === "symbol")
|
|
@@ -14124,13 +14124,13 @@ function resolveRef(ref, ctx) {
|
|
|
14124
14124
|
if (!ref.startsWith("#")) {
|
|
14125
14125
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14126
14126
|
}
|
|
14127
|
-
const
|
|
14128
|
-
if (
|
|
14127
|
+
const path10 = ref.slice(1).split("/").filter(Boolean);
|
|
14128
|
+
if (path10.length === 0) {
|
|
14129
14129
|
return ctx.rootSchema;
|
|
14130
14130
|
}
|
|
14131
14131
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14132
|
-
if (
|
|
14133
|
-
const key =
|
|
14132
|
+
if (path10[0] === defsKey) {
|
|
14133
|
+
const key = path10[1];
|
|
14134
14134
|
if (!key || !ctx.defs[key]) {
|
|
14135
14135
|
throw new Error(`Reference not found: ${ref}`);
|
|
14136
14136
|
}
|
|
@@ -14905,7 +14905,7 @@ function createAnonApiKey() {
|
|
|
14905
14905
|
function createBuildHash(hash2) {
|
|
14906
14906
|
return BuildHashSchema.parse(hash2);
|
|
14907
14907
|
}
|
|
14908
|
-
var DevApiKeySchema, AnonApiKeySchema, SessionIdSchema, BuildHashSchema, SdkDiagnosticCodeSchema, CaptureConfigSchema, SdkCachedConfigSchema, GlasstraceOptionsSchema, GlasstraceEnvVarsSchema, ImportGraphPayloadSchema, SdkHealthReportSchema, TierLimitsSchema, SdkInitResponseSchema, DiscoveryResponseSchema, SourceMapUploadResponseSchema, PresignedUploadRequestSchema, PresignedUploadResponseSchema, SourceMapManifestRequestSchema, SourceMapManifestResponseSchema;
|
|
14908
|
+
var DevApiKeySchema, AnonApiKeySchema, SessionIdSchema, BuildHashSchema, SdkDiagnosticCodeSchema, CaptureConfigSchema, SdkCachedConfigSchema, GlasstraceOptionsSchema, GlasstraceEnvVarsSchema, ImportGraphPayloadSchema, SdkHealthReportSchema, TierLimitsSchema, SdkInitResponseSchema, DiscoveryResponseSchema, SourceMapUploadResponseSchema, PresignedUploadRequestSchema, PresignedUploadResponseSchema, SourceMapManifestRequestSchema, SourceMapManifestResponseSchema, K;
|
|
14909
14909
|
var init_dist = __esm({
|
|
14910
14910
|
"../protocol/dist/index.js"() {
|
|
14911
14911
|
"use strict";
|
|
@@ -15037,6 +15037,72 @@ var init_dist = __esm({
|
|
|
15037
15037
|
totalSizeBytes: external_exports.number().int().nonnegative(),
|
|
15038
15038
|
activatedAt: external_exports.number().int().positive()
|
|
15039
15039
|
});
|
|
15040
|
+
K = new Uint32Array([
|
|
15041
|
+
1116352408,
|
|
15042
|
+
1899447441,
|
|
15043
|
+
3049323471,
|
|
15044
|
+
3921009573,
|
|
15045
|
+
961987163,
|
|
15046
|
+
1508970993,
|
|
15047
|
+
2453635748,
|
|
15048
|
+
2870763221,
|
|
15049
|
+
3624381080,
|
|
15050
|
+
310598401,
|
|
15051
|
+
607225278,
|
|
15052
|
+
1426881987,
|
|
15053
|
+
1925078388,
|
|
15054
|
+
2162078206,
|
|
15055
|
+
2614888103,
|
|
15056
|
+
3248222580,
|
|
15057
|
+
3835390401,
|
|
15058
|
+
4022224774,
|
|
15059
|
+
264347078,
|
|
15060
|
+
604807628,
|
|
15061
|
+
770255983,
|
|
15062
|
+
1249150122,
|
|
15063
|
+
1555081692,
|
|
15064
|
+
1996064986,
|
|
15065
|
+
2554220882,
|
|
15066
|
+
2821834349,
|
|
15067
|
+
2952996808,
|
|
15068
|
+
3210313671,
|
|
15069
|
+
3336571891,
|
|
15070
|
+
3584528711,
|
|
15071
|
+
113926993,
|
|
15072
|
+
338241895,
|
|
15073
|
+
666307205,
|
|
15074
|
+
773529912,
|
|
15075
|
+
1294757372,
|
|
15076
|
+
1396182291,
|
|
15077
|
+
1695183700,
|
|
15078
|
+
1986661051,
|
|
15079
|
+
2177026350,
|
|
15080
|
+
2456956037,
|
|
15081
|
+
2730485921,
|
|
15082
|
+
2820302411,
|
|
15083
|
+
3259730800,
|
|
15084
|
+
3345764771,
|
|
15085
|
+
3516065817,
|
|
15086
|
+
3600352804,
|
|
15087
|
+
4094571909,
|
|
15088
|
+
275423344,
|
|
15089
|
+
430227734,
|
|
15090
|
+
506948616,
|
|
15091
|
+
659060556,
|
|
15092
|
+
883997877,
|
|
15093
|
+
958139571,
|
|
15094
|
+
1322822218,
|
|
15095
|
+
1537002063,
|
|
15096
|
+
1747873779,
|
|
15097
|
+
1955562222,
|
|
15098
|
+
2024104815,
|
|
15099
|
+
2227730452,
|
|
15100
|
+
2361852424,
|
|
15101
|
+
2428436474,
|
|
15102
|
+
2756734187,
|
|
15103
|
+
3204031479,
|
|
15104
|
+
3329325298
|
|
15105
|
+
]);
|
|
15040
15106
|
}
|
|
15041
15107
|
});
|
|
15042
15108
|
|
|
@@ -15044,11 +15110,11 @@ var init_dist = __esm({
|
|
|
15044
15110
|
async function loadFsPath() {
|
|
15045
15111
|
if (fsPathCache !== void 0) return fsPathCache;
|
|
15046
15112
|
try {
|
|
15047
|
-
const [
|
|
15113
|
+
const [fs10, path10] = await Promise.all([
|
|
15048
15114
|
import("node:fs/promises"),
|
|
15049
15115
|
import("node:path")
|
|
15050
15116
|
]);
|
|
15051
|
-
fsPathCache = { fs:
|
|
15117
|
+
fsPathCache = { fs: fs10, path: path10 };
|
|
15052
15118
|
return fsPathCache;
|
|
15053
15119
|
} catch {
|
|
15054
15120
|
fsPathCache = null;
|
|
@@ -15135,9 +15201,9 @@ var init_anon_key = __esm({
|
|
|
15135
15201
|
});
|
|
15136
15202
|
|
|
15137
15203
|
// src/agent-detection/detect.ts
|
|
15138
|
-
async function pathExists(
|
|
15204
|
+
async function pathExists(path10, mode = import_node_fs.constants.R_OK) {
|
|
15139
15205
|
try {
|
|
15140
|
-
await (0, import_promises.access)(
|
|
15206
|
+
await (0, import_promises.access)(path10, mode);
|
|
15141
15207
|
return true;
|
|
15142
15208
|
} catch {
|
|
15143
15209
|
return false;
|
|
@@ -15889,6 +15955,207 @@ var init_monorepo = __esm({
|
|
|
15889
15955
|
}
|
|
15890
15956
|
});
|
|
15891
15957
|
|
|
15958
|
+
// src/cli/discovery-file.ts
|
|
15959
|
+
function resolveStaticRoot(projectRoot) {
|
|
15960
|
+
if (isSvelteKitProject(projectRoot)) {
|
|
15961
|
+
return {
|
|
15962
|
+
absolutePath: path4.join(projectRoot, "static"),
|
|
15963
|
+
layout: "static"
|
|
15964
|
+
};
|
|
15965
|
+
}
|
|
15966
|
+
return {
|
|
15967
|
+
absolutePath: path4.join(projectRoot, "public"),
|
|
15968
|
+
layout: "public"
|
|
15969
|
+
};
|
|
15970
|
+
}
|
|
15971
|
+
function isSvelteKitProject(projectRoot) {
|
|
15972
|
+
const pkgPath = path4.join(projectRoot, "package.json");
|
|
15973
|
+
let isEsm = false;
|
|
15974
|
+
try {
|
|
15975
|
+
const pkgContent = fs4.readFileSync(pkgPath, "utf-8");
|
|
15976
|
+
const parsed = JSON.parse(pkgContent);
|
|
15977
|
+
isEsm = parsed.type === "module";
|
|
15978
|
+
} catch {
|
|
15979
|
+
return false;
|
|
15980
|
+
}
|
|
15981
|
+
if (!isEsm) return false;
|
|
15982
|
+
const svelteConfigJs = path4.join(projectRoot, "svelte.config.js");
|
|
15983
|
+
const svelteConfigTs = path4.join(projectRoot, "svelte.config.ts");
|
|
15984
|
+
const appHtml = path4.join(projectRoot, "src", "app.html");
|
|
15985
|
+
return fs4.existsSync(svelteConfigJs) || fs4.existsSync(svelteConfigTs) || fs4.existsSync(appHtml);
|
|
15986
|
+
}
|
|
15987
|
+
function relativeDiscoveryPath(layout) {
|
|
15988
|
+
return layout === "static" ? "static/.well-known/glasstrace.json" : "public/.well-known/glasstrace.json";
|
|
15989
|
+
}
|
|
15990
|
+
function readExistingDiscoveryFile(filePath) {
|
|
15991
|
+
let raw;
|
|
15992
|
+
try {
|
|
15993
|
+
raw = fs4.readFileSync(filePath, "utf-8");
|
|
15994
|
+
} catch {
|
|
15995
|
+
return null;
|
|
15996
|
+
}
|
|
15997
|
+
let parsed;
|
|
15998
|
+
try {
|
|
15999
|
+
parsed = JSON.parse(raw);
|
|
16000
|
+
} catch {
|
|
16001
|
+
return null;
|
|
16002
|
+
}
|
|
16003
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
16004
|
+
return null;
|
|
16005
|
+
}
|
|
16006
|
+
const obj = parsed;
|
|
16007
|
+
const versionRaw = obj.version;
|
|
16008
|
+
if (typeof versionRaw !== "number" || !Number.isInteger(versionRaw) || versionRaw < 1) {
|
|
16009
|
+
return null;
|
|
16010
|
+
}
|
|
16011
|
+
const keyResult = AnonApiKeySchema.safeParse(obj.key);
|
|
16012
|
+
if (!keyResult.success) {
|
|
16013
|
+
return null;
|
|
16014
|
+
}
|
|
16015
|
+
const extras = {};
|
|
16016
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
16017
|
+
if (k === "version" || k === "key") continue;
|
|
16018
|
+
extras[k] = v;
|
|
16019
|
+
}
|
|
16020
|
+
return { key: keyResult.data, extras };
|
|
16021
|
+
}
|
|
16022
|
+
function serializeDiscoveryPayload(key, extras) {
|
|
16023
|
+
const payload = {
|
|
16024
|
+
version: DISCOVERY_FILE_VERSION,
|
|
16025
|
+
key,
|
|
16026
|
+
...extras
|
|
16027
|
+
};
|
|
16028
|
+
return JSON.stringify(payload, null, 2) + "\n";
|
|
16029
|
+
}
|
|
16030
|
+
function writeDiscoveryFile(projectRoot, anonKey) {
|
|
16031
|
+
const { absolutePath: staticRoot, layout } = resolveStaticRoot(projectRoot);
|
|
16032
|
+
const wellKnownDir = path4.join(staticRoot, ".well-known");
|
|
16033
|
+
const filePath = path4.join(wellKnownDir, "glasstrace.json");
|
|
16034
|
+
let existingAction;
|
|
16035
|
+
let extras = {};
|
|
16036
|
+
if (fs4.existsSync(filePath)) {
|
|
16037
|
+
const existing = readExistingDiscoveryFile(filePath);
|
|
16038
|
+
if (existing === null) {
|
|
16039
|
+
existingAction = "skipped-foreign";
|
|
16040
|
+
} else if (existing.key === anonKey) {
|
|
16041
|
+
return {
|
|
16042
|
+
action: "skipped-matches",
|
|
16043
|
+
filePath,
|
|
16044
|
+
layout
|
|
16045
|
+
};
|
|
16046
|
+
} else {
|
|
16047
|
+
extras = existing.extras;
|
|
16048
|
+
existingAction = "updated-stale";
|
|
16049
|
+
}
|
|
16050
|
+
} else {
|
|
16051
|
+
existingAction = "created";
|
|
16052
|
+
}
|
|
16053
|
+
const tmpPath = `${filePath}.tmp-${process.pid}`;
|
|
16054
|
+
const needsWindowsReplace = process.platform === "win32" && fs4.existsSync(filePath);
|
|
16055
|
+
const backupPath = needsWindowsReplace ? `${filePath}.bak-${process.pid}` : null;
|
|
16056
|
+
try {
|
|
16057
|
+
fs4.mkdirSync(wellKnownDir, { recursive: true });
|
|
16058
|
+
const payload = serializeDiscoveryPayload(anonKey, extras);
|
|
16059
|
+
fs4.writeFileSync(tmpPath, payload, { encoding: "utf-8" });
|
|
16060
|
+
if (backupPath !== null) {
|
|
16061
|
+
fs4.renameSync(filePath, backupPath);
|
|
16062
|
+
try {
|
|
16063
|
+
fs4.renameSync(tmpPath, filePath);
|
|
16064
|
+
} catch (renameErr) {
|
|
16065
|
+
try {
|
|
16066
|
+
fs4.renameSync(backupPath, filePath);
|
|
16067
|
+
} catch {
|
|
16068
|
+
}
|
|
16069
|
+
throw renameErr;
|
|
16070
|
+
}
|
|
16071
|
+
try {
|
|
16072
|
+
fs4.unlinkSync(backupPath);
|
|
16073
|
+
} catch {
|
|
16074
|
+
}
|
|
16075
|
+
} else {
|
|
16076
|
+
fs4.renameSync(tmpPath, filePath);
|
|
16077
|
+
}
|
|
16078
|
+
return { action: existingAction, filePath, layout };
|
|
16079
|
+
} catch (err) {
|
|
16080
|
+
try {
|
|
16081
|
+
if (fs4.existsSync(tmpPath)) {
|
|
16082
|
+
fs4.unlinkSync(tmpPath);
|
|
16083
|
+
}
|
|
16084
|
+
} catch {
|
|
16085
|
+
}
|
|
16086
|
+
return {
|
|
16087
|
+
action: "failed",
|
|
16088
|
+
filePath,
|
|
16089
|
+
layout,
|
|
16090
|
+
error: err instanceof Error ? err.message : String(err)
|
|
16091
|
+
};
|
|
16092
|
+
}
|
|
16093
|
+
}
|
|
16094
|
+
function removeDiscoveryFile(projectRoot) {
|
|
16095
|
+
const { layout: inferredLayout } = resolveStaticRoot(projectRoot);
|
|
16096
|
+
const layouts = ["public", "static"];
|
|
16097
|
+
const outcomes = [];
|
|
16098
|
+
for (const layout of layouts) {
|
|
16099
|
+
const staticRoot = path4.join(projectRoot, layout);
|
|
16100
|
+
const wellKnownDir = path4.join(staticRoot, ".well-known");
|
|
16101
|
+
const filePath = path4.join(wellKnownDir, "glasstrace.json");
|
|
16102
|
+
let removed = false;
|
|
16103
|
+
try {
|
|
16104
|
+
if (fs4.existsSync(filePath)) {
|
|
16105
|
+
fs4.unlinkSync(filePath);
|
|
16106
|
+
removed = true;
|
|
16107
|
+
}
|
|
16108
|
+
} catch (err) {
|
|
16109
|
+
return {
|
|
16110
|
+
action: "failed",
|
|
16111
|
+
filePath,
|
|
16112
|
+
layout,
|
|
16113
|
+
directoryRemoved: false,
|
|
16114
|
+
error: err instanceof Error ? err.message : String(err)
|
|
16115
|
+
};
|
|
16116
|
+
}
|
|
16117
|
+
let directoryRemoved = false;
|
|
16118
|
+
if (removed) {
|
|
16119
|
+
try {
|
|
16120
|
+
if (fs4.existsSync(wellKnownDir)) {
|
|
16121
|
+
const entries = fs4.readdirSync(wellKnownDir);
|
|
16122
|
+
if (entries.length === 0) {
|
|
16123
|
+
fs4.rmdirSync(wellKnownDir);
|
|
16124
|
+
directoryRemoved = true;
|
|
16125
|
+
}
|
|
16126
|
+
}
|
|
16127
|
+
} catch {
|
|
16128
|
+
}
|
|
16129
|
+
}
|
|
16130
|
+
outcomes.push({ layout, filePath, removed, directoryRemoved });
|
|
16131
|
+
}
|
|
16132
|
+
const removals = outcomes.filter((o) => o.removed);
|
|
16133
|
+
const chosen = (() => {
|
|
16134
|
+
if (removals.length === 0) {
|
|
16135
|
+
return outcomes.find((o) => o.layout === inferredLayout) ?? outcomes[0];
|
|
16136
|
+
}
|
|
16137
|
+
if (removals.length === 1) return removals[0];
|
|
16138
|
+
return removals.find((o) => o.layout === inferredLayout) ?? removals[0];
|
|
16139
|
+
})();
|
|
16140
|
+
const anyDirectoryRemoved = outcomes.some((o) => o.directoryRemoved);
|
|
16141
|
+
return {
|
|
16142
|
+
action: removals.length > 0 ? "removed" : "not-found",
|
|
16143
|
+
filePath: chosen.filePath,
|
|
16144
|
+
layout: chosen.layout,
|
|
16145
|
+
directoryRemoved: chosen.directoryRemoved || anyDirectoryRemoved
|
|
16146
|
+
};
|
|
16147
|
+
}
|
|
16148
|
+
var fs4, path4, DISCOVERY_FILE_VERSION;
|
|
16149
|
+
var init_discovery_file = __esm({
|
|
16150
|
+
"src/cli/discovery-file.ts"() {
|
|
16151
|
+
"use strict";
|
|
16152
|
+
fs4 = __toESM(require("node:fs"), 1);
|
|
16153
|
+
path4 = __toESM(require("node:path"), 1);
|
|
16154
|
+
init_dist();
|
|
16155
|
+
DISCOVERY_FILE_VERSION = 1;
|
|
16156
|
+
}
|
|
16157
|
+
});
|
|
16158
|
+
|
|
15892
16159
|
// src/cli/uninit.ts
|
|
15893
16160
|
var uninit_exports = {};
|
|
15894
16161
|
__export(uninit_exports, {
|
|
@@ -16206,24 +16473,24 @@ function processTomlMcpConfig(content) {
|
|
|
16206
16473
|
return { action: "removed-section", content: result + "\n" };
|
|
16207
16474
|
}
|
|
16208
16475
|
function writeShutdownMarker(projectRoot) {
|
|
16209
|
-
const dirPath =
|
|
16210
|
-
if (!
|
|
16476
|
+
const dirPath = path5.join(projectRoot, ".glasstrace");
|
|
16477
|
+
if (!fs5.existsSync(dirPath)) {
|
|
16211
16478
|
return false;
|
|
16212
16479
|
}
|
|
16213
|
-
const markerPath =
|
|
16480
|
+
const markerPath = path5.join(dirPath, "shutdown-requested");
|
|
16214
16481
|
const tmpPath = `${markerPath}.tmp`;
|
|
16215
16482
|
const body = JSON.stringify({ requestedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
16216
16483
|
try {
|
|
16217
|
-
|
|
16484
|
+
fs5.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
|
|
16218
16485
|
try {
|
|
16219
|
-
|
|
16486
|
+
fs5.chmodSync(tmpPath, 384);
|
|
16220
16487
|
} catch {
|
|
16221
16488
|
}
|
|
16222
|
-
|
|
16489
|
+
fs5.renameSync(tmpPath, markerPath);
|
|
16223
16490
|
return true;
|
|
16224
16491
|
} catch {
|
|
16225
16492
|
try {
|
|
16226
|
-
|
|
16493
|
+
fs5.unlinkSync(tmpPath);
|
|
16227
16494
|
} catch {
|
|
16228
16495
|
}
|
|
16229
16496
|
return false;
|
|
@@ -16264,8 +16531,8 @@ async function runUninit(options) {
|
|
|
16264
16531
|
summary.push("Wrote .glasstrace/shutdown-requested marker");
|
|
16265
16532
|
}
|
|
16266
16533
|
} else {
|
|
16267
|
-
const dirPath =
|
|
16268
|
-
if (
|
|
16534
|
+
const dirPath = path5.join(projectRoot, ".glasstrace");
|
|
16535
|
+
if (fs5.existsSync(dirPath)) {
|
|
16269
16536
|
summary.push(`${prefix}Would write .glasstrace/shutdown-requested marker`);
|
|
16270
16537
|
}
|
|
16271
16538
|
}
|
|
@@ -16277,11 +16544,11 @@ async function runUninit(options) {
|
|
|
16277
16544
|
try {
|
|
16278
16545
|
let configHandled = false;
|
|
16279
16546
|
for (const name of NEXT_CONFIG_NAMES) {
|
|
16280
|
-
const configPath =
|
|
16281
|
-
if (!
|
|
16547
|
+
const configPath = path5.join(projectRoot, name);
|
|
16548
|
+
if (!fs5.existsSync(configPath)) {
|
|
16282
16549
|
continue;
|
|
16283
16550
|
}
|
|
16284
|
-
const content =
|
|
16551
|
+
const content = fs5.readFileSync(configPath, "utf-8");
|
|
16285
16552
|
if (!content.includes("withGlasstraceConfig")) {
|
|
16286
16553
|
continue;
|
|
16287
16554
|
}
|
|
@@ -16291,7 +16558,7 @@ async function runUninit(options) {
|
|
|
16291
16558
|
const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
|
|
16292
16559
|
const final = cleanLeadingBlankLines(cleaned);
|
|
16293
16560
|
if (!dryRun) {
|
|
16294
|
-
|
|
16561
|
+
fs5.writeFileSync(configPath, final, "utf-8");
|
|
16295
16562
|
}
|
|
16296
16563
|
summary.push(`${prefix}Unwrapped withGlasstraceConfig from ${name}`);
|
|
16297
16564
|
configHandled = true;
|
|
@@ -16312,20 +16579,20 @@ async function runUninit(options) {
|
|
|
16312
16579
|
);
|
|
16313
16580
|
}
|
|
16314
16581
|
try {
|
|
16315
|
-
const instrPath =
|
|
16316
|
-
if (
|
|
16317
|
-
const content =
|
|
16582
|
+
const instrPath = path5.join(projectRoot, "instrumentation.ts");
|
|
16583
|
+
if (fs5.existsSync(instrPath)) {
|
|
16584
|
+
const content = fs5.readFileSync(instrPath, "utf-8");
|
|
16318
16585
|
if (content.includes("registerGlasstrace") || content.includes("@glasstrace/sdk")) {
|
|
16319
16586
|
if (isInitCreatedInstrumentation(content)) {
|
|
16320
16587
|
if (!dryRun) {
|
|
16321
|
-
|
|
16588
|
+
fs5.unlinkSync(instrPath);
|
|
16322
16589
|
}
|
|
16323
16590
|
summary.push(`${prefix}Deleted instrumentation.ts (init-created)`);
|
|
16324
16591
|
} else {
|
|
16325
16592
|
const cleaned = removeRegisterGlasstrace(content);
|
|
16326
16593
|
if (cleaned !== content) {
|
|
16327
16594
|
if (!dryRun) {
|
|
16328
|
-
|
|
16595
|
+
fs5.writeFileSync(instrPath, cleaned, "utf-8");
|
|
16329
16596
|
}
|
|
16330
16597
|
summary.push(
|
|
16331
16598
|
`${prefix}Removed registerGlasstrace() from instrumentation.ts`
|
|
@@ -16340,10 +16607,10 @@ async function runUninit(options) {
|
|
|
16340
16607
|
);
|
|
16341
16608
|
}
|
|
16342
16609
|
try {
|
|
16343
|
-
const glasstraceDir =
|
|
16344
|
-
if (
|
|
16610
|
+
const glasstraceDir = path5.join(projectRoot, ".glasstrace");
|
|
16611
|
+
if (fs5.existsSync(glasstraceDir)) {
|
|
16345
16612
|
if (!dryRun) {
|
|
16346
|
-
|
|
16613
|
+
fs5.rmSync(glasstraceDir, { recursive: true, force: true });
|
|
16347
16614
|
}
|
|
16348
16615
|
summary.push(`${prefix}Removed .glasstrace/ directory`);
|
|
16349
16616
|
}
|
|
@@ -16353,9 +16620,38 @@ async function runUninit(options) {
|
|
|
16353
16620
|
);
|
|
16354
16621
|
}
|
|
16355
16622
|
try {
|
|
16356
|
-
|
|
16357
|
-
|
|
16358
|
-
|
|
16623
|
+
if (dryRun) {
|
|
16624
|
+
for (const previewLayout of ["public", "static"]) {
|
|
16625
|
+
const relPath = relativeDiscoveryPath(previewLayout);
|
|
16626
|
+
const absPath = path5.join(projectRoot, relPath);
|
|
16627
|
+
if (fs5.existsSync(absPath)) {
|
|
16628
|
+
summary.push(`${prefix}Would remove ${relPath}`);
|
|
16629
|
+
}
|
|
16630
|
+
}
|
|
16631
|
+
} else {
|
|
16632
|
+
const result = removeDiscoveryFile(projectRoot);
|
|
16633
|
+
if (result.action === "removed") {
|
|
16634
|
+
const relPath = relativeDiscoveryPath(result.layout);
|
|
16635
|
+
summary.push(`Removed ${relPath}`);
|
|
16636
|
+
if (result.directoryRemoved) {
|
|
16637
|
+
const dirRel = relPath.replace(/\/glasstrace\.json$/, "/");
|
|
16638
|
+
summary.push(`Removed empty ${dirRel}`);
|
|
16639
|
+
}
|
|
16640
|
+
} else if (result.action === "failed") {
|
|
16641
|
+
warnings.push(
|
|
16642
|
+
`Failed to remove ${relativeDiscoveryPath(result.layout)}${result.error !== void 0 ? `: ${result.error}` : ""}`
|
|
16643
|
+
);
|
|
16644
|
+
}
|
|
16645
|
+
}
|
|
16646
|
+
} catch (err) {
|
|
16647
|
+
warnings.push(
|
|
16648
|
+
`Failed to remove discovery file: ${err instanceof Error ? err.message : String(err)}`
|
|
16649
|
+
);
|
|
16650
|
+
}
|
|
16651
|
+
try {
|
|
16652
|
+
const envPath = path5.join(projectRoot, ".env.local");
|
|
16653
|
+
if (fs5.existsSync(envPath)) {
|
|
16654
|
+
const content = fs5.readFileSync(envPath, "utf-8");
|
|
16359
16655
|
const existingKey = readEnvLocalApiKey(content);
|
|
16360
16656
|
const hasDevKey = isDevApiKey(existingKey);
|
|
16361
16657
|
let proceed = true;
|
|
@@ -16388,12 +16684,12 @@ async function runUninit(options) {
|
|
|
16388
16684
|
const result = filtered.join("\n");
|
|
16389
16685
|
if (result.trim().length === 0) {
|
|
16390
16686
|
if (!dryRun) {
|
|
16391
|
-
|
|
16687
|
+
fs5.unlinkSync(envPath);
|
|
16392
16688
|
}
|
|
16393
16689
|
summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
|
|
16394
16690
|
} else {
|
|
16395
16691
|
if (!dryRun) {
|
|
16396
|
-
|
|
16692
|
+
fs5.writeFileSync(envPath, result, "utf-8");
|
|
16397
16693
|
}
|
|
16398
16694
|
let devKeyAnnotation = "";
|
|
16399
16695
|
if (devKeyPath === "interactive-confirmed") {
|
|
@@ -16416,9 +16712,9 @@ async function runUninit(options) {
|
|
|
16416
16712
|
);
|
|
16417
16713
|
}
|
|
16418
16714
|
try {
|
|
16419
|
-
const gitignorePath =
|
|
16420
|
-
if (
|
|
16421
|
-
const content =
|
|
16715
|
+
const gitignorePath = path5.join(projectRoot, ".gitignore");
|
|
16716
|
+
if (fs5.existsSync(gitignorePath)) {
|
|
16717
|
+
const content = fs5.readFileSync(gitignorePath, "utf-8");
|
|
16422
16718
|
const lines = content.split("\n");
|
|
16423
16719
|
const mcpGitignoreEntries = /* @__PURE__ */ new Set([
|
|
16424
16720
|
".glasstrace/",
|
|
@@ -16434,12 +16730,12 @@ async function runUninit(options) {
|
|
|
16434
16730
|
const result = filtered.join("\n");
|
|
16435
16731
|
if (result.trim().length === 0) {
|
|
16436
16732
|
if (!dryRun) {
|
|
16437
|
-
|
|
16733
|
+
fs5.unlinkSync(gitignorePath);
|
|
16438
16734
|
}
|
|
16439
16735
|
summary.push(`${prefix}Deleted .gitignore (no remaining entries)`);
|
|
16440
16736
|
} else {
|
|
16441
16737
|
if (!dryRun) {
|
|
16442
|
-
|
|
16738
|
+
fs5.writeFileSync(gitignorePath, result, "utf-8");
|
|
16443
16739
|
}
|
|
16444
16740
|
summary.push(`${prefix}Removed Glasstrace entries from .gitignore`);
|
|
16445
16741
|
}
|
|
@@ -16452,63 +16748,63 @@ async function runUninit(options) {
|
|
|
16452
16748
|
}
|
|
16453
16749
|
try {
|
|
16454
16750
|
for (const configFile of MCP_CONFIG_FILES) {
|
|
16455
|
-
const configPath =
|
|
16456
|
-
if (!
|
|
16751
|
+
const configPath = path5.join(projectRoot, configFile);
|
|
16752
|
+
if (!fs5.existsSync(configPath)) {
|
|
16457
16753
|
continue;
|
|
16458
16754
|
}
|
|
16459
|
-
const content =
|
|
16755
|
+
const content = fs5.readFileSync(configPath, "utf-8");
|
|
16460
16756
|
const result = processJsonMcpConfig(content);
|
|
16461
16757
|
if (result.action === "deleted") {
|
|
16462
16758
|
if (!dryRun) {
|
|
16463
|
-
|
|
16759
|
+
fs5.unlinkSync(configPath);
|
|
16464
16760
|
}
|
|
16465
16761
|
summary.push(`${prefix}Deleted ${configFile}`);
|
|
16466
16762
|
} else if (result.action === "removed-key" && result.content !== void 0) {
|
|
16467
16763
|
if (!dryRun) {
|
|
16468
|
-
|
|
16764
|
+
fs5.writeFileSync(configPath, result.content, "utf-8");
|
|
16469
16765
|
}
|
|
16470
16766
|
summary.push(`${prefix}Removed glasstrace from ${configFile}`);
|
|
16471
16767
|
}
|
|
16472
16768
|
}
|
|
16473
|
-
const codexConfigPath =
|
|
16474
|
-
if (
|
|
16475
|
-
const content =
|
|
16769
|
+
const codexConfigPath = path5.join(projectRoot, ".codex", "config.toml");
|
|
16770
|
+
if (fs5.existsSync(codexConfigPath)) {
|
|
16771
|
+
const content = fs5.readFileSync(codexConfigPath, "utf-8");
|
|
16476
16772
|
const tomlResult = processTomlMcpConfig(content);
|
|
16477
16773
|
if (tomlResult.action === "deleted") {
|
|
16478
16774
|
if (!dryRun) {
|
|
16479
|
-
|
|
16775
|
+
fs5.unlinkSync(codexConfigPath);
|
|
16480
16776
|
}
|
|
16481
16777
|
summary.push(`${prefix}Deleted .codex/config.toml`);
|
|
16482
16778
|
} else if (tomlResult.action === "removed-section" && tomlResult.content !== void 0) {
|
|
16483
16779
|
if (!dryRun) {
|
|
16484
|
-
|
|
16780
|
+
fs5.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
|
|
16485
16781
|
}
|
|
16486
16782
|
summary.push(`${prefix}Removed glasstrace from .codex/config.toml`);
|
|
16487
16783
|
}
|
|
16488
16784
|
}
|
|
16489
|
-
const hasWindsurfMarkers =
|
|
16785
|
+
const hasWindsurfMarkers = fs5.existsSync(path5.join(projectRoot, ".windsurfrules")) || fs5.existsSync(path5.join(projectRoot, ".windsurf"));
|
|
16490
16786
|
if (hasWindsurfMarkers) {
|
|
16491
|
-
const windsurfConfigPath =
|
|
16787
|
+
const windsurfConfigPath = path5.join(
|
|
16492
16788
|
os.homedir(),
|
|
16493
16789
|
".codeium",
|
|
16494
16790
|
"windsurf",
|
|
16495
16791
|
"mcp_config.json"
|
|
16496
16792
|
);
|
|
16497
|
-
if (
|
|
16498
|
-
const content =
|
|
16793
|
+
if (fs5.existsSync(windsurfConfigPath)) {
|
|
16794
|
+
const content = fs5.readFileSync(windsurfConfigPath, "utf-8");
|
|
16499
16795
|
const windsurfResult = processJsonMcpConfig(content);
|
|
16500
16796
|
const home = os.homedir();
|
|
16501
16797
|
const displayPath = windsurfConfigPath.startsWith(home) ? "~" + windsurfConfigPath.slice(home.length) : windsurfConfigPath;
|
|
16502
16798
|
if (windsurfResult.action === "deleted") {
|
|
16503
16799
|
if (!dryRun) {
|
|
16504
|
-
|
|
16800
|
+
fs5.unlinkSync(windsurfConfigPath);
|
|
16505
16801
|
}
|
|
16506
16802
|
summary.push(
|
|
16507
16803
|
`${prefix}Deleted global Windsurf config (${displayPath})`
|
|
16508
16804
|
);
|
|
16509
16805
|
} else if (windsurfResult.action === "removed-key" && windsurfResult.content !== void 0) {
|
|
16510
16806
|
if (!dryRun) {
|
|
16511
|
-
|
|
16807
|
+
fs5.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
|
|
16512
16808
|
}
|
|
16513
16809
|
summary.push(
|
|
16514
16810
|
`${prefix}Removed glasstrace from global Windsurf config (${displayPath})`
|
|
@@ -16523,21 +16819,21 @@ async function runUninit(options) {
|
|
|
16523
16819
|
}
|
|
16524
16820
|
try {
|
|
16525
16821
|
for (const infoFile of AGENT_INFO_FILES) {
|
|
16526
|
-
const filePath =
|
|
16527
|
-
if (!
|
|
16822
|
+
const filePath = path5.join(projectRoot, infoFile);
|
|
16823
|
+
if (!fs5.existsSync(filePath)) {
|
|
16528
16824
|
continue;
|
|
16529
16825
|
}
|
|
16530
|
-
const content =
|
|
16826
|
+
const content = fs5.readFileSync(filePath, "utf-8");
|
|
16531
16827
|
const result = removeMarkerSection(content);
|
|
16532
16828
|
if (result.removed) {
|
|
16533
16829
|
if (result.content.trim().length === 0) {
|
|
16534
16830
|
if (!dryRun) {
|
|
16535
|
-
|
|
16831
|
+
fs5.unlinkSync(filePath);
|
|
16536
16832
|
}
|
|
16537
16833
|
summary.push(`${prefix}Deleted ${infoFile} (only contained Glasstrace section)`);
|
|
16538
16834
|
} else {
|
|
16539
16835
|
if (!dryRun) {
|
|
16540
|
-
|
|
16836
|
+
fs5.writeFileSync(filePath, result.content, "utf-8");
|
|
16541
16837
|
}
|
|
16542
16838
|
summary.push(`${prefix}Removed Glasstrace section from ${infoFile}`);
|
|
16543
16839
|
}
|
|
@@ -16553,15 +16849,16 @@ async function runUninit(options) {
|
|
|
16553
16849
|
}
|
|
16554
16850
|
return { exitCode: errors.length > 0 ? 1 : 0, summary, warnings, errors };
|
|
16555
16851
|
}
|
|
16556
|
-
var
|
|
16852
|
+
var fs5, os, path5, MCP_CONFIG_FILES, AGENT_INFO_FILES;
|
|
16557
16853
|
var init_uninit = __esm({
|
|
16558
16854
|
"src/cli/uninit.ts"() {
|
|
16559
16855
|
"use strict";
|
|
16560
|
-
|
|
16856
|
+
fs5 = __toESM(require("node:fs"), 1);
|
|
16561
16857
|
os = __toESM(require("node:os"), 1);
|
|
16562
|
-
|
|
16858
|
+
path5 = __toESM(require("node:path"), 1);
|
|
16563
16859
|
init_constants();
|
|
16564
16860
|
init_scaffolder();
|
|
16861
|
+
init_discovery_file();
|
|
16565
16862
|
MCP_CONFIG_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json"];
|
|
16566
16863
|
AGENT_INFO_FILES = [
|
|
16567
16864
|
"CLAUDE.md",
|
|
@@ -16607,11 +16904,11 @@ async function registerViaCli(agent, anonKey) {
|
|
|
16607
16904
|
MCP_ENDPOINT
|
|
16608
16905
|
]);
|
|
16609
16906
|
const configPath = agent.mcpConfigPath;
|
|
16610
|
-
if (configPath !== null &&
|
|
16611
|
-
const content =
|
|
16907
|
+
if (configPath !== null && fs6.existsSync(configPath)) {
|
|
16908
|
+
const content = fs6.readFileSync(configPath, "utf-8");
|
|
16612
16909
|
if (!content.includes("bearer_token_env_var")) {
|
|
16613
16910
|
const appendContent = content.endsWith("\n") ? "" : "\n";
|
|
16614
|
-
|
|
16911
|
+
fs6.writeFileSync(
|
|
16615
16912
|
configPath,
|
|
16616
16913
|
content + appendContent + 'bearer_token_env_var = "GLASSTRACE_API_KEY"\n',
|
|
16617
16914
|
"utf-8"
|
|
@@ -16656,8 +16953,8 @@ async function mcpAdd(options) {
|
|
|
16656
16953
|
messages: ["Error: Run `glasstrace init` first to generate an API key."]
|
|
16657
16954
|
};
|
|
16658
16955
|
}
|
|
16659
|
-
const markerPath =
|
|
16660
|
-
if (
|
|
16956
|
+
const markerPath = path6.join(projectRoot, ".glasstrace", "mcp-connected");
|
|
16957
|
+
if (fs6.existsSync(markerPath) && !force) {
|
|
16661
16958
|
return {
|
|
16662
16959
|
exitCode: 0,
|
|
16663
16960
|
results: [],
|
|
@@ -16716,7 +17013,7 @@ async function mcpAdd(options) {
|
|
|
16716
17013
|
try {
|
|
16717
17014
|
const configContent = generateMcpConfig(agent, MCP_ENDPOINT, anonKey);
|
|
16718
17015
|
await writeMcpConfig(agent, configContent, projectRoot);
|
|
16719
|
-
if (
|
|
17016
|
+
if (fs6.existsSync(agent.mcpConfigPath)) {
|
|
16720
17017
|
const infoContent = generateInfoSection(agent, MCP_ENDPOINT);
|
|
16721
17018
|
if (infoContent !== "") {
|
|
16722
17019
|
await injectInfoSection(agent, infoContent, projectRoot);
|
|
@@ -16783,13 +17080,13 @@ async function mcpAdd(options) {
|
|
|
16783
17080
|
}
|
|
16784
17081
|
return { exitCode: 0, results, messages };
|
|
16785
17082
|
}
|
|
16786
|
-
var import_node_child_process2,
|
|
17083
|
+
var import_node_child_process2, fs6, path6, import_node_util, execFileAsync;
|
|
16787
17084
|
var init_mcp_add = __esm({
|
|
16788
17085
|
"src/cli/mcp-add.ts"() {
|
|
16789
17086
|
"use strict";
|
|
16790
17087
|
import_node_child_process2 = require("node:child_process");
|
|
16791
|
-
|
|
16792
|
-
|
|
17088
|
+
fs6 = __toESM(require("node:fs"), 1);
|
|
17089
|
+
path6 = __toESM(require("node:path"), 1);
|
|
16793
17090
|
import_node_util = require("node:util");
|
|
16794
17091
|
init_anon_key();
|
|
16795
17092
|
init_detect();
|
|
@@ -16820,15 +17117,15 @@ function hasRegisterGlasstraceImport(content) {
|
|
|
16820
17117
|
function runValidate(options) {
|
|
16821
17118
|
const { projectRoot } = options;
|
|
16822
17119
|
const issues = [];
|
|
16823
|
-
const glasstraceDir =
|
|
16824
|
-
const instrumentationPath =
|
|
16825
|
-
const markerPath =
|
|
17120
|
+
const glasstraceDir = path7.join(projectRoot, ".glasstrace");
|
|
17121
|
+
const instrumentationPath = path7.join(projectRoot, "instrumentation.ts");
|
|
17122
|
+
const markerPath = path7.join(glasstraceDir, "mcp-connected");
|
|
16826
17123
|
const glasstraceDirExists = isDirectorySafe(glasstraceDir);
|
|
16827
|
-
const instrumentationExists =
|
|
17124
|
+
const instrumentationExists = fs7.existsSync(instrumentationPath);
|
|
16828
17125
|
const instrumentationContent = instrumentationExists ? safeReadFile(instrumentationPath) : null;
|
|
16829
|
-
const markerExists =
|
|
17126
|
+
const markerExists = fs7.existsSync(markerPath);
|
|
16830
17127
|
const mcpConfigsPresent = MCP_CONFIG_CANDIDATES.filter(
|
|
16831
|
-
(rel) =>
|
|
17128
|
+
(rel) => fs7.existsSync(path7.join(projectRoot, rel))
|
|
16832
17129
|
);
|
|
16833
17130
|
if (glasstraceDirExists) {
|
|
16834
17131
|
if (instrumentationContent === null || !hasRegisterGlasstraceImport(instrumentationContent)) {
|
|
@@ -16878,25 +17175,25 @@ function runValidate(options) {
|
|
|
16878
17175
|
}
|
|
16879
17176
|
function safeReadFile(filePath) {
|
|
16880
17177
|
try {
|
|
16881
|
-
return
|
|
17178
|
+
return fs7.readFileSync(filePath, "utf-8");
|
|
16882
17179
|
} catch {
|
|
16883
17180
|
return null;
|
|
16884
17181
|
}
|
|
16885
17182
|
}
|
|
16886
17183
|
function isDirectorySafe(dirPath) {
|
|
16887
17184
|
try {
|
|
16888
|
-
if (!
|
|
16889
|
-
return
|
|
17185
|
+
if (!fs7.existsSync(dirPath)) return false;
|
|
17186
|
+
return fs7.statSync(dirPath).isDirectory();
|
|
16890
17187
|
} catch {
|
|
16891
17188
|
return false;
|
|
16892
17189
|
}
|
|
16893
17190
|
}
|
|
16894
|
-
var
|
|
17191
|
+
var fs7, path7, MCP_CONFIG_CANDIDATES;
|
|
16895
17192
|
var init_validate = __esm({
|
|
16896
17193
|
"src/cli/validate.ts"() {
|
|
16897
17194
|
"use strict";
|
|
16898
|
-
|
|
16899
|
-
|
|
17195
|
+
fs7 = __toESM(require("node:fs"), 1);
|
|
17196
|
+
path7 = __toESM(require("node:path"), 1);
|
|
16900
17197
|
MCP_CONFIG_CANDIDATES = [
|
|
16901
17198
|
".mcp.json",
|
|
16902
17199
|
".cursor/mcp.json",
|
|
@@ -16926,8 +17223,8 @@ function runStatus(options) {
|
|
|
16926
17223
|
}
|
|
16927
17224
|
function checkInstalled(root) {
|
|
16928
17225
|
try {
|
|
16929
|
-
const pkgPath =
|
|
16930
|
-
const content =
|
|
17226
|
+
const pkgPath = path8.join(root, "package.json");
|
|
17227
|
+
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
16931
17228
|
const pkg = JSON.parse(content);
|
|
16932
17229
|
const deps = pkg["dependencies"];
|
|
16933
17230
|
const devDeps = pkg["devDependencies"];
|
|
@@ -16938,7 +17235,7 @@ function checkInstalled(root) {
|
|
|
16938
17235
|
}
|
|
16939
17236
|
function checkInitialized(root) {
|
|
16940
17237
|
try {
|
|
16941
|
-
return
|
|
17238
|
+
return fs8.statSync(path8.join(root, ".glasstrace")).isDirectory();
|
|
16942
17239
|
} catch {
|
|
16943
17240
|
return false;
|
|
16944
17241
|
}
|
|
@@ -16946,7 +17243,7 @@ function checkInitialized(root) {
|
|
|
16946
17243
|
function checkInstrumentation(root) {
|
|
16947
17244
|
for (const name of INSTRUMENTATION_FILES) {
|
|
16948
17245
|
try {
|
|
16949
|
-
const content =
|
|
17246
|
+
const content = fs8.readFileSync(path8.join(root, name), "utf-8");
|
|
16950
17247
|
if (content.includes("registerGlasstrace")) {
|
|
16951
17248
|
return true;
|
|
16952
17249
|
}
|
|
@@ -16958,7 +17255,7 @@ function checkInstrumentation(root) {
|
|
|
16958
17255
|
function checkConfigWrapped(root) {
|
|
16959
17256
|
for (const name of NEXT_CONFIG_NAMES) {
|
|
16960
17257
|
try {
|
|
16961
|
-
const content =
|
|
17258
|
+
const content = fs8.readFileSync(path8.join(root, name), "utf-8");
|
|
16962
17259
|
if (content.includes("withGlasstraceConfig")) {
|
|
16963
17260
|
return true;
|
|
16964
17261
|
}
|
|
@@ -16969,7 +17266,7 @@ function checkConfigWrapped(root) {
|
|
|
16969
17266
|
}
|
|
16970
17267
|
function checkAnonKey(root) {
|
|
16971
17268
|
try {
|
|
16972
|
-
return
|
|
17269
|
+
return fs8.statSync(path8.join(root, ".glasstrace", "anon_key")).isFile();
|
|
16973
17270
|
} catch {
|
|
16974
17271
|
return false;
|
|
16975
17272
|
}
|
|
@@ -16977,7 +17274,7 @@ function checkAnonKey(root) {
|
|
|
16977
17274
|
function checkMcpConfigured(root) {
|
|
16978
17275
|
for (const name of MCP_JSON_FILES) {
|
|
16979
17276
|
try {
|
|
16980
|
-
const content =
|
|
17277
|
+
const content = fs8.readFileSync(path8.join(root, name), "utf-8");
|
|
16981
17278
|
const parsed = JSON.parse(content);
|
|
16982
17279
|
const mcpServers = parsed["mcpServers"];
|
|
16983
17280
|
if (mcpServers && typeof mcpServers === "object" && "glasstrace" in mcpServers) {
|
|
@@ -16988,7 +17285,7 @@ function checkMcpConfigured(root) {
|
|
|
16988
17285
|
}
|
|
16989
17286
|
for (const name of MCP_TOML_FILES) {
|
|
16990
17287
|
try {
|
|
16991
|
-
const content =
|
|
17288
|
+
const content = fs8.readFileSync(path8.join(root, name), "utf-8");
|
|
16992
17289
|
if (content.includes("[mcp_servers.glasstrace]")) {
|
|
16993
17290
|
return true;
|
|
16994
17291
|
}
|
|
@@ -17001,7 +17298,7 @@ function checkAgents(root) {
|
|
|
17001
17298
|
const found = [];
|
|
17002
17299
|
for (const name of AGENT_INFO_FILES2) {
|
|
17003
17300
|
try {
|
|
17004
|
-
const content =
|
|
17301
|
+
const content = fs8.readFileSync(path8.join(root, name), "utf-8");
|
|
17005
17302
|
const hasHtmlMarkers = content.includes("<!-- glasstrace:mcp:start -->") && content.includes("<!-- glasstrace:mcp:end -->");
|
|
17006
17303
|
const hasHashMarkers = content.includes("# glasstrace:mcp:start") && content.includes("# glasstrace:mcp:end");
|
|
17007
17304
|
if (hasHtmlMarkers || hasHashMarkers) {
|
|
@@ -17024,8 +17321,8 @@ function readRuntimeState(root) {
|
|
|
17024
17321
|
pid: null
|
|
17025
17322
|
};
|
|
17026
17323
|
try {
|
|
17027
|
-
const filePath =
|
|
17028
|
-
const content =
|
|
17324
|
+
const filePath = path8.join(root, ".glasstrace", "runtime-state.json");
|
|
17325
|
+
const content = fs8.readFileSync(filePath, "utf-8");
|
|
17029
17326
|
const parsed = JSON.parse(content);
|
|
17030
17327
|
const updatedAt = typeof parsed.updatedAt === "string" ? parsed.updatedAt : null;
|
|
17031
17328
|
const pid = typeof parsed.pid === "number" ? parsed.pid : null;
|
|
@@ -17074,12 +17371,12 @@ function readRuntimeState(root) {
|
|
|
17074
17371
|
return empty;
|
|
17075
17372
|
}
|
|
17076
17373
|
}
|
|
17077
|
-
var
|
|
17374
|
+
var fs8, path8, MCP_JSON_FILES, MCP_TOML_FILES, AGENT_INFO_FILES2, INSTRUMENTATION_FILES, STALE_THRESHOLD_MS;
|
|
17078
17375
|
var init_status = __esm({
|
|
17079
17376
|
"src/cli/status.ts"() {
|
|
17080
17377
|
"use strict";
|
|
17081
|
-
|
|
17082
|
-
|
|
17378
|
+
fs8 = __toESM(require("node:fs"), 1);
|
|
17379
|
+
path8 = __toESM(require("node:path"), 1);
|
|
17083
17380
|
init_constants();
|
|
17084
17381
|
MCP_JSON_FILES = [".mcp.json", ".cursor/mcp.json", ".gemini/settings.json", ".glasstrace/mcp.json"];
|
|
17085
17382
|
MCP_TOML_FILES = [".codex/config.toml"];
|
|
@@ -17104,14 +17401,15 @@ var init_status = __esm({
|
|
|
17104
17401
|
var init_exports = {};
|
|
17105
17402
|
__export(init_exports, {
|
|
17106
17403
|
decideMcpConfigAction: () => decideMcpConfigAction,
|
|
17404
|
+
gitignoreExcludesDiscoveryFile: () => gitignoreExcludesDiscoveryFile,
|
|
17107
17405
|
meetsNodeVersion: () => meetsNodeVersion,
|
|
17108
17406
|
rollbackSteps: () => rollbackSteps,
|
|
17109
17407
|
runInit: () => runInit,
|
|
17110
17408
|
verifyAnonKeyRegistration: () => verifyAnonKeyRegistration
|
|
17111
17409
|
});
|
|
17112
17410
|
module.exports = __toCommonJS(init_exports);
|
|
17113
|
-
var
|
|
17114
|
-
var
|
|
17411
|
+
var fs9 = __toESM(require("node:fs"), 1);
|
|
17412
|
+
var path9 = __toESM(require("node:path"), 1);
|
|
17115
17413
|
var readline = __toESM(require("node:readline"), 1);
|
|
17116
17414
|
init_scaffolder();
|
|
17117
17415
|
|
|
@@ -17639,6 +17937,7 @@ function resolveConfig(options) {
|
|
|
17639
17937
|
}
|
|
17640
17938
|
|
|
17641
17939
|
// src/cli/init.ts
|
|
17940
|
+
init_discovery_file();
|
|
17642
17941
|
function meetsNodeVersion(minMajor) {
|
|
17643
17942
|
const [major] = process.versions.node.split(".").map(Number);
|
|
17644
17943
|
return major >= minMajor;
|
|
@@ -17646,8 +17945,8 @@ function meetsNodeVersion(minMajor) {
|
|
|
17646
17945
|
async function decideMcpConfigAction(options) {
|
|
17647
17946
|
const { configPath, expectedContent, force } = options;
|
|
17648
17947
|
if (configPath === null) return "write";
|
|
17649
|
-
const exists = options.existsSync ??
|
|
17650
|
-
const read = options.readFile ?? ((p) =>
|
|
17948
|
+
const exists = options.existsSync ?? fs9.existsSync;
|
|
17949
|
+
const read = options.readFile ?? ((p) => fs9.readFileSync(p, "utf-8"));
|
|
17651
17950
|
const prompt = options.prompt ?? promptYesNo;
|
|
17652
17951
|
if (!exists(configPath)) return "write";
|
|
17653
17952
|
let existingContent;
|
|
@@ -17692,22 +17991,69 @@ async function promptYesNo(question, defaultValue) {
|
|
|
17692
17991
|
function cleanLeadingBlankLines2(content) {
|
|
17693
17992
|
return content.replace(/^\n{2,}/, "\n");
|
|
17694
17993
|
}
|
|
17994
|
+
function gitignoreExcludesDiscoveryFile(gitignoreContent, layout) {
|
|
17995
|
+
const staticRoot = layout === "static" ? "static" : "public";
|
|
17996
|
+
const rootTargets = [staticRoot, `${staticRoot}/`];
|
|
17997
|
+
const wellKnownTargets = [
|
|
17998
|
+
`${staticRoot}/.well-known`,
|
|
17999
|
+
`${staticRoot}/.well-known/`,
|
|
18000
|
+
".well-known",
|
|
18001
|
+
".well-known/"
|
|
18002
|
+
];
|
|
18003
|
+
const fileTargets = [
|
|
18004
|
+
`${staticRoot}/.well-known/glasstrace.json`,
|
|
18005
|
+
".well-known/glasstrace.json"
|
|
18006
|
+
];
|
|
18007
|
+
let rootIgnored = false;
|
|
18008
|
+
let wellKnownIgnored = false;
|
|
18009
|
+
let fileIgnored = false;
|
|
18010
|
+
for (const rawLine of gitignoreContent.split("\n")) {
|
|
18011
|
+
const line = rawLine.trim();
|
|
18012
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
18013
|
+
const negation = line.startsWith("!");
|
|
18014
|
+
const pattern = negation ? line.slice(1).trim() : line;
|
|
18015
|
+
if (pattern === "") continue;
|
|
18016
|
+
const normalized = pattern.startsWith("/") ? pattern.slice(1) : pattern;
|
|
18017
|
+
const matchesRoot = matchesDiscoveryPath(normalized, rootTargets);
|
|
18018
|
+
const matchesWellKnown = matchesDiscoveryPath(normalized, wellKnownTargets);
|
|
18019
|
+
const matchesFile = matchesDiscoveryPath(normalized, fileTargets);
|
|
18020
|
+
if (!matchesRoot && !matchesWellKnown && !matchesFile) continue;
|
|
18021
|
+
const newState = !negation;
|
|
18022
|
+
if (matchesRoot) rootIgnored = newState;
|
|
18023
|
+
if (matchesWellKnown) wellKnownIgnored = newState;
|
|
18024
|
+
if (matchesFile) fileIgnored = newState;
|
|
18025
|
+
}
|
|
18026
|
+
return rootIgnored || wellKnownIgnored || fileIgnored;
|
|
18027
|
+
}
|
|
18028
|
+
function matchesDiscoveryPath(pattern, targets) {
|
|
18029
|
+
const bare = pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
18030
|
+
for (const target of targets) {
|
|
18031
|
+
const tBare = target.endsWith("/") ? target.slice(0, -1) : target;
|
|
18032
|
+
if (bare === tBare) return true;
|
|
18033
|
+
if (pattern.startsWith("**/")) {
|
|
18034
|
+
const suffix = pattern.slice(3);
|
|
18035
|
+
const sBare = suffix.endsWith("/") ? suffix.slice(0, -1) : suffix;
|
|
18036
|
+
if (tBare === sBare || tBare.endsWith(`/${sBare}`)) return true;
|
|
18037
|
+
}
|
|
18038
|
+
}
|
|
18039
|
+
return false;
|
|
18040
|
+
}
|
|
17695
18041
|
async function rollbackSteps(steps, projectRoot, state) {
|
|
17696
18042
|
for (const step of [...steps].reverse()) {
|
|
17697
18043
|
try {
|
|
17698
18044
|
switch (step) {
|
|
17699
18045
|
case "instrumentation": {
|
|
17700
|
-
const instrPath = state?.instrumentationPath ??
|
|
17701
|
-
if (
|
|
17702
|
-
const content =
|
|
18046
|
+
const instrPath = state?.instrumentationPath ?? path9.join(projectRoot, "instrumentation.ts");
|
|
18047
|
+
if (fs9.existsSync(instrPath)) {
|
|
18048
|
+
const content = fs9.readFileSync(instrPath, "utf-8");
|
|
17703
18049
|
if (isInitCreatedInstrumentation(content)) {
|
|
17704
|
-
|
|
18050
|
+
fs9.unlinkSync(instrPath);
|
|
17705
18051
|
} else if (state?.originalInstrumentationContent !== void 0) {
|
|
17706
|
-
|
|
18052
|
+
fs9.writeFileSync(instrPath, state.originalInstrumentationContent, "utf-8");
|
|
17707
18053
|
} else {
|
|
17708
18054
|
const cleaned = removeRegisterGlasstrace(content);
|
|
17709
18055
|
if (cleaned !== content) {
|
|
17710
|
-
|
|
18056
|
+
fs9.writeFileSync(instrPath, cleaned, "utf-8");
|
|
17711
18057
|
}
|
|
17712
18058
|
}
|
|
17713
18059
|
}
|
|
@@ -17715,11 +18061,11 @@ async function rollbackSteps(steps, projectRoot, state) {
|
|
|
17715
18061
|
}
|
|
17716
18062
|
case "next-config": {
|
|
17717
18063
|
for (const name of NEXT_CONFIG_NAMES) {
|
|
17718
|
-
const configPath =
|
|
17719
|
-
if (!
|
|
18064
|
+
const configPath = path9.join(projectRoot, name);
|
|
18065
|
+
if (!fs9.existsSync(configPath)) {
|
|
17720
18066
|
continue;
|
|
17721
18067
|
}
|
|
17722
|
-
const content =
|
|
18068
|
+
const content = fs9.readFileSync(configPath, "utf-8");
|
|
17723
18069
|
if (!content.includes("withGlasstraceConfig")) {
|
|
17724
18070
|
continue;
|
|
17725
18071
|
}
|
|
@@ -17727,16 +18073,16 @@ async function rollbackSteps(steps, projectRoot, state) {
|
|
|
17727
18073
|
const unwrapResult = isESM ? unwrapExport(content) : unwrapCJSExport(content);
|
|
17728
18074
|
if (unwrapResult.unwrapped) {
|
|
17729
18075
|
const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
|
|
17730
|
-
|
|
18076
|
+
fs9.writeFileSync(configPath, cleanLeadingBlankLines2(cleaned), "utf-8");
|
|
17731
18077
|
}
|
|
17732
18078
|
break;
|
|
17733
18079
|
}
|
|
17734
18080
|
break;
|
|
17735
18081
|
}
|
|
17736
18082
|
case "env-local": {
|
|
17737
|
-
const envPath =
|
|
17738
|
-
if (
|
|
17739
|
-
const content =
|
|
18083
|
+
const envPath = path9.join(projectRoot, ".env.local");
|
|
18084
|
+
if (fs9.existsSync(envPath)) {
|
|
18085
|
+
const content = fs9.readFileSync(envPath, "utf-8");
|
|
17740
18086
|
const lines = content.split("\n");
|
|
17741
18087
|
const filtered = lines.filter((line) => {
|
|
17742
18088
|
const trimmed = line.trim();
|
|
@@ -17745,18 +18091,18 @@ async function rollbackSteps(steps, projectRoot, state) {
|
|
|
17745
18091
|
if (filtered.length !== lines.length) {
|
|
17746
18092
|
const result = filtered.join("\n");
|
|
17747
18093
|
if (result.trim().length === 0) {
|
|
17748
|
-
|
|
18094
|
+
fs9.unlinkSync(envPath);
|
|
17749
18095
|
} else {
|
|
17750
|
-
|
|
18096
|
+
fs9.writeFileSync(envPath, result, "utf-8");
|
|
17751
18097
|
}
|
|
17752
18098
|
}
|
|
17753
18099
|
}
|
|
17754
18100
|
break;
|
|
17755
18101
|
}
|
|
17756
18102
|
case "gitignore": {
|
|
17757
|
-
const gitignorePath =
|
|
17758
|
-
if (
|
|
17759
|
-
const content =
|
|
18103
|
+
const gitignorePath = path9.join(projectRoot, ".gitignore");
|
|
18104
|
+
if (fs9.existsSync(gitignorePath)) {
|
|
18105
|
+
const content = fs9.readFileSync(gitignorePath, "utf-8");
|
|
17760
18106
|
const lines = content.split("\n");
|
|
17761
18107
|
const filtered = lines.filter(
|
|
17762
18108
|
(line) => line.trim() !== ".glasstrace/"
|
|
@@ -17764,14 +18110,18 @@ async function rollbackSteps(steps, projectRoot, state) {
|
|
|
17764
18110
|
if (filtered.length !== lines.length) {
|
|
17765
18111
|
const result = filtered.join("\n");
|
|
17766
18112
|
if (result.trim().length === 0) {
|
|
17767
|
-
|
|
18113
|
+
fs9.unlinkSync(gitignorePath);
|
|
17768
18114
|
} else {
|
|
17769
|
-
|
|
18115
|
+
fs9.writeFileSync(gitignorePath, result, "utf-8");
|
|
17770
18116
|
}
|
|
17771
18117
|
}
|
|
17772
18118
|
}
|
|
17773
18119
|
break;
|
|
17774
18120
|
}
|
|
18121
|
+
case "discovery-file": {
|
|
18122
|
+
removeDiscoveryFile(projectRoot);
|
|
18123
|
+
break;
|
|
18124
|
+
}
|
|
17775
18125
|
}
|
|
17776
18126
|
} catch {
|
|
17777
18127
|
}
|
|
@@ -17793,8 +18143,8 @@ async function runInit(options) {
|
|
|
17793
18143
|
errors.push(err instanceof Error ? err.message : String(err));
|
|
17794
18144
|
return { exitCode: 1, summary, warnings, errors };
|
|
17795
18145
|
}
|
|
17796
|
-
const packageJsonPath =
|
|
17797
|
-
if (!
|
|
18146
|
+
const packageJsonPath = path9.join(projectRoot, "package.json");
|
|
18147
|
+
if (!fs9.existsSync(packageJsonPath)) {
|
|
17798
18148
|
errors.push("No package.json found. Run this command from a Node.js project root.");
|
|
17799
18149
|
return { exitCode: 1, summary, warnings, errors };
|
|
17800
18150
|
}
|
|
@@ -17803,8 +18153,8 @@ async function runInit(options) {
|
|
|
17803
18153
|
const preResolved = resolveInstrumentationTarget(projectRoot);
|
|
17804
18154
|
if (!preResolved.conflict && preResolved.target !== null) {
|
|
17805
18155
|
rollbackState.instrumentationPath = preResolved.target;
|
|
17806
|
-
if (
|
|
17807
|
-
rollbackState.originalInstrumentationContent =
|
|
18156
|
+
if (fs9.existsSync(preResolved.target)) {
|
|
18157
|
+
rollbackState.originalInstrumentationContent = fs9.readFileSync(
|
|
17808
18158
|
preResolved.target,
|
|
17809
18159
|
"utf-8"
|
|
17810
18160
|
);
|
|
@@ -17819,7 +18169,7 @@ async function runInit(options) {
|
|
|
17819
18169
|
if (instrResult.filePath !== void 0) {
|
|
17820
18170
|
rollbackState.instrumentationPath = instrResult.filePath;
|
|
17821
18171
|
}
|
|
17822
|
-
const relativePath = instrResult.filePath !== void 0 ?
|
|
18172
|
+
const relativePath = instrResult.filePath !== void 0 ? path9.relative(projectRoot, instrResult.filePath) : "instrumentation.ts";
|
|
17823
18173
|
switch (instrResult.action) {
|
|
17824
18174
|
case "created":
|
|
17825
18175
|
summary.push(`Created ${relativePath}`);
|
|
@@ -17844,8 +18194,8 @@ async function runInit(options) {
|
|
|
17844
18194
|
);
|
|
17845
18195
|
break;
|
|
17846
18196
|
case "conflict": {
|
|
17847
|
-
const primary = instrResult.filePath !== void 0 ?
|
|
17848
|
-
const competing = instrResult.conflictingPath !== void 0 ?
|
|
18197
|
+
const primary = instrResult.filePath !== void 0 ? path9.relative(projectRoot, instrResult.filePath) : "src/instrumentation.ts";
|
|
18198
|
+
const competing = instrResult.conflictingPath !== void 0 ? path9.relative(projectRoot, instrResult.conflictingPath) : "instrumentation.ts";
|
|
17849
18199
|
await rollbackSteps(rollbackState.steps, projectRoot, rollbackState);
|
|
17850
18200
|
errors.push(
|
|
17851
18201
|
`Both ${primary} and ${competing} exist. Next.js's loader behavior is undefined when both are present.
|
|
@@ -17892,10 +18242,10 @@ Then add this as the first statement in your register() function:
|
|
|
17892
18242
|
return { exitCode: 1, summary, warnings, errors };
|
|
17893
18243
|
}
|
|
17894
18244
|
try {
|
|
17895
|
-
const envPathForCheck =
|
|
18245
|
+
const envPathForCheck = path9.join(projectRoot, ".env.local");
|
|
17896
18246
|
let existingDevKey = false;
|
|
17897
|
-
if (
|
|
17898
|
-
const existingContent =
|
|
18247
|
+
if (fs9.existsSync(envPathForCheck)) {
|
|
18248
|
+
const existingContent = fs9.readFileSync(envPathForCheck, "utf-8");
|
|
17899
18249
|
existingDevKey = isDevApiKey(readEnvLocalApiKey(existingContent));
|
|
17900
18250
|
}
|
|
17901
18251
|
const envCreated = await scaffoldEnvLocal(projectRoot);
|
|
@@ -17935,11 +18285,55 @@ Then add this as the first statement in your register() function:
|
|
|
17935
18285
|
if (preExistingAnonKey !== null) {
|
|
17936
18286
|
summary.push("Preserved existing .glasstrace/anon_key");
|
|
17937
18287
|
}
|
|
18288
|
+
try {
|
|
18289
|
+
const discoveryResult = writeDiscoveryFile(projectRoot, anonKey);
|
|
18290
|
+
const relPath = relativeDiscoveryPath(discoveryResult.layout);
|
|
18291
|
+
switch (discoveryResult.action) {
|
|
18292
|
+
case "created":
|
|
18293
|
+
summary.push(`Created ${relPath}`);
|
|
18294
|
+
rollbackState.steps.push("discovery-file");
|
|
18295
|
+
break;
|
|
18296
|
+
case "updated-stale":
|
|
18297
|
+
summary.push(`Updated ${relPath} (anon key had changed)`);
|
|
18298
|
+
break;
|
|
18299
|
+
case "skipped-matches":
|
|
18300
|
+
summary.push(`Skipped ${relPath} (already matches anon key)`);
|
|
18301
|
+
break;
|
|
18302
|
+
case "skipped-foreign":
|
|
18303
|
+
summary.push(
|
|
18304
|
+
`Rewrote ${relPath} (existing file was malformed or not SDK-managed)`
|
|
18305
|
+
);
|
|
18306
|
+
break;
|
|
18307
|
+
case "failed":
|
|
18308
|
+
warnings.push(
|
|
18309
|
+
`Failed to write ${relPath}${discoveryResult.error !== void 0 ? `: ${discoveryResult.error}` : ""}. The Glasstrace browser extension will fall back to the runtime handler until the file is written.`
|
|
18310
|
+
);
|
|
18311
|
+
break;
|
|
18312
|
+
}
|
|
18313
|
+
const gitignorePath = path9.join(projectRoot, ".gitignore");
|
|
18314
|
+
if (fs9.existsSync(gitignorePath)) {
|
|
18315
|
+
try {
|
|
18316
|
+
const gitignoreContent = fs9.readFileSync(gitignorePath, "utf-8");
|
|
18317
|
+
if (gitignoreExcludesDiscoveryFile(gitignoreContent, discoveryResult.layout)) {
|
|
18318
|
+
warnings.push(
|
|
18319
|
+
`Your .gitignore excludes ${relPath} (directly or via a parent rule). The discovery file must be committed for the Glasstrace browser extension to find it in deployed builds. Remove the matching line from .gitignore or add an explicit negation (e.g. \`!` + relPath + "`)."
|
|
18320
|
+
);
|
|
18321
|
+
}
|
|
18322
|
+
} catch {
|
|
18323
|
+
}
|
|
18324
|
+
}
|
|
18325
|
+
} catch (err) {
|
|
18326
|
+
warnings.push(
|
|
18327
|
+
`Failed to write ${relativeDiscoveryPath(
|
|
18328
|
+
resolveStaticRoot(projectRoot).layout
|
|
18329
|
+
)}: ${err instanceof Error ? err.message : String(err)}`
|
|
18330
|
+
);
|
|
18331
|
+
}
|
|
17938
18332
|
let anyConfigWritten = false;
|
|
17939
18333
|
if (isCI) {
|
|
17940
18334
|
const genericAgent = {
|
|
17941
18335
|
name: "generic",
|
|
17942
|
-
mcpConfigPath:
|
|
18336
|
+
mcpConfigPath: path9.join(projectRoot, ".glasstrace", "mcp.json"),
|
|
17943
18337
|
infoFilePath: null,
|
|
17944
18338
|
cliAvailable: false,
|
|
17945
18339
|
registrationCommand: null
|
|
@@ -17953,7 +18347,7 @@ Then add this as the first statement in your register() function:
|
|
|
17953
18347
|
if (decision !== "skip") {
|
|
17954
18348
|
await writeMcpConfig(genericAgent, genericConfig, projectRoot);
|
|
17955
18349
|
}
|
|
17956
|
-
if (genericAgent.mcpConfigPath !== null &&
|
|
18350
|
+
if (genericAgent.mcpConfigPath !== null && fs9.existsSync(genericAgent.mcpConfigPath)) {
|
|
17957
18351
|
anyConfigWritten = true;
|
|
17958
18352
|
summary.push("Created .glasstrace/mcp.json (CI mode)");
|
|
17959
18353
|
}
|
|
@@ -17967,14 +18361,14 @@ Then add this as the first statement in your register() function:
|
|
|
17967
18361
|
);
|
|
17968
18362
|
const genericAgent = {
|
|
17969
18363
|
name: "generic",
|
|
17970
|
-
mcpConfigPath:
|
|
18364
|
+
mcpConfigPath: path9.join(projectRoot, ".glasstrace", "mcp.json"),
|
|
17971
18365
|
infoFilePath: null,
|
|
17972
18366
|
cliAvailable: false,
|
|
17973
18367
|
registrationCommand: null
|
|
17974
18368
|
};
|
|
17975
18369
|
const genericConfig = generateMcpConfig(genericAgent, MCP_ENDPOINT, anonKey);
|
|
17976
18370
|
await writeMcpConfig(genericAgent, genericConfig, projectRoot);
|
|
17977
|
-
if (genericAgent.mcpConfigPath !== null &&
|
|
18371
|
+
if (genericAgent.mcpConfigPath !== null && fs9.existsSync(genericAgent.mcpConfigPath)) {
|
|
17978
18372
|
anyConfigWritten = true;
|
|
17979
18373
|
}
|
|
17980
18374
|
agents = [];
|
|
@@ -17992,13 +18386,13 @@ Then add this as the first statement in your register() function:
|
|
|
17992
18386
|
summary.push(
|
|
17993
18387
|
`Preserved existing ${agent.mcpConfigPath ?? agent.name} (user declined overwrite)`
|
|
17994
18388
|
);
|
|
17995
|
-
if (agent.mcpConfigPath !== null &&
|
|
18389
|
+
if (agent.mcpConfigPath !== null && fs9.existsSync(agent.mcpConfigPath)) {
|
|
17996
18390
|
anyConfigWritten = true;
|
|
17997
18391
|
}
|
|
17998
18392
|
continue;
|
|
17999
18393
|
}
|
|
18000
18394
|
await writeMcpConfig(agent, configContent, projectRoot);
|
|
18001
|
-
const configExists = agent.mcpConfigPath !== null &&
|
|
18395
|
+
const configExists = agent.mcpConfigPath !== null && fs9.existsSync(agent.mcpConfigPath);
|
|
18002
18396
|
if (!configExists) {
|
|
18003
18397
|
continue;
|
|
18004
18398
|
}
|
|
@@ -18084,9 +18478,9 @@ async function verifyAnonKeyRegistration(projectRoot) {
|
|
|
18084
18478
|
}
|
|
18085
18479
|
let devKey;
|
|
18086
18480
|
try {
|
|
18087
|
-
const envPath =
|
|
18088
|
-
if (
|
|
18089
|
-
const envContent =
|
|
18481
|
+
const envPath = path9.join(projectRoot, ".env.local");
|
|
18482
|
+
if (fs9.existsSync(envPath)) {
|
|
18483
|
+
const envContent = fs9.readFileSync(envPath, "utf-8");
|
|
18090
18484
|
const effective = readEnvLocalApiKey(envContent);
|
|
18091
18485
|
if (effective !== null && isDevApiKey(effective)) {
|
|
18092
18486
|
devKey = effective;
|
|
@@ -18096,7 +18490,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
|
|
|
18096
18490
|
}
|
|
18097
18491
|
const baseConfig = resolveConfig({ apiKey: devKey });
|
|
18098
18492
|
const config2 = { ...baseConfig, apiKey: devKey };
|
|
18099
|
-
const sdkVersion = true ? "0.
|
|
18493
|
+
const sdkVersion = true ? "0.20.0" : "0.0.0-dev";
|
|
18100
18494
|
const result = await verifyInitReachable(config2, anonKey, sdkVersion);
|
|
18101
18495
|
if (result.ok) {
|
|
18102
18496
|
return { outcome: "verified" };
|
|
@@ -18145,7 +18539,7 @@ function parseArgs(argv) {
|
|
|
18145
18539
|
};
|
|
18146
18540
|
}
|
|
18147
18541
|
var scriptPath = typeof process !== "undefined" && process.argv[1] !== void 0 ? process.argv[1].replace(/\\/g, "/") : void 0;
|
|
18148
|
-
var scriptBasename = scriptPath !== void 0 ?
|
|
18542
|
+
var scriptBasename = scriptPath !== void 0 ? path9.basename(scriptPath) : void 0;
|
|
18149
18543
|
var isDirectExecution = scriptPath !== void 0 && (scriptPath.endsWith("/cli/init.js") || scriptPath.endsWith("/cli/init.ts") || scriptBasename === "glasstrace");
|
|
18150
18544
|
if (isDirectExecution) {
|
|
18151
18545
|
if (!meetsNodeVersion(20)) {
|
|
@@ -18346,6 +18740,7 @@ Usage:
|
|
|
18346
18740
|
// Annotate the CommonJS export names for ESM import in node:
|
|
18347
18741
|
0 && (module.exports = {
|
|
18348
18742
|
decideMcpConfigAction,
|
|
18743
|
+
gitignoreExcludesDiscoveryFile,
|
|
18349
18744
|
meetsNodeVersion,
|
|
18350
18745
|
rollbackSteps,
|
|
18351
18746
|
runInit,
|