@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,6 +1,6 @@
1
1
  import { type EntryLike, type TimelineEvent } from "../timeline/index.js";
2
+ import type { AgentLearning } from "../learn/rows.js";
2
3
  import { type LearningChange, type LearningCommitResult } from "../learn/commit.js";
3
- import { type LearningFolder } from "../learn/folder.js";
4
4
  import { type CompileAsk, type CompileTrace, type DraftChecked } from "../learn/compile.js";
5
5
  import type { RunPath } from "../learning-cost.js";
6
6
  import { type RunLaunch } from "../run-launch.js";
@@ -8,16 +8,13 @@ import type { SignInReader } from "../run-view.js";
8
8
  import { type Store } from "../store/store.js";
9
9
  import type { EndOfRunTurn } from "./loop-contract.js";
10
10
  import { type DraftCommit } from "./reflect-hook.js";
11
- /** What the step reads: the run's store, the data directory (the server's tool settings a draft's tools are read with),
12
- * the agent's learning folder (where the run's place keeps it), the runner's environment (the host's secrets a draft or
11
+ /** What the step reads: the run's store (its agent's learning among it), the data directory (the server's tool settings
12
+ * a draft's tools are read with), the runner's environment (the host's secrets a draft or
13
13
  * a correction is refused for), and what the run was handed (its claim's keys, its sign-in's pointers through
14
14
  * `signIns`), which it never learns. */
15
15
  export interface LearningEndDeps {
16
16
  readonly store: Store;
17
17
  readonly data: string;
18
- /** Agent `agentId`'s learning folder, where the run's place keeps it: learningWorkspace({ mode: "local", agentId, data })
19
- * in Mode 1, { mode: "archil", agentId, archil } in Mode 2. Opened for each read or write, and ended after it. */
20
- readonly learningFolder: (agentId: string) => LearningFolder;
21
18
  readonly env?: NodeJS.ProcessEnv;
22
19
  /** The agent's sign-ins, opened (sign-ins-store.ts signInReads over the store and the seal key): the pointers the run's
23
20
  * row says it was handed are read back through them and never learned. Absent, a run marked as handed one learns
@@ -66,15 +63,14 @@ export declare function auditRoomOf(store: Pick<Store, "runs">, runId: string, l
66
63
  * kernel's unknownSpend refusal does, never "no room". */
67
64
  export declare function capSpendOf(store: Pick<Store, "runs">, runId: string, entries: readonly EntryLike[]): Promise<number | null>;
68
65
  /**
69
- * A run's merge on the agent's learning folder, written by the runner directly (learn/commit.ts learningCommit, one
70
- * exec): its compiled draft's files and its owner's correction, committed by `change.runId` (its Run-Id trailer). A file
71
- * changed on main since the run's seed (or a revision's `bases` commit) is a conflict, never written over; a correction
72
- * that holds what must never be stored, or would take corrections.md past its cap, is refused (past the cap beside a
73
- * draft, it is left out alone and the draft merges). Any failure is logged by its reason alone. The folder is always
74
- * released.
66
+ * A run's merge on the agent's learning, written by the runner directly (learn/commit.ts learningCommit, one save): its
67
+ * compiled draft's files and its owner's correction, saved by `change.runId`. A file changed since the run's seed (or a
68
+ * revision's `bases` save) is a conflict, never written over; a correction that holds what must never be stored, or
69
+ * would take corrections.md past its cap, is refused (past the cap beside a draft, it is left out alone and the draft
70
+ * merges). Any failure is logged by its reason alone.
75
71
  */
76
72
  export declare function commitDirect(deps: {
77
- readonly folder: () => LearningFolder;
73
+ readonly learning: AgentLearning;
78
74
  readonly log: (line: string) => void;
79
75
  }, change: LearningChange): Promise<LearningCommitResult>;
80
76
  /** What a run's owner said of it, in order, each a line for corrections.md: the grade's words its end closes (a feedback
@@ -133,9 +129,9 @@ export declare const draftFailedDigest: (runId: string) => string;
133
129
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
134
130
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
135
131
  * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
136
- * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
137
- * writes none. */
138
- export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log" | "learningFolder">, input: {
132
+ * reviseAttemptOf). One record per run (its digest is the run's, and the record is the run's: its purge takes it, and
133
+ * one written after that purge writes nothing), written once: a claim that ends the run again writes none. */
134
+ export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log">, input: {
139
135
  runId: string;
140
136
  agentId: string;
141
137
  compile: CompileAsk;
@@ -27,7 +27,7 @@ import { correctionRefused, learningCommit } from "../learn/commit.js";
27
27
  import { CAPS, checkDraft, problemWords, unstorable } from "../learn/index.js";
28
28
  import { repickSiteOf } from "../learn/check.js";
29
29
  import { repickLabelOf, repickRewrite } from "../learn/repick.js";
30
- import { folderAt, holdsCommit, readLearning, readSnapshot, runMergeOf, snapshotAt, textsAt } from "../learn/folder.js";
30
+ import { holdsSave, learningOf, readAt, readLearning, readOf, runMergeOf } from "../learn/rows.js";
31
31
  import { completedRun, compileStoppedOf, lastOwnRuns, sinceReset, compileDue, compilePrompt, compileReference, COMPILE_TRACES, DRAFT_FAILED, draftFailedOf, heldNamesOf, newCompileAttempt } from "../learn/compile.js";
32
32
  import { heldOnGiveBacks, reviseAttemptOf, sdkInputText } from "./promotion.js";
33
33
  import { loopOf, repickOf } from "../learning-setting.js";
@@ -44,7 +44,6 @@ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
44
44
  import { FINAL_STATES } from "../store/store.js";
45
45
  import { shadowRunId } from "../learn/audit.js";
46
46
  import { getMcpServer } from "../mcp-store.js";
47
- import { purgeGate, refusedIn } from "../purged-workflow.js";
48
47
  import { readApprovers } from "../server-approvers.js";
49
48
  import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
50
49
  import { capNowOf, KINDS } from "./journal-kinds.js";
@@ -105,7 +104,7 @@ export function learningEndOfRun(launch, deps) {
105
104
  },
106
105
  // A round whose merge is on main already (a stop after its commit, before its end was saved) is not checked for room
107
106
  // again: its merge gives back what it did.
108
- correctionRefused: ({ runId, agentId, round: at, text, refuse }) => withFolder(deps, agentId, (folder) => correctionRefused(folder.workspace, text, refuse, { runId, round: at })),
107
+ correctionRefused: ({ runId, agentId, round: at, text, refuse }) => correctionRefused(learningOf(deps.store, agentId), text, refuse, { runId, round: at }),
109
108
  // A run with no workflow binding (an SDK run's `noWorkflows`) compiles nothing.
110
109
  ...(start.noWorkflows ? {} : {
111
110
  compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, ...(launch.sdk ? { sdkTask: sdkInputText(launch) } : {}), seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
@@ -133,7 +132,7 @@ export function learningEndOfRun(launch, deps) {
133
132
  checkDraft: ({ runId, agentId, draft, refuse, revised }) => checkDraftOf(deps, { runId, agentId, seed, draft, refuse, ...(revised ? { revised } : {}) }),
134
133
  commit: async ({ runId, agentId, round: at, draft, correction, refuse }) => {
135
134
  const reason = draft ? `Compiled the job as workflow ${draft.name}${correction !== undefined ? ", with its owner's correction" : ""}.` : "Its owner's correction.";
136
- const done = await commitDirect({ folder: () => deps.learningFolder(agentId), log: deps.log ?? (() => undefined) }, {
135
+ const done = await commitDirect({ learning: learningOf(deps.store, agentId), log: deps.log ?? (() => undefined) }, {
137
136
  runId, round: at, reason, seed, ...(mustHold ? { mustHold } : {}), files: draft ? draft.files.map((file) => ({ ...file })) : [],
138
137
  ...(draft?.held?.length ? { held: [...draft.held] } : {}), ...(draft?.bases ? { bases: draft.bases } : {}),
139
138
  ...(correction !== undefined ? { correction, refuseValues: refuse } : {}),
@@ -153,15 +152,14 @@ export function learningEndOfRun(launch, deps) {
153
152
  // The one check at the entry of a run's learning end, before any merge, look-back, compile, draft check or record: a
154
153
  // run whose seed was read at or before a reset of its agent's learning (its watermark, learn/promote.ts resetAtOf; a
155
154
  // start that records no time is read as before it) learns nothing, whole. Its corrections and compile would land on
156
- // what the reset left. Read by time alone: a Mode 2 run's end writes the folder on its disk, which never held the
157
- // seed the server read from its own folder, so a commit missing here says nothing of a reset.
155
+ // what the reset left.
158
156
  const reset = await resetAtOf(deps.store.settings, input.agentId);
159
157
  if (reset !== undefined && !(start.seededAt !== undefined && start.seededAt > reset)) {
160
158
  return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "reset", detail: said.reset } } }] };
161
159
  }
162
- // The second wall, once the agent's learning was reset: a seed this folder holds now is one its merge must still
163
- // find (commit.ts mustHold), so a reset after this check refuses the merge whole in the script.
164
- const mustHold = reset !== undefined && (await withFolder(deps, input.agentId, (folder) => holdsCommit(folder.workspace, start.seed))) ? start.seed : undefined;
160
+ // The second wall, once the agent's learning was reset: a seed its learning holds now is one its merge must still
161
+ // find (commit.ts mustHold), so a reset after this check refuses the merge whole in the save's own transaction.
162
+ const mustHold = reset !== undefined && (await holdsSave(learningOf(deps.store, input.agentId), start.seed)) ? start.seed : undefined;
165
163
  // Which end of the run this is: the round after the newest it kept (a follow-up opened the run again after it), else
166
164
  // its first. A replayed end reads the same round: its rows are written only with the end that closes it.
167
165
  const prior = await deps.store.learning.proposal(input.runId);
@@ -216,35 +214,18 @@ export async function capSpendOf(store, runId, entries) {
216
214
  const beside = await shadowBesideOf(store, runId);
217
215
  return beside === null ? null : spent + beside;
218
216
  }
219
- /** `read` over agent `agentId`'s learning folder, opened for it and always ended after. */
220
- async function withFolder(deps, agentId, read) {
221
- const folder = deps.learningFolder(agentId);
222
- try {
223
- return await read(folder);
224
- }
225
- finally {
226
- await folder.end().catch(() => undefined);
227
- }
228
- }
229
217
  /**
230
- * A run's merge on the agent's learning folder, written by the runner directly (learn/commit.ts learningCommit, one
231
- * exec): its compiled draft's files and its owner's correction, committed by `change.runId` (its Run-Id trailer). A file
232
- * changed on main since the run's seed (or a revision's `bases` commit) is a conflict, never written over; a correction
233
- * that holds what must never be stored, or would take corrections.md past its cap, is refused (past the cap beside a
234
- * draft, it is left out alone and the draft merges). Any failure is logged by its reason alone. The folder is always
235
- * released.
218
+ * A run's merge on the agent's learning, written by the runner directly (learn/commit.ts learningCommit, one save): its
219
+ * compiled draft's files and its owner's correction, saved by `change.runId`. A file changed since the run's seed (or a
220
+ * revision's `bases` save) is a conflict, never written over; a correction that holds what must never be stored, or
221
+ * would take corrections.md past its cap, is refused (past the cap beside a draft, it is left out alone and the draft
222
+ * merges). Any failure is logged by its reason alone.
236
223
  */
237
224
  export async function commitDirect(deps, change) {
238
- const folder = deps.folder();
239
- try {
240
- const done = await learningCommit(folder.workspace, change);
241
- if (!done.ok)
242
- deps.log(`learning: run ${change.runId}: its merge could not be written (${done.reason})`);
243
- return done;
244
- }
245
- finally {
246
- await folder.end();
247
- }
225
+ const done = await learningCommit(deps.learning, change);
226
+ if (!done.ok)
227
+ deps.log(`learning: run ${change.runId}: its merge could not be written (${done.reason})`);
228
+ return done;
248
229
  }
249
230
  /** A merge's result as the hook reads it. */
250
231
  const committedOf = (done) => done.ok ? { ok: true, commit: done.commit, ...(done.refusedCorrection ? { refusedCorrection: done.refusedCorrection } : {}) } : done.reason === "unavailable" ? { ok: false, reason: "unavailable", problems: [] } : { ok: false, reason: done.reason, problems: done.problems };
@@ -347,17 +328,13 @@ export async function checkDraftOf(deps, input) {
347
328
  const readmePath = `${WORKFLOWS_DIR}/${name}/README.md`;
348
329
  const revised = input.revised && input.revised.workflow === name && input.revised.base !== input.seed ? input.revised : undefined;
349
330
  const base = revised?.base ?? input.seed;
350
- const at = await withFolder(deps, input.agentId, async (folder) => {
351
- const now = await readSnapshot(folder.workspace);
352
- const snapshot = now?.main === base ? now : await snapshotAt(folder.workspace, base);
353
- if (!snapshot)
354
- throw new Error(`the learning folder has no commit ${base}`);
355
- return { snapshot, texts: (await textsAt(folder.workspace, base, [jsonPath, readmePath])) ?? {} };
356
- });
357
- if (at.texts[jsonPath] === json && at.texts[readmePath] === readme)
331
+ const at = await readAt(learningOf(deps.store, input.agentId), base);
332
+ if (!at)
333
+ throw new Error(`the agent's learning has no save ${base}`);
334
+ if (at.text(jsonPath) === json && at.text(readmePath) === readme)
358
335
  return { errors: [] };
359
336
  const refused = (problems) => ({ errors: problems.map((problem) => problemWords([problem])), problems });
360
- const held = new Set(at.snapshot.workflows.flatMap((item) => item.files.map(({ path }) => path)));
337
+ const held = new Set((at.view?.workflows ?? []).flatMap((item) => item.files.map(({ path }) => path)));
361
338
  const changeOf = (path, text) => ({ path, status: held.has(path) ? "modified" : "added", mode: "100644", bytes: Buffer.from(text) });
362
339
  // Its example is the run's own input, read as every text it gave is: one that holds what must never be stored refuses
363
340
  // the draft, said at its README, though it is never written there.
@@ -373,7 +350,7 @@ export async function checkDraftOf(deps, input) {
373
350
  // none of the compact state rule), so an SDK agent's drafts are never rewritten.
374
351
  const repick = workflowAdapters === undefined ? repickOf(await learningOfRun(deps.store, input.runId)) : undefined;
375
352
  // A draft whose text on main has a status is a person's call (retired, or waiting for their OK): never changed.
376
- const kept = at.snapshot.workflows.filter((item) => item.status !== "active").map((item) => item.file);
353
+ const kept = (at.view?.workflows ?? []).filter((item) => item.status !== "active").map((item) => item.file);
377
354
  const check = (text, dryRuns) => checkDraft({
378
355
  changes: [changeOf(jsonPath, text), changeOf(readmePath, readme)], refuseValues: input.refuse, tools, dsl,
379
356
  ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ...(decisions ? { decisions } : {}),
@@ -405,7 +382,7 @@ export async function checkDraftOf(deps, input) {
405
382
  else
406
383
  deps.log?.(`learning.repick: workflow ${name} is kept as compiled; its re-pick over the run's pages failed the checks (${[...new Set(again.map((problem) => problem.rule))].join(", ")})`);
407
384
  }
408
- if (text !== json && at.texts[jsonPath] === text && at.texts[readmePath] === readme)
385
+ if (text !== json && at.text(jsonPath) === text && at.text(readmePath) === readme)
409
386
  return { errors: [] };
410
387
  const files = [{ path: jsonPath, text }, { path: readmePath, text: readme }];
411
388
  return {
@@ -477,11 +454,11 @@ export const draftFailedDigest = (runId) => createHash("sha256").update(`draft-f
477
454
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
478
455
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
479
456
  * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
480
- * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
481
- * writes none. */
457
+ * reviseAttemptOf). One record per run (its digest is the run's, and the record is the run's: its purge takes it, and
458
+ * one written after that purge writes nothing), written once: a claim that ends the run again writes none. */
482
459
  export async function recordDraftFailed(deps, input) {
483
460
  try {
484
- const records = await promotionsOf(deps.store.settings, input.agentId);
461
+ const records = await promotionsOf(deps.store.learning, input.agentId);
485
462
  const attempt = input.compile.mode === "revise" ? reviseAttemptOf(records, input.compile.held) : newCompileAttempt(records);
486
463
  const { compile_after, agree_min, alone_min } = await loopOfRun(deps.store, input.runId);
487
464
  const workflow = input.compile.mode === "revise" ? input.compile.workflow : input.workflow;
@@ -489,7 +466,7 @@ export async function recordDraftFailed(deps, input) {
489
466
  const failed = input.errors.join("; ").slice(0, CHECK_TEXT_MAX) || "no draft passed";
490
467
  const reason = `${DRAFT_FAILED}: ${failed}. ${attempt === 2 ? "It was the recompile, so it stops: nothing compiles again until its owner acts" : "It is not promoted; the next due run compiles it once more"}`;
491
468
  const check = { compile_after, agree_min, alone_min, attempt, n: 0, agreed: 0, alone: 0, agent_agreed: 0, of: [], ...(attempt === 2 ? { stopped: true } : {}) };
492
- const kept = await recordPromotion(deps.store.settings, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined, refusedIn(() => deps.learningFolder(input.agentId), deps.store, deps.log));
469
+ const kept = await recordPromotion(deps.store.learning, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined, { anyDigest: true, runId: input.runId });
493
470
  if (kept.won)
494
471
  deps.log?.(`learning: run ${input.runId}: the compile of ${workflow} failed its checks (attempt ${attempt}${attempt === 2 ? ", stopped" : ""})`);
495
472
  }
@@ -543,10 +520,8 @@ export async function compileAskOf(deps, input) {
543
520
  const { agentId } = input;
544
521
  // A revision is asked only of a workflow its promotion holds, once per hold. The workflows whose newest revision other
545
522
  // than their champion (learn/promote.ts championOf: it serves while that one is held) is held: the run's own may be one.
546
- // A record the purge gate refuses is skipped as the champion's readers skip it (purged-workflow.ts refusedOf); a gate
547
- // that can't be asked skips none, and the text read below is gated again.
548
- const records = await promotionsOf(deps.store.settings, agentId).catch(() => []);
549
- const heldNames = heldNamesOf(records, records.length ? await refusedIn(() => deps.learningFolder(agentId), deps.store, deps.log)(records).catch(() => undefined) : undefined);
523
+ const records = await promotionsOf(deps.store.learning, agentId).catch(() => []);
524
+ const heldNames = heldNamesOf(records);
550
525
  // The loop's numbers on the agent's definition (the revision this run runs): the first compile waits for compile_after
551
526
  // completed agent runs, the ending one counted.
552
527
  const { compile_after: compileAfter } = await loopOfRun(deps.store, input.runId);
@@ -576,17 +551,15 @@ export async function compileAskOf(deps, input) {
576
551
  const shown = secretsShown(input.refuse);
577
552
  const holds = (value) => holdsSecret(typeof value === "string" ? value : (JSON.stringify(value) ?? ""), shown);
578
553
  const leftOut = { workflows: new Set(), traces: 0, input: false };
579
- const folder = deps.learningFolder(input.agentId);
580
- // `main`: the commit the snapshot read is main's at, which `current` was read from.
554
+ const learning = learningOf(deps.store, input.agentId);
555
+ // `main`: the save the read is at, which `current` was read from.
581
556
  let read;
582
557
  try {
583
- // A workflow a purged run wrote is neither counted nor told (purgeGate), on main or at a replayed round's parent.
584
- const readFrom = async ({ snapshot, body }) => {
585
- const purged = (await purgeGate(snapshot, deps.store)).workflows;
586
- const workflows = (snapshot?.workflows ?? []).filter(({ name, status }) => (status === "active" || status === "pending") && !purged.has(name));
558
+ const readFrom = async ({ view, text: textAt }) => {
559
+ const workflows = (view?.workflows ?? []).filter(({ status }) => status === "active" || status === "pending");
587
560
  const textOf = async (name) => {
588
561
  const file = workflows.find((one) => one.name === name)?.files.find(({ path }) => path.endsWith("/workflow.json"));
589
- const text = file ? await body(file.path, file.oid) : undefined;
562
+ const text = file ? textAt(file.path) : undefined;
590
563
  if (text === undefined || !(holds(name) || holds(text)))
591
564
  return text;
592
565
  leftOut.workflows.add(shown.name(name));
@@ -610,25 +583,18 @@ export async function compileAskOf(deps, input) {
610
583
  if (record?.decided === "hold" && !record.check?.stopped && !record.audit?.stopped)
611
584
  [held, current] = [record, fitting[0].workflow];
612
585
  }
613
- return { workflows: workflows.length, ...(current !== undefined ? { current } : {}), ...(held ? { held } : {}), ...(snapshot?.main ? { main: snapshot.main } : {}) };
586
+ return { workflows: workflows.length, ...(current !== undefined ? { current } : {}), ...(held ? { held } : {}), ...(view?.main ? { main: view.main } : {}) };
614
587
  };
615
- // A round that merged already (a crash between its commit and its end): main holds its own merge, so the turn is
616
- // decided again on main as that merge read it (its parent), and the replayed answer lands on the merge it made
617
- // (learn/commit.ts learningCommit: a round merges once), never a drop that leaves its commit unrecorded. A stop
618
- // between the merge and its diff file is read back from the run's ref (runMergeOf).
619
- const own = await runMergeOf(folder.workspace, input.runId, input.round);
620
- const before = own ? await folderAt(folder.workspace, own.parent) : undefined;
621
- read = before
622
- ? await readFrom({ snapshot: before.snapshot, body: async (path, oid) => { const blob = before.blobs.get(oid); if (!blob)
623
- throw new Error(`${path} is not in ${own.parent}`); return blob.toString("utf8"); } })
624
- : await readLearning(folder.workspace, readFrom);
588
+ // A round that merged already (a crash between its save and its end): the newest save holds its own merge, so the
589
+ // turn is decided again as that merge read it (the save before it), and the replayed answer lands on the merge it
590
+ // made (learn/commit.ts learningCommit: a round merges once), never a drop that leaves its save unrecorded.
591
+ const own = await runMergeOf(learning, input.runId, input.round);
592
+ const before = own ? (own.parent ? await readAt(learning, own.parent) : readOf(undefined)) : undefined;
593
+ read = before ? await readFrom(before) : await readLearning(learning, readFrom);
625
594
  }
626
595
  catch {
627
596
  return undefined;
628
597
  }
629
- finally {
630
- await folder.end().catch(() => undefined);
631
- }
632
598
  // What it left out, by name and count: said once the facts are gathered, or now when it asks nothing.
633
599
  const sayLeftOut = () => {
634
600
  const parts = [...[...leftOut.workflows].map((name) => `workflow \`${name}\``), ...(leftOut.traces ? [`${leftOut.traces} earlier run${leftOut.traces === 1 ? "" : "s"}`] : []), ...(leftOut.input ? ["the run's input"] : [])];
@@ -1,15 +1,14 @@
1
1
  import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
2
- import type { LearningFolder } from "../learn/folder.js";
3
- import type { Store } from "../store/index.js";
4
- /** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
5
- * the read and ended after it), the store whose runs say which are purged (a purged run's workflow is no seed's:
6
- * learning.ts seedAt; null in a run's own process, which reads no other run: its lay only tells its runner whether it
7
- * laid any, and the runner reads the seed again with its store, workflowsAt), the server's secrets as cuts (`shown`),
8
- * its log, and `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
2
+ import { type LearningRows } from "../learn/rows.js";
3
+ /** What a claim reads its seed with: the save, the store's learning rows (a run's own process reads them through its
4
+ * runner, run-child-host.ts storeCall), the agent, the server's secrets as cuts (`shown`), its log, and
5
+ * `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
9
6
  export interface LearningSeedLay {
10
7
  readonly seed: string | null;
11
- readonly folder: () => LearningFolder;
12
- readonly store: Pick<Store, "runs"> | null;
8
+ readonly store: {
9
+ readonly learning: LearningRows;
10
+ };
11
+ readonly agentId: string;
13
12
  readonly shown: () => Promise<Shown>;
14
13
  readonly log: (line: string) => void;
15
14
  readonly workflows?: false;
@@ -28,10 +27,8 @@ export declare const laidOf: (laid: LaidSeed | undefined) => {
28
27
  * secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
29
28
  * throws: a learning fault never stops a run. */
30
29
  export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed | undefined>;
31
- /** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
32
- * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
33
- * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
34
- * commit is gone. */
35
- export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown"> & {
36
- readonly store: Pick<Store, "runs">;
37
- }, commit: string | null): Promise<LearnedWorkflow[]>;
30
+ /** The learned workflows the agent's learning held active at save `save`, read now, as a claim's read hands them to the
31
+ * learned_workflow tool (chooseWorkflows): what a champion serves from while a newer revision of it is the newest
32
+ * (runner/promotion.ts), and what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the
33
+ * store cannot answer or the save is gone. */
34
+ export declare function workflowsAt(read: Pick<LearningSeedLay, "store" | "agentId" | "shown">, save: string | null): Promise<LearnedWorkflow[]>;
@@ -1,8 +1,10 @@
1
- // A claim's read of a run's learning seed: the learned workflows its learning folder held active at the commit the run
2
- // started from, which the run's learned_workflow tool runs and workflow-first serves (learning.ts chooseWorkflows: within
3
- // the tool's budget, none holding a host secret). Nothing is laid in the run's work: its corrections reach it in its
4
- // instructions (learning.ts laidLearned, from the launch's learning start).
1
+ // A claim's read of a run's learning seed: the learned workflows its agent's learning held active at the save the run
2
+ // started from, read now (a purged run's text gone from it), which the run's learned_workflow tool runs and
3
+ // workflow-first serves (learning.ts chooseWorkflows: within the tool's budget, none holding a host secret). Nothing is
4
+ // laid in the run's work: its corrections reach it in its instructions (learning.ts laidLearned, from the launch's
5
+ // learning start).
5
6
  import { chooseWorkflows, seedAt } from "../learning.js";
7
+ import { learningOf } from "../learn/rows.js";
6
8
  /** What a claim handed a run of its seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
7
9
  * workflow it handed the tool; none when nothing was read. */
8
10
  export const laidOf = (laid) => ({ workflows: (laid?.workflows ?? []).map(({ name }) => name) });
@@ -12,17 +14,13 @@ const message = (error) => (error instanceof Error ? error.message : String(erro
12
14
  * throws: a learning fault never stops a run. */
13
15
  export async function layLearningSeed(lay) {
14
16
  let seed;
15
- const folder = lay.folder();
16
17
  try {
17
- seed = await seedAt(folder.workspace, lay.seed, lay.store);
18
+ seed = await seedAt(learningOf(lay.store, lay.agentId), lay.seed);
18
19
  }
19
20
  catch (error) {
20
21
  lay.log(`the run starts with no learned workflow: ${message(error)}`);
21
22
  return undefined;
22
23
  }
23
- finally {
24
- await folder.end().catch(() => undefined);
25
- }
26
24
  if (lay.workflows === false)
27
25
  return { seed, workflows: [] };
28
26
  try {
@@ -36,18 +34,10 @@ export async function layLearningSeed(lay) {
36
34
  return { seed, workflows: [] };
37
35
  }
38
36
  }
39
- /** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
40
- * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
41
- * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
42
- * commit is gone. */
43
- export async function workflowsAt(read, commit) {
44
- const folder = read.folder();
45
- let seed;
46
- try {
47
- seed = await seedAt(folder.workspace, commit, read.store);
48
- }
49
- finally {
50
- await folder.end().catch(() => undefined);
51
- }
52
- return chooseWorkflows(seed, await read.shown()).flows;
37
+ /** The learned workflows the agent's learning held active at save `save`, read now, as a claim's read hands them to the
38
+ * learned_workflow tool (chooseWorkflows): what a champion serves from while a newer revision of it is the newest
39
+ * (runner/promotion.ts), and what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the
40
+ * store cannot answer or the save is gone. */
41
+ export async function workflowsAt(read, save) {
42
+ return chooseWorkflows(await seedAt(learningOf(read.store, read.agentId), save), await read.shown()).flows;
53
43
  }
@@ -65,10 +65,9 @@ export function withLiveTicker(store, createLoop, options = {}) {
65
65
  };
66
66
  deps.signal.addEventListener("abort", onAbort, { once: true });
67
67
  // The run's one redactor: a running tool's args and output and a partial answer can quote a secret the runner holds
68
- // (a key its claim opened), and the live view is read by people and consoles. A loop given none (never one the runner
69
- // makes) has no live view: its held state is never written uncut. Nor has a loop whose redactor does not know its
70
- // values (a bare function): a value still streaming, a number or an object's names cannot be cut by text alone.
71
- const values = deps.redact?.heldValues;
68
+ // (a key its claim opened), and the live view is read by people and consoles. A loop whose redactor does not know its
69
+ // values has no live view: a value still streaming, a number or an object's names cannot be cut by text alone.
70
+ const values = deps.redact.heldValues;
72
71
  const loop = createLoop({
73
72
  ...deps,
74
73
  live: (read) => {
@@ -602,7 +602,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
602
602
  try {
603
603
  holds = runnerHolds(args, env);
604
604
  // The Archil settings an operator sets, read by every run's claim here as the server reads them (archil-settings.ts):
605
- // one of the region and S3 URL without the other, or a value the server would refuse, stops this start as it stops
605
+ // one set without the region, or a value the server would refuse, stops this start as it stops
606
606
  // the server's.
607
607
  archilSettingsFromEnv(env);
608
608
  }
@@ -22,8 +22,9 @@
22
22
  //
23
23
  // A per_run server keeps no credential: the run's caller hands one with the run or a message (mcp_auth), sealed in the
24
24
  // run's launch row for the run's life (store/seal.ts sealRunMcpAuth) and erased by the write that ends it. Each fresh()
25
- // opens it again, so a message's new credential reaches the run's next model request; a run handed none gets its calls
26
- // refused unsent (UNUSABLE.perRunMissing).
25
+ // opens it again, so a message's new credential reaches the run's next model request; a run handed none has the server's
26
+ // tools left out of its own (mcp-run.ts mcpForClaim), and a call that still names it is refused unsent
27
+ // (UNUSABLE.perRunMissing).
27
28
  //
28
29
  // A per-run Composio server (composio-made.ts composioPerRun) is bound by each run's caller ({composio_user_id,
29
30
  // connected_account_id?} in mcp_auth, sealed in its launch): its entry carries them as `query` (mcp-gateway.ts). Each
@@ -73,6 +73,10 @@ export interface McpForClaimOptions {
73
73
  };
74
74
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
75
75
  readonly hold?: (values: string[]) => void;
76
+ /** The run's revision's own tool settings (body.toolSettings), where a tool's file setting is read (filed-tool.ts
77
+ * filedBy): each answer of such a tool is filed whole in the run's files and the tool's result is its summary. A run's
78
+ * own process passes none: its runner reads them from the revision it reads itself (run-child-host.ts). */
79
+ readonly toolSettings?: unknown;
76
80
  }
77
81
  /** What a spec builder gives a claim's MCP for its metered jobs (`capped` and `media`), the same for every builder:
78
82
  * whether its launch has a cap, and where a job's input media are read from: the run's eval web fake (`web`, as its
@@ -88,6 +92,12 @@ export interface ClaimMcp {
88
92
  /** One host tool per pinned tool, under its wire name, on every harness. Each reaches the gateway only as the loop
89
93
  * wraps it, behind the run's one gate (the gate before the intent); nothing else does. */
90
94
  readonly tools: readonly HostTool[];
95
+ /** The pinned servers whose credential comes from each run (a per_run server, a per-run Composio server) that this run
96
+ * was handed none for (UNUSABLE.perRunMissing) when the claim opened them: every call of their tools is refused
97
+ * unsent. mcpWhereHeld leaves their tools out where the harness takes its tools again at each claim. */
98
+ readonly unconnected: readonly string[];
99
+ /** The servers whose tools mcpWhereHeld left out of `tools` (of `unconnected`); none where it left none out. */
100
+ readonly leftOut?: readonly string[];
91
101
  /** A pinned tool's catalog name (`mcp:<server>/<tool>`) by its wire name; undefined for any other tool. */
92
102
  catalogOf(tool: string): string | undefined;
93
103
  /** The top-level arguments a pinned tool's listing declares (its inputSchema's `properties`, as the run's pin holds it
@@ -101,9 +111,10 @@ export interface ClaimMcp {
101
111
  /** A pinned tool's effect (`mcp:<server>/<tool>`), by its annotations as the pin holds them (tool-gate.ts toolEffect):
102
112
  * what the gate's "allow reads" and a destructive call's card read; never a later listing. Undefined for any other. */
103
113
  effectOf(name: string): ToolEffect | undefined;
104
- /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed), then the claim
105
- * confirmed: before a resumed loop's next model request. */
106
- fresh(): Promise<void>;
114
+ /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed, a per_run one a
115
+ * message handed), then the claim confirmed: before a resumed loop's next model request. Answers the servers still
116
+ * handed no credential, as `unconnected` reads at the claim. */
117
+ fresh(): Promise<readonly string[]>;
107
118
  /** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
108
119
  release(): void;
109
120
  }
@@ -120,7 +131,15 @@ export declare function heldMcpOf(mcp: ClaimMcp, cut: (text: string) => string):
120
131
  /** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
121
132
  export declare function claimMcpOfHeld(held: HeldMcp): ClaimMcp;
122
133
  /** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
123
- * record of each call appended to the run's root through this process's own harness. */
134
+ * record of each call appended to the run's root through this process's own harness.
135
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
136
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
137
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
138
+ * next claim (the loop holds one that comes while a turn is going for the run's next turn, adapter-loop steer). Not for a harness whose tools are fixed at its thread's start (`toolsFixedAtStart`, AdapterFacts): left
139
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
140
+ * comes. */
124
141
  export declare function mcpWhereHeld(options: Omit<McpForClaimOptions, "sealKey"> & {
125
142
  readonly sealKey: Buffer | undefined;
143
+ readonly say?: (words: string) => void;
144
+ readonly toolsFixedAtStart?: boolean;
126
145
  }): Promise<ClaimMcp | undefined>;
@@ -8,11 +8,13 @@ import { fakeSaveOptions } from "../web-fake.js";
8
8
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
9
9
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
10
10
  import { mcpNameOf } from "../tool-names.js";
11
+ import { UNUSABLE, unconnectedWords } from "../mcp-probe.js";
11
12
  import { mcpToolName, permissionKeys, pinnedEffect } from "../tool-gate.js";
12
13
  import { mcpClaim } from "./mcp-claim.js";
13
14
  import { registryListing } from "../mcp-pin-first.js";
14
15
  import { heldOrThrow } from "./held.js";
15
16
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
17
+ import { filedBy } from "../filed-tool.js";
16
18
  /** What a spec builder gives a claim's MCP for its metered jobs (`capped` and `media`), the same for every builder:
17
19
  * whether its launch has a cap, and where a job's input media are read from: the run's eval web fake (`web`, as its
18
20
  * builder read the run's fakes, once), else the builder's `env`, in web_save's slots. */
@@ -87,11 +89,16 @@ export async function mcpForClaim(options) {
87
89
  ...(options.fetch ? { fetch: options.fetch } : {}),
88
90
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
89
91
  capped: options.capped !== false,
92
+ ...(options.toolSettings !== undefined ? { filed: filedBy(options.toolSettings) } : {}),
90
93
  ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
91
94
  });
92
95
  const catalog = new Map();
93
96
  const declared = new Map();
94
97
  const tools = [];
98
+ // A server the run was handed no credential for: the gateway refuses every call of it unsent, in those words, until a
99
+ // message hands one. Its tools are still listed here; mcpWhereHeld leaves them out where that is safe.
100
+ const unconnectedNow = () => Object.keys(pin).filter((server) => step.credentials[server]?.unopened === UNUSABLE.perRunMissing);
101
+ const unconnected = unconnectedNow();
95
102
  for (const [server, pinned] of Object.entries(pin)) {
96
103
  for (const tool of pinned.tools) {
97
104
  const name = mcpToolName(server, tool.name);
@@ -115,6 +122,7 @@ export async function mcpForClaim(options) {
115
122
  }
116
123
  return {
117
124
  tools,
125
+ unconnected,
118
126
  catalogOf: (tool) => catalog.get(tool),
119
127
  argumentsOf: (name) => declared.get(name),
120
128
  priceOf(name) {
@@ -128,7 +136,10 @@ export async function mcpForClaim(options) {
128
136
  return meterNamed(pinned.url, pinned.meter) && falBills(parsed.tool) ? "priced by usage" : "not metered";
129
137
  },
130
138
  effectOf: (name) => pinnedEffect(pin, name),
131
- fresh: () => step.fresh(),
139
+ fresh: async () => {
140
+ await step.fresh();
141
+ return unconnectedNow();
142
+ },
132
143
  release: () => held.abort(),
133
144
  };
134
145
  }
@@ -160,6 +171,7 @@ export function heldMcpOf(mcp, cut) {
160
171
  },
161
172
  };
162
173
  }),
174
+ unconnected: [...mcp.unconnected],
163
175
  fresh: () => mcp.fresh(),
164
176
  release: async () => mcp.release(),
165
177
  };
@@ -176,6 +188,7 @@ export function claimMcpOfHeld(held) {
176
188
  replay: "never",
177
189
  call: (args, context) => tool.call(args, { ...(context.signal ? { signal: context.signal } : {}), ...(context.callId ? { callId: context.callId } : {}) }),
178
190
  })),
191
+ unconnected: held.unconnected ?? [],
179
192
  catalogOf: (tool) => byWire.get(tool)?.catalog,
180
193
  argumentsOf: (name) => {
181
194
  const declared = byCatalog.get(name)?.arguments;
@@ -188,8 +201,24 @@ export function claimMcpOfHeld(held) {
188
201
  };
189
202
  }
190
203
  /** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
191
- * record of each call appended to the run's root through this process's own harness. */
204
+ * record of each call appended to the run's root through this process's own harness.
205
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
206
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
207
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
208
+ * next claim (the loop holds one that comes while a turn is going for the run's next turn, adapter-loop steer). Not for a harness whose tools are fixed at its thread's start (`toolsFixedAtStart`, AdapterFacts): left
209
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
210
+ * comes. */
192
211
  export async function mcpWhereHeld(options) {
212
+ const { say, toolsFixedAtStart, ...rest } = options;
213
+ const mcp = await mcpHeld(rest);
214
+ if (!mcp || mcp.unconnected.length === 0 || toolsFixedAtStart)
215
+ return mcp;
216
+ const out = new Set(mcp.unconnected);
217
+ for (const server of mcp.unconnected)
218
+ say?.(unconnectedWords(server));
219
+ return { ...mcp, leftOut: mcp.unconnected, tools: mcp.tools.filter((tool) => !out.has(mcpNameOf(mcp.catalogOf(tool.name) ?? "")?.server ?? "")) };
220
+ }
221
+ async function mcpHeld(options) {
193
222
  if (options.sealKey)
194
223
  return mcpForClaim({ ...options, sealKey: options.sealKey });
195
224
  const at = heldOrThrow("a run's MCP");
@@ -81,6 +81,10 @@ export declare function bookedDecisionsOf(entries: readonly EntryLike[], ids: Re
81
81
  * call (runner/workflow-calls.ts). $0 for none; null once one has no known cost, or one a crash cut is counted at its
82
82
  * hold (`atMost`: the most it can cost, never what it cost). */
83
83
  export declare function callCostOf(entries: readonly EntryLike[], callId: string, from: number, to: number): number | null;
84
+ /** The turns of the requests call `callId` booked, by callCostOf's rule: each request whose record names it or one nested
85
+ * in it, and each of host work admitted in its window (`from` < at <= `to`; -1 for both: no window, those named alone).
86
+ * None: nothing was booked under the call. */
87
+ export declare function callTurnsOf(entries: readonly EntryLike[], callId: string, from: number, to: number): Set<unknown>;
84
88
  /** A cost of charges as a usage row or a run's cost block says it (costsofar/1, cutathold/1), by the kernel's one rule
85
89
  * (costOfParts) over `parts`, its float noise rounded off (floatNoiseOff): `usd` their sum, `upper_bound` when it counts
86
90
  * a cut request at its hold, with `so_far_usd` the charges' own figures alone and `unpriced` how many it counts at their