@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
@@ -1,7 +1,6 @@
1
1
  import type { Duplex } from "node:stream";
2
2
  import { type GenAiTracing } from "../otel/tracer.js";
3
3
  import { type HeldRedact, type Redact } from "./redact.js";
4
- import type { Workspace } from "../workspace/workspace.js";
5
4
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
6
5
  import type { ClaudeAgentLogin } from "@parcha/agentrun-harness-claude";
7
6
  import type { Held } from "./held.js";
@@ -141,13 +140,6 @@ export declare function heldFor(deps: AdapterSpecDeps & {
141
140
  release(): Promise<void>;
142
141
  projectEnd?(): Promise<void>;
143
142
  };
144
- /** A call of the learning folder a run's process asks (Held.learning), on the runner's own Workspace of the claim's
145
- * agent's folder: reads pass, and the learning script runs its reads, with the script's own environment (the script
146
- * laid by the runner as the folder's own); nothing the process asks writes there. */
147
- export declare function learningCall(folder: {
148
- readonly workspace: Workspace;
149
- end(): Promise<void>;
150
- }, method: string, args: readonly unknown[]): Promise<unknown>;
151
143
  /** What the runner's child loops share: its deps (its seal key), its isolation, its slots, its log. */
152
144
  export interface ChildLoopsOptions {
153
145
  readonly deps: AdapterSpecDeps & {
@@ -165,7 +157,7 @@ export interface ChildLoopsOptions {
165
157
  export declare const childArgv: () => string[];
166
158
  /** Whether a run stays in its runner's process rather than one of its own: one that runs no agent's code or tool here.
167
159
  * A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
168
- * and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
160
+ * and its one write is the merge into the agent's learning, which no run's process may write. An SDK backend
169
161
  * run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
170
162
  * its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
171
163
  * A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
@@ -43,7 +43,6 @@ import { withinCarried } from "../paid-calls.js";
43
43
  import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
44
44
  import { runZone } from "../environment.js";
45
45
  import { shadowRunId } from "../learn/audit.js";
46
- import { LEARNING_SCRIPT, learningWorkspace } from "../learn/folder.js";
47
46
  import { agreeOnOf } from "../learning-setting.js";
48
47
  import { openedAtUse, openRunWorkspace } from "../workspace/run-workspace.js";
49
48
  import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
@@ -56,7 +55,7 @@ import { githubAppAccess } from "./github-app.js";
56
55
  import { githubPullOf, githubTargetOf } from "../github.js";
57
56
  import { isObject } from "../validate.js";
58
57
  import { liveForRun, runnerLiveOf } from "../live-reach.js";
59
- import { learningFolderOf, secretsShown } from "../learning.js";
58
+ import { secretsShown } from "../learning.js";
60
59
  import { learningStartOf, seedFailed } from "../run-launch.js";
61
60
  import { messageText } from "../run-manifest.js";
62
61
  import { filesToCopy, placeRunInputs } from "../uploads.js";
@@ -409,15 +408,14 @@ const ownWrittenSettings = (bound) => new Map([
409
408
  * over, and the server parses the row on every read of the run and every Screen poll. */
410
409
  const OWN_ROW_MAX_BYTES = 4096;
411
410
  /** The settings of the claim's own run and agent a run's process may read: its run's Archil disk, SDK record, kept
412
- * computer, browser wait and browser take, and its agent's Archil disk and promotions. Every other row (another run's
413
- * or agent's) is not its to read. */
411
+ * computer, browser wait and browser take, and its agent's Archil disk. Every other row (another run's or agent's)
412
+ * is not its to read. */
414
413
  const ownSettings = (bound) => new Set([
415
414
  `archil.run.${bound.claim.runId}`,
416
415
  `sdk-run:${bound.claim.runId}`,
417
416
  keptKeyOf(bound.claim.runId),
418
417
  ...ownWrittenSettings(bound).keys(),
419
418
  `archil.agent.${bound.agentId}`,
420
- `learning.promotions.${bound.agentId}`,
421
419
  ]);
422
420
  /** Whether a run's process may read setting `key`. */
423
421
  export const settingReadable = (key, bound) => typeof key === "string" && (SHARED_SETTINGS.has(key) || ownSettings(bound).has(key));
@@ -484,6 +482,8 @@ const STORE_CALLS = new Map([
484
482
  ["learning.proposals", ownAgent],
485
483
  ["learning.list", ownAgent],
486
484
  ["learning.get", always],
485
+ // Its agent's learning at a save (learning-seed.ts layLearningSeed): read only, its agent's alone.
486
+ ["learning.itemsAt", ownAgent],
487
487
  ["computerLedger.book", ownClaim],
488
488
  ["computerLedger.list", ownRun],
489
489
  ["live.put", ownClaim],
@@ -686,15 +686,6 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
686
686
  * A faux run still runs its learned steps on the faux model: only modelRefused refuses them. */
687
687
  const keyless = sendsNoModelKey(launch, deps.env ?? {});
688
688
  const refusedSpend = () => new ClaimRefused("a held run its model kept from running asks its runner for no model spend: it routes no model and takes no learning step");
689
- const learningFolder = async () => {
690
- const made = await archilOf();
691
- return made === undefined ? learningFolderOf(deps.data, run.agentId) : learningWorkspace({ mode: "archil", agentId: run.agentId, archil: made });
692
- };
693
- /** The learning folder's reader, made once the claim's Archil claim is known (learnedFirst's folder is synchronous). */
694
- const folderNow = async () => {
695
- const made = await archilOf();
696
- return () => (made === undefined ? learningFolderOf(deps.data, run.agentId) : learningWorkspace({ mode: "archil", agentId: run.agentId, archil: made }));
697
- };
698
689
  /** What a learned workflow must never hold, as this runner sees it: every secret it holds (learning-seed.ts). */
699
690
  const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(store, sealKey, deps.data)), { local: true });
700
691
  /** The workflows the claim's learned_workflow tool runs, as this runner chose them (held.learnedFirst): what scopes the
@@ -834,7 +825,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
834
825
  const overTheDisk = disk === undefined ? undefined : openedAtUse(() => openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: disk, sweep: false, log }));
835
826
  if (overTheDisk)
836
827
  releases.push(() => overTheDisk.end());
837
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => (overTheDisk === undefined ? runFolder(deps.data, run.agentId, claim.runId) : mountedFolder ?? overTheDisk.workspace()), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, undefined, launch) });
828
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, toolSettings: revision.body.toolSettings, work: () => (overTheDisk === undefined ? runFolder(deps.data, run.agentId, claim.runId) : mountedFolder ?? overTheDisk.workspace()), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, undefined, launch) });
838
829
  if (!made)
839
830
  return undefined;
840
831
  releases.push(() => made.release());
@@ -934,7 +925,6 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
934
925
  signInForgotten: (resolution) => forgottenSignIns(store, sealKey, run.agentId, String(resolution)),
935
926
  emailAccount: async () => (grantsEmail(granted) ? openAccount(store, sealKey) : undefined),
936
927
  calendar: async () => (granted.includes(CALENDAR_EVENTS) ? openCalendar(store, sealKey) : undefined),
937
- learning: async (method, args) => learningCall(await learningFolder(), method, args),
938
928
  install: async (name, signal) => {
939
929
  const harness = launch.harness ?? revision.body.harness;
940
930
  const entry = harness === undefined ? undefined : harnessOf(deps.env, harness);
@@ -1015,14 +1005,13 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
1015
1005
  // compares its answer with the other one through its grader, handed in by the run's process (runner/compare-end.ts).
1016
1006
  // This runner reads both answers and the learning ledger, which no run's process may.
1017
1007
  if (launch.replay || launch.audit) {
1018
- const compare = compareEndOfRun(launch, { store, folder: await folderNow(), log, redact: cut });
1008
+ const compare = compareEndOfRun(launch, { store, log, redact: cut });
1019
1009
  const grade = input.grade;
1020
1010
  const rows = compare && grade && typeof input.grader === "string"
1021
1011
  ? await compare({ runId: claim.runId, agentId: run.agentId, claim, outcome: input.outcome === "failed" ? "failed" : "completed", ...(input.cut === undefined ? {} : { cut: "faulted" }), grader: input.grader, grade: (request) => grade(request), ask: input.ask, signal: input.signal })
1022
1012
  : undefined;
1023
1013
  return rows?.compared ? { also: [], compared: dataOnly(rows.compared) } : undefined;
1024
1014
  }
1025
- const made = await archilOf();
1026
1015
  // The audit's spend, skipped as the run's spec skips it (claim-secrets.ts claimSpendOff): over the claim's own key.
1027
1016
  const spendOff = await claimSpendOff(keys, await claimModelKey(keys, claim.runId));
1028
1017
  // The audit's start after the step (audit.ts withAudit) is this runner's too: it reads the run's journal and writes
@@ -1036,8 +1025,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
1036
1025
  stored: () => storeSecrets(store, sealKey, deps.data),
1037
1026
  log,
1038
1027
  decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys(keys, DECISION_PROVIDER_KEYS)) }),
1039
- learningFolder: made === undefined ? (agentId) => learningFolderOf(deps.data, agentId) : (agentId) => learningWorkspace({ mode: "archil", agentId, archil: made }),
1040
- }), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, folder: await folderNow(), shown, log, sealKey, spendOff, launch, redact: cut, admitAuxiliary });
1028
+ }), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, shown, log, sealKey, spendOff, launch, redact: cut, admitAuxiliary });
1041
1029
  if (!step)
1042
1030
  return undefined;
1043
1031
  // keptOf is the run's process's, asked over the channel: read once, for the round learningEndOfRun reads (the
@@ -1065,11 +1053,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
1065
1053
  // the process's lay chose them: none where its lay laid none (`laid` false: a read that failed, a seed with no
1066
1054
  // workflows).
1067
1055
  const start = learningStartOf(launch);
1068
- const folder = await folderNow();
1069
- const laid = ask?.laid === true && start && !seedFailed(start) && !start.noWorkflows ? await workflowsAt({ folder, store, shown }, start.seed).catch(() => []) : [];
1056
+ const laid = ask?.laid === true && start && !seedFailed(start) && !start.noWorkflows ? await workflowsAt({ store, agentId: run.agentId, shown }, start.seed).catch(() => []) : [];
1070
1057
  const spendOff = await claimSpendOff(keys, await claimModelKey(keys, claim.runId));
1071
1058
  const outputSchema = revision.body.outputSchema;
1072
- const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, folder, shown, spendOff, admitAuxiliary }, laid);
1059
+ const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, shown, spendOff, admitAuxiliary }, laid);
1073
1060
  learnedFlows = got.workflows;
1074
1061
  return cutDeep(dataOnly(got), cut);
1075
1062
  })()),
@@ -1118,54 +1105,11 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
1118
1105
  }
1119
1106
  /** `env`'s string values. */
1120
1107
  const stringsOf = (env) => Object.fromEntries(Object.getOwnPropertyNames(env).flatMap((name) => (typeof env[name] === "string" ? [[name, env[name]]] : [])));
1121
- /** The learning-script ops a run's process may run (learn/folder.ts): its reads alone. The folder's writers (the
1122
- * end-of-run step's check, the learning run's merge, a repair) are the runner's. */
1123
- const LEARNING_OPS = new Set(["read", "show", "has", "log", "diff", "status"]);
1124
- /** A call of the learning folder a run's process asks (Held.learning), on the runner's own Workspace of the claim's
1125
- * agent's folder: reads pass, and the learning script runs its reads, with the script's own environment (the script
1126
- * laid by the runner as the folder's own); nothing the process asks writes there. */
1127
- export async function learningCall(folder, method, args) {
1128
- const ws = folder.workspace;
1129
- try {
1130
- switch (method) {
1131
- case "read":
1132
- return await ws.read(String(args[0]), args[1]);
1133
- case "stat":
1134
- return dataOnly(await ws.stat(String(args[0])));
1135
- case "list":
1136
- return dataOnly(await ws.list(String(args[0])));
1137
- case "grep":
1138
- return dataOnly(await ws.grep(String(args[0]), args[1]));
1139
- case "write":
1140
- // The learning script laid as learn/folder.ts lays it (ensureScript, before a script run): the runner's own text.
1141
- if (args[0] === LEARNING_SCRIPT.file())
1142
- return await LEARNING_SCRIPT.ensure(ws);
1143
- throw new ClaimRefused(`a run's process may not write ${JSON.stringify(args[0])} in its learning folder`);
1144
- case "append":
1145
- case "remove":
1146
- case "mkdir":
1147
- throw new ClaimRefused(`a run's process may not ${method} ${JSON.stringify(args[0])} in its learning folder`);
1148
- case "exec": {
1149
- const argv = args[0];
1150
- const options = (args[1] ?? {});
1151
- if (!Array.isArray(argv) || argv[0] !== "sh" || argv[1] !== LEARNING_SCRIPT.file() || !LEARNING_OPS.has(String(argv[2])) || !argv.every((part) => typeof part === "string"))
1152
- throw new ClaimRefused("a run's process runs no program in its learning folder but its learning script");
1153
- await LEARNING_SCRIPT.ensure(ws);
1154
- return dataOnly(await ws.exec(argv, { env: LEARNING_SCRIPT.env(), timeoutMs: LEARNING_SCRIPT.timeoutMs(), ...(options.stdin instanceof Uint8Array ? { stdin: options.stdin } : {}) }));
1155
- }
1156
- default:
1157
- throw new ClaimRefused(`a run's learning folder has no ${method} in its process`);
1158
- }
1159
- }
1160
- finally {
1161
- await folder.end().catch(() => undefined);
1162
- }
1163
- }
1164
1108
  /** The node and module a run's process starts with. */
1165
1109
  export const childArgv = () => [process.execPath, "--import", new URL("../secrets.js", import.meta.url).pathname, new URL("./run-child.js", import.meta.url).pathname];
1166
1110
  /** Whether a run stays in its runner's process rather than one of its own: one that runs no agent's code or tool here.
1167
1111
  * A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
1168
- * and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
1112
+ * and its one write is the merge into the agent's learning, which no run's process may write. An SDK backend
1169
1113
  * run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
1170
1114
  * its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
1171
1115
  * A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
@@ -1264,7 +1208,7 @@ export function runChannel(socket, onClose, gate = SERVER_SLOTS, more = {}) {
1264
1208
  /** `login`: the Claude login this run's claim read (staysInRunner), the one its runner hands the run (ClaimReads). */
1265
1209
  function childLoop(options, slots, loopDeps, login) {
1266
1210
  const { deps, isolation } = options;
1267
- const cut = loopDeps.redact ?? ((text) => text);
1211
+ const cut = loopDeps.redact;
1268
1212
  const log = (line) => options.log(cut(line));
1269
1213
  let channel;
1270
1214
  let child;
@@ -120,7 +120,7 @@ export interface RunnerOptions {
120
120
  onBeat?: () => void;
121
121
  /** Whether this runner may claim now: undefined while it may, else why not, in words a person can act on (runner/main.ts
122
122
  * diskFreeGate: a runner whose data directory is not the server's, while the server keeps runs' folders on its own
123
- * disk). Asked before each poll's claims (`fresh` false: an answer a few seconds old will do) and again, fresh, once a
123
+ * disk; a runner given an Archil region whose S3 URL may not be the server's). Asked before each poll's claims (`fresh` false: an answer a few seconds old will do) and again, fresh, once a
124
124
  * poll claimed any, before a loop starts on them: a run claimed as the answer changed is released at once, untouched,
125
125
  * for a runner that can serve it. While it refuses, the runner claims nothing and says why on its presence row, where
126
126
  * the server reads it (presence.ts runnersRefused); a throw is said as an error and that poll claims nothing. Absent:
@@ -5,8 +5,7 @@ import { setTimeout as delay } from "node:timers/promises";
5
5
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
6
6
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
7
7
  import { freeRequestLimitOf } from "@parcha/agentrun-kernel/kernel/cap";
8
- import { learningFolderOf, secretsShown } from "../learning.js";
9
- import { refusedIn } from "../purged-workflow.js";
8
+ import { secretsShown } from "../learning.js";
10
9
  import { said, STOPPED } from "../learning-words.js";
11
10
  import { cliPolicyOf, closeSdkInbox, sdkInbox } from "../sdk/runs.js";
12
11
  import { settleSdkCheck } from "../sdk/check.js";
@@ -19,12 +18,14 @@ import { capNowOf, KINDS } from "./journal-kinds.js";
19
18
  import { bookedSpend } from "./metrics.js";
20
19
  import { stopEnd } from "./loop-contract.js";
21
20
  import { END_PATCH_MS, END_PATCH_UNKNOWN, REAL_TIMER } from "./loop.js";
21
+ import { mustHold } from "./redact.js";
22
22
  import { storeSecrets } from "./store-secrets.js";
23
23
  const ROOT = ROOT_CONVERSATION_ID;
24
24
  export function createSdkLoop(launch, host, route) {
25
25
  const execution = launch.cli_learning ?? launch.sdk;
26
26
  const MARK = launch.cli_learning ? "agentrun.cli" : "agentrun.sdk";
27
27
  return (deps) => {
28
+ mustHold(deps.redact, "An SDK loop");
28
29
  let stopped;
29
30
  const abort = new AbortController(), signal = AbortSignal.any([deps.signal, abort.signal]);
30
31
  let settled;
@@ -79,7 +80,7 @@ export function createSdkLoop(launch, host, route) {
79
80
  });
80
81
  return asked?.data?.kept;
81
82
  };
82
- const redacted = (value) => deps.redact?.(value) ?? value;
83
+ const redacted = (value) => deps.redact(value);
83
84
  let also;
84
85
  const droppedLearning = (cancelled) => launch.learning && !launch.learning.use ? [{
85
86
  table: "learning_proposals",
@@ -103,7 +104,6 @@ export function createSdkLoop(launch, host, route) {
103
104
  store: host.store, agentId: agent, launch, inbox,
104
105
  shown: async () => secretsShown(Object.values(await storeSecrets(host.store, host.sealKey, host.data)), { local: true }),
105
106
  log: (line) => host.log?.(line),
106
- refused: refusedIn(() => learningFolderOf(host.data, agent), host.store, (line) => host.log?.(line)),
107
107
  });
108
108
  }
109
109
  catch (error) {
@@ -194,6 +194,7 @@ export function createSdkLoop(launch, host, route) {
194
194
  kind: KINDS.callStart,
195
195
  data: { callId: event.id, tool: event.name, input: event.input ?? {}, replaySafe: false,
196
196
  ...(event.parent_tool_use_id ? { parentCallId: event.parent_tool_use_id } : {}),
197
+ ...(event.name === "learned_workflow" && inbox.workflow_calls && Object.hasOwn(inbox.workflow_calls, event.id) ? { workflow: inbox.workflow_calls[event.id] } : {}),
197
198
  },
198
199
  });
199
200
  }
@@ -285,7 +286,6 @@ export function createSdkLoop(launch, host, route) {
285
286
  const end = learningEndOfRun(launch, {
286
287
  store: host.store,
287
288
  data: host.data,
288
- learningFolder: (id) => learningFolderOf(host.data, id),
289
289
  env: host.env ?? process.env,
290
290
  stored: () => storeSecrets(host.store, host.sealKey, host.data),
291
291
  });
@@ -405,7 +405,7 @@ export function createSdkLoop(launch, host, route) {
405
405
  const spend = bookedSpend(entries.map(({ kind, conversationId, data }) => ({ kind, conversationId, data })), "model");
406
406
  const turns = entries.filter((entry) => entry.kind === "runner.turn").map((entry) => entry.data).filter((turn) => !turn.givenBack && !turn.unsent);
407
407
  const tokens = (key) => spend.unmetered || turns.some((turn) => typeof turn.usage?.[key] !== "number") ? null : spend.tokens[key];
408
- const path = completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {};
408
+ const path = completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch, { redact: deps.redact }) : {};
409
409
  return {
410
410
  costUsd: spend.usd,
411
411
  metrics: { ...metrics, input: tokens("input"), output: tokens("output"), cacheRead: tokens("cacheRead"), cacheWrite: tokens("cacheWrite"), ...path },
@@ -424,7 +424,7 @@ export function createSdkLoop(launch, host, route) {
424
424
  also = droppedLearning(cancelled);
425
425
  const patch = await patchOf(async () => ({
426
426
  costUsd: usage?.cost_usd ?? null,
427
- metrics: { ...metrics, ...(completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {}) },
427
+ metrics: { ...metrics, ...(completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch, { redact: deps.redact }) : {}) },
428
428
  }));
429
429
  await append([
430
430
  {
@@ -5,5 +5,8 @@ import type { EntryLike } from "../timeline/index.js";
5
5
  * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
6
6
  * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
7
7
  * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
8
- * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
8
+ * before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
9
+ * call id (bookedUnder); one an earlier attempt spent under (a crash cut it, and its rerun was refused: at its gate, at
10
+ * runLearned's check of its call nodes' tools, or the platform's at serveFirst) is `failed`, at what it booked. A
11
+ * record that names no digest or caller is left out. */
9
12
  export declare function workflowCallsOf(entries: readonly EntryLike[]): WorkflowCall[];
@@ -7,7 +7,7 @@
7
7
  import { WORKFLOW_CALLERS } from "../learning-cost.js";
8
8
  import { learnedCallEntries } from "../learned-nodes.js";
9
9
  import { KINDS } from "./journal-kinds.js";
10
- import { callCostOf } from "./metrics.js";
10
+ import { callCostOf, callTurnsOf } from "./metrics.js";
11
11
  import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
12
12
  const dataOf = (entry) => (entry.data ?? {});
13
13
  const callIdOf = (entry) => {
@@ -82,24 +82,23 @@ function piShared(entries, from, to) {
82
82
  }
83
83
  return false;
84
84
  }
85
- /** What call `callId` booked (runner/metrics.ts callCostOf), over the window from its start (its call start entry, or on
86
- * pi the answer that asked for it) to the later of its end (its call end, or pi's tool result) and its record
87
- * (`recordAt`); null when the window is not its alone: no start, a pi answer that asked for another call beside it,
88
- * another conversation's tool at work in it on pi (piShared: a sibling subagent's), or another call (none of its own)
89
- * started within it or still open at its start (a nesting tool's, or the call it runs inside, is its own). Never a
90
- * guess: a cost that can't be told apart is unknown. */
91
- function callUsdOf(entries, callId, recordAt) {
85
+ /** Call `callId`'s window in `entries`, from its start (its call start entry, or on pi the answer that asked for it) to
86
+ * the later of its end (its call end, or pi's tool result) and its record (`recordAt`); none when the window is not its
87
+ * alone: no start, a pi answer that asked for another call beside it, another conversation's tool at work in it on pi
88
+ * (piShared: a sibling subagent's), or another call (none of its own) started within it or still open at its start (a
89
+ * nesting tool's, or the call it runs inside, is its own). */
90
+ function callWindowOf(entries, callId, recordAt) {
92
91
  const started = entries.findIndex((entry) => entry.kind === KINDS.callStart && callIdOf(entry) === callId);
93
92
  const asked = started < 0 ? entries.findIndex((entry) => piCallsOf(entry).includes(callId)) : -1;
94
93
  const from = started >= 0 ? started : asked;
95
94
  if (from < 0 || from > recordAt)
96
- return null;
95
+ return undefined;
97
96
  if (asked >= 0 && piCallsOf(entries[asked]).length > 1)
98
- return null;
97
+ return undefined;
99
98
  const start = (started >= 0 ? entries[from].data : {});
100
99
  const to = Math.max(recordAt, entries.findLastIndex((entry) => (entry.kind === KINDS.callEnd && callIdOf(entry) === callId) || piResultOf(entry) === callId));
101
100
  if (asked >= 0 && piShared(entries, from, to))
102
- return null;
101
+ return undefined;
103
102
  // A call that holds this one (a nesting tool's: its id a prefix of this one's, or the harness's own call it runs in).
104
103
  const holds = (id) => callId.startsWith(`${id}/`) || start.parent === id || start.parentCallId === id;
105
104
  const open = new Set();
@@ -114,21 +113,36 @@ function callUsdOf(entries, callId, recordAt) {
114
113
  open.delete(id);
115
114
  }
116
115
  if ([...open].some((id) => !holds(id)))
117
- return null;
116
+ return undefined;
118
117
  for (let at = from + 1; at <= to; at++) {
119
118
  const entry = entries[at];
120
119
  const id = callIdOf(entry);
121
120
  if (entry.kind === KINDS.callStart && id !== undefined && !within(id, callId))
122
- return null;
121
+ return undefined;
123
122
  }
124
- return callCostOf(entries, callId, from, to);
123
+ return { from, to };
124
+ }
125
+ /** What call `callId` booked (runner/metrics.ts callCostOf) over its window (callWindowOf); null with none. Never a
126
+ * guess: a cost that can't be told apart is unknown. */
127
+ function callUsdOf(entries, callId, recordAt) {
128
+ const window = callWindowOf(entries, callId, recordAt);
129
+ return window ? callCostOf(entries, callId, window.from, window.to) : null;
130
+ }
131
+ /** Whether anything was booked under call `callId` (runner/metrics.ts callTurnsOf): a request named under it, or one of
132
+ * host work in its window while that window is its alone. */
133
+ function bookedUnder(entries, callId, recordAt) {
134
+ const window = callWindowOf(entries, callId, recordAt);
135
+ return callTurnsOf(entries, callId, window?.from ?? -1, window?.to ?? -1).size > 0;
125
136
  }
126
137
  /** Each learned workflow call run `entries` show (every conversation's, in log order: store-reads/journal.ts runEntries),
127
138
  * in the order the calls first kept a record, from the record that counts for each (a call run again after a park or a
128
139
  * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
129
140
  * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
130
141
  * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
131
- * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
142
+ * before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
143
+ * call id (bookedUnder); one an earlier attempt spent under (a crash cut it, and its rerun was refused: at its gate, at
144
+ * runLearned's check of its call nodes' tools, or the platform's at serveFirst) is `failed`, at what it booked. A
145
+ * record that names no digest or caller is left out. */
132
146
  export function workflowCallsOf(entries) {
133
147
  // The record that counts for each call (learned-nodes.ts learnedCallEntries): a rerun refused before any node ran leaves
134
148
  // the attempt that ran standing, as the call's timeline row does.
@@ -139,9 +153,12 @@ export function workflowCallsOf(entries) {
139
153
  const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && ["answered", "handed_back"].includes(String(entry.data?.outcome)))?.data;
140
154
  const calls = [...newest].map(([call, at]) => {
141
155
  const data = dataOf(entries[at]);
142
- // Refused before any node ran (its record's `refused`): it ran nothing, whatever the run did after.
143
- const outcome = data.refused === true ? "refused" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
144
- return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd: callUsdOf(entries, call, at) };
156
+ // Refused before any node ran (its record's `refused`) with nothing booked under its id: it ran nothing, whatever the
157
+ // run did after. Refused with something booked: an earlier attempt ran and spent, so it failed.
158
+ const refused = data.refused === true && !bookedUnder(entries, call, at);
159
+ const outcome = refused ? "refused" : data.refused === true ? "failed" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
160
+ // A refused call ran nothing: its $ is 0, never a shared window's unknown (two denied calls in one pi answer).
161
+ return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd: refused ? 0 : callUsdOf(entries, call, at) };
145
162
  });
146
163
  if (served && !newest.has(WORKFLOW_FIRST_CALL) && typeof served.workflow === "string" && typeof served.digest === "string") {
147
164
  calls.unshift({ workflow: served.workflow, digest: served.digest, caller: "platform", outcome: served.outcome, usd: null });
@@ -5,7 +5,7 @@ import type { Workflow } from "@parcha/agentrun-dsl";
5
5
  import { type WorkflowTaskHost } from "../workflow/task.js";
6
6
  import { type BudgetData, type EndData } from "./journal-kinds.js";
7
7
  import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
8
- import type { HeldRedact } from "./redact.js";
8
+ import { type HeldRedact } from "./redact.js";
9
9
  /** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
10
10
  * via the spec, so flat or tiered pricing is the cap's, not this loop's). */
11
11
  /** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
@@ -23,6 +23,7 @@ import { createWorkflowExtension } from "../workflow/task.js";
23
23
  import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
24
24
  import { KINDS } from "./journal-kinds.js";
25
25
  import { stopEnd } from "./loop-contract.js";
26
+ import { mustHold } from "./redact.js";
26
27
  import { END_PATCH_MS, END_PATCH_UNKNOWN, readAgain } from "./loop.js";
27
28
  /** A paused run's words, its row's summary while it waits for a resume. */
28
29
  export const PAUSED_WORDS = "Paused.";
@@ -34,6 +35,7 @@ export function createWorkflowLoop(specOf) {
34
35
  return (deps) => workflowLoop(specOf, deps);
35
36
  }
36
37
  function workflowLoop(specOf, deps) {
38
+ mustHold(deps.redact, "A workflow loop");
37
39
  let harness;
38
40
  let workflows;
39
41
  let runId;
@@ -193,7 +195,7 @@ function workflowLoop(specOf, deps) {
193
195
  const patch = await readAgain(() => endPatch(data), late, (error, tries, last) => {
194
196
  // Cut of every secret the runner holds (LoopDeps.redact): an error's text may echo one.
195
197
  const text = error?.message ?? String(error);
196
- const cut = deps.redact ? deps.redact(text) : text;
198
+ const cut = deps.redact(text);
197
199
  console.warn(last ? `[runner] ${runId}: its end's patch failed ${tries} times, last: ${cut}; the end is written with its cost and metrics unknown` : `[runner] ${runId}: its end's patch failed: ${cut}; read again`);
198
200
  });
199
201
  if (patch === "late") {
@@ -3,6 +3,7 @@ import { type DecisionProvider, type LoadImage, type Workflow } from "@parcha/ag
3
3
  import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
4
4
  import { type ProviderPolicy, type ProxyUsage } from "@parcha/agentrun-kernel/host";
5
5
  import { type CapModel, type RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
6
+ import type { RunLaunch } from "../run-launch.js";
6
7
  import { type Tier } from "../model.js";
7
8
  import { deniedText } from "../refusal-words.js";
8
9
  import { type PaidBooking } from "../paid-calls.js";
@@ -61,6 +62,9 @@ export interface WorkflowSpecDeps {
61
62
  readonly sealKey?: Buffer;
62
63
  /** The runner's data directory: what the server keeps sealed beside the store is read from it (store-secrets.ts). */
63
64
  readonly data?: string;
65
+ /** The claim's plane as the runner hands it (harness-loops.ts: the launch's, under the server's settings now), over the
66
+ * launch's own. */
67
+ readonly plane?: RunLaunch["plane"];
64
68
  /** Resolves the provider and cap model for each tier the workflow names (byTier's model, its provider, its price).
65
69
  * Absent: the runner's model route (routeProviderOf), so a workflow and a pi run resolve models one way; a test gives a
66
70
  * scripted one. */
@@ -23,7 +23,7 @@ import { askedBefore, catalogPrice, JEV_INPUT_USD, PARALLEL_DECISION_USD } from
23
23
  import { decisionProvidersIn } from "../decisions.js";
24
24
  import { imageLoader } from "../pdf-pages.js";
25
25
  import { llmTiers, nodeTiers, workflowNodes } from "../model.js";
26
- import { CALL_TOOLS, toolOf, workflowTools } from "../tools.js";
26
+ import { answersCutInside, CALL_TOOLS, toolOf, workflowTools } from "../tools.js";
27
27
  import { forModel } from "../result.js";
28
28
  import { WEB_FETCH_TOOL } from "../web-fetch.js";
29
29
  import { runGate } from "../tool-gate.js";
@@ -44,7 +44,7 @@ import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
44
44
  import { cutStrings } from "../key-refusal.js";
45
45
  import { CLOSE_MS } from "./loop.js";
46
46
  import { PAUSED_WORDS } from "./workflow-loop.js";
47
- import { holdClaimed } from "./redact.js";
47
+ import { holdClaimed, mustHold } from "./redact.js";
48
48
  import { holdStored } from "./store-secrets.js";
49
49
  import { workflowHost } from "./workflow-host.js";
50
50
  import { SUBMIT_TOOL } from "../workflow/host-tools.js";
@@ -137,11 +137,11 @@ export function workflowSpecOf(deps) {
137
137
  }
138
138
  };
139
139
  async function claimSpec(claim, run, proxies) {
140
+ const redact = mustHold(run?.redact, "A workflow run's spec");
140
141
  /** The keys a claim opens, held by the runner's one redactor (run.redact) before a decision can echo one. */
141
142
  const holding = async (opening) => {
142
143
  const opened = await opening;
143
- if (run?.redact)
144
- holdClaimed(run.redact, opened);
144
+ holdClaimed(redact, opened);
145
145
  return opened;
146
146
  };
147
147
  const claimed = await readClaim(deps, claim.runId);
@@ -153,15 +153,15 @@ export function workflowSpecOf(deps) {
153
153
  if (unbound !== undefined)
154
154
  throw new Error(nodeToolUnboundText(unbound));
155
155
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor before the workflow runs.
156
- if (run?.redact && deps.sealKey)
157
- await holdStored(run.redact, deps.store, deps.sealKey, deps.data);
156
+ if (deps.sealKey)
157
+ await holdStored(redact, deps.store, deps.sealKey, deps.data);
158
158
  const tiers = tiersOf(claimed.workflow);
159
159
  // The run's own keys, as the server's runnable check reads them: each by its name from the runner's environment first,
160
160
  // then the store's sealed value (claim-secrets.ts; the environment wins, rule 4), scoped to what the run needs. Its
161
161
  // models, its decisions, its call nodes' effects and its model nodes' tools all run on these, never on another run's
162
162
  // keys or on this process's whole environment.
163
163
  // Held by the runner's one redactor before anything can echo one (holding: run.redact), as the decision keys were.
164
- const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}), redact: run?.redact }, claimed.revision, { plane: claimed.plane }, claim.runId));
164
+ const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}), redact }, claimed.revision, { plane: claimed.plane }, claim.runId));
165
165
  // The run's models resolve the one way the runner resolves any (routeProviderOf over routeOf), unless a test gives its
166
166
  // own: each tier's key from the runner's environment, else the one the claim opened (a key saved in
167
167
  // Settings → Model keys runs the next run with no restart).
@@ -171,8 +171,8 @@ export function workflowSpecOf(deps) {
171
171
  const runKey = await claimModelKey({ store: deps.store, sealKey: deps.sealKey, env: deps.env ?? process.env }, claim.runId);
172
172
  if (keyedAtClaim(runKey))
173
173
  withoutModelKeys(claimedEnv);
174
- if (runKey && run?.redact)
175
- holdRunKey(run.redact, runKey);
174
+ if (runKey)
175
+ holdRunKey(redact, runKey);
176
176
  const providerOf = deps.providerOf ?? routeProviderOf(claimModelEnv(deps.env ?? process.env, [claimedEnv], runKey, claim));
177
177
  // Each tier's provider and cap model, resolved once; the proxies start here (before the Harness opens, since the models
178
178
  // catalog the Harness takes points at them), their hooks deferred to the booking wired at harnessReady.
@@ -265,6 +265,7 @@ export function workflowSpecOf(deps) {
265
265
  const nodeHost = {
266
266
  where: { root: claimed.workRoot, work: claimed.workRoot, ref: { id: claim.runId } },
267
267
  env: callEnv,
268
+ redact,
268
269
  install: (extension) => void installed.push(extension),
269
270
  onConversation: () => { },
270
271
  beforeResume: () => { },
@@ -272,11 +273,15 @@ export function workflowSpecOf(deps) {
272
273
  };
273
274
  const nodeBindings = await bindNodeTools(nodeNames, nodeHost);
274
275
  // Each node tool as the node gets it and the registry holds it: booked on the run's one ledger (bookedNodeTools), in an
275
- // extension of its own; the binding's raw extension (installed through `installed`) is never put in the registry.
276
+ // extension of its own; the binding's raw extension (installed through `installed`) is never put in the registry. Its
277
+ // answer, and a throw's words, pass the run's one redactor (tools.ts answersCutInside) before the node's model or the
278
+ // journal sees them, as an agentic run's tools do (adapter-run-spec.ts answersCut): a page or a search result can
279
+ // echo a key the run holds.
276
280
  const nodeTools = new Map();
277
281
  for (const [name, binding] of nodeBindings) {
278
282
  const booked = bookedNodeTools(binding, () => paidTools, parkAt);
279
- nodeTools.set(name, { tools: booked.tools, extensions: [defineExtension({ name: `node-tool-${name}`, tools: booked.tools })] });
283
+ const tools = run?.redact ? booked.tools.map((tool) => answersCutInside(tool, run.redact)) : booked.tools;
284
+ nodeTools.set(name, { tools, extensions: [defineExtension({ name: `node-tool-${name}`, tools: tools })] });
280
285
  }
281
286
  const nodePolicy = callPolicyOf(deps.store, claim.runId, claimed);
282
287
  const tierModel = (tier) => (providers.get(tier ?? "default") ?? providers.get("default"))?.capModel;
@@ -310,7 +315,7 @@ export function workflowSpecOf(deps) {
310
315
  // would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
311
316
  sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
312
317
  nodeTool: (name) => nodeTools.get(name),
313
- runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: (run?.redact ? cutStrings(line, run.redact) : line) }]) ?? Promise.resolve()),
318
+ runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: cutStrings(line, redact) }]) ?? Promise.resolve()),
314
319
  workRoot: claimed.workRoot,
315
320
  flush: () => deps.store.flush(),
316
321
  // A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
@@ -1049,6 +1054,6 @@ async function readClaim(deps, runId) {
1049
1054
  const input = launch && typeof launch.input === "object" && launch.input !== null ? launch.input : {};
1050
1055
  const capUsd = typeof launch?.max_cost_usd === "number" ? launch.max_cost_usd : undefined;
1051
1056
  const workRoot = typeof launch?.documents === "string" ? launch.documents : "/tmp";
1052
- return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: launch?.plane };
1057
+ return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: deps.plane ?? launch?.plane };
1053
1058
  }
1054
1059
  export { BACKGROUND_CONTEXT };
@@ -172,8 +172,8 @@ export interface StartDeps {
172
172
  admitted?(): Promise<void>;
173
173
  } | undefined>;
174
174
  };
175
- /** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
176
- fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
175
+ /** Where a revision naming these tools and no place runs here, in the folder mode of now (server.ts fallbackPlace). */
176
+ fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Promise<Place>;
177
177
  /** The Archil disk the run's launch record keeps (server.ts launchDiskOf): the one its body's `archil_disk` names, else
178
178
  * its agent's when it has one now; undefined for neither, or in Mode 1. A disk named in Mode 1 is refused. Absent, no
179
179
  * disk is kept. */
@@ -756,7 +756,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
756
756
  const refused = await deps.runnersRefused?.();
757
757
  if (refused !== undefined)
758
758
  throw new ApiError("runner_refused", refused);
759
- const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
759
+ const place = resolvePlace(rbody.place, await deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
760
760
  // A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
761
761
  // revision's computer, else its place's). Read before the run's check, which defers a held run's model refusal.
762
762
  const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
@@ -1,5 +1,4 @@
1
1
  import type { Shown } from "../learning.js";
2
- import { type PromotionDeps } from "../runner/promotion.js";
3
2
  import type { RunLaunch } from "../run-launch.js";
4
3
  import type { Store } from "../store/store.js";
5
4
  import type { SdkInbox } from "./runs.js";
@@ -22,8 +21,7 @@ export type SdkWorkflowCheckEvent = {
22
21
  * the check (sdkCheckTurn: kept until the check holds compile_after rows, the one that makes compile_after deciding on
23
22
  * them all); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the backend
24
23
  * never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims compete on
25
- * the reservation. `refused`: what the purge gate refuses of the records, so the promotions trim keeps the champion its
26
- * readers serve (purged-workflow.ts refusedIn). */
24
+ * the reservation. */
27
25
  export declare function settleSdkCheck(deps: {
28
26
  store: Store;
29
27
  agentId: string;
@@ -31,5 +29,4 @@ export declare function settleSdkCheck(deps: {
31
29
  inbox: SdkInbox;
32
30
  shown: () => Promise<Shown>;
33
31
  log: (line: string) => void;
34
- refused?: PromotionDeps["refused"];
35
32
  }): Promise<import("../learn/promote.js").Recorded | undefined>;