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

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 (194) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +188 -106
  3. package/dist/agent-delete.d.ts +6 -9
  4. package/dist/agent-delete.js +5 -3
  5. package/dist/agent-package.js +11 -1
  6. package/dist/api-only.d.ts +2 -2
  7. package/dist/api-only.js +3 -3
  8. package/dist/archil-routes.d.ts +4 -1
  9. package/dist/archil-routes.js +15 -12
  10. package/dist/archil-settings.d.ts +18 -8
  11. package/dist/archil-settings.js +35 -17
  12. package/dist/chatgpt-plan.d.ts +4 -2
  13. package/dist/chatgpt-plan.js +13 -3
  14. package/dist/claude-login-token.d.ts +5 -0
  15. package/dist/claude-login-token.js +8 -0
  16. package/dist/claude-login.d.ts +49 -3
  17. package/dist/claude-login.js +140 -10
  18. package/dist/cli-learning/connections.js +1 -1
  19. package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
  20. package/dist/console/assets/index-DZi-muIj.js +629 -0
  21. package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
  22. package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
  23. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/decisions.d.ts +1 -1
  27. package/dist/decisions.js +2 -2
  28. package/dist/factory-activity.d.ts +68 -0
  29. package/dist/factory-activity.js +153 -0
  30. package/dist/factory-runs.d.ts +11 -0
  31. package/dist/factory-runs.js +52 -0
  32. package/dist/filed-tool.d.ts +32 -0
  33. package/dist/filed-tool.js +122 -0
  34. package/dist/harness-keys.d.ts +1 -2
  35. package/dist/harness-keys.js +1 -2
  36. package/dist/harness-table.d.ts +4 -0
  37. package/dist/harness-table.js +4 -0
  38. package/dist/harness.js +6 -2
  39. package/dist/import-worker.js +2 -2
  40. package/dist/import.d.ts +9 -0
  41. package/dist/import.js +11 -1
  42. package/dist/key-refusal.d.ts +5 -0
  43. package/dist/key-refusal.js +25 -15
  44. package/dist/learn/audit.d.ts +20 -22
  45. package/dist/learn/audit.js +72 -55
  46. package/dist/learn/check.js +1 -1
  47. package/dist/learn/commit.d.ts +35 -43
  48. package/dist/learn/commit.js +62 -270
  49. package/dist/learn/compile.d.ts +4 -4
  50. package/dist/learn/compile.js +6 -7
  51. package/dist/learn/corrections.js +1 -1
  52. package/dist/learn/delete.d.ts +5 -12
  53. package/dist/learn/delete.js +17 -30
  54. package/dist/learn/forget-run.d.ts +16 -0
  55. package/dist/learn/forget-run.js +53 -0
  56. package/dist/learn/index.js +1 -1
  57. package/dist/learn/learning-of.d.ts +0 -4
  58. package/dist/learn/learning-of.js +0 -5
  59. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  60. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  61. package/dist/learn/legacy/place.d.ts +16 -0
  62. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  63. package/dist/learn/legacy/scrub.d.ts +28 -0
  64. package/dist/learn/legacy/scrub.js +258 -0
  65. package/dist/learn/promote.d.ts +40 -66
  66. package/dist/learn/promote.js +69 -207
  67. package/dist/learn/reset-ledger.d.ts +18 -0
  68. package/dist/learn/reset-ledger.js +14 -0
  69. package/dist/learn/rows.d.ts +186 -0
  70. package/dist/learn/rows.js +376 -0
  71. package/dist/learn/workflow-draft.d.ts +4 -1
  72. package/dist/learn/workflow-draft.js +12 -2
  73. package/dist/learning-reset.d.ts +1 -1
  74. package/dist/learning-reset.js +9 -11
  75. package/dist/learning-routes.d.ts +60 -81
  76. package/dist/learning-routes.js +187 -360
  77. package/dist/learning-words.d.ts +2 -0
  78. package/dist/learning-words.js +2 -0
  79. package/dist/learning.d.ts +18 -24
  80. package/dist/learning.js +35 -66
  81. package/dist/mcp-gateway.d.ts +6 -0
  82. package/dist/mcp-gateway.js +44 -8
  83. package/dist/mcp-resources.d.ts +1 -1
  84. package/dist/native/discovery.d.ts +6 -0
  85. package/dist/native/discovery.js +14 -1
  86. package/dist/native/remote.d.ts +5 -0
  87. package/dist/native/remote.js +16 -0
  88. package/dist/native/runtime.js +3 -2
  89. package/dist/observation/observer.d.ts +6 -6
  90. package/dist/openapi.js +89 -29
  91. package/dist/place-offers.d.ts +3 -0
  92. package/dist/place-offers.js +3 -0
  93. package/dist/place.d.ts +33 -11
  94. package/dist/place.js +61 -26
  95. package/dist/purged-workflow.d.ts +0 -33
  96. package/dist/purged-workflow.js +3 -71
  97. package/dist/redact/match.d.ts +19 -4
  98. package/dist/redact/match.js +123 -30
  99. package/dist/run-launch.d.ts +3 -3
  100. package/dist/run-learning-served.d.ts +3 -3
  101. package/dist/run-learning-served.js +1 -1
  102. package/dist/run-listing.d.ts +1 -1
  103. package/dist/run-timeline-served.d.ts +1 -1
  104. package/dist/run-timeline-served.js +6 -5
  105. package/dist/runnable.js +25 -8
  106. package/dist/runner/adapter-run-spec.js +11 -20
  107. package/dist/runner/audit.d.ts +2 -4
  108. package/dist/runner/audit.js +28 -51
  109. package/dist/runner/cli-run-spec.js +8 -14
  110. package/dist/runner/compare-end.d.ts +0 -2
  111. package/dist/runner/compare-end.js +6 -2
  112. package/dist/runner/disk-free.d.ts +15 -4
  113. package/dist/runner/disk-free.js +25 -7
  114. package/dist/runner/feedback-round.d.ts +1 -1
  115. package/dist/runner/feedback-round.js +2 -2
  116. package/dist/runner/harness-loops.js +2 -3
  117. package/dist/runner/held.d.ts +0 -10
  118. package/dist/runner/held.js +0 -25
  119. package/dist/runner/journal-kinds.d.ts +4 -1
  120. package/dist/runner/journal-kinds.js +1 -1
  121. package/dist/runner/learned-first.d.ts +0 -2
  122. package/dist/runner/learned-first.js +3 -3
  123. package/dist/runner/learning-end.d.ts +12 -16
  124. package/dist/runner/learning-end.js +41 -75
  125. package/dist/runner/learning-seed.d.ts +13 -16
  126. package/dist/runner/learning-seed.js +13 -23
  127. package/dist/runner/main.js +1 -1
  128. package/dist/runner/mcp-run.d.ts +4 -0
  129. package/dist/runner/mcp-run.js +2 -0
  130. package/dist/runner/native-loop.js +2 -3
  131. package/dist/runner/promotion.d.ts +19 -28
  132. package/dist/runner/promotion.js +50 -69
  133. package/dist/runner/reflect-hook.d.ts +2 -2
  134. package/dist/runner/reflect-hook.js +4 -1
  135. package/dist/runner/run-child-host.d.ts +1 -9
  136. package/dist/runner/run-child-host.js +11 -67
  137. package/dist/runner/runner.d.ts +1 -1
  138. package/dist/runner/sdk-loop.js +2 -4
  139. package/dist/sdk/check.d.ts +1 -4
  140. package/dist/sdk/check.js +2 -3
  141. package/dist/sdk/runs.d.ts +20 -7
  142. package/dist/sdk/runs.js +105 -68
  143. package/dist/secrets.d.ts +4 -0
  144. package/dist/secrets.js +44 -10
  145. package/dist/server-fs.d.ts +1 -1
  146. package/dist/server-fs.js +1 -1
  147. package/dist/server-keys.d.ts +6 -0
  148. package/dist/server-keys.js +12 -0
  149. package/dist/server.d.ts +15 -15
  150. package/dist/server.js +214 -164
  151. package/dist/source-sync/auxiliary.js +2 -2
  152. package/dist/store/index.d.ts +1 -1
  153. package/dist/store/index.js +1 -1
  154. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  155. package/dist/store/schema.d.ts +28 -2
  156. package/dist/store/schema.js +81 -5
  157. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  158. package/dist/store/sqlite/learning-rows.js +559 -0
  159. package/dist/store/sqlite/store.d.ts +7 -1
  160. package/dist/store/sqlite/store.js +84 -18
  161. package/dist/store/store.d.ts +219 -6
  162. package/dist/store/store.js +13 -0
  163. package/dist/store-reads/journal.d.ts +33 -3
  164. package/dist/store-reads/journal.js +99 -4
  165. package/dist/store-reads/learning.d.ts +18 -22
  166. package/dist/store-reads/learning.js +35 -26
  167. package/dist/store-reads/loop.js +1 -1
  168. package/dist/store-view.d.ts +24 -2
  169. package/dist/store-view.js +40 -11
  170. package/dist/templates.d.ts +10 -2
  171. package/dist/templates.js +31 -4
  172. package/dist/tool-plane.d.ts +4 -2
  173. package/dist/tool-plane.js +9 -2
  174. package/dist/web-holds.d.ts +2 -0
  175. package/dist/web-holds.js +5 -2
  176. package/dist/web-run.js +2 -1
  177. package/dist/workspace/archil-exec.js +1 -1
  178. package/dist/workspace/archil.d.ts +1 -1
  179. package/dist/workspace/archil.js +1 -1
  180. package/dist/workspace/computer-deps.js +5 -3
  181. package/dist/workspace/computer-providers.d.ts +11 -1
  182. package/dist/workspace/computer-providers.js +29 -2
  183. package/dist/workspace/index.d.ts +1 -2
  184. package/dist/workspace/index.js +1 -2
  185. package/dist/workspace/paths.d.ts +0 -4
  186. package/dist/workspace/paths.js +0 -6
  187. package/dist/workspace/workspace.d.ts +1 -1
  188. package/dist/workspace/workspace.js +1 -1
  189. package/package.json +13 -13
  190. package/templates/TOOLS.md +46 -0
  191. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  192. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  193. package/dist/workspace/learning-workspace.d.ts +0 -24
  194. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -57,6 +57,8 @@ export declare const said: {
57
57
  stopped: (cause: string) => string;
58
58
  /** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
59
59
  reset: string;
60
+ /** A run whose learning seed predates a run's purge (learn/commit.ts `purged`, reason `purged_since_seed`). */
61
+ purgedSinceSeed: string;
60
62
  };
61
63
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
62
64
  * from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
@@ -113,6 +113,8 @@ export const said = {
113
113
  stopped: (cause) => `Not kept: learning stopped (${cause}).`,
114
114
  /** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
115
115
  reset: "Dropped: its learning seed predates a reset of the agent's learning.",
116
+ /** A run whose learning seed predates a run's purge (learn/commit.ts `purged`, reason `purged_since_seed`). */
117
+ purgedSinceSeed: "Dropped: another run's learning was purged after this run started, so nothing it learned is kept.",
116
118
  };
117
119
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
118
120
  * from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
@@ -1,7 +1,5 @@
1
1
  import { type Problem } from "./learn/index.js";
2
- import { type LearningFolder } from "./learn/folder.js";
3
- import type { Store } from "./store/index.js";
4
- import type { Workspace } from "./workspace/index.js";
2
+ import { type AgentLearning } from "./learn/rows.js";
5
3
  export { learnsOf } from "./learning-setting.js";
6
4
  /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
7
5
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
@@ -15,7 +13,7 @@ export declare function learningOf(env: NodeJS.ProcessEnv, given?: string): Lear
15
13
  * is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
16
14
  * nothing learned, `seed_failed`. */
17
15
  export declare const LEARNING_STATES: readonly ["seeded", "reflecting", "merged", "dropped"];
18
- export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
16
+ export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset", "purged_since_seed"];
19
17
  /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
20
18
  * learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
21
19
  * however many run at once. Its learning ends `dropped`, reason `use`. */
@@ -112,7 +110,7 @@ export declare const detailShown: (learning: Learning, shown: Shown, max?: numbe
112
110
  export declare const learningView: (learning: Learning, shown: Shown) => {
113
111
  workflows?: LearnedFile[];
114
112
  state: "dropped" | "merged" | "seeded" | "reflecting";
115
- reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
113
+ reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
116
114
  detail: string | null;
117
115
  at: string;
118
116
  };
@@ -127,7 +125,7 @@ export declare function shortOf<T extends {
127
125
  at: string;
128
126
  }>({ state, reason, detail, at: _, ...rest }: T): {
129
127
  state: "dropped" | "merged" | "seeded" | "reflecting";
130
- reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
128
+ reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
131
129
  detail: string | null;
132
130
  } & Omit<T, "at" | "reason" | "detail" | "state">;
133
131
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
@@ -163,24 +161,20 @@ export declare const LEARNED_WORKFLOWS_BUDGET: number;
163
161
  export declare const workflowLine: ({ name, description, workflow }: Pick<LearnedWorkflow, "name" | "description"> & {
164
162
  workflow?: string;
165
163
  }) => string;
166
- /** The agent's learning folder: `learning/` in its folder on the disk, which only the host writes. The folder is files.ts
167
- * agentFolderOf (server-fs.ts agentDiskDir), so two ids that differ only in case never share one. */
168
- export declare const learningRepo: (data: string, agentId: string) => string;
169
- /** Runs `work` once every call queued before it on the agent's folder has finished: one at a time per agent, in this
170
- * process. Everything that touches an agent's folder goes through it, so two runs made at once never both make it. */
171
- export declare const withAgentRepo: <T>(data: string, agentId: string, work: () => Promise<T>) => Promise<T>;
172
- /** Agent `agentId`'s learning folder (learn/folder.ts learningWorkspace), in this server's place: Mode 1's local folder
173
- * under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
174
- export declare const learningFolderOf: (data: string, agentId: string) => LearningFolder;
175
- /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
176
- * learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
177
- * reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
178
- export declare function seedOf(data: string, agentId: string): Promise<Seed>;
179
- /** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script), but a
180
- * learned workflow a purged run wrote, by `store`'s runs (purged-workflow.ts): no claim lays, checks, replays or serves
181
- * it. `store` null: a run's own process, which reads no other run; its runner reads the seed again with its store
182
- * (runner/learning-seed.ts). No commit (null) is the empty seed; a commit the folder no longer holds throws. */
183
- export declare function seedAt(ws: Workspace, commit: string | null, store: Pick<Store, "runs"> | null): Promise<Seed>;
164
+ /** Runs `work` once every call queued before it on agent `agentId`'s learning has finished: one at a time per agent, in
165
+ * this process. A run's seed read and a reset of the agent's learning (learning-reset.ts) go through it, so a seed is
166
+ * read wholly before a reset or wholly after. Keyed by the agent's folder (files.ts agentFolderOf): two ids that
167
+ * differ only in case share one queue. */
168
+ export declare const inLearningQueue: <T>(data: string, agentId: string, work: () => Promise<T>) => Promise<T>;
169
+ /** The seed of a run of agent `agentId` about to be made: its learning's newest save (its first, empty, made when it has
170
+ * none, so every seed names one), what it holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as
171
+ * a reset is (learning-reset.ts). */
172
+ export declare function seedOf(data: string, store: {
173
+ readonly learning: Pick<AgentLearning["rows"], "seed">;
174
+ }, agentId: string): Promise<Seed>;
175
+ /** What save `save` of the agent's learning holds for a run, as seedOf reads the newest, read now: a purged run's
176
+ * workflow is gone from it. No save (null) is the empty seed; a save the agent's learning no longer holds throws. */
177
+ export declare function seedAt(learning: AgentLearning, save: string | null): Promise<Seed>;
184
178
  /** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
185
179
  * decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
186
180
  * and every text its compile turn is told (runner/learning-end.ts compileAskOf); a text that is not JSON is read as
package/dist/learning.js CHANGED
@@ -1,24 +1,16 @@
1
- // Learning: an agent whose definition says `learning: true` keeps a folder of what it learned, and each of its runs
2
- // starts from it. The folder is `learning/` in the agent's folder on the disk (files.ts agentFolderOf): plain git with
3
- // main checked out, reached through its Workspace (learningWorkspace). It holds two things:
1
+ // Learning: an agent whose definition says `learning: true` keeps what it learned, and each of its runs starts from it.
2
+ // It is kept as versioned rows in the store (Store.learning; learn/rows.ts reads and writes them as files):
4
3
  // - corrections.md, its owner's standing corrections (learn/corrections.ts): every run of the agent is served it whole
5
4
  // under `# Learned` (laidLearned), cut of the host's secrets;
6
5
  // - workflows/<name>/, the workflows its runs compiled (learn/compile.ts): a run whose input one fits is answered by it
7
6
  // (runner/workflow-first.ts).
8
- // Every write to main is one exec of the learning script (learn/folder.ts), which also writes `.agentrun/snapshot.json`,
9
- // what the routes and a run's seed read: no git runs in this process. When a run of such an agent is made, the server
10
- // makes the folder if it is absent (the script's init: one empty host commit on main) and reads main's snapshot; the
11
- // run's launch keeps the commit it started from and its # Learned text, so its runner reads no folder.
12
- //
13
- // The host never follows a symbolic link into the folder (learn/folder.ts learningWorkspace, and the script): a link
14
- // there is refused, and the run starts with nothing learned.
15
- import { join } from "node:path";
7
+ // When a run of such an agent is made, the server reads its newest save (its first, empty, made when there is none);
8
+ // the run's launch keeps the save it started from and its # Learned text.
16
9
  import { CORRECTIONS_FILE, decodedStrings, frontMatter, learnedSecretShapes, redactLearned, valueMatcher } from "./learn/index.js";
17
- import { folderAt, learningInit, learningWorkspace, readLearning } from "./learn/folder.js";
10
+ import { readAt, readOf } from "./learn/rows.js";
18
11
  import { agentFolderOf, serialBy } from "./files.js";
19
12
  import { withoutLoopbackAddresses } from "./key-refusal.js";
20
13
  import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
21
- import { purgeGate } from "./purged-workflow.js";
22
14
  export { learnsOf } from "./learning-setting.js";
23
15
  /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
24
16
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
@@ -36,7 +28,7 @@ export function learningOf(env, given) {
36
28
  * is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
37
29
  * nothing learned, `seed_failed`. */
38
30
  export const LEARNING_STATES = ["seeded", "reflecting", "merged", "dropped"];
39
- export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
31
+ export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset", "purged_since_seed"];
40
32
  /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
41
33
  * learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
42
34
  * however many run at once. Its learning ends `dropped`, reason `use`. */
@@ -160,69 +152,46 @@ function compactSchema(schema, schemas, depth = 0, defs = {}) {
160
152
  return s.enum.map((value) => JSON.stringify(value)).join("|");
161
153
  return typeof s.type === "string" ? s.type : Array.isArray(s.type) ? s.type.join("|") : "any";
162
154
  }
163
- /** The agent's learning folder: `learning/` in its folder on the disk, which only the host writes. The folder is files.ts
164
- * agentFolderOf (server-fs.ts agentDiskDir), so two ids that differ only in case never share one. */
165
- export const learningRepo = (data, agentId) => join(agentFolderOf(data, agentId), "learning");
166
155
  const queues = new Map();
167
- /** Runs `work` once every call queued before it on the agent's folder has finished: one at a time per agent, in this
168
- * process. Everything that touches an agent's folder goes through it, so two runs made at once never both make it. */
169
- export const withAgentRepo = (data, agentId, work) => serialBy(queues, learningRepo(data, agentId), work);
170
- /** Agent `agentId`'s learning folder (learn/folder.ts learningWorkspace), in this server's place: Mode 1's local folder
171
- * under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
172
- export const learningFolderOf = (data, agentId) => learningWorkspace({ mode: "local", agentId, data });
173
- /** The seed of `snapshot` (undefined: no main yet), each body read by `text`: corrections.md, and each active draft's
174
- * README.md and workflow.json. A draft whose README's front matter does not read one way is never read as active. */
175
- async function seedIn(sha, snapshot, text) {
176
- const corrections = snapshot?.corrections ? await text(CORRECTIONS_FILE, snapshot.corrections.oid) : "";
156
+ /** Runs `work` once every call queued before it on agent `agentId`'s learning has finished: one at a time per agent, in
157
+ * this process. A run's seed read and a reset of the agent's learning (learning-reset.ts) go through it, so a seed is
158
+ * read wholly before a reset or wholly after. Keyed by the agent's folder (files.ts agentFolderOf): two ids that
159
+ * differ only in case share one queue. */
160
+ export const inLearningQueue = (data, agentId, work) => serialBy(queues, agentFolderOf(data, agentId), work);
161
+ /** The seed of a read (its view undefined: no save yet): corrections.md, and each active draft's README.md and
162
+ * workflow.json. A draft whose README's front matter does not read one way is never read as active. */
163
+ function seedIn(read) {
164
+ const corrections = read.text(CORRECTIONS_FILE) ?? "";
177
165
  const workflows = [];
178
- for (const item of snapshot?.workflows ?? []) {
166
+ for (const item of read.view?.workflows ?? []) {
179
167
  if (item.status !== "active")
180
168
  continue;
181
- const readme = item.files.find((file) => file.path.endsWith("/README.md"));
182
- const json = item.files.find((file) => file.path.endsWith("/workflow.json"));
183
- if (!readme || !json)
169
+ const readme = read.text(item.file);
170
+ const json = read.text(item.files.find((file) => file.path.endsWith("/workflow.json"))?.path ?? "");
171
+ if (readme === undefined || json === undefined)
184
172
  continue;
185
- const front = frontMatter(await text(readme.path, readme.oid));
173
+ const front = frontMatter(readme);
186
174
  if (!front)
187
175
  continue;
188
- workflows.push({ name: item.name, description: front.get("description") ?? "", workflow: await text(json.path, json.oid) });
176
+ workflows.push({ name: item.name, description: front.get("description") ?? "", workflow: json });
189
177
  }
190
- return { sha, corrections, workflows };
178
+ return { sha: read.view?.main ?? null, corrections, workflows };
191
179
  }
192
- /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
193
- * learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
194
- * reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
195
- export function seedOf(data, agentId) {
196
- return withAgentRepo(data, agentId, async () => {
197
- const { workspace, end } = learningFolderOf(data, agentId);
198
- try {
199
- await learningInit(workspace);
200
- const seed = await readLearning(workspace, async ({ snapshot, body }) => seedIn(snapshot?.main ?? null, snapshot, body));
201
- return { ...seed, at: Date.now() };
202
- }
203
- finally {
204
- await end();
205
- }
206
- });
180
+ /** The seed of a run of agent `agentId` about to be made: its learning's newest save (its first, empty, made when it has
181
+ * none, so every seed names one), what it holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as
182
+ * a reset is (learning-reset.ts). */
183
+ export function seedOf(data, store, agentId) {
184
+ return inLearningQueue(data, agentId, async () => ({ ...seedIn(readOf(await store.learning.seed(agentId))), at: Date.now() }));
207
185
  }
208
- /** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script), but a
209
- * learned workflow a purged run wrote, by `store`'s runs (purged-workflow.ts): no claim lays, checks, replays or serves
210
- * it. `store` null: a run's own process, which reads no other run; its runner reads the seed again with its store
211
- * (runner/learning-seed.ts). No commit (null) is the empty seed; a commit the folder no longer holds throws. */
212
- export async function seedAt(ws, commit, store) {
213
- if (commit === null)
186
+ /** What save `save` of the agent's learning holds for a run, as seedOf reads the newest, read now: a purged run's
187
+ * workflow is gone from it. No save (null) is the empty seed; a save the agent's learning no longer holds throws. */
188
+ export async function seedAt(learning, save) {
189
+ if (save === null)
214
190
  return { sha: null, corrections: "", workflows: [] };
215
- const at = await folderAt(ws, commit);
216
- if (!at)
217
- throw new Error(`the learning folder's read at ${commit} is gone`);
218
- const purged = store ? (await purgeGate(at.snapshot, store)).workflows : new Map();
219
- const seed = await seedIn(commit, at.snapshot, async (_path, oid) => {
220
- const bytes = at.blobs.get(oid);
221
- if (!bytes)
222
- throw new Error(`the learning folder's read at ${commit} holds no blob ${oid}`);
223
- return bytes.toString("utf8");
224
- });
225
- return { ...seed, workflows: seed.workflows.filter(({ name }) => !purged.has(name)) };
191
+ const read = await readAt(learning, save);
192
+ if (!read)
193
+ throw new Error(`the agent's learning holds no save ${save}`);
194
+ return seedIn(read);
226
195
  }
227
196
  /** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
228
197
  * decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
@@ -1,5 +1,6 @@
1
1
  import type { McpCallResult, McpTool } from "@parcha/agentrun-kernel";
2
2
  import { type FalMeterName, type MediaReader } from "./fal-price.js";
3
+ import { type FileSetting, UNREADABLE } from "./filed-tool.js";
3
4
  import { type Workspace } from "./workspace/index.js";
4
5
  /** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
5
6
  * (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
@@ -128,6 +129,11 @@ export interface McpGatewayOptions {
128
129
  now?: () => number;
129
130
  /** The run's id: what a meter scopes a server's keys to (McpMeter.keys). None: no key is scoped. */
130
131
  run?: string;
132
+ /** The file setting of a server's tool, read from the agent's own tool settings (filed-tool.ts filedBy): each answer
133
+ * of it, an error answer too, is filed whole in its folder of the run's files, and the tool's result is only a
134
+ * summary. UNREADABLE for a tool: a stored setting that does not read, and every call of the tool is refused unsent.
135
+ * None, or undefined for a tool: its answers are the model's, as always. */
136
+ filed?: (server: string, tool: string) => FileSetting | typeof UNREADABLE | undefined;
131
137
  }
132
138
  /** A run's journal commit. */
133
139
  export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
@@ -25,6 +25,7 @@ import { TOOL_UNMETERED } from "./timeline/index.js";
25
25
  import { until } from "./until.js";
26
26
  import { meterFor, meterNamed } from "./fal-price.js";
27
27
  import { filedAnswer } from "./filed-answer.js";
28
+ import { filedSummary, UNREADABLE, unfiledSummary } from "./filed-tool.js";
28
29
  import { saveOnce } from "./save-once.js";
29
30
  import { paidLedger, paidStep } from "./paid-calls.js";
30
31
  import { metaToolOf } from "./mcp-meta.js";
@@ -187,6 +188,8 @@ function unreachable(error) {
187
188
  return deepest;
188
189
  }
189
190
  const said = (text, isError = false) => ({ content: [{ type: "text", text }], ...(isError ? { isError: true } : {}) });
191
+ /** The refusal of a call of a tool whose stored file setting does not read (filed-tool.ts UNREADABLE). */
192
+ const unreadableFile = (server, tool) => `${mcpToolName(server, tool)} can't be called: its file setting in the agent's tool settings does not read, so no call is let through until the owner sets it again or removes it (Settings → Tools). Nothing was sent.`;
190
193
  export function mcpGateway(options) {
191
194
  /** Each server's client, with the account query it was connected with (`query`, JSON): a message that binds the run to
192
195
  * another account connects again, so no session made as one account carries another's calls. */
@@ -280,13 +283,8 @@ export function mcpGateway(options) {
280
283
  upstream.catch(() => clients.get(server) === made && clients.delete(server));
281
284
  return upstream;
282
285
  };
283
- /** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
284
- * file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
285
- * run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
286
- * and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
287
- * neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
288
- * credential the call's server took or sent. */
289
- const textOf = async (server, tool, result, clean) => {
286
+ /** The answer's text, as textOf reads it before any clip, scrubbed: `other`, how many blocks of it are not text. */
287
+ const answerOf = (result, clean) => {
290
288
  const blocks = Array.isArray(result.content) ? result.content : [];
291
289
  const texts = blocks.flatMap((block) => {
292
290
  if (block?.type === "text" && typeof block.text === "string")
@@ -300,7 +298,16 @@ export function mcpGateway(options) {
300
298
  let text = clean(texts.join("\n\n"));
301
299
  if (!text && result.structuredContent !== undefined)
302
300
  text = clean(JSON.stringify(result.structuredContent));
303
- const other = blocks.length - texts.length;
301
+ return { text, other: blocks.length - texts.length };
302
+ };
303
+ /** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
304
+ * file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
305
+ * run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
306
+ * and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
307
+ * neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
308
+ * credential the call's server took or sent. */
309
+ const textOf = async (server, tool, result, clean) => {
310
+ const { text, other } = answerOf(result, clean);
304
311
  if (text.length <= MCP_CLIP && other === 0)
305
312
  return text;
306
313
  const name = `${tool}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
@@ -316,6 +323,25 @@ export function mcpGateway(options) {
316
323
  }
317
324
  return `${head}the whole answer is in the run's files at evidence/mcp/${server}/${name}.json]`;
318
325
  };
326
+ /** An answer of a tool the agent's setting files (options.filed): written whole, scrubbed, at
327
+ * <folder>/<tool>-<time>-<id>.json in the run's files before the model is answered, and the tool's result the summary
328
+ * alone (filed-tool.ts), never through the clip. An error answer is filed the same way and its summary answers an
329
+ * error, so the model can still react through a shown field. An answer with blocks that are not text is filed as the
330
+ * whole result's JSON. A write that fails (or a Workspace that cannot open) answers an error in the Workspace's words,
331
+ * none of the answer shown. */
332
+ const filedOf = async (setting, tool, result, clean) => {
333
+ const { text: answer, other } = answerOf(result, clean);
334
+ const text = other === 0 ? answer : clean(JSON.stringify(result));
335
+ const path = `${setting.folder}/${tool.replace(/[^A-Za-z0-9_.-]/g, "_")}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}.json`;
336
+ try {
337
+ await workspaceAt(await options.work()).write(path, text);
338
+ }
339
+ catch (error) {
340
+ // The Workspace's code and the port's line for it, never the error's message, which names paths.
341
+ return said(unfiledSummary(tool, text, setting.folder, workspaceErrorWords(error) ?? (typeof error?.code === "string" ? error.code : "write failed")), true);
342
+ }
343
+ return said(filedSummary(tool, text, path, setting.show), result.isError === true);
344
+ };
319
345
  /** The results `result` carries that `server`'s meter keeps (McpMeter.results), each filed at its `<dir>/<name>.json`
320
346
  * in the run's files, once (save-once.ts): a file, folder or link already there is kept, and a link on the way is never
321
347
  * followed. Scrubbed as the model's text is. Nothing is said of it in the answer, and a result that could not be filed
@@ -383,6 +409,12 @@ export function mcpGateway(options) {
383
409
  return said("", result.isError === true);
384
410
  // Filed before the answer is given, so a model that reads it next finds it.
385
411
  await fileResults(server, tool.name, result, clean);
412
+ const filing = options.filed?.(server, tool.name);
413
+ // UNREADABLE never gets here (unsendable refuses it unsent); never answered unfiled either way.
414
+ if (filing === UNREADABLE)
415
+ return said(unreadableFile(server, tool.name), true);
416
+ if (filing)
417
+ return await filedOf(filing, tool.name, result, clean);
386
418
  return said(await textOf(server, tool.name, result, clean), result.isError === true);
387
419
  }
388
420
  catch (error) {
@@ -422,6 +454,10 @@ export function mcpGateway(options) {
422
454
  const pinned = pins.get(server);
423
455
  if (!pinned?.tools.some((t) => t.name === tool))
424
456
  return `${tool} is not a tool of the MCP server ${server} in this run.`;
457
+ // A file setting that does not read fails closed, as a broken pin does: never a call whose answer goes to the model
458
+ // unfiled.
459
+ if (options.filed?.(server, tool) === UNREADABLE)
460
+ return unreadableFile(server, tool);
425
461
  const resourceProblem = resourceToolProblem(pinned.tools.find(t => t.name === tool));
426
462
  if (resourceProblem)
427
463
  return `The MCP operation ${tool} is invalid: ${resourceProblem}. Nothing was sent.`;
@@ -8,7 +8,7 @@ export declare const RESOURCE_PAGES_MAX = 64;
8
8
  export declare const reservedResourceName: (name: string) => boolean;
9
9
  export declare function resourceTools(): {
10
10
  name: string;
11
- resource: "read" | "templates" | "list";
11
+ resource: "read" | "list" | "templates";
12
12
  title: string;
13
13
  description: string;
14
14
  input_schema: {
@@ -6,6 +6,12 @@ export declare class NativeDiscoveryError extends ApiError {
6
6
  }
7
7
  /** Resolve only through the supplied native PATH. Never substitutes a bundled managed runtime. */
8
8
  export declare function nativeExecutable(runtime: NativeRuntime, env?: NodeJS.ProcessEnv): Promise<string | null>;
9
+ /** The environment a native CLI starts with: `env`, with `USER` and `LOGNAME` filled in where it has none (unset or
10
+ * empty) by the user this process runs as (loginUser, from the user database). On macOS Claude Code names its Keychain
11
+ * item's account by `$USER`, else by its Bun runtime's userInfo, which reads `$USER` too: "unknown" with none. So a
12
+ * server started with no USER (a launchd service) would read the person's login under "unknown", where their terminal's
13
+ * `claude` never saved it, and say signed out. A USER `env` has is the person's own shell's and is kept as it is. */
14
+ export declare function nativeSpawnEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
9
15
  /** Metadata commands are bounded and never contain a prompt or a launch command. */
10
16
  export declare function nativeMetadata(binary: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, timeoutMs?: number): Promise<{
11
17
  code: number | null;
@@ -4,6 +4,7 @@ import { constants } from "node:fs";
4
4
  import { dirname, join, resolve, delimiter, basename } from "node:path";
5
5
  import { homedir, hostname } from "node:os";
6
6
  import { spawn } from "node:child_process";
7
+ import { loginUser } from "@parcha/agentrun-harness-claude/facts";
7
8
  import { ApiError } from "../errors.js";
8
9
  import { NATIVE_MINIMUM_VERSION, NATIVE_RUNTIME_FACTS, NATIVE_RUNTIMES, NATIVE_CLAUDE_POLICY_UNRESOLVED, NATIVE_CLAUDE_ADDITIONAL_POLICY_UNRESOLVED } from "./runtimes.js";
9
10
  export { NATIVE_MINIMUM_VERSION } from "./runtimes.js";
@@ -46,11 +47,23 @@ export async function nativeExecutable(runtime, env = process.env) {
46
47
  }
47
48
  return null;
48
49
  }
50
+ /** The environment a native CLI starts with: `env`, with `USER` and `LOGNAME` filled in where it has none (unset or
51
+ * empty) by the user this process runs as (loginUser, from the user database). On macOS Claude Code names its Keychain
52
+ * item's account by `$USER`, else by its Bun runtime's userInfo, which reads `$USER` too: "unknown" with none. So a
53
+ * server started with no USER (a launchd service) would read the person's login under "unknown", where their terminal's
54
+ * `claude` never saved it, and say signed out. A USER `env` has is the person's own shell's and is kept as it is. */
55
+ export function nativeSpawnEnv(env) {
56
+ const user = loginUser(), filled = { ...env };
57
+ for (const name of ["USER", "LOGNAME"])
58
+ if (!filled[name] && user[name])
59
+ filled[name] = user[name];
60
+ return filled;
61
+ }
49
62
  /** Metadata commands are bounded and never contain a prompt or a launch command. */
50
63
  export async function nativeMetadata(binary, args, cwd, env, timeoutMs = 5_000) {
51
64
  return new Promise((resolveResult) => {
52
65
  let stdout = "", done = false;
53
- const child = spawn(binary, args, { cwd, env, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "ignore"] });
66
+ const child = spawn(binary, args, { cwd, env: nativeSpawnEnv(env), detached: process.platform !== "win32", stdio: ["ignore", "pipe", "ignore"] });
54
67
  const finish = (code) => { if (done)
55
68
  return; done = true; clearTimeout(timer); resolveResult({ code, stdout }); };
56
69
  const timer = setTimeout(() => { try {
@@ -17,6 +17,11 @@ export declare class RemoteConnectors {
17
17
  constructor(store: Store, now?: () => number);
18
18
  private connector;
19
19
  private targets;
20
+ /** Connector transport health only: an online worker does not establish any external session's liveness. */
21
+ health(id: string): Promise<{
22
+ status: "current" | "offline" | "revoked" | "unreported";
23
+ last_seen_at: string | null;
24
+ }>;
20
25
  private view;
21
26
  list(): Promise<{
22
27
  connectors: {
@@ -43,6 +43,22 @@ export class RemoteConnectors {
43
43
  async targets(id) {
44
44
  return (await this.store.settings.all({ prefix: keyOf('target', `${id}.`) })).map(row => row.value);
45
45
  }
46
+ /** Connector transport health only: an online worker does not establish any external session's liveness. */
47
+ async health(id) {
48
+ let row;
49
+ try {
50
+ row = await this.connector(id);
51
+ }
52
+ catch (error) {
53
+ if (error instanceof ApiError && error.code === "not_found")
54
+ return { status: "unreported", last_seen_at: null };
55
+ throw error;
56
+ }
57
+ return {
58
+ status: row.revoked || row.expires <= this.now() ? "revoked" : row.last_seen + ONLINE_MS >= this.now() ? "current" : "offline",
59
+ last_seen_at: row.last_seen ? new Date(row.last_seen).toISOString() : null,
60
+ };
61
+ }
46
62
  async view(row) {
47
63
  const targets = await this.targets(row.id);
48
64
  return { id: row.id, connector_id: row.id, label: row.label, created_at: row.created_at, last_seen_at: row.last_seen ? new Date(row.last_seen).toISOString() : null,
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { StringDecoder } from "node:string_decoder";
3
3
  import { NATIVE_RUNTIME_FACTS } from "./runtimes.js";
4
- import { nativeExecutable, nativeMetadata } from "./discovery.js";
4
+ import { nativeExecutable, nativeMetadata, nativeSpawnEnv } from "./discovery.js";
5
5
  const unknownUsage = () => ({ input_tokens: null, output_tokens: null, cache_read_tokens: null, cache_write_tokens: null, cost_usd: null });
6
6
  const count = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
7
7
  /** A stop kills the source immediately, then gives its already reported events this long to finish recording. */
@@ -118,7 +118,8 @@ export async function openNativeSession(options) {
118
118
  const denials = [], toolNames = new Map();
119
119
  const seenEvents = new Set();
120
120
  let eventQueue = Promise.resolve(), eventsClosed = false;
121
- const child = spawn(binary, args, { cwd: target.project, env, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
121
+ // USER filled where the server has none, so the CLI reads the person's Keychain item (nativeSpawnEnv).
122
+ const child = spawn(binary, args, { cwd: target.project, env: nativeSpawnEnv(env), detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
122
123
  active = child;
123
124
  const emit = (event) => { eventQueue = eventQueue.then(() => eventsClosed ? undefined : options.onEvent?.(event)).then(() => { }); eventQueue.catch(error => stop(error instanceof Error ? error : new Error("Native event recording failed."))); };
124
125
  const abort = () => stop(new NativeRuntimeError("Native turn was cancelled; its outcome may be incomplete. Inspect the recorded session before retrying.", "aborted", sessionId));
@@ -60,7 +60,7 @@ export declare class Observations {
60
60
  id: string;
61
61
  workspace_id: string;
62
62
  kind: string;
63
- state: "revoked" | "active";
63
+ state: "active" | "revoked";
64
64
  display_name: string;
65
65
  owner_user_id: string;
66
66
  cli_version: string;
@@ -86,7 +86,7 @@ export declare class Observations {
86
86
  id: string;
87
87
  workspace_id: string;
88
88
  kind: string;
89
- state: "revoked" | "active";
89
+ state: "active" | "revoked";
90
90
  display_name: string;
91
91
  owner_user_id: string;
92
92
  cli_version: string;
@@ -111,7 +111,7 @@ export declare class Observations {
111
111
  id: string;
112
112
  workspace_id: string;
113
113
  kind: string;
114
- state: "revoked" | "active";
114
+ state: "active" | "revoked";
115
115
  display_name: string;
116
116
  owner_user_id: string;
117
117
  cli_version: string;
@@ -133,7 +133,7 @@ export declare class Observations {
133
133
  id: string;
134
134
  workspace_id: string;
135
135
  kind: string;
136
- state: "revoked" | "active";
136
+ state: "active" | "revoked";
137
137
  display_name: string;
138
138
  owner_user_id: string;
139
139
  cli_version: string;
@@ -179,7 +179,7 @@ export declare class Observations {
179
179
  id: string;
180
180
  workspace_id: string;
181
181
  kind: string;
182
- state: "revoked" | "active";
182
+ state: "active" | "revoked";
183
183
  display_name: string;
184
184
  owner_user_id: string;
185
185
  cli_version: string;
@@ -204,7 +204,7 @@ export declare class Observations {
204
204
  id: string;
205
205
  workspace_id: string;
206
206
  kind: string;
207
- state: "revoked" | "active";
207
+ state: "active" | "revoked";
208
208
  display_name: string;
209
209
  owner_user_id: string;
210
210
  cli_version: string;