@glasstrace/sdk 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +56 -0
  2. package/dist/{chunk-JZ475QRH.js → chunk-D3QXU2VM.js} +22 -191
  3. package/dist/chunk-D3QXU2VM.js.map +1 -0
  4. package/dist/{chunk-VQDYXXVS.js → chunk-N3XIVM2U.js} +154 -8
  5. package/dist/chunk-N3XIVM2U.js.map +1 -0
  6. package/dist/{chunk-VJQIFY33.js → chunk-YLY7AGLC.js} +7 -4
  7. package/dist/chunk-YLY7AGLC.js.map +1 -0
  8. package/dist/chunk-ZBQQXVHD.js +208 -0
  9. package/dist/chunk-ZBQQXVHD.js.map +1 -0
  10. package/dist/cli/init.cjs +206 -34
  11. package/dist/cli/init.cjs.map +1 -1
  12. package/dist/cli/init.js +65 -8
  13. package/dist/cli/init.js.map +1 -1
  14. package/dist/cli/mcp-add.cjs +45 -25
  15. package/dist/cli/mcp-add.cjs.map +1 -1
  16. package/dist/cli/mcp-add.js +10 -7
  17. package/dist/cli/mcp-add.js.map +1 -1
  18. package/dist/cli/status.cjs +33 -3
  19. package/dist/cli/status.cjs.map +1 -1
  20. package/dist/cli/status.js +12 -3
  21. package/dist/cli/status.js.map +1 -1
  22. package/dist/cli/uninit.cjs +27 -3
  23. package/dist/cli/uninit.cjs.map +1 -1
  24. package/dist/cli/uninit.d.cts +10 -2
  25. package/dist/cli/uninit.d.ts +10 -2
  26. package/dist/cli/uninit.js +2 -1
  27. package/dist/cli/upgrade-instructions.cjs +440 -0
  28. package/dist/cli/upgrade-instructions.cjs.map +1 -0
  29. package/dist/cli/upgrade-instructions.d.cts +48 -0
  30. package/dist/cli/upgrade-instructions.d.ts +48 -0
  31. package/dist/cli/upgrade-instructions.js +80 -0
  32. package/dist/cli/upgrade-instructions.js.map +1 -0
  33. package/dist/index.cjs +229 -60
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.js +2 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/node-entry.cjs +237 -68
  38. package/dist/node-entry.cjs.map +1 -1
  39. package/dist/node-entry.js +2 -1
  40. package/package.json +1 -1
  41. package/dist/chunk-JZ475QRH.js.map +0 -1
  42. package/dist/chunk-VJQIFY33.js.map +0 -1
  43. package/dist/chunk-VQDYXXVS.js.map +0 -1
@@ -14514,28 +14514,39 @@ function generateMcpConfig(agent, endpoint, bearer) {
14514
14514
  }
14515
14515
  }
14516
14516
  }
14517
- function htmlMarkers() {
14517
+ var SDK_VERSION_STAMP_PATTERN = /^[A-Za-z0-9.+-]+$/;
14518
+ function htmlMarkers(sdkVersion) {
14518
14519
  return {
14519
- start: "<!-- glasstrace:mcp:start -->",
14520
+ start: `<!-- glasstrace:mcp:start v=${sdkVersion} -->`,
14520
14521
  end: "<!-- glasstrace:mcp:end -->"
14521
14522
  };
14522
14523
  }
14523
- function hashMarkers() {
14524
+ function hashMarkers(sdkVersion) {
14524
14525
  return {
14525
- start: "# glasstrace:mcp:start",
14526
+ start: `# glasstrace:mcp:start v=${sdkVersion}`,
14526
14527
  end: "# glasstrace:mcp:end"
14527
14528
  };
14528
14529
  }
14529
- function generateInfoSection(agent, endpoint) {
14530
+ function generateInfoSection(agent, endpoint, sdkVersion) {
14530
14531
  if (!endpoint || endpoint.trim() === "") {
14531
14532
  throw new Error("endpoint must not be empty");
14532
14533
  }
14534
+ if (!sdkVersion || sdkVersion.trim() === "") {
14535
+ throw new Error("sdkVersion must not be empty");
14536
+ }
14537
+ if (!SDK_VERSION_STAMP_PATTERN.test(sdkVersion)) {
14538
+ throw new Error(
14539
+ "sdkVersion must match [A-Za-z0-9.+\\-]+ (semver-shaped, no whitespace, no angle brackets)"
14540
+ );
14541
+ }
14533
14542
  const content = [
14534
14543
  "",
14535
14544
  "## Glasstrace MCP Integration",
14536
14545
  "",
14537
14546
  `Glasstrace is configured as an MCP server at: ${endpoint}`,
14538
14547
  "",
14548
+ "Glasstrace MCP is available when runtime evidence would materially reduce uncertainty. Use it when there is a failing request, stack trace, unclear runtime behavior, race/data-flow symptom, side effect, or performance issue that source inspection alone does not explain. For a current error, `get_latest_error` or `get_error_list` is usually the cheapest orientation call. For a known route/procedure with no exact error, use `find_trace_candidates` and follow returned exact `get_trace` or `get_root_cause` arguments only if the candidates look relevant. Do not call trace tools for trivial source-local fixes. Treat **no candidates** or **no_traces_found** as a scoped retrieval result, not proof the bug is absent.",
14549
+ "",
14539
14550
  "Available tools:",
14540
14551
  "- `get_latest_error` - Get the most recent error trace from the current session",
14541
14552
  "- `find_trace_candidates` - First-contact route/procedure/URL candidate selection when you have a route fragment, tRPC procedure, method, status, or rough recent activity window but not the exact trace ID. Returns candidate traces plus suggested `get_trace` / `get_root_cause` follow-up call arguments. Candidate discovery, not root-cause proof.",
@@ -14545,24 +14556,24 @@ function generateInfoSection(agent, endpoint) {
14545
14556
  "- `get_test_suggestions` - Get test suggestions based on recent errors",
14546
14557
  "- `get_session_timeline` - Get the timeline of all traces in the current session",
14547
14558
  "",
14548
- "To reconfigure, run: `npx glasstrace mcp add`",
14559
+ "To refresh this managed section after a `@glasstrace/sdk` upgrade, run: `npx glasstrace upgrade-instructions`. To reconfigure MCP credentials, run: `npx glasstrace mcp add`.",
14549
14560
  ""
14550
14561
  ].join("\n");
14551
14562
  switch (agent.name) {
14552
14563
  case "claude": {
14553
- const m = htmlMarkers();
14564
+ const m = htmlMarkers(sdkVersion);
14554
14565
  return `${m.start}
14555
14566
  ${content}${m.end}
14556
14567
  `;
14557
14568
  }
14558
14569
  case "codex": {
14559
- const m = htmlMarkers();
14570
+ const m = htmlMarkers(sdkVersion);
14560
14571
  return `${m.start}
14561
14572
  ${content}${m.end}
14562
14573
  `;
14563
14574
  }
14564
14575
  case "cursor": {
14565
- const m = hashMarkers();
14576
+ const m = hashMarkers(sdkVersion);
14566
14577
  return `${m.start}
14567
14578
  ${content}${m.end}
14568
14579
  `;
@@ -14581,10 +14592,26 @@ ${content}${m.end}
14581
14592
  // src/agent-detection/inject.ts
14582
14593
  var import_promises2 = require("node:fs/promises");
14583
14594
  var import_node_path2 = require("node:path");
14584
- var HTML_START = "<!-- glasstrace:mcp:start -->";
14595
+ var HTML_START_RE = /^<!--\s*glasstrace:mcp:start(?:\s+v=([^\s>]+))?\s*-->$/;
14585
14596
  var HTML_END = "<!-- glasstrace:mcp:end -->";
14586
- var HASH_START = "# glasstrace:mcp:start";
14597
+ var HASH_START_RE = /^#\s*glasstrace:mcp:start(?:\s+v=(\S+))?$/;
14587
14598
  var HASH_END = "# glasstrace:mcp:end";
14599
+ function parseStartMarkerLine(line) {
14600
+ const trimmed = line.trim();
14601
+ const html = HTML_START_RE.exec(trimmed);
14602
+ if (html !== null) {
14603
+ return { kind: "html", stamp: html[1] ?? null };
14604
+ }
14605
+ const hash2 = HASH_START_RE.exec(trimmed);
14606
+ if (hash2 !== null) {
14607
+ return { kind: "hash", stamp: hash2[1] ?? null };
14608
+ }
14609
+ return null;
14610
+ }
14611
+ function isEndMarker(line) {
14612
+ const trimmed = line.trim();
14613
+ return trimmed === HTML_END || trimmed === HASH_END;
14614
+ }
14588
14615
  function isPermissionError(err) {
14589
14616
  const code = err.code;
14590
14617
  return code === "EACCES" || code === "EPERM" || code === "EROFS";
@@ -14626,22 +14653,14 @@ async function writeMcpConfig(agent, content, projectRoot) {
14626
14653
  }
14627
14654
  function findMarkerBoundaries(lines) {
14628
14655
  let startIdx = -1;
14629
- let endIdx = -1;
14630
14656
  for (let i = 0; i < lines.length; i++) {
14631
- const trimmed = lines[i].trim();
14632
- if (trimmed === HTML_START || trimmed === HASH_START) {
14657
+ if (parseStartMarkerLine(lines[i]) !== null) {
14633
14658
  startIdx = i;
14634
- } else if (trimmed === HTML_END || trimmed === HASH_END) {
14635
- if (startIdx !== -1) {
14636
- endIdx = i;
14637
- break;
14638
- }
14659
+ } else if (startIdx !== -1 && isEndMarker(lines[i])) {
14660
+ return { startIdx, endIdx: i };
14639
14661
  }
14640
14662
  }
14641
- if (startIdx === -1 || endIdx === -1) {
14642
- return null;
14643
- }
14644
- return { startIdx, endIdx };
14663
+ return null;
14645
14664
  }
14646
14665
  async function injectInfoSection(agent, content, projectRoot) {
14647
14666
  if (agent.infoFilePath === null) {
@@ -14910,10 +14929,11 @@ async function mcpAdd(options) {
14910
14929
  const bearer = resolved.effective.key;
14911
14930
  for (const agent of targetAgents) {
14912
14931
  const name = formatAgentName(agent.name);
14932
+ const sdkVersion = true ? "1.5.0" : "0.0.0-dev";
14913
14933
  if (agent.name !== "generic") {
14914
14934
  const cliSuccess = await registerViaCli(agent, bearer);
14915
14935
  if (cliSuccess) {
14916
- const infoContent = generateInfoSection(agent, MCP_ENDPOINT);
14936
+ const infoContent = generateInfoSection(agent, MCP_ENDPOINT, sdkVersion);
14917
14937
  if (infoContent !== "") {
14918
14938
  await injectInfoSection(agent, infoContent, projectRoot);
14919
14939
  }
@@ -14931,7 +14951,7 @@ async function mcpAdd(options) {
14931
14951
  const configContent = generateMcpConfig(agent, MCP_ENDPOINT, bearer);
14932
14952
  await writeMcpConfig(agent, configContent, projectRoot);
14933
14953
  if (fs.existsSync(agent.mcpConfigPath)) {
14934
- const infoContent = generateInfoSection(agent, MCP_ENDPOINT);
14954
+ const infoContent = generateInfoSection(agent, MCP_ENDPOINT, sdkVersion);
14935
14955
  if (infoContent !== "") {
14936
14956
  await injectInfoSection(agent, infoContent, projectRoot);
14937
14957
  }