@glasstrace/sdk 1.6.0 → 1.7.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.
@@ -177,5 +177,17 @@ type VerifyAnonKeyOutcome = {
177
177
  * @internal Exported for testability.
178
178
  */
179
179
  declare function verifyAnonKeyRegistration(projectRoot: string): Promise<VerifyAnonKeyOutcome>;
180
+ /**
181
+ * Detect a help invocation. Help flags short-circuit before any
182
+ * subcommand routing so help invocations never run mutating code paths
183
+ * (DISC-1566). Accepts the argv slice from the second positional onward
184
+ * (i.e., `process.argv.slice(2)`).
185
+ *
186
+ * The check is presence-based on `--help` or `-h` anywhere in the slice.
187
+ * Composite invocations like `glasstrace init --yes --help` are help
188
+ * invocations: the user asked for help, so help is what they get; the
189
+ * `--yes` is ignored.
190
+ */
191
+ declare function isHelpInvocation(argv: readonly string[]): boolean;
180
192
 
181
- export { type InitOptions, type InitResult, type VerifyAnonKeyOutcome, decideMcpConfigAction, gitignoreExcludesDiscoveryFile, meetsNodeVersion, rollbackSteps, runInit, verifyAnonKeyRegistration };
193
+ export { type InitOptions, type InitResult, type VerifyAnonKeyOutcome, decideMcpConfigAction, gitignoreExcludesDiscoveryFile, isHelpInvocation, meetsNodeVersion, rollbackSteps, runInit, verifyAnonKeyRegistration };
@@ -177,5 +177,17 @@ type VerifyAnonKeyOutcome = {
177
177
  * @internal Exported for testability.
178
178
  */
179
179
  declare function verifyAnonKeyRegistration(projectRoot: string): Promise<VerifyAnonKeyOutcome>;
180
+ /**
181
+ * Detect a help invocation. Help flags short-circuit before any
182
+ * subcommand routing so help invocations never run mutating code paths
183
+ * (DISC-1566). Accepts the argv slice from the second positional onward
184
+ * (i.e., `process.argv.slice(2)`).
185
+ *
186
+ * The check is presence-based on `--help` or `-h` anywhere in the slice.
187
+ * Composite invocations like `glasstrace init --yes --help` are help
188
+ * invocations: the user asked for help, so help is what they get; the
189
+ * `--yes` is ignored.
190
+ */
191
+ declare function isHelpInvocation(argv: readonly string[]): boolean;
180
192
 
181
- export { type InitOptions, type InitResult, type VerifyAnonKeyOutcome, decideMcpConfigAction, gitignoreExcludesDiscoveryFile, meetsNodeVersion, rollbackSteps, runInit, verifyAnonKeyRegistration };
193
+ export { type InitOptions, type InitResult, type VerifyAnonKeyOutcome, decideMcpConfigAction, gitignoreExcludesDiscoveryFile, isHelpInvocation, meetsNodeVersion, rollbackSteps, runInit, verifyAnonKeyRegistration };
package/dist/cli/init.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  detectAgents,
27
27
  generateInfoSection,
28
28
  generateMcpConfig
29
- } from "../chunk-D3QXU2VM.js";
29
+ } from "../chunk-KI7YJ7XD.js";
30
30
  import {
31
31
  MCP_ENDPOINT,
32
32
  getOrCreateAnonKey,
@@ -625,6 +625,7 @@ async function runInit(options) {
625
625
  const summary = [];
626
626
  const warnings = [];
627
627
  const errors = [];
628
+ let discoveryFileWriteFailed = false;
628
629
  let projectRoot;
629
630
  try {
630
631
  const classification = resolveProjectRoot(options.projectRoot);
@@ -801,6 +802,7 @@ Then add this as the first statement in your register() function:
801
802
  warnings.push(
802
803
  `Failed to write ${relPath}${discoveryResult.error !== void 0 ? `: ${discoveryResult.error}` : ""}. The Glasstrace browser extension cannot discover this project until the file is written; rerun \`glasstrace init\` after fixing the underlying error.`
803
804
  );
805
+ discoveryFileWriteFailed = true;
804
806
  break;
805
807
  }
806
808
  const gitignorePath = path2.join(projectRoot, ".gitignore");
@@ -821,6 +823,7 @@ Then add this as the first statement in your register() function:
821
823
  resolveStaticRoot(projectRoot).layout
822
824
  )}: ${err instanceof Error ? err.message : String(err)}`
823
825
  );
826
+ discoveryFileWriteFailed = true;
824
827
  }
825
828
  let anyConfigWritten = false;
826
829
  let anyConfigRewrittenWithBearer = false;
@@ -898,7 +901,7 @@ Then add this as the first statement in your register() function:
898
901
  }
899
902
  anyConfigWritten = true;
900
903
  anyConfigRewrittenWithBearer = true;
901
- const sdkVersionForInject = true ? "1.6.0" : "0.0.0-dev";
904
+ const sdkVersionForInject = true ? "1.7.0" : "0.0.0-dev";
902
905
  const infoContent = generateInfoSection(
903
906
  agent,
904
907
  MCP_ENDPOINT,
@@ -980,6 +983,9 @@ Then add this as the first statement in your register() function:
980
983
  summary.push("Skipped anon key verification (no anon key on disk)");
981
984
  }
982
985
  }
986
+ if (discoveryFileWriteFailed) {
987
+ return { exitCode: 1, summary, warnings, errors };
988
+ }
983
989
  return { exitCode: 0, summary, warnings, errors };
984
990
  }
985
991
  async function verifyAnonKeyRegistration(projectRoot) {
@@ -1001,7 +1007,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
1001
1007
  }
1002
1008
  const baseConfig = resolveConfig({ apiKey: devKey });
1003
1009
  const config = { ...baseConfig, apiKey: devKey };
1004
- const sdkVersion = true ? "1.6.0" : "0.0.0-dev";
1010
+ const sdkVersion = true ? "1.7.0" : "0.0.0-dev";
1005
1011
  const result = await verifyInitReachable(config, anonKey, sdkVersion);
1006
1012
  if (result.ok) {
1007
1013
  return { outcome: "verified" };
@@ -1051,7 +1057,11 @@ function parseArgs(argv) {
1051
1057
  }
1052
1058
  var scriptPath = typeof process !== "undefined" && process.argv[1] !== void 0 ? process.argv[1].replace(/\\/g, "/") : void 0;
1053
1059
  var scriptBasename = scriptPath !== void 0 ? path2.basename(scriptPath) : void 0;
1054
- var isDirectExecution = scriptPath !== void 0 && (scriptPath.endsWith("/cli/init.js") || scriptPath.endsWith("/cli/init.ts") || scriptBasename === "glasstrace");
1060
+ var isDirectExecution = scriptPath !== void 0 && (scriptPath.endsWith("/cli/init.js") || scriptPath.endsWith("/cli/init.cjs") || scriptPath.endsWith("/cli/init.ts") || scriptBasename === "glasstrace");
1061
+ function isHelpInvocation(argv) {
1062
+ return argv.some((arg) => arg === "--help" || arg === "-h");
1063
+ }
1064
+ var HELP_TEXT = "glasstrace \u2014 Glasstrace SDK CLI\n\nUsage:\n glasstrace init [--yes] [--coverage-map] [--force] [--validate]\n glasstrace uninit [--dry-run] [--force]\n glasstrace status [--json]\n glasstrace mcp add [--force] [--dry-run]\n glasstrace upgrade-instructions\n\nRun a command without arguments to see its defaults.\nDocs: https://glasstrace.dev/docs/cli\n";
1055
1065
  if (isDirectExecution) {
1056
1066
  if (!meetsNodeVersion(20)) {
1057
1067
  process.stderr.write(
@@ -1060,6 +1070,10 @@ if (isDirectExecution) {
1060
1070
  );
1061
1071
  process.exit(1);
1062
1072
  }
1073
+ if (isHelpInvocation(process.argv.slice(2))) {
1074
+ process.stdout.write(HELP_TEXT);
1075
+ process.exit(0);
1076
+ }
1063
1077
  const subcommand = process.argv[2];
1064
1078
  if (subcommand === "mcp") {
1065
1079
  if (process.argv[3] === "add") {
@@ -1301,6 +1315,7 @@ Usage:
1301
1315
  export {
1302
1316
  decideMcpConfigAction,
1303
1317
  gitignoreExcludesDiscoveryFile,
1318
+ isHelpInvocation,
1304
1319
  meetsNodeVersion,
1305
1320
  rollbackSteps,
1306
1321
  runInit,