securewithtrace 0.18.0 → 0.18.2

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 (2) hide show
  1. package/dist/index.js +863 -82
  2. package/package.json +4 -1
package/dist/index.js CHANGED
@@ -1160,7 +1160,7 @@ var require_command = __commonJS({
1160
1160
  var childProcess = __require("child_process");
1161
1161
  var path = __require("path");
1162
1162
  var fs = __require("fs");
1163
- var process3 = __require("process");
1163
+ var process4 = __require("process");
1164
1164
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1165
1165
  var { CommanderError: CommanderError2 } = require_error();
1166
1166
  var { Help: Help2, stripColor } = require_help();
@@ -1207,13 +1207,13 @@ var require_command = __commonJS({
1207
1207
  this._showSuggestionAfterError = true;
1208
1208
  this._savedState = null;
1209
1209
  this._outputConfiguration = {
1210
- writeOut: (str) => process3.stdout.write(str),
1211
- writeErr: (str) => process3.stderr.write(str),
1210
+ writeOut: (str) => process4.stdout.write(str),
1211
+ writeErr: (str) => process4.stderr.write(str),
1212
1212
  outputError: (str, write) => write(str),
1213
- getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : void 0,
1214
- getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : void 0,
1215
- getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
1216
- getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
1213
+ getOutHelpWidth: () => process4.stdout.isTTY ? process4.stdout.columns : void 0,
1214
+ getErrHelpWidth: () => process4.stderr.isTTY ? process4.stderr.columns : void 0,
1215
+ getOutHasColors: () => useColor() ?? (process4.stdout.isTTY && process4.stdout.hasColors?.()),
1216
+ getErrHasColors: () => useColor() ?? (process4.stderr.isTTY && process4.stderr.hasColors?.()),
1217
1217
  stripColor: (str) => stripColor(str)
1218
1218
  };
1219
1219
  this._hidden = false;
@@ -1596,7 +1596,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1596
1596
  if (this._exitCallback) {
1597
1597
  this._exitCallback(new CommanderError2(exitCode, code, message));
1598
1598
  }
1599
- process3.exit(exitCode);
1599
+ process4.exit(exitCode);
1600
1600
  }
1601
1601
  /**
1602
1602
  * Register callback `fn` for the command.
@@ -1994,16 +1994,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
1994
1994
  }
1995
1995
  parseOptions = parseOptions || {};
1996
1996
  if (argv === void 0 && parseOptions.from === void 0) {
1997
- if (process3.versions?.electron) {
1997
+ if (process4.versions?.electron) {
1998
1998
  parseOptions.from = "electron";
1999
1999
  }
2000
- const execArgv = process3.execArgv ?? [];
2000
+ const execArgv = process4.execArgv ?? [];
2001
2001
  if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
2002
2002
  parseOptions.from = "eval";
2003
2003
  }
2004
2004
  }
2005
2005
  if (argv === void 0) {
2006
- argv = process3.argv;
2006
+ argv = process4.argv;
2007
2007
  }
2008
2008
  this.rawArgs = argv.slice();
2009
2009
  let userArgs;
@@ -2014,7 +2014,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2014
2014
  userArgs = argv.slice(2);
2015
2015
  break;
2016
2016
  case "electron":
2017
- if (process3.defaultApp) {
2017
+ if (process4.defaultApp) {
2018
2018
  this._scriptPath = argv[1];
2019
2019
  userArgs = argv.slice(2);
2020
2020
  } else {
@@ -2201,11 +2201,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2201
2201
  }
2202
2202
  launchWithNode = sourceExt.includes(path.extname(executableFile));
2203
2203
  let proc;
2204
- if (process3.platform !== "win32") {
2204
+ if (process4.platform !== "win32") {
2205
2205
  if (launchWithNode) {
2206
2206
  args.unshift(executableFile);
2207
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
2208
- proc = childProcess.spawn(process3.argv[0], args, { stdio: "inherit" });
2207
+ args = incrementNodeInspectorPort(process4.execArgv).concat(args);
2208
+ proc = childProcess.spawn(process4.argv[0], args, { stdio: "inherit" });
2209
2209
  } else {
2210
2210
  proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
2211
2211
  }
@@ -2216,13 +2216,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2216
2216
  subcommand._name
2217
2217
  );
2218
2218
  args.unshift(executableFile);
2219
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
2220
- proc = childProcess.spawn(process3.execPath, args, { stdio: "inherit" });
2219
+ args = incrementNodeInspectorPort(process4.execArgv).concat(args);
2220
+ proc = childProcess.spawn(process4.execPath, args, { stdio: "inherit" });
2221
2221
  }
2222
2222
  if (!proc.killed) {
2223
2223
  const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
2224
2224
  signals.forEach((signal) => {
2225
- process3.on(signal, () => {
2225
+ process4.on(signal, () => {
2226
2226
  if (proc.killed === false && proc.exitCode === null) {
2227
2227
  proc.kill(signal);
2228
2228
  }
@@ -2233,7 +2233,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2233
2233
  proc.on("close", (code) => {
2234
2234
  code = code ?? 1;
2235
2235
  if (!exitCallback) {
2236
- process3.exit(code);
2236
+ process4.exit(code);
2237
2237
  } else {
2238
2238
  exitCallback(
2239
2239
  new CommanderError2(
@@ -2255,7 +2255,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2255
2255
  throw new Error(`'${executableFile}' not executable`);
2256
2256
  }
2257
2257
  if (!exitCallback) {
2258
- process3.exit(1);
2258
+ process4.exit(1);
2259
2259
  } else {
2260
2260
  const wrappedError = new CommanderError2(
2261
2261
  1,
@@ -2750,13 +2750,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2750
2750
  */
2751
2751
  _parseOptionsEnv() {
2752
2752
  this.options.forEach((option) => {
2753
- if (option.envVar && option.envVar in process3.env) {
2753
+ if (option.envVar && option.envVar in process4.env) {
2754
2754
  const optionKey = option.attributeName();
2755
2755
  if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
2756
2756
  this.getOptionValueSource(optionKey)
2757
2757
  )) {
2758
2758
  if (option.required || option.optional) {
2759
- this.emit(`optionEnv:${option.name()}`, process3.env[option.envVar]);
2759
+ this.emit(`optionEnv:${option.name()}`, process4.env[option.envVar]);
2760
2760
  } else {
2761
2761
  this.emit(`optionEnv:${option.name()}`);
2762
2762
  }
@@ -3211,7 +3211,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3211
3211
  */
3212
3212
  help(contextOptions) {
3213
3213
  this.outputHelp(contextOptions);
3214
- let exitCode = Number(process3.exitCode ?? 0);
3214
+ let exitCode = Number(process4.exitCode ?? 0);
3215
3215
  if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
3216
3216
  exitCode = 1;
3217
3217
  }
@@ -3301,9 +3301,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3301
3301
  });
3302
3302
  }
3303
3303
  function useColor() {
3304
- if (process3.env.NO_COLOR || process3.env.FORCE_COLOR === "0" || process3.env.FORCE_COLOR === "false")
3304
+ if (process4.env.NO_COLOR || process4.env.FORCE_COLOR === "0" || process4.env.FORCE_COLOR === "false")
3305
3305
  return false;
3306
- if (process3.env.FORCE_COLOR || process3.env.CLICOLOR_FORCE !== void 0)
3306
+ if (process4.env.FORCE_COLOR || process4.env.CLICOLOR_FORCE !== void 0)
3307
3307
  return true;
3308
3308
  return void 0;
3309
3309
  }
@@ -8071,12 +8071,12 @@ function $constructor(name, initializer3, params) {
8071
8071
  }
8072
8072
  inst._zod.traits.add(name);
8073
8073
  initializer3(inst, def);
8074
- const proto = _.prototype;
8075
- const keys = Object.keys(proto);
8074
+ const proto2 = _.prototype;
8075
+ const keys = Object.keys(proto2);
8076
8076
  for (let i = 0; i < keys.length; i++) {
8077
8077
  const k = keys[i];
8078
8078
  if (!(k in inst)) {
8079
- inst[k] = proto[k].bind(inst);
8079
+ inst[k] = proto2[k].bind(inst);
8080
8080
  }
8081
8081
  }
8082
8082
  }
@@ -25108,6 +25108,540 @@ function tsvSafe(value) {
25108
25108
  return (value ?? "").replace(/[\t\r\n]/g, " ");
25109
25109
  }
25110
25110
 
25111
+ // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
25112
+ var ANSI_BACKGROUND_OFFSET = 10;
25113
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
25114
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
25115
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
25116
+ var styles = {
25117
+ modifier: {
25118
+ reset: [0, 0],
25119
+ // 21 isn't widely supported and 22 does the same thing
25120
+ bold: [1, 22],
25121
+ dim: [2, 22],
25122
+ italic: [3, 23],
25123
+ underline: [4, 24],
25124
+ overline: [53, 55],
25125
+ inverse: [7, 27],
25126
+ hidden: [8, 28],
25127
+ strikethrough: [9, 29]
25128
+ },
25129
+ color: {
25130
+ black: [30, 39],
25131
+ red: [31, 39],
25132
+ green: [32, 39],
25133
+ yellow: [33, 39],
25134
+ blue: [34, 39],
25135
+ magenta: [35, 39],
25136
+ cyan: [36, 39],
25137
+ white: [37, 39],
25138
+ // Bright color
25139
+ blackBright: [90, 39],
25140
+ gray: [90, 39],
25141
+ // Alias of `blackBright`
25142
+ grey: [90, 39],
25143
+ // Alias of `blackBright`
25144
+ redBright: [91, 39],
25145
+ greenBright: [92, 39],
25146
+ yellowBright: [93, 39],
25147
+ blueBright: [94, 39],
25148
+ magentaBright: [95, 39],
25149
+ cyanBright: [96, 39],
25150
+ whiteBright: [97, 39]
25151
+ },
25152
+ bgColor: {
25153
+ bgBlack: [40, 49],
25154
+ bgRed: [41, 49],
25155
+ bgGreen: [42, 49],
25156
+ bgYellow: [43, 49],
25157
+ bgBlue: [44, 49],
25158
+ bgMagenta: [45, 49],
25159
+ bgCyan: [46, 49],
25160
+ bgWhite: [47, 49],
25161
+ // Bright color
25162
+ bgBlackBright: [100, 49],
25163
+ bgGray: [100, 49],
25164
+ // Alias of `bgBlackBright`
25165
+ bgGrey: [100, 49],
25166
+ // Alias of `bgBlackBright`
25167
+ bgRedBright: [101, 49],
25168
+ bgGreenBright: [102, 49],
25169
+ bgYellowBright: [103, 49],
25170
+ bgBlueBright: [104, 49],
25171
+ bgMagentaBright: [105, 49],
25172
+ bgCyanBright: [106, 49],
25173
+ bgWhiteBright: [107, 49]
25174
+ }
25175
+ };
25176
+ var modifierNames = Object.keys(styles.modifier);
25177
+ var foregroundColorNames = Object.keys(styles.color);
25178
+ var backgroundColorNames = Object.keys(styles.bgColor);
25179
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
25180
+ function assembleStyles() {
25181
+ const codes = /* @__PURE__ */ new Map();
25182
+ for (const [groupName, group] of Object.entries(styles)) {
25183
+ for (const [styleName, style] of Object.entries(group)) {
25184
+ styles[styleName] = {
25185
+ open: `\x1B[${style[0]}m`,
25186
+ close: `\x1B[${style[1]}m`
25187
+ };
25188
+ group[styleName] = styles[styleName];
25189
+ codes.set(style[0], style[1]);
25190
+ }
25191
+ Object.defineProperty(styles, groupName, {
25192
+ value: group,
25193
+ enumerable: false
25194
+ });
25195
+ }
25196
+ Object.defineProperty(styles, "codes", {
25197
+ value: codes,
25198
+ enumerable: false
25199
+ });
25200
+ styles.color.close = "\x1B[39m";
25201
+ styles.bgColor.close = "\x1B[49m";
25202
+ styles.color.ansi = wrapAnsi16();
25203
+ styles.color.ansi256 = wrapAnsi256();
25204
+ styles.color.ansi16m = wrapAnsi16m();
25205
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
25206
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
25207
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
25208
+ Object.defineProperties(styles, {
25209
+ rgbToAnsi256: {
25210
+ value(red, green, blue) {
25211
+ if (red === green && green === blue) {
25212
+ if (red < 8) {
25213
+ return 16;
25214
+ }
25215
+ if (red > 248) {
25216
+ return 231;
25217
+ }
25218
+ return Math.round((red - 8) / 247 * 24) + 232;
25219
+ }
25220
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
25221
+ },
25222
+ enumerable: false
25223
+ },
25224
+ hexToRgb: {
25225
+ value(hex3) {
25226
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex3.toString(16));
25227
+ if (!matches) {
25228
+ return [0, 0, 0];
25229
+ }
25230
+ let [colorString] = matches;
25231
+ if (colorString.length === 3) {
25232
+ colorString = [...colorString].map((character) => character + character).join("");
25233
+ }
25234
+ const integer2 = Number.parseInt(colorString, 16);
25235
+ return [
25236
+ /* eslint-disable no-bitwise */
25237
+ integer2 >> 16 & 255,
25238
+ integer2 >> 8 & 255,
25239
+ integer2 & 255
25240
+ /* eslint-enable no-bitwise */
25241
+ ];
25242
+ },
25243
+ enumerable: false
25244
+ },
25245
+ hexToAnsi256: {
25246
+ value: (hex3) => styles.rgbToAnsi256(...styles.hexToRgb(hex3)),
25247
+ enumerable: false
25248
+ },
25249
+ ansi256ToAnsi: {
25250
+ value(code) {
25251
+ if (code < 8) {
25252
+ return 30 + code;
25253
+ }
25254
+ if (code < 16) {
25255
+ return 90 + (code - 8);
25256
+ }
25257
+ let red;
25258
+ let green;
25259
+ let blue;
25260
+ if (code >= 232) {
25261
+ red = ((code - 232) * 10 + 8) / 255;
25262
+ green = red;
25263
+ blue = red;
25264
+ } else {
25265
+ code -= 16;
25266
+ const remainder = code % 36;
25267
+ red = Math.floor(code / 36) / 5;
25268
+ green = Math.floor(remainder / 6) / 5;
25269
+ blue = remainder % 6 / 5;
25270
+ }
25271
+ const value = Math.max(red, green, blue) * 2;
25272
+ if (value === 0) {
25273
+ return 30;
25274
+ }
25275
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
25276
+ if (value === 2) {
25277
+ result += 60;
25278
+ }
25279
+ return result;
25280
+ },
25281
+ enumerable: false
25282
+ },
25283
+ rgbToAnsi: {
25284
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
25285
+ enumerable: false
25286
+ },
25287
+ hexToAnsi: {
25288
+ value: (hex3) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex3)),
25289
+ enumerable: false
25290
+ }
25291
+ });
25292
+ return styles;
25293
+ }
25294
+ var ansiStyles = assembleStyles();
25295
+ var ansi_styles_default = ansiStyles;
25296
+
25297
+ // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
25298
+ import process3 from "process";
25299
+ import os from "os";
25300
+ import tty from "tty";
25301
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process3.argv) {
25302
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
25303
+ const position = argv.indexOf(prefix + flag);
25304
+ const terminatorPosition = argv.indexOf("--");
25305
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
25306
+ }
25307
+ var { env } = process3;
25308
+ var flagForceColor;
25309
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
25310
+ flagForceColor = 0;
25311
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
25312
+ flagForceColor = 1;
25313
+ }
25314
+ function envForceColor() {
25315
+ if ("FORCE_COLOR" in env) {
25316
+ if (env.FORCE_COLOR === "true") {
25317
+ return 1;
25318
+ }
25319
+ if (env.FORCE_COLOR === "false") {
25320
+ return 0;
25321
+ }
25322
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
25323
+ }
25324
+ }
25325
+ function translateLevel(level) {
25326
+ if (level === 0) {
25327
+ return false;
25328
+ }
25329
+ return {
25330
+ level,
25331
+ hasBasic: true,
25332
+ has256: level >= 2,
25333
+ has16m: level >= 3
25334
+ };
25335
+ }
25336
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
25337
+ const noFlagForceColor = envForceColor();
25338
+ if (noFlagForceColor !== void 0) {
25339
+ flagForceColor = noFlagForceColor;
25340
+ }
25341
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
25342
+ if (forceColor === 0) {
25343
+ return 0;
25344
+ }
25345
+ if (sniffFlags) {
25346
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
25347
+ return 3;
25348
+ }
25349
+ if (hasFlag("color=256")) {
25350
+ return 2;
25351
+ }
25352
+ }
25353
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
25354
+ return 1;
25355
+ }
25356
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
25357
+ return 0;
25358
+ }
25359
+ const min = forceColor || 0;
25360
+ if (env.TERM === "dumb") {
25361
+ return min;
25362
+ }
25363
+ if (process3.platform === "win32") {
25364
+ const osRelease = os.release().split(".");
25365
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
25366
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
25367
+ }
25368
+ return 1;
25369
+ }
25370
+ if ("CI" in env) {
25371
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
25372
+ return 3;
25373
+ }
25374
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
25375
+ return 1;
25376
+ }
25377
+ return min;
25378
+ }
25379
+ if ("TEAMCITY_VERSION" in env) {
25380
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
25381
+ }
25382
+ if (env.COLORTERM === "truecolor") {
25383
+ return 3;
25384
+ }
25385
+ if (env.TERM === "xterm-kitty") {
25386
+ return 3;
25387
+ }
25388
+ if (env.TERM === "xterm-ghostty") {
25389
+ return 3;
25390
+ }
25391
+ if (env.TERM === "wezterm") {
25392
+ return 3;
25393
+ }
25394
+ if ("TERM_PROGRAM" in env) {
25395
+ const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
25396
+ switch (env.TERM_PROGRAM) {
25397
+ case "iTerm.app": {
25398
+ return version2 >= 3 ? 3 : 2;
25399
+ }
25400
+ case "Apple_Terminal": {
25401
+ return 2;
25402
+ }
25403
+ }
25404
+ }
25405
+ if (/-256(color)?$/i.test(env.TERM)) {
25406
+ return 2;
25407
+ }
25408
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
25409
+ return 1;
25410
+ }
25411
+ if ("COLORTERM" in env) {
25412
+ return 1;
25413
+ }
25414
+ return min;
25415
+ }
25416
+ function createSupportsColor(stream, options = {}) {
25417
+ const level = _supportsColor(stream, {
25418
+ streamIsTTY: stream && stream.isTTY,
25419
+ ...options
25420
+ });
25421
+ return translateLevel(level);
25422
+ }
25423
+ var supportsColor = {
25424
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
25425
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
25426
+ };
25427
+ var supports_color_default = supportsColor;
25428
+
25429
+ // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/utilities.js
25430
+ function stringReplaceAll(string4, substring, replacer) {
25431
+ let index = string4.indexOf(substring);
25432
+ if (index === -1) {
25433
+ return string4;
25434
+ }
25435
+ const substringLength = substring.length;
25436
+ let endIndex = 0;
25437
+ let returnValue = "";
25438
+ do {
25439
+ returnValue += string4.slice(endIndex, index) + substring + replacer;
25440
+ endIndex = index + substringLength;
25441
+ index = string4.indexOf(substring, endIndex);
25442
+ } while (index !== -1);
25443
+ returnValue += string4.slice(endIndex);
25444
+ return returnValue;
25445
+ }
25446
+ function stringEncaseCRLFWithFirstIndex(string4, prefix, postfix, index) {
25447
+ let endIndex = 0;
25448
+ let returnValue = "";
25449
+ do {
25450
+ const gotCR = string4[index - 1] === "\r";
25451
+ returnValue += string4.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
25452
+ endIndex = index + 1;
25453
+ index = string4.indexOf("\n", endIndex);
25454
+ } while (index !== -1);
25455
+ returnValue += string4.slice(endIndex);
25456
+ return returnValue;
25457
+ }
25458
+
25459
+ // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/index.js
25460
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
25461
+ var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
25462
+ var STYLER = /* @__PURE__ */ Symbol("STYLER");
25463
+ var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
25464
+ var levelMapping = [
25465
+ "ansi",
25466
+ "ansi",
25467
+ "ansi256",
25468
+ "ansi16m"
25469
+ ];
25470
+ var styles2 = /* @__PURE__ */ Object.create(null);
25471
+ var applyOptions = (object2, options = {}) => {
25472
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
25473
+ throw new Error("The `level` option should be an integer from 0 to 3");
25474
+ }
25475
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
25476
+ object2.level = options.level === void 0 ? colorLevel : options.level;
25477
+ };
25478
+ var chalkFactory = (options) => {
25479
+ const chalk2 = (...strings) => strings.join(" ");
25480
+ applyOptions(chalk2, options);
25481
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
25482
+ return chalk2;
25483
+ };
25484
+ function createChalk(options) {
25485
+ return chalkFactory(options);
25486
+ }
25487
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
25488
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
25489
+ styles2[styleName] = {
25490
+ get() {
25491
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
25492
+ Object.defineProperty(this, styleName, { value: builder });
25493
+ return builder;
25494
+ }
25495
+ };
25496
+ }
25497
+ styles2.visible = {
25498
+ get() {
25499
+ const builder = createBuilder(this, this[STYLER], true);
25500
+ Object.defineProperty(this, "visible", { value: builder });
25501
+ return builder;
25502
+ }
25503
+ };
25504
+ var getModelAnsi = (model, level, type, ...arguments_) => {
25505
+ if (model === "rgb") {
25506
+ if (level === "ansi16m") {
25507
+ return ansi_styles_default[type].ansi16m(...arguments_);
25508
+ }
25509
+ if (level === "ansi256") {
25510
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
25511
+ }
25512
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
25513
+ }
25514
+ if (model === "hex") {
25515
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
25516
+ }
25517
+ return ansi_styles_default[type][model](...arguments_);
25518
+ };
25519
+ var usedModels = ["rgb", "hex", "ansi256"];
25520
+ for (const model of usedModels) {
25521
+ styles2[model] = {
25522
+ get() {
25523
+ const { level } = this;
25524
+ return function(...arguments_) {
25525
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
25526
+ return createBuilder(this, styler, this[IS_EMPTY]);
25527
+ };
25528
+ }
25529
+ };
25530
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
25531
+ styles2[bgModel] = {
25532
+ get() {
25533
+ const { level } = this;
25534
+ return function(...arguments_) {
25535
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
25536
+ return createBuilder(this, styler, this[IS_EMPTY]);
25537
+ };
25538
+ }
25539
+ };
25540
+ }
25541
+ var proto = Object.defineProperties(() => {
25542
+ }, {
25543
+ ...styles2,
25544
+ level: {
25545
+ enumerable: true,
25546
+ get() {
25547
+ return this[GENERATOR].level;
25548
+ },
25549
+ set(level) {
25550
+ this[GENERATOR].level = level;
25551
+ }
25552
+ }
25553
+ });
25554
+ var createStyler = (open, close, parent) => {
25555
+ let openAll;
25556
+ let closeAll;
25557
+ if (parent === void 0) {
25558
+ openAll = open;
25559
+ closeAll = close;
25560
+ } else {
25561
+ openAll = parent.openAll + open;
25562
+ closeAll = close + parent.closeAll;
25563
+ }
25564
+ return {
25565
+ open,
25566
+ close,
25567
+ openAll,
25568
+ closeAll,
25569
+ parent
25570
+ };
25571
+ };
25572
+ var createBuilder = (self, _styler, _isEmpty) => {
25573
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
25574
+ Object.setPrototypeOf(builder, proto);
25575
+ builder[GENERATOR] = self;
25576
+ builder[STYLER] = _styler;
25577
+ builder[IS_EMPTY] = _isEmpty;
25578
+ return builder;
25579
+ };
25580
+ var applyStyle = (self, string4) => {
25581
+ if (self.level <= 0 || !string4) {
25582
+ return self[IS_EMPTY] ? "" : string4;
25583
+ }
25584
+ let styler = self[STYLER];
25585
+ if (styler === void 0) {
25586
+ return string4;
25587
+ }
25588
+ const { openAll, closeAll } = styler;
25589
+ if (string4.includes("\x1B")) {
25590
+ while (styler !== void 0) {
25591
+ string4 = stringReplaceAll(string4, styler.close, styler.open);
25592
+ styler = styler.parent;
25593
+ }
25594
+ }
25595
+ const lfIndex = string4.indexOf("\n");
25596
+ if (lfIndex !== -1) {
25597
+ string4 = stringEncaseCRLFWithFirstIndex(string4, closeAll, openAll, lfIndex);
25598
+ }
25599
+ return openAll + string4 + closeAll;
25600
+ };
25601
+ Object.defineProperties(createChalk.prototype, styles2);
25602
+ var chalk = createChalk();
25603
+ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
25604
+ var source_default = chalk;
25605
+
25606
+ // src/theme.ts
25607
+ function colorSeverity(severity, text, colorizer = source_default) {
25608
+ switch (severity) {
25609
+ case "CRITICAL":
25610
+ return colorizer.red.bold(text);
25611
+ case "HIGH":
25612
+ return colorizer.hex("#ff6b00").bold(text);
25613
+ case "MEDIUM":
25614
+ return colorizer.yellow(text);
25615
+ case "LOW":
25616
+ return colorizer.cyan(text);
25617
+ case "INFORMATIONAL":
25618
+ return colorizer.gray(text);
25619
+ default:
25620
+ return text;
25621
+ }
25622
+ }
25623
+ function colorBanner(text, colorizer = source_default) {
25624
+ return colorizer.cyan.bold(text);
25625
+ }
25626
+ function colorMuted(text, colorizer = source_default) {
25627
+ return colorizer.dim(text);
25628
+ }
25629
+ function colorSuccess(text, colorizer = source_default) {
25630
+ return colorizer.green(text);
25631
+ }
25632
+ function colorError(text, colorizer = source_default) {
25633
+ return colorizer.red(text);
25634
+ }
25635
+ function colorWarning(text, colorizer = source_default) {
25636
+ return colorizer.yellow(text);
25637
+ }
25638
+ function colorAccentBold(text, colorizer = source_default) {
25639
+ return colorizer.bold.cyan(text);
25640
+ }
25641
+ function colorAccentUnderline(text, colorizer = source_default) {
25642
+ return colorizer.underline.cyan(text);
25643
+ }
25644
+
25111
25645
  // src/auth/commands.ts
25112
25646
  function getClientId() {
25113
25647
  const clientId = "client_01KEZ01W5Q3107GTBY51WQ67HT";
@@ -25172,6 +25706,34 @@ function planOrganizationSelectionPersistence(args) {
25172
25706
  function isSafeOrganizationId(organizationId) {
25173
25707
  return SAFE_ORGANIZATION_ID_PATTERN.test(organizationId);
25174
25708
  }
25709
+ function parseOrganizationSelectorInputKey(input) {
25710
+ const rawInput = typeof input === "string" ? input : input.toString("utf8");
25711
+ if (rawInput === "\x1B[A" || rawInput === "\x1BOA") {
25712
+ return "up";
25713
+ }
25714
+ if (rawInput === "\x1B[B" || rawInput === "\x1BOB") {
25715
+ return "down";
25716
+ }
25717
+ if (rawInput === "\r" || rawInput === "\n") {
25718
+ return "enter";
25719
+ }
25720
+ if (rawInput === "\x1B") {
25721
+ return "escape";
25722
+ }
25723
+ if (rawInput === "") {
25724
+ return "interrupt";
25725
+ }
25726
+ return "other";
25727
+ }
25728
+ function getNextOrganizationSelectionIndex(currentIndex, direction, organizationCount) {
25729
+ if (organizationCount <= 0) {
25730
+ return 0;
25731
+ }
25732
+ if (direction === "up") {
25733
+ return (currentIndex - 1 + organizationCount) % organizationCount;
25734
+ }
25735
+ return (currentIndex + 1) % organizationCount;
25736
+ }
25175
25737
  async function fetchOrganizationContext() {
25176
25738
  const result = await authenticatedRequest((client) => client.organization.listMyOrganizations());
25177
25739
  if (result.status !== 200) {
@@ -25285,35 +25847,102 @@ function resolveOrganizationSelectionInput(organizations, input) {
25285
25847
  return findOrganizationByInput(organizations, trimmedInput);
25286
25848
  }
25287
25849
  async function promptForOrganizationSelection(organizations, activeOrganizationId) {
25288
- console.log("Select an organization:");
25289
- for (const [index, organization] of organizations.entries()) {
25290
- const marker = organization.organizationId === activeOrganizationId ? "*" : " ";
25291
- console.log(
25292
- `${marker} ${index + 1}) ${sanitizeForOutput(organization.name)} (${sanitizeForOutput(organization.slug)}) - ${organization.organizationId}`
25293
- );
25850
+ if (organizations.length === 0) {
25851
+ return null;
25294
25852
  }
25295
- console.log("");
25296
- const readline = createInterface({
25297
- input: process.stdin,
25298
- output: process.stdout
25299
- });
25300
- try {
25301
- while (true) {
25302
- const input = await readline.question(
25303
- "Enter number, organization ID, slug, or name (press Enter to cancel): "
25304
- );
25305
- if (input.trim().length === 0) {
25306
- return null;
25307
- }
25308
- const selection = resolveOrganizationSelectionInput(organizations, input);
25309
- if ("organization" in selection) {
25310
- return selection.organization;
25853
+ if (!process.stdin.setRawMode) {
25854
+ const readline = createInterface({
25855
+ input: process.stdin,
25856
+ output: process.stdout
25857
+ });
25858
+ try {
25859
+ while (true) {
25860
+ const input = await readline.question(
25861
+ "Enter number, organization ID, slug, or name (press Enter to cancel): "
25862
+ );
25863
+ if (input.trim().length === 0) {
25864
+ return null;
25865
+ }
25866
+ const selection = resolveOrganizationSelectionInput(organizations, input);
25867
+ if ("organization" in selection) {
25868
+ return selection.organization;
25869
+ }
25870
+ console.error(selection.error);
25311
25871
  }
25312
- console.error(selection.error);
25872
+ } finally {
25873
+ readline.close();
25313
25874
  }
25314
- } finally {
25315
- readline.close();
25316
25875
  }
25876
+ const stdin = process.stdin;
25877
+ const stdout = process.stdout;
25878
+ const activeOrganizationIndex = organizations.findIndex(
25879
+ (organization) => organization.organizationId === activeOrganizationId
25880
+ );
25881
+ let selectedOrganizationIndex = activeOrganizationIndex >= 0 ? activeOrganizationIndex : 0;
25882
+ let renderedLineCount = 0;
25883
+ const wasRawModeEnabled = Boolean(stdin.isRaw);
25884
+ const renderSelector = () => {
25885
+ const lines = ["Select an organization (use Up/Down arrows and Enter):", ""];
25886
+ for (const [index, organization] of organizations.entries()) {
25887
+ const isSelected = index === selectedOrganizationIndex;
25888
+ const isActive = organization.organizationId === activeOrganizationId;
25889
+ const selectionMarker = isSelected ? ">" : " ";
25890
+ const activeMarker = isActive ? "*" : " ";
25891
+ lines.push(
25892
+ `${selectionMarker} ${activeMarker} ${sanitizeForOutput(organization.name)} (${sanitizeForOutput(organization.slug)}) - ${organization.organizationId}`
25893
+ );
25894
+ }
25895
+ lines.push("", "Press Esc to cancel.");
25896
+ if (renderedLineCount > 0) {
25897
+ stdout.write(`\x1B[${renderedLineCount}A`);
25898
+ }
25899
+ for (const line of lines) {
25900
+ stdout.write(`\x1B[2K${line}
25901
+ `);
25902
+ }
25903
+ renderedLineCount = lines.length;
25904
+ };
25905
+ return await new Promise((resolve) => {
25906
+ const finishSelection = (result) => {
25907
+ stdin.off("data", handleInput);
25908
+ stdin.setRawMode(wasRawModeEnabled);
25909
+ stdout.write("\x1B[2K");
25910
+ resolve(result);
25911
+ };
25912
+ const handleInput = (chunk) => {
25913
+ const inputKey = parseOrganizationSelectorInputKey(chunk);
25914
+ if (inputKey === "up") {
25915
+ selectedOrganizationIndex = getNextOrganizationSelectionIndex(
25916
+ selectedOrganizationIndex,
25917
+ "up",
25918
+ organizations.length
25919
+ );
25920
+ renderSelector();
25921
+ return;
25922
+ }
25923
+ if (inputKey === "down") {
25924
+ selectedOrganizationIndex = getNextOrganizationSelectionIndex(
25925
+ selectedOrganizationIndex,
25926
+ "down",
25927
+ organizations.length
25928
+ );
25929
+ renderSelector();
25930
+ return;
25931
+ }
25932
+ if (inputKey === "enter") {
25933
+ const selectedOrganization = organizations[selectedOrganizationIndex];
25934
+ finishSelection(selectedOrganization ?? null);
25935
+ return;
25936
+ }
25937
+ if (inputKey === "escape" || inputKey === "interrupt") {
25938
+ finishSelection(null);
25939
+ }
25940
+ };
25941
+ stdin.setRawMode(true);
25942
+ stdin.resume();
25943
+ stdin.on("data", handleInput);
25944
+ renderSelector();
25945
+ });
25317
25946
  }
25318
25947
  async function refreshAfterOrganizationSwitch(workosOrganizationId, refreshForOrganization = (organizationId) => refreshStoredAccessTokenForOrganization(organizationId)) {
25319
25948
  if (!workosOrganizationId || workosOrganizationId.trim().length === 0) {
@@ -25331,22 +25960,24 @@ Examples:
25331
25960
  ).action(async () => {
25332
25961
  const existingToken = readToken();
25333
25962
  if (existingToken) {
25334
- console.log("You are already logged in. Run `trace auth logout` first to re-authenticate.");
25963
+ console.log(
25964
+ `${colorWarning("You are already logged in.")} Run \`trace auth logout\` first to re-authenticate.`
25965
+ );
25335
25966
  return;
25336
25967
  }
25337
25968
  const clientId = getClientId();
25338
25969
  console.log("Initiating device authorization...\n");
25339
25970
  const auth = await requestDeviceAuthorization(clientId);
25340
25971
  console.log("Your one-time code is:\n");
25341
- console.log(` ${auth.user_code}
25972
+ console.log(` ${colorAccentBold(auth.user_code)}
25342
25973
  `);
25343
- console.log(`Open this URL in your browser: ${auth.verification_uri}`);
25974
+ console.log(`Open this URL in your browser: ${colorAccentUnderline(auth.verification_uri)}`);
25344
25975
  console.log("");
25345
25976
  const opened = await openBrowser(auth.verification_uri_complete);
25346
25977
  if (opened) {
25347
- console.log("A browser window has been opened for you.");
25978
+ console.log(colorSuccess("A browser window has been opened for you."));
25348
25979
  } else {
25349
- console.log(`Or visit: ${auth.verification_uri_complete}`);
25980
+ console.log(`Or visit: ${colorAccentUnderline(auth.verification_uri_complete)}`);
25350
25981
  }
25351
25982
  console.log("\nWaiting for authorization...");
25352
25983
  const tokenResponse = await pollForToken(clientId, auth.device_code, {
@@ -25357,8 +25988,8 @@ Examples:
25357
25988
  const name = [tokenResponse.user.first_name, tokenResponse.user.last_name].filter(Boolean).join(" ");
25358
25989
  const displayName = name || tokenResponse.user.email;
25359
25990
  console.log(`
25360
- Authenticated as ${displayName} (${tokenResponse.user.email})`);
25361
- console.log("Tokens saved to ~/.trace");
25991
+ ${colorSuccess(`Authenticated as ${displayName} (${tokenResponse.user.email})`)}`);
25992
+ console.log(colorSuccess("Tokens saved to ~/.trace"));
25362
25993
  });
25363
25994
  }
25364
25995
  function createLogoutCommand() {
@@ -25370,9 +26001,11 @@ Examples:
25370
26001
  ).action(() => {
25371
26002
  const removed = removeToken();
25372
26003
  if (removed) {
25373
- console.log("Logged out successfully. Local session data removed from ~/.trace/");
26004
+ console.log(
26005
+ colorSuccess("Logged out successfully. Local session data removed from ~/.trace/")
26006
+ );
25374
26007
  } else {
25375
- console.log("No active session found.");
26008
+ console.log(colorWarning("No active session found."));
25376
26009
  }
25377
26010
  });
25378
26011
  }
@@ -25437,7 +26070,7 @@ Examples:
25437
26070
  return;
25438
26071
  }
25439
26072
  if (!info.loggedIn) {
25440
- console.log("Not logged in. Run `tracecli auth login` to authenticate.");
26073
+ console.log(colorError("Not logged in. Run `tracecli auth login` to authenticate."));
25441
26074
  return;
25442
26075
  }
25443
26076
  console.log("Logged in to Trace");
@@ -25451,7 +26084,9 @@ Examples:
25451
26084
  console.log(` Active Org (CLI): ${info.activeOrg}`);
25452
26085
  }
25453
26086
  if (info.expires) {
25454
- console.log(` Expires: ${info.expires}${info.expired ? " (EXPIRED)" : ""}`);
26087
+ console.log(
26088
+ info.expired ? ` Expires: ${info.expires} ${colorError("(EXPIRED)")}` : ` Expires: ${info.expires}`
26089
+ );
25455
26090
  }
25456
26091
  console.log(
25457
26092
  ` Refresh: ${info.hasRefreshToken ? "Available (auto-refresh enabled)" : "Not available"}`
@@ -25637,10 +26272,6 @@ function createAuthCommand() {
25637
26272
  }
25638
26273
 
25639
26274
  // src/banner.ts
25640
- var ESC = "\x1B";
25641
- var RESET = `${ESC}[0m`;
25642
- var CYAN_BOLD = `${ESC}[1;36m`;
25643
- var DIM = `${ESC}[2m`;
25644
26275
  var BANNER = `
25645
26276
  \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
25646
26277
  \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
@@ -25650,8 +26281,8 @@ var BANNER = `
25650
26281
  \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
25651
26282
  `;
25652
26283
  function showBanner() {
25653
- console.log(`${CYAN_BOLD}${BANNER}${RESET}`);
25654
- console.log(`${DIM} Continuous security vulnerability intelligence${RESET}
26284
+ console.log(colorBanner(BANNER));
26285
+ console.log(`${colorMuted(" Continuous security vulnerability intelligence")}
25655
26286
  `);
25656
26287
  }
25657
26288
 
@@ -26236,10 +26867,11 @@ Examples:
26236
26867
  `);
26237
26868
  for (const finding of sorted) {
26238
26869
  const sev = formatFindingSeverity(finding.severity);
26870
+ const severityLabel = colorSeverity(finding.severity, sev);
26239
26871
  const status = formatStatus(finding.status);
26240
26872
  const cwes = finding.cweIds.length > 0 ? ` | ${finding.cweIds.join(", ")}` : "";
26241
26873
  const score = finding.cvssScore != null ? ` | CVSS ${finding.cvssScore.toFixed(1)}` : "";
26242
- console.log(` [${sev}] ${finding.title}`);
26874
+ console.log(` [${severityLabel}] ${finding.title}`);
26243
26875
  console.log(` ${finding.category} \xB7 ${status}${cwes}${score}`);
26244
26876
  if (finding.repositories.length > 0) {
26245
26877
  for (const repo of finding.repositories) {
@@ -26268,11 +26900,11 @@ import { chmodSync, mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSy
26268
26900
  import { tmpdir } from "os";
26269
26901
  import { join as join3 } from "path";
26270
26902
  function stripAnsi(str) {
26271
- const ESC2 = String.fromCharCode(27);
26903
+ const ESC = String.fromCharCode(27);
26272
26904
  const CSI = String.fromCharCode(155);
26273
26905
  const BEL = String.fromCharCode(7);
26274
- const csi = `[${ESC2}${CSI}][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`;
26275
- const osc = `${ESC2}\\].*?(?:${BEL}|${ESC2}\\\\)`;
26906
+ const csi = `[${ESC}${CSI}][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`;
26907
+ const osc = `${ESC}\\].*?(?:${BEL}|${ESC}\\\\)`;
26276
26908
  const pattern = new RegExp(`${osc}|${csi}`, "g");
26277
26909
  return str.replace(pattern, "");
26278
26910
  }
@@ -26548,6 +27180,101 @@ function collectFilterExpression(value, previous) {
26548
27180
  previous.push(value);
26549
27181
  return previous;
26550
27182
  }
27183
+ function extractErrorMessage(body) {
27184
+ if (typeof body === "object" && body !== null && "message" in body && typeof body.message === "string") {
27185
+ const message = body.message.trim();
27186
+ return message.length > 0 ? message : null;
27187
+ }
27188
+ return null;
27189
+ }
27190
+ function decodeJwtExpiration(token) {
27191
+ if (!token) {
27192
+ return null;
27193
+ }
27194
+ const parts = token.split(".");
27195
+ const payload = parts[1];
27196
+ if (!payload) {
27197
+ return null;
27198
+ }
27199
+ try {
27200
+ const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8"));
27201
+ if (typeof decoded.exp !== "number" || !Number.isFinite(decoded.exp)) {
27202
+ return null;
27203
+ }
27204
+ return new Date(decoded.exp * 1e3);
27205
+ } catch {
27206
+ return null;
27207
+ }
27208
+ }
27209
+ function resolveLocalCloneAuthFailure() {
27210
+ const token = readTokenSafe();
27211
+ if (!token) {
27212
+ return { kind: "not_logged_in", hasRefreshToken: readRefreshToken() !== null };
27213
+ }
27214
+ const expiresAt = decodeJwtExpiration(token);
27215
+ if (expiresAt && expiresAt.getTime() <= Date.now()) {
27216
+ return { kind: "expired_access_token", hasRefreshToken: readRefreshToken() !== null };
27217
+ }
27218
+ return { kind: "organization_unresolved" };
27219
+ }
27220
+ function buildCloneTokenFailureWarning(cloneUrl, failure) {
27221
+ const fallbackSuffix = "Falling back to standard git authentication for this clone attempt.";
27222
+ const quotedMessage = failure.message ? ` (${failure.message})` : "";
27223
+ switch (failure.kind) {
27224
+ case "not_logged_in":
27225
+ return `Trace clone credentials are unavailable for ${cloneUrl}: you are not logged in. Run \`tracecli auth login\`. ${fallbackSuffix}`;
27226
+ case "expired_access_token":
27227
+ return `Trace clone credentials are unavailable for ${cloneUrl}: your CLI access token is expired${failure.hasRefreshToken ? ", and refresh did not complete" : ""}. Run \`tracecli auth logout && tracecli auth login\`, then retry. ${fallbackSuffix}`;
27228
+ case "organization_unresolved":
27229
+ return `Trace clone credentials are unavailable for ${cloneUrl}: the active organization could not be resolved from your session. Run \`tracecli org current\` and \`tracecli org switch <organization>\`, or re-authenticate with \`tracecli auth logout && tracecli auth login\`. ${fallbackSuffix}`;
27230
+ case "request_failed":
27231
+ return `Trace clone credentials are temporarily unavailable for ${cloneUrl}: the request to the Trace API failed. Check connectivity, then retry. ${fallbackSuffix}`;
27232
+ case "unauthorized":
27233
+ return `Trace rejected clone credential generation for ${cloneUrl} (401${quotedMessage}). Re-authenticate with \`tracecli auth logout && tracecli auth login\`, then retry. ${fallbackSuffix}`;
27234
+ case "forbidden":
27235
+ return `Trace denied clone credential generation for ${cloneUrl} (403${quotedMessage}). Confirm you can access this organization and repository in Trace. ${fallbackSuffix}`;
27236
+ case "not_found":
27237
+ return `Trace could not generate clone credentials for ${cloneUrl} (404${quotedMessage}). Ensure the repository is connected in the active organization and the GitHub App installation is active. ${fallbackSuffix}`;
27238
+ case "server_error":
27239
+ return `Trace failed to generate clone credentials for ${cloneUrl} due to a server error${quotedMessage}. Retry shortly. ${fallbackSuffix}`;
27240
+ case "unexpected_status":
27241
+ return `Trace returned an unexpected response while generating clone credentials for ${cloneUrl}${quotedMessage ? ` ${quotedMessage}` : ""}. ${fallbackSuffix}`;
27242
+ }
27243
+ }
27244
+ function withOptionalMessage(base, message) {
27245
+ if (typeof message === "string") {
27246
+ return { ...base, message };
27247
+ }
27248
+ return base;
27249
+ }
27250
+ async function listOrganizationsSafe() {
27251
+ const result = await authenticatedRequestSafe(
27252
+ (client) => client.organization.listMyOrganizations()
27253
+ );
27254
+ if (!result || result.status !== 200) {
27255
+ return null;
27256
+ }
27257
+ return result.body;
27258
+ }
27259
+ function resolveWorkosOrganizationId(organizations, organizationId) {
27260
+ const organization = organizations.find((item) => item.organizationId === organizationId);
27261
+ const workosOrganizationId = organization?.workosOrganizationId;
27262
+ if (!workosOrganizationId || workosOrganizationId.trim().length === 0) {
27263
+ return null;
27264
+ }
27265
+ return workosOrganizationId;
27266
+ }
27267
+ async function maybeRefreshCloneTokenSessionForOrganization(organizationId, listOrganizations = listOrganizationsSafe, refreshForOrganization = (workosOrganizationId) => refreshStoredAccessTokenForOrganization(workosOrganizationId)) {
27268
+ const organizations = await listOrganizations();
27269
+ if (!organizations) {
27270
+ return false;
27271
+ }
27272
+ const workosOrganizationId = resolveWorkosOrganizationId(organizations, organizationId);
27273
+ if (!workosOrganizationId) {
27274
+ return false;
27275
+ }
27276
+ return refreshForOrganization(workosOrganizationId);
27277
+ }
26551
27278
  function toRepositoryListFilterOptions(options) {
26552
27279
  return {
26553
27280
  ...options.platform ? { platform: options.platform } : {},
@@ -26764,24 +27491,66 @@ async function fetchCloneToken(repoUrl) {
26764
27491
  try {
26765
27492
  const organizationId = await resolveOrganizationIdSafe();
26766
27493
  if (!organizationId) {
26767
- return null;
27494
+ return { token: null, failure: resolveLocalCloneAuthFailure() };
26768
27495
  }
26769
- const result = await authenticatedRequestSafe(
27496
+ let result = await authenticatedRequestSafe(
26770
27497
  (client) => client.repository.getCloneToken({
26771
27498
  params: { organizationId },
26772
27499
  body: { repositoryUrl: repoUrl }
26773
27500
  })
26774
27501
  );
27502
+ if (result && (result.status === 401 || result.status === 403)) {
27503
+ const refreshed = await maybeRefreshCloneTokenSessionForOrganization(organizationId);
27504
+ if (refreshed) {
27505
+ result = await authenticatedRequestSafe(
27506
+ (client) => client.repository.getCloneToken({
27507
+ params: { organizationId },
27508
+ body: { repositoryUrl: repoUrl }
27509
+ })
27510
+ );
27511
+ }
27512
+ }
26775
27513
  if (!result) {
26776
- return null;
27514
+ return { token: null, failure: { kind: "request_failed" } };
26777
27515
  }
26778
27516
  if (result.status === 200) {
26779
27517
  const token = result.body.token.trim();
26780
- return token.length > 0 ? token : null;
27518
+ if (token.length > 0) {
27519
+ return { token, failure: null };
27520
+ }
27521
+ return { token: null, failure: { kind: "unexpected_status", status: 200 } };
26781
27522
  }
26782
- return null;
27523
+ const message = extractErrorMessage(result.body) ?? void 0;
27524
+ if (result.status === 401) {
27525
+ return {
27526
+ token: null,
27527
+ failure: withOptionalMessage({ kind: "unauthorized", status: 401 }, message)
27528
+ };
27529
+ }
27530
+ if (result.status === 403) {
27531
+ return {
27532
+ token: null,
27533
+ failure: withOptionalMessage({ kind: "forbidden", status: 403 }, message)
27534
+ };
27535
+ }
27536
+ if (result.status === 404) {
27537
+ return {
27538
+ token: null,
27539
+ failure: withOptionalMessage({ kind: "not_found", status: 404 }, message)
27540
+ };
27541
+ }
27542
+ if (result.status >= 500) {
27543
+ return {
27544
+ token: null,
27545
+ failure: withOptionalMessage({ kind: "server_error", status: result.status }, message)
27546
+ };
27547
+ }
27548
+ return {
27549
+ token: null,
27550
+ failure: withOptionalMessage({ kind: "unexpected_status", status: result.status }, message)
27551
+ };
26783
27552
  } catch {
26784
- return null;
27553
+ return { token: null, failure: { kind: "request_failed" } };
26785
27554
  }
26786
27555
  }
26787
27556
  function createCloneCommand() {
@@ -26797,8 +27566,14 @@ Examples:
26797
27566
  const cloneUrl = resolveRepoUrl(repository);
26798
27567
  const targetDir = directory ?? extractRepoName(repository);
26799
27568
  let installationToken = null;
27569
+ let cloneTokenFailure = null;
26800
27570
  if (cloneUrl.startsWith("https://github.com/")) {
26801
- installationToken = await fetchCloneToken(cloneUrl);
27571
+ const cloneTokenResult = await fetchCloneToken(cloneUrl);
27572
+ installationToken = cloneTokenResult.token;
27573
+ cloneTokenFailure = cloneTokenResult.failure;
27574
+ if (cloneTokenFailure) {
27575
+ console.warn(buildCloneTokenFailureWarning(cloneUrl, cloneTokenFailure));
27576
+ }
26802
27577
  }
26803
27578
  const effectiveUrl = installationToken ? urlWithUsername(cloneUrl) : cloneUrl;
26804
27579
  let askPassScript;
@@ -26827,6 +27602,11 @@ Examples:
26827
27602
  });
26828
27603
  const exitCode = await proc.exited;
26829
27604
  if (exitCode !== 0) {
27605
+ if (!installationToken && cloneTokenFailure) {
27606
+ console.error(
27607
+ "Clone failed while Trace clone credentials were unavailable. Resolve the warning above and retry."
27608
+ );
27609
+ }
26830
27610
  process.exit(1);
26831
27611
  }
26832
27612
  if (installationToken) {
@@ -26928,11 +27708,12 @@ function printVulnerabilities(vulnerabilities) {
26928
27708
  );
26929
27709
  for (const vuln of sorted) {
26930
27710
  const sev = formatSeverity(vuln.severity);
27711
+ const displaySeverity = colorSeverity(vuln.severity, sev);
26931
27712
  const status = formatStatus(vuln.status);
26932
27713
  const repo = vuln.repositoryName;
26933
27714
  const file2 = vuln.codeSnippet.filePath;
26934
27715
  const line = vuln.codeSnippet.startLine;
26935
- console.log(` [${sev}] ${vuln.title}`);
27716
+ console.log(` [${displaySeverity}] ${vuln.title}`);
26936
27717
  console.log(` ${repo} \xB7 ${file2}:${line} \xB7 ${status}`);
26937
27718
  console.log(` ${vuln.traceId}`);
26938
27719
  console.log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securewithtrace",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Official Trace CLI for vulnerability intelligence in your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,5 +34,8 @@
34
34
  ],
35
35
  "publishConfig": {
36
36
  "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "chalk": "5.6.2"
37
40
  }
38
41
  }