@craftspace/cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1199,9 +1199,9 @@ var require_command = __commonJS({
1199
1199
  "../../../node_modules/commander/lib/command.js"(exports) {
1200
1200
  var EventEmitter = __require("node:events").EventEmitter;
1201
1201
  var childProcess = __require("node:child_process");
1202
- var path3 = __require("node:path");
1202
+ var path5 = __require("node:path");
1203
1203
  var fs = __require("node:fs");
1204
- var process3 = __require("node:process");
1204
+ var process5 = __require("node:process");
1205
1205
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1206
1206
  var { CommanderError: CommanderError2 } = require_error();
1207
1207
  var { Help: Help2, stripColor } = require_help();
@@ -1248,13 +1248,13 @@ var require_command = __commonJS({
1248
1248
  this._showSuggestionAfterError = true;
1249
1249
  this._savedState = null;
1250
1250
  this._outputConfiguration = {
1251
- writeOut: (str) => process3.stdout.write(str),
1252
- writeErr: (str) => process3.stderr.write(str),
1251
+ writeOut: (str) => process5.stdout.write(str),
1252
+ writeErr: (str) => process5.stderr.write(str),
1253
1253
  outputError: (str, write) => write(str),
1254
- getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : void 0,
1255
- getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : void 0,
1256
- getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
1257
- getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
1254
+ getOutHelpWidth: () => process5.stdout.isTTY ? process5.stdout.columns : void 0,
1255
+ getErrHelpWidth: () => process5.stderr.isTTY ? process5.stderr.columns : void 0,
1256
+ getOutHasColors: () => useColor() ?? (process5.stdout.isTTY && process5.stdout.hasColors?.()),
1257
+ getErrHasColors: () => useColor() ?? (process5.stderr.isTTY && process5.stderr.hasColors?.()),
1258
1258
  stripColor: (str) => stripColor(str)
1259
1259
  };
1260
1260
  this._hidden = false;
@@ -1648,7 +1648,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1648
1648
  if (this._exitCallback) {
1649
1649
  this._exitCallback(new CommanderError2(exitCode, code, message));
1650
1650
  }
1651
- process3.exit(exitCode);
1651
+ process5.exit(exitCode);
1652
1652
  }
1653
1653
  /**
1654
1654
  * Register callback `fn` for the command.
@@ -2048,16 +2048,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
2048
2048
  }
2049
2049
  parseOptions = parseOptions || {};
2050
2050
  if (argv === void 0 && parseOptions.from === void 0) {
2051
- if (process3.versions?.electron) {
2051
+ if (process5.versions?.electron) {
2052
2052
  parseOptions.from = "electron";
2053
2053
  }
2054
- const execArgv = process3.execArgv ?? [];
2054
+ const execArgv = process5.execArgv ?? [];
2055
2055
  if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
2056
2056
  parseOptions.from = "eval";
2057
2057
  }
2058
2058
  }
2059
2059
  if (argv === void 0) {
2060
- argv = process3.argv;
2060
+ argv = process5.argv;
2061
2061
  }
2062
2062
  this.rawArgs = argv.slice();
2063
2063
  let userArgs;
@@ -2068,7 +2068,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2068
2068
  userArgs = argv.slice(2);
2069
2069
  break;
2070
2070
  case "electron":
2071
- if (process3.defaultApp) {
2071
+ if (process5.defaultApp) {
2072
2072
  this._scriptPath = argv[1];
2073
2073
  userArgs = argv.slice(2);
2074
2074
  } else {
@@ -2212,9 +2212,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
2212
2212
  let launchWithNode = false;
2213
2213
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
2214
2214
  function findFile(baseDir, baseName) {
2215
- const localBin = path3.resolve(baseDir, baseName);
2215
+ const localBin = path5.resolve(baseDir, baseName);
2216
2216
  if (fs.existsSync(localBin)) return localBin;
2217
- if (sourceExt.includes(path3.extname(baseName))) return void 0;
2217
+ if (sourceExt.includes(path5.extname(baseName))) return void 0;
2218
2218
  const foundExt = sourceExt.find(
2219
2219
  (ext) => fs.existsSync(`${localBin}${ext}`)
2220
2220
  );
@@ -2232,17 +2232,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
2232
2232
  } catch {
2233
2233
  resolvedScriptPath = this._scriptPath;
2234
2234
  }
2235
- executableDir = path3.resolve(
2236
- path3.dirname(resolvedScriptPath),
2235
+ executableDir = path5.resolve(
2236
+ path5.dirname(resolvedScriptPath),
2237
2237
  executableDir
2238
2238
  );
2239
2239
  }
2240
2240
  if (executableDir) {
2241
2241
  let localFile = findFile(executableDir, executableFile);
2242
2242
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
2243
- const legacyName = path3.basename(
2243
+ const legacyName = path5.basename(
2244
2244
  this._scriptPath,
2245
- path3.extname(this._scriptPath)
2245
+ path5.extname(this._scriptPath)
2246
2246
  );
2247
2247
  if (legacyName !== this._name) {
2248
2248
  localFile = findFile(
@@ -2253,13 +2253,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2253
2253
  }
2254
2254
  executableFile = localFile || executableFile;
2255
2255
  }
2256
- launchWithNode = sourceExt.includes(path3.extname(executableFile));
2256
+ launchWithNode = sourceExt.includes(path5.extname(executableFile));
2257
2257
  let proc;
2258
- if (process3.platform !== "win32") {
2258
+ if (process5.platform !== "win32") {
2259
2259
  if (launchWithNode) {
2260
2260
  args.unshift(executableFile);
2261
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
2262
- proc = childProcess.spawn(process3.argv[0], args, { stdio: "inherit" });
2261
+ args = incrementNodeInspectorPort(process5.execArgv).concat(args);
2262
+ proc = childProcess.spawn(process5.argv[0], args, { stdio: "inherit" });
2263
2263
  } else {
2264
2264
  proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
2265
2265
  }
@@ -2270,13 +2270,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2270
2270
  subcommand._name
2271
2271
  );
2272
2272
  args.unshift(executableFile);
2273
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
2274
- proc = childProcess.spawn(process3.execPath, args, { stdio: "inherit" });
2273
+ args = incrementNodeInspectorPort(process5.execArgv).concat(args);
2274
+ proc = childProcess.spawn(process5.execPath, args, { stdio: "inherit" });
2275
2275
  }
2276
2276
  if (!proc.killed) {
2277
- const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
2278
- signals.forEach((signal) => {
2279
- process3.on(signal, () => {
2277
+ const signals2 = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
2278
+ signals2.forEach((signal) => {
2279
+ process5.on(signal, () => {
2280
2280
  if (proc.killed === false && proc.exitCode === null) {
2281
2281
  proc.kill(signal);
2282
2282
  }
@@ -2287,7 +2287,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2287
2287
  proc.on("close", (code) => {
2288
2288
  code = code ?? 1;
2289
2289
  if (!exitCallback) {
2290
- process3.exit(code);
2290
+ process5.exit(code);
2291
2291
  } else {
2292
2292
  exitCallback(
2293
2293
  new CommanderError2(
@@ -2309,7 +2309,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2309
2309
  throw new Error(`'${executableFile}' not executable`);
2310
2310
  }
2311
2311
  if (!exitCallback) {
2312
- process3.exit(1);
2312
+ process5.exit(1);
2313
2313
  } else {
2314
2314
  const wrappedError = new CommanderError2(
2315
2315
  1,
@@ -2809,13 +2809,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2809
2809
  */
2810
2810
  _parseOptionsEnv() {
2811
2811
  this.options.forEach((option) => {
2812
- if (option.envVar && option.envVar in process3.env) {
2812
+ if (option.envVar && option.envVar in process5.env) {
2813
2813
  const optionKey = option.attributeName();
2814
2814
  if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
2815
2815
  this.getOptionValueSource(optionKey)
2816
2816
  )) {
2817
2817
  if (option.required || option.optional) {
2818
- this.emit(`optionEnv:${option.name()}`, process3.env[option.envVar]);
2818
+ this.emit(`optionEnv:${option.name()}`, process5.env[option.envVar]);
2819
2819
  } else {
2820
2820
  this.emit(`optionEnv:${option.name()}`);
2821
2821
  }
@@ -3168,7 +3168,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3168
3168
  * @return {Command}
3169
3169
  */
3170
3170
  nameFromFilename(filename) {
3171
- this._name = path3.basename(filename, path3.extname(filename));
3171
+ this._name = path5.basename(filename, path5.extname(filename));
3172
3172
  return this;
3173
3173
  }
3174
3174
  /**
@@ -3182,9 +3182,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3182
3182
  * @param {string} [path]
3183
3183
  * @return {(string|null|Command)}
3184
3184
  */
3185
- executableDir(path4) {
3186
- if (path4 === void 0) return this._executableDir;
3187
- this._executableDir = path4;
3185
+ executableDir(path6) {
3186
+ if (path6 === void 0) return this._executableDir;
3187
+ this._executableDir = path6;
3188
3188
  return this;
3189
3189
  }
3190
3190
  /**
@@ -3339,7 +3339,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3339
3339
  */
3340
3340
  help(contextOptions) {
3341
3341
  this.outputHelp(contextOptions);
3342
- let exitCode = Number(process3.exitCode ?? 0);
3342
+ let exitCode = Number(process5.exitCode ?? 0);
3343
3343
  if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
3344
3344
  exitCode = 1;
3345
3345
  }
@@ -3429,9 +3429,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3429
3429
  });
3430
3430
  }
3431
3431
  function useColor() {
3432
- if (process3.env.NO_COLOR || process3.env.FORCE_COLOR === "0" || process3.env.FORCE_COLOR === "false")
3432
+ if (process5.env.NO_COLOR || process5.env.FORCE_COLOR === "0" || process5.env.FORCE_COLOR === "false")
3433
3433
  return false;
3434
- if (process3.env.FORCE_COLOR || process3.env.CLICOLOR_FORCE !== void 0)
3434
+ if (process5.env.FORCE_COLOR || process5.env.CLICOLOR_FORCE !== void 0)
3435
3435
  return true;
3436
3436
  return void 0;
3437
3437
  }
@@ -3462,6 +3462,171 @@ var require_commander = __commonJS({
3462
3462
  }
3463
3463
  });
3464
3464
 
3465
+ // ../../../node_modules/cli-width/index.js
3466
+ var require_cli_width = __commonJS({
3467
+ "../../../node_modules/cli-width/index.js"(exports, module) {
3468
+ "use strict";
3469
+ module.exports = cliWidth2;
3470
+ function normalizeOpts(options) {
3471
+ const defaultOpts = {
3472
+ defaultWidth: 0,
3473
+ output: process.stdout,
3474
+ tty: __require("tty")
3475
+ };
3476
+ if (!options) {
3477
+ return defaultOpts;
3478
+ }
3479
+ Object.keys(defaultOpts).forEach(function(key) {
3480
+ if (!options[key]) {
3481
+ options[key] = defaultOpts[key];
3482
+ }
3483
+ });
3484
+ return options;
3485
+ }
3486
+ function cliWidth2(options) {
3487
+ const opts = normalizeOpts(options);
3488
+ if (opts.output.getWindowSize) {
3489
+ return opts.output.getWindowSize()[0] || opts.defaultWidth;
3490
+ }
3491
+ if (opts.tty.getWindowSize) {
3492
+ return opts.tty.getWindowSize()[1] || opts.defaultWidth;
3493
+ }
3494
+ if (opts.output.columns) {
3495
+ return opts.output.columns;
3496
+ }
3497
+ if (process.env.CLI_WIDTH) {
3498
+ const width = parseInt(process.env.CLI_WIDTH, 10);
3499
+ if (!isNaN(width) && width !== 0) {
3500
+ return width;
3501
+ }
3502
+ }
3503
+ return opts.defaultWidth;
3504
+ }
3505
+ }
3506
+ });
3507
+
3508
+ // ../../../node_modules/mute-stream/lib/index.js
3509
+ var require_lib = __commonJS({
3510
+ "../../../node_modules/mute-stream/lib/index.js"(exports, module) {
3511
+ var Stream = __require("stream");
3512
+ var MuteStream2 = class extends Stream {
3513
+ #isTTY = null;
3514
+ constructor(opts = {}) {
3515
+ super(opts);
3516
+ this.writable = this.readable = true;
3517
+ this.muted = false;
3518
+ this.on("pipe", this._onpipe);
3519
+ this.replace = opts.replace;
3520
+ this._prompt = opts.prompt || null;
3521
+ this._hadControl = false;
3522
+ }
3523
+ #destSrc(key, def) {
3524
+ if (this._dest) {
3525
+ return this._dest[key];
3526
+ }
3527
+ if (this._src) {
3528
+ return this._src[key];
3529
+ }
3530
+ return def;
3531
+ }
3532
+ #proxy(method, ...args) {
3533
+ if (typeof this._dest?.[method] === "function") {
3534
+ this._dest[method](...args);
3535
+ }
3536
+ if (typeof this._src?.[method] === "function") {
3537
+ this._src[method](...args);
3538
+ }
3539
+ }
3540
+ get isTTY() {
3541
+ if (this.#isTTY !== null) {
3542
+ return this.#isTTY;
3543
+ }
3544
+ return this.#destSrc("isTTY", false);
3545
+ }
3546
+ // basically just get replace the getter/setter with a regular value
3547
+ set isTTY(val) {
3548
+ this.#isTTY = val;
3549
+ }
3550
+ get rows() {
3551
+ return this.#destSrc("rows");
3552
+ }
3553
+ get columns() {
3554
+ return this.#destSrc("columns");
3555
+ }
3556
+ mute() {
3557
+ this.muted = true;
3558
+ }
3559
+ unmute() {
3560
+ this.muted = false;
3561
+ }
3562
+ _onpipe(src) {
3563
+ this._src = src;
3564
+ }
3565
+ pipe(dest, options) {
3566
+ this._dest = dest;
3567
+ return super.pipe(dest, options);
3568
+ }
3569
+ pause() {
3570
+ if (this._src) {
3571
+ return this._src.pause();
3572
+ }
3573
+ }
3574
+ resume() {
3575
+ if (this._src) {
3576
+ return this._src.resume();
3577
+ }
3578
+ }
3579
+ write(c) {
3580
+ if (this.muted) {
3581
+ if (!this.replace) {
3582
+ return true;
3583
+ }
3584
+ if (c.match(/^\u001b/)) {
3585
+ if (c.indexOf(this._prompt) === 0) {
3586
+ c = c.slice(this._prompt.length);
3587
+ c = c.replace(/./g, this.replace);
3588
+ c = this._prompt + c;
3589
+ }
3590
+ this._hadControl = true;
3591
+ return this.emit("data", c);
3592
+ } else {
3593
+ if (this._prompt && this._hadControl && c.indexOf(this._prompt) === 0) {
3594
+ this._hadControl = false;
3595
+ this.emit("data", this._prompt);
3596
+ c = c.slice(this._prompt.length);
3597
+ }
3598
+ c = c.toString().replace(/./g, this.replace);
3599
+ }
3600
+ }
3601
+ this.emit("data", c);
3602
+ }
3603
+ end(c) {
3604
+ if (this.muted) {
3605
+ if (c && this.replace) {
3606
+ c = c.toString().replace(/./g, this.replace);
3607
+ } else {
3608
+ c = null;
3609
+ }
3610
+ }
3611
+ if (c) {
3612
+ this.emit("data", c);
3613
+ }
3614
+ this.emit("end");
3615
+ }
3616
+ destroy(...args) {
3617
+ return this.#proxy("destroy", ...args);
3618
+ }
3619
+ destroySoon(...args) {
3620
+ return this.#proxy("destroySoon", ...args);
3621
+ }
3622
+ close(...args) {
3623
+ return this.#proxy("close", ...args);
3624
+ }
3625
+ };
3626
+ module.exports = MuteStream2;
3627
+ }
3628
+ });
3629
+
3465
3630
  // ../../../node_modules/commander/esm.mjs
3466
3631
  var import_index = __toESM(require_commander(), 1);
3467
3632
  var {
@@ -4245,10 +4410,10 @@ function mergeDefs(...defs) {
4245
4410
  function cloneDef(schema) {
4246
4411
  return mergeDefs(schema._zod.def);
4247
4412
  }
4248
- function getElementAtPath(obj, path3) {
4249
- if (!path3)
4413
+ function getElementAtPath(obj, path5) {
4414
+ if (!path5)
4250
4415
  return obj;
4251
- return path3.reduce((acc, key) => acc?.[key], obj);
4416
+ return path5.reduce((acc, key) => acc?.[key], obj);
4252
4417
  }
4253
4418
  function promiseAllObject(promisesObj) {
4254
4419
  const keys = Object.keys(promisesObj);
@@ -4657,11 +4822,11 @@ function explicitlyAborted(x, startIndex = 0) {
4657
4822
  }
4658
4823
  return false;
4659
4824
  }
4660
- function prefixIssues(path3, issues) {
4825
+ function prefixIssues(path5, issues) {
4661
4826
  return issues.map((iss) => {
4662
4827
  var _a3;
4663
4828
  (_a3 = iss).path ?? (_a3.path = []);
4664
- iss.path.unshift(path3);
4829
+ iss.path.unshift(path5);
4665
4830
  return iss;
4666
4831
  });
4667
4832
  }
@@ -4808,16 +4973,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
4808
4973
  }
4809
4974
  function formatError(error51, mapper = (issue2) => issue2.message) {
4810
4975
  const fieldErrors = { _errors: [] };
4811
- const processError = (error52, path3 = []) => {
4976
+ const processError = (error52, path5 = []) => {
4812
4977
  for (const issue2 of error52.issues) {
4813
4978
  if (issue2.code === "invalid_union" && issue2.errors.length) {
4814
- issue2.errors.map((issues) => processError({ issues }, [...path3, ...issue2.path]));
4979
+ issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
4815
4980
  } else if (issue2.code === "invalid_key") {
4816
- processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
4981
+ processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
4817
4982
  } else if (issue2.code === "invalid_element") {
4818
- processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
4983
+ processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
4819
4984
  } else {
4820
- const fullpath = [...path3, ...issue2.path];
4985
+ const fullpath = [...path5, ...issue2.path];
4821
4986
  if (fullpath.length === 0) {
4822
4987
  fieldErrors._errors.push(mapper(issue2));
4823
4988
  } else {
@@ -4844,17 +5009,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
4844
5009
  }
4845
5010
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
4846
5011
  const result = { errors: [] };
4847
- const processError = (error52, path3 = []) => {
5012
+ const processError = (error52, path5 = []) => {
4848
5013
  var _a3, _b;
4849
5014
  for (const issue2 of error52.issues) {
4850
5015
  if (issue2.code === "invalid_union" && issue2.errors.length) {
4851
- issue2.errors.map((issues) => processError({ issues }, [...path3, ...issue2.path]));
5016
+ issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
4852
5017
  } else if (issue2.code === "invalid_key") {
4853
- processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
5018
+ processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
4854
5019
  } else if (issue2.code === "invalid_element") {
4855
- processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
5020
+ processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
4856
5021
  } else {
4857
- const fullpath = [...path3, ...issue2.path];
5022
+ const fullpath = [...path5, ...issue2.path];
4858
5023
  if (fullpath.length === 0) {
4859
5024
  result.errors.push(mapper(issue2));
4860
5025
  continue;
@@ -4886,8 +5051,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
4886
5051
  }
4887
5052
  function toDotPath(_path) {
4888
5053
  const segs = [];
4889
- const path3 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
4890
- for (const seg of path3) {
5054
+ const path5 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
5055
+ for (const seg of path5) {
4891
5056
  if (typeof seg === "number")
4892
5057
  segs.push(`[${seg}]`);
4893
5058
  else if (typeof seg === "symbol")
@@ -17579,13 +17744,13 @@ function resolveRef(ref, ctx) {
17579
17744
  if (!ref.startsWith("#")) {
17580
17745
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
17581
17746
  }
17582
- const path3 = ref.slice(1).split("/").filter(Boolean);
17583
- if (path3.length === 0) {
17747
+ const path5 = ref.slice(1).split("/").filter(Boolean);
17748
+ if (path5.length === 0) {
17584
17749
  return ctx.rootSchema;
17585
17750
  }
17586
17751
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
17587
- if (path3[0] === defsKey) {
17588
- const key = path3[1];
17752
+ if (path5[0] === defsKey) {
17753
+ const key = path5[1];
17589
17754
  if (!key || !ctx.defs[key]) {
17590
17755
  throw new Error(`Reference not found: ${ref}`);
17591
17756
  }
@@ -19589,7 +19754,7 @@ var SaveWorkstationBodySchema = external_exports.object({
19589
19754
  var WorkstationResponseSchema = external_exports.object({ workstation: WorkstationSchema });
19590
19755
 
19591
19756
  // ../../shared/dist/machines/machine.js
19592
- var CLI_VERSION = "0.1.0";
19757
+ var CLI_VERSION = "0.2.0";
19593
19758
  var MACHINE_BEAT_INTERVAL_MS = 15e3;
19594
19759
  var MACHINE_BEAT_BUSY_INTERVAL_MS = 3e3;
19595
19760
  var MACHINE_RUN_OUTPUT_MAX = 32e3;
@@ -20056,10 +20221,1874 @@ var MemberActivityListResponse = external_exports.object({
20056
20221
  // dist/machine.js
20057
20222
  import { execFile as execFile3 } from "node:child_process";
20058
20223
  import { mkdir, readFile as readFile2, readdir, rm, writeFile } from "node:fs/promises";
20059
- import os2 from "node:os";
20060
- import path2 from "node:path";
20224
+ import os3 from "node:os";
20225
+ import path4 from "node:path";
20061
20226
  import { promisify as promisify3 } from "node:util";
20062
20227
 
20228
+ // ../../../node_modules/@inquirer/core/dist/lib/key.js
20229
+ var keybindings = ["emacs", "vim"];
20230
+ var keybindingLookup = new Set(keybindings);
20231
+ function isKeybinding(value) {
20232
+ return keybindingLookup.has(value);
20233
+ }
20234
+ function getDefaultKeybindings() {
20235
+ const env = process.env["INQUIRER_KEYBINDINGS"];
20236
+ if (!env)
20237
+ return [];
20238
+ return Array.from(new Set(env.toLowerCase().split(/[\s,]+/).filter(isKeybinding)));
20239
+ }
20240
+ var isUpKey = (key, keybindings2 = []) => (
20241
+ // The up key
20242
+ key.name === "up" || // Vim keybinding: hjkl keys map to left/down/up/right
20243
+ keybindings2.includes("vim") && key.name === "k" || // Emacs keybinding: Ctrl+P means "previous" in Emacs navigation conventions
20244
+ keybindings2.includes("emacs") && key.ctrl && key.name === "p"
20245
+ );
20246
+ var isDownKey = (key, keybindings2 = []) => (
20247
+ // The down key
20248
+ key.name === "down" || // Vim keybinding: hjkl keys map to left/down/up/right
20249
+ keybindings2.includes("vim") && key.name === "j" || // Emacs keybinding: Ctrl+N means "next" in Emacs navigation conventions
20250
+ keybindings2.includes("emacs") && key.ctrl && key.name === "n"
20251
+ );
20252
+ var isBackspaceKey = (key) => key.name === "backspace";
20253
+ var isTabKey = (key) => key.name === "tab";
20254
+ var isNumberKey = (key) => "1234567890".includes(key.name);
20255
+ var isEnterKey = (key) => key.name === "enter" || key.name === "return";
20256
+
20257
+ // ../../../node_modules/@inquirer/core/dist/lib/errors.js
20258
+ var AbortPromptError = class extends Error {
20259
+ name = "AbortPromptError";
20260
+ message = "Prompt was aborted";
20261
+ constructor(options) {
20262
+ super();
20263
+ this.cause = options?.cause;
20264
+ }
20265
+ };
20266
+ var CancelPromptError = class extends Error {
20267
+ name = "CancelPromptError";
20268
+ message = "Prompt was canceled";
20269
+ };
20270
+ var ExitPromptError = class extends Error {
20271
+ name = "ExitPromptError";
20272
+ };
20273
+ var HookError = class extends Error {
20274
+ name = "HookError";
20275
+ };
20276
+ var ValidationError = class extends Error {
20277
+ name = "ValidationError";
20278
+ };
20279
+
20280
+ // ../../../node_modules/@inquirer/core/dist/lib/use-state.js
20281
+ import { AsyncResource as AsyncResource2 } from "node:async_hooks";
20282
+
20283
+ // ../../../node_modules/@inquirer/core/dist/lib/hook-engine.js
20284
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
20285
+ var hookStorage = new AsyncLocalStorage();
20286
+ function createStore(rl) {
20287
+ const store = {
20288
+ rl,
20289
+ hooks: [],
20290
+ hooksCleanup: [],
20291
+ hooksEffect: [],
20292
+ index: 0,
20293
+ handleChange() {
20294
+ }
20295
+ };
20296
+ return store;
20297
+ }
20298
+ function withHooks(rl, cb) {
20299
+ const store = createStore(rl);
20300
+ return hookStorage.run(store, () => {
20301
+ function cycle(render) {
20302
+ store.handleChange = () => {
20303
+ store.index = 0;
20304
+ render();
20305
+ };
20306
+ store.handleChange();
20307
+ }
20308
+ return cb(cycle);
20309
+ });
20310
+ }
20311
+ function getStore() {
20312
+ const store = hookStorage.getStore();
20313
+ if (!store) {
20314
+ throw new HookError("[Inquirer] Hook functions can only be called from within a prompt");
20315
+ }
20316
+ return store;
20317
+ }
20318
+ function readline() {
20319
+ return getStore().rl;
20320
+ }
20321
+ function withUpdates(fn) {
20322
+ const wrapped = (...args) => {
20323
+ const store = getStore();
20324
+ let shouldUpdate = false;
20325
+ const oldHandleChange = store.handleChange;
20326
+ store.handleChange = () => {
20327
+ shouldUpdate = true;
20328
+ };
20329
+ const returnValue = fn(...args);
20330
+ if (shouldUpdate) {
20331
+ oldHandleChange();
20332
+ }
20333
+ store.handleChange = oldHandleChange;
20334
+ return returnValue;
20335
+ };
20336
+ return AsyncResource.bind(wrapped);
20337
+ }
20338
+ function withPointer(cb) {
20339
+ const store = getStore();
20340
+ const { index } = store;
20341
+ const pointer = {
20342
+ get() {
20343
+ return store.hooks[index];
20344
+ },
20345
+ set(value) {
20346
+ store.hooks[index] = value;
20347
+ },
20348
+ initialized: index in store.hooks
20349
+ };
20350
+ const returnValue = cb(pointer);
20351
+ store.index++;
20352
+ return returnValue;
20353
+ }
20354
+ function handleChange() {
20355
+ getStore().handleChange();
20356
+ }
20357
+ var effectScheduler = {
20358
+ queue(cb) {
20359
+ const store = getStore();
20360
+ const { index } = store;
20361
+ store.hooksEffect.push(() => {
20362
+ store.hooksCleanup[index]?.();
20363
+ const cleanFn = cb(readline());
20364
+ if (cleanFn != null && typeof cleanFn !== "function") {
20365
+ throw new ValidationError("useEffect return value must be a cleanup function or nothing.");
20366
+ }
20367
+ store.hooksCleanup[index] = cleanFn;
20368
+ });
20369
+ },
20370
+ run() {
20371
+ const store = getStore();
20372
+ withUpdates(() => {
20373
+ store.hooksEffect.forEach((effect) => {
20374
+ effect();
20375
+ });
20376
+ store.hooksEffect.length = 0;
20377
+ })();
20378
+ },
20379
+ clearAll() {
20380
+ const store = getStore();
20381
+ store.hooksCleanup.forEach((cleanFn) => {
20382
+ cleanFn?.();
20383
+ });
20384
+ store.hooksEffect.length = 0;
20385
+ store.hooksCleanup.length = 0;
20386
+ }
20387
+ };
20388
+
20389
+ // ../../../node_modules/@inquirer/core/dist/lib/use-state.js
20390
+ function isFactory(value) {
20391
+ return typeof value === "function";
20392
+ }
20393
+ function isReducer(value) {
20394
+ return typeof value === "function";
20395
+ }
20396
+ function useState(defaultValue) {
20397
+ return withPointer((pointer) => {
20398
+ const setState = AsyncResource2.bind(function setState2(newValue) {
20399
+ const currentValue = pointer.get();
20400
+ const nextValue = isReducer(newValue) ? newValue(currentValue) : newValue;
20401
+ if (!Object.is(currentValue, nextValue)) {
20402
+ pointer.set(nextValue);
20403
+ handleChange();
20404
+ }
20405
+ });
20406
+ if (pointer.initialized) {
20407
+ return [pointer.get(), setState];
20408
+ }
20409
+ const value = isFactory(defaultValue) ? defaultValue() : defaultValue;
20410
+ pointer.set(value);
20411
+ return [value, setState];
20412
+ });
20413
+ }
20414
+
20415
+ // ../../../node_modules/@inquirer/core/dist/lib/use-effect.js
20416
+ function useEffect(cb, depArray) {
20417
+ withPointer((pointer) => {
20418
+ const oldDeps = pointer.get();
20419
+ const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
20420
+ if (hasChanged) {
20421
+ effectScheduler.queue(cb);
20422
+ }
20423
+ pointer.set(depArray);
20424
+ });
20425
+ }
20426
+
20427
+ // ../../../node_modules/@inquirer/core/dist/lib/theme.js
20428
+ import { styleText } from "node:util";
20429
+
20430
+ // ../../../node_modules/@inquirer/figures/dist/index.js
20431
+ import process3 from "node:process";
20432
+ function isUnicodeSupported() {
20433
+ if (!process3.platform.startsWith("win")) {
20434
+ return process3.env["TERM"] !== "linux";
20435
+ }
20436
+ return Boolean(process3.env["CI"]) || // CI environments generally support unicode
20437
+ Boolean(process3.env["WT_SESSION"]) || // Windows Terminal
20438
+ Boolean(process3.env["TERMINUS_SUBLIME"]) || // Terminus (<0.2.27)
20439
+ process3.env["ConEmuTask"] === "{cmd::Cmder}" || // ConEmu and cmder
20440
+ process3.env["TERM_PROGRAM"] === "Terminus-Sublime" || process3.env["TERM_PROGRAM"] === "vscode" || process3.env["TERM"] === "xterm-256color" || process3.env["TERM"] === "alacritty" || process3.env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
20441
+ }
20442
+ var common = {
20443
+ circleQuestionMark: "(?)",
20444
+ questionMarkPrefix: "(?)",
20445
+ square: "\u2588",
20446
+ squareDarkShade: "\u2593",
20447
+ squareMediumShade: "\u2592",
20448
+ squareLightShade: "\u2591",
20449
+ squareTop: "\u2580",
20450
+ squareBottom: "\u2584",
20451
+ squareLeft: "\u258C",
20452
+ squareRight: "\u2590",
20453
+ squareCenter: "\u25A0",
20454
+ bullet: "\u25CF",
20455
+ dot: "\u2024",
20456
+ ellipsis: "\u2026",
20457
+ pointerSmall: "\u203A",
20458
+ triangleUp: "\u25B2",
20459
+ triangleUpSmall: "\u25B4",
20460
+ triangleDown: "\u25BC",
20461
+ triangleDownSmall: "\u25BE",
20462
+ triangleLeftSmall: "\u25C2",
20463
+ triangleRightSmall: "\u25B8",
20464
+ home: "\u2302",
20465
+ heart: "\u2665",
20466
+ musicNote: "\u266A",
20467
+ musicNoteBeamed: "\u266B",
20468
+ arrowUp: "\u2191",
20469
+ arrowDown: "\u2193",
20470
+ arrowLeft: "\u2190",
20471
+ arrowRight: "\u2192",
20472
+ arrowLeftRight: "\u2194",
20473
+ arrowUpDown: "\u2195",
20474
+ almostEqual: "\u2248",
20475
+ notEqual: "\u2260",
20476
+ lessOrEqual: "\u2264",
20477
+ greaterOrEqual: "\u2265",
20478
+ identical: "\u2261",
20479
+ infinity: "\u221E",
20480
+ subscriptZero: "\u2080",
20481
+ subscriptOne: "\u2081",
20482
+ subscriptTwo: "\u2082",
20483
+ subscriptThree: "\u2083",
20484
+ subscriptFour: "\u2084",
20485
+ subscriptFive: "\u2085",
20486
+ subscriptSix: "\u2086",
20487
+ subscriptSeven: "\u2087",
20488
+ subscriptEight: "\u2088",
20489
+ subscriptNine: "\u2089",
20490
+ oneHalf: "\xBD",
20491
+ oneThird: "\u2153",
20492
+ oneQuarter: "\xBC",
20493
+ oneFifth: "\u2155",
20494
+ oneSixth: "\u2159",
20495
+ oneEighth: "\u215B",
20496
+ twoThirds: "\u2154",
20497
+ twoFifths: "\u2156",
20498
+ threeQuarters: "\xBE",
20499
+ threeFifths: "\u2157",
20500
+ threeEighths: "\u215C",
20501
+ fourFifths: "\u2158",
20502
+ fiveSixths: "\u215A",
20503
+ fiveEighths: "\u215D",
20504
+ sevenEighths: "\u215E",
20505
+ line: "\u2500",
20506
+ lineBold: "\u2501",
20507
+ lineDouble: "\u2550",
20508
+ lineDashed0: "\u2504",
20509
+ lineDashed1: "\u2505",
20510
+ lineDashed2: "\u2508",
20511
+ lineDashed3: "\u2509",
20512
+ lineDashed4: "\u254C",
20513
+ lineDashed5: "\u254D",
20514
+ lineDashed6: "\u2574",
20515
+ lineDashed7: "\u2576",
20516
+ lineDashed8: "\u2578",
20517
+ lineDashed9: "\u257A",
20518
+ lineDashed10: "\u257C",
20519
+ lineDashed11: "\u257E",
20520
+ lineDashed12: "\u2212",
20521
+ lineDashed13: "\u2013",
20522
+ lineDashed14: "\u2010",
20523
+ lineDashed15: "\u2043",
20524
+ lineVertical: "\u2502",
20525
+ lineVerticalBold: "\u2503",
20526
+ lineVerticalDouble: "\u2551",
20527
+ lineVerticalDashed0: "\u2506",
20528
+ lineVerticalDashed1: "\u2507",
20529
+ lineVerticalDashed2: "\u250A",
20530
+ lineVerticalDashed3: "\u250B",
20531
+ lineVerticalDashed4: "\u254E",
20532
+ lineVerticalDashed5: "\u254F",
20533
+ lineVerticalDashed6: "\u2575",
20534
+ lineVerticalDashed7: "\u2577",
20535
+ lineVerticalDashed8: "\u2579",
20536
+ lineVerticalDashed9: "\u257B",
20537
+ lineVerticalDashed10: "\u257D",
20538
+ lineVerticalDashed11: "\u257F",
20539
+ lineDownLeft: "\u2510",
20540
+ lineDownLeftArc: "\u256E",
20541
+ lineDownBoldLeftBold: "\u2513",
20542
+ lineDownBoldLeft: "\u2512",
20543
+ lineDownLeftBold: "\u2511",
20544
+ lineDownDoubleLeftDouble: "\u2557",
20545
+ lineDownDoubleLeft: "\u2556",
20546
+ lineDownLeftDouble: "\u2555",
20547
+ lineDownRight: "\u250C",
20548
+ lineDownRightArc: "\u256D",
20549
+ lineDownBoldRightBold: "\u250F",
20550
+ lineDownBoldRight: "\u250E",
20551
+ lineDownRightBold: "\u250D",
20552
+ lineDownDoubleRightDouble: "\u2554",
20553
+ lineDownDoubleRight: "\u2553",
20554
+ lineDownRightDouble: "\u2552",
20555
+ lineUpLeft: "\u2518",
20556
+ lineUpLeftArc: "\u256F",
20557
+ lineUpBoldLeftBold: "\u251B",
20558
+ lineUpBoldLeft: "\u251A",
20559
+ lineUpLeftBold: "\u2519",
20560
+ lineUpDoubleLeftDouble: "\u255D",
20561
+ lineUpDoubleLeft: "\u255C",
20562
+ lineUpLeftDouble: "\u255B",
20563
+ lineUpRight: "\u2514",
20564
+ lineUpRightArc: "\u2570",
20565
+ lineUpBoldRightBold: "\u2517",
20566
+ lineUpBoldRight: "\u2516",
20567
+ lineUpRightBold: "\u2515",
20568
+ lineUpDoubleRightDouble: "\u255A",
20569
+ lineUpDoubleRight: "\u2559",
20570
+ lineUpRightDouble: "\u2558",
20571
+ lineUpDownLeft: "\u2524",
20572
+ lineUpBoldDownBoldLeftBold: "\u252B",
20573
+ lineUpBoldDownBoldLeft: "\u2528",
20574
+ lineUpDownLeftBold: "\u2525",
20575
+ lineUpBoldDownLeftBold: "\u2529",
20576
+ lineUpDownBoldLeftBold: "\u252A",
20577
+ lineUpDownBoldLeft: "\u2527",
20578
+ lineUpBoldDownLeft: "\u2526",
20579
+ lineUpDoubleDownDoubleLeftDouble: "\u2563",
20580
+ lineUpDoubleDownDoubleLeft: "\u2562",
20581
+ lineUpDownLeftDouble: "\u2561",
20582
+ lineUpDownRight: "\u251C",
20583
+ lineUpBoldDownBoldRightBold: "\u2523",
20584
+ lineUpBoldDownBoldRight: "\u2520",
20585
+ lineUpDownRightBold: "\u251D",
20586
+ lineUpBoldDownRightBold: "\u2521",
20587
+ lineUpDownBoldRightBold: "\u2522",
20588
+ lineUpDownBoldRight: "\u251F",
20589
+ lineUpBoldDownRight: "\u251E",
20590
+ lineUpDoubleDownDoubleRightDouble: "\u2560",
20591
+ lineUpDoubleDownDoubleRight: "\u255F",
20592
+ lineUpDownRightDouble: "\u255E",
20593
+ lineDownLeftRight: "\u252C",
20594
+ lineDownBoldLeftBoldRightBold: "\u2533",
20595
+ lineDownLeftBoldRightBold: "\u252F",
20596
+ lineDownBoldLeftRight: "\u2530",
20597
+ lineDownBoldLeftBoldRight: "\u2531",
20598
+ lineDownBoldLeftRightBold: "\u2532",
20599
+ lineDownLeftRightBold: "\u252E",
20600
+ lineDownLeftBoldRight: "\u252D",
20601
+ lineDownDoubleLeftDoubleRightDouble: "\u2566",
20602
+ lineDownDoubleLeftRight: "\u2565",
20603
+ lineDownLeftDoubleRightDouble: "\u2564",
20604
+ lineUpLeftRight: "\u2534",
20605
+ lineUpBoldLeftBoldRightBold: "\u253B",
20606
+ lineUpLeftBoldRightBold: "\u2537",
20607
+ lineUpBoldLeftRight: "\u2538",
20608
+ lineUpBoldLeftBoldRight: "\u2539",
20609
+ lineUpBoldLeftRightBold: "\u253A",
20610
+ lineUpLeftRightBold: "\u2536",
20611
+ lineUpLeftBoldRight: "\u2535",
20612
+ lineUpDoubleLeftDoubleRightDouble: "\u2569",
20613
+ lineUpDoubleLeftRight: "\u2568",
20614
+ lineUpLeftDoubleRightDouble: "\u2567",
20615
+ lineUpDownLeftRight: "\u253C",
20616
+ lineUpBoldDownBoldLeftBoldRightBold: "\u254B",
20617
+ lineUpDownBoldLeftBoldRightBold: "\u2548",
20618
+ lineUpBoldDownLeftBoldRightBold: "\u2547",
20619
+ lineUpBoldDownBoldLeftRightBold: "\u254A",
20620
+ lineUpBoldDownBoldLeftBoldRight: "\u2549",
20621
+ lineUpBoldDownLeftRight: "\u2540",
20622
+ lineUpDownBoldLeftRight: "\u2541",
20623
+ lineUpDownLeftBoldRight: "\u253D",
20624
+ lineUpDownLeftRightBold: "\u253E",
20625
+ lineUpBoldDownBoldLeftRight: "\u2542",
20626
+ lineUpDownLeftBoldRightBold: "\u253F",
20627
+ lineUpBoldDownLeftBoldRight: "\u2543",
20628
+ lineUpBoldDownLeftRightBold: "\u2544",
20629
+ lineUpDownBoldLeftBoldRight: "\u2545",
20630
+ lineUpDownBoldLeftRightBold: "\u2546",
20631
+ lineUpDoubleDownDoubleLeftDoubleRightDouble: "\u256C",
20632
+ lineUpDoubleDownDoubleLeftRight: "\u256B",
20633
+ lineUpDownLeftDoubleRightDouble: "\u256A",
20634
+ lineCross: "\u2573",
20635
+ lineBackslash: "\u2572",
20636
+ lineSlash: "\u2571"
20637
+ };
20638
+ var specialMainSymbols = {
20639
+ tick: "\u2714",
20640
+ info: "\u2139",
20641
+ warning: "\u26A0",
20642
+ cross: "\u2718",
20643
+ squareSmall: "\u25FB",
20644
+ squareSmallFilled: "\u25FC",
20645
+ circle: "\u25EF",
20646
+ circleFilled: "\u25C9",
20647
+ circleDotted: "\u25CC",
20648
+ circleDouble: "\u25CE",
20649
+ circleCircle: "\u24DE",
20650
+ circleCross: "\u24E7",
20651
+ circlePipe: "\u24BE",
20652
+ radioOn: "\u25C9",
20653
+ radioOff: "\u25EF",
20654
+ checkboxOn: "\u2612",
20655
+ checkboxOff: "\u2610",
20656
+ checkboxCircleOn: "\u24E7",
20657
+ checkboxCircleOff: "\u24BE",
20658
+ pointer: "\u276F",
20659
+ triangleUpOutline: "\u25B3",
20660
+ triangleLeft: "\u25C0",
20661
+ triangleRight: "\u25B6",
20662
+ lozenge: "\u25C6",
20663
+ lozengeOutline: "\u25C7",
20664
+ hamburger: "\u2630",
20665
+ smiley: "\u32E1",
20666
+ mustache: "\u0DF4",
20667
+ star: "\u2605",
20668
+ play: "\u25B6",
20669
+ nodejs: "\u2B22",
20670
+ oneSeventh: "\u2150",
20671
+ oneNinth: "\u2151",
20672
+ oneTenth: "\u2152"
20673
+ };
20674
+ var specialFallbackSymbols = {
20675
+ tick: "\u221A",
20676
+ info: "i",
20677
+ warning: "\u203C",
20678
+ cross: "\xD7",
20679
+ squareSmall: "\u25A1",
20680
+ squareSmallFilled: "\u25A0",
20681
+ circle: "( )",
20682
+ circleFilled: "(*)",
20683
+ circleDotted: "( )",
20684
+ circleDouble: "( )",
20685
+ circleCircle: "(\u25CB)",
20686
+ circleCross: "(\xD7)",
20687
+ circlePipe: "(\u2502)",
20688
+ radioOn: "(*)",
20689
+ radioOff: "( )",
20690
+ checkboxOn: "[\xD7]",
20691
+ checkboxOff: "[ ]",
20692
+ checkboxCircleOn: "(\xD7)",
20693
+ checkboxCircleOff: "( )",
20694
+ pointer: ">",
20695
+ triangleUpOutline: "\u2206",
20696
+ triangleLeft: "\u25C4",
20697
+ triangleRight: "\u25BA",
20698
+ lozenge: "\u2666",
20699
+ lozengeOutline: "\u25CA",
20700
+ hamburger: "\u2261",
20701
+ smiley: "\u263A",
20702
+ mustache: "\u250C\u2500\u2510",
20703
+ star: "\u2736",
20704
+ play: "\u25BA",
20705
+ nodejs: "\u2666",
20706
+ oneSeventh: "1/7",
20707
+ oneNinth: "1/9",
20708
+ oneTenth: "1/10"
20709
+ };
20710
+ var mainSymbols = {
20711
+ ...common,
20712
+ ...specialMainSymbols
20713
+ };
20714
+ var fallbackSymbols = {
20715
+ ...common,
20716
+ ...specialFallbackSymbols
20717
+ };
20718
+ var shouldUseMain = isUnicodeSupported();
20719
+ var figures = shouldUseMain ? mainSymbols : fallbackSymbols;
20720
+ var dist_default = figures;
20721
+ var replacements = Object.entries(specialMainSymbols);
20722
+
20723
+ // ../../../node_modules/@inquirer/core/dist/lib/theme.js
20724
+ var defaultTheme = {
20725
+ prefix: {
20726
+ idle: styleText("blue", "?"),
20727
+ done: styleText("green", dist_default.tick)
20728
+ },
20729
+ spinner: {
20730
+ interval: 80,
20731
+ frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"].map((frame) => styleText("yellow", frame))
20732
+ },
20733
+ keybindings: [],
20734
+ style: {
20735
+ answer: (text) => styleText("cyan", text),
20736
+ message: (text) => styleText("bold", text),
20737
+ error: (text) => styleText("red", `> ${text}`),
20738
+ defaultAnswer: (text) => styleText("dim", `(${text})`),
20739
+ help: (text) => styleText("dim", text),
20740
+ highlight: (text) => styleText("cyan", text),
20741
+ key: (text) => styleText("cyan", styleText("bold", `<${text}>`))
20742
+ }
20743
+ };
20744
+ function getDefaultTheme() {
20745
+ return {
20746
+ ...defaultTheme,
20747
+ keybindings: getDefaultKeybindings()
20748
+ };
20749
+ }
20750
+
20751
+ // ../../../node_modules/@inquirer/core/dist/lib/make-theme.js
20752
+ function isPlainObject2(value) {
20753
+ if (typeof value !== "object" || value === null)
20754
+ return false;
20755
+ let proto = value;
20756
+ while (Object.getPrototypeOf(proto) !== null) {
20757
+ proto = Object.getPrototypeOf(proto);
20758
+ }
20759
+ return Object.getPrototypeOf(value) === proto;
20760
+ }
20761
+ function deepMerge(...objects) {
20762
+ const output = {};
20763
+ for (const obj of objects) {
20764
+ for (const [key, value] of Object.entries(obj)) {
20765
+ const prevValue = output[key];
20766
+ output[key] = isPlainObject2(prevValue) && isPlainObject2(value) ? deepMerge(prevValue, value) : value;
20767
+ }
20768
+ }
20769
+ return output;
20770
+ }
20771
+ function makeTheme(...themes) {
20772
+ const themesToMerge = [
20773
+ getDefaultTheme(),
20774
+ ...themes.filter((theme) => theme != null)
20775
+ ];
20776
+ return deepMerge(...themesToMerge);
20777
+ }
20778
+
20779
+ // ../../../node_modules/@inquirer/core/dist/lib/use-prefix.js
20780
+ function usePrefix({ status = "idle", theme }) {
20781
+ const [showLoader, setShowLoader] = useState(false);
20782
+ const [tick, setTick] = useState(0);
20783
+ const { prefix, spinner } = makeTheme(theme);
20784
+ useEffect(() => {
20785
+ if (status === "loading") {
20786
+ let tickInterval;
20787
+ let inc = -1;
20788
+ const delayTimeout = setTimeout(() => {
20789
+ setShowLoader(true);
20790
+ tickInterval = setInterval(() => {
20791
+ inc = inc + 1;
20792
+ setTick(inc % spinner.frames.length);
20793
+ }, spinner.interval);
20794
+ }, 300);
20795
+ return () => {
20796
+ clearTimeout(delayTimeout);
20797
+ clearInterval(tickInterval);
20798
+ };
20799
+ } else {
20800
+ setShowLoader(false);
20801
+ }
20802
+ }, [status]);
20803
+ if (showLoader) {
20804
+ return spinner.frames[tick];
20805
+ }
20806
+ const iconName = status === "loading" ? "idle" : status;
20807
+ return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
20808
+ }
20809
+
20810
+ // ../../../node_modules/@inquirer/core/dist/lib/use-memo.js
20811
+ function useMemo(fn, dependencies) {
20812
+ return withPointer((pointer) => {
20813
+ const prev = pointer.get();
20814
+ if (!pointer.initialized || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
20815
+ const value = fn();
20816
+ pointer.set({ value, dependencies });
20817
+ return value;
20818
+ }
20819
+ return prev.value;
20820
+ });
20821
+ }
20822
+
20823
+ // ../../../node_modules/@inquirer/core/dist/lib/use-ref.js
20824
+ function useRef(val) {
20825
+ return useState({ current: val })[0];
20826
+ }
20827
+
20828
+ // ../../../node_modules/@inquirer/core/dist/lib/use-keypress.js
20829
+ function useKeypress(userHandler) {
20830
+ const signal = useRef(userHandler);
20831
+ signal.current = userHandler;
20832
+ useEffect((rl) => {
20833
+ let ignore = false;
20834
+ const handler = withUpdates((_input, event) => {
20835
+ if (ignore)
20836
+ return;
20837
+ void signal.current(event, rl);
20838
+ });
20839
+ rl.input.on("keypress", handler);
20840
+ return () => {
20841
+ ignore = true;
20842
+ rl.input.removeListener("keypress", handler);
20843
+ };
20844
+ }, []);
20845
+ }
20846
+
20847
+ // ../../../node_modules/@inquirer/core/dist/lib/utils.js
20848
+ var import_cli_width = __toESM(require_cli_width(), 1);
20849
+
20850
+ // ../../../node_modules/fast-string-truncated-width/dist/utils.js
20851
+ var getCodePointsLength = /* @__PURE__ */ (() => {
20852
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
20853
+ return (input) => {
20854
+ let surrogatePairsNr = 0;
20855
+ SURROGATE_PAIR_RE.lastIndex = 0;
20856
+ while (SURROGATE_PAIR_RE.test(input)) {
20857
+ surrogatePairsNr += 1;
20858
+ }
20859
+ return input.length - surrogatePairsNr;
20860
+ };
20861
+ })();
20862
+ var isFullWidth = (x) => {
20863
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
20864
+ };
20865
+ var isWideNotCJKTNotEmoji = (x) => {
20866
+ return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
20867
+ };
20868
+
20869
+ // ../../../node_modules/fast-string-truncated-width/dist/index.js
20870
+ var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
20871
+ var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
20872
+ var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
20873
+ var TAB_RE = /\t{1,1000}/y;
20874
+ var EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
20875
+ var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
20876
+ var MODIFIER_RE = /\p{M}+/gu;
20877
+ var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
20878
+ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
20879
+ const LIMIT = truncationOptions.limit ?? Infinity;
20880
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
20881
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
20882
+ const ANSI_WIDTH = 0;
20883
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
20884
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
20885
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
20886
+ const FULL_WIDTH_WIDTH = 2;
20887
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
20888
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
20889
+ const PARSE_BLOCKS = [
20890
+ [LATIN_RE, REGULAR_WIDTH],
20891
+ [ANSI_RE, ANSI_WIDTH],
20892
+ [CONTROL_RE, CONTROL_WIDTH],
20893
+ [TAB_RE, TAB_WIDTH],
20894
+ [EMOJI_RE, EMOJI_WIDTH],
20895
+ [CJKT_WIDE_RE, WIDE_WIDTH]
20896
+ ];
20897
+ let indexPrev = 0;
20898
+ let index = 0;
20899
+ let length = input.length;
20900
+ let lengthExtra = 0;
20901
+ let truncationEnabled = false;
20902
+ let truncationIndex = length;
20903
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
20904
+ let unmatchedStart = 0;
20905
+ let unmatchedEnd = 0;
20906
+ let width = 0;
20907
+ let widthExtra = 0;
20908
+ outer: while (true) {
20909
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
20910
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
20911
+ lengthExtra = 0;
20912
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
20913
+ const codePoint = char.codePointAt(0) || 0;
20914
+ if (isFullWidth(codePoint)) {
20915
+ widthExtra = FULL_WIDTH_WIDTH;
20916
+ } else if (isWideNotCJKTNotEmoji(codePoint)) {
20917
+ widthExtra = WIDE_WIDTH;
20918
+ } else {
20919
+ widthExtra = REGULAR_WIDTH;
20920
+ }
20921
+ if (width + widthExtra > truncationLimit) {
20922
+ truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
20923
+ }
20924
+ if (width + widthExtra > LIMIT) {
20925
+ truncationEnabled = true;
20926
+ break outer;
20927
+ }
20928
+ lengthExtra += char.length;
20929
+ width += widthExtra;
20930
+ }
20931
+ unmatchedStart = unmatchedEnd = 0;
20932
+ }
20933
+ if (index >= length) {
20934
+ break outer;
20935
+ }
20936
+ for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
20937
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
20938
+ BLOCK_RE.lastIndex = index;
20939
+ if (BLOCK_RE.test(input)) {
20940
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
20941
+ widthExtra = lengthExtra * BLOCK_WIDTH;
20942
+ if (width + widthExtra > truncationLimit) {
20943
+ truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
20944
+ }
20945
+ if (width + widthExtra > LIMIT) {
20946
+ truncationEnabled = true;
20947
+ break outer;
20948
+ }
20949
+ width += widthExtra;
20950
+ unmatchedStart = indexPrev;
20951
+ unmatchedEnd = index;
20952
+ index = indexPrev = BLOCK_RE.lastIndex;
20953
+ continue outer;
20954
+ }
20955
+ }
20956
+ index += 1;
20957
+ }
20958
+ return {
20959
+ width: truncationEnabled ? truncationLimit : width,
20960
+ index: truncationEnabled ? truncationIndex : length,
20961
+ truncated: truncationEnabled,
20962
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
20963
+ };
20964
+ };
20965
+ var dist_default2 = getStringTruncatedWidth;
20966
+
20967
+ // ../../../node_modules/fast-string-width/dist/index.js
20968
+ var NO_TRUNCATION2 = {
20969
+ limit: Infinity,
20970
+ ellipsis: "",
20971
+ ellipsisWidth: 0
20972
+ };
20973
+ var fastStringWidth = (input, options = {}) => {
20974
+ return dist_default2(input, NO_TRUNCATION2, options).width;
20975
+ };
20976
+ var dist_default3 = fastStringWidth;
20977
+
20978
+ // ../../../node_modules/fast-wrap-ansi/lib/main.js
20979
+ var ESC = "\x1B";
20980
+ var CSI = "\x9B";
20981
+ var END_CODE = 39;
20982
+ var ANSI_ESCAPE_BELL = "\x07";
20983
+ var ANSI_CSI = "[";
20984
+ var ANSI_OSC = "]";
20985
+ var ANSI_SGR_TERMINATOR = "m";
20986
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
20987
+ var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
20988
+ var getClosingCode = (openingCode) => {
20989
+ if (openingCode >= 30 && openingCode <= 37)
20990
+ return 39;
20991
+ if (openingCode >= 90 && openingCode <= 97)
20992
+ return 39;
20993
+ if (openingCode >= 40 && openingCode <= 47)
20994
+ return 49;
20995
+ if (openingCode >= 100 && openingCode <= 107)
20996
+ return 49;
20997
+ if (openingCode === 1 || openingCode === 2)
20998
+ return 22;
20999
+ if (openingCode === 3)
21000
+ return 23;
21001
+ if (openingCode === 4)
21002
+ return 24;
21003
+ if (openingCode === 7)
21004
+ return 27;
21005
+ if (openingCode === 8)
21006
+ return 28;
21007
+ if (openingCode === 9)
21008
+ return 29;
21009
+ if (openingCode === 0)
21010
+ return 0;
21011
+ return void 0;
21012
+ };
21013
+ var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
21014
+ var wrapAnsiHyperlink = (url2) => `${ESC}${ANSI_ESCAPE_LINK}${url2}${ANSI_ESCAPE_BELL}`;
21015
+ var wrapWord = (rows, word, columns) => {
21016
+ const characters = word[Symbol.iterator]();
21017
+ let isInsideEscape = false;
21018
+ let isInsideLinkEscape = false;
21019
+ let lastRow = rows.at(-1);
21020
+ let visible = lastRow === void 0 ? 0 : dist_default3(lastRow);
21021
+ let currentCharacter = characters.next();
21022
+ let nextCharacter = characters.next();
21023
+ let rawCharacterIndex = 0;
21024
+ while (!currentCharacter.done) {
21025
+ const character = currentCharacter.value;
21026
+ const characterLength = dist_default3(character);
21027
+ if (visible + characterLength <= columns) {
21028
+ rows[rows.length - 1] += character;
21029
+ } else {
21030
+ rows.push(character);
21031
+ visible = 0;
21032
+ }
21033
+ if (character === ESC || character === CSI) {
21034
+ isInsideEscape = true;
21035
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
21036
+ }
21037
+ if (isInsideEscape) {
21038
+ if (isInsideLinkEscape) {
21039
+ if (character === ANSI_ESCAPE_BELL) {
21040
+ isInsideEscape = false;
21041
+ isInsideLinkEscape = false;
21042
+ }
21043
+ } else if (character === ANSI_SGR_TERMINATOR) {
21044
+ isInsideEscape = false;
21045
+ }
21046
+ } else {
21047
+ visible += characterLength;
21048
+ if (visible === columns && !nextCharacter.done) {
21049
+ rows.push("");
21050
+ visible = 0;
21051
+ }
21052
+ }
21053
+ currentCharacter = nextCharacter;
21054
+ nextCharacter = characters.next();
21055
+ rawCharacterIndex += character.length;
21056
+ }
21057
+ lastRow = rows.at(-1);
21058
+ if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) {
21059
+ rows[rows.length - 2] += rows.pop();
21060
+ }
21061
+ };
21062
+ var stringVisibleTrimSpacesRight = (string4) => {
21063
+ const words = string4.split(" ");
21064
+ let last = words.length;
21065
+ while (last) {
21066
+ if (dist_default3(words[last - 1])) {
21067
+ break;
21068
+ }
21069
+ last--;
21070
+ }
21071
+ if (last === words.length) {
21072
+ return string4;
21073
+ }
21074
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
21075
+ };
21076
+ var exec = (string4, columns, options = {}) => {
21077
+ if (options.trim !== false && string4.trim() === "") {
21078
+ return "";
21079
+ }
21080
+ let returnValue = "";
21081
+ let escapeCode;
21082
+ let escapeUrl;
21083
+ const words = string4.split(" ");
21084
+ let rows = [""];
21085
+ let rowLength = 0;
21086
+ for (let index = 0; index < words.length; index++) {
21087
+ const word = words[index];
21088
+ if (options.trim !== false) {
21089
+ const row = rows.at(-1) ?? "";
21090
+ const trimmed = row.trimStart();
21091
+ if (row.length !== trimmed.length) {
21092
+ rows[rows.length - 1] = trimmed;
21093
+ rowLength = dist_default3(trimmed);
21094
+ }
21095
+ }
21096
+ if (index !== 0) {
21097
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
21098
+ rows.push("");
21099
+ rowLength = 0;
21100
+ }
21101
+ if (rowLength || options.trim === false) {
21102
+ rows[rows.length - 1] += " ";
21103
+ rowLength++;
21104
+ }
21105
+ }
21106
+ const wordLength = dist_default3(word);
21107
+ if (options.hard && wordLength > columns) {
21108
+ const remainingColumns = columns - rowLength;
21109
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
21110
+ const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
21111
+ if (breaksStartingNextLine < breaksStartingThisLine) {
21112
+ rows.push("");
21113
+ }
21114
+ wrapWord(rows, word, columns);
21115
+ rowLength = dist_default3(rows.at(-1) ?? "");
21116
+ continue;
21117
+ }
21118
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
21119
+ if (options.wordWrap === false && rowLength < columns) {
21120
+ wrapWord(rows, word, columns);
21121
+ rowLength = dist_default3(rows.at(-1) ?? "");
21122
+ continue;
21123
+ }
21124
+ rows.push("");
21125
+ rowLength = 0;
21126
+ }
21127
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
21128
+ wrapWord(rows, word, columns);
21129
+ rowLength = dist_default3(rows.at(-1) ?? "");
21130
+ continue;
21131
+ }
21132
+ rows[rows.length - 1] += word;
21133
+ rowLength += wordLength;
21134
+ }
21135
+ if (options.trim !== false) {
21136
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
21137
+ }
21138
+ const preString = rows.join("\n");
21139
+ let inSurrogate = false;
21140
+ for (let i = 0; i < preString.length; i++) {
21141
+ const character = preString[i];
21142
+ returnValue += character;
21143
+ if (!inSurrogate) {
21144
+ inSurrogate = character >= "\uD800" && character <= "\uDBFF";
21145
+ if (inSurrogate) {
21146
+ continue;
21147
+ }
21148
+ } else {
21149
+ inSurrogate = false;
21150
+ }
21151
+ if (character === ESC || character === CSI) {
21152
+ GROUP_REGEX.lastIndex = i + 1;
21153
+ const groupsResult = GROUP_REGEX.exec(preString);
21154
+ const groups = groupsResult?.groups;
21155
+ if (groups?.code !== void 0) {
21156
+ const code = Number.parseFloat(groups.code);
21157
+ escapeCode = code === END_CODE ? void 0 : code;
21158
+ } else if (groups?.uri !== void 0) {
21159
+ escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
21160
+ }
21161
+ }
21162
+ if (preString[i + 1] === "\n") {
21163
+ if (escapeUrl) {
21164
+ returnValue += wrapAnsiHyperlink("");
21165
+ }
21166
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
21167
+ if (escapeCode && closingCode) {
21168
+ returnValue += wrapAnsiCode(closingCode);
21169
+ }
21170
+ } else if (character === "\n") {
21171
+ if (escapeCode && getClosingCode(escapeCode)) {
21172
+ returnValue += wrapAnsiCode(escapeCode);
21173
+ }
21174
+ if (escapeUrl) {
21175
+ returnValue += wrapAnsiHyperlink(escapeUrl);
21176
+ }
21177
+ }
21178
+ }
21179
+ return returnValue;
21180
+ };
21181
+ var CRLF_OR_LF = /\r?\n/;
21182
+ function wrapAnsi(string4, columns, options) {
21183
+ return String(string4).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
21184
+ }
21185
+
21186
+ // ../../../node_modules/@inquirer/core/dist/lib/utils.js
21187
+ function breakLines(content, width) {
21188
+ return content.split("\n").flatMap((line) => wrapAnsi(line, width, { trim: false, wordWrap: false }).split("\n").map((str) => str.trimEnd())).join("\n");
21189
+ }
21190
+ function readlineWidth() {
21191
+ return (0, import_cli_width.default)({ defaultWidth: 80, output: readline().output });
21192
+ }
21193
+
21194
+ // ../../../node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js
21195
+ function usePointerPosition({ active, renderedItems, pageSize, loop }) {
21196
+ const state = useRef({
21197
+ lastPointer: active,
21198
+ lastActive: void 0
21199
+ });
21200
+ const { lastPointer, lastActive } = state.current;
21201
+ const middle = Math.floor(pageSize / 2);
21202
+ const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
21203
+ const defaultPointerPosition = renderedItems.slice(0, active).reduce((acc, item) => acc + item.length, 0);
21204
+ let pointer = defaultPointerPosition;
21205
+ if (renderedLength > pageSize) {
21206
+ if (loop) {
21207
+ pointer = lastPointer;
21208
+ if (
21209
+ // First render, skip this logic.
21210
+ lastActive != null && // Only move the pointer down when the user moves down.
21211
+ lastActive < active && // Check user didn't move up across page boundary.
21212
+ active - lastActive < pageSize
21213
+ ) {
21214
+ pointer = Math.min(
21215
+ // Furthest allowed position for the pointer is the middle of the list
21216
+ middle,
21217
+ Math.abs(active - lastActive) === 1 ? Math.min(
21218
+ // Move the pointer at most the height of the last active item.
21219
+ lastPointer + (renderedItems[lastActive]?.length ?? 0),
21220
+ // If the user moved by one item, move the pointer to the natural position of the active item as
21221
+ // long as it doesn't move the cursor up.
21222
+ Math.max(defaultPointerPosition, lastPointer)
21223
+ ) : (
21224
+ // Otherwise, move the pointer down by the difference between the active and last active item.
21225
+ lastPointer + active - lastActive
21226
+ )
21227
+ );
21228
+ }
21229
+ } else {
21230
+ const spaceUnderActive = renderedItems.slice(active).reduce((acc, item) => acc + item.length, 0);
21231
+ pointer = spaceUnderActive < pageSize - middle ? (
21232
+ // If the active item is near the end of the list, progressively move the cursor towards the end.
21233
+ pageSize - spaceUnderActive
21234
+ ) : (
21235
+ // Otherwise, progressively move the pointer to the middle of the list.
21236
+ Math.min(defaultPointerPosition, middle)
21237
+ );
21238
+ }
21239
+ }
21240
+ state.current.lastPointer = pointer;
21241
+ state.current.lastActive = active;
21242
+ return pointer;
21243
+ }
21244
+ function usePagination({ items, active, renderItem, pageSize, loop = true }) {
21245
+ const width = readlineWidth();
21246
+ const bound = (num) => (num % items.length + items.length) % items.length;
21247
+ const renderedItems = items.map((item, index) => {
21248
+ if (item == null)
21249
+ return [];
21250
+ return breakLines(renderItem({ item, index, isActive: index === active }), width).split("\n");
21251
+ });
21252
+ const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
21253
+ const renderItemAtIndex = (index) => renderedItems[index] ?? [];
21254
+ const pointer = usePointerPosition({ active, renderedItems, pageSize, loop });
21255
+ const activeItem = renderItemAtIndex(active).slice(0, pageSize);
21256
+ const activeItemPosition = pointer + activeItem.length <= pageSize ? pointer : pageSize - activeItem.length;
21257
+ const pageBuffer = Array.from({ length: pageSize });
21258
+ pageBuffer.splice(activeItemPosition, activeItem.length, ...activeItem);
21259
+ const itemVisited = /* @__PURE__ */ new Set([active]);
21260
+ let bufferPointer = activeItemPosition + activeItem.length;
21261
+ let itemPointer = bound(active + 1);
21262
+ while (bufferPointer < pageSize && !itemVisited.has(itemPointer) && (loop && renderedLength > pageSize ? itemPointer !== active : itemPointer > active)) {
21263
+ const lines = renderItemAtIndex(itemPointer);
21264
+ const linesToAdd = lines.slice(0, pageSize - bufferPointer);
21265
+ pageBuffer.splice(bufferPointer, linesToAdd.length, ...linesToAdd);
21266
+ itemVisited.add(itemPointer);
21267
+ bufferPointer += linesToAdd.length;
21268
+ itemPointer = bound(itemPointer + 1);
21269
+ }
21270
+ bufferPointer = activeItemPosition - 1;
21271
+ itemPointer = bound(active - 1);
21272
+ while (bufferPointer >= 0 && !itemVisited.has(itemPointer) && (loop && renderedLength > pageSize ? itemPointer !== active : itemPointer < active)) {
21273
+ const lines = renderItemAtIndex(itemPointer);
21274
+ const linesToAdd = lines.slice(Math.max(0, lines.length - bufferPointer - 1));
21275
+ pageBuffer.splice(bufferPointer - linesToAdd.length + 1, linesToAdd.length, ...linesToAdd);
21276
+ itemVisited.add(itemPointer);
21277
+ bufferPointer -= linesToAdd.length;
21278
+ itemPointer = bound(itemPointer - 1);
21279
+ }
21280
+ return pageBuffer.filter((line) => typeof line === "string").join("\n");
21281
+ }
21282
+
21283
+ // ../../../node_modules/@inquirer/core/dist/lib/create-prompt.js
21284
+ var import_mute_stream = __toESM(require_lib(), 1);
21285
+ import * as readline2 from "node:readline";
21286
+ import { AsyncResource as AsyncResource3 } from "node:async_hooks";
21287
+
21288
+ // ../../../node_modules/signal-exit/dist/mjs/signals.js
21289
+ var signals = [];
21290
+ signals.push("SIGHUP", "SIGINT", "SIGTERM");
21291
+ if (process.platform !== "win32") {
21292
+ signals.push(
21293
+ "SIGALRM",
21294
+ "SIGABRT",
21295
+ "SIGVTALRM",
21296
+ "SIGXCPU",
21297
+ "SIGXFSZ",
21298
+ "SIGUSR2",
21299
+ "SIGTRAP",
21300
+ "SIGSYS",
21301
+ "SIGQUIT",
21302
+ "SIGIOT"
21303
+ // should detect profiler and enable/disable accordingly.
21304
+ // see #21
21305
+ // 'SIGPROF'
21306
+ );
21307
+ }
21308
+ if (process.platform === "linux") {
21309
+ signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
21310
+ }
21311
+
21312
+ // ../../../node_modules/signal-exit/dist/mjs/index.js
21313
+ var processOk = (process5) => !!process5 && typeof process5 === "object" && typeof process5.removeListener === "function" && typeof process5.emit === "function" && typeof process5.reallyExit === "function" && typeof process5.listeners === "function" && typeof process5.kill === "function" && typeof process5.pid === "number" && typeof process5.on === "function";
21314
+ var kExitEmitter = /* @__PURE__ */ Symbol.for("signal-exit emitter");
21315
+ var global = globalThis;
21316
+ var ObjectDefineProperty = Object.defineProperty.bind(Object);
21317
+ var Emitter = class {
21318
+ emitted = {
21319
+ afterExit: false,
21320
+ exit: false
21321
+ };
21322
+ listeners = {
21323
+ afterExit: [],
21324
+ exit: []
21325
+ };
21326
+ count = 0;
21327
+ id = Math.random();
21328
+ constructor() {
21329
+ if (global[kExitEmitter]) {
21330
+ return global[kExitEmitter];
21331
+ }
21332
+ ObjectDefineProperty(global, kExitEmitter, {
21333
+ value: this,
21334
+ writable: false,
21335
+ enumerable: false,
21336
+ configurable: false
21337
+ });
21338
+ }
21339
+ on(ev, fn) {
21340
+ this.listeners[ev].push(fn);
21341
+ }
21342
+ removeListener(ev, fn) {
21343
+ const list = this.listeners[ev];
21344
+ const i = list.indexOf(fn);
21345
+ if (i === -1) {
21346
+ return;
21347
+ }
21348
+ if (i === 0 && list.length === 1) {
21349
+ list.length = 0;
21350
+ } else {
21351
+ list.splice(i, 1);
21352
+ }
21353
+ }
21354
+ emit(ev, code, signal) {
21355
+ if (this.emitted[ev]) {
21356
+ return false;
21357
+ }
21358
+ this.emitted[ev] = true;
21359
+ let ret = false;
21360
+ for (const fn of this.listeners[ev]) {
21361
+ ret = fn(code, signal) === true || ret;
21362
+ }
21363
+ if (ev === "exit") {
21364
+ ret = this.emit("afterExit", code, signal) || ret;
21365
+ }
21366
+ return ret;
21367
+ }
21368
+ };
21369
+ var SignalExitBase = class {
21370
+ };
21371
+ var signalExitWrap = (handler) => {
21372
+ return {
21373
+ onExit(cb, opts) {
21374
+ return handler.onExit(cb, opts);
21375
+ },
21376
+ load() {
21377
+ return handler.load();
21378
+ },
21379
+ unload() {
21380
+ return handler.unload();
21381
+ }
21382
+ };
21383
+ };
21384
+ var SignalExitFallback = class extends SignalExitBase {
21385
+ onExit() {
21386
+ return () => {
21387
+ };
21388
+ }
21389
+ load() {
21390
+ }
21391
+ unload() {
21392
+ }
21393
+ };
21394
+ var SignalExit = class extends SignalExitBase {
21395
+ // "SIGHUP" throws an `ENOSYS` error on Windows,
21396
+ // so use a supported signal instead
21397
+ /* c8 ignore start */
21398
+ #hupSig = process4.platform === "win32" ? "SIGINT" : "SIGHUP";
21399
+ /* c8 ignore stop */
21400
+ #emitter = new Emitter();
21401
+ #process;
21402
+ #originalProcessEmit;
21403
+ #originalProcessReallyExit;
21404
+ #sigListeners = {};
21405
+ #loaded = false;
21406
+ constructor(process5) {
21407
+ super();
21408
+ this.#process = process5;
21409
+ this.#sigListeners = {};
21410
+ for (const sig of signals) {
21411
+ this.#sigListeners[sig] = () => {
21412
+ const listeners = this.#process.listeners(sig);
21413
+ let { count } = this.#emitter;
21414
+ const p = process5;
21415
+ if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
21416
+ count += p.__signal_exit_emitter__.count;
21417
+ }
21418
+ if (listeners.length === count) {
21419
+ this.unload();
21420
+ const ret = this.#emitter.emit("exit", null, sig);
21421
+ const s = sig === "SIGHUP" ? this.#hupSig : sig;
21422
+ if (!ret)
21423
+ process5.kill(process5.pid, s);
21424
+ }
21425
+ };
21426
+ }
21427
+ this.#originalProcessReallyExit = process5.reallyExit;
21428
+ this.#originalProcessEmit = process5.emit;
21429
+ }
21430
+ onExit(cb, opts) {
21431
+ if (!processOk(this.#process)) {
21432
+ return () => {
21433
+ };
21434
+ }
21435
+ if (this.#loaded === false) {
21436
+ this.load();
21437
+ }
21438
+ const ev = opts?.alwaysLast ? "afterExit" : "exit";
21439
+ this.#emitter.on(ev, cb);
21440
+ return () => {
21441
+ this.#emitter.removeListener(ev, cb);
21442
+ if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
21443
+ this.unload();
21444
+ }
21445
+ };
21446
+ }
21447
+ load() {
21448
+ if (this.#loaded) {
21449
+ return;
21450
+ }
21451
+ this.#loaded = true;
21452
+ this.#emitter.count += 1;
21453
+ for (const sig of signals) {
21454
+ try {
21455
+ const fn = this.#sigListeners[sig];
21456
+ if (fn)
21457
+ this.#process.on(sig, fn);
21458
+ } catch (_) {
21459
+ }
21460
+ }
21461
+ this.#process.emit = (ev, ...a) => {
21462
+ return this.#processEmit(ev, ...a);
21463
+ };
21464
+ this.#process.reallyExit = (code) => {
21465
+ return this.#processReallyExit(code);
21466
+ };
21467
+ }
21468
+ unload() {
21469
+ if (!this.#loaded) {
21470
+ return;
21471
+ }
21472
+ this.#loaded = false;
21473
+ signals.forEach((sig) => {
21474
+ const listener = this.#sigListeners[sig];
21475
+ if (!listener) {
21476
+ throw new Error("Listener not defined for signal: " + sig);
21477
+ }
21478
+ try {
21479
+ this.#process.removeListener(sig, listener);
21480
+ } catch (_) {
21481
+ }
21482
+ });
21483
+ this.#process.emit = this.#originalProcessEmit;
21484
+ this.#process.reallyExit = this.#originalProcessReallyExit;
21485
+ this.#emitter.count -= 1;
21486
+ }
21487
+ #processReallyExit(code) {
21488
+ if (!processOk(this.#process)) {
21489
+ return 0;
21490
+ }
21491
+ this.#process.exitCode = code || 0;
21492
+ this.#emitter.emit("exit", this.#process.exitCode, null);
21493
+ return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
21494
+ }
21495
+ #processEmit(ev, ...args) {
21496
+ const og = this.#originalProcessEmit;
21497
+ if (ev === "exit" && processOk(this.#process)) {
21498
+ if (typeof args[0] === "number") {
21499
+ this.#process.exitCode = args[0];
21500
+ }
21501
+ const ret = og.call(this.#process, ev, ...args);
21502
+ this.#emitter.emit("exit", this.#process.exitCode, null);
21503
+ return ret;
21504
+ } else {
21505
+ return og.call(this.#process, ev, ...args);
21506
+ }
21507
+ }
21508
+ };
21509
+ var process4 = globalThis.process;
21510
+ var {
21511
+ /**
21512
+ * Called when the process is exiting, whether via signal, explicit
21513
+ * exit, or running out of stuff to do.
21514
+ *
21515
+ * If the global process object is not suitable for instrumentation,
21516
+ * then this will be a no-op.
21517
+ *
21518
+ * Returns a function that may be used to unload signal-exit.
21519
+ */
21520
+ onExit,
21521
+ /**
21522
+ * Load the listeners. Likely you never need to call this, unless
21523
+ * doing a rather deep integration with signal-exit functionality.
21524
+ * Mostly exposed for the benefit of testing.
21525
+ *
21526
+ * @internal
21527
+ */
21528
+ load,
21529
+ /**
21530
+ * Unload the listeners. Likely you never need to call this, unless
21531
+ * doing a rather deep integration with signal-exit functionality.
21532
+ * Mostly exposed for the benefit of testing.
21533
+ *
21534
+ * @internal
21535
+ */
21536
+ unload
21537
+ } = signalExitWrap(processOk(process4) ? new SignalExit(process4) : new SignalExitFallback());
21538
+
21539
+ // ../../../node_modules/@inquirer/core/dist/lib/screen-manager.js
21540
+ import { stripVTControlCharacters } from "node:util";
21541
+
21542
+ // ../../../node_modules/@inquirer/ansi/dist/index.js
21543
+ var ESC2 = "\x1B[";
21544
+ var cursorLeft = ESC2 + "G";
21545
+ var cursorHide = ESC2 + "?25l";
21546
+ var cursorShow = ESC2 + "?25h";
21547
+ var cursorUp = (rows = 1) => rows > 0 ? `${ESC2}${rows}A` : "";
21548
+ var cursorDown = (rows = 1) => rows > 0 ? `${ESC2}${rows}B` : "";
21549
+ var cursorTo = (x, y) => {
21550
+ if (typeof y === "number" && !Number.isNaN(y)) {
21551
+ return `${ESC2}${y + 1};${x + 1}H`;
21552
+ }
21553
+ return `${ESC2}${x + 1}G`;
21554
+ };
21555
+ var eraseLine = ESC2 + "2K";
21556
+ var eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + eraseLine + cursorLeft : "";
21557
+
21558
+ // ../../../node_modules/@inquirer/core/dist/lib/screen-manager.js
21559
+ var height = (content) => content.split("\n").length;
21560
+ var lastLine = (content) => content.split("\n").pop() ?? "";
21561
+ var ScreenManager = class {
21562
+ // These variables are keeping information to allow correct prompt re-rendering
21563
+ height = 0;
21564
+ extraLinesUnderPrompt = 0;
21565
+ cursorPos;
21566
+ rl;
21567
+ constructor(rl) {
21568
+ this.rl = rl;
21569
+ this.cursorPos = rl.getCursorPos();
21570
+ }
21571
+ write(content) {
21572
+ this.rl.output.unmute();
21573
+ this.rl.output.write(content);
21574
+ this.rl.output.mute();
21575
+ }
21576
+ render(content, bottomContent = "") {
21577
+ const promptLine = lastLine(content);
21578
+ const rawPromptLine = stripVTControlCharacters(promptLine);
21579
+ let prompt = rawPromptLine;
21580
+ if (this.rl.line.length > 0) {
21581
+ prompt = prompt.slice(0, -this.rl.line.length);
21582
+ }
21583
+ this.rl.setPrompt(prompt);
21584
+ this.cursorPos = this.rl.getCursorPos();
21585
+ const width = readlineWidth();
21586
+ content = breakLines(content, width);
21587
+ bottomContent = breakLines(bottomContent, width);
21588
+ if (rawPromptLine.length % width === 0) {
21589
+ content += "\n";
21590
+ }
21591
+ let output = content + (bottomContent ? "\n" + bottomContent : "");
21592
+ const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
21593
+ const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
21594
+ if (bottomContentHeight > 0)
21595
+ output += cursorUp(bottomContentHeight);
21596
+ output += cursorTo(this.cursorPos.cols);
21597
+ this.write(cursorDown(this.extraLinesUnderPrompt) + eraseLines(this.height) + output);
21598
+ this.extraLinesUnderPrompt = bottomContentHeight;
21599
+ this.height = height(output);
21600
+ }
21601
+ checkCursorPos() {
21602
+ const cursorPos = this.rl.getCursorPos();
21603
+ if (cursorPos.cols !== this.cursorPos.cols) {
21604
+ this.write(cursorTo(cursorPos.cols));
21605
+ this.cursorPos = cursorPos;
21606
+ }
21607
+ }
21608
+ done({ clearContent }) {
21609
+ this.rl.setPrompt("");
21610
+ let output = cursorDown(this.extraLinesUnderPrompt);
21611
+ output += clearContent ? eraseLines(this.height) : "\n";
21612
+ output += cursorLeft;
21613
+ output += cursorShow;
21614
+ this.write(output);
21615
+ this.rl.close();
21616
+ }
21617
+ };
21618
+
21619
+ // ../../../node_modules/@inquirer/core/dist/lib/promise-polyfill.js
21620
+ var PromisePolyfill = class extends Promise {
21621
+ // Available starting from Node 22
21622
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
21623
+ static withResolver() {
21624
+ let resolve;
21625
+ let reject;
21626
+ const promise2 = new Promise((res, rej) => {
21627
+ resolve = res;
21628
+ reject = rej;
21629
+ });
21630
+ return { promise: promise2, resolve, reject };
21631
+ }
21632
+ };
21633
+
21634
+ // ../../../node_modules/@inquirer/core/dist/lib/create-prompt.js
21635
+ import path from "node:path";
21636
+ var nativeSetImmediate = globalThis.setImmediate;
21637
+ function listenTo(target, event, listener) {
21638
+ if ("on" in target) {
21639
+ target.on(event, listener);
21640
+ return () => target.removeListener(event, listener);
21641
+ }
21642
+ target.addEventListener(event, listener);
21643
+ return () => target.removeEventListener(event, listener);
21644
+ }
21645
+ function getCallSites() {
21646
+ const savedPrepareStackTrace = Error.prepareStackTrace;
21647
+ let result = [];
21648
+ try {
21649
+ Error.prepareStackTrace = (_, callSites) => {
21650
+ const callSitesWithoutCurrent = callSites.slice(1);
21651
+ result = callSitesWithoutCurrent;
21652
+ return callSitesWithoutCurrent;
21653
+ };
21654
+ new Error().stack;
21655
+ } catch {
21656
+ return result;
21657
+ }
21658
+ Error.prepareStackTrace = savedPrepareStackTrace;
21659
+ return result;
21660
+ }
21661
+ function createPrompt(view) {
21662
+ const callSites = getCallSites();
21663
+ const prompt = (config2, context = {}) => {
21664
+ const { input = process.stdin, signal } = context;
21665
+ const cleanups = /* @__PURE__ */ new Set();
21666
+ const output = new import_mute_stream.default();
21667
+ output.pipe(context.output ?? process.stdout);
21668
+ const rl = readline2.createInterface({
21669
+ terminal: true,
21670
+ input,
21671
+ output
21672
+ });
21673
+ output.mute();
21674
+ const screen = new ScreenManager(rl);
21675
+ const { promise: promise2, resolve, reject } = PromisePolyfill.withResolver();
21676
+ return withHooks(rl, (cycle) => {
21677
+ const clearEffects = AsyncResource3.bind(() => effectScheduler.clearAll());
21678
+ const settlePrompt = (settle) => {
21679
+ try {
21680
+ clearEffects();
21681
+ settle();
21682
+ } catch (error51) {
21683
+ reject(error51);
21684
+ }
21685
+ };
21686
+ const resolvePrompt = (value) => settlePrompt(() => resolve(value));
21687
+ const rejectPrompt = (error51) => settlePrompt(() => reject(error51));
21688
+ const promptPromise = Object.assign(promise2.finally(() => {
21689
+ cleanups.forEach((cleanup) => cleanup());
21690
+ screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
21691
+ output.end();
21692
+ }).then(() => promise2), { cancel: () => rejectPrompt(new CancelPromptError()) });
21693
+ if (signal) {
21694
+ const abort = () => rejectPrompt(new AbortPromptError({ cause: signal.reason }));
21695
+ if (signal.aborted) {
21696
+ abort();
21697
+ return promptPromise;
21698
+ }
21699
+ cleanups.add(listenTo(signal, "abort", abort));
21700
+ }
21701
+ cleanups.add(onExit((code, signal2) => {
21702
+ rejectPrompt(new ExitPromptError(`User force closed the prompt with ${code} ${signal2}`));
21703
+ }));
21704
+ cleanups.add(listenTo(rl, "SIGINT", () => rejectPrompt(new ExitPromptError(`User force closed the prompt with SIGINT`))));
21705
+ cleanups.add(listenTo(rl, "close", clearEffects));
21706
+ const startCycle = () => {
21707
+ cleanups.add(listenTo(rl.input, "keypress", () => screen.checkCursorPos()));
21708
+ let pendingDone = null;
21709
+ cycle(() => {
21710
+ let effectsSettled = false;
21711
+ try {
21712
+ const nextView = view(config2, (value) => {
21713
+ if (effectsSettled) {
21714
+ resolvePrompt(value);
21715
+ } else {
21716
+ pendingDone = { value };
21717
+ }
21718
+ });
21719
+ if (nextView === void 0) {
21720
+ let callerFilename = callSites[1]?.getFileName();
21721
+ if (callerFilename && !callerFilename.startsWith("file://")) {
21722
+ callerFilename = path.resolve(callerFilename);
21723
+ }
21724
+ throw new Error(`Prompt functions must return a string.
21725
+ at ${callerFilename}`);
21726
+ }
21727
+ const [content, bottomContent] = typeof nextView === "string" ? [nextView] : nextView;
21728
+ screen.render(content, bottomContent);
21729
+ effectScheduler.run();
21730
+ } catch (error51) {
21731
+ rejectPrompt(error51);
21732
+ }
21733
+ effectsSettled = true;
21734
+ if (pendingDone !== null) {
21735
+ const { value } = pendingDone;
21736
+ pendingDone = null;
21737
+ resolvePrompt(value);
21738
+ }
21739
+ });
21740
+ };
21741
+ if ("readableFlowing" in input) {
21742
+ nativeSetImmediate(startCycle);
21743
+ } else {
21744
+ startCycle();
21745
+ }
21746
+ return promptPromise;
21747
+ });
21748
+ };
21749
+ return prompt;
21750
+ }
21751
+
21752
+ // ../../../node_modules/@inquirer/core/dist/lib/Separator.js
21753
+ import { styleText as styleText2 } from "node:util";
21754
+ var Separator = class {
21755
+ separator = styleText2("dim", Array.from({ length: 15 }).join(dist_default.line));
21756
+ type = "separator";
21757
+ constructor(separator) {
21758
+ if (separator) {
21759
+ this.separator = separator;
21760
+ }
21761
+ }
21762
+ static isSeparator(choice) {
21763
+ return Boolean(choice && typeof choice === "object" && "type" in choice && choice.type === "separator");
21764
+ }
21765
+ };
21766
+
21767
+ // ../../../node_modules/@inquirer/confirm/dist/index.js
21768
+ import { styleText as styleText3 } from "node:util";
21769
+ var confirmTheme = {
21770
+ keywords: {
21771
+ yes: "Yes",
21772
+ no: "No"
21773
+ },
21774
+ style: {
21775
+ confirmDefault: (text) => {
21776
+ const first = text[0] ?? "";
21777
+ if (first.toLowerCase() === first.toUpperCase()) {
21778
+ return styleText3("cyan", text);
21779
+ }
21780
+ return first.toUpperCase() + text.slice(1);
21781
+ }
21782
+ }
21783
+ };
21784
+ var dist_default4 = createPrompt((config2, done) => {
21785
+ const [status, setStatus] = useState("idle");
21786
+ const [value, setValue] = useState("");
21787
+ const theme = makeTheme(confirmTheme, config2.theme);
21788
+ const prefix = usePrefix({ status, theme });
21789
+ const { yes, no } = theme.keywords;
21790
+ const yesHint = (yes[0] ?? "").toLowerCase();
21791
+ const noHint = (no[0] ?? "").toLowerCase();
21792
+ const hint = config2.default === false ? `${yesHint}/${theme.style.confirmDefault(noHint)}` : `${theme.style.confirmDefault(yesHint)}/${noHint}`;
21793
+ function boolToString(value2) {
21794
+ return value2 ? yes : no;
21795
+ }
21796
+ const { transformer = boolToString } = config2;
21797
+ function getBooleanValue(value2, defaultValue2) {
21798
+ const v = value2.trim().toLowerCase();
21799
+ if (v === "")
21800
+ return defaultValue2 !== false;
21801
+ if (yes.toLowerCase().startsWith(v))
21802
+ return true;
21803
+ if (no.toLowerCase().startsWith(v))
21804
+ return false;
21805
+ return defaultValue2 !== false;
21806
+ }
21807
+ useKeypress((key, rl) => {
21808
+ if (status !== "idle")
21809
+ return;
21810
+ if (isEnterKey(key)) {
21811
+ const answer = getBooleanValue(value, config2.default);
21812
+ setValue(transformer(answer));
21813
+ setStatus("done");
21814
+ done(answer);
21815
+ } else if (isTabKey(key)) {
21816
+ const answer = boolToString(!getBooleanValue(value, config2.default));
21817
+ rl.clearLine(0);
21818
+ rl.write(answer);
21819
+ setValue(answer);
21820
+ } else {
21821
+ setValue(rl.line);
21822
+ }
21823
+ });
21824
+ let formattedValue = value;
21825
+ let defaultValue = "";
21826
+ if (status === "done") {
21827
+ formattedValue = theme.style.answer(value);
21828
+ } else {
21829
+ defaultValue = ` ${theme.style.defaultAnswer(hint)}`;
21830
+ }
21831
+ const message = theme.style.message(config2.message, status);
21832
+ return `${prefix} ${message}${defaultValue} ${formattedValue}`;
21833
+ });
21834
+
21835
+ // ../../../node_modules/@inquirer/input/dist/index.js
21836
+ var inputTheme = {
21837
+ validationFailureMode: "keep"
21838
+ };
21839
+ var dist_default5 = createPrompt((config2, done) => {
21840
+ const { prefill = "tab" } = config2;
21841
+ const theme = makeTheme(inputTheme, config2.theme);
21842
+ const [status, setStatus] = useState("idle");
21843
+ const [defaultValue, setDefaultValue] = useState(String(config2.default ?? ""));
21844
+ const [errorMsg, setError] = useState();
21845
+ const [value, setValue] = useState("");
21846
+ const prefix = usePrefix({ status, theme });
21847
+ async function validate(value2) {
21848
+ const { required: required2, pattern, patternError = "Invalid input" } = config2;
21849
+ if (required2 && !value2) {
21850
+ return "You must provide a value";
21851
+ }
21852
+ if (pattern && !pattern.test(value2)) {
21853
+ return patternError;
21854
+ }
21855
+ if (typeof config2.validate === "function") {
21856
+ return await config2.validate(value2) || "You must provide a valid value";
21857
+ }
21858
+ return true;
21859
+ }
21860
+ useKeypress(async (key, rl) => {
21861
+ if (status !== "idle") {
21862
+ return;
21863
+ }
21864
+ if (isEnterKey(key)) {
21865
+ const answer = value || defaultValue;
21866
+ setStatus("loading");
21867
+ const isValid = await validate(answer);
21868
+ if (isValid === true) {
21869
+ setValue(answer);
21870
+ setStatus("done");
21871
+ done(answer);
21872
+ } else {
21873
+ if (theme.validationFailureMode === "clear") {
21874
+ setValue("");
21875
+ } else {
21876
+ rl.write(value);
21877
+ }
21878
+ setError(isValid);
21879
+ setStatus("idle");
21880
+ }
21881
+ } else if (isBackspaceKey(key) && !value) {
21882
+ setDefaultValue("");
21883
+ } else if (isTabKey(key) && !value) {
21884
+ setDefaultValue("");
21885
+ rl.clearLine(0);
21886
+ rl.write(defaultValue);
21887
+ setValue(defaultValue);
21888
+ } else {
21889
+ setValue(rl.line);
21890
+ setError(void 0);
21891
+ }
21892
+ });
21893
+ useEffect((rl) => {
21894
+ if (prefill === "editable" && defaultValue) {
21895
+ rl.write(defaultValue);
21896
+ setValue(defaultValue);
21897
+ }
21898
+ }, []);
21899
+ const message = theme.style.message(config2.message, status);
21900
+ let formattedValue = value;
21901
+ if (typeof config2.transformer === "function") {
21902
+ formattedValue = config2.transformer(value, { isFinal: status === "done" });
21903
+ } else if (status === "done") {
21904
+ formattedValue = theme.style.answer(value);
21905
+ }
21906
+ let defaultStr;
21907
+ if (defaultValue && status !== "done" && !value) {
21908
+ defaultStr = theme.style.defaultAnswer(defaultValue);
21909
+ }
21910
+ let error51 = "";
21911
+ if (errorMsg) {
21912
+ error51 = theme.style.error(errorMsg);
21913
+ }
21914
+ return [
21915
+ [prefix, message, defaultStr, formattedValue].filter((v) => v !== void 0).join(" "),
21916
+ error51
21917
+ ];
21918
+ });
21919
+
21920
+ // ../../../node_modules/@inquirer/select/dist/index.js
21921
+ import { styleText as styleText4 } from "node:util";
21922
+ var selectTheme = {
21923
+ icon: { cursor: dist_default.pointer },
21924
+ style: {
21925
+ disabled: (text) => styleText4("dim", text),
21926
+ description: (text) => styleText4("cyan", text),
21927
+ keysHelpTip: (keys) => keys.map(([key, action]) => `${styleText4("bold", key)} ${styleText4("dim", action)}`).join(styleText4("dim", " \u2022 "))
21928
+ },
21929
+ i18n: { disabledError: "This option is disabled and cannot be selected." },
21930
+ indexMode: "hidden"
21931
+ };
21932
+ function isSelectable(item) {
21933
+ return !Separator.isSeparator(item) && !item.disabled;
21934
+ }
21935
+ function isNavigable(item) {
21936
+ return !Separator.isSeparator(item);
21937
+ }
21938
+ function normalizeChoices(choices) {
21939
+ return choices.map((choice) => {
21940
+ if (Separator.isSeparator(choice))
21941
+ return choice;
21942
+ if (typeof choice !== "object" || choice === null || !("value" in choice)) {
21943
+ const name2 = String(choice);
21944
+ return {
21945
+ value: choice,
21946
+ name: name2,
21947
+ short: name2,
21948
+ disabled: false
21949
+ };
21950
+ }
21951
+ const name = choice.name ?? String(choice.value);
21952
+ const normalizedChoice = {
21953
+ value: choice.value,
21954
+ name,
21955
+ short: choice.short ?? name,
21956
+ disabled: choice.disabled ?? false
21957
+ };
21958
+ if (choice.description) {
21959
+ normalizedChoice.description = choice.description;
21960
+ }
21961
+ return normalizedChoice;
21962
+ });
21963
+ }
21964
+ var dist_default6 = createPrompt((config2, done) => {
21965
+ const { loop = true, pageSize = 7 } = config2;
21966
+ const theme = makeTheme(selectTheme, config2.theme);
21967
+ const { keybindings: keybindings2 } = theme;
21968
+ const [status, setStatus] = useState("idle");
21969
+ const prefix = usePrefix({ status, theme });
21970
+ const searchTimeoutRef = useRef();
21971
+ const searchEnabled = !keybindings2.includes("vim");
21972
+ const items = useMemo(() => normalizeChoices(config2.choices), [config2.choices]);
21973
+ const bounds = useMemo(() => {
21974
+ const first = items.findIndex(isNavigable);
21975
+ const last = items.findLastIndex(isNavigable);
21976
+ if (first === -1) {
21977
+ throw new ValidationError("[select prompt] No selectable choices. All choices are disabled.");
21978
+ }
21979
+ return { first, last };
21980
+ }, [items]);
21981
+ const defaultItemIndex = useMemo(() => {
21982
+ if (!("default" in config2))
21983
+ return -1;
21984
+ return items.findIndex((item) => isSelectable(item) && item.value === config2.default);
21985
+ }, [config2.default, items]);
21986
+ const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
21987
+ const selectedChoice = items[active];
21988
+ if (selectedChoice == null || Separator.isSeparator(selectedChoice)) {
21989
+ throw new Error("Active index does not point to a choice");
21990
+ }
21991
+ const [errorMsg, setError] = useState();
21992
+ useKeypress((key, rl) => {
21993
+ clearTimeout(searchTimeoutRef.current);
21994
+ if (errorMsg) {
21995
+ setError(void 0);
21996
+ }
21997
+ if (isEnterKey(key)) {
21998
+ if (selectedChoice.disabled) {
21999
+ setError(theme.i18n.disabledError);
22000
+ } else {
22001
+ setStatus("done");
22002
+ done(selectedChoice.value);
22003
+ }
22004
+ } else if (isUpKey(key, keybindings2) || isDownKey(key, keybindings2)) {
22005
+ rl.clearLine(0);
22006
+ if (loop || isUpKey(key, keybindings2) && active !== bounds.first || isDownKey(key, keybindings2) && active !== bounds.last) {
22007
+ const offset = isUpKey(key, keybindings2) ? -1 : 1;
22008
+ let next = active;
22009
+ do {
22010
+ next = (next + offset + items.length) % items.length;
22011
+ } while (!isNavigable(items[next]));
22012
+ setActive(next);
22013
+ }
22014
+ } else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
22015
+ const selectedIndex = Number(rl.line) - 1;
22016
+ let selectableIndex = -1;
22017
+ const position = items.findIndex((item2) => {
22018
+ if (Separator.isSeparator(item2))
22019
+ return false;
22020
+ selectableIndex++;
22021
+ return selectableIndex === selectedIndex;
22022
+ });
22023
+ const item = items[position];
22024
+ if (item != null && isSelectable(item)) {
22025
+ setActive(position);
22026
+ }
22027
+ searchTimeoutRef.current = setTimeout(() => {
22028
+ rl.clearLine(0);
22029
+ }, 700);
22030
+ } else if (isBackspaceKey(key)) {
22031
+ rl.clearLine(0);
22032
+ } else if (searchEnabled) {
22033
+ const searchTerm = rl.line.toLowerCase();
22034
+ const matchIndex = items.findIndex((item) => {
22035
+ if (Separator.isSeparator(item) || !isSelectable(item))
22036
+ return false;
22037
+ return item.name.toLowerCase().startsWith(searchTerm);
22038
+ });
22039
+ if (matchIndex !== -1) {
22040
+ setActive(matchIndex);
22041
+ }
22042
+ searchTimeoutRef.current = setTimeout(() => {
22043
+ rl.clearLine(0);
22044
+ }, 700);
22045
+ }
22046
+ });
22047
+ useEffect(() => () => {
22048
+ clearTimeout(searchTimeoutRef.current);
22049
+ }, []);
22050
+ const message = theme.style.message(config2.message, status);
22051
+ const helpLine = theme.style.keysHelpTip([
22052
+ ["\u2191\u2193", "navigate"],
22053
+ ["\u23CE", "select"]
22054
+ ]);
22055
+ let separatorCount = 0;
22056
+ const page = usePagination({
22057
+ items,
22058
+ active,
22059
+ renderItem({ item, isActive, index }) {
22060
+ if (Separator.isSeparator(item)) {
22061
+ separatorCount++;
22062
+ return ` ${item.separator}`;
22063
+ }
22064
+ const cursor = isActive ? theme.icon.cursor : " ";
22065
+ const indexLabel = theme.indexMode === "number" ? `${index + 1 - separatorCount}. ` : "";
22066
+ if (item.disabled) {
22067
+ const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
22068
+ const disabledCursor = isActive ? theme.icon.cursor : "-";
22069
+ return theme.style.disabled(`${disabledCursor} ${indexLabel}${item.name} ${disabledLabel}`);
22070
+ }
22071
+ const color = isActive ? theme.style.highlight : (x) => x;
22072
+ return color(`${cursor} ${indexLabel}${item.name}`);
22073
+ },
22074
+ pageSize,
22075
+ loop
22076
+ });
22077
+ if (status === "done") {
22078
+ return [prefix, message, theme.style.answer(selectedChoice.short)].filter(Boolean).join(" ");
22079
+ }
22080
+ const { description } = selectedChoice;
22081
+ const lines = [
22082
+ [prefix, message].filter(Boolean).join(" "),
22083
+ page,
22084
+ " ",
22085
+ description ? theme.style.description(description) : "",
22086
+ errorMsg ? theme.style.error(errorMsg) : "",
22087
+ helpLine
22088
+ ].filter(Boolean).join("\n").trimEnd();
22089
+ return `${lines}${cursorHide}`;
22090
+ });
22091
+
20063
22092
  // dist/run.js
20064
22093
  import { spawn } from "node:child_process";
20065
22094
  var runner = {
@@ -20140,7 +22169,7 @@ function headlessArgv(work) {
20140
22169
  if (!isAgent(argv[0]))
20141
22170
  return argv;
20142
22171
  if (argv.includes("--remote-control"))
20143
- return argv;
22172
+ return underTty(argv);
20144
22173
  const streaming = ["--output-format", "stream-json", "--verbose"];
20145
22174
  if (work.answer !== null && work.agentSessionId !== null) {
20146
22175
  return [argv[0], "--resume", work.agentSessionId, "-p", work.answer, ...streaming];
@@ -20149,6 +22178,9 @@ function headlessArgv(work) {
20149
22178
  return [...argv, ...streaming];
20150
22179
  return [argv[0], "-p", argv.slice(1).join(" "), ...streaming];
20151
22180
  }
22181
+ function underTty(argv) {
22182
+ return process.platform === "linux" ? ["script", "-qec", argv.join(" "), "/dev/null"] : ["script", "-q", "/dev/null", ...argv];
22183
+ }
20152
22184
  function isAgent(command) {
20153
22185
  return AGENTS.has((command ?? "").split("/").pop() ?? "");
20154
22186
  }
@@ -20177,6 +22209,8 @@ function parseJson(line) {
20177
22209
 
20178
22210
  // dist/setup.js
20179
22211
  import { execFile as execFile2 } from "node:child_process";
22212
+ import os2 from "node:os";
22213
+ import path3 from "node:path";
20180
22214
  import { promisify as promisify2 } from "node:util";
20181
22215
 
20182
22216
  // dist/probe.js
@@ -20184,11 +22218,11 @@ import { execFile } from "node:child_process";
20184
22218
  import net from "node:net";
20185
22219
  import { access, readFile } from "node:fs/promises";
20186
22220
  import os from "node:os";
20187
- import path from "node:path";
22221
+ import path2 from "node:path";
20188
22222
  import { promisify } from "node:util";
20189
22223
  var run = promisify(execFile);
20190
22224
  var probe = {
20191
- async tools({ mcpPath = path.join(os.homedir(), ".mcp.json") } = {}) {
22225
+ async tools({ mcpPath = path2.join(os.homedir(), ".mcp.json") } = {}) {
20192
22226
  const [brain, claude, codex, git, chrome, ssh] = await Promise.all([
20193
22227
  brainWired(mcpPath),
20194
22228
  version2({ id: "claude", command: "claude" }),
@@ -20215,26 +22249,26 @@ async function brainWired(mcpPath) {
20215
22249
  }
20216
22250
  async function version2({ id, command }) {
20217
22251
  const found = await firstLine(command, ["--version"]);
20218
- if (typeof found === "string")
20219
- return { id, ok: true, detail: found };
20220
- return { id, ok: false, detail: found === "absent" ? "not installed" : "installed, but it will not report a version" };
22252
+ if (found.ran)
22253
+ return { id, ok: true, detail: found.line };
22254
+ return { id, ok: false, detail: found.why === "absent" ? "not installed" : "installed, but it will not report a version" };
20221
22255
  }
20222
22256
  async function gitAndGithub() {
20223
22257
  const git = await firstLine("git", ["--version"]);
20224
- if (typeof git !== "string")
22258
+ if (!git.ran)
20225
22259
  return { id: "git", ok: false, detail: "git is not installed" };
20226
22260
  const gh = await firstLine("gh", ["--version"]);
20227
- if (typeof gh !== "string")
20228
- return { id: "git", ok: false, detail: `${git} \xB7 the GitHub CLI is not installed yet` };
22261
+ if (!gh.ran)
22262
+ return { id: "git", ok: false, detail: `${git.line} \xB7 the GitHub CLI is not installed yet` };
20229
22263
  const account = await githubAccount();
20230
22264
  return {
20231
22265
  id: "git",
20232
22266
  ok: account !== null,
20233
- detail: account === null ? `${git} \xB7 ${gh}, run gh auth login on this machine` : `${git} \xB7 ${gh}, signed in as ${account}`
22267
+ detail: account === null ? `${git.line} \xB7 ${gh.line}, run gh auth login on this machine` : `${git.line} \xB7 ${gh.line}, signed in as ${account}`
20234
22268
  };
20235
22269
  }
20236
22270
  async function githubAccount() {
20237
- const raw = await readFile(path.join(os.homedir(), ".config", "gh", "hosts.yml"), "utf8").catch(() => null);
22271
+ const raw = await readFile(path2.join(os.homedir(), ".config", "gh", "hosts.yml"), "utf8").catch(() => null);
20238
22272
  return raw === null ? null : githubUser(raw);
20239
22273
  }
20240
22274
  function githubUser(hostsYml) {
@@ -20243,8 +22277,8 @@ function githubUser(hostsYml) {
20243
22277
  async function chromeInstalled() {
20244
22278
  for (const command of [...MAC_CHROME, ...LINUX_CHROME]) {
20245
22279
  const found = await firstLine(command, ["--version"]);
20246
- if (typeof found === "string")
20247
- return { id: "chrome", ok: true, detail: found };
22280
+ if (found.ran)
22281
+ return { id: "chrome", ok: true, detail: found.line };
20248
22282
  }
20249
22283
  return { id: "chrome", ok: false, detail: "not installed yet, so browser runs will fail" };
20250
22284
  }
@@ -20265,13 +22299,13 @@ async function firstLine(command, args) {
20265
22299
  if (command.includes("/")) {
20266
22300
  const reachable = await access(command).then(() => true, () => false);
20267
22301
  if (!reachable)
20268
- return "absent";
22302
+ return { ran: false, why: "absent" };
20269
22303
  }
20270
22304
  const answer = await run(command, args, { timeout: PROBE_TIMEOUT_MS }).catch((thrown) => thrown);
20271
22305
  if (answer instanceof Error)
20272
- return answer.code === "ENOENT" ? "absent" : "broken";
22306
+ return { ran: false, why: answer.code === "ENOENT" ? "absent" : "broken" };
20273
22307
  const line = answer.stdout.split("\n")[0]?.trim() ?? "";
20274
- return line === "" ? "broken" : line.slice(0, 200);
22308
+ return line === "" ? { ran: false, why: "broken" } : { ran: true, line: line.slice(0, 200) };
20275
22309
  }
20276
22310
  function short(target) {
20277
22311
  return target.startsWith(os.homedir()) ? `~${target.slice(os.homedir().length)}` : target;
@@ -20284,29 +22318,68 @@ var SSH_PROBE_TIMEOUT_MS = 1500;
20284
22318
  // dist/setup.js
20285
22319
  var run2 = promisify2(execFile2);
20286
22320
  var setup = {
22321
+ widenPath() {
22322
+ const current = (process.env.PATH ?? "").split(path3.delimiter).filter((entry) => entry !== "");
22323
+ const missing = toolDirs().filter((entry) => !current.includes(entry));
22324
+ if (missing.length > 0)
22325
+ process.env.PATH = [...current, ...missing].join(path3.delimiter);
22326
+ },
20287
22327
  async run({ install, rewire: rewire2, say }) {
20288
22328
  const found = await probe.tools();
20289
22329
  if (!install)
20290
- return found;
22330
+ return withReasons(found);
20291
22331
  const repairs = { ...REPAIRS, ...rewire2 === void 0 ? {} : { brain: { name: "the brain", fix: rewire2 } } };
20292
- const broken = found.filter((tool) => !tool.ok && repairs[tool.id] !== void 0);
22332
+ const broken = found.filter((tool) => !tool.ok && repairs[tool.id] !== void 0 && isDue(tool.id));
20293
22333
  if (broken.length === 0)
20294
- return found;
22334
+ return withReasons(found);
20295
22335
  for (const tool of broken) {
20296
22336
  const repair = repairs[tool.id];
20297
22337
  if (repair === void 0)
20298
22338
  continue;
20299
22339
  say?.(`Setting up ${repair.name}`);
22340
+ tried.set(tool.id, Date.now());
20300
22341
  const failed = await repair.fix().then(() => null, (error51) => firstLine2(error51.message));
22342
+ if (failed === null)
22343
+ reasons.delete(tool.id);
22344
+ else
22345
+ reasons.set(tool.id, failed);
20301
22346
  say?.(failed === null ? ` ${repair.name} is ready` : ` could not set up ${repair.name}: ${failed}`);
20302
22347
  }
20303
- return probe.tools();
22348
+ return withReasons(await probe.tools());
20304
22349
  }
20305
22350
  };
22351
+ function isDue(id) {
22352
+ const last = tried.get(id);
22353
+ return last === void 0 || Date.now() - last > RETRY_AFTER_MS;
22354
+ }
22355
+ function withReasons(tools2) {
22356
+ return tools2.map((tool) => {
22357
+ const reason = tool.ok ? void 0 : reasons.get(tool.id);
22358
+ return reason === void 0 ? tool : { ...tool, detail: `${tool.detail} \xB7 ${reason}`.slice(0, 200) };
22359
+ });
22360
+ }
22361
+ function toolDirs() {
22362
+ const prefix = process.env.npm_config_prefix;
22363
+ return [
22364
+ path3.dirname(process.execPath),
22365
+ ...prefix === void 0 ? [] : [path3.join(prefix, "bin")],
22366
+ path3.join(os2.homedir(), ".local", "bin"),
22367
+ path3.join(os2.homedir(), ".npm-global", "bin"),
22368
+ "/opt/homebrew/bin",
22369
+ "/usr/local/bin"
22370
+ ];
22371
+ }
20306
22372
  var REPAIRS = {
20307
22373
  claude: { name: "Claude Code", fix: () => npmGlobal("@anthropic-ai/claude-code") },
20308
22374
  codex: { name: "Codex", fix: () => npmGlobal("@openai/codex") },
20309
- git: { name: "the GitHub CLI", fix: () => installPackage({ brew: ["gh"], apt: ["gh"], dnf: ["gh"] }) },
22375
+ git: {
22376
+ name: "the GitHub CLI",
22377
+ fix: async () => {
22378
+ if (await firstAvailable(["gh"]) !== null)
22379
+ return;
22380
+ await installPackage({ brew: ["gh"], apt: ["gh"], dnf: ["gh"] });
22381
+ }
22382
+ },
20310
22383
  chrome: {
20311
22384
  name: "Google Chrome",
20312
22385
  fix: () => installPackage({ brew: ["--cask", "google-chrome"], apt: ["chromium"], dnf: ["chromium"] })
@@ -20337,13 +22410,16 @@ async function firstAvailable(commands) {
20337
22410
  function firstLine2(message) {
20338
22411
  return message.split("\n")[0] ?? "it failed";
20339
22412
  }
22413
+ var tried = /* @__PURE__ */ new Map();
22414
+ var reasons = /* @__PURE__ */ new Map();
20340
22415
  var INSTALL_TIMEOUT_MS = 18e4;
22416
+ var RETRY_AFTER_MS = 216e5;
20341
22417
 
20342
22418
  // dist/machine.js
20343
22419
  var run3 = promisify3(execFile3);
20344
22420
  var machine = {
20345
22421
  home() {
20346
- return process.env.CRAFTSPACE_CLI_HOME ?? path2.join(os2.homedir(), ".craftspace");
22422
+ return process.env.CRAFTSPACE_CLI_HOME ?? path4.join(os3.homedir(), ".craftspace");
20347
22423
  },
20348
22424
  async login({ token, url: url2, install }) {
20349
22425
  const answer = await call({
@@ -20352,11 +22428,11 @@ var machine = {
20352
22428
  method: "POST",
20353
22429
  path: "/api/machines/login",
20354
22430
  body: {
20355
- name: os2.hostname().split(".")[0] ?? "machine",
22431
+ name: os3.hostname().split(".")[0] ?? "machine",
20356
22432
  platform: `${process.platform}-${process.arch}`,
20357
- sshUser: os2.userInfo().username,
20358
- cores: os2.cpus().length,
20359
- memoryGb: Math.max(1, Math.round(os2.totalmem() / 1024 ** 3)),
22433
+ sshUser: os3.userInfo().username,
22434
+ cores: os3.cpus().length,
22435
+ memoryGb: Math.max(1, Math.round(os3.totalmem() / 1024 ** 3)),
20360
22436
  cli: CLI_VERSION,
20361
22437
  publicKey: await ensureKey()
20362
22438
  },
@@ -20374,15 +22450,37 @@ var machine = {
20374
22450
  };
20375
22451
  return answer.machine;
20376
22452
  },
22453
+ async signIn({ url: url2, why, install = false }) {
22454
+ const where = url2 ?? (await readConfig())?.url ?? DEFAULT_URL;
22455
+ if (!process.stdin.isTTY)
22456
+ throw new Error(`${why} Run: craftspace login --token <token>`);
22457
+ const page = `${where}/workstations`;
22458
+ process.stdout.write(`
22459
+ ${why}
22460
+
22461
+ `);
22462
+ if (await dist_default4({ message: `Open ${page} for a key?`, default: true })) {
22463
+ await openInBrowser(page);
22464
+ process.stdout.write(' Click "Add a workstation" there, then copy the line it gives you.\n');
22465
+ } else {
22466
+ process.stdout.write(` Get one at ${page} under "Add a workstation".
22467
+ `);
22468
+ }
22469
+ const token = tokenIn(await dist_default5({
22470
+ message: "Paste it here",
22471
+ validate: (line) => tokenIn(line) !== void 0 || "No cst_\u2026 token in that. Paste the whole line if it is easier."
22472
+ }));
22473
+ if (token === void 0)
22474
+ throw new Error("That line carries no key.");
22475
+ const signed = await machine.login({ token, url: where, install });
22476
+ process.stdout.write(`
22477
+ Signed in as ${signed.ownerName}. This machine is ${signed.name}.
22478
+ `);
22479
+ return { url: where, token, machine: signed };
22480
+ },
20377
22481
  async status() {
20378
- const config2 = await readConfig();
20379
- if (!config2)
20380
- return null;
20381
- const token = await readToken();
20382
- if (!token)
20383
- return null;
20384
- const found = await call({ url: config2.url, token, method: "GET", path: "/api/machines/me", schema: MachineSchema });
20385
- return { machine: found, url: config2.url };
22482
+ const found = await withAuth(await signedInOrAsk(), (auth) => call({ ...auth, method: "GET", path: "/api/machines/me", schema: MachineSchema }));
22483
+ return { machine: found.value, url: found.auth.url };
20386
22484
  },
20387
22485
  async beatOnce() {
20388
22486
  const { url: url2, token } = await requireSignedIn();
@@ -20393,11 +22491,11 @@ var machine = {
20393
22491
  path: "/api/machines/beat",
20394
22492
  body: {
20395
22493
  cli: CLI_VERSION,
20396
- ...load(),
22494
+ ...load2(),
20397
22495
  sessions: await readSessions(),
20398
22496
  runs: drainReports(),
20399
22497
  tools: await tools(),
20400
- sshUser: os2.userInfo().username
22498
+ sshUser: os3.userInfo().username
20401
22499
  },
20402
22500
  schema: MachineBeatResponseSchema
20403
22501
  });
@@ -20458,8 +22556,9 @@ async function runHere(argv) {
20458
22556
  }
20459
22557
  }
20460
22558
  async function runThere({ argv, on }) {
20461
- const { url: url2, token } = await requireSignedIn();
20462
- const target = await machineNamed({ url: url2, token, name: on });
22559
+ const first = await signedInOrAsk();
22560
+ const { auth, value: target } = await withAuth(first, (live) => machineNamed({ ...live, name: on }));
22561
+ const { url: url2, token } = auth;
20463
22562
  let run4 = await call({
20464
22563
  url: url2,
20465
22564
  token,
@@ -20519,10 +22618,24 @@ async function readRun({ url: url2, token, machineId, runId }) {
20519
22618
  async function machineNamed({ url: url2, token, name }) {
20520
22619
  const answer = await call({ url: url2, token, method: "GET", path: "/api/machines", schema: MachinesResponseSchema });
20521
22620
  const found = answer.machines.find((candidate) => candidate.name === name || candidate.id === name);
20522
- if (found === void 0) {
22621
+ if (found !== void 0)
22622
+ return found;
22623
+ if (answer.machines.length === 0)
22624
+ throw new Error("This team has no workstations yet. Add one at /workstations.");
22625
+ if (!process.stdin.isTTY) {
20523
22626
  throw new Error(`No workstation called ${name}. This team has: ${answer.machines.map((m) => m.name).join(", ")}`);
20524
22627
  }
20525
- return found;
22628
+ process.stdout.write(`
22629
+ No workstation called ${name}.
22630
+
22631
+ `);
22632
+ return dist_default6({
22633
+ message: "Run it on",
22634
+ choices: answer.machines.map((candidate) => ({
22635
+ name: `${candidate.name.padEnd(20)} ${candidate.state}`,
22636
+ value: candidate
22637
+ }))
22638
+ });
20526
22639
  }
20527
22640
  function readStdinLine() {
20528
22641
  return new Promise((resolve) => {
@@ -20577,18 +22690,53 @@ async function call({ url: url2, token, method, path: route, body, schema }) {
20577
22690
  ...body === void 0 ? {} : { body: JSON.stringify(body) },
20578
22691
  signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
20579
22692
  });
22693
+ if (response.status === 401)
22694
+ throw new Unauthorized();
20580
22695
  if (!response.ok)
20581
22696
  throw new Error(`${route} answered ${response.status}`);
20582
22697
  return schema.parse(await response.json());
20583
22698
  }
22699
+ var Unauthorized = class extends Error {
22700
+ constructor() {
22701
+ super("This machine no longer has a key Craftspace accepts.");
22702
+ }
22703
+ };
22704
+ async function signedInOrAsk() {
22705
+ const config2 = await readConfig();
22706
+ const token = await readToken();
22707
+ if (config2 && token)
22708
+ return { url: config2.url, token };
22709
+ return machine.signIn({ why: "This machine is not signed in to Craftspace yet." });
22710
+ }
22711
+ async function withAuth(auth, work) {
22712
+ try {
22713
+ return { auth, value: await work(auth) };
22714
+ } catch (error51) {
22715
+ if (!(error51 instanceof Unauthorized))
22716
+ throw error51;
22717
+ const next = await machine.signIn({
22718
+ url: auth.url,
22719
+ why: "Craftspace does not know this machine any more. Its key was revoked, which is what forgetting the workstation, or signing the same box in somewhere else, does."
22720
+ });
22721
+ process.stdout.write("\nPicking up where you left off.\n\n");
22722
+ return { auth: next, value: await work(next) };
22723
+ }
22724
+ }
22725
+ async function openInBrowser(url2) {
22726
+ const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
22727
+ await run3(opener, [url2]).catch(() => void 0);
22728
+ }
22729
+ function tokenIn(line) {
22730
+ return /cst_[A-Za-z0-9_-]+/.exec(line)?.[0];
22731
+ }
20584
22732
  async function ensureKey() {
20585
- const priv = path2.join(machine.home(), "id_ed25519");
22733
+ const priv = path4.join(machine.home(), "id_ed25519");
20586
22734
  const pub = `${priv}.pub`;
20587
22735
  const existing = await readFile2(pub, "utf8").catch(() => null);
20588
22736
  if (existing !== null)
20589
22737
  return existing.trim();
20590
22738
  await mkdir(machine.home(), { recursive: true, mode: 448 });
20591
- await run3("ssh-keygen", ["-t", "ed25519", "-N", "", "-q", "-f", priv, "-C", `craftspace-${os2.hostname()}`]);
22739
+ await run3("ssh-keygen", ["-t", "ed25519", "-N", "", "-q", "-f", priv, "-C", `craftspace-${os3.hostname()}`]);
20592
22740
  return (await readFile2(pub, "utf8")).trim();
20593
22741
  }
20594
22742
  async function readConfig() {
@@ -20602,11 +22750,11 @@ async function readToken() {
20602
22750
  return raw === null ? null : raw.trim();
20603
22751
  }
20604
22752
  async function readSessions() {
20605
- const dir = path2.join(machine.home(), "sessions");
22753
+ const dir = path4.join(machine.home(), "sessions");
20606
22754
  const names = await readdir(dir).catch(() => []);
20607
22755
  const sessions = [];
20608
22756
  for (const name of names.filter((entry) => entry.endsWith(".json"))) {
20609
- const raw = await readFile2(path2.join(dir, name), "utf8").catch(() => null);
22757
+ const raw = await readFile2(path4.join(dir, name), "utf8").catch(() => null);
20610
22758
  if (raw === null)
20611
22759
  continue;
20612
22760
  const parsed = MachineSessionSchema.safeParse(JSON.parse(raw));
@@ -20616,7 +22764,7 @@ async function readSessions() {
20616
22764
  return sessions.slice(0, MAX_REPORTED_SESSIONS);
20617
22765
  }
20618
22766
  async function writeAuthorizedKeys(keys) {
20619
- const target = path2.join(os2.homedir(), ".ssh", "authorized_keys");
22767
+ const target = path4.join(os3.homedir(), ".ssh", "authorized_keys");
20620
22768
  const current = await readFile2(target, "utf8").catch(() => "");
20621
22769
  const before = current.split(KEYS_BEGIN)[0] ?? "";
20622
22770
  const after = current.includes(KEYS_END) ? current.split(KEYS_END)[1] ?? "" : "";
@@ -20627,26 +22775,26 @@ ${KEYS_END}
20627
22775
  const next = `${trimEnd(before)}${trimEnd(before) === "" ? "" : "\n"}${block}${after.replace(/^\n/, "")}`;
20628
22776
  if (next === current)
20629
22777
  return;
20630
- await mkdir(path2.dirname(target), { recursive: true, mode: 448 });
22778
+ await mkdir(path4.dirname(target), { recursive: true, mode: 448 });
20631
22779
  await writeFile(target, next, { mode: 384 });
20632
22780
  }
20633
22781
  function trimEnd(text) {
20634
22782
  return text.replace(/\s+$/, "");
20635
22783
  }
20636
22784
  async function writeSession(session) {
20637
- const dir = path2.join(machine.home(), "sessions");
22785
+ const dir = path4.join(machine.home(), "sessions");
20638
22786
  await mkdir(dir, { recursive: true, mode: 448 });
20639
- await writeFile(path2.join(dir, `${session.id}.json`), JSON.stringify(session), { mode: 384 });
22787
+ await writeFile(path4.join(dir, `${session.id}.json`), JSON.stringify(session), { mode: 384 });
20640
22788
  }
20641
22789
  async function clearSession(id) {
20642
- await rm(path2.join(machine.home(), "sessions", `${id}.json`), { force: true });
22790
+ await rm(path4.join(machine.home(), "sessions", `${id}.json`), { force: true });
20643
22791
  }
20644
22792
  async function writeAgentConfigs({ url: url2, token, writes }) {
20645
22793
  const planned = writes.length > 0 ? writes : defaultWrites({ url: url2, token });
20646
22794
  const owned = [];
20647
22795
  for (const write of planned) {
20648
22796
  const target = expand(write.path);
20649
- await mkdir(path2.dirname(target), { recursive: true });
22797
+ await mkdir(path4.dirname(target), { recursive: true });
20650
22798
  const current = await readFile2(target, "utf8").catch(() => null);
20651
22799
  if (current !== null)
20652
22800
  await writeFile(`${target}.craftspace-backup`, current, { flag: "wx" }).catch(() => void 0);
@@ -20661,11 +22809,11 @@ function mergeInto(current, incoming) {
20661
22809
  const merged = { ...current };
20662
22810
  for (const [key, value] of Object.entries(incoming)) {
20663
22811
  const existing = merged[key];
20664
- merged[key] = isPlainObject2(existing) && isPlainObject2(value) ? mergeInto(existing, value) : value;
22812
+ merged[key] = isPlainObject3(existing) && isPlainObject3(value) ? mergeInto(existing, value) : value;
20665
22813
  }
20666
22814
  return merged;
20667
22815
  }
20668
- function isPlainObject2(value) {
22816
+ function isPlainObject3(value) {
20669
22817
  return typeof value === "object" && value !== null && !Array.isArray(value);
20670
22818
  }
20671
22819
  function defaultWrites({ url: url2, token }) {
@@ -20683,7 +22831,7 @@ async function removeAgentConfigs() {
20683
22831
  continue;
20684
22832
  const parsed = JSON.parse(current);
20685
22833
  const servers = parsed.mcpServers;
20686
- if (isPlainObject2(servers))
22834
+ if (isPlainObject3(servers))
20687
22835
  delete servers.craftspace;
20688
22836
  if (await weCreated(target)) {
20689
22837
  await rm(target, { force: true });
@@ -20703,16 +22851,16 @@ async function installService() {
20703
22851
  return;
20704
22852
  }
20705
22853
  if (process.platform === "linux") {
20706
- const dir = path2.join(os2.homedir(), ".config", "systemd", "user");
22854
+ const dir = path4.join(os3.homedir(), ".config", "systemd", "user");
20707
22855
  await mkdir(dir, { recursive: true });
20708
- await writeFile(path2.join(dir, `${SERVICE_NAME}.service`), systemdUnit());
22856
+ await writeFile(path4.join(dir, `${SERVICE_NAME}.service`), systemdUnit());
20709
22857
  await run3("systemctl", ["--user", "daemon-reload"]).catch(() => void 0);
20710
22858
  await run3("systemctl", ["--user", "enable", "--now", SERVICE_NAME]).catch(() => void 0);
20711
22859
  return;
20712
22860
  }
20713
22861
  if (process.platform === "darwin") {
20714
- const target = path2.join(os2.homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
20715
- await mkdir(path2.dirname(target), { recursive: true });
22862
+ const target = path4.join(os3.homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
22863
+ await mkdir(path4.dirname(target), { recursive: true });
20716
22864
  await writeFile(target, launchdPlist());
20717
22865
  await run3("launchctl", ["unload", target]).catch(() => void 0);
20718
22866
  await run3("launchctl", ["load", target]).catch(() => void 0);
@@ -20721,11 +22869,11 @@ async function installService() {
20721
22869
  async function uninstallService() {
20722
22870
  if (process.platform === "linux") {
20723
22871
  await run3("systemctl", ["--user", "disable", "--now", SERVICE_NAME]).catch(() => void 0);
20724
- await rm(path2.join(os2.homedir(), ".config", "systemd", "user", `${SERVICE_NAME}.service`), { force: true });
22872
+ await rm(path4.join(os3.homedir(), ".config", "systemd", "user", `${SERVICE_NAME}.service`), { force: true });
20725
22873
  return;
20726
22874
  }
20727
22875
  if (process.platform === "darwin") {
20728
- const target = path2.join(os2.homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
22876
+ const target = path4.join(os3.homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
20729
22877
  await run3("launchctl", ["unload", target]).catch(() => void 0);
20730
22878
  await rm(target, { force: true });
20731
22879
  }
@@ -20760,24 +22908,24 @@ function launchdPlist() {
20760
22908
  `;
20761
22909
  }
20762
22910
  function entryPath() {
20763
- return path2.join(path2.dirname(new URL(import.meta.url).pathname), "index.js");
22911
+ return path4.join(path4.dirname(new URL(import.meta.url).pathname), "index.js");
20764
22912
  }
20765
22913
  function expand(target) {
20766
- return target.startsWith("~/") ? path2.join(os2.homedir(), target.slice(2)) : target;
22914
+ return target.startsWith("~/") ? path4.join(os3.homedir(), target.slice(2)) : target;
20767
22915
  }
20768
22916
  function configPath() {
20769
- return path2.join(machine.home(), "config.json");
22917
+ return path4.join(machine.home(), "config.json");
20770
22918
  }
20771
22919
  function tokenPath() {
20772
- return path2.join(machine.home(), "token");
22920
+ return path4.join(machine.home(), "token");
20773
22921
  }
20774
22922
  function ownedPath() {
20775
- return path2.join(machine.home(), "owned.json");
22923
+ return path4.join(machine.home(), "owned.json");
20776
22924
  }
20777
- function load() {
20778
- const cores = Math.max(1, os2.cpus().length);
20779
- const busy = Math.min(100, (os2.loadavg()[0] ?? 0) / cores * 100);
20780
- const used = (os2.totalmem() - os2.freemem()) / os2.totalmem() * 100;
22925
+ function load2() {
22926
+ const cores = Math.max(1, os3.cpus().length);
22927
+ const busy = Math.min(100, (os3.loadavg()[0] ?? 0) / cores * 100);
22928
+ const used = (os3.totalmem() - os3.freemem()) / os3.totalmem() * 100;
20781
22929
  return { cpuPercent: Math.round(busy), memoryPercent: Math.round(used) };
20782
22930
  }
20783
22931
  function nextDelayMs(failures, busy = false) {
@@ -20801,16 +22949,19 @@ var MAX_BACKOFF_MS = 12e4;
20801
22949
  var KEYS_BEGIN = "# craftspace begin";
20802
22950
  var KEYS_END = "# craftspace end";
20803
22951
  var POLL_INTERVAL_MS = 1e3;
22952
+ var DEFAULT_URL = process.env.CRAFTSPACE_URL ?? "https://craftspace.app";
20804
22953
  var PROBE_EVERY_MS = 3e5;
20805
22954
  var probed = null;
20806
22955
  var reports = /* @__PURE__ */ new Map();
20807
22956
  var running = /* @__PURE__ */ new Set();
20808
22957
 
20809
22958
  // dist/index.js
22959
+ setup.widenPath();
20810
22960
  var program2 = new Command();
20811
22961
  program2.enablePositionalOptions().name("craftspace").description("Sign this machine in to your team, so every agent on it reads the same brain.").version(CLI_VERSION).showHelpAfterError();
20812
- program2.command("login").description("sign this machine in").requiredOption("--token <token>", "the login token from your team", process.env.CRAFTSPACE_TOKEN).option("--url <url>", "your control plane", process.env.CRAFTSPACE_URL ?? "https://craftspace.app").option("--no-install", "do not install anything this machine is missing").action(async ({ token, url: url2, install }) => {
20813
- const signed = await machine.login({ token, url: url2.replace(/\/$/, ""), install });
22962
+ program2.command("login").description("sign this machine in").option("--token <token>", "the login token from your team", process.env.CRAFTSPACE_TOKEN).option("--url <url>", "your control plane", process.env.CRAFTSPACE_URL ?? "https://craftspace.app").option("--no-install", "do not install anything this machine is missing").action(async ({ token, url: url2, install }) => {
22963
+ const where = url2.replace(/\/$/, "");
22964
+ const signed = token === void 0 ? (await machine.signIn({ url: where, why: "Signing this machine in.", install })).machine : await machine.login({ token, url: where, install });
20814
22965
  process.stdout.write([
20815
22966
  `Signed in as ${signed.ownerName}`,
20816
22967
  `Machine ${signed.name} \xB7 ${signed.platform} \xB7 ${signed.cores ?? "?"} vCPU`,
@@ -20825,13 +22976,7 @@ program2.command("run").description("run a command here, or on another workstati
20825
22976
  process.exitCode = await machine.run({ argv: command, ...on === void 0 ? {} : { on } });
20826
22977
  });
20827
22978
  program2.command("status").description("what this machine is and what it is doing").action(async () => {
20828
- const current = await machine.status();
20829
- if (!current) {
20830
- process.stdout.write("Not signed in. Run: craftspace login --token <token>\n");
20831
- process.exitCode = 1;
20832
- return;
20833
- }
20834
- const { machine: found } = current;
22979
+ const { machine: found } = await machine.status();
20835
22980
  const since = found.lastBeatAt === null ? "never" : `${secondsSince(found.lastBeatAt)}s ago`;
20836
22981
  process.stdout.write([
20837
22982
  `${found.name} ${found.state} cli ${found.cli} beat ${since}`,