@parcha/agentrun-serve 0.1.0-beta.39 → 0.1.0-beta.41

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 (173) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +129 -16
  3. package/dist/api-only.d.ts +3 -1
  4. package/dist/api-only.js +4 -2
  5. package/dist/api-token.d.ts +30 -0
  6. package/dist/api-token.js +89 -0
  7. package/dist/cli.js +19 -5
  8. package/dist/composio-made.d.ts +54 -0
  9. package/dist/composio-made.js +83 -0
  10. package/dist/composio-preset.d.ts +16 -8
  11. package/dist/composio-preset.js +106 -43
  12. package/dist/composio-triggers.d.ts +7 -2
  13. package/dist/composio-triggers.js +13 -7
  14. package/dist/computer-attach.d.ts +29 -11
  15. package/dist/computer-attach.js +141 -47
  16. package/dist/computer-keys.d.ts +4 -0
  17. package/dist/computer-keys.js +5 -0
  18. package/dist/computers.d.ts +11 -1
  19. package/dist/computers.js +21 -12
  20. package/dist/console/assets/index-C3gNPz58.css +1 -0
  21. package/dist/console/assets/index-COGhx_2Z.js +711 -0
  22. package/dist/console/index.html +2 -2
  23. package/dist/decisions.js +9 -2
  24. package/dist/email/account.d.ts +0 -1
  25. package/dist/email/account.js +3 -3
  26. package/dist/email/answer.d.ts +5 -0
  27. package/dist/email/answer.js +35 -0
  28. package/dist/email/mail.js +19 -26
  29. package/dist/email/names.d.ts +30 -0
  30. package/dist/email/names.js +34 -0
  31. package/dist/email/routes.d.ts +1 -0
  32. package/dist/email/routes.js +1 -1
  33. package/dist/email/tools.d.ts +11 -4
  34. package/dist/email/tools.js +91 -46
  35. package/dist/eval-feed.d.ts +26 -0
  36. package/dist/eval-feed.js +68 -0
  37. package/dist/eval-mailbox.d.ts +5 -2
  38. package/dist/eval-mailbox.js +14 -6
  39. package/dist/exa-keyless.d.ts +1 -1
  40. package/dist/exa-keyless.js +1 -1
  41. package/dist/feed/feed-faux.d.ts +62 -0
  42. package/dist/feed/feed-faux.js +123 -0
  43. package/dist/feed/fetch.d.ts +41 -0
  44. package/dist/feed/fetch.js +128 -0
  45. package/dist/feed/parse.d.ts +41 -0
  46. package/dist/feed/parse.js +300 -0
  47. package/dist/learn/check.d.ts +3 -1
  48. package/dist/learn/check.js +57 -2
  49. package/dist/learn/compile.d.ts +3 -2
  50. package/dist/learn/compile.js +7 -6
  51. package/dist/learn/promote.d.ts +25 -14
  52. package/dist/learn/promote.js +32 -14
  53. package/dist/learned-nodes.d.ts +21 -4
  54. package/dist/learned-nodes.js +21 -8
  55. package/dist/learned-workflow.d.ts +3 -3
  56. package/dist/learned-workflow.js +14 -5
  57. package/dist/learning-cost.d.ts +17 -8
  58. package/dist/learning-cost.js +12 -4
  59. package/dist/local-models.d.ts +7 -1
  60. package/dist/local-models.js +11 -5
  61. package/dist/mcp-oauth.d.ts +15 -1
  62. package/dist/mcp-oauth.js +39 -5
  63. package/dist/mcp-pin-first.d.ts +4 -2
  64. package/dist/mcp-pin-first.js +4 -3
  65. package/dist/mcp-servers-store.d.ts +58 -5
  66. package/dist/mcp-servers-store.js +136 -17
  67. package/dist/mcp.d.ts +2 -2
  68. package/dist/mcp.js +2 -2
  69. package/dist/observation/http.d.ts +4 -1
  70. package/dist/observation/http.js +5 -4
  71. package/dist/openapi.d.ts +1 -1
  72. package/dist/openapi.js +63 -27
  73. package/dist/port-models.d.ts +4 -1
  74. package/dist/port-models.js +1 -0
  75. package/dist/print.d.ts +6 -3
  76. package/dist/print.js +4 -2
  77. package/dist/refusal-words.d.ts +3 -0
  78. package/dist/refusal-words.js +3 -0
  79. package/dist/run-labels.d.ts +23 -0
  80. package/dist/run-labels.js +79 -0
  81. package/dist/run-launch.d.ts +2 -0
  82. package/dist/run-launch.js +2 -0
  83. package/dist/run-secrets.js +12 -4
  84. package/dist/run-view.d.ts +3 -4
  85. package/dist/run-view.js +26 -24
  86. package/dist/runner/adapter-loop.d.ts +6 -2
  87. package/dist/runner/adapter-loop.js +136 -22
  88. package/dist/runner/adapter-run-spec.d.ts +5 -0
  89. package/dist/runner/adapter-run-spec.js +75 -32
  90. package/dist/runner/beside.d.ts +6 -3
  91. package/dist/runner/beside.js +9 -7
  92. package/dist/runner/cli-run-spec.js +33 -26
  93. package/dist/runner/conformance/harness.js +69 -14
  94. package/dist/runner/conformance/subject.d.ts +4 -1
  95. package/dist/runner/journal-kinds.d.ts +22 -0
  96. package/dist/runner/journal-kinds.js +39 -0
  97. package/dist/runner/main.d.ts +1 -1
  98. package/dist/runner/main.js +2 -2
  99. package/dist/runner/mcp-claim.d.ts +3 -0
  100. package/dist/runner/mcp-claim.js +1 -1
  101. package/dist/runner/mcp-run.d.ts +4 -0
  102. package/dist/runner/mcp-run.js +5 -3
  103. package/dist/runner/model-route.d.ts +7 -3
  104. package/dist/runner/model-route.js +24 -9
  105. package/dist/runner/promotion.d.ts +16 -8
  106. package/dist/runner/promotion.js +178 -55
  107. package/dist/runner/workflow-first.d.ts +6 -5
  108. package/dist/runner/workflow-first.js +9 -7
  109. package/dist/runs-over-store.js +5 -2
  110. package/dist/sdk/runs.d.ts +7 -1
  111. package/dist/sdk/runs.js +19 -6
  112. package/dist/secret-cut.js +3 -1
  113. package/dist/secrets.js +3 -1
  114. package/dist/server.d.ts +27 -2
  115. package/dist/server.js +181 -56
  116. package/dist/store/dialect.d.ts +6 -0
  117. package/dist/store/dialect.js +2 -0
  118. package/dist/store/index.d.ts +1 -1
  119. package/dist/store/postgres/connection.d.ts +11 -5
  120. package/dist/store/postgres/connection.js +44 -17
  121. package/dist/store/postgres/dialect.js +6 -0
  122. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  123. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  124. package/dist/store/postgres/store.d.ts +7 -3
  125. package/dist/store/postgres/store.js +1 -0
  126. package/dist/store/schema.d.ts +9 -0
  127. package/dist/store/schema.js +26 -2
  128. package/dist/store/sqlite/connection.js +80 -8
  129. package/dist/store/sqlite/run-launch.d.ts +11 -0
  130. package/dist/store/sqlite/run-launch.js +8 -0
  131. package/dist/store/sqlite/run-patch.d.ts +2 -1
  132. package/dist/store/sqlite/run-patch.js +3 -2
  133. package/dist/store/sqlite/store.js +101 -26
  134. package/dist/store/sqlite/worker.d.ts +2 -0
  135. package/dist/store/sqlite/worker.js +13 -10
  136. package/dist/store/store.d.ts +53 -1
  137. package/dist/store-reads/journal.js +2 -1
  138. package/dist/store-reads/learning.d.ts +30 -13
  139. package/dist/store-reads/learning.js +130 -51
  140. package/dist/store-reads/runs.d.ts +4 -3
  141. package/dist/store-reads/runs.js +3 -2
  142. package/dist/store-view.js +4 -2
  143. package/dist/template-eval.d.ts +4 -0
  144. package/dist/template-eval.js +127 -50
  145. package/dist/templates.d.ts +24 -1
  146. package/dist/templates.js +129 -21
  147. package/dist/timeline/origin.d.ts +1 -1
  148. package/dist/timeline/origin.js +2 -2
  149. package/dist/tool-gate.d.ts +5 -3
  150. package/dist/tool-gate.js +5 -2
  151. package/dist/tools.d.ts +13 -0
  152. package/dist/tools.js +15 -10
  153. package/dist/trigger-adapter.d.ts +12 -36
  154. package/dist/trigger-adapters.js +2 -1
  155. package/dist/trigger-email.js +30 -77
  156. package/dist/trigger-feed.d.ts +12 -0
  157. package/dist/trigger-feed.js +371 -0
  158. package/dist/triggers.d.ts +27 -14
  159. package/dist/triggers.js +121 -80
  160. package/dist/webhooks.js +9 -5
  161. package/dist/workflow/decision-recovery.js +5 -2
  162. package/dist/workflow/decisions.d.ts +7 -0
  163. package/dist/workspace/computer-deps.d.ts +5 -1
  164. package/dist/workspace/computer-deps.js +2 -2
  165. package/dist/workspace/index.d.ts +1 -0
  166. package/dist/workspace/index.js +2 -0
  167. package/dist/workspace/resolve-computer.d.ts +32 -3
  168. package/dist/workspace/resolve-computer.js +47 -9
  169. package/launcher/agentrun-serve +6 -1
  170. package/package.json +10 -9
  171. package/templates/README.md +27 -2
  172. package/dist/console/assets/index-BNhZs-jp.css +0 -1
  173. package/dist/console/assets/index-BQv5aOGB.js +0 -700
@@ -1,16 +1,24 @@
1
1
  import { harnessModelKeys } from "./adapters.js";
2
+ import { COMPUTER_KEY_NAMES } from "./computer-keys.js";
2
3
  import { BOX_KEYS } from "./place-offers.js";
3
4
  import { providersNamed } from "./decisions.js";
4
5
  import { harnessOfBody } from "./harness.js";
5
6
  import { harnessOf } from "./harness-table.js";
6
7
  import { GATEWAY_KEY_ENV, llmTiers, modelKeys, nodeTiers, PROVIDER_KEYS, workflowNodes } from "./model.js";
7
8
  import { DECISION_KEYS, SECRET_NAMES } from "./secrets.js";
8
- import { TOOL_KEYS, unlocksTool } from "./tool-keys.js";
9
+ import { TOOL_FIELDS, TOOL_KEYS, unlocksTool } from "./tool-keys.js";
9
10
  import { workflowTools } from "./tools.js";
11
+ import { ARCHIL_API_KEY_ENV } from "./workspace/archil-key.js";
12
+ /** The computer providers' account keys a run never gets: every computer key (computer-keys.ts COMPUTER_KEY_NAMES) but
13
+ * a tool key's field (Browserbase's and Kernel's, which a run's `browser` tool takes when its revision binds it). Only
14
+ * the server's and the runner's computer providers read one, at a claim or a Settings test. */
15
+ const COMPUTER_ACCOUNT_KEYS = COMPUTER_KEY_NAMES.filter((name) => !TOOL_FIELDS.includes(name));
10
16
  /** The server's own secrets, which a run never gets: the API token, by name or by value, the seal key the tool keys are
11
- * kept under (tool-keys.ts), the store's URL (it may hold the database's password), and the remote boxes' keys
12
- * (place-offers.ts BOX_KEYS), which only the server's computer providers use. */
13
- const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS]);
17
+ * kept under (tool-keys.ts), the store's URL (it may hold the database's password), the remote boxes' keys
18
+ * (place-offers.ts BOX_KEYS) and every other computer provider's account key, which only the server's and the runner's
19
+ * computer providers use, and the Archil account key (archil-key.ts), from which the claim mints each run's own mount
20
+ * credential. */
21
+ const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS, ...COMPUTER_ACCOUNT_KEYS, ARCHIL_API_KEY_ENV]);
14
22
  /** The secrets a run may be handed: every one but the server's own and the decision keys, which go apart. */
15
23
  export const RUN_SECRETS = SECRET_NAMES.filter((name) => !SERVER_ONLY.has(name) && !DECISION_KEYS.includes(name));
16
24
  /** The fields a run gets only when its revision names what they unlock: a `tool` key's. Any other kind's (a model key's)
@@ -4,7 +4,6 @@ import { type RefusalFigures } from "./cap.js";
4
4
  import type { Turns } from "./turns.js";
5
5
  import type { PendingAsk } from "./browser-person.js";
6
6
  import { type ApprovalPrice, type PendingApproval } from "./tool-gate.js";
7
- import "./email/labels.js";
8
7
  import { type signInReads } from "./sign-ins-store.js";
9
8
  import { type CostWords } from "./runner/metrics.js";
10
9
  import type { CostParts } from "@parcha/agentrun-kernel";
@@ -459,9 +458,9 @@ export declare function outcomeShows(tool: string, answer: {
459
458
  /** The rows of a run whose calls waited for approval, as the runner writes it (store-view.ts): the gate's ask
460
459
  * (agentrun.ask, `asks`) and the person's answer (agentrun.answer, `answers`) are journal entries, and an allowed call runs
461
460
  * in place, so its result row is its real result; a denied one's is the refusal. Each such call reads in order: its call,
462
- * then the approval row at the ask's time, then its result, then, once there is one, the outcome row (before a result is
463
- * in, the approval row and any outcome follow its own rows); its own rows say only that it was held once the
464
- * outcome shows below, and before that what came of the approval so far. Arguments and notes go through `redact`, the
461
+ * then the approval row at the ask's time (above the rows written while it waited), then its result, then, once there
462
+ * is one, the outcome row (before a result is in, any outcome follows its own rows); its own rows say only that it was
463
+ * held once the outcome shows below, and before that what came of the approval so far. Arguments and notes go through `redact`, the
465
464
  * run's redactor, before any cut. The rows this function makes are dropped first, so a pass over its own output gives the
466
465
  * same rows. */
467
466
  export declare function withApprovalRows(rows: readonly TimelineEvent[], asks: ReadonlyMap<string, Approval>, answers: Readonly<Record<string, ApprovalAnswer>>, redact: (text: string) => string): TimelineEvent[];
package/dist/run-view.js CHANGED
@@ -9,10 +9,7 @@
9
9
  import { chargedTool, isMessageRow, NOTE_SUFFIX, registerLabel, registerTurnEnding, scrubUrls } from "./timeline/index.js";
10
10
  import { CAP_TOLERANCE, FIT_TOLERANCE, money, roomRefusal } from "./cap.js";
11
11
  import { APPROVAL_ROW, previewOf } from "./tool-gate.js";
12
- import { ASK_TOOL } from "./tools.js";
13
- import { EMAIL_FILE, EMAIL_SEND, fileSummary, sendSummary } from "./email/names.js";
14
- // The email tools' timeline lines (registerLabel), registered as this module loads.
15
- import "./email/labels.js";
12
+ import { ASK_TOOL, toolOf } from "./tools.js";
16
13
  import { LEARNING_LABEL } from "./learning.js";
17
14
  import { builtinHarness } from "./harness-table.js";
18
15
  import { cutStrings, redacted, withoutLoopback } from "./key-refusal.js";
@@ -20,7 +17,7 @@ import { pointerHash } from "./sign-ins-store.js";
20
17
  import { MIN_SECRET } from "./learn/secrets.js";
21
18
  import { costWordsOf, usageParts } from "./runner/metrics.js";
22
19
  import { KINDS } from "./runner/journal-kinds.js";
23
- import { ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
20
+ import { ASKED_BECAUSE, ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
24
21
  /** The run's newest usage row, which carries its cost. */
25
22
  const usageOf = (rows) => rows.findLast((r) => r.kind === "usage");
26
23
  /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
@@ -366,14 +363,10 @@ export const pendingOf = (rows) => {
366
363
  return last?.kind === "waiting" ? { kind: "question", question: last.text ?? last.summary ?? "", asked_at: last.timestamp } : null;
367
364
  };
368
365
  /** The run's pending approval (`pending`, kind approval): the call that waits; else undefined. */
369
- /** The tools whose approval card says what the call does in words: email_send's to whom and what, email_file's which
370
- * message and where. */
371
- const SUMMARIES = { [EMAIL_SEND]: sendSummary, [EMAIL_FILE]: fileSummary };
372
- /** A call's approval summary, where its tool has one (SUMMARIES), redacted as its arguments are. */
366
+ /** A call's approval summary, where its tool has one (tools.ts ToolEntry.approvalSummary), then why it asks when its tool
367
+ * asked about it itself (the card's ASKED_BECAUSE, the gate's), redacted as its arguments are. */
373
368
  function summaryOf(approval, redact) {
374
- const summarize = Object.hasOwn(SUMMARIES, approval.tool) ? SUMMARIES[approval.tool] : undefined;
375
- if (!summarize)
376
- return {};
369
+ const summarize = toolOf(approval.tool)?.approvalSummary;
377
370
  let args;
378
371
  try {
379
372
  args = JSON.parse(approval.args_json);
@@ -381,8 +374,9 @@ function summaryOf(approval, redact) {
381
374
  catch {
382
375
  return {};
383
376
  }
384
- const summary = summarize(args);
385
- return summary === undefined ? {} : { summary: redact(summary) };
377
+ const because = typeof args === "object" && args !== null && typeof args[ASKED_BECAUSE] === "string" ? args[ASKED_BECAUSE] : undefined;
378
+ const parts = [summarize?.(args), because === undefined ? undefined : `Asks because ${because}.`].filter((part) => part !== undefined);
379
+ return parts.length ? { summary: redact(parts.join("\n\n")) } : {};
386
380
  }
387
381
  export const approvalOf = (run, redact) => {
388
382
  const waiting = waitingApproval(run);
@@ -650,9 +644,9 @@ const approvalRowId = (callId) => `approval:${callId}`;
650
644
  /** The rows of a run whose calls waited for approval, as the runner writes it (store-view.ts): the gate's ask
651
645
  * (agentrun.ask, `asks`) and the person's answer (agentrun.answer, `answers`) are journal entries, and an allowed call runs
652
646
  * in place, so its result row is its real result; a denied one's is the refusal. Each such call reads in order: its call,
653
- * then the approval row at the ask's time, then its result, then, once there is one, the outcome row (before a result is
654
- * in, the approval row and any outcome follow its own rows); its own rows say only that it was held once the
655
- * outcome shows below, and before that what came of the approval so far. Arguments and notes go through `redact`, the
647
+ * then the approval row at the ask's time (above the rows written while it waited), then its result, then, once there
648
+ * is one, the outcome row (before a result is in, any outcome follows its own rows); its own rows say only that it was
649
+ * held once the outcome shows below, and before that what came of the approval so far. Arguments and notes go through `redact`, the
656
650
  * run's redactor, before any cut. The rows this function makes are dropped first, so a pass over its own output gives the
657
651
  * same rows. */
658
652
  export function withApprovalRows(rows, asks, answers, redact) {
@@ -665,6 +659,11 @@ export function withApprovalRows(rows, asks, answers, redact) {
665
659
  for (const row of given)
666
660
  if (owns(row))
667
661
  lastOf.set(row.tool_use_id, row.id);
662
+ // The call's own row the approval row goes below: its call's (the last of its rows that is not its result).
663
+ const callOf = new Map();
664
+ for (const row of given)
665
+ if (owns(row) && row.kind !== "tool_result")
666
+ callOf.set(row.tool_use_id, row.id);
668
667
  // The result rows of the calls that waited: a Saved row read from such a call's write (pi's `<result>:saved:<n>`) says
669
668
  // a file was written that the park never wrote; an allowed call's file is its outcome row's to say, as on main.
670
669
  const waitedResults = new Set(given.filter((row) => row.kind === "tool_result" && owns(row)).map((row) => row.id));
@@ -687,22 +686,25 @@ export function withApprovalRows(rows, asks, answers, redact) {
687
686
  const own = ran ? (row.kind === "tool_result" && !row.summary?.endsWith(said) ? { ...row, summary: row.summary ? `${row.summary} ${said}` : said } : row)
688
687
  : answer?.decision === "deny" && answer.by === "setting" ? { ...row, summary: DENIED_SINCE }
689
688
  : { ...row, summary: outcome ? HELD : callSays(answer), tool_status: null };
690
- // The approval row sits above the call's result once there is one (the ask came before the call ran), else below its
691
- // last own row; the outcome rows below its last own row.
692
- const askHere = row.id === (result?.id ?? lastOf.get(approval.call_id));
689
+ // The approval row sits right below the call's own row, as the ask came at the call: above what came while it waited
690
+ // (a park's keep, a resume's computer ready again) and above its result. A call with only its result row has it above
691
+ // that. The outcome rows go below its last own row.
692
+ const call = callOf.get(approval.call_id);
693
+ const askHere = row.id === (call ?? result?.id);
693
694
  const last = lastOf.get(approval.call_id) === row.id;
694
695
  if (!askHere && !last)
695
696
  return [own];
696
697
  const args = shownArgs(approval, redact);
697
- // A served row keeps the place it was first served at (rows.ts). The approval row is served while the call waits, above
698
- // the result yet to come, so it keeps its id. The call's result comes in after the answer (the park writes none), so the
699
- // outcome rows take a new id once it is there: served anew below the result, as a person reads it.
698
+ // A served row keeps the place it was first served at (rows.ts). The approval row is served while the call waits, below
699
+ // its call's row, where it stays once the result is in, so it keeps its id. The call's result comes in after the
700
+ // answer (the park writes none), so the outcome rows take a new id once it is there: served anew below the result, as
701
+ // a person reads it.
700
702
  const at = result ? `${approvalRowId(approval.call_id)}:after` : approvalRowId(approval.call_id);
701
703
  const head = !answer ? "Waiting for your approval" : answer.decision === "canceled" ? "Withdrawn when the run was cancelled" : answer.decision === "withdrawn" ? (answer.ended ? "Withdrawn when the run ended" : "Withdrawn when the run was stopped") : answer.by === "message" ? "Declined by your message" : answer.by === "setting" ? (answer.decision === "deny" ? "Denied by the tool's setting on this server" : "Allowed by the tool's setting") : "Asked your approval";
702
704
  // Its time is the ask's (the gate's requestedAt), never the row it was made from.
703
705
  const when = approval.requested_at ? { timestamp: approval.requested_at, created_at: approval.requested_at } : {};
704
706
  const asked = { ...madeFrom(row), ...when, id: approvalRowId(approval.call_id), kind: APPROVAL_ROW, summary: `${head}: ${approval.tool} ${clip(args, 400)}`, text: args, tool_name: approval.tool, tool_status: null, tool_input_preview: clip(args, 500), tool_result_preview: null, tool_result_size_bytes: null };
705
- const placed = !askHere ? [own] : result ? [asked, own] : [own, asked];
707
+ const placed = !askHere ? [own] : row.id === call ? [own, asked] : [asked, own];
706
708
  if (!last || !outcome)
707
709
  return placed;
708
710
  const failed = answer.decision === "allow" && result?.tool_status === "failed";
@@ -1,7 +1,7 @@
1
1
  import { type ConversationId, type ConversationRetryPolicy, type ConversationStreamOptions, Harness, type Tx } from "@earendil-works/pi-durable";
2
2
  import { type AgentAdapter, type Refusal, type SessionRecord, type SessionSpec } from "@parcha/agentrun-kernel";
3
3
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
4
- import { type BudgetData, type EndData } from "./journal-kinds.js";
4
+ import { type BudgetData, type EndData, type ToolCalls } from "./journal-kinds.js";
5
5
  import { type MessageOrigin } from "../timeline/index.js";
6
6
  type EndCost = Required<Pick<EndData, "costUsd" | "costUpperBound">>;
7
7
  import { type Claim, type EndOfRunTurn, type LoopFactory } from "./loop-contract.js";
@@ -65,8 +65,11 @@ export type GateAnswer = "allow" | "ask" | "deny" | {
65
65
  /** The gate before a call's intent; `askedAs`, when it has one, names a call as a person is asked about it (its settings
66
66
  * key, as main's pending approval names it), else the call is asked about by its own name. `replayed`: asked again for a
67
67
  * call run again after an earlier attempt that may have been sent, so a refusal's words never say nothing was sent. */
68
+ /** `ran`: the calls of a tool the run's journal shows (toolCalls: run to a good end, and every one with a result), read
69
+ * now (a tool's own ask counts by it, with the calls its gate let through that have no result yet). */
68
70
  export type SpecGate = ((call: ToolCall, options?: {
69
71
  readonly replayed?: boolean;
72
+ readonly ran?: (tool: string) => Promise<ToolCalls>;
70
73
  }) => GateAnswer | Promise<GateAnswer>) & {
71
74
  readonly askedAs?: (tool: string, args?: unknown) => string;
72
75
  /** A tool's setting now, by any name a call reaches the gate by (a harness's own, Codex's `web_search`), read again at
@@ -322,7 +325,8 @@ export interface AdapterLoopOptions {
322
325
  /** The gate's clock (epoch ms): when an ask was asked and answered, and when a wait in the claim on the person's answer
323
326
  * started. Default Date.now. */
324
327
  readonly now?: () => number;
325
- /** For tests: awaited as a wait in the claim on the person's answer starts, before it takes their messages. */
328
+ /** For tests: awaited once a turn ended on its question to the person, before the wait in the claim (or the park, with
329
+ * nothing to hold open) takes their messages. */
326
330
  readonly beforePersonWait?: () => Promise<void>;
327
331
  }
328
332
  /** A paid call's refusal an earlier claim kept (KINDS.pausePending) whose pause never landed: the newest one with no
@@ -2,7 +2,7 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
2
2
  import { createModels } from "@earendil-works/pi-ai/models";
3
3
  import { createRegistry, defineDoc, Harness, LiveDoc, ROOT_CONVERSATION_ID, ToolTask } from "@earendil-works/pi-durable";
4
4
  import { modelPortFor, RUNNER_RECORDS, sessionSpendOf, turnCostOf } from "@parcha/agentrun-kernel";
5
- import { ASK_PERSON_WAITING, capNowOf, endedAnswer, KINDS, MESSAGE_SENT_AGAIN, withdrawnAnswers } from "./journal-kinds.js";
5
+ import { ASK_PERSON_WAITING, capNowOf, endedAnswer, KINDS, MESSAGE_SENT_AGAIN, toolCalls, withdrawnAnswers } from "./journal-kinds.js";
6
6
  import { turnEndedOnAsk } from "../store-reads/journal.js";
7
7
  import { CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_ORIGIN, originOf, REQUEST_ENDED, REQUEST_STARTED, RUN_RESUMED } from "../timeline/index.js";
8
8
  import { raiseFollowUpId } from "../run-view.js";
@@ -27,10 +27,10 @@ const outputRetried = (entries) => {
27
27
  return at >= 0 && entries.slice(at + 1).some((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
28
28
  };
29
29
  import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
30
- import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
30
+ import { ASKED_BECAUSE, deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
31
31
  import { ADAPTER_API } from "../turn-end.js";
32
32
  import { answerText, REFLECT_NOTE_ONLY, REFLECT_PREFIX, reflectRequestId, underLearning, WRITES } from "./end-of-run.js";
33
- import { approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
33
+ import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
34
34
  import { outputMiss, outputRetryWords } from "../answer-json.js";
35
35
  import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
36
36
  import { isComputerCommand, journalHold } from "./computer-journal.js";
@@ -62,11 +62,12 @@ export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool
62
62
  export const AGENTIC_PAUSE_REFUSED = "Only a workflow run pauses here: an agentic run's turn is stopped with POST /runs/{id}/stop.";
63
63
  /** An asked call's card: the gate's own fields (`shown`) first, so a card cut at its preview's bound (ARGS_PREVIEW_BYTES)
64
64
  * still names them whatever the input's size, then the call's input, which the model wrote, without any field of
65
- * theirs; a learned_workflow call's card fields (LEARNED_CARD_FIELDS) are only ever the gate's. */
65
+ * theirs; a learned_workflow call's card fields (LEARNED_CARD_FIELDS) are only ever the gate's, and so is the reason a
66
+ * call its setting allows asks anyway (ASKED_BECAUSE). */
66
67
  function cardOf(tool, shown, args) {
67
- if (!shown && tool !== LEARNED_WORKFLOW_TOOL)
68
+ if (!shown && tool !== LEARNED_WORKFLOW_TOOL && !(args && Object.hasOwn(args, ASKED_BECAUSE)))
68
69
  return args;
69
- return { ...shown, ...Object.fromEntries(Object.entries(args ?? {}).filter(([key]) => !(shown && Object.hasOwn(shown, key)) && !(tool === LEARNED_WORKFLOW_TOOL && LEARNED_CARD_FIELDS.has(key)))) };
70
+ return { ...shown, ...Object.fromEntries(Object.entries(args ?? {}).filter(([key]) => !(shown && Object.hasOwn(shown, key)) && key !== ASKED_BECAUSE && !(tool === LEARNED_WORKFLOW_TOOL && LEARNED_CARD_FIELDS.has(key)))) };
70
71
  }
71
72
  /** The request ids of the person's messages placed as turns (loop.ts commandRequest). */
72
73
  const COMMAND_REQUEST_PREFIX = commandRequest(0).replace(/0$/, "");
@@ -391,6 +392,20 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
391
392
  followUps.add(requestId);
392
393
  personWritten = true;
393
394
  }),
395
+ steered: (input, requestId, origin) => inTurn(async () => {
396
+ if (followUps.has(requestId))
397
+ return;
398
+ const entry = origin
399
+ ? { entry: { kind: KINDS.input, data: { origin, requestId, at: now() }, model: [{ role: "user", content: input, timestamp: now() }] } }
400
+ : { kind: KINDS.message, data: { role: "steer", text: input, requestId } };
401
+ if (turnsOpen === 0)
402
+ await startsTurn(entry);
403
+ else if ("entry" in entry)
404
+ await harness.commit((tx) => tx.appendEntry(root.id, entry.entry), context);
405
+ else
406
+ await append(entry.kind, entry.data);
407
+ followUps.add(requestId);
408
+ }),
394
409
  message: (input, origin) => inTurn(async () => {
395
410
  if (origin)
396
411
  await startsTurn({ entry: { kind: KINDS.input, data: { origin }, model: [{ role: "user", content: input, timestamp: now() }] } });
@@ -664,9 +679,35 @@ function adapterLoop(specOf, options, deps) {
664
679
  * end waits on each one's submission (turnOfRequest) before the run may end, so the run never reads completed with a
665
680
  * message it took still unanswered, and its session is never closed under that answer. */
666
681
  const steeredIn = [];
682
+ /** A CLI's steers (a harness whose record the loop keeps, and whose session steers: claude-agent), by request id: the
683
+ * model took it (its adapter's message_taken, `takenIds`), then its record entry, the commit its row is taken in
684
+ * (`recorded`). The record says where the model read it, after the tool calls in flight, never where it was queued. */
685
+ const cliSteers = new Map();
686
+ /** The submissions a CLI's adapter said its model took (message_taken), and who waits on one of them. */
687
+ const takenIds = new Set();
688
+ const takenWaiters = new Map();
689
+ const modelTook = (id) => takenIds.has(id) ? Promise.resolve() : new Promise((resolve) => takenWaiters.set(id, [...(takenWaiters.get(id) ?? []), resolve]));
690
+ const tookNow = (ids) => {
691
+ for (const id of ids) {
692
+ takenIds.add(id);
693
+ for (const resolve of takenWaiters.get(id) ?? [])
694
+ resolve();
695
+ takenWaiters.delete(id);
696
+ }
697
+ };
667
698
  /** Set once the claim's last turn has ended and nothing more is sent: a message after it waits for the run's end, as one
668
699
  * during the end-of-run turn does. */
669
700
  let turnsOver = false;
701
+ /** Set, synchronously, once the claim has decided to park on its question (no wait in the claim holds, or the wait
702
+ * lapsed): from here to the park's seal (its host's release can take a while), a person's message is left untaken for
703
+ * the resume. Placed now, it would start a turn the seal then cuts, its row taken and the run parked with nothing to
704
+ * wake it, the message lost. */
705
+ let askParking = false;
706
+ /** The claim parks on its question: no message is placed from here (askParking). */
707
+ const parkingOnAsk = () => {
708
+ askParking = true;
709
+ return undefined;
710
+ };
670
711
  /** While the run's learned workflow runs first (AdapterRunSpec.workflowFirst): a message waits for it, then goes the way
671
712
  * any message goes once the workflow answered (the run is ending) or handed the job back (the agent's turn runs). */
672
713
  let servingFirst;
@@ -994,7 +1035,7 @@ function adapterLoop(specOf, options, deps) {
994
1035
  };
995
1036
  /** A person's message placed (steer): as the run's next turn, into the turn in flight, or after it. */
996
1037
  const placeSteer = async (command) => {
997
- if (!gate || !session || gate.sealed)
1038
+ if (!gate || !session || gate.sealed || askParking)
998
1039
  return { later: "the run is parking: the steer waits for its resume" };
999
1040
  // The session is still new and this is no reopen's message: the claim has yet to send the run's input. Placed now,
1000
1041
  // the message would be the session's first prompt and the input would follow it; it waits for the input instead, then
@@ -1032,6 +1073,9 @@ function adapterLoop(specOf, options, deps) {
1032
1073
  const servedAnswer = reopen && !reopen.sent && session.state === "new" && root !== undefined ? servedAnswerOf(await entriesOf(gate.journal, root.id, context)) : undefined;
1033
1074
  if (!gate || !session || gate.sealed)
1034
1075
  return { later: "the run is parking: the steer waits for its resume" };
1076
+ // The claim parks on its question (askParking), its seal still to come: the message is the resume's answer.
1077
+ if (askParking)
1078
+ return { later: "the run is parking on its question: the message answers it on the resume" };
1035
1079
  // A message that may not answer a person (a trigger's), delivered once the run waits on its person (in its claim, or
1036
1080
  // between the question's turn end and that wait): never the wait's answer, never placed now. Its firing reads sent (the
1037
1081
  // door took the row), so it is never refused either: left untaken, it runs as a turn of its own after the person's
@@ -1111,15 +1155,19 @@ function adapterLoop(specOf, options, deps) {
1111
1155
  }
1112
1156
  // Who wrote it, when the person did not (a trigger's message): carried on its input, as the Timeline shows it.
1113
1157
  const origin = originOf(command.body?.origin);
1114
- if (!session.steer) {
1115
- // A harness that takes no message mid-turn: the API answered it `follow_up` (it waits for the turn's end), so it is
1116
- // the run's next turn, after any taken before it (afterTurn). Taken now as the dispatch takes a row it buffers: the
1117
- // store's take is the commit of its submission, once sent.
1158
+ // A harness that takes no message mid-turn, or a CLI's message that is no steer of the turn in flight (a trigger's that
1159
+ // answers nothing, or the person's answer to the question its last turn ended on, whose session is idle): the API
1160
+ // answered it `follow_up` (it waits for the turn's end), so it is the run's next turn, after any taken before it
1161
+ // (afterTurn). Taken now as the dispatch takes a row it buffers: the store's take is the commit of its submission, once
1162
+ // sent.
1163
+ if (!session.steer || (cliRecord && (followUp || askedLast))) {
1118
1164
  if (turnsOver)
1119
1165
  return { later: "the run has answered and is ending: the message waits for the run's end" };
1120
1166
  afterTurn.push({ commandId: command.id, text, requestId, ...(origin ? { origin } : {}) });
1121
1167
  return { taken: true };
1122
1168
  }
1169
+ if (cliRecord)
1170
+ return steerCli(session, cliRecord, gate, command.id, text, requestId, origin);
1123
1171
  // The claim's last turn has ended and nothing more is sent (turnsOver): a steer placed now would start a turn the run's
1124
1172
  // end then cuts, so it waits for the run's end, as a CLI's message does.
1125
1173
  if (turnsOver && !askedLast)
@@ -1152,6 +1200,50 @@ function adapterLoop(specOf, options, deps) {
1152
1200
  await taken.catch(() => { });
1153
1201
  return { taken: true };
1154
1202
  };
1203
+ /** A person's message steered into a CLI's turn in flight (claude-agent): its session places it (its harness sends it to the
1204
+ * CLI at once, which hands it to the model at its next step); once the model took it, the record's steer entry is written
1205
+ * and the row is taken in that commit (cliSteers). A runner lost before that leaves the row untaken, and the session holds
1206
+ * the steer under the row's request id: the next claim's steer() of the same row places nothing again, its resumed turn
1207
+ * carries the steer if the CLI never had it, and the record is written once. Neither lost nor sent twice. */
1208
+ const steerCli = async (theSession, theRecord, theGate, commandId, text, requestId, origin) => {
1209
+ if (turnsOver)
1210
+ return { later: "the run has answered and is ending: the message waits for the run's end" };
1211
+ const taken = theGate.expect(writesEntry(origin ? KINDS.input : KINDS.message, (data) => data.requestId === requestId), { take: [commandId] });
1212
+ taken.catch(() => undefined);
1213
+ // Waited on before it is placed: the model may take it before steer() resolves.
1214
+ const took = modelTook(requestId);
1215
+ try {
1216
+ await theSession.steer(text, requestId, "steer", origin ? { origin } : undefined);
1217
+ }
1218
+ catch (error) {
1219
+ if (theGate.sealed)
1220
+ return { later: "the run is parking: the steer waits for its resume" };
1221
+ return { refused: `the steer was not placed: ${error.message}` };
1222
+ }
1223
+ await specNow?.hooks?.afterSteerPlaced?.();
1224
+ const recorded = took.then(() => theRecord.steered(text, requestId, origin));
1225
+ recorded.catch(() => undefined);
1226
+ cliSteers.set(requestId, { text, ...(origin ? { origin } : {}), recorded });
1227
+ // Placed in the turn in flight: the turn's end waits for it to be answered (steeredIn), never ending the run first.
1228
+ steeredIn.push(requestId);
1229
+ return { taken: true };
1230
+ };
1231
+ /** The end of the turn that answers a CLI's steer (steerCli): the turn in flight, or the next one its session started for
1232
+ * it. One the turn that ended never took (it ended as the steer was placed) is placed again, which writes nothing twice
1233
+ * and starts the session's next turn. A turn that ends without the model taking it is that end: its row stays untaken. */
1234
+ const cliSteerAnswered = async (theSession, requestId) => {
1235
+ const steer = cliSteers.get(requestId);
1236
+ if (!steer)
1237
+ return theSession.turnEnd();
1238
+ if (!takenIds.has(requestId))
1239
+ await theSession.steer(steer.text, requestId, "steer", steer.origin ? { origin: steer.origin } : undefined);
1240
+ const end = await Promise.race([steer.recorded.then(() => undefined), theSession.turnEnd()]);
1241
+ if (end !== undefined && !takenIds.has(requestId))
1242
+ return end;
1243
+ await steer.recorded;
1244
+ cliSteers.delete(requestId);
1245
+ return theSession.turnEnd();
1246
+ };
1155
1247
  /** A message the turn in flight could not take (afterTurn), sent as a turn of its own. Its row is taken only once the
1156
1248
  * session holds the prompt (send resolves once it is placed): in the commit that writes it on the run's record, right
1157
1249
  * after the send (a CLI's session writes no submission to the run's journal), or, for an adapter keeping its own record,
@@ -2148,6 +2240,9 @@ function adapterLoop(specOf, options, deps) {
2148
2240
  // After a CLI's question to the person (TurnCut armed): what its model says is not on the record, as pi's turn says
2149
2241
  // nothing after the question; a call of another tool lets the turn go on.
2150
2242
  const onEvent = (theRecord) => (event) => {
2243
+ // The model took a steer: its record entry, and its row, follow (steerCli).
2244
+ if (event.type === "message_taken")
2245
+ return tookNow(event.ids);
2151
2246
  if (askCut.armed && event.type === "text")
2152
2247
  return;
2153
2248
  if (askCut.armed && event.type === "tool_start")
@@ -2278,11 +2373,11 @@ function adapterLoop(specOf, options, deps) {
2278
2373
  firstInputPlaced = new Promise((resolve) => (mine.placed = resolve));
2279
2374
  reopen = mine;
2280
2375
  }
2281
- // A CLI run parked on its question (its turn cut there, TurnCut): its session takes no steer, so the person's
2282
- // answer is this claim's turn, sent as a reopened run's follow-up is (steer, through `reopen`), the row's waiting
2283
- // summary going in its take. A turn the session still reads open is the one the cut stopped: settled first,
2284
- // never recovered (recovered, the CLI would go on past its question).
2285
- if (!endsRoot && !inFlight && spec.record === "loop" && !session.steer && turnEndedOnAsk(foundEntries) !== undefined) {
2376
+ // A CLI run parked on its question (its turn cut there, TurnCut): no turn is in flight for a steer to reach (a CLI
2377
+ // steers only the turn in flight), so the person's answer is this claim's turn, sent as a reopened run's follow-up
2378
+ // is (steer, through `reopen`), the row's waiting summary going in its take. A turn the session still reads open is
2379
+ // the one the cut stopped: settled first, never recovered (recovered, the CLI would go on past its question).
2380
+ if (!endsRoot && !inFlight && spec.record === "loop" && turnEndedOnAsk(foundEntries) !== undefined) {
2286
2381
  if (session.state === "open_turn")
2287
2382
  await session.settleOpenTurn();
2288
2383
  if (session.state === "idle")
@@ -2779,7 +2874,7 @@ function adapterLoop(specOf, options, deps) {
2779
2874
  // the run's end. One already answered settles at once.
2780
2875
  const steered = cut ? undefined : steeredIn.shift();
2781
2876
  if (steered !== undefined) {
2782
- turn = turnOfRequest(harness, root, steered);
2877
+ turn = record ? cliSteerAnswered(session, steered) : turnOfRequest(harness, root, steered);
2783
2878
  continue;
2784
2879
  }
2785
2880
  // The output contract: an answer whose last json block misses the agent's output schema is asked again, once,
@@ -2900,7 +2995,7 @@ function adapterLoop(specOf, options, deps) {
2900
2995
  return { deny: wrapUpDeny };
2901
2996
  // A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
2902
2997
  const replayed = call.replayed === true;
2903
- const given = (await spec.gate?.(kernelCall, replayed ? { replayed } : {})) ?? "allow";
2998
+ const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf })) ?? "allow";
2904
2999
  // An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape).
2905
3000
  const shown = typeof given === "object" && "ask" in given ? given.ask : undefined;
2906
3001
  let decision = shown ? "ask" : given;
@@ -3085,6 +3180,12 @@ function adapterLoop(specOf, options, deps) {
3085
3180
  * end reads withdrawn: its rows said "Not run: the run ended while it waited" of a call that ran. A deny set since still
3086
3181
  * refuses it first. Read from the journal once a claim: an ask written later in the claim parks it, and an answer
3087
3182
  * written later is read by answerOf itself. */
3183
+ /** The calls of `tool` the run's journal shows now (toolCalls): run to a good end, and every one with a result. Read
3184
+ * over every agent conversation of the run (agentEntriesOf): the root's and each subagent's, so a child's calls count
3185
+ * on the claim after a pause as on the one they ran in. */
3186
+ async function ranOf(tool) {
3187
+ return toolCalls(await agentEntriesOf(gate.journal, context), tool);
3188
+ }
3088
3189
  async function askStands(callId) {
3089
3190
  standing ??= (async () => {
3090
3191
  const conversation = await harness.root(context);
@@ -3177,6 +3278,7 @@ function adapterLoop(specOf, options, deps) {
3177
3278
  * the run's next user message and resumes it on the next claim, as on main: the ask_person tool result stays what pi
3178
3279
  * wrote, so nothing is re-asked or re-billed. The summary is plain words, never the question. */
3179
3280
  async function parkOnAsk(on, conversation, theGate, callId) {
3281
+ parkingOnAsk();
3180
3282
  const parkedAt = theGate.expect(writesEntry(KINDS.personAsked, (entry) => entry.callId === callId), { run: { state: "parked", summary: ASK_PERSON_WAITING } });
3181
3283
  parkedAt.catch(() => undefined);
3182
3284
  await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.personAsked, data: { callId } }), context);
@@ -3263,9 +3365,18 @@ function adapterLoop(specOf, options, deps) {
3263
3365
  * or the session went), and the run parks on its question. Undefined when no host holds anything: the run parks. */
3264
3366
  async function waitInClaim(on, callId) {
3265
3367
  const holders = specNow?.lifecycle?.personWait ?? [];
3266
- if (!holders.length || !session || !gate || gate.sealed || !root)
3267
- return undefined;
3268
3368
  await options.beforePersonWait?.();
3369
+ if (!session || !gate || gate.sealed || !root)
3370
+ return parkingOnAsk();
3371
+ if (!holders.length) {
3372
+ // Nothing to hold open: the run parks, unless the answer already came, between the question's turn end and here,
3373
+ // placed as a steer of the idle session (steer): then its turn is the next, at once, never cut by the park's seal.
3374
+ const early = idleSteer;
3375
+ idleSteer = undefined;
3376
+ if (early && (await early.placed))
3377
+ return { next: turnOfRequest(on, root, early.requestId) };
3378
+ return parkingOnAsk();
3379
+ }
3269
3380
  // Set before anything else: an answer sent from here is the claim's next turn, never a steer into no turn.
3270
3381
  const [theSession, theGate, conversation] = [session, gate, root];
3271
3382
  const mine = {};
@@ -3299,7 +3410,7 @@ function adapterLoop(specOf, options, deps) {
3299
3410
  // Nothing held, and no answer placed meanwhile: the run parks.
3300
3411
  if (!waitHolds.length && !mine.sent) {
3301
3412
  endWait(mine);
3302
- return undefined;
3413
+ return parkingOnAsk();
3303
3414
  }
3304
3415
  // The wait's start, once, in the journal, with the row's waiting summary (the server tells run.needs_input by it).
3305
3416
  if (!marked && !mine.sent) {
@@ -3315,9 +3426,12 @@ function adapterLoop(specOf, options, deps) {
3315
3426
  if (done)
3316
3427
  return;
3317
3428
  done = true;
3318
- if (value === "lapsed")
3429
+ if (value === "lapsed") {
3319
3430
  for (const hold of waitHolds)
3320
3431
  hold.confirmed?.();
3432
+ // The run parks on its question (the turn loop's "lapsed"): the person's next message is the resume's.
3433
+ parkingOnAsk();
3434
+ }
3321
3435
  endWait(mine);
3322
3436
  resolve(value);
3323
3437
  };
@@ -134,6 +134,10 @@ export interface AdapterSpecDeps {
134
134
  * server (runner/beside.ts, Serve.localInstall) is told so, by that server in its own process. Absent, never: a hosted
135
135
  * or standalone runner's loopback is its host's other services. */
136
136
  readonly mcpLoopback?: boolean;
137
+ /** That server's own addresses (Serve.own: where it listens, and its public address on loopback), told with
138
+ * mcpLoopback: a run's loopback request (an MCP server's, its authorization server's, a pin's listing) never goes to
139
+ * their ports, as the server's own requests never do. */
140
+ readonly mcpOwn?: readonly string[];
137
141
  /** A template eval's fakes, by the agent a run is of (template-eval.ts, from its case: EvalFakes). Only the eval's own
138
142
  * runner, in the eval's process, is given it (runner/beside.ts); no environment variable, flag, setting or API field
139
143
  * maps onto it. Absent, or undefined for a run: none. */
@@ -208,6 +212,7 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
208
212
  }): Promise<NonNullable<AdapterRunSpec["gate"]> & {
209
213
  readonly permissions: RunPermissions;
210
214
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
215
+ readonly askedOn: (host: ToolHost) => void;
211
216
  }>;
212
217
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
213
218
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */