@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36

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 (372) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +260 -168
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/box-image.d.ts +1 -97
  19. package/dist/box-image.js +4 -284
  20. package/dist/box-paths.d.ts +2 -7
  21. package/dist/box-paths.js +7 -13
  22. package/dist/box-settings.d.ts +0 -11
  23. package/dist/box-settings.js +4 -29
  24. package/dist/browser-commands.js +1 -1
  25. package/dist/browser-computer.d.ts +47 -3
  26. package/dist/browser-computer.js +286 -18
  27. package/dist/browser-person.d.ts +19 -2
  28. package/dist/browser-person.js +55 -6
  29. package/dist/browser-wait-ended.d.ts +23 -0
  30. package/dist/browser-wait-ended.js +42 -0
  31. package/dist/cap.d.ts +13 -41
  32. package/dist/cap.js +24 -73
  33. package/dist/cli.js +4 -22
  34. package/dist/computer-routes.d.ts +1 -4
  35. package/dist/computer-routes.js +3 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +38 -1
  38. package/dist/computer-view.d.ts +11 -2
  39. package/dist/computer-view.js +2 -1
  40. package/dist/computers.d.ts +48 -7
  41. package/dist/computers.js +100 -23
  42. package/dist/console/assets/index-BI4Byidu.js +550 -0
  43. package/dist/console/assets/index-C19gUF2n.css +1 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/docker-daemon.d.ts +2 -2
  46. package/dist/docker-daemon.js +2 -2
  47. package/dist/errors.js +5 -5
  48. package/dist/faux-computers.js +4 -0
  49. package/dist/files.d.ts +1 -9
  50. package/dist/files.js +1 -9
  51. package/dist/github.d.ts +22 -2
  52. package/dist/github.js +42 -8
  53. package/dist/gpu-words.d.ts +14 -0
  54. package/dist/gpu-words.js +21 -0
  55. package/dist/graph-view.d.ts +2 -0
  56. package/dist/graph-view.js +25 -1
  57. package/dist/handed-values.d.ts +1 -1
  58. package/dist/handed-values.js +1 -1
  59. package/dist/harness-install.d.ts +60 -3
  60. package/dist/harness-install.js +322 -34
  61. package/dist/harness.js +1 -1
  62. package/dist/host-tools.d.ts +8 -9
  63. package/dist/host-tools.js +7 -7
  64. package/dist/index.d.ts +1 -3
  65. package/dist/index.js +1 -2
  66. package/dist/key-refusal.d.ts +1 -1
  67. package/dist/key-refusal.js +2 -2
  68. package/dist/learn/check.d.ts +7 -1
  69. package/dist/learn/check.js +123 -5
  70. package/dist/learn/commit.d.ts +40 -6
  71. package/dist/learn/commit.js +164 -20
  72. package/dist/learn/folder.d.ts +5 -0
  73. package/dist/learn/folder.js +33 -0
  74. package/dist/learn/grade.d.ts +18 -1
  75. package/dist/learn/grade.js +86 -16
  76. package/dist/learn/index.d.ts +1 -1
  77. package/dist/learn/index.js +1 -1
  78. package/dist/learn/learning.sh +12 -1
  79. package/dist/learn/notes.d.ts +3 -0
  80. package/dist/learn/notes.js +3 -0
  81. package/dist/learn/reflect.d.ts +5 -2
  82. package/dist/learn/reflect.js +43 -29
  83. package/dist/learn/skills.d.ts +4 -0
  84. package/dist/learn/skills.js +7 -0
  85. package/dist/learned-nodes.d.ts +6 -2
  86. package/dist/learned-workflow.d.ts +19 -9
  87. package/dist/learned-workflow.js +62 -34
  88. package/dist/learning-cost.d.ts +79 -0
  89. package/dist/learning-cost.js +69 -0
  90. package/dist/learning-routes.d.ts +8 -3
  91. package/dist/learning-routes.js +9 -6
  92. package/dist/learning-words.d.ts +3 -0
  93. package/dist/learning-words.js +6 -2
  94. package/dist/learning.d.ts +13 -6
  95. package/dist/learning.js +4 -2
  96. package/dist/mcp-probe.d.ts +8 -1
  97. package/dist/mcp-probe.js +62 -20
  98. package/dist/mcp-secret-writes.js +4 -0
  99. package/dist/mcp-servers-store.js +8 -3
  100. package/dist/model.d.ts +5 -5
  101. package/dist/model.js +6 -6
  102. package/dist/openapi.d.ts +2 -0
  103. package/dist/openapi.js +204 -47
  104. package/dist/owner.d.ts +0 -1
  105. package/dist/owner.js +0 -2
  106. package/dist/paid-calls.js +1 -1
  107. package/dist/place-offers.d.ts +97 -0
  108. package/dist/place-offers.js +206 -0
  109. package/dist/place.d.ts +9 -13
  110. package/dist/place.js +22 -32
  111. package/dist/port-models.d.ts +2 -1
  112. package/dist/port-models.js +5 -3
  113. package/dist/print.d.ts +1 -8
  114. package/dist/print.js +1 -14
  115. package/dist/propose.d.ts +1 -0
  116. package/dist/propose.js +25 -10
  117. package/dist/run-cut.d.ts +5 -0
  118. package/dist/run-cut.js +19 -0
  119. package/dist/run-db.js +3 -3
  120. package/dist/run-launch.d.ts +14 -1
  121. package/dist/run-launch.js +7 -2
  122. package/dist/run-learning-served.d.ts +1 -1
  123. package/dist/run-manifest.d.ts +2 -2
  124. package/dist/run-manifest.js +2 -2
  125. package/dist/run-secrets.js +3 -3
  126. package/dist/run-timeline-served.js +56 -44
  127. package/dist/run-view.d.ts +5 -2
  128. package/dist/run-view.js +4 -3
  129. package/dist/runnable.d.ts +2 -2
  130. package/dist/runnable.js +6 -2
  131. package/dist/runner/adapter-loop.d.ts +16 -1
  132. package/dist/runner/adapter-loop.js +131 -30
  133. package/dist/runner/adapter-run-spec.d.ts +25 -4
  134. package/dist/runner/adapter-run-spec.js +103 -24
  135. package/dist/runner/adapters/pi.d.ts +11 -3
  136. package/dist/runner/adapters/pi.js +35 -12
  137. package/dist/runner/beside.js +6 -2
  138. package/dist/runner/cli-run-spec.d.ts +7 -0
  139. package/dist/runner/cli-run-spec.js +92 -38
  140. package/dist/runner/commands.d.ts +5 -1
  141. package/dist/runner/commands.js +3 -3
  142. package/dist/runner/conformance/harness.d.ts +0 -1
  143. package/dist/runner/conformance/harness.js +8 -5
  144. package/dist/runner/github-app.js +2 -2
  145. package/dist/runner/harness-loops.js +1 -1
  146. package/dist/runner/journal-kinds.d.ts +15 -5
  147. package/dist/runner/journal-kinds.js +6 -1
  148. package/dist/runner/learning-end.d.ts +15 -0
  149. package/dist/runner/learning-end.js +26 -5
  150. package/dist/runner/learning-factory.js +6 -2
  151. package/dist/runner/learning-loop.d.ts +73 -1
  152. package/dist/runner/learning-loop.js +203 -18
  153. package/dist/runner/learning-seed.d.ts +2 -0
  154. package/dist/runner/learning-seed.js +1 -1
  155. package/dist/runner/loop-contract.d.ts +8 -0
  156. package/dist/runner/loop-contract.js +6 -0
  157. package/dist/runner/loop.d.ts +5 -1
  158. package/dist/runner/loop.js +20 -0
  159. package/dist/runner/main.js +12 -2
  160. package/dist/runner/mcp-claim.d.ts +4 -0
  161. package/dist/runner/mcp-claim.js +29 -1
  162. package/dist/runner/mcp-github.d.ts +4 -2
  163. package/dist/runner/mcp-github.js +0 -7
  164. package/dist/runner/mcp-run.d.ts +2 -0
  165. package/dist/runner/mcp-run.js +1 -0
  166. package/dist/runner/metrics.d.ts +4 -0
  167. package/dist/runner/metrics.js +9 -0
  168. package/dist/runner/model-route.d.ts +3 -0
  169. package/dist/runner/model-route.js +5 -2
  170. package/dist/runner/pr-checkout.d.ts +59 -0
  171. package/dist/runner/pr-checkout.js +176 -0
  172. package/dist/runner/reflect-hook.d.ts +1 -0
  173. package/dist/runner/reflect-hook.js +3 -3
  174. package/dist/runner/runner.js +47 -12
  175. package/dist/runner/spec-holds.d.ts +8 -3
  176. package/dist/runner/spec-holds.js +12 -10
  177. package/dist/runner/store-port.d.ts +4 -1
  178. package/dist/runner/store-secrets.js +17 -1
  179. package/dist/runner/subagent.d.ts +44 -0
  180. package/dist/runner/subagent.js +188 -0
  181. package/dist/runner/workflow-host.d.ts +18 -2
  182. package/dist/runner/workflow-host.js +23 -3
  183. package/dist/runner/workflow-loop.d.ts +5 -2
  184. package/dist/runner/workflow-loop.js +9 -8
  185. package/dist/runner/workflow-spec.d.ts +26 -14
  186. package/dist/runner/workflow-spec.js +97 -30
  187. package/dist/runs-over-store.d.ts +11 -6
  188. package/dist/runs-over-store.js +111 -24
  189. package/dist/sealing.js +1 -2
  190. package/dist/secret-cut.d.ts +1 -1
  191. package/dist/secret-cut.js +1 -1
  192. package/dist/server.d.ts +32 -49
  193. package/dist/server.js +249 -199
  194. package/dist/store/agent-body.d.ts +9 -2
  195. package/dist/store/agent-body.js +16 -8
  196. package/dist/store/deadline.js +9 -5
  197. package/dist/store/index.d.ts +3 -3
  198. package/dist/store/index.js +2 -2
  199. package/dist/store/journal/storage.js +2 -1
  200. package/dist/store/postgres/connection.js +9 -4
  201. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  202. package/dist/store/schema.d.ts +2 -1
  203. package/dist/store/schema.js +11 -8
  204. package/dist/store/seal.d.ts +13 -0
  205. package/dist/store/seal.js +19 -0
  206. package/dist/store/sqlite/connection.d.ts +5 -0
  207. package/dist/store/sqlite/connection.js +88 -47
  208. package/dist/store/sqlite/run-patch.d.ts +18 -2
  209. package/dist/store/sqlite/run-patch.js +31 -2
  210. package/dist/store/sqlite/store.js +65 -11
  211. package/dist/store/store.d.ts +62 -12
  212. package/dist/store/store.js +22 -1
  213. package/dist/store-reads/analytics.js +3 -2
  214. package/dist/store-reads/cap.d.ts +1 -3
  215. package/dist/store-reads/cap.js +8 -6
  216. package/dist/store-reads/decisions.d.ts +2 -2
  217. package/dist/store-reads/decisions.js +3 -6
  218. package/dist/store-reads/journal.js +45 -12
  219. package/dist/store-reads/learning.d.ts +15 -1
  220. package/dist/store-reads/learning.js +68 -10
  221. package/dist/store-reads/runs.d.ts +6 -4
  222. package/dist/store-reads/runs.js +17 -10
  223. package/dist/store-reads/stats.js +5 -1
  224. package/dist/store-view.js +45 -19
  225. package/dist/template-eval.js +2 -1
  226. package/dist/templates.d.ts +64 -0
  227. package/dist/templates.js +101 -16
  228. package/dist/timeline/timeline.d.ts +3 -1
  229. package/dist/timeline/timeline.js +19 -4
  230. package/dist/tool-blurbs.js +1 -0
  231. package/dist/tool-budget.d.ts +8 -0
  232. package/dist/tool-budget.js +7 -1
  233. package/dist/tool-gate.d.ts +7 -1
  234. package/dist/tool-gate.js +7 -2
  235. package/dist/tool-plane.d.ts +33 -19
  236. package/dist/tool-plane.js +64 -27
  237. package/dist/tools.d.ts +18 -34
  238. package/dist/tools.js +104 -70
  239. package/dist/trigger-signatures.d.ts +1 -0
  240. package/dist/trigger-signatures.js +3 -1
  241. package/dist/triggers.d.ts +3 -3
  242. package/dist/triggers.js +2 -2
  243. package/dist/turn-end.d.ts +0 -3
  244. package/dist/turn-end.js +0 -3
  245. package/dist/usage-lines.d.ts +1 -1
  246. package/dist/validate.d.ts +6 -0
  247. package/dist/validate.js +30 -3
  248. package/dist/webhooks.d.ts +2 -1
  249. package/dist/webhooks.js +5 -2
  250. package/dist/workflow/decision-recovery.d.ts +23 -0
  251. package/dist/workflow/decision-recovery.js +80 -0
  252. package/dist/workflow/decisions.d.ts +134 -0
  253. package/dist/workflow/decisions.js +46 -0
  254. package/dist/workflow/host-session.d.ts +5 -0
  255. package/dist/workflow/host-session.js +85 -0
  256. package/dist/workflow/host-tools.d.ts +3 -0
  257. package/dist/workflow/host-tools.js +3 -0
  258. package/dist/workflow/node-runner.d.ts +112 -0
  259. package/dist/workflow/node-runner.js +270 -0
  260. package/dist/workflow/node.d.ts +88 -0
  261. package/dist/workflow/node.js +99 -0
  262. package/dist/workflow/operator-error.d.ts +4 -0
  263. package/dist/workflow/operator-error.js +4 -0
  264. package/dist/workflow/pi-versions.d.ts +9 -0
  265. package/dist/workflow/pi-versions.js +8 -0
  266. package/dist/workflow/readers.d.ts +36 -0
  267. package/dist/workflow/readers.js +145 -0
  268. package/dist/workflow/record-file.d.ts +10 -0
  269. package/dist/workflow/record-file.js +56 -0
  270. package/dist/workflow/record-tool.d.ts +76 -0
  271. package/dist/workflow/record-tool.js +126 -0
  272. package/dist/workflow/record.d.ts +151 -0
  273. package/dist/workflow/record.js +401 -0
  274. package/dist/workflow/run-error.d.ts +16 -0
  275. package/dist/workflow/run-error.js +26 -0
  276. package/dist/workflow/runner.d.ts +6 -0
  277. package/dist/workflow/runner.js +240 -0
  278. package/dist/workflow/store.d.ts +23 -0
  279. package/dist/workflow/store.js +242 -0
  280. package/dist/workflow/task.d.ts +133 -0
  281. package/dist/workflow/task.js +411 -0
  282. package/dist/workflow/thinking.d.ts +3 -0
  283. package/dist/workflow/thinking.js +7 -0
  284. package/dist/workflow/tool-context.d.ts +21 -0
  285. package/dist/workflow/tool-context.js +13 -0
  286. package/dist/workflow/types.d.ts +126 -0
  287. package/dist/workflow/types.js +1 -0
  288. package/dist/workflow/wal.d.ts +11 -0
  289. package/dist/workflow/wal.js +106 -0
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/agent-computer.d.ts +137 -0
  292. package/dist/workspace/agent-computer.js +292 -0
  293. package/dist/workspace/archil-claim.d.ts +11 -0
  294. package/dist/workspace/archil-claim.js +18 -10
  295. package/dist/workspace/archil-disks.d.ts +49 -0
  296. package/dist/workspace/archil-disks.js +185 -0
  297. package/dist/workspace/archil-exec.js +2 -3
  298. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  299. package/dist/workspace/archil-mount-credential.js +13 -4
  300. package/dist/workspace/computer-deps.d.ts +16 -8
  301. package/dist/workspace/computer-deps.js +18 -7
  302. package/dist/workspace/computer-for-claim.d.ts +42 -6
  303. package/dist/workspace/computer-for-claim.js +209 -9
  304. package/dist/workspace/computer-janitor.d.ts +3 -2
  305. package/dist/workspace/computer-janitor.js +43 -9
  306. package/dist/workspace/computer-ledger.d.ts +3 -1
  307. package/dist/workspace/computer-ledger.js +7 -0
  308. package/dist/workspace/index.d.ts +3 -2
  309. package/dist/workspace/index.js +1 -0
  310. package/dist/workspace/resolve-computer.d.ts +42 -11
  311. package/dist/workspace/resolve-computer.js +65 -13
  312. package/dist/workspace/run-disk.d.ts +34 -0
  313. package/dist/workspace/run-disk.js +91 -0
  314. package/dist/workspace/run-tools.d.ts +4 -4
  315. package/dist/workspace/run-tools.js +8 -6
  316. package/dist/workspace/server-run-workspace.d.ts +3 -2
  317. package/dist/workspace/server-run-workspace.js +17 -4
  318. package/dist/workspace.js +1 -1
  319. package/package.json +10 -15
  320. package/templates/README.md +9 -6
  321. package/templates/code-review/agent.md +27 -11
  322. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  323. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  324. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  325. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  326. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  327. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  328. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  329. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  330. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  331. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  332. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  333. package/templates/code-review/evals/re-review/prompt.md +1 -1
  334. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  335. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  336. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  337. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  338. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  339. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  340. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  341. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  342. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  343. package/templates/code-review/findings.schema.json +131 -27
  344. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  345. package/templates/code-review/skills/review/DEEP.md +130 -0
  346. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  347. package/templates/code-review/skills/review/SKILL.md +104 -154
  348. package/dist/box/record.d.ts +0 -6
  349. package/dist/box/record.js +0 -41
  350. package/dist/box/sweep.d.ts +0 -53
  351. package/dist/box/sweep.js +0 -193
  352. package/dist/box-egress-vm.d.ts +0 -118
  353. package/dist/box-egress-vm.js +0 -354
  354. package/dist/box-egress.d.ts +0 -105
  355. package/dist/box-egress.js +0 -256
  356. package/dist/box-relay-vm.d.ts +0 -84
  357. package/dist/box-relay-vm.js +0 -437
  358. package/dist/box-relay.d.ts +0 -36
  359. package/dist/box-relay.js +0 -207
  360. package/dist/boxes.d.ts +0 -109
  361. package/dist/boxes.js +0 -249
  362. package/dist/budget.d.ts +0 -71
  363. package/dist/budget.js +0 -199
  364. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  365. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  366. package/dist/daytona-api.d.ts +0 -10
  367. package/dist/daytona-api.js +0 -20
  368. package/dist/egress-proxy.d.ts +0 -45
  369. package/dist/egress-proxy.js +0 -416
  370. package/dist/egress-table.d.ts +0 -24
  371. package/dist/egress-table.js +0 -165
  372. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -20,9 +20,9 @@
20
20
  // that directory, never a half install, and the next install removes it; a tree that is not whole (an install by hand
21
21
  // cut short) is never loaded, and the next install replaces it.
22
22
  import { spawn } from "node:child_process";
23
- import { existsSync, readFileSync, realpathSync } from "node:fs";
24
- import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
25
- import { createRequire } from "node:module";
23
+ import { randomUUID } from "node:crypto";
24
+ import { existsSync, readFileSync, readlinkSync, realpathSync, statSync } from "node:fs";
25
+ import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
26
26
  import { hostname } from "node:os";
27
27
  import { basename, dirname, join, sep } from "node:path";
28
28
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -50,22 +50,97 @@ export function installLine(dir, lock) {
50
50
  return `rm -rf ${next} && mkdir -p ${next} && cp ${shellWord(join(dirname(lock), "package.json"))} ${shellWord(lock)} ${next}/ && npm ci --prefix ${next} --ignore-scripts --include=optional && (chmod -R u+w ${at} 2>/dev/null || true) && rm -rf ${at} && mv ${next} ${at}`;
51
51
  }
52
52
  /** Where `specifier` (a package, or a file of one) resolves from `dir`'s node_modules, only when it is that package's own
53
- * file there: undefined when the package is not in `dir`, or its file resolves outside it (a node_modules above `dir`,
54
- * NODE_PATH, a global one). A package linked into `dir` counts by where its link points. */
53
+ * file there: undefined when the package is not in `dir`, does not export it, or its file resolves outside it (a link to
54
+ * a file elsewhere). A package linked into `dir` counts by where its link points. Its real path, as Node's resolver gives.
55
+ *
56
+ * Read from the tree as it is now, never through Node's resolver: a long-lived process (a runner) keeps what that
57
+ * resolver read for its whole life (its path cache, and the real path of each link it walked), so a package once linked
58
+ * into the tree, then replaced at the same path by an install, would read as the link's old target until the process
59
+ * restarts. The package's own package.json is read here, and real paths taken with no cache. */
55
60
  export function inTree(dir, specifier) {
56
61
  const parts = specifier.split("/");
57
62
  const name = parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
58
63
  const home = join(dir, "node_modules", name);
59
- if (!existsSync(join(home, "package.json")))
60
- return undefined;
61
64
  try {
62
- const found = createRequire(join(dir, "package.json")).resolve(specifier);
63
- return realpathSync(found).startsWith(realpathSync(home) + sep) ? found : undefined;
65
+ const manifest = JSON.parse(readFileSync(join(home, "package.json"), "utf8"));
66
+ const subpath = `.${specifier.slice(name.length)}`;
67
+ const target = manifest.exports !== undefined ? exportsTarget(manifest.exports, subpath) : (subpath === "." ? (typeof manifest.main === "string" ? manifest.main : "index.js") : subpath);
68
+ if (target === undefined)
69
+ return undefined;
70
+ const found = [target, `${target}.js`, join(target, "index.js")].map((path) => join(home, path)).find(statFile);
71
+ if (!found)
72
+ return undefined;
73
+ const real = realpathSync(found);
74
+ return real.startsWith(realpathSync(home) + sep) ? real : undefined;
64
75
  }
65
76
  catch {
66
77
  return undefined;
67
78
  }
68
79
  }
80
+ /** Whether `path` is a file (a link to one counts). */
81
+ const statFile = (path) => {
82
+ try {
83
+ return statSync(path).isFile();
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ };
89
+ /** The conditions Node's require() matches a package's exports by; a package's own key order decides among them. */
90
+ const REQUIRE_CONDITIONS = new Set(["require", "node", "node-addons", "module-sync", "default"]);
91
+ /** The file `exports` maps `subpath` (".", "./server/mcp.js") to, as Node's require() reads it: the subpath's own key,
92
+ * else the pattern ("./*") whose part before its "*" is longest, its "*" given the rest; within it, the first condition
93
+ * require() matches, in the package's own order (an array: its first target that is one). Undefined when the package
94
+ * does not export it. */
95
+ function exportsTarget(exportsField, subpath) {
96
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
97
+ const map = isObject(exportsField) && Object.keys(exportsField).some((key) => key.startsWith(".")) ? exportsField : { ".": exportsField };
98
+ let target = Object.hasOwn(map, subpath) ? map[subpath] : undefined;
99
+ let star;
100
+ if (target === undefined) {
101
+ let best;
102
+ for (const key of Object.keys(map)) {
103
+ const at = key.indexOf("*");
104
+ if (at < 0 || key.indexOf("*", at + 1) >= 0)
105
+ continue;
106
+ const [before, after] = [key.slice(0, at), key.slice(at + 1)];
107
+ if (subpath.length < key.length - 1 || !subpath.startsWith(before) || !subpath.endsWith(after))
108
+ continue;
109
+ if (!best || before.length > best.before || (before.length === best.before && key.length > best.key.length))
110
+ best = { key, before: before.length };
111
+ }
112
+ if (!best)
113
+ return undefined;
114
+ const at = best.key.indexOf("*");
115
+ star = subpath.slice(at, subpath.length - (best.key.length - at - 1));
116
+ target = map[best.key];
117
+ }
118
+ const chosen = (function pick(value) {
119
+ if (typeof value === "string" || value === null)
120
+ return value;
121
+ if (Array.isArray(value)) {
122
+ for (const one of value) {
123
+ const got = pick(one);
124
+ if (typeof got === "string")
125
+ return got;
126
+ }
127
+ return undefined;
128
+ }
129
+ if (isObject(value)) {
130
+ for (const [condition, inner] of Object.entries(value)) {
131
+ if (!REQUIRE_CONDITIONS.has(condition))
132
+ continue;
133
+ const got = pick(inner);
134
+ if (got !== undefined)
135
+ return got;
136
+ }
137
+ }
138
+ return undefined;
139
+ })(target);
140
+ if (typeof chosen !== "string" || !chosen.startsWith("./"))
141
+ return undefined;
142
+ return star === undefined ? chosen : chosen.replaceAll("*", star);
143
+ }
69
144
  /** The file at `path` inside `dir`'s package `name`, when it is that package's own file (where a link points counts). */
70
145
  function fileInPackage(dir, name, ...path) {
71
146
  const home = join(dir, "node_modules", ...name.split("/"));
@@ -331,8 +406,9 @@ export async function installSettled(entry, dir, pins, { signal, onWait, pollMs
331
406
  if (entry.lacking(dir, pins) === undefined)
332
407
  return "installed";
333
408
  const mark = await readMark(dir);
409
+ // No mark: an install that landed since the look above (its tree whole, then its mark gone) is installed, not none.
334
410
  if (mark === undefined)
335
- return "none";
411
+ return entry.lacking(dir, pins) === undefined ? "installed" : "none";
336
412
  if ("failed" in mark)
337
413
  return { failed: mark.failed };
338
414
  if (Date.now() - mark.startedAt > timeoutMs || (mark.host === host && !isAlive(mark.pid)))
@@ -356,8 +432,144 @@ export async function installSettled(entry, dir, pins, { signal, onWait, pollMs
356
432
  });
357
433
  }
358
434
  }
435
+ /** The file an installer holds while it installs into `dir`, beside the install's mark: made exclusively, so of every
436
+ * process on this data (the server, a runner beside it, one of its own) one installs at a time, and the others wait for
437
+ * that install. npm's staging directories beside `dir` are each install's own, and an install removes what an earlier one
438
+ * left there, so two at once would undo each other. */
439
+ export const installHoldOf = (dir) => `${installMarkOf(dir)}.hold`;
440
+ /** How young a hold that cannot be read is still taken as held (none is ever written part way: one left unreadable is a
441
+ * copy cut short, or a file of another's that this bound lets go of in time). */
442
+ const HOLD_WRITING_MS = 10_000;
443
+ /** How long past the install's timeout another host's hold is still taken as held: its npm's own timer starts after the
444
+ * hold is taken, then npm is given its grace to stop and to exit once killed (runNpm). A minute covers what comes
445
+ * before npm starts. */
446
+ const HOLD_STOP_MS = 60_000 + NPM_STOP_GRACE_MS + NPM_KILLED_WAIT_MS;
447
+ /** Process `pid`'s identity beyond its pid, where this system shows one (Linux's /proc): the boot it runs in and its start
448
+ * time in clock ticks since that boot. A pid reused by another process (a restarted container's, which may well be
449
+ * given the same one) never reads as the one that wrote a hold. Undefined where it can't be read (no such process, or
450
+ * no /proc). */
451
+ /** This process's pid namespace, where this system shows one (Linux's /proc/self/ns/pid: `pid:[<inode>]`): two
452
+ * containers on one data directory may share a hostname but not their pids, so a pid is asked of this process table only
453
+ * for a hold written in this namespace. Undefined where it can't be read. */
454
+ export function pidNamespace() {
455
+ try {
456
+ const ns = readlinkSync("/proc/self/ns/pid");
457
+ return /^pid:\[\d+\]$/.test(ns) ? ns : undefined;
458
+ }
459
+ catch {
460
+ return undefined;
461
+ }
462
+ }
463
+ export function processIdentity(pid) {
464
+ try {
465
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
466
+ // The fields after the command (in parentheses, which may hold spaces): the state is the 3rd field, the start the 22nd.
467
+ const start = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
468
+ const boot = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
469
+ return start && /^\d+$/.test(start) && boot ? `${boot}:${start}` : undefined;
470
+ }
471
+ catch {
472
+ return undefined;
473
+ }
474
+ }
475
+ /** The hold at `at` as written, or undefined when it cannot be read (gone, cut short, not one). */
476
+ async function readHold(at) {
477
+ try {
478
+ const held = JSON.parse(await readFile(at, "utf8"));
479
+ return held !== null && typeof held === "object" ? held : undefined;
480
+ }
481
+ catch {
482
+ return undefined;
483
+ }
484
+ }
485
+ /** Takes the hold on installs into `dir` for this process: its token when it holds it now, undefined while another
486
+ * installer does. One of this host's (and of this pid namespace, where it names one) is held while the process that wrote it lives, whatever its age (its npm may still
487
+ * be stopping): its pid alive and, where the system shows it, the same process (processIdentity), so a pid another
488
+ * process was given since never keeps it; where the identity can't be read, while its pid lives within INSTALL_TIMEOUT_MS
489
+ * and the time npm takes to stop (HOLD_STOP_MS). Another host's, whose process can't be asked, within that bound. The hold
490
+ * is written whole beside its place and linked into it, which fails when a hold is there, so no reader sees one part
491
+ * way. A hold its installer left (gone, or past that bound, or unreadable and older than HOLD_WRITING_MS) is taken over
492
+ * by one taker alone: the one that links it to a name of that very file's removes it, and only while it is still that
493
+ * file, so a hold another taker made meanwhile is never removed. */
494
+ export async function takeHold(dir, { isAlive = alive, identity = processIdentity, host = hostname(), pidns = pidNamespace(), timeoutMs = INSTALL_TIMEOUT_MS } = {}) {
495
+ const at = installHoldOf(dir);
496
+ await mkdir(dirname(at), { recursive: true });
497
+ const token = randomUUID();
498
+ const draft = `${at}.${token}`;
499
+ const own = identity(process.pid);
500
+ await writeFile(draft, JSON.stringify({ host, ...(pidns ? { pidns } : {}), pid: process.pid, ...(own ? { identity: own } : {}), startedAt: Date.now(), token }));
501
+ /** Whether a hold's pid can be asked of this process table: written on this host, in this pid namespace where both
502
+ * name one. Another namespace's (another container's on the same data, with the same hostname) is judged as another
503
+ * host's. */
504
+ const local = (held) => held.host === host && (typeof held.pidns !== "string" || pidns === undefined || held.pidns === pidns);
505
+ /** Whether a hold of this host's is still its installer's: that process alive, by its identity where both are known. */
506
+ const installing = (held) => {
507
+ if (!isAlive(held.pid))
508
+ return false;
509
+ const now = typeof held.identity === "string" ? identity(held.pid) : undefined;
510
+ return now !== undefined ? now === held.identity : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS;
511
+ };
512
+ try {
513
+ for (let tries = 0; tries < 3; tries++) {
514
+ try {
515
+ await link(draft, at);
516
+ return token;
517
+ }
518
+ catch (error) {
519
+ if (error.code !== "EEXIST")
520
+ throw error;
521
+ }
522
+ const judged = await lstat(at).catch(() => undefined);
523
+ if (!judged)
524
+ continue;
525
+ const held = await readHold(at);
526
+ const live = typeof held?.pid === "number" && typeof held.startedAt === "number"
527
+ ? local(held) ? installing(held) : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS
528
+ : Date.now() - judged.mtimeMs <= HOLD_WRITING_MS;
529
+ if (live)
530
+ return undefined;
531
+ // Left by its installer: reaped by one taker alone. The hold is never moved; a taker links it to a name of that very
532
+ // file's (its device and inode), which only one can make, and that one removes the hold, once the link shows it is
533
+ // still the hold judged left: its device, inode and token. An inode alone is not enough: once another taker removes
534
+ // the hold, a fresh hold can be given the same inode, and only its token tells it apart. The others wait. A reap a
535
+ // taker cut short left long ago is cleared for the next look.
536
+ const reap = `${at}.reap-${judged.dev}-${judged.ino}`;
537
+ try {
538
+ await link(at, reap);
539
+ }
540
+ catch (error) {
541
+ const code = error.code;
542
+ if (code === "ENOENT")
543
+ continue;
544
+ if (code !== "EEXIST")
545
+ throw error;
546
+ const since = (await lstat(reap).catch(() => undefined))?.ctimeMs;
547
+ if (since !== undefined && Date.now() - since > HOLD_WRITING_MS)
548
+ await rm(reap, { force: true });
549
+ return undefined;
550
+ }
551
+ const reaped = await lstat(reap);
552
+ const same = reaped.ino === judged.ino && reaped.dev === judged.dev && (await readHold(reap))?.token === held?.token;
553
+ if (same)
554
+ await rm(at, { force: true });
555
+ await rm(reap, { force: true });
556
+ }
557
+ return undefined;
558
+ }
559
+ finally {
560
+ await rm(draft, { force: true }).catch(() => undefined);
561
+ }
562
+ }
563
+ /** Lets go of the hold on installs into `dir` that `token` took; a hold of another's (one that took over this one past
564
+ * its bound) stays. */
565
+ export async function releaseHold(dir, token) {
566
+ const at = installHoldOf(dir);
567
+ if ((await readHold(at))?.token === token)
568
+ await rm(at, { force: true });
569
+ }
359
570
  /** The server's one installer of a harness into `dir`: `ensure()` resolves once it is installed whole, installing it first
360
- * when it is not, and every caller while an install runs waits for that one. A failed install is not kept: the next call
571
+ * when it is not, and every caller while an install runs waits for that one. While another process installs it (it holds
572
+ * installHoldOf), this one waits for that install instead of starting its own. A failed install is not kept: the next call
361
573
  * tries again. `stop()` stops an install that runs (its npm) and waits, bounded, for it to end. `onInstalled` hears of an
362
574
  * install this server made, and how long it took. */
363
575
  export class HarnessInstall {
@@ -399,33 +611,54 @@ export class HarnessInstall {
399
611
  if (this.stopping.signal.aborted)
400
612
  return Promise.reject(new Error("the server is stopping"));
401
613
  this.running ??= (async () => {
402
- // The mark a run's claim reads, in this process or a runner's own (installSettled): installing now, then gone once
403
- // it is in, or why it failed. Written first, before anything is read, so a claim made as this install starts (a run
404
- // started just after the save that started it) finds it; gone at once when the harness is installed already.
405
- await writeMark(this.dir, { host: hostname(), pid: process.pid, startedAt: Date.now() });
406
- const pins = await this.pins().catch(async (error) => {
407
- await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
408
- throw error;
409
- });
410
- if (this.entry.lacking(this.dir, pins) === undefined) {
411
- await rm(installMarkOf(this.dir), { force: true });
412
- return void (this.done = true);
614
+ // One installer at a time on this data: while another process holds the install, wait for it to settle, then look
615
+ // again (installed: done; failed while this waited on it: so is this; let go with nothing in: take the hold). A
616
+ // failure read at once, with no wait, is the last install's: its holder may be retrying it and not yet have written
617
+ // its own mark, so this looks again rather than failing in that old install's words.
618
+ let token;
619
+ while (!(token = await takeHold(this.dir))) {
620
+ if (this.stopping.signal.aborted)
621
+ throw new Error("the server is stopping");
622
+ let waited = false;
623
+ const settled = await installSettled(this.entry, this.dir, await this.pins(), { signal: this.stopping.signal, onWait: () => (waited = true) });
624
+ if (settled === "installed")
625
+ return void (this.done = true);
626
+ if (typeof settled === "object" && waited)
627
+ throw new Error(settled.failed);
628
+ await new Promise((resolve) => setTimeout(resolve, 250));
413
629
  }
414
- const started = performance.now();
415
630
  try {
416
- await this.install(this.entry, this.dir, pins, this.stopping.signal);
417
- }
418
- catch (error) {
419
- // Why it failed, for the runs that waited on it; a server that stops leaves no mark (its npm was stopped, not refused).
420
- if (this.stopping.signal.aborted)
631
+ // The mark a run's claim reads, in this process or a runner's own (installSettled): installing now, then gone once
632
+ // it is in, or why it failed. Written first, before anything is read, so a claim made as this install starts (a run
633
+ // started just after the save that started it) finds it; gone at once when the harness is installed already.
634
+ await writeMark(this.dir, { host: hostname(), pid: process.pid, startedAt: Date.now() });
635
+ const pins = await this.pins().catch(async (error) => {
421
636
  await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
422
- else
423
- await writeMark(this.dir, { failed: error.message, at: Date.now() }).catch(() => undefined);
424
- throw error;
637
+ throw error;
638
+ });
639
+ if (this.entry.lacking(this.dir, pins) === undefined) {
640
+ await rm(installMarkOf(this.dir), { force: true });
641
+ return void (this.done = true);
642
+ }
643
+ const started = performance.now();
644
+ try {
645
+ await this.install(this.entry, this.dir, pins, this.stopping.signal);
646
+ }
647
+ catch (error) {
648
+ // Why it failed, for the runs that waited on it; a server that stops leaves no mark (its npm was stopped, not refused).
649
+ if (this.stopping.signal.aborted)
650
+ await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
651
+ else
652
+ await writeMark(this.dir, { failed: error.message, at: Date.now() }).catch(() => undefined);
653
+ throw error;
654
+ }
655
+ await rm(installMarkOf(this.dir), { force: true });
656
+ this.done = true;
657
+ this.onInstalled?.(Math.round(performance.now() - started));
658
+ }
659
+ finally {
660
+ await releaseHold(this.dir, token).catch(() => undefined);
425
661
  }
426
- await rm(installMarkOf(this.dir), { force: true });
427
- this.done = true;
428
- this.onInstalled?.(Math.round(performance.now() - started));
429
662
  })().finally(() => (this.running = undefined));
430
663
  return this.running;
431
664
  }
@@ -435,3 +668,58 @@ export class HarnessInstall {
435
668
  await this.running?.catch(() => undefined);
436
669
  }
437
670
  }
671
+ /** A runner's installs, by the directory each goes into: one HarnessInstall per directory in this process, which every
672
+ * claim that needs it waits on, and how many wait now. */
673
+ const claimInstalls = new Map();
674
+ /** Where a run's claim stands on the install into `dir`, as installSettled says, except that an install this process's
675
+ * claims run (installForClaim) is never waited on from outside: it reads "none", so the claim joins it by installForClaim
676
+ * and counts among those that wait for it. Waited on from outside, it would stop once the claim that started it let go,
677
+ * though this one still needed it, and start again. An install the server runs is waited on as before. */
678
+ export function claimSettled(entry, dir, pins, options = {}) {
679
+ const isAlive = options.isAlive ?? alive;
680
+ return installSettled(entry, dir, pins, { ...options, isAlive: (pid) => !(pid === process.pid && claimInstalls.has(dir)) && isAlive(pid) });
681
+ }
682
+ /** Installs `entry` into `dir` for a run's claim when nothing installs it (no install runs, or the last one failed before
683
+ * this claim): the claim installs it itself, by `lock` (default the one AgentRun ships), or waits for the install this
684
+ * process or another runs for it already; it resolves once it is in and rejects with the install's own words when it
685
+ * fails. `signal` aborted (the run stopped, its claim lost, the runner closing): this claim stops waiting at once, and the
686
+ * install's npm is stopped once no claim waits for it. `install`: what runs the install in place of npm (a test's). */
687
+ export async function installForClaim(entry, dir, pins, { lock, signal, install } = {}) {
688
+ let held = claimInstalls.get(dir);
689
+ if (!held) {
690
+ held = { install: new HarnessInstall(entry, dir, pins, install ?? ((entry, dir, pins, stop) => npmInstall(entry, dir, pins, { signal: stop, ...(lock ? { lock } : {}) }))), waiting: 0 };
691
+ claimInstalls.set(dir, held);
692
+ }
693
+ const mine = held;
694
+ mine.waiting += 1;
695
+ try {
696
+ const installing = mine.install.ensure();
697
+ installing.catch(() => undefined);
698
+ if (!signal)
699
+ return await installing;
700
+ signal.throwIfAborted();
701
+ await new Promise((resolve, reject) => {
702
+ const stop = () => reject(signal.reason);
703
+ signal.addEventListener("abort", stop, { once: true });
704
+ installing.then(resolve, reject).finally(() => signal.removeEventListener("abort", stop));
705
+ });
706
+ }
707
+ finally {
708
+ mine.waiting -= 1;
709
+ if (mine.waiting === 0 && claimInstalls.get(dir) === mine) {
710
+ claimInstalls.delete(dir);
711
+ // Nothing waits for it any more: its npm stops (nothing to stop once it is in or has failed). The claim goes on at
712
+ // once; the stop is kept until it ends, for the runner's close to wait on (claimInstallsStopped).
713
+ const stopping = mine.install.stop();
714
+ claimStops.add(stopping);
715
+ void stopping.finally(() => claimStops.delete(stopping));
716
+ }
717
+ }
718
+ }
719
+ /** The stops of the claims' installs under way (installForClaim). */
720
+ const claimStops = new Set();
721
+ /** Resolves once every install a claim let go of has stopped (its npm ended, SIGTERM then SIGKILL past its grace, its
722
+ * staging directory and hold gone): a runner's close waits for it before the process can end, so no npm outlives it. */
723
+ export async function claimInstallsStopped() {
724
+ await Promise.all([...claimStops]);
725
+ }
package/dist/harness.js CHANGED
@@ -1,4 +1,4 @@
1
- // The harness that runs a revision: pi (pi-durable-disk's, the default and the one a revision that names none gets) or
1
+ // The harness that runs a revision: pi (the default and the one a revision that names none gets) or
2
2
  // one of the run adapters. A revision keeps the harness it names; the default is never stored, so a revision written
3
3
  // before this field existed and one that names pi are the same revision. Which harnesses this server runs is said in
4
4
  // capabilities, and a revision naming one it does not run saves with a warning and is refused at run time.
@@ -18,14 +18,14 @@ export type ToolResults = Map<string, {
18
18
  * nested-tool members) belongs to the tool task pi runs a tool in, which a host tool, called by another harness, has
19
19
  * none of: the full type cannot be built here, so a read of any other member throws, naming it, rather than reading as
20
20
  * "is not a function". `conversationId` is the run's root conversation, where a host tool's calls are made: serve's
21
- * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot`, `conversation`
22
- * and `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
- * document, a conversation or a task of this run, never another's. A remote executor (workspace/executors.ts
24
- * piExecutor) has no run Harness and gives none of these four (RUN_ONLY_MEMBERS); the coding tools it runs read none.
21
+ * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot` and
22
+ * `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
+ * document or a task of this run, never another's. A remote executor (workspace/executors.ts
24
+ * piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
25
25
  * `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here. */
26
- export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
26
+ export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
27
27
  /** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
28
- export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "conversation", "waitForTask"];
28
+ export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "waitForTask"];
29
29
  /** What one host tool's call reads of the run: the run's environment (its file environment, the api's `env`), its
30
30
  * harness's commit and its root agent (a paid call's booking and pi's read), the context and the results map, and the
31
31
  * paid-call money seam, over the runner's claim Harness (runner/adapter-run-spec.ts). */
@@ -36,10 +36,9 @@ export interface HostToolCtx {
36
36
  env(): Promise<ToolExecutionApi["env"]>;
37
37
  readonly commit: ToolExecutionApi["commit"];
38
38
  readonly agent: ToolExecutionApi["agent"];
39
- /** The run's own Harness's snapshot, conversation and waitForTask (run.harness, the claim's journal on the runner), as
40
- * `commit` is: a document, conversation or task of this run only. */
39
+ /** The run's own Harness's snapshot and waitForTask (run.harness, the claim's journal on the runner), as
40
+ * `commit` is: a document or task of this run only. */
41
41
  readonly snapshot: ToolExecutionApi["snapshot"];
42
- readonly conversation: ToolExecutionApi["conversation"];
43
42
  readonly waitForTask: ToolExecutionApi["waitForTask"];
44
43
  /** A gate for a tool that cannot be run on the runner yet: undefined to run the call, else the refusal that is its answer,
45
44
  * so the tool is listed but never run as a stub. No tool sets it now (learned_workflow runs for real on every session's
@@ -18,14 +18,14 @@ export { cutUtf8, MAX_BYTES, MAX_LINES } from "./workspace/executors.js";
18
18
  * nested-tool members) belongs to the tool task pi runs a tool in, which a host tool, called by another harness, has
19
19
  * none of: the full type cannot be built here, so a read of any other member throws, naming it, rather than reading as
20
20
  * "is not a function". `conversationId` is the run's root conversation, where a host tool's calls are made: serve's
21
- * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot`, `conversation`
22
- * and `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
- * document, a conversation or a task of this run, never another's. A remote executor (workspace/executors.ts
24
- * piExecutor) has no run Harness and gives none of these four (RUN_ONLY_MEMBERS); the coding tools it runs read none.
21
+ * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot` and
22
+ * `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
+ * document or a task of this run, never another's. A remote executor (workspace/executors.ts
24
+ * piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
25
25
  * `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here. */
26
- export const HOST_API_MEMBERS = ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
26
+ export const HOST_API_MEMBERS = ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
27
27
  /** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
28
- export const RUN_ONLY_MEMBERS = ["conversationId", "snapshot", "conversation", "waitForTask"];
28
+ export const RUN_ONLY_MEMBERS = ["conversationId", "snapshot", "waitForTask"];
29
29
  const hostApi = (given) => new Proxy(given, {
30
30
  get: (target, key) => {
31
31
  if (typeof key === "symbol" || key === "then" || Object.hasOwn(target, key))
@@ -68,7 +68,7 @@ export function hostToolOf(name, tool, ctx) {
68
68
  agent: ctx.agent,
69
69
  models: createModels(),
70
70
  conversationId: ROOT_CONVERSATION_ID,
71
- snapshot: ctx.snapshot, conversation: ctx.conversation, waitForTask: ctx.waitForTask,
71
+ snapshot: ctx.snapshot, waitForTask: ctx.waitForTask,
72
72
  });
73
73
  // A tool that throws (bash on a non-zero exit or a timeout) still answers with its output, as pi's harness does;
74
74
  // monid's answer a failure as an error result, which is kept as it is.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,4 @@ export { serveWithRunner } from "./runner/beside.js";
3
3
  export { SERVER_LOCK, type ServerLock, ServerLockHeldError, takeServerLock } from "./server-lock.js";
4
4
  export { ApiError, ERROR_STATUS, type ErrorCode } from "./errors.js";
5
5
  export { defaultMaxRuns, type Health } from "./host.js";
6
- export { banner, type TokenSource } from "./print.js";
7
- export { ASK_TOOL, BOUND_TOOLS, TOOLS, type ToolEntry } from "./tools.js";
8
- export type { FauxHelpers } from "./model.js";
6
+ export { BOUND_TOOLS, TOOLS } from "./tools.js";
package/dist/index.js CHANGED
@@ -3,5 +3,4 @@ export { serveWithRunner } from "./runner/beside.js";
3
3
  export { SERVER_LOCK, ServerLockHeldError, takeServerLock } from "./server-lock.js";
4
4
  export { ApiError, ERROR_STATUS } from "./errors.js";
5
5
  export { defaultMaxRuns } from "./host.js";
6
- export { banner } from "./print.js";
7
- export { ASK_TOOL, BOUND_TOOLS, TOOLS } from "./tools.js";
6
+ export { BOUND_TOOLS, TOOLS } from "./tools.js";
@@ -34,7 +34,7 @@ export declare function redactedAnswer(text: string, secrets: readonly string[])
34
34
  * included (a dictionary field can be keyed by anything a run wrote), its shape kept. Two names of one object that come
35
35
  * out the same would merge one value over the other: that object is withheld whole, as "[redacted]". */
36
36
  export declare function redactedOutput(value: unknown, secrets: readonly string[]): unknown;
37
- /** What a thinking or text block may show while it streams (pi-durable-agent's `redactLive`): what has streamed so far,
37
+ /** What a thinking or text block may show while it streams: what has streamed so far,
38
38
  * redacted by the same rule as redacted(), less a fixed tail held back until the block ends, when its settled row
39
39
  * replaces this one whole. A key whose head has streamed but not its tail cannot be found by any redactor, and a key
40
40
  * ending inside the tail would show its head. So the tail is the most a held value takes in its widest form (6 times it,
@@ -44,7 +44,7 @@ function detailOf(rest) {
44
44
  return (text.split(/(?<=[.!?])\s/)[0] ?? "").slice(0, 200).replace(/[.\s]+$/, "");
45
45
  }
46
46
  /** The most of a run's error or a tool's output serve ever shows: a Timeline row's text, cut at 2000 characters
47
- * (pi-durable-agent's CAPS.text; a summary and a tool result's preview at 500), which the error box reads too. */
47
+ * (`CAPS.text` in timeline/; a summary and a tool result's preview at 500), which the error box reads too. */
48
48
  const SHOWN = 2000;
49
49
  /** `text`, a run's error as serve shows it, with no held secret in it: the one rule learning's checker uses
50
50
  * (learn/secrets.ts redactSecrets: each value as written, JSON-escaped, base64 at each offset, hex and percent-encoded,
@@ -128,7 +128,7 @@ export function redactedOutput(value, secrets) {
128
128
  }
129
129
  return value;
130
130
  }
131
- /** What a thinking or text block may show while it streams (pi-durable-agent's `redactLive`): what has streamed so far,
131
+ /** What a thinking or text block may show while it streams: what has streamed so far,
132
132
  * redacted by the same rule as redacted(), less a fixed tail held back until the block ends, when its settled row
133
133
  * replaces this one whole. A key whose head has streamed but not its tail cannot be found by any redactor, and a key
134
134
  * ending inside the tail would show its head. So the tail is the most a held value takes in its widest form (6 times it,
@@ -24,7 +24,7 @@ export declare const CAPS: Readonly<{
24
24
  workflows: 1;
25
25
  }>;
26
26
  /** The rule a problem breaks. SPEC.md lists each. */
27
- export type Rule = "too_many_files" | "outside" | "file_name" | "file_mode" | "encoding" | "edited" | "deleted" | "exists" | "too_large" | "too_many_notes" | "invisible_unicode" | "secret_shape" | "secret_value" | "note" | "status" | "supersedes" | "index_full" | "skill" | "skill_outcome" | "too_many_skills" | "workflow" | "too_many_workflows" | "no_tool_list" | "executable_node" | "skill_front_matter" | "skill_status";
27
+ export type Rule = "too_many_files" | "outside" | "file_name" | "file_mode" | "encoding" | "edited" | "deleted" | "exists" | "too_large" | "too_many_notes" | "invisible_unicode" | "secret_shape" | "secret_value" | "note" | "status" | "supersedes" | "index_full" | "skill" | "skill_outcome" | "too_many_skills" | "workflow" | "too_many_workflows" | "no_tool_list" | "executable_node" | "skill_front_matter" | "skill_status" | "duplicate";
28
28
  /** One problem with what a run proposed, printable as it is. */
29
29
  export type Problem = {
30
30
  readonly rule: Rule;
@@ -43,9 +43,12 @@ export type Change = {
43
43
  };
44
44
  /** The folder a proposal is checked against (the run's seed, or main at merge time): every path it holds, and its active
45
45
  * notes. */
46
+ /** What a proposal is checked against: every path at the seed's top, its active notes, and `rules`, when the caller read
47
+ * the active notes' texts, each one's rule (notes.ts ruleOf) to its file: a new note of the same rule is a duplicate. */
46
48
  export type Base = {
47
49
  readonly files: Iterable<string>;
48
50
  readonly active: readonly LearnedNote[];
51
+ readonly rules?: ReadonlyMap<string, string>;
49
52
  };
50
53
  /** A new note that passed, with its whole text. */
51
54
  export type ProposedNote = LearnedNote & {
@@ -69,6 +72,9 @@ export type CheckInput = {
69
72
  readonly ask?: DraftAsk;
70
73
  /** Where each of `gated`'s denies was set (this agent's settings or this server's), for the refusal's words. */
71
74
  readonly deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
75
+ /** False for a run of a revision that says `learning: "notes"`: a workflow draft it gives is left out (rule `workflow`,
76
+ * NOTES_ONLY), and its notes and skill go on. */
77
+ readonly workflows?: false;
72
78
  /** The workflow DSL a draft is read with; a proposal that holds a draft is checked with it, never without. */
73
79
  readonly dsl?: DraftReader;
74
80
  /** Each draft's dry run (skills.ts draftDryRun), by its workflow.json's path: one that failed is refused, rule