replicas-cli 0.3.371 → 0.3.373

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.cjs +287 -160
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -261,7 +261,7 @@ var init_urls = __esm({
261
261
  WEB_APP_PATHS.automations,
262
262
  `${WEB_APP_PATHS.automations}/${UUID_PATTERN}`
263
263
  ];
264
- APP_LINK_PATTERNS = APP_LINK_PATHS.map((path10) => new RegExp(`^${path10.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\?/g, ".").replace(/\*/g, ".*")}$`));
264
+ APP_LINK_PATTERNS = APP_LINK_PATHS.map((path11) => new RegExp(`^${path11.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\?/g, ".").replace(/\*/g, ".*")}$`));
265
265
  LEGACY_WEB_APP_PATHS = {
266
266
  app: "/app",
267
267
  home: "/home",
@@ -635,10 +635,10 @@ function mergeDefs(...defs) {
635
635
  function cloneDef(schema) {
636
636
  return mergeDefs(schema._zod.def);
637
637
  }
638
- function getElementAtPath(obj, path10) {
639
- if (!path10)
638
+ function getElementAtPath(obj, path11) {
639
+ if (!path11)
640
640
  return obj;
641
- return path10.reduce((acc, key) => acc?.[key], obj);
641
+ return path11.reduce((acc, key) => acc?.[key], obj);
642
642
  }
643
643
  function promiseAllObject(promisesObj) {
644
644
  const keys = Object.keys(promisesObj);
@@ -897,11 +897,11 @@ function explicitlyAborted(x, startIndex = 0) {
897
897
  }
898
898
  return false;
899
899
  }
900
- function prefixIssues(path10, issues) {
900
+ function prefixIssues(path11, issues) {
901
901
  return issues.map((iss) => {
902
902
  var _a3;
903
903
  (_a3 = iss).path ?? (_a3.path = []);
904
- iss.path.unshift(path10);
904
+ iss.path.unshift(path11);
905
905
  return iss;
906
906
  });
907
907
  }
@@ -1436,16 +1436,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
1436
1436
  }
1437
1437
  function formatError(error62, mapper = (issue2) => issue2.message) {
1438
1438
  const fieldErrors = { _errors: [] };
1439
- const processError = (error63, path10 = []) => {
1439
+ const processError = (error63, path11 = []) => {
1440
1440
  for (const issue2 of error63.issues) {
1441
1441
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1442
- issue2.errors.map((issues) => processError({ issues }, [...path10, ...issue2.path]));
1442
+ issue2.errors.map((issues) => processError({ issues }, [...path11, ...issue2.path]));
1443
1443
  } else if (issue2.code === "invalid_key") {
1444
- processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1444
+ processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1445
1445
  } else if (issue2.code === "invalid_element") {
1446
- processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1446
+ processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1447
1447
  } else {
1448
- const fullpath = [...path10, ...issue2.path];
1448
+ const fullpath = [...path11, ...issue2.path];
1449
1449
  if (fullpath.length === 0) {
1450
1450
  fieldErrors._errors.push(mapper(issue2));
1451
1451
  } else {
@@ -1484,17 +1484,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
1484
1484
  }
1485
1485
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
1486
1486
  const result = { errors: [] };
1487
- const processError = (error63, path10 = []) => {
1487
+ const processError = (error63, path11 = []) => {
1488
1488
  var _a3;
1489
1489
  for (const issue2 of error63.issues) {
1490
1490
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1491
- issue2.errors.map((issues) => processError({ issues }, [...path10, ...issue2.path]));
1491
+ issue2.errors.map((issues) => processError({ issues }, [...path11, ...issue2.path]));
1492
1492
  } else if (issue2.code === "invalid_key") {
1493
- processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1493
+ processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1494
1494
  } else if (issue2.code === "invalid_element") {
1495
- processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1495
+ processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1496
1496
  } else {
1497
- const fullpath = [...path10, ...issue2.path];
1497
+ const fullpath = [...path11, ...issue2.path];
1498
1498
  if (fullpath.length === 0) {
1499
1499
  result.errors.push(mapper(issue2));
1500
1500
  continue;
@@ -1533,8 +1533,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
1533
1533
  }
1534
1534
  function toDotPath(_path) {
1535
1535
  const segs = [];
1536
- const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1537
- for (const seg of path10) {
1536
+ const path11 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1537
+ for (const seg of path11) {
1538
1538
  if (typeof seg === "number")
1539
1539
  segs.push(`[${seg}]`);
1540
1540
  else if (typeof seg === "symbol")
@@ -19652,13 +19652,13 @@ function resolveRef(ref, ctx) {
19652
19652
  if (!ref.startsWith("#")) {
19653
19653
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
19654
19654
  }
19655
- const path10 = ref.slice(1).split("/").filter(Boolean);
19656
- if (path10.length === 0) {
19655
+ const path11 = ref.slice(1).split("/").filter(Boolean);
19656
+ if (path11.length === 0) {
19657
19657
  return ctx.rootSchema;
19658
19658
  }
19659
19659
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
19660
- if (path10[0] === defsKey) {
19661
- const key = path10[1] === void 0 ? void 0 : decodeJSONPointerSegment(path10[1]);
19660
+ if (path11[0] === defsKey) {
19661
+ const key = path11[1] === void 0 ? void 0 : decodeJSONPointerSegment(path11[1]);
19662
19662
  if (!key || !ctx.defs[key]) {
19663
19663
  throw new Error(`Reference not found: ${ref}`);
19664
19664
  }
@@ -24083,12 +24083,14 @@ var init_runtime_env = __esm({
24083
24083
  });
24084
24084
 
24085
24085
  // ../shared/src/engine/environment.ts
24086
- var ENGINE_PORT;
24086
+ var ENGINE_PORT, DEVICES_DIR, LOCAL_CONTROL_FILE_PREFIX;
24087
24087
  var init_environment2 = __esm({
24088
24088
  "../shared/src/engine/environment.ts"() {
24089
24089
  "use strict";
24090
24090
  init_type_guards();
24091
24091
  ENGINE_PORT = 3737;
24092
+ DEVICES_DIR = ".ssh/replicas-devices";
24093
+ LOCAL_CONTROL_FILE_PREFIX = "desktop-";
24092
24094
  }
24093
24095
  });
24094
24096
 
@@ -24592,7 +24594,7 @@ var init_local_computer = __esm({
24592
24594
  "../shared/src/default-skills/replicas-agent/abilities/local-computer.ts"() {
24593
24595
  "use strict";
24594
24596
  SECTION8 = `### The user's computer
24595
- Run commands on the user's own Mac or Linux computer over \`ssh <name>\`, such as an Xcode build, a simulator, or a tool that only exists there. Your instructions name the computers this workspace can reach, either through the desktop app's local control or as devices.
24597
+ Run commands on the user's own Mac or Linux computer over \`ssh <name>\`, such as an Xcode build, a simulator, or a tool that only exists there. Your instructions name the computers this workspace can reach, either through the desktop app's local control or as devices. With none, ask the user for theirs with \`replicas local-control request\`.
24596
24598
 
24597
24599
  **Reference:** \`references/LOCAL-COMPUTER.md\`
24598
24600
 
@@ -24607,7 +24609,13 @@ Your instructions list the computers you can reach and how: \`ssh <name>\`, \`sc
24607
24609
  grep '^Host' ~/.ssh/replicas-devices/*.conf
24608
24610
  \`\`\`
24609
24611
 
24610
- Hosts from a \`desktop-*.conf\` file connect through the desktop app. When one is the same computer as a device reached over the tailnet, use the desktop app host. If there are none, the user hasn't set any up: point them to **Local control** under Dashboard \u2192 Personal \u2192 Preferences \u2192 Experimental, with the Replicas desktop app open on that computer.
24612
+ Hosts from a \`desktop-*.conf\` file connect through the desktop app. When one is the same computer as a device reached over the tailnet, use the desktop app host. If there are none, ask for the user's computer:
24613
+
24614
+ \`\`\`bash
24615
+ replicas local-control request --reason "Build and run the iOS app in the Simulator"
24616
+ \`\`\`
24617
+
24618
+ It asks the user above the chat composer to let this workspace use their computer and to open the desktop app, waits until their computer connects, and prints its name. If it stops waiting first, end your turn and say what you need the computer for; you get a message when the user answers.
24611
24619
 
24612
24620
  It is a personal machine with the user's files, accounts and running apps. Change only what the task needs, keep your files in one folder, and ask before anything destructive, slow to undo, or visible on their screen (opening apps, booting a simulator window, changing settings).
24613
24621
 
@@ -24660,7 +24668,7 @@ ssh mac 'xcodebuild -version; xcrun simctl list runtimes; xcrun simctl list devi
24660
24668
 
24661
24669
  ## When it fails
24662
24670
 
24663
- - \`ssh\` closes straight away, such as "Connection closed by UNKNOWN port 65535": through the desktop app, the app isn't running there or local control is off: ask the user to open it. Over the tailnet it can also mean this workspace hasn't joined it (\`tailscale status\`): use a desktop app host for that computer if there is one before asking the user to fix the tailnet.
24671
+ - \`ssh\` closes straight away, such as "Connection closed by UNKNOWN port 65535": through the desktop app, the app isn't running there or the user turned this workspace's access off: run \`replicas local-control request\` to ask the user in the chat. Over the tailnet it can also mean this workspace hasn't joined it (\`tailscale status\`): use a desktop app host for that computer if there is one before asking the user to fix the tailnet.
24664
24672
  - "Operation not permitted" on the user's files: macOS is blocking the app. Ask the user to allow Replicas under System Settings \u2192 Privacy & Security \u2192 Full Disk Access.
24665
24673
  `;
24666
24674
  LOCAL_COMPUTER_ABILITY = {
@@ -26607,11 +26615,11 @@ function parseShellScript(script, cwd) {
26607
26615
  parseUntil(scope, 0, false);
26608
26616
  return scope.commands;
26609
26617
  }
26610
- function resolveShellPath(dir, path10) {
26611
- if (path10.includes(SHELL_OPAQUE) || path10.startsWith("~")) return null;
26612
- if (!path10.startsWith("/") && dir === null) return null;
26618
+ function resolveShellPath(dir, path11) {
26619
+ if (path11.includes(SHELL_OPAQUE) || path11.startsWith("~")) return null;
26620
+ if (!path11.startsWith("/") && dir === null) return null;
26613
26621
  const parts = [];
26614
- for (const part of (path10.startsWith("/") ? path10 : `${dir}/${path10}`).split("/")) {
26622
+ for (const part of (path11.startsWith("/") ? path11 : `${dir}/${path11}`).split("/")) {
26615
26623
  if (part === "..") parts.pop();
26616
26624
  else if (part && part !== ".") parts.push(part);
26617
26625
  }
@@ -27001,8 +27009,8 @@ function parseSkillName(tool, input2) {
27001
27009
  const skillName = parsedInput.skill ?? parsedInput.name;
27002
27010
  return typeof skillName === "string" && skillName ? skillName : null;
27003
27011
  }
27004
- function skillNameFromFilePath(path10) {
27005
- const parts = path10.split(/[\\/]+/).filter(Boolean);
27012
+ function skillNameFromFilePath(path11) {
27013
+ const parts = path11.split(/[\\/]+/).filter(Boolean);
27006
27014
  if (parts.length < 2 || parts[parts.length - 1].toLowerCase() !== "skill.md") return null;
27007
27015
  const skillName = parts[parts.length - 2];
27008
27016
  return /[*?[\]{}…$]/.test(skillName) || ["skills", ".system"].includes(skillName.toLowerCase()) ? null : skillName;
@@ -27011,19 +27019,19 @@ function skillFilePath(tool, input2) {
27011
27019
  if (!READ_TOOL_NAMES.has(tool.toLowerCase())) return null;
27012
27020
  const parsedInput = typeof input2 === "string" ? safeJsonParse(input2, null) : input2;
27013
27021
  if (!isRecord(parsedInput)) return null;
27014
- const path10 = [parsedInput.path, parsedInput.filePath, parsedInput.file_path].find((value) => typeof value === "string" && value.length > 0);
27015
- return path10 && skillNameFromFilePath(path10) ? path10 : null;
27022
+ const path11 = [parsedInput.path, parsedInput.filePath, parsedInput.file_path].find((value) => typeof value === "string" && value.length > 0);
27023
+ return path11 && skillNameFromFilePath(path11) ? path11 : null;
27016
27024
  }
27017
27025
  function createCallDisplayMessage(message2) {
27018
27026
  if (message2.inputRequest) return { ...message2, type: "tool_call" };
27019
- const path10 = skillFilePath(message2.tool, message2.input);
27020
- const skillName = message2.server.toLowerCase() === "skills" ? message2.tool : path10 ? skillNameFromFilePath(path10) : parseSkillName(message2.tool, message2.input);
27027
+ const path11 = skillFilePath(message2.tool, message2.input);
27028
+ const skillName = message2.server.toLowerCase() === "skills" ? message2.tool : path11 ? skillNameFromFilePath(path11) : parseSkillName(message2.tool, message2.input);
27021
27029
  if (skillName === null) return { ...message2, type: "tool_call" };
27022
27030
  return {
27023
27031
  id: message2.id,
27024
27032
  type: "skill",
27025
27033
  skillName,
27026
- ...path10 ? { path: path10 } : {},
27034
+ ...path11 ? { path: path11 } : {},
27027
27035
  status: message2.status,
27028
27036
  timestamp: message2.timestamp
27029
27037
  };
@@ -27050,11 +27058,11 @@ var init_utils = __esm({
27050
27058
  });
27051
27059
 
27052
27060
  // ../shared/src/display-message/format.ts
27053
- function fileContentDiff(path10, content, action) {
27061
+ function fileContentDiff(path11, content, action) {
27054
27062
  const lines = content.replace(/\n$/, "").split("\n");
27055
27063
  return [
27056
- `--- ${action === "add" ? "/dev/null" : `a/${path10}`}`,
27057
- `+++ ${action === "add" ? `b/${path10}` : "/dev/null"}`,
27064
+ `--- ${action === "add" ? "/dev/null" : `a/${path11}`}`,
27065
+ `+++ ${action === "add" ? `b/${path11}` : "/dev/null"}`,
27058
27066
  action === "add" ? `@@ -0,0 +1,${lines.length} @@` : `@@ -1,${lines.length} +0,0 @@`,
27059
27067
  ...lines.map((line) => `${action === "add" ? "+" : "-"}${line}`)
27060
27068
  ].join("\n");
@@ -27069,8 +27077,8 @@ function skillNamesFromCommand(command) {
27069
27077
  if (!SKILL_READ_COMMANDS.has(name) || writesFiles(name, argv) || fileWrites(shellCommand).length > 0) return [];
27070
27078
  const paths = readCommandPaths(name, argv);
27071
27079
  const stdinTarget = shellCommand.stdinTarget?.replaceAll(SHELL_OPAQUE, "\u2026");
27072
- return (paths.length === 0 && stdinTarget ? [stdinTarget] : paths).flatMap((path10) => {
27073
- const resolved = path10.startsWith("~") ? path10 : resolveShellPath(shellCommand.dir, path10)?.replace(SCRIPT_ROOT, "");
27080
+ return (paths.length === 0 && stdinTarget ? [stdinTarget] : paths).flatMap((path11) => {
27081
+ const resolved = path11.startsWith("~") ? path11 : resolveShellPath(shellCommand.dir, path11)?.replace(SCRIPT_ROOT, "");
27074
27082
  const skillName = resolved && skillNameFromFilePath(resolved);
27075
27083
  return skillName ? [skillName] : [];
27076
27084
  });
@@ -27154,7 +27162,7 @@ var init_format2 = __esm({
27154
27162
  PATTERN_FLAGS = /* @__PURE__ */ new Set(["-e", "-f", "--file", "--regexp"]);
27155
27163
  SCRIPT_ROOT = "/";
27156
27164
  commandName = (argv) => argv[0].split("/").pop() ?? argv[0];
27157
- fileWrites = ({ writes }) => writes.filter(({ path: path10 }) => path10 !== "/dev/null");
27165
+ fileWrites = ({ writes }) => writes.filter(({ path: path11 }) => path11 !== "/dev/null");
27158
27166
  SKILL_READ_COMMANDS = /* @__PURE__ */ new Set(["awk", "bat", "cat", "head", "less", "more", "nl", "sed", "tail"]);
27159
27167
  }
27160
27168
  });
@@ -27269,17 +27277,17 @@ var require_visit = __commonJS({
27269
27277
  visit2.BREAK = BREAK;
27270
27278
  visit2.SKIP = SKIP;
27271
27279
  visit2.REMOVE = REMOVE;
27272
- function visit_(key, node2, visitor, path10) {
27273
- const ctrl = callVisitor(key, node2, visitor, path10);
27280
+ function visit_(key, node2, visitor, path11) {
27281
+ const ctrl = callVisitor(key, node2, visitor, path11);
27274
27282
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
27275
- replaceNode(key, path10, ctrl);
27276
- return visit_(key, ctrl, visitor, path10);
27283
+ replaceNode(key, path11, ctrl);
27284
+ return visit_(key, ctrl, visitor, path11);
27277
27285
  }
27278
27286
  if (typeof ctrl !== "symbol") {
27279
27287
  if (identity.isCollection(node2)) {
27280
- path10 = Object.freeze(path10.concat(node2));
27288
+ path11 = Object.freeze(path11.concat(node2));
27281
27289
  for (let i = 0; i < node2.items.length; ++i) {
27282
- const ci = visit_(i, node2.items[i], visitor, path10);
27290
+ const ci = visit_(i, node2.items[i], visitor, path11);
27283
27291
  if (typeof ci === "number")
27284
27292
  i = ci - 1;
27285
27293
  else if (ci === BREAK)
@@ -27290,13 +27298,13 @@ var require_visit = __commonJS({
27290
27298
  }
27291
27299
  }
27292
27300
  } else if (identity.isPair(node2)) {
27293
- path10 = Object.freeze(path10.concat(node2));
27294
- const ck = visit_("key", node2.key, visitor, path10);
27301
+ path11 = Object.freeze(path11.concat(node2));
27302
+ const ck = visit_("key", node2.key, visitor, path11);
27295
27303
  if (ck === BREAK)
27296
27304
  return BREAK;
27297
27305
  else if (ck === REMOVE)
27298
27306
  node2.key = null;
27299
- const cv = visit_("value", node2.value, visitor, path10);
27307
+ const cv = visit_("value", node2.value, visitor, path11);
27300
27308
  if (cv === BREAK)
27301
27309
  return BREAK;
27302
27310
  else if (cv === REMOVE)
@@ -27317,17 +27325,17 @@ var require_visit = __commonJS({
27317
27325
  visitAsync.BREAK = BREAK;
27318
27326
  visitAsync.SKIP = SKIP;
27319
27327
  visitAsync.REMOVE = REMOVE;
27320
- async function visitAsync_(key, node2, visitor, path10) {
27321
- const ctrl = await callVisitor(key, node2, visitor, path10);
27328
+ async function visitAsync_(key, node2, visitor, path11) {
27329
+ const ctrl = await callVisitor(key, node2, visitor, path11);
27322
27330
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
27323
- replaceNode(key, path10, ctrl);
27324
- return visitAsync_(key, ctrl, visitor, path10);
27331
+ replaceNode(key, path11, ctrl);
27332
+ return visitAsync_(key, ctrl, visitor, path11);
27325
27333
  }
27326
27334
  if (typeof ctrl !== "symbol") {
27327
27335
  if (identity.isCollection(node2)) {
27328
- path10 = Object.freeze(path10.concat(node2));
27336
+ path11 = Object.freeze(path11.concat(node2));
27329
27337
  for (let i = 0; i < node2.items.length; ++i) {
27330
- const ci = await visitAsync_(i, node2.items[i], visitor, path10);
27338
+ const ci = await visitAsync_(i, node2.items[i], visitor, path11);
27331
27339
  if (typeof ci === "number")
27332
27340
  i = ci - 1;
27333
27341
  else if (ci === BREAK)
@@ -27338,13 +27346,13 @@ var require_visit = __commonJS({
27338
27346
  }
27339
27347
  }
27340
27348
  } else if (identity.isPair(node2)) {
27341
- path10 = Object.freeze(path10.concat(node2));
27342
- const ck = await visitAsync_("key", node2.key, visitor, path10);
27349
+ path11 = Object.freeze(path11.concat(node2));
27350
+ const ck = await visitAsync_("key", node2.key, visitor, path11);
27343
27351
  if (ck === BREAK)
27344
27352
  return BREAK;
27345
27353
  else if (ck === REMOVE)
27346
27354
  node2.key = null;
27347
- const cv = await visitAsync_("value", node2.value, visitor, path10);
27355
+ const cv = await visitAsync_("value", node2.value, visitor, path11);
27348
27356
  if (cv === BREAK)
27349
27357
  return BREAK;
27350
27358
  else if (cv === REMOVE)
@@ -27371,23 +27379,23 @@ var require_visit = __commonJS({
27371
27379
  }
27372
27380
  return visitor;
27373
27381
  }
27374
- function callVisitor(key, node2, visitor, path10) {
27382
+ function callVisitor(key, node2, visitor, path11) {
27375
27383
  if (typeof visitor === "function")
27376
- return visitor(key, node2, path10);
27384
+ return visitor(key, node2, path11);
27377
27385
  if (identity.isMap(node2))
27378
- return visitor.Map?.(key, node2, path10);
27386
+ return visitor.Map?.(key, node2, path11);
27379
27387
  if (identity.isSeq(node2))
27380
- return visitor.Seq?.(key, node2, path10);
27388
+ return visitor.Seq?.(key, node2, path11);
27381
27389
  if (identity.isPair(node2))
27382
- return visitor.Pair?.(key, node2, path10);
27390
+ return visitor.Pair?.(key, node2, path11);
27383
27391
  if (identity.isScalar(node2))
27384
- return visitor.Scalar?.(key, node2, path10);
27392
+ return visitor.Scalar?.(key, node2, path11);
27385
27393
  if (identity.isAlias(node2))
27386
- return visitor.Alias?.(key, node2, path10);
27394
+ return visitor.Alias?.(key, node2, path11);
27387
27395
  return void 0;
27388
27396
  }
27389
- function replaceNode(key, path10, node2) {
27390
- const parent = path10[path10.length - 1];
27397
+ function replaceNode(key, path11, node2) {
27398
+ const parent = path11[path11.length - 1];
27391
27399
  if (identity.isCollection(parent)) {
27392
27400
  parent.items[key] = node2;
27393
27401
  } else if (identity.isPair(parent)) {
@@ -27997,10 +28005,10 @@ var require_Collection = __commonJS({
27997
28005
  var createNode = require_createNode();
27998
28006
  var identity = require_identity();
27999
28007
  var Node = require_Node();
28000
- function collectionFromPath(schema, path10, value) {
28008
+ function collectionFromPath(schema, path11, value) {
28001
28009
  let v = value;
28002
- for (let i = path10.length - 1; i >= 0; --i) {
28003
- const k = path10[i];
28010
+ for (let i = path11.length - 1; i >= 0; --i) {
28011
+ const k = path11[i];
28004
28012
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
28005
28013
  const a = [];
28006
28014
  a[k] = v;
@@ -28019,7 +28027,7 @@ var require_Collection = __commonJS({
28019
28027
  sourceObjects: /* @__PURE__ */ new Map()
28020
28028
  });
28021
28029
  }
28022
- var isEmptyPath = (path10) => path10 == null || typeof path10 === "object" && !!path10[Symbol.iterator]().next().done;
28030
+ var isEmptyPath = (path11) => path11 == null || typeof path11 === "object" && !!path11[Symbol.iterator]().next().done;
28023
28031
  var Collection = class extends Node.NodeBase {
28024
28032
  constructor(type, schema) {
28025
28033
  super(type);
@@ -28049,11 +28057,11 @@ var require_Collection = __commonJS({
28049
28057
  * be a Pair instance or a `{ key, value }` object, which may not have a key
28050
28058
  * that already exists in the map.
28051
28059
  */
28052
- addIn(path10, value) {
28053
- if (isEmptyPath(path10))
28060
+ addIn(path11, value) {
28061
+ if (isEmptyPath(path11))
28054
28062
  this.add(value);
28055
28063
  else {
28056
- const [key, ...rest] = path10;
28064
+ const [key, ...rest] = path11;
28057
28065
  const node2 = this.get(key, true);
28058
28066
  if (identity.isCollection(node2))
28059
28067
  node2.addIn(rest, value);
@@ -28067,8 +28075,8 @@ var require_Collection = __commonJS({
28067
28075
  * Removes a value from the collection.
28068
28076
  * @returns `true` if the item was found and removed.
28069
28077
  */
28070
- deleteIn(path10) {
28071
- const [key, ...rest] = path10;
28078
+ deleteIn(path11) {
28079
+ const [key, ...rest] = path11;
28072
28080
  if (rest.length === 0)
28073
28081
  return this.delete(key);
28074
28082
  const node2 = this.get(key, true);
@@ -28082,8 +28090,8 @@ var require_Collection = __commonJS({
28082
28090
  * scalar values from their surrounding node; to disable set `keepScalar` to
28083
28091
  * `true` (collections are always returned intact).
28084
28092
  */
28085
- getIn(path10, keepScalar) {
28086
- const [key, ...rest] = path10;
28093
+ getIn(path11, keepScalar) {
28094
+ const [key, ...rest] = path11;
28087
28095
  const node2 = this.get(key, true);
28088
28096
  if (rest.length === 0)
28089
28097
  return !keepScalar && identity.isScalar(node2) ? node2.value : node2;
@@ -28101,8 +28109,8 @@ var require_Collection = __commonJS({
28101
28109
  /**
28102
28110
  * Checks if the collection includes a value with the key `key`.
28103
28111
  */
28104
- hasIn(path10) {
28105
- const [key, ...rest] = path10;
28112
+ hasIn(path11) {
28113
+ const [key, ...rest] = path11;
28106
28114
  if (rest.length === 0)
28107
28115
  return this.has(key);
28108
28116
  const node2 = this.get(key, true);
@@ -28112,8 +28120,8 @@ var require_Collection = __commonJS({
28112
28120
  * Sets a value in this collection. For `!!set`, `value` needs to be a
28113
28121
  * boolean to add/remove the item from the set.
28114
28122
  */
28115
- setIn(path10, value) {
28116
- const [key, ...rest] = path10;
28123
+ setIn(path11, value) {
28124
+ const [key, ...rest] = path11;
28117
28125
  if (rest.length === 0) {
28118
28126
  this.set(key, value);
28119
28127
  } else {
@@ -30628,9 +30636,9 @@ var require_Document = __commonJS({
30628
30636
  this.contents.add(value);
30629
30637
  }
30630
30638
  /** Adds a value to the document. */
30631
- addIn(path10, value) {
30639
+ addIn(path11, value) {
30632
30640
  if (assertCollection(this.contents))
30633
- this.contents.addIn(path10, value);
30641
+ this.contents.addIn(path11, value);
30634
30642
  }
30635
30643
  /**
30636
30644
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -30705,14 +30713,14 @@ var require_Document = __commonJS({
30705
30713
  * Removes a value from the document.
30706
30714
  * @returns `true` if the item was found and removed.
30707
30715
  */
30708
- deleteIn(path10) {
30709
- if (Collection.isEmptyPath(path10)) {
30716
+ deleteIn(path11) {
30717
+ if (Collection.isEmptyPath(path11)) {
30710
30718
  if (this.contents == null)
30711
30719
  return false;
30712
30720
  this.contents = null;
30713
30721
  return true;
30714
30722
  }
30715
- return assertCollection(this.contents) ? this.contents.deleteIn(path10) : false;
30723
+ return assertCollection(this.contents) ? this.contents.deleteIn(path11) : false;
30716
30724
  }
30717
30725
  /**
30718
30726
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -30727,10 +30735,10 @@ var require_Document = __commonJS({
30727
30735
  * scalar values from their surrounding node; to disable set `keepScalar` to
30728
30736
  * `true` (collections are always returned intact).
30729
30737
  */
30730
- getIn(path10, keepScalar) {
30731
- if (Collection.isEmptyPath(path10))
30738
+ getIn(path11, keepScalar) {
30739
+ if (Collection.isEmptyPath(path11))
30732
30740
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
30733
- return identity.isCollection(this.contents) ? this.contents.getIn(path10, keepScalar) : void 0;
30741
+ return identity.isCollection(this.contents) ? this.contents.getIn(path11, keepScalar) : void 0;
30734
30742
  }
30735
30743
  /**
30736
30744
  * Checks if the document includes a value with the key `key`.
@@ -30741,10 +30749,10 @@ var require_Document = __commonJS({
30741
30749
  /**
30742
30750
  * Checks if the document includes a value at `path`.
30743
30751
  */
30744
- hasIn(path10) {
30745
- if (Collection.isEmptyPath(path10))
30752
+ hasIn(path11) {
30753
+ if (Collection.isEmptyPath(path11))
30746
30754
  return this.contents !== void 0;
30747
- return identity.isCollection(this.contents) ? this.contents.hasIn(path10) : false;
30755
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path11) : false;
30748
30756
  }
30749
30757
  /**
30750
30758
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -30761,13 +30769,13 @@ var require_Document = __commonJS({
30761
30769
  * Sets a value in this document. For `!!set`, `value` needs to be a
30762
30770
  * boolean to add/remove the item from the set.
30763
30771
  */
30764
- setIn(path10, value) {
30765
- if (Collection.isEmptyPath(path10)) {
30772
+ setIn(path11, value) {
30773
+ if (Collection.isEmptyPath(path11)) {
30766
30774
  this.contents = value;
30767
30775
  } else if (this.contents == null) {
30768
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path10), value);
30776
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path11), value);
30769
30777
  } else if (assertCollection(this.contents)) {
30770
- this.contents.setIn(path10, value);
30778
+ this.contents.setIn(path11, value);
30771
30779
  }
30772
30780
  }
30773
30781
  /**
@@ -32727,9 +32735,9 @@ var require_cst_visit = __commonJS({
32727
32735
  visit2.BREAK = BREAK;
32728
32736
  visit2.SKIP = SKIP;
32729
32737
  visit2.REMOVE = REMOVE;
32730
- visit2.itemAtPath = (cst, path10) => {
32738
+ visit2.itemAtPath = (cst, path11) => {
32731
32739
  let item = cst;
32732
- for (const [field2, index] of path10) {
32740
+ for (const [field2, index] of path11) {
32733
32741
  const tok = item?.[field2];
32734
32742
  if (tok && "items" in tok) {
32735
32743
  item = tok.items[index];
@@ -32738,23 +32746,23 @@ var require_cst_visit = __commonJS({
32738
32746
  }
32739
32747
  return item;
32740
32748
  };
32741
- visit2.parentCollection = (cst, path10) => {
32742
- const parent = visit2.itemAtPath(cst, path10.slice(0, -1));
32743
- const field2 = path10[path10.length - 1][0];
32749
+ visit2.parentCollection = (cst, path11) => {
32750
+ const parent = visit2.itemAtPath(cst, path11.slice(0, -1));
32751
+ const field2 = path11[path11.length - 1][0];
32744
32752
  const coll = parent?.[field2];
32745
32753
  if (coll && "items" in coll)
32746
32754
  return coll;
32747
32755
  throw new Error("Parent collection not found");
32748
32756
  };
32749
- function _visit(path10, item, visitor) {
32750
- let ctrl = visitor(item, path10);
32757
+ function _visit(path11, item, visitor) {
32758
+ let ctrl = visitor(item, path11);
32751
32759
  if (typeof ctrl === "symbol")
32752
32760
  return ctrl;
32753
32761
  for (const field2 of ["key", "value"]) {
32754
32762
  const token = item[field2];
32755
32763
  if (token && "items" in token) {
32756
32764
  for (let i = 0; i < token.items.length; ++i) {
32757
- const ci = _visit(Object.freeze(path10.concat([[field2, i]])), token.items[i], visitor);
32765
+ const ci = _visit(Object.freeze(path11.concat([[field2, i]])), token.items[i], visitor);
32758
32766
  if (typeof ci === "number")
32759
32767
  i = ci - 1;
32760
32768
  else if (ci === BREAK)
@@ -32765,10 +32773,10 @@ var require_cst_visit = __commonJS({
32765
32773
  }
32766
32774
  }
32767
32775
  if (typeof ctrl === "function" && field2 === "key")
32768
- ctrl = ctrl(item, path10);
32776
+ ctrl = ctrl(item, path11);
32769
32777
  }
32770
32778
  }
32771
- return typeof ctrl === "function" ? ctrl(item, path10) : ctrl;
32779
+ return typeof ctrl === "function" ? ctrl(item, path11) : ctrl;
32772
32780
  }
32773
32781
  exports2.visit = visit2;
32774
32782
  }
@@ -34070,14 +34078,14 @@ var require_parser = __commonJS({
34070
34078
  case "scalar":
34071
34079
  case "single-quoted-scalar":
34072
34080
  case "double-quoted-scalar": {
34073
- const fs11 = this.flowScalar(this.type);
34081
+ const fs12 = this.flowScalar(this.type);
34074
34082
  if (atNextItem || it.value) {
34075
- map2.items.push({ start, key: fs11, sep: [] });
34083
+ map2.items.push({ start, key: fs12, sep: [] });
34076
34084
  this.onKeyLine = true;
34077
34085
  } else if (it.sep) {
34078
- this.stack.push(fs11);
34086
+ this.stack.push(fs12);
34079
34087
  } else {
34080
- Object.assign(it, { key: fs11, sep: [] });
34088
+ Object.assign(it, { key: fs12, sep: [] });
34081
34089
  this.onKeyLine = true;
34082
34090
  }
34083
34091
  return;
@@ -34205,13 +34213,13 @@ var require_parser = __commonJS({
34205
34213
  case "scalar":
34206
34214
  case "single-quoted-scalar":
34207
34215
  case "double-quoted-scalar": {
34208
- const fs11 = this.flowScalar(this.type);
34216
+ const fs12 = this.flowScalar(this.type);
34209
34217
  if (!it || it.value)
34210
- fc.items.push({ start: [], key: fs11, sep: [] });
34218
+ fc.items.push({ start: [], key: fs12, sep: [] });
34211
34219
  else if (it.sep)
34212
- this.stack.push(fs11);
34220
+ this.stack.push(fs12);
34213
34221
  else
34214
- Object.assign(it, { key: fs11, sep: [] });
34222
+ Object.assign(it, { key: fs12, sep: [] });
34215
34223
  return;
34216
34224
  }
34217
34225
  case "flow-map-end":
@@ -34581,6 +34589,7 @@ var init_mothership_board = __esm({
34581
34589
  init_zod();
34582
34590
  init_mothership();
34583
34591
  init_mothership_events();
34592
+ init_urls();
34584
34593
  MOTHERSHIP_TICKET_LIMITS = {
34585
34594
  title: 80,
34586
34595
  task: 1e3,
@@ -34637,7 +34646,7 @@ var init_mothership_board = __esm({
34637
34646
  pull_requests: external_exports.array(httpsUrl).max(20).optional().describe("Pull request URLs that came out of this ticket's task. They move here from any other ticket. Each pull request is filed under the ticket its ship was working on when it opened it, so pass this only to correct that."),
34638
34647
  note: clearable(text3(L.note)).describe(`Your one short comment on the ticket, shown under its row, replacing the last. "" removes it. At most ${L.note} characters.`),
34639
34648
  linear: clearable(linearIdentifier).describe('The Linear issue this ticket is for, such as REP-123. "" removes it.'),
34640
- archived: external_exports.boolean().optional().describe("Take it off the board.")
34649
+ archived: external_exports.boolean().optional().describe("true takes it off the board for good: closes its open pull requests without merging, stops their automatic fixes, and archives its ships unless they still have other tickets. false puts it back on the board.")
34641
34650
  })).max(50).optional().describe("Changes to existing tickets."),
34642
34651
  order: external_exports.array(external_exports.uuid()).optional().describe("Ticket ids, most important first. Tickets left out keep their order after these."),
34643
34652
  create: external_exports.array(external_exports.object({
@@ -34847,7 +34856,7 @@ function stripAttachmentNote(text4) {
34847
34856
  if (annotationsNote) content = content.slice(0, annotationsNote.index).trim();
34848
34857
  return {
34849
34858
  content,
34850
- files: match ? [...match[1].matchAll(/^- (.+)$/gm)].map(([, path10]) => path10) : [],
34859
+ files: match ? [...match[1].matchAll(/^- (.+)$/gm)].map(([, path11]) => path11) : [],
34851
34860
  walkthroughs,
34852
34861
  appshots,
34853
34862
  annotations: annotationsNote ? parseAnnotationsNote(annotationsNote.body) : []
@@ -35863,7 +35872,7 @@ function parseOpencodeEvents(events) {
35863
35872
  upsertDisplayMessage(messages, {
35864
35873
  id,
35865
35874
  type: "file_change",
35866
- changes: files.map((path10) => ({ path: path10, kind: "update" })),
35875
+ changes: files.map((path11) => ({ path: path11, kind: "update" })),
35867
35876
  status: "completed",
35868
35877
  timestamp
35869
35878
  });
@@ -37734,7 +37743,7 @@ var CLI_VERSION;
37734
37743
  var init_cli_version = __esm({
37735
37744
  "../shared/src/cli-version.ts"() {
37736
37745
  "use strict";
37737
- CLI_VERSION = "0.3.371";
37746
+ CLI_VERSION = "0.3.373";
37738
37747
  }
37739
37748
  });
37740
37749
 
@@ -38624,6 +38633,11 @@ var init_workspace_events = __esm({
38624
38633
  workspaceId: external_exports.string(),
38625
38634
  ts: external_exports.string()
38626
38635
  }),
38636
+ external_exports.object({
38637
+ type: external_exports.literal("local-control-request.changed"),
38638
+ workspaceId: external_exports.string(),
38639
+ ts: external_exports.string()
38640
+ }),
38627
38641
  external_exports.object({
38628
38642
  type: external_exports.literal("pull-request.changed"),
38629
38643
  prUrl: external_exports.string(),
@@ -48860,6 +48874,21 @@ var init_variable_requests = __esm({
48860
48874
  }
48861
48875
  });
48862
48876
 
48877
+ // ../shared/src/routes/local-control-requests.ts
48878
+ var createLocalControlRequestSchema, respondLocalControlRequestSchema, setLocalControlSchema;
48879
+ var init_local_control_requests = __esm({
48880
+ "../shared/src/routes/local-control-requests.ts"() {
48881
+ "use strict";
48882
+ init_zod();
48883
+ createLocalControlRequestSchema = external_exports.object({
48884
+ reason: external_exports.string().trim().max(500).optional().transform((value) => value || null),
48885
+ wait: external_exports.boolean().default(true)
48886
+ });
48887
+ respondLocalControlRequestSchema = external_exports.object({ action: external_exports.enum(["allow", "dismiss"]) });
48888
+ setLocalControlSchema = external_exports.object({ enabled: external_exports.boolean() });
48889
+ }
48890
+ });
48891
+
48863
48892
  // ../shared/src/websocket-liveness.ts
48864
48893
  function trackWebSocketLiveness(socket) {
48865
48894
  let answered = true;
@@ -49068,6 +49097,7 @@ var init_src = __esm({
49068
49097
  init_cli_auth();
49069
49098
  init_environment_setups();
49070
49099
  init_variable_requests();
49100
+ init_local_control_requests();
49071
49101
  init_api_casing();
49072
49102
  init_websocket_liveness();
49073
49103
  init_mothership_board();
@@ -50064,11 +50094,30 @@ async function confirmAction(message2) {
50064
50094
  if (!confirm) console.log(import_chalk7.default.yellow("\nCancelled."));
50065
50095
  return Boolean(confirm);
50066
50096
  }
50097
+ function parseRequestTimeout(value) {
50098
+ if (!value) return VARIABLE_REQUEST_WAIT.defaultMs;
50099
+ const timeout = /^(\d+)(s|m)?$/.exec(value.trim());
50100
+ if (!timeout) throw new Error(`Invalid timeout "${value}". Use seconds or minutes, for example 90s or 10m`);
50101
+ return Math.min(Math.max(Number(timeout[1]) * (timeout[2] === "m" ? 6e4 : 1e3), VARIABLE_REQUEST_WAIT.pollMs), VARIABLE_REQUEST_WAIT.maxMs);
50102
+ }
50103
+ async function waitForUser(params) {
50104
+ const { timeoutMs } = params;
50105
+ if (!isJsonMode()) console.log(import_chalk7.default.gray(`
50106
+ ${params.asked} Waiting up to ${timeoutMs >= 6e4 ? `${Math.round(timeoutMs / 6e4)} minute(s)` : `${timeoutMs / 1e3} seconds`}\u2026`));
50107
+ let value = params.initial;
50108
+ const deadline = Date.now() + timeoutMs;
50109
+ while (!params.settled(value) && Date.now() < deadline) {
50110
+ await new Promise((resolve3) => setTimeout(resolve3, VARIABLE_REQUEST_WAIT.pollMs));
50111
+ value = await params.poll(true);
50112
+ }
50113
+ return params.settled(value) ? value : params.poll(false);
50114
+ }
50067
50115
  var import_chalk7, import_prompts8;
50068
50116
  var init_command_utils = __esm({
50069
50117
  "src/lib/command-utils.ts"() {
50070
50118
  "use strict";
50071
50119
  import_chalk7 = __toESM(require("chalk"));
50120
+ init_src();
50072
50121
  import_prompts8 = __toESM(require("prompts"));
50073
50122
  init_config();
50074
50123
  init_output();
@@ -51058,8 +51107,8 @@ var init_claude_auth2 = __esm({
51058
51107
  });
51059
51108
 
51060
51109
  // src/lib/muse-oauth.ts
51061
- async function post(path10, body) {
51062
- return fetch(`${AUTH_URL}${path10}`, {
51110
+ async function post(path11, body) {
51111
+ return fetch(`${AUTH_URL}${path11}`, {
51063
51112
  method: "POST",
51064
51113
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
51065
51114
  body
@@ -51288,7 +51337,7 @@ async function credentialsGetCommand(service, options) {
51288
51337
  });
51289
51338
  }
51290
51339
  async function credentialsSetCommand(service, options) {
51291
- const path10 = credentialsPath(service, options, true);
51340
+ const path11 = credentialsPath(service, options, true);
51292
51341
  const { org: org2, models, ...fields } = options;
51293
51342
  const secretField = service === "bedrock" ? "aws_secret_access_key" : "api_key";
51294
51343
  const body = {
@@ -51296,7 +51345,7 @@ async function credentialsSetCommand(service, options) {
51296
51345
  ...models ? { models: models.split(",").map((model2) => model2.trim()).filter(Boolean) } : {},
51297
51346
  [secretField]: await readSecret(service, secretField === "api_key" ? "API key" : "AWS secret access key")
51298
51347
  };
51299
- const response = await orgAuthenticatedFetch(path10, { method: "POST", body });
51348
+ const response = await orgAuthenticatedFetch(path11, { method: "POST", body });
51300
51349
  output2(response, () => console.log(import_chalk17.default.green(`Saved ${scopeLabel(options)} ${service} credentials.`)));
51301
51350
  }
51302
51351
  async function credentialsRemoveCommand(service, options) {
@@ -51698,9 +51747,7 @@ async function envVarsRequestCommand(requiredKeys, options) {
51698
51747
  if (keys.length === 0) throw new Error("Name at least one variable to request");
51699
51748
  const invalid = keys.find((key) => !VARIABLE_KEY_RE.test(key));
51700
51749
  if (invalid) throw new Error(`${invalid} is not a valid environment variable name`);
51701
- const timeout = options.timeout ? /^(\d+)(s|m)?$/.exec(options.timeout.trim()) : null;
51702
- if (options.timeout && !timeout) throw new Error(`Invalid timeout "${options.timeout}". Use seconds or minutes, for example 90s or 10m`);
51703
- const timeoutMs = timeout ? Math.min(Math.max(Number(timeout[1]) * (timeout[2] === "m" ? 6e4 : 1e3), VARIABLE_REQUEST_WAIT.pollMs), VARIABLE_REQUEST_WAIT.maxMs) : VARIABLE_REQUEST_WAIT.defaultMs;
51750
+ const timeoutMs = parseRequestTimeout(options.timeout);
51704
51751
  const readRuntimeEnv = () => import_fs4.default.existsSync(RUNTIME_ENV_FILE) ? import_fs4.default.readFileSync(RUNTIME_ENV_FILE, "utf8") : "";
51705
51752
  const local = parsePosixEnvFile(readRuntimeEnv());
51706
51753
  const available = options.replace ? [] : keys.filter((key) => Object.hasOwn(local, key) && local[key].length > 0);
@@ -51723,14 +51770,14 @@ async function envVarsRequestCommand(requiredKeys, options) {
51723
51770
  });
51724
51771
  let { request } = created;
51725
51772
  if (request.status === "pending" && created.wait) {
51726
- if (!isJsonMode()) console.log(import_chalk20.default.gray(`
51727
- Asked the user for ${wanted.join(", ")} above the chat composer. Waiting up to ${timeoutMs >= 6e4 ? `${Math.round(timeoutMs / 6e4)} minute(s)` : `${timeoutMs / 1e3} seconds`}\u2026`));
51728
- const deadline = Date.now() + timeoutMs;
51729
- while (request.status === "pending" && Date.now() < deadline) {
51730
- await new Promise((resolve3) => setTimeout(resolve3, VARIABLE_REQUEST_WAIT.pollMs));
51731
- ({ request } = await orgAuthenticatedFetch(`/v1/variable-requests/${request.id}`));
51732
- }
51733
- if (request.status === "pending") ({ request } = await orgAuthenticatedFetch(`/v1/variable-requests/${request.id}?waiting=false`));
51773
+ const id = request.id;
51774
+ request = await waitForUser({
51775
+ timeoutMs,
51776
+ asked: `Asked the user for ${wanted.join(", ")} above the chat composer.`,
51777
+ initial: request,
51778
+ settled: (current) => current.status !== "pending",
51779
+ poll: async (waiting) => (await orgAuthenticatedFetch(`/v1/variable-requests/${id}${waiting ? "" : "?waiting=false"}`)).request
51780
+ });
51734
51781
  }
51735
51782
  let exported = [];
51736
51783
  if (request.status === "provided") {
@@ -52843,8 +52890,8 @@ async function chatQueueListCommand(id, chatId) {
52843
52890
  printQueue(queue);
52844
52891
  });
52845
52892
  }
52846
- async function mutateQueue(path10, method, body) {
52847
- output2(await orgAuthenticatedFetch(path10, { method, body }), ({ queue }) => {
52893
+ async function mutateQueue(path11, method, body) {
52894
+ output2(await orgAuthenticatedFetch(path11, { method, body }), ({ queue }) => {
52848
52895
  if (queue) printQueue(queue);
52849
52896
  else console.log("Done.");
52850
52897
  });
@@ -52857,7 +52904,7 @@ var init_chat = __esm({
52857
52904
  init_api2();
52858
52905
  init_output();
52859
52906
  init_replica2();
52860
- chatPath2 = (id, chatId, path10 = "") => `/v1/replica/${id}/chats/${chatId}${path10}`;
52907
+ chatPath2 = (id, chatId, path11 = "") => `/v1/replica/${id}/chats/${chatId}${path11}`;
52861
52908
  chatQueueClearCommand = (id, chatId) => mutateQueue(chatPath2(id, chatId, "/queue"), "DELETE");
52862
52909
  chatQueueRemoveCommand = (id, chatId, messageId) => mutateQueue(chatPath2(id, chatId, `/queue/${messageId}`), "DELETE");
52863
52910
  chatQueueEditCommand = (id, chatId, messageId, message2) => mutateQueue(chatPath2(id, chatId, `/queue/${messageId}`), "PATCH", { message: message2 });
@@ -52908,7 +52955,7 @@ var init_plugins3 = __esm({
52908
52955
  init_command_utils();
52909
52956
  init_output();
52910
52957
  init_environment3();
52911
- pluginsPath = async ({ env }, path10) => env ? `/v1/environments/${await resolveEnvironmentId(env)}/plugins${path10}` : `/v1/plugins${path10}`;
52958
+ pluginsPath = async ({ env }, path11) => env ? `/v1/environments/${await resolveEnvironmentId(env)}/plugins${path11}` : `/v1/plugins${path11}`;
52912
52959
  }
52913
52960
  });
52914
52961
 
@@ -53894,10 +53941,10 @@ var init_automation = __esm({
53894
53941
  });
53895
53942
 
53896
53943
  // src/lib/agent-api.ts
53897
- async function agentFetch(path10, options) {
53898
- return (await agentRequest(path10, options)).json();
53944
+ async function agentFetch(path11, options) {
53945
+ return (await agentRequest(path11, options)).json();
53899
53946
  }
53900
- async function agentRequest(path10, options) {
53947
+ async function agentRequest(path11, options) {
53901
53948
  const config3 = readAgentConfig();
53902
53949
  if (!config3) {
53903
53950
  throw new Error("Agent mode config not found");
@@ -53913,7 +53960,7 @@ async function agentRequest(path10, options) {
53913
53960
  ...options?.headers || {}
53914
53961
  };
53915
53962
  const body = rawBody === void 0 ? void 0 : rawBody instanceof FormData || rawBody instanceof ReadableStream ? rawBody : JSON.stringify(rawBody);
53916
- const response = await fetch(`${MONOLITH_URL}${path10}`, {
53963
+ const response = await fetch(`${MONOLITH_URL}${path11}`, {
53917
53964
  ...options,
53918
53965
  headers,
53919
53966
  body,
@@ -53925,7 +53972,7 @@ async function agentRequest(path10, options) {
53925
53972
  }
53926
53973
  return response;
53927
53974
  }
53928
- async function engineFetch(path10, options) {
53975
+ async function engineFetch(path11, options) {
53929
53976
  const config3 = readAgentConfig();
53930
53977
  if (!config3) {
53931
53978
  throw new Error("Agent mode config not found");
@@ -53935,7 +53982,7 @@ async function engineFetch(path10, options) {
53935
53982
  "Content-Type": "application/json",
53936
53983
  ...options?.headers || {}
53937
53984
  };
53938
- const response = await fetch(`http://localhost:${ENGINE_PORT2}${path10}`, {
53985
+ const response = await fetch(`http://localhost:${ENGINE_PORT2}${path11}`, {
53939
53986
  ...options,
53940
53987
  headers,
53941
53988
  body: options?.body !== void 0 ? JSON.stringify(options.body) : void 0
@@ -54822,21 +54869,21 @@ function assertTransferSize(bytes, localPath) {
54822
54869
  }
54823
54870
  }
54824
54871
  function archive(localPath) {
54825
- const path10 = (0, import_node_path2.resolve)(localPath);
54826
- if (!(0, import_node_fs2.existsSync)(path10)) throw new Error(`${path10} does not exist`);
54827
- if (!(0, import_node_fs2.statSync)(path10).isDirectory()) {
54828
- assertTransferSize((0, import_node_fs2.statSync)(path10).size, localPath);
54829
- return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", (0, import_node_path2.dirname)(path10), (0, import_node_path2.basename)(path10)], { stdio: ["ignore", "pipe", "pipe"] });
54872
+ const path11 = (0, import_node_path2.resolve)(localPath);
54873
+ if (!(0, import_node_fs2.existsSync)(path11)) throw new Error(`${path11} does not exist`);
54874
+ if (!(0, import_node_fs2.statSync)(path11).isDirectory()) {
54875
+ assertTransferSize((0, import_node_fs2.statSync)(path11).size, localPath);
54876
+ return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", (0, import_node_path2.dirname)(path11), (0, import_node_path2.basename)(path11)], { stdio: ["ignore", "pipe", "pipe"] });
54830
54877
  }
54831
- const listed = (0, import_node_child_process2.spawnSync)("git", ["-C", path10, "ls-files", "-co", "--exclude-standard", "-z"], { maxBuffer: 256 * 1024 * 1024 });
54878
+ const listed = (0, import_node_child_process2.spawnSync)("git", ["-C", path11, "ls-files", "-co", "--exclude-standard", "-z"], { maxBuffer: 256 * 1024 * 1024 });
54832
54879
  if (listed.status !== 0) {
54833
- const du = (0, import_node_child_process2.spawnSync)("du", ["-sk", "--exclude=.git", "--exclude=node_modules", path10]);
54880
+ const du = (0, import_node_child_process2.spawnSync)("du", ["-sk", "--exclude=.git", "--exclude=node_modules", path11]);
54834
54881
  assertTransferSize(Number(du.stdout.toString().split(" ")[0]) * 1024, localPath);
54835
- return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path10, "--exclude=.git", "--exclude=node_modules", "."], { stdio: ["ignore", "pipe", "pipe"] });
54882
+ return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path11, "--exclude=.git", "--exclude=node_modules", "."], { stdio: ["ignore", "pipe", "pipe"] });
54836
54883
  }
54837
- const files = listed.stdout.toString().split("\0").filter((file2) => file2 && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(path10, file2)));
54838
- assertTransferSize(files.reduce((total, file2) => total + (0, import_node_fs2.statSync)((0, import_node_path2.join)(path10, file2)).size, 0), localPath);
54839
- const child = (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path10, "--null", "-T", "-"], { stdio: ["pipe", "pipe", "pipe"] });
54884
+ const files = listed.stdout.toString().split("\0").filter((file2) => file2 && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(path11, file2)));
54885
+ assertTransferSize(files.reduce((total, file2) => total + (0, import_node_fs2.statSync)((0, import_node_path2.join)(path11, file2)).size, 0), localPath);
54886
+ const child = (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path11, "--null", "-T", "-"], { stdio: ["pipe", "pipe", "pipe"] });
54840
54887
  child.stdin.end(files.map((file2) => `${file2}\0`).join(""));
54841
54888
  return child;
54842
54889
  }
@@ -55394,6 +55441,81 @@ var init_device = __esm({
55394
55441
  }
55395
55442
  });
55396
55443
 
55444
+ // src/commands/local-control.ts
55445
+ async function connectedComputers() {
55446
+ const dir = import_path10.default.join(import_os5.default.homedir(), DEVICES_DIR);
55447
+ if (!import_fs11.default.existsSync(dir)) return [];
55448
+ const names = import_fs11.default.readdirSync(dir).flatMap((entry) => entry.startsWith(LOCAL_CONTROL_FILE_PREFIX) && entry.endsWith(".conf") ? [entry.slice(LOCAL_CONTROL_FILE_PREFIX.length, -".conf".length)] : []);
55449
+ const answers = await Promise.all(names.map((name) => execFileAsync2("ssh", ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10", name, "true"], { timeout: 2e4 }).then(() => true, () => false)));
55450
+ return names.filter((_, index) => answers[index]);
55451
+ }
55452
+ async function localControlRequestCommand(options) {
55453
+ ensureOrgApiAuthenticated();
55454
+ const timeoutMs = parseRequestTimeout(options.timeout);
55455
+ const connected = async (computers2) => {
55456
+ await orgAuthenticatedFetch("/v1/local-control-request", { method: "DELETE" });
55457
+ output2({ status: "connected", computers: computers2 }, () => {
55458
+ console.log(`
55459
+ ${import_chalk33.default.green("Connected:")} ${computers2.join(", ")}`);
55460
+ console.log(import_chalk33.default.gray(` Run commands there with: ssh ${computers2[0]} '<command>'
55461
+ `));
55462
+ });
55463
+ };
55464
+ const computers = await connectedComputers();
55465
+ if (computers.length > 0) return connected(computers);
55466
+ const created = await orgAuthenticatedFetch("/v1/local-control-request", {
55467
+ method: "POST",
55468
+ body: { reason: options.reason, wait: options.wait !== false }
55469
+ });
55470
+ let pending = true;
55471
+ if (created.wait) {
55472
+ const answer = await waitForUser({
55473
+ timeoutMs,
55474
+ asked: "Asked the user above the chat composer to let you run commands on their computer.",
55475
+ initial: { pending: true, computers: [] },
55476
+ settled: (current) => !current.pending || current.computers.length > 0,
55477
+ poll: async (waiting) => {
55478
+ const found = await connectedComputers();
55479
+ if (found.length > 0) return { pending: true, computers: found };
55480
+ return { ...await orgAuthenticatedFetch(`/v1/local-control-request${waiting ? "" : "?waiting=false"}`), computers: found };
55481
+ }
55482
+ });
55483
+ if (answer.computers.length > 0) return connected(answer.computers);
55484
+ ({ pending } = answer);
55485
+ }
55486
+ output2({ status: pending ? "pending" : "declined", computers: [], url: created.url }, () => {
55487
+ if (!pending) {
55488
+ console.log(import_chalk33.default.yellow("\n The user declined. Continue without their computer, or ask how they want to proceed.\n"));
55489
+ return;
55490
+ }
55491
+ console.log(import_chalk33.default.gray(options.wait === false ? `
55492
+ Asked above the chat composer (${created.url}). Keep working, and run this command again when you need the computer.
55493
+ ` : created.wait ? `
55494
+ The request stays open above the chat composer (${created.url}). End your turn and say what you need the computer for. When the user answers, you get a message; run this command again then.
55495
+ ` : `
55496
+ The user may not be watching Replicas. Send them this link where you are talking with them (the Slack thread, Linear issue, or pull request) and ask them to allow local control there: ${created.url}
55497
+ When they answer, you get a message; run this command again then.
55498
+ `));
55499
+ });
55500
+ }
55501
+ var import_child_process6, import_fs11, import_os5, import_path10, import_util10, import_chalk33, execFileAsync2;
55502
+ var init_local_control = __esm({
55503
+ "src/commands/local-control.ts"() {
55504
+ "use strict";
55505
+ import_child_process6 = require("child_process");
55506
+ import_fs11 = __toESM(require("fs"));
55507
+ import_os5 = __toESM(require("os"));
55508
+ import_path10 = __toESM(require("path"));
55509
+ import_util10 = require("util");
55510
+ import_chalk33 = __toESM(require("chalk"));
55511
+ init_src();
55512
+ init_api2();
55513
+ init_command_utils();
55514
+ init_output();
55515
+ execFileAsync2 = (0, import_util10.promisify)(import_child_process6.execFile);
55516
+ }
55517
+ });
55518
+
55397
55519
  // src/index.ts
55398
55520
  var src_exports = {};
55399
55521
  function parseBooleanOption(value) {
@@ -55466,6 +55588,7 @@ var init_src2 = __esm({
55466
55588
  init_service();
55467
55589
  init_environment3();
55468
55590
  init_device();
55591
+ init_local_control();
55469
55592
  init_config();
55470
55593
  init_organization2();
55471
55594
  init_output();
@@ -55634,6 +55757,9 @@ var init_src2 = __esm({
55634
55757
  if (isAgentMode()) {
55635
55758
  envVars.command("request [keys...]").description("Ask the user for variables and load them into this workspace").option("-r, --reason <text>", "One sentence on what the values are for, shown to the user").option("--optional <keys>", "Comma-separated keys to ask for that the user may leave empty (repeatable)", (value, previous) => [...previous, value], []).option("--replace", "Ask for new values even if the keys are already set, for example when a saved key is rejected").option("-t, --timeout <duration>", "How long to wait for the user, for example 90s or 10m (default 10m)").option("--no-wait", "Return right after asking instead of waiting for the user").action(run(envVarsRequestCommand));
55636
55759
  }
55760
+ if (isAgentMode()) {
55761
+ program.command("local-control").description("Reach the user's own computer through the Replicas desktop app").command("request").description("Ask the user to let you run commands on their computer, and wait until it connects").option("-r, --reason <text>", "One sentence on what you need the computer for, shown to the user").option("-t, --timeout <duration>", "How long to wait for the user, for example 90s or 10m (default 10m)").option("--no-wait", "Return right after asking instead of waiting for the user").action(run(localControlRequestCommand));
55762
+ }
55637
55763
  envFiles = environment.command("files").description("Manage environment files (mounted into workspaces at workspace start)");
55638
55764
  envFiles.command("list <env>").description("List files in an environment").action(run(envFilesListCommand));
55639
55765
  envFiles.command("set <env> <destination-path>").description("Create or update a file at <destination-path> inside the workspace").option("-c, --content <content>", "Inline file content").option("-f, --file <local-path>", "Read content from a local file").option("-n, --name <name>", "Display name (defaults to basename of destination path)").action(run(envFilesSetCommand));
@@ -55749,6 +55875,7 @@ ${VISUAL_PAGE_RULES}`).action(run(visualizeCommand));
55749
55875
  "skills",
55750
55876
  "slack",
55751
55877
  "computer",
55878
+ "local-control",
55752
55879
  "automation",
55753
55880
  "repos",
55754
55881
  "environment",
@@ -55787,11 +55914,11 @@ ${VISUAL_PAGE_RULES}`).action(run(visualizeCommand));
55787
55914
 
55788
55915
  // src/bin.ts
55789
55916
  var import_node_child_process5 = require("child_process");
55790
- var import_chalk33 = __toESM(require("chalk"));
55917
+ var import_chalk34 = __toESM(require("chalk"));
55791
55918
  init_config();
55792
55919
  if (process.argv[2] === "computer" && isAgentMode()) {
55793
55920
  const result = (0, import_node_child_process5.spawnSync)("replicas-computer", process.argv.slice(3), { stdio: "inherit" });
55794
- if (result.error) console.error(import_chalk33.default.red(`
55921
+ if (result.error) console.error(import_chalk34.default.red(`
55795
55922
  \u2717 replicas-computer is unavailable in this workspace image
55796
55923
  `));
55797
55924
  process.exitCode = result.error ? 1 : result.status ?? 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-cli",
3
- "version": "0.3.371",
3
+ "version": "0.3.373",
4
4
  "description": "CLI for managing Replicas workspaces - SSH into cloud dev environments with automatic port forwarding",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {