@standardagents/code 0.11.4 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1565,8 +1565,9 @@ var Bridge = class {
1565
1565
  } finally {
1566
1566
  this.hooks.onStatus?.(callKey, null);
1567
1567
  }
1568
- if (req.durable && req.toolCallId) {
1569
- this.ledger.record(req.toolCallId, {
1568
+ const ledgerKey = req.toolCallId ?? req.id;
1569
+ if (ledgerKey) {
1570
+ this.ledger.record(ledgerKey, {
1570
1571
  ok: result.ok,
1571
1572
  result: result.ok ? result.result ?? "" : void 0,
1572
1573
  error: result.ok ? void 0 : result.error
@@ -3299,6 +3300,7 @@ function parseToolCalls(message) {
3299
3300
  var EMPTY_BOUNDARY_STALE_MS = 15e4;
3300
3301
  var WAITING_FOR_CLIENT_MARKER = "Waiting for your machine to reconnect";
3301
3302
  var PENDING_TAIL_STALE_MS = 10 * 6e4;
3303
+ var FORWARDED_TOOL_STALE_MS = 6.5 * 6e4;
3302
3304
  var BUSY_TAIL_STALE_MS = 30 * 6e4;
3303
3305
  function toMs(raw) {
3304
3306
  return raw > 1e14 ? raw / 1e3 : raw < 1e12 ? raw * 1e3 : raw;
@@ -3328,7 +3330,17 @@ function deriveSessionActivity(messages, nowMs = Date.now()) {
3328
3330
  return { busy: true, currentTool: { ...tool ?? { id: last.tool_call_id ?? "", name: "forwarded", arguments: {} }, waitingForHost: true } };
3329
3331
  }
3330
3332
  const currentTool = unresolvedTool(visible);
3331
- if (currentTool) return { busy: true, currentTool };
3333
+ if (currentTool) {
3334
+ const carrier = [...visible].reverse().find((message) => {
3335
+ const raw = message.tool_calls;
3336
+ return typeof raw === "string" && raw.includes(currentTool.id);
3337
+ });
3338
+ const carrierMs = carrier ? toMs(createdAt(carrier)) : 0;
3339
+ if (carrierMs > 0 && nowMs - carrierMs > FORWARDED_TOOL_STALE_MS) {
3340
+ return { busy: false, currentTool: null, stalled: true };
3341
+ }
3342
+ return { busy: true, currentTool };
3343
+ }
3332
3344
  if (last.role === "user" || last.role === "tool") {
3333
3345
  const lastMs = toMs(createdAt(last));
3334
3346
  if (lastMs > 0 && nowMs - lastMs > BUSY_TAIL_STALE_MS) {
@@ -4464,7 +4476,7 @@ var Tui = class _Tui {
4464
4476
  // The `[⚙ n bg]` prompt badge can be selected with ← from the start of the
4465
4477
  // input (rendered inverted); Enter then opens the background-process panel.
4466
4478
  bgBadgeSelected = false;
4467
- queuedCount = 0;
4479
+ queuedMessages = [];
4468
4480
  subagents = [];
4469
4481
  // active subagents (one line each)
4470
4482
  subagentColorByID = /* @__PURE__ */ new Map();
@@ -5139,11 +5151,10 @@ var Tui = class _Tui {
5139
5151
  }
5140
5152
  /** The prompt line prefix (with ANSI colour) that precedes the typed text. */
5141
5153
  promptPrefix() {
5142
- const q = this.queuedCount > 0 ? `${C.yellow}[\u23F3 ${this.queuedCount} queued]${C.reset} ` : "";
5143
5154
  const attachments2 = this.externalAttachmentNames.length > 0 ? `${C.gray}[\u{1F4CE} ${this.externalAttachmentNames.length}]${C.reset} ` : "";
5144
5155
  const bgText = `[\u2699 ${this.bgCount} bg]`;
5145
5156
  const bg = this.bgCount > 0 ? this.bgBadgeSelected ? `${C.cyan}\x1B[7m${bgText}\x1B[27m${C.reset} ` : `${C.cyan}${bgText}${C.reset} ` : "";
5146
- return `${q}${attachments2}${bg}${this.levelColor()}\u276F${C.reset} `;
5157
+ return `${attachments2}${bg}${this.levelColor()}\u276F${C.reset} `;
5147
5158
  }
5148
5159
  visibleWidth(s) {
5149
5160
  let w = 0;
@@ -5331,6 +5342,13 @@ var Tui = class _Tui {
5331
5342
  }
5332
5343
  const goalLines = this.goalLines(workCols);
5333
5344
  for (const line of goalLines) writeHudRow(workPad + line);
5345
+ for (const [i, text] of this.queuedMessages.entries()) {
5346
+ const hint = i === 0 ? ` ${C.dim}esc to steer \xB7 /queue to edit${C.reset}` : "";
5347
+ const budget = workCols - 3 - (i === 0 ? 30 : 0);
5348
+ let msg = text.replace(/\s+/g, " ").trim();
5349
+ if (budget > 1 && msg.length > budget) msg = msg.slice(0, budget - 1) + "\u2026";
5350
+ writeHudRow(workPad + `${C.yellow}\u23F3${C.reset} ${C.gray}${msg}${C.reset}${hint}`);
5351
+ }
5334
5352
  const prefix = this.promptPrefix();
5335
5353
  const pw = this.visibleWidth(prefix);
5336
5354
  const borderAnimating = this.working;
@@ -5684,9 +5702,9 @@ var Tui = class _Tui {
5684
5702
  if (n === 0) this.bgBadgeSelected = false;
5685
5703
  this.renderBottom();
5686
5704
  }
5687
- setQueuedCount(n) {
5688
- if (n === this.queuedCount) return;
5689
- this.queuedCount = n;
5705
+ setQueuedMessages(texts) {
5706
+ if (texts.length === this.queuedMessages.length && texts.every((t, i) => t === this.queuedMessages[i])) return;
5707
+ this.queuedMessages = texts;
5690
5708
  this.renderBottom();
5691
5709
  }
5692
5710
  setConnected(connected) {
@@ -6439,10 +6457,10 @@ var PRODUCTION_ENDPOINT = "https://api.standardcode.ai";
6439
6457
  function readVersion() {
6440
6458
  try {
6441
6459
  const pkg = JSON.parse(fs5.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
6442
- return typeof pkg.version === "string" ? pkg.version : "";
6460
+ if (typeof pkg.version === "string" && pkg.version) return pkg.version;
6443
6461
  } catch {
6444
- return "";
6445
6462
  }
6463
+ return "0.11.6" ;
6446
6464
  }
6447
6465
  function isLocalHost(host) {
6448
6466
  return host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".local") || host.endsWith(".localhost") || /^10\./.test(host) || /^192\.168\./.test(host) || /^172\.(1[6-9]|2\d|3[01])\./.test(host);
@@ -8319,6 +8337,7 @@ function printUsage() {
8319
8337
  " standardcode [options] [dir]",
8320
8338
  "",
8321
8339
  `${c4.bold}Options${c4.reset}`,
8340
+ " -v, --version Print the Standard Code version and exit.",
8322
8341
  " -e, --endpoint [url] Use a different Standard Agents instance for this run",
8323
8342
  " (default: https://api.standardcode.ai).",
8324
8343
  " If url is omitted, prompt for it.",
@@ -8495,6 +8514,11 @@ ${indent}${c4.dim}\u2026 +${hidden} more line${hidden === 1 ? "" : "s"}${c4.rese
8495
8514
  return `${indent}${c4.yellow}\u26D4 ${rest}${c4.reset}`;
8496
8515
  }
8497
8516
  async function main() {
8517
+ if (process.argv.slice(2).some((arg) => arg === "-v" || arg === "--version")) {
8518
+ stdout.write(`${readVersion() || "unknown"}
8519
+ `);
8520
+ return;
8521
+ }
8498
8522
  if (process.argv[2] === "daemon") {
8499
8523
  await runDaemonCommand(process.argv.slice(3));
8500
8524
  return;
@@ -9429,7 +9453,7 @@ why: ${req.requestPermission}` : ""}`,
9429
9453
  sharedMessaging = firstSnapshot ? snapshot : mergeSharedMessagingSnapshot(sharedMessaging, snapshot);
9430
9454
  sharedMessagingReady = true;
9431
9455
  sharedMessagingUnavailableShown = false;
9432
- tui.setQueuedCount(sharedMessaging.pending.items.length);
9456
+ tui.setQueuedMessages(sharedMessaging.pending.items.map((item) => item.content));
9433
9457
  if (mirrorDraft && (firstSnapshot || sharedMessaging.draft.revision > previousDraftRevision) && (firstSnapshot || sharedMessaging.draft.originClientId !== messagingOrigin.originClientId)) {
9434
9458
  mirroredDraftRefs = sharedMessaging.draft.attachments.filter(isSharedAttachmentRef);
9435
9459
  tui.setExternalAttachmentNames(mirroredDraftRefs.map((attachment) => attachment.name));
@@ -9853,9 +9877,7 @@ ${c4.gray}Close another session (its slot frees within ~90s), then resend your m
9853
9877
  return;
9854
9878
  }
9855
9879
  if (busy) {
9856
- if (await appendSharedPending(text, images, draftRefs)) {
9857
- tui.print(`${c4.gray}\u23F3 pending:${c4.reset} ${text} ${c4.dim}(/queue to edit, steer, or dismiss)${c4.reset}`);
9858
- } else {
9880
+ if (await appendSharedPending(text, images, draftRefs)) ; else {
9859
9881
  mirroredDraftRefs = draftRefs;
9860
9882
  tui.setExternalAttachmentNames(draftRefs.map((attachment) => attachment.name));
9861
9883
  tui.setInput(text, images);
@@ -9882,8 +9904,13 @@ ${c4.gray}Close another session (its slot frees within ~90s), then resend your m
9882
9904
  return;
9883
9905
  }
9884
9906
  if (busy) {
9885
- const queued = sharedMessaging.pending.items.length;
9886
- tui.print(`${c4.yellow}\u25A0 stopping now${queued > 0 ? ` \u2014 ${queued} queued message${queued === 1 ? "" : "s"} kept` : ""}${c4.reset}`);
9907
+ const head = sharedMessaging.pending.items[0];
9908
+ if (head) {
9909
+ tui.print(`${c4.yellow}\u21AA steering \u2014 stopping the current step to run the queued message${c4.reset}`);
9910
+ void promoteSharedPending(head);
9911
+ return;
9912
+ }
9913
+ tui.print(`${c4.yellow}\u25A0 stopping now${c4.reset}`);
9887
9914
  const stops = [api.stopThread(threadId).catch(() => {
9888
9915
  })];
9889
9916
  for (const childId of activeSubagents.keys()) {
@@ -9990,6 +10017,7 @@ ${c4.dim}runs on ${request.machine || runnerName}${c4.reset}`,
9990
10017
  approvalPromptOpen = false;
9991
10018
  }
9992
10019
  };
10020
+ let stalledNoticeShown = false;
9993
10021
  const poll = async () => {
9994
10022
  let msgs;
9995
10023
  let serverBusy = null;
@@ -9999,6 +10027,14 @@ ${c4.dim}runs on ${request.machine || runnerName}${c4.reset}`,
9999
10027
  msgs = snapshot.messages.slice(-60);
10000
10028
  serverBusy = snapshot.busy;
10001
10029
  serverTool = snapshot.current_tool;
10030
+ if (snapshot.stalled && !stalledNoticeShown) {
10031
+ stalledNoticeShown = true;
10032
+ tui.print(
10033
+ `${c4.yellow}\u26A0 session interrupted${c4.reset} ${c4.dim}\u2014 the last operation never finished (the runtime is attempting recovery). Send a message to continue.${c4.reset}`
10034
+ );
10035
+ } else if (!snapshot.stalled && stalledNoticeShown && snapshot.busy) {
10036
+ stalledNoticeShown = false;
10037
+ }
10002
10038
  } catch {
10003
10039
  try {
10004
10040
  msgs = await api.getMessages(threadId, 60);
@@ -10116,7 +10152,7 @@ ${c4.dim}runs on ${request.machine || runnerName}${c4.reset}`,
10116
10152
  tui.setWorking(false);
10117
10153
  tui.setSubagents([]);
10118
10154
  tui.setGoal(null);
10119
- tui.setQueuedCount(0);
10155
+ tui.setQueuedMessages([]);
10120
10156
  tui.setContextPct(null);
10121
10157
  tui.setStep(null, 0);
10122
10158
  tui.setBackgroundCount(0);