@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61

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 (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/runnable.js CHANGED
@@ -11,7 +11,7 @@ import { harnessOf, onAdapter } from "./harness-table.js";
11
11
  import { capShortOf } from "./cap-short.js";
12
12
  import { chooseModel } from "./model.js";
13
13
  import { llmTiers, MODEL_NODES, nodeTiers, unpricedModels, workflowNodes } from "./model.js";
14
- import { boxAvailability, newAgentPlace, placeFix } from "./place.js";
14
+ import { boxAvailability, newAgentPlace, noPlaceIssue, placeFix } from "./place.js";
15
15
  import { allows, BOUND_TOOLS, CALL_TOOLS, grantedTools, missingEnv, NODE_TOOLS, shellTools, toolOf, workflowTools } from "./tools.js";
16
16
  import { DENIED, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
17
17
  import { computerDenied, denyPlace, permissionFrom, permissionKeys, permissionOf } from "./tool-gate.js";
@@ -118,17 +118,30 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
118
118
  // server's folder with the runner-only tools, which the runnerOnly check below holds to a sandbox place alone.
119
119
  const onRunner = revision.kind === "agentic" && shellOf && (place?.mode ?? "runner") === "runner";
120
120
  const runnerShell = onRunner && (await shellOf(revision.computer ?? { kind: "none" })) === "local" ? shellTools("local") : new Set();
121
- /** A shell tool the runner does not run: a box this server runs in is the fix; with none, why it has none
122
- * (capabilities' default_reason) and both ways out, fixing that or keeping the agent on the runner without the tool.
123
- * Where the runner has a shell that runs others (Mode 2's Archil exec runs bash), it says which. */
121
+ /** A shell tool the runner does not run. One that names no place, on a runner with no shell (Mode 1), is there only
122
+ * because Docker's box, its default, is not here (place.ts defaultPlaceOf): it names a box or the runner, in the words
123
+ * its create is refused in (nameABox), never given another box. One whose place is the runner: a box this server runs in is the fix; with none, why
124
+ * Docker's box is not here and both ways out, fixing that or keeping the agent on the runner without the tool. Where
125
+ * the runner has a shell that runs others (Mode 2's Archil exec runs bash), it says which. */
124
126
  const shellOnRunner = (tool, field, named) => {
127
+ const fresh = newAgentPlace(boxes);
128
+ if (!named && !runnerShell.size && "reason" in fresh) {
129
+ // A tool the box refuses (the browser) keeps this agent out of every box, so naming one is no way out: its words
130
+ // say that it is one tool or the other.
131
+ const boxless = (revision.tools ?? []).filter((one) => toolOf(one)?.runnerOnly);
132
+ if (!boxless.length)
133
+ return { ...noPlaceIssue(boxes), host: false, tool };
134
+ const them = new Intl.ListFormat("en", { type: "conjunction" }).format(boxless.map((one) => `"${one}"`));
135
+ return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${boxless.join(", ")} never ${boxless.length > 1 ? "run" : "runs"} in one, so no place runs this agent with both: remove "${tool}" from definition.tools to keep it on the runner, or remove ${them} and name a box.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool };
136
+ }
125
137
  const where = named ? "this agent's place is the runner" : "this agent names no place, so it runs on the runner";
126
138
  const has = runnerShell.size ? `whose shell here runs ${[...runnerShell].join(", ")} alone` : "which has no shell";
127
139
  const box = boxAvailability(boxes).find((b) => b.available);
128
140
  if (box)
129
141
  return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${where}, ${has}: give it a sandbox computer (a sandbox place).`, fix: placeFix({ mode: "sandbox", box: box.id }), host: false, tool };
130
- const fresh = newAgentPlace(boxes);
131
- const why = "reason" in fresh ? fresh.reason : "no box runs execute in is available here";
142
+ // In Mode 2 new agents do run on the runner (placesOf), so its words say so, as they always have; in Mode 1 a new
143
+ // agent names its place, so they say only why Docker's box is not here.
144
+ const why = "why" in fresh ? `${runnerShell.size ? "new agents run on the runner, because " : ""}the docker box is unavailable here: ${fresh.why}` : "no box runs execute in is available here";
132
145
  return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${where}, ${has} (${runnerShell.size ? tool : "a shell"} needs a sandbox computer), and ${why}. Do that, or keep this agent on the runner: name "place": {"mode": "runner"} and remove "${tool}" from definition.tools.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool };
133
146
  };
134
147
  // A harness's own MCP client may drop or retype a shape of a tool's schema (its facts' schemaProblems, measured on its
@@ -199,8 +212,12 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
199
212
  if (!allows(BOUND_TOOLS, tool))
200
213
  out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} is not a tool here: grant one of ${BOUND_TOOLS.join(", ")}, an MCP server's tool as mcp:<server>/<tool>, or a monid endpoint as monid:<provider>/<endpoint>.`, host: false, tool });
201
214
  // A shell runs in a box; on the runner (no place names one) only what its shell here runs (runnerShell).
202
- else if (toolOf(tool).sandboxOnly && (place?.mode ?? "runner") === "runner" && !runnerShell.has(tool))
203
- out.push(shellOnRunner(tool, `definition.tools[${index}]`, !!place && !revision.unnamed));
215
+ // One that names no place is refused at its place, once, whatever shell tools it names.
216
+ else if (toolOf(tool).sandboxOnly && (place?.mode ?? "runner") === "runner" && !runnerShell.has(tool)) {
217
+ const blocker = shellOnRunner(tool, `definition.tools[${index}]`, !!place && !revision.unnamed);
218
+ if (!out.some((b) => b.field === "definition.place" && b.message === blocker.message))
219
+ out.push(blocker);
220
+ }
204
221
  // Its writes into work/ go by path from this machine, and a box's command could swap a link in on their way.
205
222
  else if (toolOf(tool).runnerOnly && place?.mode === "sandbox")
206
223
  out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} does not run in a sandbox place yet: it saves files into the run's work/ from this server, outside the box, and a command in the box could point those writes elsewhere on this server. Give it to an agent whose place is the runner.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool });
@@ -8,7 +8,7 @@ import { type GenAiTracing } from "../otel/tracer.js";
8
8
  import { type AgentOfRun, type RouteTrace } from "../otel/genai.js";
9
9
  type EndCost = Required<Pick<EndData, "costUsd" | "costUpperBound">>;
10
10
  import { type Claim, type EndOfRunTurn, type LoopFactory } from "./loop-contract.js";
11
- import type { HeldRedact } from "./redact.js";
11
+ import { type HeldRedact } from "./redact.js";
12
12
  import { type BoundTimer, Parked } from "./loop.js";
13
13
  import type { PiRun } from "./adapters/pi.js";
14
14
  import { type HeldSpec } from "./held-run.js";
@@ -84,6 +84,13 @@ export type SpecGate = ((call: ToolCall, options?: {
84
84
  /** 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
85
85
  * each ask: what the session reads (SessionIO.permission) for a tool no call of which reaches the gate before it runs. */
86
86
  readonly permission?: (tool: string) => Promise<"allow" | "ask" | "deny">;
87
+ /** The run's learned workflow a learned_workflow call's arguments name (its name and its digest, workflow-first.ts
88
+ * workflowDigest), or undefined for a name the run has none of: what the record of such a call the gate refuses
89
+ * names (learnedEntry). */
90
+ readonly learnedOf?: (args: unknown) => {
91
+ readonly workflow: string;
92
+ readonly digest: string;
93
+ } | undefined;
87
94
  };
88
95
  /** What one claimed run's adapter loop runs. */
89
96
  export interface AdapterRunSpec {
@@ -20,6 +20,7 @@ import { ASK_PERSON_WAITING, capNowOf, endedAnswer, KINDS, MESSAGE_SENT_AGAIN, t
20
20
  import { turnEndedOnAsk } from "../store-reads/journal.js";
21
21
  import { CAP_REFUSED, CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_ORIGIN, originOf, REQUEST_ENDED, REQUEST_STARTED, RUN_RESUMED } from "../timeline/index.js";
22
22
  import { raiseFollowUpId } from "../run-view.js";
23
+ import { connectedLaterWords } from "../mcp-probe.js";
23
24
  import { durableWait } from "../workflow/pi-versions.js";
24
25
  import { genAiTracing } from "../otel/tracer.js";
25
26
  import { tracedAgent, tracedEvent, tracedModel } from "../otel/genai.js";
@@ -43,6 +44,7 @@ const outputRetried = (entries) => {
43
44
  return at >= 0 && entries.slice(at + 1).some((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
44
45
  };
45
46
  import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
47
+ import { mustHold } from "./redact.js";
46
48
  import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
47
49
  import { ADAPTER_API } from "../turn-end.js";
48
50
  import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
@@ -68,7 +70,7 @@ import { Fenced } from "../store/index.js";
68
70
  import { answerAsServed } from "../answer-json.js";
69
71
  import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
70
72
  import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
71
- import { LEARNED_NODES } from "../learned-nodes.js";
73
+ import { failedRecord, LEARNED_ALLOWED, LEARNED_NODES, learnedCallRan, refusedRecord } from "../learned-nodes.js";
72
74
  import { warnHoldShort } from "../print.js";
73
75
  import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
74
76
  import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
@@ -579,6 +581,7 @@ export function createAdapterLoop(spec, options = {}) {
579
581
  return (deps) => adapterLoop(spec, options, deps);
580
582
  }
581
583
  function adapterLoop(specOf, options, deps) {
584
+ mustHold(deps.redact, "An adapter loop");
582
585
  const restartLimit = options.restartLimit ?? DEFAULT_RESTART_LIMIT;
583
586
  const retry = options.retry ?? MODEL_RETRY;
584
587
  const stream = options.stream ?? MODEL_STREAM;
@@ -598,7 +601,7 @@ function adapterLoop(specOf, options, deps) {
598
601
  * (LoopDeps.redact), since a provider's or a computer's error may echo one. */
599
602
  const said = (error) => {
600
603
  const text = error?.message ?? String(error);
601
- return deps.redact ? deps.redact(text) : text;
604
+ return deps.redact(text);
602
605
  };
603
606
  let stopped = () => { };
604
607
  const stopping = new Promise((resolve) => (stopped = resolve));
@@ -710,6 +713,9 @@ function adapterLoop(specOf, options, deps) {
710
713
  let waitHolds = [];
711
714
  /** The wait's own `reopen`, while it is set. */
712
715
  let waitTurn;
716
+ /** Ends the wait in the claim at once, the run parking on its question as a lapse does, though no host's hold lapsed:
717
+ * set while the wait holds (waitInClaim). */
718
+ let endWaitNow;
713
719
  /** The `reopen` of a CLI run parked on its question (its turn cut there: no steer reaches its idle session), while it is
714
720
  * set: the person's answer is the claim's turn, and a trigger's message is no answer. */
715
721
  let askReopen;
@@ -772,6 +778,7 @@ function adapterLoop(specOf, options, deps) {
772
778
  if (reopen === waitTurn)
773
779
  reopen = undefined;
774
780
  waitTurn = undefined;
781
+ endWaitNow = undefined;
775
782
  for (const hold of waitHolds.splice(0)) {
776
783
  try {
777
784
  hold.drop();
@@ -820,6 +827,11 @@ function adapterLoop(specOf, options, deps) {
820
827
  /** The pass's MCP (spec.mcp), until the pass ends; and whether a command row came since its credentials were last made
821
828
  * fresh (a parked token may have expired meanwhile). */
822
829
  let mcp;
830
+ /** The pass's phase row (AdapterRun.phase), until the pass ends; and whether a message of the pass was left for the
831
+ * run's next turn, as one handing the credential of a server its claim left out (steer): every message after it waits
832
+ * too, and the timeline says so once a pass (connectedLaterWords). */
833
+ let phaseNow;
834
+ let leftForNextTurn = false;
823
835
  /** The calls of this run a person was asked about (their ask in the journal, on this claim or read on a resume), set as
824
836
  * the ask is read: one of them the gate lets through was let through by a person's answer. */
825
837
  const askedCalls = new Set();
@@ -1062,6 +1074,28 @@ function adapterLoop(specOf, options, deps) {
1062
1074
  // untaken for the next claim, which hands it on again; never refused for good.
1063
1075
  if (!gate || !session || gate.sealed)
1064
1076
  return { later: "the run is parking: the steer waits for its resume" };
1077
+ // A message that hands the credential of a server whose tools this claim left out (mcpWhereHeld, ClaimMcp.leftOut):
1078
+ // the session's tools are fixed for the claim, so a turn it reached could not call them. Left untaken, it runs as
1079
+ // the run's next turn, on a claim that lists them: the run's end opens it again with the message (as for a message
1080
+ // that comes while the run ends), and a park's resume takes it. Every message after it waits the same way, whatever
1081
+ // the credentials say at its own check (a later message may hand them no longer), so none runs before it. Said once
1082
+ // on the timeline, since the API answered the message as steered.
1083
+ if (leftForNextTurn)
1084
+ return { later: "a message before this one runs as the run's next turn: this one runs after it" };
1085
+ const claimMcp = mcp;
1086
+ const leftOut = claimMcp?.leftOut;
1087
+ if (claimMcp && leftOut?.length) {
1088
+ const still = new Set(await claimMcp.fresh());
1089
+ const handed = leftOut.filter((server) => !still.has(server));
1090
+ if (handed.length) {
1091
+ phaseNow?.(connectedLaterWords(handed));
1092
+ leftForNextTurn = true;
1093
+ // A wait in the claim on the person's answer (waitInClaim) ends here: no message reaches it from now on, the
1094
+ // answer included, so the run parks on its question and its next claim takes them in the order they came.
1095
+ endWaitNow?.();
1096
+ return { later: "the message hands the credential of a server this claim left out: it runs as the run's next turn, which lists its tools" };
1097
+ }
1098
+ }
1065
1099
  // A trigger's message into a session on its owner's sign-in (personOnly): refused for good, before it is queued or
1066
1100
  // placed, so no turn of it reaches the vendor on that sign-in. Known by its origin's kind as written (an origin whose
1067
1101
  // source originOf does not know is still a trigger's), or by answering nothing (answers: false, a trigger's message).
@@ -1178,7 +1212,7 @@ function adapterLoop(specOf, options, deps) {
1178
1212
  const sendId = first ? INPUT_REQUEST : requestId;
1179
1213
  // A run its learned workflow answered alone: the job, what the workflow answered (cut of the runner's secrets, as a
1180
1214
  // handback is), then the message.
1181
- const answered = first && servedAnswer ? servedAnswerText(servedAnswer.workflow, deps.redact ? deps.redact(servedAnswer.answer) : servedAnswer.answer) : undefined;
1215
+ const answered = first && servedAnswer ? servedAnswerText(servedAnswer.workflow, deps.redact(servedAnswer.answer)) : undefined;
1182
1216
  const content = first ? [first.input, ...(answered ? [answered] : []), text].join("\n\n") : text;
1183
1217
  // The row is taken only once the session holds the prompt: pi's in its submission's commit; a CLI's (whose harness
1184
1218
  // writes no submission) in the record's follow-up entry, written right after the send, as sendAfterTurn takes its
@@ -1339,7 +1373,7 @@ function adapterLoop(specOf, options, deps) {
1339
1373
  * it unanswered (outputRetried). Its turn's end is what this gives. */
1340
1374
  const sendOutputRetry = async (why) => {
1341
1375
  outputRetrySent = true;
1342
- const text = outputRetryWords(deps.redact ? deps.redact(why) : why);
1376
+ const text = outputRetryWords(deps.redact(why));
1343
1377
  await cliRecord?.followUp(text, OUTPUT_RETRY_REQUEST, OUTPUT_RETRY_ORIGIN);
1344
1378
  await session.send(text, { id: OUTPUT_RETRY_REQUEST, origin: OUTPUT_RETRY_ORIGIN });
1345
1379
  await specNow?.hooks?.afterMessageSent?.();
@@ -1517,6 +1551,8 @@ function adapterLoop(specOf, options, deps) {
1517
1551
  await phasing.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data }), context);
1518
1552
  })().catch((error) => console.warn(`[runner] a phase row was not written: ${said(error)}`));
1519
1553
  };
1554
+ phaseNow = phase;
1555
+ leftForNextTurn = false;
1520
1556
  const passGate = gate;
1521
1557
  const rowSummaryOn = (kind, test, summary) => {
1522
1558
  if (passGate.sealed)
@@ -2450,6 +2486,33 @@ function adapterLoop(specOf, options, deps) {
2450
2486
  return answer;
2451
2487
  }
2452
2488
  : nestedGate;
2489
+ // An agent's learned_workflow call the gate refuses (a deny set, a person's deny of its ask, the cap's wrap-up)
2490
+ // never reaches the tool, which keeps every other call's record: its record is kept here, as serveFirst keeps the
2491
+ // platform's (learned-nodes.ts refusedRecord), so the run's workflow_calls name it, refused, on pi and on every
2492
+ // CLI alike. A name the run has no workflow of keeps none, as the tool keeps none for it. Each attempt the gate lets
2493
+ // go is marked first (LEARNED_ALLOWED), committed before the tool runs: a call issued again after a crash cut it may
2494
+ // have run nodes and spent on such an attempt, so its refusal is then no proof it ran nothing, and it is kept
2495
+ // `failed`, never `refused`, priced from what its call id booked (failedRecord). The newest of the call's marks and
2496
+ // records says which (learned-nodes.ts learnedCallRan): its bridge can't alone (a tool that nests is asked alike on
2497
+ // every attempt: process/tools.ts runNesting), nor can the call's start on the CLI record, which a refusal writes
2498
+ // too. With neither, the bridge's `replayed` stands in: a run begun before the marks existed has none. Whatever is
2499
+ // kept, a refusal reads `failed` once anything was booked under the call id (workflow-calls.ts workflowCallsOf).
2500
+ const learnedEntry = async (call, answer) => {
2501
+ const named = call.tool === LEARNED_WORKFLOW_TOOL ? spec.gate?.learnedOf?.(call.args) : undefined;
2502
+ const [journalOf, rootOf] = [harness, root];
2503
+ if (!named || !journalOf || !rootOf || !gate || gate.sealed)
2504
+ return;
2505
+ const [kind, data] = answer === "allow"
2506
+ ? [LEARNED_ALLOWED, { call: call.callId }]
2507
+ : [LEARNED_NODES, (learnedCallRan(await entriesOf(gate.journal, rootOf.id, context), call.callId, call.replayed === true) ? failedRecord : refusedRecord)(call.callId, named.workflow, named.digest, "agent")];
2508
+ await journalOf.commit((tx) => tx.appendEntry(rootOf.id, { kind, data: data }), context).catch(unlessSealed);
2509
+ };
2510
+ const sessionGate = async (call, hookContext) => {
2511
+ const answer = await bridgeGate(call, hookContext);
2512
+ if (answer === "allow" || "deny" in answer)
2513
+ await learnedEntry(call, answer);
2514
+ return answer;
2515
+ };
2453
2516
  // A tool no call of which reaches the gate before it runs (Codex's live search, inside its model requests): its
2454
2517
  // setting now, read again at each request, so a deny or ask set mid-run reaches the next one.
2455
2518
  const permission = spec.gate?.permission;
@@ -2483,7 +2546,7 @@ function adapterLoop(specOf, options, deps) {
2483
2546
  trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, ...(deps.redact ? { redact: deps.redact } : {}) }));
2484
2547
  recorded?.(event);
2485
2548
  };
2486
- const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: bridgeGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
2549
+ const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: sessionGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
2487
2550
  // The end-of-run turn an earlier claim asked and never saw end (its runner lost mid look-back or mid compile): the
2488
2551
  // root's newest input still in flight is that turn's (end-of-run.ts REFLECT_PREFIX), which pi picks up again as its
2489
2552
  // session opens. The job's turn ended before it, answered: this pass runs no job turn (no recovery as the job's, no
@@ -2836,9 +2899,9 @@ function adapterLoop(specOf, options, deps) {
2836
2899
  answer = taken(answer);
2837
2900
  const outcome = answer.isError ? "handed_back" : "answered";
2838
2901
  const data = { workflow: first.name, digest: first.digest, ...(first.promotion !== undefined ? { promotion: first.promotion } : {}), revision: first.revision, call: WORKFLOW_FIRST_CALL, outcome };
2839
- // A call refused at its gate keeps its record as one the tool refused does (learned-nodes.ts LEARNED_NODES
2840
- // `refused`): no workflow ran it, so the money rule charges none and the run names none.
2841
- const refusal = refused ? { call: WORKFLOW_FIRST_CALL, workflow: first.name, digest: first.digest, caller: "platform", nodes: [], ended: "failed", refused: true } : undefined;
2902
+ // A call refused at its gate keeps its record as one the tool refused does (learned-nodes.ts refusedRecord): no
2903
+ // workflow ran it, so the money rule charges none and the run names none.
2904
+ const refusal = refused ? refusedRecord(WORKFLOW_FIRST_CALL, first.name, first.digest, "platform") : undefined;
2842
2905
  await on.commit(async (tx) => {
2843
2906
  if (outcome === "answered")
2844
2907
  await tx.appendEntry(theRoot.id, { kind: KINDS.message, data: { role: "model", text: answer.text, at: now() } });
@@ -2897,7 +2960,7 @@ function adapterLoop(specOf, options, deps) {
2897
2960
  else if (served?.outcome === "handed_back") {
2898
2961
  // The agent's first input: the handback, the server's (its row "AgentRun: …"), the job whole after it. Cut of
2899
2962
  // every secret the runner holds: the workflow's words may quote what its steps read.
2900
- const text = deps.redact ? deps.redact(served.text) : served.text;
2963
+ const text = deps.redact(served.text);
2901
2964
  await record?.message(text, HANDED_BACK_ORIGIN);
2902
2965
  await session.send(text, { origin: HANDED_BACK_ORIGIN });
2903
2966
  }
@@ -3005,7 +3068,7 @@ function adapterLoop(specOf, options, deps) {
3005
3068
  // What the model said last, on the record before the run's end.
3006
3069
  await record?.flushText();
3007
3070
  // The turn's end on the record, after its last text: a CLI run reads working until here.
3008
- await record?.turnEnded(outcome.status, outcome.error === undefined ? undefined : deps.redact ? deps.redact(outcome.error) : outcome.error);
3071
+ await record?.turnEnded(outcome.status, outcome.error === undefined ? undefined : deps.redact(outcome.error));
3009
3072
  await harness.waitForIdle(context);
3010
3073
  const settledEntries = await entriesOf(gate.journal, root.id, context);
3011
3074
  const cutOff = restartLimited(settledEntries);
@@ -3053,7 +3116,7 @@ function adapterLoop(specOf, options, deps) {
3053
3116
  // answer (the same row the run's end would have written).
3054
3117
  const said = outcome.error?.trim() ?? "";
3055
3118
  const rootId = root.id;
3056
- await harness.commit((tx) => tx.appendEntry(rootId, { kind: PI_ASSISTANT, model: [cliErrorAnswer(specNow?.adapter.id ?? "cli", said ? cutWhole(deps.redact ? deps.redact(said) : said, TURN_ERROR_MAX) : "the turn gave no answer (failed)", now())] }), context);
3119
+ await harness.commit((tx) => tx.appendEntry(rootId, { kind: PI_ASSISTANT, model: [cliErrorAnswer(specNow?.adapter.id ?? "cli", said ? cutWhole(deps.redact(said), TURN_ERROR_MAX) : "the turn gave no answer (failed)", now())] }), context);
3057
3120
  turn = sendAfterTurn(gate, afterTurn.shift());
3058
3121
  continue;
3059
3122
  }
@@ -3072,7 +3135,7 @@ function adapterLoop(specOf, options, deps) {
3072
3135
  // A CLI's turn (record "loop"; pi journals its own): its error is also main's error row, pi's error answer in the
3073
3136
  // end's commit, cut of every secret the runner holds, so the timeline shows it as an error row with no key in it.
3074
3137
  if (said && spec.record === "loop")
3075
- failedWith = deps.redact ? deps.redact(said) : said;
3138
+ failedWith = deps.redact(said);
3076
3139
  }
3077
3140
  else if (turnEndedOnAsk(settledEntries) !== undefined) {
3078
3141
  // The turn ended on a tool that waits on the person (ask_person ended its turn). With something a tool host keeps
@@ -3605,7 +3668,7 @@ function adapterLoop(specOf, options, deps) {
3605
3668
  /** A job's end as KINDS.jobEnd keeps it: its summary cut of every secret the runner holds, as every summary is when
3606
3669
  * served. */
3607
3670
  function jobEndOf(data, failedWith, endedAt) {
3608
- const end = data.summary !== undefined && deps.redact ? { ...data, summary: deps.redact(data.summary) } : data;
3671
+ const end = data.summary !== undefined ? { ...data, summary: deps.redact(data.summary) } : data;
3609
3672
  return { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
3610
3673
  }
3611
3674
  /** The job's end for a claim that found the end-of-run turn open (lookingBackOpen), or a grade's round (its steer's
@@ -3641,9 +3704,11 @@ function adapterLoop(specOf, options, deps) {
3641
3704
  await options.beforePersonWait?.();
3642
3705
  if (!session || !gate || gate.sealed || !root)
3643
3706
  return parkingOnAsk();
3644
- if (!holders.length) {
3645
- // Nothing to hold open: the run parks, unless the answer already came, between the question's turn end and here,
3646
- // placed as a steer of the idle session (steer): then its turn is the next, at once, never cut by the park's seal.
3707
+ if (!holders.length || leftForNextTurn) {
3708
+ // Nothing to hold open, or a message of this claim is left for the run's next turn (steer), so none, the answer
3709
+ // included, would reach the wait: the run parks, unless the answer already came, between the question's turn end
3710
+ // and here, placed as a steer of the idle session (steer): then its turn is the next, at once, never cut by the
3711
+ // park's seal.
3647
3712
  const early = idleSteer;
3648
3713
  idleSteer = undefined;
3649
3714
  if (early && (await early.placed))
@@ -3695,13 +3760,16 @@ function adapterLoop(specOf, options, deps) {
3695
3760
  const next = new Promise((resolve, reject) => {
3696
3761
  let done = false;
3697
3762
  let lapsed = false;
3763
+ /** Ended by a message left for the run's next turn (endWaitNow), no hold having lapsed. */
3764
+ let cut = false;
3698
3765
  const finish = (value) => {
3699
3766
  if (done)
3700
3767
  return;
3701
3768
  done = true;
3702
3769
  if (value === "lapsed") {
3703
- for (const hold of waitHolds)
3704
- hold.confirmed?.();
3770
+ if (lapsed)
3771
+ for (const hold of waitHolds)
3772
+ hold.confirmed?.();
3705
3773
  // The run parks on its question (the turn loop's "lapsed"): the person's next message is the resume's.
3706
3774
  parkingOnAsk();
3707
3775
  }
@@ -3715,6 +3783,17 @@ function adapterLoop(specOf, options, deps) {
3715
3783
  if (!mine.sent)
3716
3784
  finish("lapsed");
3717
3785
  }, () => undefined);
3786
+ // So does a message left for the run's next turn (steer), the same way; one left while the wait was starting ends it
3787
+ // as soon as it holds.
3788
+ if (waitTurn === mine) {
3789
+ endWaitNow = () => {
3790
+ cut = true;
3791
+ if (!mine.sent)
3792
+ finish("lapsed");
3793
+ };
3794
+ if (leftForNextTurn)
3795
+ endWaitNow();
3796
+ }
3718
3797
  void (async () => {
3719
3798
  for (;;) {
3720
3799
  await placing;
@@ -3726,7 +3805,7 @@ function adapterLoop(specOf, options, deps) {
3726
3805
  // Not placed (the steer was refused): the next message may be.
3727
3806
  mine.sent = undefined;
3728
3807
  placing = new Promise((resolve) => (mine.placed = resolve));
3729
- if (lapsed)
3808
+ if (lapsed || cut)
3730
3809
  return finish("lapsed");
3731
3810
  }
3732
3811
  }
@@ -3748,6 +3827,7 @@ function adapterLoop(specOf, options, deps) {
3748
3827
  // The pass's MCP credentials go with it.
3749
3828
  mcp?.release();
3750
3829
  mcp = undefined;
3830
+ phaseNow = undefined;
3751
3831
  // The pass's resources go once nothing more is written through them (AdapterRunSpec.release), once each.
3752
3832
  // A park's keeps the run's computer (keepAtPark).
3753
3833
  const release = releaseNow;
@@ -3865,7 +3945,7 @@ function adapterLoop(specOf, options, deps) {
3865
3945
  // A grade's feedback round (feedbackNow): its first ask is told the grade first (feedback-round.ts feedbackAsk), cut
3866
3946
  // of every secret the runner holds. Only a run the agent finished opens one, so its session saw the job.
3867
3947
  if (feedbackNow && !again && step === undefined) {
3868
- const cut = (text) => (deps.redact ? deps.redact(text) : text);
3948
+ const cut = (text) => deps.redact(text);
3869
3949
  prompt = `${feedbackAsk({ ...feedbackNow, text: cut(feedbackNow.text) })}\n\n${prompt}`;
3870
3950
  }
3871
3951
  let timer;
@@ -376,11 +376,9 @@ export declare function liveViewersOf(store: LiveViewerStore, sealKey: Buffer |
376
376
  drop(tag?: string): Promise<void>;
377
377
  };
378
378
  /** `tool` with its answer's text, and a throw's message, cut by `cut` (the run's one redactor). A web call's answer is cut
379
- * string by string inside its JSON (timeline/web-calls.ts webCut), so what the harness stores still parses and keeps
380
- * its links whole for a grader's link check; one whose strings, read joined, hold a held value no cut in place takes (a
381
- * value split across two of them) is "[redacted]" (webHeld). The join is read against the values `cut` holds
382
- * (key-refusal.ts withheldWhole), or through `cut` itself when it does not know them (joinCut). Each string is cut once
383
- * in a call, for the join's read and the answer both. */
379
+ * string by string inside its JSON (tools.ts webAnswerCut), so what the harness stores still parses and keeps its links
380
+ * whole for a grader's link check; one whose strings, read joined, hold a held value split across two of them is
381
+ * "[redacted]". */
384
382
  export declare function answersCut(tool: HostTool, cut: Redact): HostTool;
385
383
  /** The ToolHost a run's non-hand tools bind through, the one both the pi spec and the CLI spec build: the run's folder and
386
384
  * the claim's environment (claim-secrets.ts: the run's keys from the store, its plane set), the run's registry for an