@asteroidai/cli 1.9.193 → 1.9.224

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/asteroid.js CHANGED
@@ -374,7 +374,7 @@ var COMMANDS = [
374
374
  command: "catalog get",
375
375
  tool: "catalog_get",
376
376
  title: "Get catalog",
377
- description: "The organization's agent catalog: categories, portals and every live template. `accessLevel` is `granted` (can instantiate a `runnable` template) or `viewable` (locked). A template the organization has not added is `viewable`; `catalog_template_add` grants it. `organizationId` defaults to the caller's one organization. Template definitions are omitted; read one with `catalog_template_get`.",
377
+ description: "The organization's agent catalog: categories, portals and every runnable template, with its category and portal by name. `accessLevel` is `granted` (can instantiate) or `viewable` (locked). A template the organization has not added is `viewable`; `catalog_template_add` grants it. Templates on a portal whose `portalType` is `mock` run against stand-in sites with sample data that Asteroid hosts: they are `granted` to every organization, need no credentials and touch nothing real. Offer them for a demo or when the user has no access to the real portal yet, and prefer a real portal's template otherwise. `organizationId` defaults to the caller's one organization. Template definitions are omitted; read one with `catalog_template_get`.",
378
378
  method: "GET",
379
379
  path: "/agents/v2/catalog",
380
380
  args: [],
@@ -435,7 +435,7 @@ var COMMANDS = [
435
435
  command: "catalog template instantiate",
436
436
  tool: "catalog_template_instantiate",
437
437
  title: "Instantiate catalog template",
438
- description: "Create a new workflow in the organization from a catalog template. Needs `accessLevel` `granted`: add the template with `catalog_template_add` first. Pass `credentials` (keyed by the portal's credential field keys) to create a profile, or `agentProfileId` to reuse one, or neither for a bare clone. Returns the workflow ID, its version ID and any profile ID. `organizationId` defaults to the caller's one organization.",
438
+ description: "Create a new workflow in the organization from a catalog template. Needs `accessLevel` `granted`: add the template with `catalog_template_add` first; a template on a `mock` portal is already granted. Pass `credentials` (keyed by the portal's credential field keys) to create a profile, or `agentProfileId` to reuse one, or neither for a bare clone. Returns the workflow ID, its version ID and any profile ID. `organizationId` defaults to the caller's one organization.",
439
439
  method: "POST",
440
440
  path: "/agents/v2/catalog/templates/{templateId}/instantiate",
441
441
  args: [
@@ -2245,8 +2245,8 @@ var COMMANDS = [
2245
2245
  {
2246
2246
  command: "execution sync",
2247
2247
  tool: "execution_sync",
2248
- title: "Wait for an execution to finish",
2249
- description: "Wait up to `timeoutSeconds` (1-25, default 25) for a running execution to finish. Returns the terminal `status` and `executionResult` when it finishes in time. Otherwise returns the current status: call it again to keep waiting. A paused or `awaiting_confirmation` execution returns at once, since it needs a person. Use it after `workflow_execute_post`, or after `workflow_execute_sync_post` timed out, instead of polling `execution_get`.",
2248
+ title: "Wait for an execution's status to change",
2249
+ description: "Wait up to `timeoutSeconds` (1-25, default 25) for an execution's status to change. Returns as soon as the status differs from the one it had when the call began. A `paused`, `paused_by_agent` or `awaiting_confirmation` execution returns at once, since it needs a person. `returnReason` says why it returned: `ended` (with `executionResult` when the run recorded one), `needs_person`, `status_change` or `timed_out`. After `status_change` or `timed_out`, call it again to keep following the run. On `awaiting_confirmation`, `awaitingConfirmation.nodeName` names the node the run holds at: get the user's go-ahead, then approve with `execution_resume`. Use it after `workflow_execute_post`, or after `workflow_execute_sync_post` timed out, instead of polling `execution_get`.",
2250
2250
  method: "GET",
2251
2251
  path: "/agents/v2/executions/{executionId}/sync",
2252
2252
  args: [
@@ -2263,7 +2263,7 @@ var COMMANDS = [
2263
2263
  flag: "timeout-seconds",
2264
2264
  type: "integer",
2265
2265
  required: false,
2266
- description: "Seconds to wait for the execution to finish before returning 202. Defaults to 25."
2266
+ description: "Seconds to wait for a change before returning 202. Defaults to 25."
2267
2267
  }
2268
2268
  ],
2269
2269
  binary: false,
@@ -6563,71 +6563,53 @@ function statusOf(error) {
6563
6563
 
6564
6564
  // src/sync/execution-wait.ts
6565
6565
  var WAIT_TIMEOUT_SECONDS = 600;
6566
- var WAIT_INTERVAL_SECONDS = 15;
6567
6566
  var MAX_WAIT_TIMEOUT_SECONDS = 3600;
6568
- var MAX_WAIT_INTERVAL_SECONDS = 120;
6569
- var TERMINAL = /* @__PURE__ */ new Set(["completed", "cancelled", "failed"]);
6570
- function isTerminalExecutionStatus(status) {
6571
- return TERMINAL.has(status);
6572
- }
6573
6567
  var SYNC_TIMEOUT_SECONDS = 25;
6574
- function pause(ms) {
6575
- return new Promise((resolve2) => setTimeout(resolve2, ms));
6576
- }
6577
- async function readStatus(sync, executionId2, timeoutMs) {
6578
- if (timeoutMs <= 0)
6579
- return await sync.remote.json(
6580
- get(`/agents/v2/executions/${executionId2}`)
6581
- );
6568
+ async function syncExecution(sync, executionId2, timeoutMs) {
6582
6569
  const timeoutSeconds = Math.min(
6583
6570
  SYNC_TIMEOUT_SECONDS,
6584
6571
  Math.max(1, Math.ceil(timeoutMs / 1e3))
6585
6572
  );
6586
- const response = await sync.remote.json(
6573
+ return await sync.remote.json(
6587
6574
  get(`/agents/v2/executions/${executionId2}/sync`, {
6588
6575
  timeoutSeconds: String(timeoutSeconds)
6589
6576
  })
6590
6577
  );
6591
- return {
6592
- id: response.executionId,
6593
- status: response.status,
6594
- executionResult: response.executionResult
6595
- };
6596
6578
  }
6597
6579
  async function waitForExecution(sync, options) {
6598
6580
  const timeoutMs = (options.timeoutSeconds ?? WAIT_TIMEOUT_SECONDS) * 1e3;
6599
- const intervalMs = (options.intervalSeconds ?? WAIT_INTERVAL_SECONDS) * 1e3;
6600
6581
  const now = options.now ?? Date.now;
6601
- const sleep = options.sleep ?? pause;
6602
6582
  const started = now();
6603
- let polls = 0;
6604
- for (; ; ) {
6605
- const called = now();
6606
- const execution = await readStatus(
6583
+ for (let polls = 1; ; polls++) {
6584
+ const execution = await syncExecution(
6607
6585
  sync,
6608
6586
  options.executionId,
6609
- timeoutMs - (called - started)
6587
+ timeoutMs - (now() - started)
6610
6588
  );
6611
- polls++;
6612
6589
  const elapsed = now() - started;
6613
- const waitedSeconds = Math.round(elapsed / 1e3);
6614
- if (isTerminalExecutionStatus(execution.status))
6615
- return { execution, terminal: true, waitedSeconds, polls };
6616
- const remaining = timeoutMs - elapsed;
6617
- if (remaining <= 0)
6618
- return { execution, terminal: false, waitedSeconds, polls };
6619
- const early = intervalMs - (now() - called);
6620
- if (early > 0) await sleep(Math.min(early, remaining));
6590
+ if (execution.returnReason !== "timed_out" || elapsed >= timeoutMs)
6591
+ return { execution, waitedSeconds: Math.round(elapsed / 1e3), polls };
6621
6592
  }
6622
6593
  }
6623
6594
  function formatExecutionWait(result) {
6624
6595
  const { execution } = result;
6625
- if (!result.terminal) {
6626
- return `Execution ${execution.id} still ${execution.status} after ${result.waitedSeconds}s. Wait again, or read what it has so far with \`asteroid execution pull ${execution.id}\`.`;
6596
+ const id = execution.executionId;
6597
+ const hold = execution.awaitingConfirmation;
6598
+ if (hold)
6599
+ return `Execution ${id} ${execution.status} at node "${hold.nodeName}". Approve it with \`asteroid execution resume ${id}\` once the user agrees.`;
6600
+ switch (execution.returnReason) {
6601
+ case "ended": {
6602
+ const line2 = `Execution ${id} ${execution.status}.`;
6603
+ const outcome = execution.executionResult;
6604
+ return outcome ? `${line2} Result: ${outcome.outcome}: ${outcome.reasoning}` : line2;
6605
+ }
6606
+ case "needs_person":
6607
+ return `Execution ${id} ${execution.status} and needs a person. Read why with \`asteroid execution activities ${id} --order desc\`.`;
6608
+ case "status_change":
6609
+ return `Execution ${id} is now ${execution.status}. Wait again to follow it.`;
6610
+ default:
6611
+ return `Execution ${id} still ${execution.status} after ${result.waitedSeconds}s. Wait again, or read what it has so far with \`asteroid execution pull ${id}\`.`;
6627
6612
  }
6628
- const line2 = `Execution ${execution.id} ${execution.status}.`;
6629
- const outcome = execution.executionResult;
6630
- return outcome ? `${line2} Result: ${outcome.outcome}: ${outcome.reasoning}` : line2;
6631
6613
  }
6632
6614
 
6633
6615
  // src/sync/commands.ts
@@ -6686,8 +6668,8 @@ var SYNC_COMMANDS = [
6686
6668
  ...local,
6687
6669
  command: "execution wait",
6688
6670
  tool: "execution_wait",
6689
- title: "Wait for an execution to end",
6690
- description: "Poll an execution until it is completed, failed or cancelled, then print its status and, when the run produced one, its result. When the timeout passes first, print the status it still has, so you can wait again.",
6671
+ title: "Wait for an execution's status to change",
6672
+ description: "Call `execution sync` until it reports a reason to stop, then print the status. It returns as soon as the run's status changes, at once when the run has ended or needs a person, and otherwise at the timeout, when it prints the status the run still has so you can wait again. On `awaiting_confirmation` it names the node the run holds at when the API reports one, and otherwise points to `asteroid execution activities`. Approve it with `asteroid execution resume <execution-id>` once the user agrees.",
6691
6673
  readOnly: true,
6692
6674
  args: [executionId],
6693
6675
  query: [
@@ -6695,11 +6677,6 @@ var SYNC_COMMANDS = [
6695
6677
  "timeout",
6696
6678
  "integer",
6697
6679
  `Give up after this many seconds, ${WAIT_TIMEOUT_SECONDS} unless set, ${MAX_WAIT_TIMEOUT_SECONDS} at most.`
6698
- ),
6699
- option(
6700
- "interval",
6701
- "integer",
6702
- `Poll every this many seconds, ${WAIT_INTERVAL_SECONDS} unless set, ${MAX_WAIT_INTERVAL_SECONDS} at most.`
6703
6680
  )
6704
6681
  ]
6705
6682
  },
@@ -6800,6 +6777,7 @@ function columns(rows, options) {
6800
6777
  scalarKeys.push(key);
6801
6778
  }
6802
6779
  }
6780
+ if (options.curated) return scalarKeys;
6803
6781
  const ordered = [
6804
6782
  ...PREFERRED.filter((key) => scalarKeys.includes(key)),
6805
6783
  ...scalarKeys.filter((key) => !PREFERRED.includes(key))
@@ -6824,22 +6802,22 @@ function flatten(row) {
6824
6802
  function table(input, options = {}) {
6825
6803
  if (input.length === 0) return "No results.";
6826
6804
  const rows = input.map(flatten);
6827
- const keys = columns(rows, options);
6828
- if (keys.length === 0) return rows.map((row) => text(row)).join("\n");
6829
- const cells = rows.map((row) => keys.map((key) => cell(row[key], options)));
6805
+ const keys2 = columns(rows, options);
6806
+ if (keys2.length === 0) return rows.map((row) => text(row)).join("\n");
6807
+ const cells = rows.map((row) => keys2.map((key) => cell(row[key], options)));
6830
6808
  if (options.styled) {
6831
6809
  const grid = new Table({
6832
- head: keys.map((key) => style("bold", key, options)),
6810
+ head: keys2.map((key) => style("bold", key, options)),
6833
6811
  style: { head: [], border: [] }
6834
6812
  });
6835
6813
  grid.push(...cells);
6836
6814
  return grid.toString();
6837
6815
  }
6838
- const widths = keys.map(
6816
+ const widths = keys2.map(
6839
6817
  (key, i) => Math.max(key.length, ...cells.map((r) => r[i].length))
6840
6818
  );
6841
6819
  const line2 = (values) => values.map((v, i) => v.padEnd(widths[i])).join(" ").trimEnd();
6842
- return [line2(keys.map((k) => k.toUpperCase())), ...cells.map(line2)].join(
6820
+ return [line2(keys2.map((k) => k.toUpperCase())), ...cells.map(line2)].join(
6843
6821
  "\n"
6844
6822
  );
6845
6823
  }
@@ -7226,6 +7204,8 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
7226
7204
  if (notes.length > 0) leaf.addHelpText("after", `
7227
7205
  ${notes.join("\n")}`);
7228
7206
  leafOptions(leaf, command);
7207
+ for (const [flags, text3] of options.extraOptions?.(command) ?? [])
7208
+ leaf.option(flags, text3);
7229
7209
  leaf.action((...args) => {
7230
7210
  const cmd = args.at(-1);
7231
7211
  let positionals = cmd.args;
@@ -7756,7 +7736,7 @@ var ApiError = class extends Error {
7756
7736
  status;
7757
7737
  body;
7758
7738
  };
7759
- var VERSION = "1.9.193";
7739
+ var VERSION = "1.9.224";
7760
7740
  function problem(status, body, fallback) {
7761
7741
  if (body && typeof body === "object") {
7762
7742
  const record2 = body;
@@ -8040,8 +8020,8 @@ function servedDigests(row, skipped) {
8040
8020
  }
8041
8021
  function sameDigests(a, b) {
8042
8022
  if (!a) return false;
8043
- const keys = Object.keys(a);
8044
- return keys.length === Object.keys(b).length && keys.every((path) => a[path] === b[path]);
8023
+ const keys2 = Object.keys(a);
8024
+ return keys2.length === Object.keys(b).length && keys2.every((path) => a[path] === b[path]);
8045
8025
  }
8046
8026
  function removeEmptyDirs(from, upTo) {
8047
8027
  let dir = from;
@@ -8419,8 +8399,8 @@ async function orgs(deps, flagOrg, json) {
8419
8399
  return 0;
8420
8400
  }
8421
8401
  function timeLeft(expiresAt) {
8422
- const minutes = Math.max(0, Math.round((expiresAt - Date.now()) / 6e4));
8423
- return minutes >= 60 ? `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}m` : `${minutes}m`;
8402
+ const minutes2 = Math.max(0, Math.round((expiresAt - Date.now()) / 6e4));
8403
+ return minutes2 >= 60 ? `${Math.floor(minutes2 / 60)}h${String(minutes2 % 60).padStart(2, "0")}m` : `${minutes2}m`;
8424
8404
  }
8425
8405
  function isMember(config, org) {
8426
8406
  return (config.orgs ?? []).some((o) => o.workosId === org.workosId);
@@ -8658,10 +8638,10 @@ async function whoami(deps, flagOrg, json) {
8658
8638
  deps.fetch
8659
8639
  );
8660
8640
  const body = response.json ?? {};
8661
- const minutes = auth.expiresAt ? Math.max(0, Math.round((auth.expiresAt - Date.now()) / 6e4)) : void 0;
8641
+ const minutes2 = auth.expiresAt ? Math.max(0, Math.round((auth.expiresAt - Date.now()) / 6e4)) : void 0;
8662
8642
  if (json) {
8663
8643
  deps.stdout(
8664
- `${JSON.stringify({ ...body, organizationName: auth.org?.name, tokenExpiresInMinutes: minutes }, null, 2)}
8644
+ `${JSON.stringify({ ...body, organizationName: auth.org?.name, tokenExpiresInMinutes: minutes2 }, null, 2)}
8665
8645
  `
8666
8646
  );
8667
8647
  return 0;
@@ -9712,8 +9692,7 @@ function bounded(parsed, name, min, max) {
9712
9692
  function executionWaitOptions(parsed) {
9713
9693
  return {
9714
9694
  executionId: parsed.positionals[0],
9715
- timeoutSeconds: bounded(parsed, "timeout", 0, MAX_WAIT_TIMEOUT_SECONDS),
9716
- intervalSeconds: bounded(parsed, "interval", 1, MAX_WAIT_INTERVAL_SECONDS)
9695
+ timeoutSeconds: bounded(parsed, "timeout", 0, MAX_WAIT_TIMEOUT_SECONDS)
9717
9696
  };
9718
9697
  }
9719
9698
  function given(value2, name) {
@@ -9826,6 +9805,44 @@ async function runSync(command, parsed, deps) {
9826
9805
  return 0;
9827
9806
  }
9828
9807
 
9808
+ // src/views.ts
9809
+ function minutes(timestamp) {
9810
+ if (typeof timestamp !== "string") return timestamp;
9811
+ return `${timestamp.slice(0, 10)} ${timestamp.slice(11, 16)}`;
9812
+ }
9813
+ function keys(fields) {
9814
+ if (!Array.isArray(fields)) return fields;
9815
+ return fields.map((field) => field.key).join(", ");
9816
+ }
9817
+ function catalog({ categories, portals, templates }) {
9818
+ return {
9819
+ categories: categories.map(({ id, name, description }) => ({
9820
+ id,
9821
+ name,
9822
+ description
9823
+ })),
9824
+ portals: portals.map(({ id, name, portalType, credentials }) => ({
9825
+ id,
9826
+ name,
9827
+ portalType,
9828
+ credentials: keys(credentials)
9829
+ })),
9830
+ templates: templates.map((template) => ({
9831
+ id: template.id,
9832
+ templateName: template.templateName,
9833
+ categoryName: template.categoryName,
9834
+ portalName: template.portalName,
9835
+ accessMethod: template.accessMethod,
9836
+ portalOperation: template.portalOperation,
9837
+ shortDescription: template.shortDescription,
9838
+ updatedAt: minutes(template.updatedAt)
9839
+ }))
9840
+ };
9841
+ }
9842
+ var VIEWS = {
9843
+ catalog_get: (json) => catalog(json)
9844
+ };
9845
+
9829
9846
  // src/run.ts
9830
9847
  function rejectOrgWithApiKey(deps, flagOrg) {
9831
9848
  if (deps.env.apiKey && (flagOrg || deps.env.org)) {
@@ -9925,10 +9942,12 @@ async function runCommand(command, parsed, deps) {
9925
9942
  return 0;
9926
9943
  }
9927
9944
  if (response.json !== void 0) {
9945
+ const view = VIEWS[command.tool];
9928
9946
  deps.stdout(
9929
- `${parsed.json ? JSON.stringify(response.json, null, 2) : render(response.json, {
9947
+ `${parsed.json ? JSON.stringify(response.json, null, 2) : render(view ? view(response.json) : response.json, {
9930
9948
  styled: deps.styled,
9931
- full: !deps.stdoutIsTTY
9949
+ full: !deps.stdoutIsTTY,
9950
+ curated: view !== void 0
9932
9951
  })}
9933
9952
  `
9934
9953
  );
package/dist/core.js CHANGED
@@ -395,7 +395,7 @@ var COMMANDS = [
395
395
  command: "catalog get",
396
396
  tool: "catalog_get",
397
397
  title: "Get catalog",
398
- description: "The organization's agent catalog: categories, portals and every live template. `accessLevel` is `granted` (can instantiate a `runnable` template) or `viewable` (locked). A template the organization has not added is `viewable`; `catalog_template_add` grants it. `organizationId` defaults to the caller's one organization. Template definitions are omitted; read one with `catalog_template_get`.",
398
+ description: "The organization's agent catalog: categories, portals and every runnable template, with its category and portal by name. `accessLevel` is `granted` (can instantiate) or `viewable` (locked). A template the organization has not added is `viewable`; `catalog_template_add` grants it. Templates on a portal whose `portalType` is `mock` run against stand-in sites with sample data that Asteroid hosts: they are `granted` to every organization, need no credentials and touch nothing real. Offer them for a demo or when the user has no access to the real portal yet, and prefer a real portal's template otherwise. `organizationId` defaults to the caller's one organization. Template definitions are omitted; read one with `catalog_template_get`.",
399
399
  method: "GET",
400
400
  path: "/agents/v2/catalog",
401
401
  args: [],
@@ -456,7 +456,7 @@ var COMMANDS = [
456
456
  command: "catalog template instantiate",
457
457
  tool: "catalog_template_instantiate",
458
458
  title: "Instantiate catalog template",
459
- description: "Create a new workflow in the organization from a catalog template. Needs `accessLevel` `granted`: add the template with `catalog_template_add` first. Pass `credentials` (keyed by the portal's credential field keys) to create a profile, or `agentProfileId` to reuse one, or neither for a bare clone. Returns the workflow ID, its version ID and any profile ID. `organizationId` defaults to the caller's one organization.",
459
+ description: "Create a new workflow in the organization from a catalog template. Needs `accessLevel` `granted`: add the template with `catalog_template_add` first; a template on a `mock` portal is already granted. Pass `credentials` (keyed by the portal's credential field keys) to create a profile, or `agentProfileId` to reuse one, or neither for a bare clone. Returns the workflow ID, its version ID and any profile ID. `organizationId` defaults to the caller's one organization.",
460
460
  method: "POST",
461
461
  path: "/agents/v2/catalog/templates/{templateId}/instantiate",
462
462
  args: [
@@ -2266,8 +2266,8 @@ var COMMANDS = [
2266
2266
  {
2267
2267
  command: "execution sync",
2268
2268
  tool: "execution_sync",
2269
- title: "Wait for an execution to finish",
2270
- description: "Wait up to `timeoutSeconds` (1-25, default 25) for a running execution to finish. Returns the terminal `status` and `executionResult` when it finishes in time. Otherwise returns the current status: call it again to keep waiting. A paused or `awaiting_confirmation` execution returns at once, since it needs a person. Use it after `workflow_execute_post`, or after `workflow_execute_sync_post` timed out, instead of polling `execution_get`.",
2269
+ title: "Wait for an execution's status to change",
2270
+ description: "Wait up to `timeoutSeconds` (1-25, default 25) for an execution's status to change. Returns as soon as the status differs from the one it had when the call began. A `paused`, `paused_by_agent` or `awaiting_confirmation` execution returns at once, since it needs a person. `returnReason` says why it returned: `ended` (with `executionResult` when the run recorded one), `needs_person`, `status_change` or `timed_out`. After `status_change` or `timed_out`, call it again to keep following the run. On `awaiting_confirmation`, `awaitingConfirmation.nodeName` names the node the run holds at: get the user's go-ahead, then approve with `execution_resume`. Use it after `workflow_execute_post`, or after `workflow_execute_sync_post` timed out, instead of polling `execution_get`.",
2271
2271
  method: "GET",
2272
2272
  path: "/agents/v2/executions/{executionId}/sync",
2273
2273
  args: [
@@ -2284,7 +2284,7 @@ var COMMANDS = [
2284
2284
  flag: "timeout-seconds",
2285
2285
  type: "integer",
2286
2286
  required: false,
2287
- description: "Seconds to wait for the execution to finish before returning 202. Defaults to 25."
2287
+ description: "Seconds to wait for a change before returning 202. Defaults to 25."
2288
2288
  }
2289
2289
  ],
2290
2290
  binary: false,
@@ -6619,6 +6619,7 @@ function columns(rows, options) {
6619
6619
  scalarKeys.push(key);
6620
6620
  }
6621
6621
  }
6622
+ if (options.curated) return scalarKeys;
6622
6623
  const ordered = [
6623
6624
  ...PREFERRED.filter((key) => scalarKeys.includes(key)),
6624
6625
  ...scalarKeys.filter((key) => !PREFERRED.includes(key))
@@ -6968,6 +6969,8 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
6968
6969
  if (notes.length > 0) leaf.addHelpText("after", `
6969
6970
  ${notes.join("\n")}`);
6970
6971
  leafOptions(leaf, command);
6972
+ for (const [flags, text2] of options.extraOptions?.(command) ?? [])
6973
+ leaf.option(flags, text2);
6971
6974
  leaf.action((...args) => {
6972
6975
  const cmd = args.at(-1);
6973
6976
  let positionals = cmd.args;
@@ -7286,71 +7289,53 @@ function statusOf(error) {
7286
7289
 
7287
7290
  // src/sync/execution-wait.ts
7288
7291
  var WAIT_TIMEOUT_SECONDS = 600;
7289
- var WAIT_INTERVAL_SECONDS = 15;
7290
7292
  var MAX_WAIT_TIMEOUT_SECONDS = 3600;
7291
- var MAX_WAIT_INTERVAL_SECONDS = 120;
7292
- var TERMINAL = /* @__PURE__ */ new Set(["completed", "cancelled", "failed"]);
7293
- function isTerminalExecutionStatus(status) {
7294
- return TERMINAL.has(status);
7295
- }
7296
7293
  var SYNC_TIMEOUT_SECONDS = 25;
7297
- function pause(ms) {
7298
- return new Promise((resolve2) => setTimeout(resolve2, ms));
7299
- }
7300
- async function readStatus(sync, executionId2, timeoutMs) {
7301
- if (timeoutMs <= 0)
7302
- return await sync.remote.json(
7303
- get(`/agents/v2/executions/${executionId2}`)
7304
- );
7294
+ async function syncExecution(sync, executionId2, timeoutMs) {
7305
7295
  const timeoutSeconds = Math.min(
7306
7296
  SYNC_TIMEOUT_SECONDS,
7307
7297
  Math.max(1, Math.ceil(timeoutMs / 1e3))
7308
7298
  );
7309
- const response = await sync.remote.json(
7299
+ return await sync.remote.json(
7310
7300
  get(`/agents/v2/executions/${executionId2}/sync`, {
7311
7301
  timeoutSeconds: String(timeoutSeconds)
7312
7302
  })
7313
7303
  );
7314
- return {
7315
- id: response.executionId,
7316
- status: response.status,
7317
- executionResult: response.executionResult
7318
- };
7319
7304
  }
7320
7305
  async function waitForExecution(sync, options) {
7321
7306
  const timeoutMs = (options.timeoutSeconds ?? WAIT_TIMEOUT_SECONDS) * 1e3;
7322
- const intervalMs = (options.intervalSeconds ?? WAIT_INTERVAL_SECONDS) * 1e3;
7323
7307
  const now = options.now ?? Date.now;
7324
- const sleep = options.sleep ?? pause;
7325
7308
  const started = now();
7326
- let polls = 0;
7327
- for (; ; ) {
7328
- const called = now();
7329
- const execution = await readStatus(
7309
+ for (let polls = 1; ; polls++) {
7310
+ const execution = await syncExecution(
7330
7311
  sync,
7331
7312
  options.executionId,
7332
- timeoutMs - (called - started)
7313
+ timeoutMs - (now() - started)
7333
7314
  );
7334
- polls++;
7335
7315
  const elapsed = now() - started;
7336
- const waitedSeconds = Math.round(elapsed / 1e3);
7337
- if (isTerminalExecutionStatus(execution.status))
7338
- return { execution, terminal: true, waitedSeconds, polls };
7339
- const remaining = timeoutMs - elapsed;
7340
- if (remaining <= 0)
7341
- return { execution, terminal: false, waitedSeconds, polls };
7342
- const early = intervalMs - (now() - called);
7343
- if (early > 0) await sleep(Math.min(early, remaining));
7316
+ if (execution.returnReason !== "timed_out" || elapsed >= timeoutMs)
7317
+ return { execution, waitedSeconds: Math.round(elapsed / 1e3), polls };
7344
7318
  }
7345
7319
  }
7346
7320
  function formatExecutionWait(result) {
7347
7321
  const { execution } = result;
7348
- if (!result.terminal) {
7349
- return `Execution ${execution.id} still ${execution.status} after ${result.waitedSeconds}s. Wait again, or read what it has so far with \`asteroid execution pull ${execution.id}\`.`;
7322
+ const id = execution.executionId;
7323
+ const hold = execution.awaitingConfirmation;
7324
+ if (hold)
7325
+ return `Execution ${id} ${execution.status} at node "${hold.nodeName}". Approve it with \`asteroid execution resume ${id}\` once the user agrees.`;
7326
+ switch (execution.returnReason) {
7327
+ case "ended": {
7328
+ const line2 = `Execution ${id} ${execution.status}.`;
7329
+ const outcome = execution.executionResult;
7330
+ return outcome ? `${line2} Result: ${outcome.outcome}: ${outcome.reasoning}` : line2;
7331
+ }
7332
+ case "needs_person":
7333
+ return `Execution ${id} ${execution.status} and needs a person. Read why with \`asteroid execution activities ${id} --order desc\`.`;
7334
+ case "status_change":
7335
+ return `Execution ${id} is now ${execution.status}. Wait again to follow it.`;
7336
+ default:
7337
+ return `Execution ${id} still ${execution.status} after ${result.waitedSeconds}s. Wait again, or read what it has so far with \`asteroid execution pull ${id}\`.`;
7350
7338
  }
7351
- const line2 = `Execution ${execution.id} ${execution.status}.`;
7352
- const outcome = execution.executionResult;
7353
- return outcome ? `${line2} Result: ${outcome.outcome}: ${outcome.reasoning}` : line2;
7354
7339
  }
7355
7340
 
7356
7341
  // src/sync/commands.ts
@@ -7409,8 +7394,8 @@ var SYNC_COMMANDS = [
7409
7394
  ...local,
7410
7395
  command: "execution wait",
7411
7396
  tool: "execution_wait",
7412
- title: "Wait for an execution to end",
7413
- description: "Poll an execution until it is completed, failed or cancelled, then print its status and, when the run produced one, its result. When the timeout passes first, print the status it still has, so you can wait again.",
7397
+ title: "Wait for an execution's status to change",
7398
+ description: "Call `execution sync` until it reports a reason to stop, then print the status. It returns as soon as the run's status changes, at once when the run has ended or needs a person, and otherwise at the timeout, when it prints the status the run still has so you can wait again. On `awaiting_confirmation` it names the node the run holds at when the API reports one, and otherwise points to `asteroid execution activities`. Approve it with `asteroid execution resume <execution-id>` once the user agrees.",
7414
7399
  readOnly: true,
7415
7400
  args: [executionId],
7416
7401
  query: [
@@ -7418,11 +7403,6 @@ var SYNC_COMMANDS = [
7418
7403
  "timeout",
7419
7404
  "integer",
7420
7405
  `Give up after this many seconds, ${WAIT_TIMEOUT_SECONDS} unless set, ${MAX_WAIT_TIMEOUT_SECONDS} at most.`
7421
- ),
7422
- option(
7423
- "interval",
7424
- "integer",
7425
- `Poll every this many seconds, ${WAIT_INTERVAL_SECONDS} unless set, ${MAX_WAIT_INTERVAL_SECONDS} at most.`
7426
7406
  )
7427
7407
  ]
7428
7408
  },
@@ -8355,8 +8335,7 @@ function bounded(parsed, name, min, max) {
8355
8335
  function executionWaitOptions(parsed) {
8356
8336
  return {
8357
8337
  executionId: parsed.positionals[0],
8358
- timeoutSeconds: bounded(parsed, "timeout", 0, MAX_WAIT_TIMEOUT_SECONDS),
8359
- intervalSeconds: bounded(parsed, "interval", 1, MAX_WAIT_INTERVAL_SECONDS)
8338
+ timeoutSeconds: bounded(parsed, "timeout", 0, MAX_WAIT_TIMEOUT_SECONDS)
8360
8339
  };
8361
8340
  }
8362
8341
  function given(value2, name) {
@@ -8486,7 +8465,6 @@ export {
8486
8465
  formatWorkflowPush,
8487
8466
  headFilesRequest,
8488
8467
  insightFileId,
8489
- isTerminalExecutionStatus,
8490
8468
  leadingWords,
8491
8469
  loadManifest,
8492
8470
  matchCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteroidai/cli",
3
- "version": "1.9.193",
3
+ "version": "1.9.224",
4
4
  "description": "The asteroid command-line interface for the Asteroid platform.",
5
5
  "type": "module",
6
6
  "license": "MIT",