replicas-cli 0.3.372 → 0.3.395

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 +288 -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 = {
@@ -26347,7 +26355,7 @@ function removeTag(text4, tag) {
26347
26355
  function stripReplicasInstructionBlock(text4) {
26348
26356
  return removeTag(text4, REPLICAS_INSTRUCTIONS_TAG);
26349
26357
  }
26350
- var REPLICAS_INSTRUCTIONS_TAG, MOTHERSHIP_INSTRUCTIONS_TAG, MOTHERSHIP_EVENT_CHAT_NOTE, BOARD_ANSWER_NOTE, BOARD_RULES, MOTHERSHIP_INSTRUCTIONS_BLOCK, T, SCOUT_LINEAR_RULES, SCOUT_MUTED_RULES, SCOUT_PRIOR_UNTAGGED_RULES, SCOUT_JOINED_RULES, SCOUT_REACTION_RULES;
26358
+ var REPLICAS_INSTRUCTIONS_TAG, MOTHERSHIP_INSTRUCTIONS_TAG, INSTRUCTIONS_OPEN, INSTRUCTIONS_CLOSE, MOTHERSHIP_EVENT_CHAT_NOTE, BOARD_ANSWER_NOTE, BOARD_RULES, MOTHERSHIP_INSTRUCTIONS_BLOCK, T, SCOUT_LINEAR_RULES, SCOUT_MUTED_RULES, SCOUT_PRIOR_UNTAGGED_RULES, SCOUT_JOINED_RULES, SCOUT_REACTION_RULES;
26351
26359
  var init_prompts = __esm({
26352
26360
  "../shared/src/prompts.ts"() {
26353
26361
  "use strict";
@@ -26364,6 +26372,8 @@ var init_prompts = __esm({
26364
26372
  init_slack_response_style();
26365
26373
  REPLICAS_INSTRUCTIONS_TAG = "replicas_instructions";
26366
26374
  MOTHERSHIP_INSTRUCTIONS_TAG = "multitask_instructions";
26375
+ INSTRUCTIONS_OPEN = `<${REPLICAS_INSTRUCTIONS_TAG}>`;
26376
+ INSTRUCTIONS_CLOSE = `</${REPLICAS_INSTRUCTIONS_TAG}>`;
26367
26377
  MOTHERSHIP_EVENT_CHAT_NOTE = `If a message the user typed in this turn is still unanswered, your final reply answers it and they see it. Otherwise they don't see text you write in this turn: if it brings something they asked for, or a blocker that needs them, send it with ${REPLICAS_MCP_TOOLS.sendToChat}; then update the board if its order, notes or overview changed, and end with a one-line note.`;
26368
26378
  BOARD_ANSWER_NOTE = "The user answered on the board.";
26369
26379
  BOARD_RULES = `- The board in the Ships pane beside this chat is the user's one view of the work. Each task the user asks for is one ticket, with only that task's pull requests. Spawning a ship creates its ticket from the \`title\` and \`task\` you pass. A ship works on one ticket at a time: when you give an existing ship a new, separate task with \`${REPLICAS_MCP_TOOLS.messageSubagent}\`, pass \`title\` so the task gets its own ticket. Pull requests are filed under the ticket their ship was on when it opened them; move one with \`pull_requests\` in \`${REPLICAS_MCP_TOOLS.updateBoard}\` only when that's wrong. Replicas files tickets under Needs you, Ready to review, Working or Done from the ship and the ticket's pull requests. Never restate what a ticket or pull request already shows.
@@ -26607,11 +26617,11 @@ function parseShellScript(script, cwd) {
26607
26617
  parseUntil(scope, 0, false);
26608
26618
  return scope.commands;
26609
26619
  }
26610
- function resolveShellPath(dir, path10) {
26611
- if (path10.includes(SHELL_OPAQUE) || path10.startsWith("~")) return null;
26612
- if (!path10.startsWith("/") && dir === null) return null;
26620
+ function resolveShellPath(dir, path11) {
26621
+ if (path11.includes(SHELL_OPAQUE) || path11.startsWith("~")) return null;
26622
+ if (!path11.startsWith("/") && dir === null) return null;
26613
26623
  const parts = [];
26614
- for (const part of (path10.startsWith("/") ? path10 : `${dir}/${path10}`).split("/")) {
26624
+ for (const part of (path11.startsWith("/") ? path11 : `${dir}/${path11}`).split("/")) {
26615
26625
  if (part === "..") parts.pop();
26616
26626
  else if (part && part !== ".") parts.push(part);
26617
26627
  }
@@ -27001,8 +27011,8 @@ function parseSkillName(tool, input2) {
27001
27011
  const skillName = parsedInput.skill ?? parsedInput.name;
27002
27012
  return typeof skillName === "string" && skillName ? skillName : null;
27003
27013
  }
27004
- function skillNameFromFilePath(path10) {
27005
- const parts = path10.split(/[\\/]+/).filter(Boolean);
27014
+ function skillNameFromFilePath(path11) {
27015
+ const parts = path11.split(/[\\/]+/).filter(Boolean);
27006
27016
  if (parts.length < 2 || parts[parts.length - 1].toLowerCase() !== "skill.md") return null;
27007
27017
  const skillName = parts[parts.length - 2];
27008
27018
  return /[*?[\]{}…$]/.test(skillName) || ["skills", ".system"].includes(skillName.toLowerCase()) ? null : skillName;
@@ -27011,19 +27021,19 @@ function skillFilePath(tool, input2) {
27011
27021
  if (!READ_TOOL_NAMES.has(tool.toLowerCase())) return null;
27012
27022
  const parsedInput = typeof input2 === "string" ? safeJsonParse(input2, null) : input2;
27013
27023
  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;
27024
+ const path11 = [parsedInput.path, parsedInput.filePath, parsedInput.file_path].find((value) => typeof value === "string" && value.length > 0);
27025
+ return path11 && skillNameFromFilePath(path11) ? path11 : null;
27016
27026
  }
27017
27027
  function createCallDisplayMessage(message2) {
27018
27028
  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);
27029
+ const path11 = skillFilePath(message2.tool, message2.input);
27030
+ const skillName = message2.server.toLowerCase() === "skills" ? message2.tool : path11 ? skillNameFromFilePath(path11) : parseSkillName(message2.tool, message2.input);
27021
27031
  if (skillName === null) return { ...message2, type: "tool_call" };
27022
27032
  return {
27023
27033
  id: message2.id,
27024
27034
  type: "skill",
27025
27035
  skillName,
27026
- ...path10 ? { path: path10 } : {},
27036
+ ...path11 ? { path: path11 } : {},
27027
27037
  status: message2.status,
27028
27038
  timestamp: message2.timestamp
27029
27039
  };
@@ -27050,11 +27060,11 @@ var init_utils = __esm({
27050
27060
  });
27051
27061
 
27052
27062
  // ../shared/src/display-message/format.ts
27053
- function fileContentDiff(path10, content, action) {
27063
+ function fileContentDiff(path11, content, action) {
27054
27064
  const lines = content.replace(/\n$/, "").split("\n");
27055
27065
  return [
27056
- `--- ${action === "add" ? "/dev/null" : `a/${path10}`}`,
27057
- `+++ ${action === "add" ? `b/${path10}` : "/dev/null"}`,
27066
+ `--- ${action === "add" ? "/dev/null" : `a/${path11}`}`,
27067
+ `+++ ${action === "add" ? `b/${path11}` : "/dev/null"}`,
27058
27068
  action === "add" ? `@@ -0,0 +1,${lines.length} @@` : `@@ -1,${lines.length} +0,0 @@`,
27059
27069
  ...lines.map((line) => `${action === "add" ? "+" : "-"}${line}`)
27060
27070
  ].join("\n");
@@ -27069,8 +27079,8 @@ function skillNamesFromCommand(command) {
27069
27079
  if (!SKILL_READ_COMMANDS.has(name) || writesFiles(name, argv) || fileWrites(shellCommand).length > 0) return [];
27070
27080
  const paths = readCommandPaths(name, argv);
27071
27081
  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, "");
27082
+ return (paths.length === 0 && stdinTarget ? [stdinTarget] : paths).flatMap((path11) => {
27083
+ const resolved = path11.startsWith("~") ? path11 : resolveShellPath(shellCommand.dir, path11)?.replace(SCRIPT_ROOT, "");
27074
27084
  const skillName = resolved && skillNameFromFilePath(resolved);
27075
27085
  return skillName ? [skillName] : [];
27076
27086
  });
@@ -27154,7 +27164,7 @@ var init_format2 = __esm({
27154
27164
  PATTERN_FLAGS = /* @__PURE__ */ new Set(["-e", "-f", "--file", "--regexp"]);
27155
27165
  SCRIPT_ROOT = "/";
27156
27166
  commandName = (argv) => argv[0].split("/").pop() ?? argv[0];
27157
- fileWrites = ({ writes }) => writes.filter(({ path: path10 }) => path10 !== "/dev/null");
27167
+ fileWrites = ({ writes }) => writes.filter(({ path: path11 }) => path11 !== "/dev/null");
27158
27168
  SKILL_READ_COMMANDS = /* @__PURE__ */ new Set(["awk", "bat", "cat", "head", "less", "more", "nl", "sed", "tail"]);
27159
27169
  }
27160
27170
  });
@@ -27269,17 +27279,17 @@ var require_visit = __commonJS({
27269
27279
  visit2.BREAK = BREAK;
27270
27280
  visit2.SKIP = SKIP;
27271
27281
  visit2.REMOVE = REMOVE;
27272
- function visit_(key, node2, visitor, path10) {
27273
- const ctrl = callVisitor(key, node2, visitor, path10);
27282
+ function visit_(key, node2, visitor, path11) {
27283
+ const ctrl = callVisitor(key, node2, visitor, path11);
27274
27284
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
27275
- replaceNode(key, path10, ctrl);
27276
- return visit_(key, ctrl, visitor, path10);
27285
+ replaceNode(key, path11, ctrl);
27286
+ return visit_(key, ctrl, visitor, path11);
27277
27287
  }
27278
27288
  if (typeof ctrl !== "symbol") {
27279
27289
  if (identity.isCollection(node2)) {
27280
- path10 = Object.freeze(path10.concat(node2));
27290
+ path11 = Object.freeze(path11.concat(node2));
27281
27291
  for (let i = 0; i < node2.items.length; ++i) {
27282
- const ci = visit_(i, node2.items[i], visitor, path10);
27292
+ const ci = visit_(i, node2.items[i], visitor, path11);
27283
27293
  if (typeof ci === "number")
27284
27294
  i = ci - 1;
27285
27295
  else if (ci === BREAK)
@@ -27290,13 +27300,13 @@ var require_visit = __commonJS({
27290
27300
  }
27291
27301
  }
27292
27302
  } else if (identity.isPair(node2)) {
27293
- path10 = Object.freeze(path10.concat(node2));
27294
- const ck = visit_("key", node2.key, visitor, path10);
27303
+ path11 = Object.freeze(path11.concat(node2));
27304
+ const ck = visit_("key", node2.key, visitor, path11);
27295
27305
  if (ck === BREAK)
27296
27306
  return BREAK;
27297
27307
  else if (ck === REMOVE)
27298
27308
  node2.key = null;
27299
- const cv = visit_("value", node2.value, visitor, path10);
27309
+ const cv = visit_("value", node2.value, visitor, path11);
27300
27310
  if (cv === BREAK)
27301
27311
  return BREAK;
27302
27312
  else if (cv === REMOVE)
@@ -27317,17 +27327,17 @@ var require_visit = __commonJS({
27317
27327
  visitAsync.BREAK = BREAK;
27318
27328
  visitAsync.SKIP = SKIP;
27319
27329
  visitAsync.REMOVE = REMOVE;
27320
- async function visitAsync_(key, node2, visitor, path10) {
27321
- const ctrl = await callVisitor(key, node2, visitor, path10);
27330
+ async function visitAsync_(key, node2, visitor, path11) {
27331
+ const ctrl = await callVisitor(key, node2, visitor, path11);
27322
27332
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
27323
- replaceNode(key, path10, ctrl);
27324
- return visitAsync_(key, ctrl, visitor, path10);
27333
+ replaceNode(key, path11, ctrl);
27334
+ return visitAsync_(key, ctrl, visitor, path11);
27325
27335
  }
27326
27336
  if (typeof ctrl !== "symbol") {
27327
27337
  if (identity.isCollection(node2)) {
27328
- path10 = Object.freeze(path10.concat(node2));
27338
+ path11 = Object.freeze(path11.concat(node2));
27329
27339
  for (let i = 0; i < node2.items.length; ++i) {
27330
- const ci = await visitAsync_(i, node2.items[i], visitor, path10);
27340
+ const ci = await visitAsync_(i, node2.items[i], visitor, path11);
27331
27341
  if (typeof ci === "number")
27332
27342
  i = ci - 1;
27333
27343
  else if (ci === BREAK)
@@ -27338,13 +27348,13 @@ var require_visit = __commonJS({
27338
27348
  }
27339
27349
  }
27340
27350
  } else if (identity.isPair(node2)) {
27341
- path10 = Object.freeze(path10.concat(node2));
27342
- const ck = await visitAsync_("key", node2.key, visitor, path10);
27351
+ path11 = Object.freeze(path11.concat(node2));
27352
+ const ck = await visitAsync_("key", node2.key, visitor, path11);
27343
27353
  if (ck === BREAK)
27344
27354
  return BREAK;
27345
27355
  else if (ck === REMOVE)
27346
27356
  node2.key = null;
27347
- const cv = await visitAsync_("value", node2.value, visitor, path10);
27357
+ const cv = await visitAsync_("value", node2.value, visitor, path11);
27348
27358
  if (cv === BREAK)
27349
27359
  return BREAK;
27350
27360
  else if (cv === REMOVE)
@@ -27371,23 +27381,23 @@ var require_visit = __commonJS({
27371
27381
  }
27372
27382
  return visitor;
27373
27383
  }
27374
- function callVisitor(key, node2, visitor, path10) {
27384
+ function callVisitor(key, node2, visitor, path11) {
27375
27385
  if (typeof visitor === "function")
27376
- return visitor(key, node2, path10);
27386
+ return visitor(key, node2, path11);
27377
27387
  if (identity.isMap(node2))
27378
- return visitor.Map?.(key, node2, path10);
27388
+ return visitor.Map?.(key, node2, path11);
27379
27389
  if (identity.isSeq(node2))
27380
- return visitor.Seq?.(key, node2, path10);
27390
+ return visitor.Seq?.(key, node2, path11);
27381
27391
  if (identity.isPair(node2))
27382
- return visitor.Pair?.(key, node2, path10);
27392
+ return visitor.Pair?.(key, node2, path11);
27383
27393
  if (identity.isScalar(node2))
27384
- return visitor.Scalar?.(key, node2, path10);
27394
+ return visitor.Scalar?.(key, node2, path11);
27385
27395
  if (identity.isAlias(node2))
27386
- return visitor.Alias?.(key, node2, path10);
27396
+ return visitor.Alias?.(key, node2, path11);
27387
27397
  return void 0;
27388
27398
  }
27389
- function replaceNode(key, path10, node2) {
27390
- const parent = path10[path10.length - 1];
27399
+ function replaceNode(key, path11, node2) {
27400
+ const parent = path11[path11.length - 1];
27391
27401
  if (identity.isCollection(parent)) {
27392
27402
  parent.items[key] = node2;
27393
27403
  } else if (identity.isPair(parent)) {
@@ -27997,10 +28007,10 @@ var require_Collection = __commonJS({
27997
28007
  var createNode = require_createNode();
27998
28008
  var identity = require_identity();
27999
28009
  var Node = require_Node();
28000
- function collectionFromPath(schema, path10, value) {
28010
+ function collectionFromPath(schema, path11, value) {
28001
28011
  let v = value;
28002
- for (let i = path10.length - 1; i >= 0; --i) {
28003
- const k = path10[i];
28012
+ for (let i = path11.length - 1; i >= 0; --i) {
28013
+ const k = path11[i];
28004
28014
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
28005
28015
  const a = [];
28006
28016
  a[k] = v;
@@ -28019,7 +28029,7 @@ var require_Collection = __commonJS({
28019
28029
  sourceObjects: /* @__PURE__ */ new Map()
28020
28030
  });
28021
28031
  }
28022
- var isEmptyPath = (path10) => path10 == null || typeof path10 === "object" && !!path10[Symbol.iterator]().next().done;
28032
+ var isEmptyPath = (path11) => path11 == null || typeof path11 === "object" && !!path11[Symbol.iterator]().next().done;
28023
28033
  var Collection = class extends Node.NodeBase {
28024
28034
  constructor(type, schema) {
28025
28035
  super(type);
@@ -28049,11 +28059,11 @@ var require_Collection = __commonJS({
28049
28059
  * be a Pair instance or a `{ key, value }` object, which may not have a key
28050
28060
  * that already exists in the map.
28051
28061
  */
28052
- addIn(path10, value) {
28053
- if (isEmptyPath(path10))
28062
+ addIn(path11, value) {
28063
+ if (isEmptyPath(path11))
28054
28064
  this.add(value);
28055
28065
  else {
28056
- const [key, ...rest] = path10;
28066
+ const [key, ...rest] = path11;
28057
28067
  const node2 = this.get(key, true);
28058
28068
  if (identity.isCollection(node2))
28059
28069
  node2.addIn(rest, value);
@@ -28067,8 +28077,8 @@ var require_Collection = __commonJS({
28067
28077
  * Removes a value from the collection.
28068
28078
  * @returns `true` if the item was found and removed.
28069
28079
  */
28070
- deleteIn(path10) {
28071
- const [key, ...rest] = path10;
28080
+ deleteIn(path11) {
28081
+ const [key, ...rest] = path11;
28072
28082
  if (rest.length === 0)
28073
28083
  return this.delete(key);
28074
28084
  const node2 = this.get(key, true);
@@ -28082,8 +28092,8 @@ var require_Collection = __commonJS({
28082
28092
  * scalar values from their surrounding node; to disable set `keepScalar` to
28083
28093
  * `true` (collections are always returned intact).
28084
28094
  */
28085
- getIn(path10, keepScalar) {
28086
- const [key, ...rest] = path10;
28095
+ getIn(path11, keepScalar) {
28096
+ const [key, ...rest] = path11;
28087
28097
  const node2 = this.get(key, true);
28088
28098
  if (rest.length === 0)
28089
28099
  return !keepScalar && identity.isScalar(node2) ? node2.value : node2;
@@ -28101,8 +28111,8 @@ var require_Collection = __commonJS({
28101
28111
  /**
28102
28112
  * Checks if the collection includes a value with the key `key`.
28103
28113
  */
28104
- hasIn(path10) {
28105
- const [key, ...rest] = path10;
28114
+ hasIn(path11) {
28115
+ const [key, ...rest] = path11;
28106
28116
  if (rest.length === 0)
28107
28117
  return this.has(key);
28108
28118
  const node2 = this.get(key, true);
@@ -28112,8 +28122,8 @@ var require_Collection = __commonJS({
28112
28122
  * Sets a value in this collection. For `!!set`, `value` needs to be a
28113
28123
  * boolean to add/remove the item from the set.
28114
28124
  */
28115
- setIn(path10, value) {
28116
- const [key, ...rest] = path10;
28125
+ setIn(path11, value) {
28126
+ const [key, ...rest] = path11;
28117
28127
  if (rest.length === 0) {
28118
28128
  this.set(key, value);
28119
28129
  } else {
@@ -30628,9 +30638,9 @@ var require_Document = __commonJS({
30628
30638
  this.contents.add(value);
30629
30639
  }
30630
30640
  /** Adds a value to the document. */
30631
- addIn(path10, value) {
30641
+ addIn(path11, value) {
30632
30642
  if (assertCollection(this.contents))
30633
- this.contents.addIn(path10, value);
30643
+ this.contents.addIn(path11, value);
30634
30644
  }
30635
30645
  /**
30636
30646
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -30705,14 +30715,14 @@ var require_Document = __commonJS({
30705
30715
  * Removes a value from the document.
30706
30716
  * @returns `true` if the item was found and removed.
30707
30717
  */
30708
- deleteIn(path10) {
30709
- if (Collection.isEmptyPath(path10)) {
30718
+ deleteIn(path11) {
30719
+ if (Collection.isEmptyPath(path11)) {
30710
30720
  if (this.contents == null)
30711
30721
  return false;
30712
30722
  this.contents = null;
30713
30723
  return true;
30714
30724
  }
30715
- return assertCollection(this.contents) ? this.contents.deleteIn(path10) : false;
30725
+ return assertCollection(this.contents) ? this.contents.deleteIn(path11) : false;
30716
30726
  }
30717
30727
  /**
30718
30728
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -30727,10 +30737,10 @@ var require_Document = __commonJS({
30727
30737
  * scalar values from their surrounding node; to disable set `keepScalar` to
30728
30738
  * `true` (collections are always returned intact).
30729
30739
  */
30730
- getIn(path10, keepScalar) {
30731
- if (Collection.isEmptyPath(path10))
30740
+ getIn(path11, keepScalar) {
30741
+ if (Collection.isEmptyPath(path11))
30732
30742
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
30733
- return identity.isCollection(this.contents) ? this.contents.getIn(path10, keepScalar) : void 0;
30743
+ return identity.isCollection(this.contents) ? this.contents.getIn(path11, keepScalar) : void 0;
30734
30744
  }
30735
30745
  /**
30736
30746
  * Checks if the document includes a value with the key `key`.
@@ -30741,10 +30751,10 @@ var require_Document = __commonJS({
30741
30751
  /**
30742
30752
  * Checks if the document includes a value at `path`.
30743
30753
  */
30744
- hasIn(path10) {
30745
- if (Collection.isEmptyPath(path10))
30754
+ hasIn(path11) {
30755
+ if (Collection.isEmptyPath(path11))
30746
30756
  return this.contents !== void 0;
30747
- return identity.isCollection(this.contents) ? this.contents.hasIn(path10) : false;
30757
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path11) : false;
30748
30758
  }
30749
30759
  /**
30750
30760
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -30761,13 +30771,13 @@ var require_Document = __commonJS({
30761
30771
  * Sets a value in this document. For `!!set`, `value` needs to be a
30762
30772
  * boolean to add/remove the item from the set.
30763
30773
  */
30764
- setIn(path10, value) {
30765
- if (Collection.isEmptyPath(path10)) {
30774
+ setIn(path11, value) {
30775
+ if (Collection.isEmptyPath(path11)) {
30766
30776
  this.contents = value;
30767
30777
  } else if (this.contents == null) {
30768
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path10), value);
30778
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path11), value);
30769
30779
  } else if (assertCollection(this.contents)) {
30770
- this.contents.setIn(path10, value);
30780
+ this.contents.setIn(path11, value);
30771
30781
  }
30772
30782
  }
30773
30783
  /**
@@ -32727,9 +32737,9 @@ var require_cst_visit = __commonJS({
32727
32737
  visit2.BREAK = BREAK;
32728
32738
  visit2.SKIP = SKIP;
32729
32739
  visit2.REMOVE = REMOVE;
32730
- visit2.itemAtPath = (cst, path10) => {
32740
+ visit2.itemAtPath = (cst, path11) => {
32731
32741
  let item = cst;
32732
- for (const [field2, index] of path10) {
32742
+ for (const [field2, index] of path11) {
32733
32743
  const tok = item?.[field2];
32734
32744
  if (tok && "items" in tok) {
32735
32745
  item = tok.items[index];
@@ -32738,23 +32748,23 @@ var require_cst_visit = __commonJS({
32738
32748
  }
32739
32749
  return item;
32740
32750
  };
32741
- visit2.parentCollection = (cst, path10) => {
32742
- const parent = visit2.itemAtPath(cst, path10.slice(0, -1));
32743
- const field2 = path10[path10.length - 1][0];
32751
+ visit2.parentCollection = (cst, path11) => {
32752
+ const parent = visit2.itemAtPath(cst, path11.slice(0, -1));
32753
+ const field2 = path11[path11.length - 1][0];
32744
32754
  const coll = parent?.[field2];
32745
32755
  if (coll && "items" in coll)
32746
32756
  return coll;
32747
32757
  throw new Error("Parent collection not found");
32748
32758
  };
32749
- function _visit(path10, item, visitor) {
32750
- let ctrl = visitor(item, path10);
32759
+ function _visit(path11, item, visitor) {
32760
+ let ctrl = visitor(item, path11);
32751
32761
  if (typeof ctrl === "symbol")
32752
32762
  return ctrl;
32753
32763
  for (const field2 of ["key", "value"]) {
32754
32764
  const token = item[field2];
32755
32765
  if (token && "items" in token) {
32756
32766
  for (let i = 0; i < token.items.length; ++i) {
32757
- const ci = _visit(Object.freeze(path10.concat([[field2, i]])), token.items[i], visitor);
32767
+ const ci = _visit(Object.freeze(path11.concat([[field2, i]])), token.items[i], visitor);
32758
32768
  if (typeof ci === "number")
32759
32769
  i = ci - 1;
32760
32770
  else if (ci === BREAK)
@@ -32765,10 +32775,10 @@ var require_cst_visit = __commonJS({
32765
32775
  }
32766
32776
  }
32767
32777
  if (typeof ctrl === "function" && field2 === "key")
32768
- ctrl = ctrl(item, path10);
32778
+ ctrl = ctrl(item, path11);
32769
32779
  }
32770
32780
  }
32771
- return typeof ctrl === "function" ? ctrl(item, path10) : ctrl;
32781
+ return typeof ctrl === "function" ? ctrl(item, path11) : ctrl;
32772
32782
  }
32773
32783
  exports2.visit = visit2;
32774
32784
  }
@@ -34070,14 +34080,14 @@ var require_parser = __commonJS({
34070
34080
  case "scalar":
34071
34081
  case "single-quoted-scalar":
34072
34082
  case "double-quoted-scalar": {
34073
- const fs11 = this.flowScalar(this.type);
34083
+ const fs12 = this.flowScalar(this.type);
34074
34084
  if (atNextItem || it.value) {
34075
- map2.items.push({ start, key: fs11, sep: [] });
34085
+ map2.items.push({ start, key: fs12, sep: [] });
34076
34086
  this.onKeyLine = true;
34077
34087
  } else if (it.sep) {
34078
- this.stack.push(fs11);
34088
+ this.stack.push(fs12);
34079
34089
  } else {
34080
- Object.assign(it, { key: fs11, sep: [] });
34090
+ Object.assign(it, { key: fs12, sep: [] });
34081
34091
  this.onKeyLine = true;
34082
34092
  }
34083
34093
  return;
@@ -34205,13 +34215,13 @@ var require_parser = __commonJS({
34205
34215
  case "scalar":
34206
34216
  case "single-quoted-scalar":
34207
34217
  case "double-quoted-scalar": {
34208
- const fs11 = this.flowScalar(this.type);
34218
+ const fs12 = this.flowScalar(this.type);
34209
34219
  if (!it || it.value)
34210
- fc.items.push({ start: [], key: fs11, sep: [] });
34220
+ fc.items.push({ start: [], key: fs12, sep: [] });
34211
34221
  else if (it.sep)
34212
- this.stack.push(fs11);
34222
+ this.stack.push(fs12);
34213
34223
  else
34214
- Object.assign(it, { key: fs11, sep: [] });
34224
+ Object.assign(it, { key: fs12, sep: [] });
34215
34225
  return;
34216
34226
  }
34217
34227
  case "flow-map-end":
@@ -34848,7 +34858,7 @@ function stripAttachmentNote(text4) {
34848
34858
  if (annotationsNote) content = content.slice(0, annotationsNote.index).trim();
34849
34859
  return {
34850
34860
  content,
34851
- files: match ? [...match[1].matchAll(/^- (.+)$/gm)].map(([, path10]) => path10) : [],
34861
+ files: match ? [...match[1].matchAll(/^- (.+)$/gm)].map(([, path11]) => path11) : [],
34852
34862
  walkthroughs,
34853
34863
  appshots,
34854
34864
  annotations: annotationsNote ? parseAnnotationsNote(annotationsNote.body) : []
@@ -35864,7 +35874,7 @@ function parseOpencodeEvents(events) {
35864
35874
  upsertDisplayMessage(messages, {
35865
35875
  id,
35866
35876
  type: "file_change",
35867
- changes: files.map((path10) => ({ path: path10, kind: "update" })),
35877
+ changes: files.map((path11) => ({ path: path11, kind: "update" })),
35868
35878
  status: "completed",
35869
35879
  timestamp
35870
35880
  });
@@ -37735,7 +37745,7 @@ var CLI_VERSION;
37735
37745
  var init_cli_version = __esm({
37736
37746
  "../shared/src/cli-version.ts"() {
37737
37747
  "use strict";
37738
- CLI_VERSION = "0.3.372";
37748
+ CLI_VERSION = "0.3.395";
37739
37749
  }
37740
37750
  });
37741
37751
 
@@ -38625,6 +38635,11 @@ var init_workspace_events = __esm({
38625
38635
  workspaceId: external_exports.string(),
38626
38636
  ts: external_exports.string()
38627
38637
  }),
38638
+ external_exports.object({
38639
+ type: external_exports.literal("local-control-request.changed"),
38640
+ workspaceId: external_exports.string(),
38641
+ ts: external_exports.string()
38642
+ }),
38628
38643
  external_exports.object({
38629
38644
  type: external_exports.literal("pull-request.changed"),
38630
38645
  prUrl: external_exports.string(),
@@ -48861,6 +48876,21 @@ var init_variable_requests = __esm({
48861
48876
  }
48862
48877
  });
48863
48878
 
48879
+ // ../shared/src/routes/local-control-requests.ts
48880
+ var createLocalControlRequestSchema, respondLocalControlRequestSchema, setLocalControlSchema;
48881
+ var init_local_control_requests = __esm({
48882
+ "../shared/src/routes/local-control-requests.ts"() {
48883
+ "use strict";
48884
+ init_zod();
48885
+ createLocalControlRequestSchema = external_exports.object({
48886
+ reason: external_exports.string().trim().max(500).optional().transform((value) => value || null),
48887
+ wait: external_exports.boolean().default(true)
48888
+ });
48889
+ respondLocalControlRequestSchema = external_exports.object({ action: external_exports.enum(["allow", "dismiss"]) });
48890
+ setLocalControlSchema = external_exports.object({ enabled: external_exports.boolean() });
48891
+ }
48892
+ });
48893
+
48864
48894
  // ../shared/src/websocket-liveness.ts
48865
48895
  function trackWebSocketLiveness(socket) {
48866
48896
  let answered = true;
@@ -49069,6 +49099,7 @@ var init_src = __esm({
49069
49099
  init_cli_auth();
49070
49100
  init_environment_setups();
49071
49101
  init_variable_requests();
49102
+ init_local_control_requests();
49072
49103
  init_api_casing();
49073
49104
  init_websocket_liveness();
49074
49105
  init_mothership_board();
@@ -50065,11 +50096,30 @@ async function confirmAction(message2) {
50065
50096
  if (!confirm) console.log(import_chalk7.default.yellow("\nCancelled."));
50066
50097
  return Boolean(confirm);
50067
50098
  }
50099
+ function parseRequestTimeout(value) {
50100
+ if (!value) return VARIABLE_REQUEST_WAIT.defaultMs;
50101
+ const timeout = /^(\d+)(s|m)?$/.exec(value.trim());
50102
+ if (!timeout) throw new Error(`Invalid timeout "${value}". Use seconds or minutes, for example 90s or 10m`);
50103
+ return Math.min(Math.max(Number(timeout[1]) * (timeout[2] === "m" ? 6e4 : 1e3), VARIABLE_REQUEST_WAIT.pollMs), VARIABLE_REQUEST_WAIT.maxMs);
50104
+ }
50105
+ async function waitForUser(params) {
50106
+ const { timeoutMs } = params;
50107
+ if (!isJsonMode()) console.log(import_chalk7.default.gray(`
50108
+ ${params.asked} Waiting up to ${timeoutMs >= 6e4 ? `${Math.round(timeoutMs / 6e4)} minute(s)` : `${timeoutMs / 1e3} seconds`}\u2026`));
50109
+ let value = params.initial;
50110
+ const deadline = Date.now() + timeoutMs;
50111
+ while (!params.settled(value) && Date.now() < deadline) {
50112
+ await new Promise((resolve3) => setTimeout(resolve3, VARIABLE_REQUEST_WAIT.pollMs));
50113
+ value = await params.poll(true);
50114
+ }
50115
+ return params.settled(value) ? value : params.poll(false);
50116
+ }
50068
50117
  var import_chalk7, import_prompts8;
50069
50118
  var init_command_utils = __esm({
50070
50119
  "src/lib/command-utils.ts"() {
50071
50120
  "use strict";
50072
50121
  import_chalk7 = __toESM(require("chalk"));
50122
+ init_src();
50073
50123
  import_prompts8 = __toESM(require("prompts"));
50074
50124
  init_config();
50075
50125
  init_output();
@@ -51059,8 +51109,8 @@ var init_claude_auth2 = __esm({
51059
51109
  });
51060
51110
 
51061
51111
  // src/lib/muse-oauth.ts
51062
- async function post(path10, body) {
51063
- return fetch(`${AUTH_URL}${path10}`, {
51112
+ async function post(path11, body) {
51113
+ return fetch(`${AUTH_URL}${path11}`, {
51064
51114
  method: "POST",
51065
51115
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
51066
51116
  body
@@ -51289,7 +51339,7 @@ async function credentialsGetCommand(service, options) {
51289
51339
  });
51290
51340
  }
51291
51341
  async function credentialsSetCommand(service, options) {
51292
- const path10 = credentialsPath(service, options, true);
51342
+ const path11 = credentialsPath(service, options, true);
51293
51343
  const { org: org2, models, ...fields } = options;
51294
51344
  const secretField = service === "bedrock" ? "aws_secret_access_key" : "api_key";
51295
51345
  const body = {
@@ -51297,7 +51347,7 @@ async function credentialsSetCommand(service, options) {
51297
51347
  ...models ? { models: models.split(",").map((model2) => model2.trim()).filter(Boolean) } : {},
51298
51348
  [secretField]: await readSecret(service, secretField === "api_key" ? "API key" : "AWS secret access key")
51299
51349
  };
51300
- const response = await orgAuthenticatedFetch(path10, { method: "POST", body });
51350
+ const response = await orgAuthenticatedFetch(path11, { method: "POST", body });
51301
51351
  output2(response, () => console.log(import_chalk17.default.green(`Saved ${scopeLabel(options)} ${service} credentials.`)));
51302
51352
  }
51303
51353
  async function credentialsRemoveCommand(service, options) {
@@ -51699,9 +51749,7 @@ async function envVarsRequestCommand(requiredKeys, options) {
51699
51749
  if (keys.length === 0) throw new Error("Name at least one variable to request");
51700
51750
  const invalid = keys.find((key) => !VARIABLE_KEY_RE.test(key));
51701
51751
  if (invalid) throw new Error(`${invalid} is not a valid environment variable name`);
51702
- const timeout = options.timeout ? /^(\d+)(s|m)?$/.exec(options.timeout.trim()) : null;
51703
- if (options.timeout && !timeout) throw new Error(`Invalid timeout "${options.timeout}". Use seconds or minutes, for example 90s or 10m`);
51704
- 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;
51752
+ const timeoutMs = parseRequestTimeout(options.timeout);
51705
51753
  const readRuntimeEnv = () => import_fs4.default.existsSync(RUNTIME_ENV_FILE) ? import_fs4.default.readFileSync(RUNTIME_ENV_FILE, "utf8") : "";
51706
51754
  const local = parsePosixEnvFile(readRuntimeEnv());
51707
51755
  const available = options.replace ? [] : keys.filter((key) => Object.hasOwn(local, key) && local[key].length > 0);
@@ -51724,14 +51772,14 @@ async function envVarsRequestCommand(requiredKeys, options) {
51724
51772
  });
51725
51773
  let { request } = created;
51726
51774
  if (request.status === "pending" && created.wait) {
51727
- if (!isJsonMode()) console.log(import_chalk20.default.gray(`
51728
- 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`));
51729
- const deadline = Date.now() + timeoutMs;
51730
- while (request.status === "pending" && Date.now() < deadline) {
51731
- await new Promise((resolve3) => setTimeout(resolve3, VARIABLE_REQUEST_WAIT.pollMs));
51732
- ({ request } = await orgAuthenticatedFetch(`/v1/variable-requests/${request.id}`));
51733
- }
51734
- if (request.status === "pending") ({ request } = await orgAuthenticatedFetch(`/v1/variable-requests/${request.id}?waiting=false`));
51775
+ const id = request.id;
51776
+ request = await waitForUser({
51777
+ timeoutMs,
51778
+ asked: `Asked the user for ${wanted.join(", ")} above the chat composer.`,
51779
+ initial: request,
51780
+ settled: (current) => current.status !== "pending",
51781
+ poll: async (waiting) => (await orgAuthenticatedFetch(`/v1/variable-requests/${id}${waiting ? "" : "?waiting=false"}`)).request
51782
+ });
51735
51783
  }
51736
51784
  let exported = [];
51737
51785
  if (request.status === "provided") {
@@ -52844,8 +52892,8 @@ async function chatQueueListCommand(id, chatId) {
52844
52892
  printQueue(queue);
52845
52893
  });
52846
52894
  }
52847
- async function mutateQueue(path10, method, body) {
52848
- output2(await orgAuthenticatedFetch(path10, { method, body }), ({ queue }) => {
52895
+ async function mutateQueue(path11, method, body) {
52896
+ output2(await orgAuthenticatedFetch(path11, { method, body }), ({ queue }) => {
52849
52897
  if (queue) printQueue(queue);
52850
52898
  else console.log("Done.");
52851
52899
  });
@@ -52858,7 +52906,7 @@ var init_chat = __esm({
52858
52906
  init_api2();
52859
52907
  init_output();
52860
52908
  init_replica2();
52861
- chatPath2 = (id, chatId, path10 = "") => `/v1/replica/${id}/chats/${chatId}${path10}`;
52909
+ chatPath2 = (id, chatId, path11 = "") => `/v1/replica/${id}/chats/${chatId}${path11}`;
52862
52910
  chatQueueClearCommand = (id, chatId) => mutateQueue(chatPath2(id, chatId, "/queue"), "DELETE");
52863
52911
  chatQueueRemoveCommand = (id, chatId, messageId) => mutateQueue(chatPath2(id, chatId, `/queue/${messageId}`), "DELETE");
52864
52912
  chatQueueEditCommand = (id, chatId, messageId, message2) => mutateQueue(chatPath2(id, chatId, `/queue/${messageId}`), "PATCH", { message: message2 });
@@ -52909,7 +52957,7 @@ var init_plugins3 = __esm({
52909
52957
  init_command_utils();
52910
52958
  init_output();
52911
52959
  init_environment3();
52912
- pluginsPath = async ({ env }, path10) => env ? `/v1/environments/${await resolveEnvironmentId(env)}/plugins${path10}` : `/v1/plugins${path10}`;
52960
+ pluginsPath = async ({ env }, path11) => env ? `/v1/environments/${await resolveEnvironmentId(env)}/plugins${path11}` : `/v1/plugins${path11}`;
52913
52961
  }
52914
52962
  });
52915
52963
 
@@ -53895,10 +53943,10 @@ var init_automation = __esm({
53895
53943
  });
53896
53944
 
53897
53945
  // src/lib/agent-api.ts
53898
- async function agentFetch(path10, options) {
53899
- return (await agentRequest(path10, options)).json();
53946
+ async function agentFetch(path11, options) {
53947
+ return (await agentRequest(path11, options)).json();
53900
53948
  }
53901
- async function agentRequest(path10, options) {
53949
+ async function agentRequest(path11, options) {
53902
53950
  const config3 = readAgentConfig();
53903
53951
  if (!config3) {
53904
53952
  throw new Error("Agent mode config not found");
@@ -53914,7 +53962,7 @@ async function agentRequest(path10, options) {
53914
53962
  ...options?.headers || {}
53915
53963
  };
53916
53964
  const body = rawBody === void 0 ? void 0 : rawBody instanceof FormData || rawBody instanceof ReadableStream ? rawBody : JSON.stringify(rawBody);
53917
- const response = await fetch(`${MONOLITH_URL}${path10}`, {
53965
+ const response = await fetch(`${MONOLITH_URL}${path11}`, {
53918
53966
  ...options,
53919
53967
  headers,
53920
53968
  body,
@@ -53926,7 +53974,7 @@ async function agentRequest(path10, options) {
53926
53974
  }
53927
53975
  return response;
53928
53976
  }
53929
- async function engineFetch(path10, options) {
53977
+ async function engineFetch(path11, options) {
53930
53978
  const config3 = readAgentConfig();
53931
53979
  if (!config3) {
53932
53980
  throw new Error("Agent mode config not found");
@@ -53936,7 +53984,7 @@ async function engineFetch(path10, options) {
53936
53984
  "Content-Type": "application/json",
53937
53985
  ...options?.headers || {}
53938
53986
  };
53939
- const response = await fetch(`http://localhost:${ENGINE_PORT2}${path10}`, {
53987
+ const response = await fetch(`http://localhost:${ENGINE_PORT2}${path11}`, {
53940
53988
  ...options,
53941
53989
  headers,
53942
53990
  body: options?.body !== void 0 ? JSON.stringify(options.body) : void 0
@@ -54823,21 +54871,21 @@ function assertTransferSize(bytes, localPath) {
54823
54871
  }
54824
54872
  }
54825
54873
  function archive(localPath) {
54826
- const path10 = (0, import_node_path2.resolve)(localPath);
54827
- if (!(0, import_node_fs2.existsSync)(path10)) throw new Error(`${path10} does not exist`);
54828
- if (!(0, import_node_fs2.statSync)(path10).isDirectory()) {
54829
- assertTransferSize((0, import_node_fs2.statSync)(path10).size, localPath);
54830
- 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"] });
54874
+ const path11 = (0, import_node_path2.resolve)(localPath);
54875
+ if (!(0, import_node_fs2.existsSync)(path11)) throw new Error(`${path11} does not exist`);
54876
+ if (!(0, import_node_fs2.statSync)(path11).isDirectory()) {
54877
+ assertTransferSize((0, import_node_fs2.statSync)(path11).size, localPath);
54878
+ 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"] });
54831
54879
  }
54832
- const listed = (0, import_node_child_process2.spawnSync)("git", ["-C", path10, "ls-files", "-co", "--exclude-standard", "-z"], { maxBuffer: 256 * 1024 * 1024 });
54880
+ const listed = (0, import_node_child_process2.spawnSync)("git", ["-C", path11, "ls-files", "-co", "--exclude-standard", "-z"], { maxBuffer: 256 * 1024 * 1024 });
54833
54881
  if (listed.status !== 0) {
54834
- const du = (0, import_node_child_process2.spawnSync)("du", ["-sk", "--exclude=.git", "--exclude=node_modules", path10]);
54882
+ const du = (0, import_node_child_process2.spawnSync)("du", ["-sk", "--exclude=.git", "--exclude=node_modules", path11]);
54835
54883
  assertTransferSize(Number(du.stdout.toString().split(" ")[0]) * 1024, localPath);
54836
- return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path10, "--exclude=.git", "--exclude=node_modules", "."], { stdio: ["ignore", "pipe", "pipe"] });
54884
+ return (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path11, "--exclude=.git", "--exclude=node_modules", "."], { stdio: ["ignore", "pipe", "pipe"] });
54837
54885
  }
54838
- const files = listed.stdout.toString().split("\0").filter((file2) => file2 && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(path10, file2)));
54839
- assertTransferSize(files.reduce((total, file2) => total + (0, import_node_fs2.statSync)((0, import_node_path2.join)(path10, file2)).size, 0), localPath);
54840
- const child = (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path10, "--null", "-T", "-"], { stdio: ["pipe", "pipe", "pipe"] });
54886
+ const files = listed.stdout.toString().split("\0").filter((file2) => file2 && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(path11, file2)));
54887
+ assertTransferSize(files.reduce((total, file2) => total + (0, import_node_fs2.statSync)((0, import_node_path2.join)(path11, file2)).size, 0), localPath);
54888
+ const child = (0, import_node_child_process2.spawn)("tar", ["-czf", "-", "-C", path11, "--null", "-T", "-"], { stdio: ["pipe", "pipe", "pipe"] });
54841
54889
  child.stdin.end(files.map((file2) => `${file2}\0`).join(""));
54842
54890
  return child;
54843
54891
  }
@@ -55395,6 +55443,81 @@ var init_device = __esm({
55395
55443
  }
55396
55444
  });
55397
55445
 
55446
+ // src/commands/local-control.ts
55447
+ async function connectedComputers() {
55448
+ const dir = import_path10.default.join(import_os5.default.homedir(), DEVICES_DIR);
55449
+ if (!import_fs11.default.existsSync(dir)) return [];
55450
+ 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)] : []);
55451
+ const answers = await Promise.all(names.map((name) => execFileAsync2("ssh", ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10", name, "true"], { timeout: 2e4 }).then(() => true, () => false)));
55452
+ return names.filter((_, index) => answers[index]);
55453
+ }
55454
+ async function localControlRequestCommand(options) {
55455
+ ensureOrgApiAuthenticated();
55456
+ const timeoutMs = parseRequestTimeout(options.timeout);
55457
+ const connected = async (computers2) => {
55458
+ await orgAuthenticatedFetch("/v1/local-control-request", { method: "DELETE" });
55459
+ output2({ status: "connected", computers: computers2 }, () => {
55460
+ console.log(`
55461
+ ${import_chalk33.default.green("Connected:")} ${computers2.join(", ")}`);
55462
+ console.log(import_chalk33.default.gray(` Run commands there with: ssh ${computers2[0]} '<command>'
55463
+ `));
55464
+ });
55465
+ };
55466
+ const computers = await connectedComputers();
55467
+ if (computers.length > 0) return connected(computers);
55468
+ const created = await orgAuthenticatedFetch("/v1/local-control-request", {
55469
+ method: "POST",
55470
+ body: { reason: options.reason, wait: options.wait !== false }
55471
+ });
55472
+ let pending = true;
55473
+ if (created.wait) {
55474
+ const answer = await waitForUser({
55475
+ timeoutMs,
55476
+ asked: "Asked the user above the chat composer to let you run commands on their computer.",
55477
+ initial: { pending: true, computers: [] },
55478
+ settled: (current) => !current.pending || current.computers.length > 0,
55479
+ poll: async (waiting) => {
55480
+ const found = await connectedComputers();
55481
+ if (found.length > 0) return { pending: true, computers: found };
55482
+ return { ...await orgAuthenticatedFetch(`/v1/local-control-request${waiting ? "" : "?waiting=false"}`), computers: found };
55483
+ }
55484
+ });
55485
+ if (answer.computers.length > 0) return connected(answer.computers);
55486
+ ({ pending } = answer);
55487
+ }
55488
+ output2({ status: pending ? "pending" : "declined", computers: [], url: created.url }, () => {
55489
+ if (!pending) {
55490
+ console.log(import_chalk33.default.yellow("\n The user declined. Continue without their computer, or ask how they want to proceed.\n"));
55491
+ return;
55492
+ }
55493
+ console.log(import_chalk33.default.gray(options.wait === false ? `
55494
+ Asked above the chat composer (${created.url}). Keep working, and run this command again when you need the computer.
55495
+ ` : created.wait ? `
55496
+ 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.
55497
+ ` : `
55498
+ 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}
55499
+ When they answer, you get a message; run this command again then.
55500
+ `));
55501
+ });
55502
+ }
55503
+ var import_child_process6, import_fs11, import_os5, import_path10, import_util10, import_chalk33, execFileAsync2;
55504
+ var init_local_control = __esm({
55505
+ "src/commands/local-control.ts"() {
55506
+ "use strict";
55507
+ import_child_process6 = require("child_process");
55508
+ import_fs11 = __toESM(require("fs"));
55509
+ import_os5 = __toESM(require("os"));
55510
+ import_path10 = __toESM(require("path"));
55511
+ import_util10 = require("util");
55512
+ import_chalk33 = __toESM(require("chalk"));
55513
+ init_src();
55514
+ init_api2();
55515
+ init_command_utils();
55516
+ init_output();
55517
+ execFileAsync2 = (0, import_util10.promisify)(import_child_process6.execFile);
55518
+ }
55519
+ });
55520
+
55398
55521
  // src/index.ts
55399
55522
  var src_exports = {};
55400
55523
  function parseBooleanOption(value) {
@@ -55467,6 +55590,7 @@ var init_src2 = __esm({
55467
55590
  init_service();
55468
55591
  init_environment3();
55469
55592
  init_device();
55593
+ init_local_control();
55470
55594
  init_config();
55471
55595
  init_organization2();
55472
55596
  init_output();
@@ -55635,6 +55759,9 @@ var init_src2 = __esm({
55635
55759
  if (isAgentMode()) {
55636
55760
  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));
55637
55761
  }
55762
+ if (isAgentMode()) {
55763
+ 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));
55764
+ }
55638
55765
  envFiles = environment.command("files").description("Manage environment files (mounted into workspaces at workspace start)");
55639
55766
  envFiles.command("list <env>").description("List files in an environment").action(run(envFilesListCommand));
55640
55767
  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));
@@ -55750,6 +55877,7 @@ ${VISUAL_PAGE_RULES}`).action(run(visualizeCommand));
55750
55877
  "skills",
55751
55878
  "slack",
55752
55879
  "computer",
55880
+ "local-control",
55753
55881
  "automation",
55754
55882
  "repos",
55755
55883
  "environment",
@@ -55788,11 +55916,11 @@ ${VISUAL_PAGE_RULES}`).action(run(visualizeCommand));
55788
55916
 
55789
55917
  // src/bin.ts
55790
55918
  var import_node_child_process5 = require("child_process");
55791
- var import_chalk33 = __toESM(require("chalk"));
55919
+ var import_chalk34 = __toESM(require("chalk"));
55792
55920
  init_config();
55793
55921
  if (process.argv[2] === "computer" && isAgentMode()) {
55794
55922
  const result = (0, import_node_child_process5.spawnSync)("replicas-computer", process.argv.slice(3), { stdio: "inherit" });
55795
- if (result.error) console.error(import_chalk33.default.red(`
55923
+ if (result.error) console.error(import_chalk34.default.red(`
55796
55924
  \u2717 replicas-computer is unavailable in this workspace image
55797
55925
  `));
55798
55926
  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.372",
3
+ "version": "0.3.395",
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": {