@cluesmith/codev 3.2.4 → 3.3.1

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 (394) hide show
  1. package/dashboard-dist/assets/index-BZRTEMtH.css +32 -0
  2. package/dashboard-dist/assets/{index-BZ1x7x1X.js → index-D3XaKpZW.js} +46 -44
  3. package/dashboard-dist/assets/index-D3XaKpZW.js.map +1 -0
  4. package/dashboard-dist/index.html +2 -2
  5. package/dist/agent-farm/cli.d.ts.map +1 -1
  6. package/dist/agent-farm/cli.js +154 -0
  7. package/dist/agent-farm/cli.js.map +1 -1
  8. package/dist/agent-farm/commands/cleanup.d.ts.map +1 -1
  9. package/dist/agent-farm/commands/cleanup.js +16 -0
  10. package/dist/agent-farm/commands/cleanup.js.map +1 -1
  11. package/dist/agent-farm/commands/inbox.d.ts +42 -0
  12. package/dist/agent-farm/commands/inbox.d.ts.map +1 -0
  13. package/dist/agent-farm/commands/inbox.js +129 -0
  14. package/dist/agent-farm/commands/inbox.js.map +1 -0
  15. package/dist/agent-farm/commands/interrupt.d.ts +20 -0
  16. package/dist/agent-farm/commands/interrupt.d.ts.map +1 -0
  17. package/dist/agent-farm/commands/interrupt.js +65 -0
  18. package/dist/agent-farm/commands/interrupt.js.map +1 -0
  19. package/dist/agent-farm/commands/reset/constants.d.ts +52 -0
  20. package/dist/agent-farm/commands/reset/constants.d.ts.map +1 -0
  21. package/dist/agent-farm/commands/reset/constants.js +52 -0
  22. package/dist/agent-farm/commands/reset/constants.js.map +1 -0
  23. package/dist/agent-farm/commands/reset/context.d.ts +230 -0
  24. package/dist/agent-farm/commands/reset/context.d.ts.map +1 -0
  25. package/dist/agent-farm/commands/reset/context.js +428 -0
  26. package/dist/agent-farm/commands/reset/context.js.map +1 -0
  27. package/dist/agent-farm/commands/reset/index.d.ts +192 -0
  28. package/dist/agent-farm/commands/reset/index.d.ts.map +1 -0
  29. package/dist/agent-farm/commands/reset/index.js +488 -0
  30. package/dist/agent-farm/commands/reset/index.js.map +1 -0
  31. package/dist/agent-farm/commands/reset/receipt.d.ts +97 -0
  32. package/dist/agent-farm/commands/reset/receipt.d.ts.map +1 -0
  33. package/dist/agent-farm/commands/reset/receipt.js +149 -0
  34. package/dist/agent-farm/commands/reset/receipt.js.map +1 -0
  35. package/dist/agent-farm/commands/reset/reorient.d.ts +117 -0
  36. package/dist/agent-farm/commands/reset/reorient.d.ts.map +1 -0
  37. package/dist/agent-farm/commands/reset/reorient.js +313 -0
  38. package/dist/agent-farm/commands/reset/reorient.js.map +1 -0
  39. package/dist/agent-farm/commands/reset.d.ts +34 -0
  40. package/dist/agent-farm/commands/reset.d.ts.map +1 -0
  41. package/dist/agent-farm/commands/reset.js +309 -0
  42. package/dist/agent-farm/commands/reset.js.map +1 -0
  43. package/dist/agent-farm/commands/send.d.ts.map +1 -1
  44. package/dist/agent-farm/commands/send.js +49 -8
  45. package/dist/agent-farm/commands/send.js.map +1 -1
  46. package/dist/agent-farm/commands/spawn-worktree.d.ts +105 -6
  47. package/dist/agent-farm/commands/spawn-worktree.d.ts.map +1 -1
  48. package/dist/agent-farm/commands/spawn-worktree.js +289 -66
  49. package/dist/agent-farm/commands/spawn-worktree.js.map +1 -1
  50. package/dist/agent-farm/commands/spawn.d.ts.map +1 -1
  51. package/dist/agent-farm/commands/spawn.js +13 -1
  52. package/dist/agent-farm/commands/spawn.js.map +1 -1
  53. package/dist/agent-farm/commands/status.d.ts.map +1 -1
  54. package/dist/agent-farm/commands/status.js +80 -8
  55. package/dist/agent-farm/commands/status.js.map +1 -1
  56. package/dist/agent-farm/commands/tower.d.ts.map +1 -1
  57. package/dist/agent-farm/commands/tower.js +13 -0
  58. package/dist/agent-farm/commands/tower.js.map +1 -1
  59. package/dist/agent-farm/db/index.d.ts +1 -1
  60. package/dist/agent-farm/db/index.d.ts.map +1 -1
  61. package/dist/agent-farm/db/index.js +80 -1
  62. package/dist/agent-farm/db/index.js.map +1 -1
  63. package/dist/agent-farm/db/mailbox.d.ts +222 -0
  64. package/dist/agent-farm/db/mailbox.d.ts.map +1 -0
  65. package/dist/agent-farm/db/mailbox.js +304 -0
  66. package/dist/agent-farm/db/mailbox.js.map +1 -0
  67. package/dist/agent-farm/db/schema.d.ts +1 -1
  68. package/dist/agent-farm/db/schema.d.ts.map +1 -1
  69. package/dist/agent-farm/db/schema.js +35 -0
  70. package/dist/agent-farm/db/schema.js.map +1 -1
  71. package/dist/agent-farm/db/types.d.ts +45 -0
  72. package/dist/agent-farm/db/types.d.ts.map +1 -1
  73. package/dist/agent-farm/db/types.js.map +1 -1
  74. package/dist/agent-farm/lib/builder-lookup.d.ts +1 -1
  75. package/dist/agent-farm/lib/builder-lookup.js +2 -2
  76. package/dist/agent-farm/lib/builder-lookup.js.map +1 -1
  77. package/dist/agent-farm/lib/reconnect-backoff.d.ts +64 -0
  78. package/dist/agent-farm/lib/reconnect-backoff.d.ts.map +1 -0
  79. package/dist/agent-farm/lib/reconnect-backoff.js +57 -0
  80. package/dist/agent-farm/lib/reconnect-backoff.js.map +1 -0
  81. package/dist/agent-farm/lib/tower-client.d.ts +16 -6
  82. package/dist/agent-farm/lib/tower-client.d.ts.map +1 -1
  83. package/dist/agent-farm/lib/tower-client.js +37 -6
  84. package/dist/agent-farm/lib/tower-client.js.map +1 -1
  85. package/dist/agent-farm/lib/tunnel-client.d.ts +69 -1
  86. package/dist/agent-farm/lib/tunnel-client.d.ts.map +1 -1
  87. package/dist/agent-farm/lib/tunnel-client.js +225 -30
  88. package/dist/agent-farm/lib/tunnel-client.js.map +1 -1
  89. package/dist/agent-farm/servers/canvas-relay.d.ts +60 -0
  90. package/dist/agent-farm/servers/canvas-relay.d.ts.map +1 -0
  91. package/dist/agent-farm/servers/canvas-relay.js +376 -0
  92. package/dist/agent-farm/servers/canvas-relay.js.map +1 -0
  93. package/dist/agent-farm/servers/cron-delivery.d.ts +72 -0
  94. package/dist/agent-farm/servers/cron-delivery.d.ts.map +1 -0
  95. package/dist/agent-farm/servers/cron-delivery.js +80 -0
  96. package/dist/agent-farm/servers/cron-delivery.js.map +1 -0
  97. package/dist/agent-farm/servers/delayed-send.d.ts +85 -0
  98. package/dist/agent-farm/servers/delayed-send.d.ts.map +1 -0
  99. package/dist/agent-farm/servers/delayed-send.js +165 -0
  100. package/dist/agent-farm/servers/delayed-send.js.map +1 -0
  101. package/dist/agent-farm/servers/gate-profiles.d.ts +67 -0
  102. package/dist/agent-farm/servers/gate-profiles.d.ts.map +1 -0
  103. package/dist/agent-farm/servers/gate-profiles.js +113 -0
  104. package/dist/agent-farm/servers/gate-profiles.js.map +1 -0
  105. package/dist/agent-farm/servers/mailbox-delivery.d.ts +370 -0
  106. package/dist/agent-farm/servers/mailbox-delivery.d.ts.map +1 -0
  107. package/dist/agent-farm/servers/mailbox-delivery.js +617 -0
  108. package/dist/agent-farm/servers/mailbox-delivery.js.map +1 -0
  109. package/dist/agent-farm/servers/mailbox-wiring.d.ts +125 -0
  110. package/dist/agent-farm/servers/mailbox-wiring.d.ts.map +1 -0
  111. package/dist/agent-farm/servers/mailbox-wiring.js +425 -0
  112. package/dist/agent-farm/servers/mailbox-wiring.js.map +1 -0
  113. package/dist/agent-farm/servers/message-write.d.ts +53 -1
  114. package/dist/agent-farm/servers/message-write.d.ts.map +1 -1
  115. package/dist/agent-farm/servers/message-write.js +63 -0
  116. package/dist/agent-farm/servers/message-write.js.map +1 -1
  117. package/dist/agent-farm/servers/overview.d.ts +19 -0
  118. package/dist/agent-farm/servers/overview.d.ts.map +1 -1
  119. package/dist/agent-farm/servers/overview.js +100 -4
  120. package/dist/agent-farm/servers/overview.js.map +1 -1
  121. package/dist/agent-farm/servers/render-gate.d.ts +141 -0
  122. package/dist/agent-farm/servers/render-gate.d.ts.map +1 -0
  123. package/dist/agent-farm/servers/render-gate.js +251 -0
  124. package/dist/agent-farm/servers/render-gate.js.map +1 -0
  125. package/dist/agent-farm/servers/session-submit.d.ts +90 -0
  126. package/dist/agent-farm/servers/session-submit.d.ts.map +1 -0
  127. package/dist/agent-farm/servers/session-submit.js +127 -0
  128. package/dist/agent-farm/servers/session-submit.js.map +1 -0
  129. package/dist/agent-farm/servers/tower-cron.d.ts +10 -7
  130. package/dist/agent-farm/servers/tower-cron.d.ts.map +1 -1
  131. package/dist/agent-farm/servers/tower-cron.js +58 -53
  132. package/dist/agent-farm/servers/tower-cron.js.map +1 -1
  133. package/dist/agent-farm/servers/tower-instances.d.ts +14 -2
  134. package/dist/agent-farm/servers/tower-instances.d.ts.map +1 -1
  135. package/dist/agent-farm/servers/tower-instances.js +78 -16
  136. package/dist/agent-farm/servers/tower-instances.js.map +1 -1
  137. package/dist/agent-farm/servers/tower-messages.d.ts +38 -1
  138. package/dist/agent-farm/servers/tower-messages.d.ts.map +1 -1
  139. package/dist/agent-farm/servers/tower-messages.js +106 -1
  140. package/dist/agent-farm/servers/tower-messages.js.map +1 -1
  141. package/dist/agent-farm/servers/tower-routes.d.ts +16 -4
  142. package/dist/agent-farm/servers/tower-routes.d.ts.map +1 -1
  143. package/dist/agent-farm/servers/tower-routes.js +826 -145
  144. package/dist/agent-farm/servers/tower-routes.js.map +1 -1
  145. package/dist/agent-farm/servers/tower-server.js +188 -34
  146. package/dist/agent-farm/servers/tower-server.js.map +1 -1
  147. package/dist/agent-farm/servers/tower-terminals.d.ts +23 -2
  148. package/dist/agent-farm/servers/tower-terminals.d.ts.map +1 -1
  149. package/dist/agent-farm/servers/tower-terminals.js +134 -127
  150. package/dist/agent-farm/servers/tower-terminals.js.map +1 -1
  151. package/dist/agent-farm/servers/tower-tunnel.d.ts.map +1 -1
  152. package/dist/agent-farm/servers/tower-tunnel.js +63 -4
  153. package/dist/agent-farm/servers/tower-tunnel.js.map +1 -1
  154. package/dist/agent-farm/servers/tower-types.d.ts +2 -1
  155. package/dist/agent-farm/servers/tower-types.d.ts.map +1 -1
  156. package/dist/agent-farm/servers/tower-utils.d.ts +64 -1
  157. package/dist/agent-farm/servers/tower-utils.d.ts.map +1 -1
  158. package/dist/agent-farm/servers/tower-utils.js +168 -1
  159. package/dist/agent-farm/servers/tower-utils.js.map +1 -1
  160. package/dist/agent-farm/servers/tower-websocket.d.ts +6 -1
  161. package/dist/agent-farm/servers/tower-websocket.d.ts.map +1 -1
  162. package/dist/agent-farm/servers/tower-websocket.js +95 -57
  163. package/dist/agent-farm/servers/tower-websocket.js.map +1 -1
  164. package/dist/agent-farm/servers/write-queue.d.ts +35 -0
  165. package/dist/agent-farm/servers/write-queue.d.ts.map +1 -0
  166. package/dist/agent-farm/servers/write-queue.js +56 -0
  167. package/dist/agent-farm/servers/write-queue.js.map +1 -0
  168. package/dist/agent-farm/types.d.ts +39 -0
  169. package/dist/agent-farm/types.d.ts.map +1 -1
  170. package/dist/agent-farm/utils/agent-names.d.ts +2 -2
  171. package/dist/agent-farm/utils/agent-names.d.ts.map +1 -1
  172. package/dist/agent-farm/utils/agent-names.js +3 -3
  173. package/dist/agent-farm/utils/agent-names.js.map +1 -1
  174. package/dist/agent-farm/utils/architect-name.d.ts +2 -2
  175. package/dist/agent-farm/utils/architect-name.d.ts.map +1 -1
  176. package/dist/agent-farm/utils/architect-name.js +3 -3
  177. package/dist/agent-farm/utils/architect-name.js.map +1 -1
  178. package/dist/agent-farm/utils/config.d.ts +13 -0
  179. package/dist/agent-farm/utils/config.d.ts.map +1 -1
  180. package/dist/agent-farm/utils/config.js +33 -1
  181. package/dist/agent-farm/utils/config.js.map +1 -1
  182. package/dist/agent-farm/utils/harness.d.ts +103 -7
  183. package/dist/agent-farm/utils/harness.d.ts.map +1 -1
  184. package/dist/agent-farm/utils/harness.js +126 -19
  185. package/dist/agent-farm/utils/harness.js.map +1 -1
  186. package/dist/agent-farm/utils/message-format.d.ts +8 -0
  187. package/dist/agent-farm/utils/message-format.d.ts.map +1 -1
  188. package/dist/agent-farm/utils/message-format.js +20 -0
  189. package/dist/agent-farm/utils/message-format.js.map +1 -1
  190. package/dist/agent-farm/utils/server-utils.d.ts +80 -4
  191. package/dist/agent-farm/utils/server-utils.d.ts.map +1 -1
  192. package/dist/agent-farm/utils/server-utils.js +286 -5
  193. package/dist/agent-farm/utils/server-utils.js.map +1 -1
  194. package/dist/cli.d.ts.map +1 -1
  195. package/dist/cli.js +6 -32
  196. package/dist/cli.js.map +1 -1
  197. package/dist/commands/consult/cli-options.d.ts +34 -0
  198. package/dist/commands/consult/cli-options.d.ts.map +1 -0
  199. package/dist/commands/consult/cli-options.js +67 -0
  200. package/dist/commands/consult/cli-options.js.map +1 -0
  201. package/dist/commands/consult/index.d.ts +56 -2
  202. package/dist/commands/consult/index.d.ts.map +1 -1
  203. package/dist/commands/consult/index.js +272 -28
  204. package/dist/commands/consult/index.js.map +1 -1
  205. package/dist/commands/consult/metrics.d.ts +42 -0
  206. package/dist/commands/consult/metrics.d.ts.map +1 -1
  207. package/dist/commands/consult/metrics.js +129 -9
  208. package/dist/commands/consult/metrics.js.map +1 -1
  209. package/dist/commands/doctor.d.ts.map +1 -1
  210. package/dist/commands/doctor.js +71 -19
  211. package/dist/commands/doctor.js.map +1 -1
  212. package/dist/commands/porch/checks.d.ts +23 -0
  213. package/dist/commands/porch/checks.d.ts.map +1 -1
  214. package/dist/commands/porch/checks.js +60 -0
  215. package/dist/commands/porch/checks.js.map +1 -1
  216. package/dist/commands/porch/config.d.ts +20 -0
  217. package/dist/commands/porch/config.d.ts.map +1 -1
  218. package/dist/commands/porch/config.js +20 -0
  219. package/dist/commands/porch/config.js.map +1 -1
  220. package/dist/commands/porch/index.js +21 -28
  221. package/dist/commands/porch/index.js.map +1 -1
  222. package/dist/commands/porch/next.d.ts.map +1 -1
  223. package/dist/commands/porch/next.js +2 -41
  224. package/dist/commands/porch/next.js.map +1 -1
  225. package/dist/lib/config.d.ts +69 -3
  226. package/dist/lib/config.d.ts.map +1 -1
  227. package/dist/lib/config.js +67 -3
  228. package/dist/lib/config.js.map +1 -1
  229. package/dist/lib/consult-lanes.d.ts +149 -0
  230. package/dist/lib/consult-lanes.d.ts.map +1 -0
  231. package/dist/lib/consult-lanes.js +360 -0
  232. package/dist/lib/consult-lanes.js.map +1 -0
  233. package/dist/lib/forge-contracts.d.ts +9 -0
  234. package/dist/lib/forge-contracts.d.ts.map +1 -1
  235. package/dist/lib/forge-contracts.js.map +1 -1
  236. package/dist/lib/github.d.ts +15 -1
  237. package/dist/lib/github.d.ts.map +1 -1
  238. package/dist/lib/github.js +18 -1
  239. package/dist/lib/github.js.map +1 -1
  240. package/dist/lib/prompt-behavior-metrics.d.ts +67 -0
  241. package/dist/lib/prompt-behavior-metrics.d.ts.map +1 -0
  242. package/dist/lib/prompt-behavior-metrics.js +290 -0
  243. package/dist/lib/prompt-behavior-metrics.js.map +1 -0
  244. package/dist/lib/skeleton.d.ts +22 -1
  245. package/dist/lib/skeleton.d.ts.map +1 -1
  246. package/dist/lib/skeleton.js +120 -0
  247. package/dist/lib/skeleton.js.map +1 -1
  248. package/dist/lib/test-env.d.ts +74 -0
  249. package/dist/lib/test-env.d.ts.map +1 -0
  250. package/dist/lib/test-env.js +92 -0
  251. package/dist/lib/test-env.js.map +1 -0
  252. package/dist/terminal/attach-replay.d.ts +39 -0
  253. package/dist/terminal/attach-replay.d.ts.map +1 -0
  254. package/dist/terminal/attach-replay.js +76 -0
  255. package/dist/terminal/attach-replay.js.map +1 -0
  256. package/dist/terminal/pty-manager.d.ts +2 -0
  257. package/dist/terminal/pty-manager.d.ts.map +1 -1
  258. package/dist/terminal/pty-manager.js +51 -23
  259. package/dist/terminal/pty-manager.js.map +1 -1
  260. package/dist/terminal/pty-session.d.ts +201 -1
  261. package/dist/terminal/pty-session.d.ts.map +1 -1
  262. package/dist/terminal/pty-session.js +327 -46
  263. package/dist/terminal/pty-session.js.map +1 -1
  264. package/dist/terminal/ring-buffer.d.ts +39 -6
  265. package/dist/terminal/ring-buffer.d.ts.map +1 -1
  266. package/dist/terminal/ring-buffer.js +74 -6
  267. package/dist/terminal/ring-buffer.js.map +1 -1
  268. package/dist/terminal/session-manager.d.ts +53 -0
  269. package/dist/terminal/session-manager.d.ts.map +1 -1
  270. package/dist/terminal/session-manager.js +94 -9
  271. package/dist/terminal/session-manager.js.map +1 -1
  272. package/dist/terminal/session-screen.d.ts +116 -0
  273. package/dist/terminal/session-screen.d.ts.map +1 -0
  274. package/dist/terminal/session-screen.js +180 -0
  275. package/dist/terminal/session-screen.js.map +1 -0
  276. package/dist/terminal/shellper-main.js +2 -1
  277. package/dist/terminal/shellper-main.js.map +1 -1
  278. package/dist/terminal/shellper-process.d.ts +1 -1
  279. package/dist/terminal/shellper-process.d.ts.map +1 -1
  280. package/dist/terminal/shellper-process.js +17 -8
  281. package/dist/terminal/shellper-process.js.map +1 -1
  282. package/dist/terminal/shellper-replay-buffer.d.ts +69 -7
  283. package/dist/terminal/shellper-replay-buffer.d.ts.map +1 -1
  284. package/dist/terminal/shellper-replay-buffer.js +167 -31
  285. package/dist/terminal/shellper-replay-buffer.js.map +1 -1
  286. package/package.json +13 -8
  287. package/scripts/forge/gitea/pr-view.sh +4 -1
  288. package/scripts/forge/github/pr-view.sh +1 -1
  289. package/scripts/forge/gitlab/pr-view.sh +4 -1
  290. package/skeleton/.claude/skills/afx/SKILL.md +68 -1
  291. package/skeleton/.claude/skills/arch-init/SKILL.md +22 -9
  292. package/skeleton/.claude/skills/arch-save/SKILL.md +183 -0
  293. package/skeleton/.claude/skills/codev/SKILL.md +31 -0
  294. package/skeleton/.claude/skills/runnable-worktrees/SKILL.md +119 -0
  295. package/skeleton/.codex/skills/afx/SKILL.md +68 -1
  296. package/skeleton/.codex/skills/arch-init/SKILL.md +22 -9
  297. package/skeleton/.codex/skills/arch-save/SKILL.md +183 -0
  298. package/skeleton/.codex/skills/codev/SKILL.md +31 -0
  299. package/skeleton/.codex/skills/runnable-worktrees/SKILL.md +119 -0
  300. package/skeleton/protocols/air/builder-prompt.md +28 -47
  301. package/skeleton/protocols/air/consult-types/impl-review.md +17 -34
  302. package/skeleton/protocols/air/consult-types/pr-review.md +14 -37
  303. package/skeleton/protocols/air/prompts/implement.md +20 -73
  304. package/skeleton/protocols/air/prompts/pr.md +22 -54
  305. package/skeleton/protocols/air/protocol.md +40 -71
  306. package/skeleton/protocols/aspir/builder-prompt.md +29 -66
  307. package/skeleton/protocols/aspir/consult-types/impl-review.md +17 -44
  308. package/skeleton/protocols/aspir/consult-types/phase-review.md +17 -44
  309. package/skeleton/protocols/aspir/consult-types/plan-review.md +14 -38
  310. package/skeleton/protocols/aspir/consult-types/pr-review.md +13 -39
  311. package/skeleton/protocols/aspir/consult-types/spec-review.md +13 -33
  312. package/skeleton/protocols/aspir/prompts/implement.md +27 -196
  313. package/skeleton/protocols/aspir/prompts/plan.md +21 -85
  314. package/skeleton/protocols/aspir/prompts/review.md +29 -228
  315. package/skeleton/protocols/aspir/prompts/specify.md +25 -111
  316. package/skeleton/protocols/aspir/protocol.json +10 -0
  317. package/skeleton/protocols/aspir/protocol.md +36 -82
  318. package/skeleton/protocols/bugfix/builder-prompt.md +23 -45
  319. package/skeleton/protocols/bugfix/consult-types/impl-review.md +21 -45
  320. package/skeleton/protocols/bugfix/consult-types/pr-review.md +18 -52
  321. package/skeleton/protocols/bugfix/prompts/fix.md +16 -61
  322. package/skeleton/protocols/bugfix/prompts/investigate.md +18 -62
  323. package/skeleton/protocols/bugfix/prompts/pr.md +22 -57
  324. package/skeleton/protocols/bugfix/protocol.md +44 -50
  325. package/skeleton/protocols/experiment/builder-prompt.md +25 -58
  326. package/skeleton/protocols/experiment/protocol.md +22 -188
  327. package/skeleton/protocols/experiment/templates/notes.md +11 -71
  328. package/skeleton/protocols/maintain/builder-prompt.md +24 -45
  329. package/skeleton/protocols/maintain/consult-types/impl-review.md +17 -44
  330. package/skeleton/protocols/maintain/consult-types/pr-review.md +13 -39
  331. package/skeleton/protocols/maintain/prompts/maintain.md +1 -1
  332. package/skeleton/protocols/maintain/protocol.md +32 -266
  333. package/skeleton/protocols/maintain/templates/maintenance-run.md +11 -0
  334. package/skeleton/protocols/pir/builder-prompt.md +31 -64
  335. package/skeleton/protocols/pir/consult-types/impl-review.md +17 -50
  336. package/skeleton/protocols/pir/consult-types/pr-review.md +11 -40
  337. package/skeleton/protocols/pir/prompts/implement.md +2 -3
  338. package/skeleton/protocols/pir/prompts/plan.md +1 -4
  339. package/skeleton/protocols/pir/prompts/review.md +2 -2
  340. package/skeleton/protocols/pir/protocol.md +54 -177
  341. package/skeleton/protocols/research/builder-prompt.md +27 -58
  342. package/skeleton/protocols/research/protocol.md +28 -153
  343. package/skeleton/protocols/spike/builder-prompt.md +30 -48
  344. package/skeleton/protocols/spike/protocol.md +24 -107
  345. package/skeleton/protocols/spike/templates/findings.md +9 -39
  346. package/skeleton/protocols/spir/builder-prompt.md +33 -62
  347. package/skeleton/protocols/spir/consult-types/impl-review.md +17 -44
  348. package/skeleton/protocols/spir/consult-types/phase-review.md +17 -44
  349. package/skeleton/protocols/spir/consult-types/plan-review.md +14 -38
  350. package/skeleton/protocols/spir/consult-types/pr-review.md +13 -39
  351. package/skeleton/protocols/spir/consult-types/spec-review.md +13 -33
  352. package/skeleton/protocols/spir/prompts/implement.md +26 -195
  353. package/skeleton/protocols/spir/prompts/plan.md +20 -84
  354. package/skeleton/protocols/spir/prompts/review.md +28 -227
  355. package/skeleton/protocols/spir/prompts/specify.md +24 -110
  356. package/skeleton/protocols/spir/protocol.json +10 -0
  357. package/skeleton/protocols/spir/protocol.md +84 -633
  358. package/skeleton/protocols/spir/templates/plan.md +28 -147
  359. package/skeleton/protocols/spir/templates/review.md +21 -80
  360. package/skeleton/protocols/spir/templates/spec.md +24 -118
  361. package/skeleton/resources/commands/agent-farm.md +262 -0
  362. package/skeleton/resources/commands/consult.md +236 -8
  363. package/skeleton/resources/commands/overview.md +1 -0
  364. package/skeleton/roles/architect.md +67 -317
  365. package/skeleton/roles/builder.md +76 -191
  366. package/skeleton/templates/AGENTS.md +2 -0
  367. package/skeleton/templates/CLAUDE.md +2 -0
  368. package/templates/3d-viewer.html +32 -4
  369. package/templates/open.html +58 -12
  370. package/templates/tower.html +65 -9
  371. package/templates/vendor/three-3MFLoader.js +1478 -0
  372. package/templates/vendor/three-STLLoader.js +410 -0
  373. package/templates/vendor/three-TrackballControls.js +828 -0
  374. package/templates/vendor/three-fflate.module.js +2474 -0
  375. package/templates/vendor/three.module.js +53044 -0
  376. package/dashboard-dist/assets/index-BZ1x7x1X.js.map +0 -1
  377. package/dashboard-dist/assets/index-DB1KBSNE.css +0 -32
  378. package/dist/agent-farm/servers/send-buffer.d.ts +0 -59
  379. package/dist/agent-farm/servers/send-buffer.d.ts.map +0 -1
  380. package/dist/agent-farm/servers/send-buffer.js +0 -116
  381. package/dist/agent-farm/servers/send-buffer.js.map +0 -1
  382. package/skeleton/porch/prompts/defend.md +0 -108
  383. package/skeleton/porch/prompts/diagnose.md +0 -70
  384. package/skeleton/porch/prompts/evaluate.md +0 -132
  385. package/skeleton/porch/prompts/fix.md +0 -59
  386. package/skeleton/porch/prompts/implement.md +0 -88
  387. package/skeleton/porch/prompts/plan.md +0 -74
  388. package/skeleton/porch/prompts/pr.md +0 -84
  389. package/skeleton/porch/prompts/review.md +0 -249
  390. package/skeleton/porch/prompts/specify.md +0 -53
  391. package/skeleton/porch/prompts/test.md +0 -63
  392. package/skeleton/protocols/aspir/templates/plan.md +0 -184
  393. package/skeleton/protocols/aspir/templates/review.md +0 -120
  394. package/skeleton/protocols/aspir/templates/spec.md +0 -154
@@ -0,0 +1,488 @@
1
+ /**
2
+ * Reset orchestrator — the `afx refresh` state machine (Spec 1273).
3
+ *
4
+ * Composes the verified parts from phases 1–5 into the flow the architect ran by
5
+ * hand on 2026-07-27: request save-state → verify the receipt → wait for the
6
+ * turn to end → `/clear` → re-orient.
7
+ *
8
+ * ## Why this is a state machine over injected ports
9
+ *
10
+ * Reset is destructive in a way almost nothing else in Agent Farm is: `/clear`
11
+ * discards a builder's entire conversation, and there is no undo. Every safety
12
+ * property is therefore an ORDERING property — "the clear never happens before
13
+ * X" — and ordering is exactly what is hardest to prove by reading code.
14
+ *
15
+ * So the orchestrator does two things no ordinary command does:
16
+ *
17
+ * 1. Every externally-visible action goes through a port (`clock`, `fs`,
18
+ * `sendMessage`, `sendRaw`, `sendEscape`). Nothing here touches Tower, a
19
+ * PTY or the filesystem directly.
20
+ * 2. Every action is appended to an ordered **step log** before it is
21
+ * performed.
22
+ *
23
+ * The invariant tests then assert over that log — that `clear` never appears
24
+ * without `assemble` before it, that `escalate-esc` never precedes
25
+ * `receipt-accepted`, that an aborted run contains no `clear` at all. That turns
26
+ * "impossible by construction" from a claim in a comment into something a test
27
+ * can fail on.
28
+ *
29
+ * ## The invariants, and where each is enforced
30
+ *
31
+ * - **R1** (never clear without a saved re-orientation): `runReset` assembles and
32
+ * writes `.builder-reorient.md` at step 2, before any destructive step exists
33
+ * in the log. Assembly failure returns before the request is even sent.
34
+ * - **R2** (never clear without a verified receipt): the poll loop only leaves
35
+ * `awaiting-receipt` on `accepted`; every other exit path returns an aborted
36
+ * result.
37
+ * - **R3** (complete-or-abort re-orientation): delegated wholesale to
38
+ * `assembleReorientation`, which throws rather than emitting a partial frame.
39
+ * - **R4** (never clear a builder mid-turn): quiescence is a bounded wait, then
40
+ * at most ONE ESC escalation, then a second bounded wait. Still not quiet
41
+ * aborts — there is deliberately no third attempt and no "clear anyway".
42
+ */
43
+ import { assembleReorientation, ReorientationAssemblyError, } from './reorient.js';
44
+ import { buildSaveRequest, describeReceiptFailure, generateNonce, stateFilePath, verifyReceipt, } from './receipt.js';
45
+ import { DEFAULT_MIN_BYTES, DEFAULT_POLL_INTERVAL_MS, DEFAULT_QUIESCE_POST_ESCALATION_TIMEOUT_MS, DEFAULT_QUIESCE_TIMEOUT_MS, DEFAULT_QUIET_WINDOW_MS, DEFAULT_RECEIPT_TIMEOUT_MS, DEFAULT_STABILITY_WINDOW_MS, REORIENT_FILE_NAME, } from './constants.js';
46
+ /** Thrown for conditions that must stop the run before anything is touched. */
47
+ export class ResetPreflightError extends Error {
48
+ constructor(message) {
49
+ super(message);
50
+ this.name = 'ResetPreflightError';
51
+ }
52
+ }
53
+ // ============================================================================
54
+ // Orchestration
55
+ // ============================================================================
56
+ export async function runReset(options) {
57
+ const { context, fs, clock, terminal, buildSpawnPrompt, buildResumeNotice, issue, addendum, dryRun = false, interruptFirst = false, receiptTimeoutMs = DEFAULT_RECEIPT_TIMEOUT_MS, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, minBytes = DEFAULT_MIN_BYTES, stabilityWindowMs = DEFAULT_STABILITY_WINDOW_MS, quietWindowMs = DEFAULT_QUIET_WINDOW_MS, quiesceTimeoutMs = DEFAULT_QUIESCE_TIMEOUT_MS, quiescePostEscalationTimeoutMs = DEFAULT_QUIESCE_POST_ESCALATION_TIMEOUT_MS, stateFileName, } = options;
58
+ const steps = [];
59
+ const step = (name, detail) => {
60
+ steps.push({ name, at: clock.now(), detail });
61
+ };
62
+ const statePath = resolveStatePath(context.worktree, stateFileName);
63
+ const reorientPath = stateFilePath(context.worktree, REORIENT_FILE_NAME);
64
+ const nonce = generateNonce();
65
+ // --------------------------------------------------------------------
66
+ // 0. Timing-parameter sanity.
67
+ //
68
+ // Validated HERE as well as at the CLI boundary, because these values do not
69
+ // merely tune the run — each one can switch OFF a safety gate while the run
70
+ // still reports success. A negative quiet window makes every quiescence check
71
+ // pass instantly (R4 gone); a non-positive minimum accepts any state file
72
+ // however empty (R2's substance floor gone); a NaN timeout produces a NaN
73
+ // deadline, and since every comparison against NaN is false, the wait never
74
+ // expires and the command hangs.
75
+ //
76
+ // The orchestrator is the component that OWNS these invariants, so it does
77
+ // not delegate their preconditions to its callers. A programmatic caller must
78
+ // not be able to disable R2 or R4 by passing a number.
79
+ // --------------------------------------------------------------------
80
+ requirePositive(receiptTimeoutMs, 'receiptTimeoutMs');
81
+ requirePositive(pollIntervalMs, 'pollIntervalMs');
82
+ requirePositive(minBytes, 'minBytes');
83
+ requirePositive(stabilityWindowMs, 'stabilityWindowMs');
84
+ requirePositive(quietWindowMs, 'quietWindowMs');
85
+ requirePositive(quiesceTimeoutMs, 'quiesceTimeoutMs');
86
+ requirePositive(quiescePostEscalationTimeoutMs, 'quiescePostEscalationTimeoutMs');
87
+ // --------------------------------------------------------------------
88
+ // 1. Preflight. Everything that can refuse does so before ANY write.
89
+ // --------------------------------------------------------------------
90
+ // Harness capability is checked first and aborts loudly, naming the harness.
91
+ // No substituted mechanism: if this agent has no in-session context reset,
92
+ // there is no partial version of a reset worth doing (fail fast).
93
+ if (!context.harness.supportsContextReset) {
94
+ throw new ResetPreflightError(`Builder '${context.builderId}' runs under the '${context.harnessName}' harness, ` +
95
+ `which has no in-session context reset. Refresh is a no-op there — there is no ` +
96
+ `substitute mechanism. Use the boundary-recycle pattern instead: let the builder ` +
97
+ `finish, then respawn with 'afx spawn <id> --resume'.`);
98
+ }
99
+ const observed = await terminal.observe();
100
+ if (!observed.exists) {
101
+ throw new ResetPreflightError(`Builder '${context.builderId}' has no live terminal. Refresh writes to a running ` +
102
+ `session; there is nothing to clear. Check 'afx status'.`);
103
+ }
104
+ // Writability is checked HERE, in preflight, not left to fail on the first
105
+ // send. The plan's contract is validate-before-touch: discovering the problem
106
+ // later would mean `.builder-reorient.md` had already been written to the
107
+ // builder's worktree for a reset that could never proceed.
108
+ //
109
+ // `status: 'running'` is not sufficient evidence — a session whose shellper
110
+ // connection died reports exactly that while dropping every write (#1198),
111
+ // which is the specific case this catches.
112
+ if (observed.writable === false) {
113
+ throw new ResetPreflightError(`Builder '${context.builderId}' has a terminal that is not accepting input ` +
114
+ `(its process connection is down — #1198). Refresh would send a save request that ` +
115
+ `is silently dropped. Nothing has been touched. Check Tower logs, or retry once ` +
116
+ `the session reconnects.`);
117
+ }
118
+ step('resolve', `${context.protocol}/${context.mode} in ${context.worktree}`);
119
+ // --------------------------------------------------------------------
120
+ // 2. Assemble + persist the re-orientation. THIS IS R1's ENFORCEMENT POINT.
121
+ //
122
+ // Everything destructive is downstream of here. A throw from assembly (R3)
123
+ // propagates with the builder completely untouched — no message sent, no
124
+ // keystroke written.
125
+ // --------------------------------------------------------------------
126
+ let payload;
127
+ try {
128
+ payload = assembleReorientation({
129
+ context,
130
+ statePath,
131
+ addendum,
132
+ buildSpawnPrompt,
133
+ buildResumeNotice,
134
+ issue,
135
+ });
136
+ }
137
+ catch (err) {
138
+ if (err instanceof ReorientationAssemblyError) {
139
+ throw new ResetPreflightError(`Refusing to refresh: ${err.message} The builder has not been touched.`);
140
+ }
141
+ throw err;
142
+ }
143
+ step('assemble', `${payload.inline.split('\n').length} inline lines`);
144
+ const saveRequest = buildSaveRequest(nonce, statePath);
145
+ // A dry run stops here, having proved the two things worth proving before a
146
+ // real run: that assembly succeeds (R3) and what the builder would receive.
147
+ // Zero writes reach the builder, which is what makes R1 auditable by
148
+ // inspection rather than by trust.
149
+ if (dryRun) {
150
+ return {
151
+ outcome: 'dry-run',
152
+ steps,
153
+ nonce,
154
+ statePath,
155
+ reorientPath,
156
+ payload,
157
+ saveRequest,
158
+ };
159
+ }
160
+ fs.write(reorientPath, payload.longForm);
161
+ step('write-reorient-file', reorientPath);
162
+ // --------------------------------------------------------------------
163
+ // 3. Optional pre-emptive interrupt.
164
+ //
165
+ // Default OFF. A builder that is reachable should be ASKED to save, not
166
+ // interrupted first — an ESC into a working builder costs it the turn it was
167
+ // mid-way through. This is opt-in for the case the architect already knows
168
+ // about: a builder wedged on a foreground wait, where every queued message
169
+ // including the save request would go unread until the turn ends.
170
+ // --------------------------------------------------------------------
171
+ if (interruptFirst) {
172
+ await terminal.sendEscape();
173
+ step('interrupt-first');
174
+ }
175
+ // --------------------------------------------------------------------
176
+ // 4–5. Request the save, then gate on a VERIFIED receipt (R2).
177
+ // --------------------------------------------------------------------
178
+ await terminal.sendMessage(saveRequest);
179
+ step('send-save-request', `nonce ${nonce}`);
180
+ const receipt = await awaitReceipt({
181
+ fs,
182
+ clock,
183
+ statePath,
184
+ nonce,
185
+ minBytes,
186
+ stabilityWindowMs,
187
+ pollIntervalMs,
188
+ timeoutMs: receiptTimeoutMs,
189
+ });
190
+ if (receipt.status !== 'accepted') {
191
+ // Abort with the builder's context fully intact. The state file may exist
192
+ // and be perfectly good — it simply was not PROVEN good, and an unproven
193
+ // save is not a basis for discarding a conversation.
194
+ return {
195
+ outcome: 'aborted',
196
+ steps,
197
+ abortReason: `Save-state receipt not verified. ${describeReceiptFailure(receipt, statePath, minBytes)}`,
198
+ nonce,
199
+ statePath,
200
+ reorientPath,
201
+ payload,
202
+ saveRequest,
203
+ };
204
+ }
205
+ step('receipt-accepted', `${receipt.bytes} bytes`);
206
+ // --------------------------------------------------------------------
207
+ // 6. Quiescence (R4).
208
+ //
209
+ // The receipt proves the file is written; it does NOT prove the turn ended.
210
+ // A builder that wrote the file and kept working would receive `/clear` as
211
+ // literal text mid-turn — the keystroke would land in its input buffer rather
212
+ // than executing. Hence a real silence check.
213
+ // --------------------------------------------------------------------
214
+ let quiet = await awaitQuiescence({
215
+ terminal,
216
+ clock,
217
+ quietWindowMs,
218
+ timeoutMs: quiesceTimeoutMs,
219
+ pollIntervalMs,
220
+ });
221
+ if (!quiet.quiet) {
222
+ if (quiet.reason === 'terminal-gone') {
223
+ return {
224
+ outcome: 'aborted',
225
+ steps,
226
+ abortReason: `Builder '${context.builderId}' lost its terminal while waiting for its turn to end. ` +
227
+ `Nothing was cleared. Its saved state is at ${statePath} — that file survives the ` +
228
+ `terminal, so respawn with 'afx spawn <id> --resume' and point the new session at it.`,
229
+ nonce,
230
+ statePath,
231
+ reorientPath,
232
+ payload,
233
+ saveRequest,
234
+ stateBytes: receipt.bytes,
235
+ };
236
+ }
237
+ if (quiet.reason === 'unobservable') {
238
+ return {
239
+ outcome: 'aborted',
240
+ steps,
241
+ abortReason: `Cannot observe terminal quiescence: this Tower does not report 'lastDataAt' ` +
242
+ `(Spec 1273 / phase 2). Refusing to clear a builder whose turn state is unknown — ` +
243
+ `treating "unknown" as "idle" is exactly how a mid-turn clear happens. ` +
244
+ `Restart Tower on a current build.`,
245
+ nonce,
246
+ statePath,
247
+ reorientPath,
248
+ payload,
249
+ saveRequest,
250
+ stateBytes: receipt.bytes,
251
+ };
252
+ }
253
+ // EXACTLY ONE escalation, and it is legal only here — after the R2 receipt.
254
+ // Before the receipt an ESC could interrupt the very save being requested;
255
+ // after it, the worst case is ending a turn whose valuable output is already
256
+ // on disk.
257
+ await terminal.sendEscape();
258
+ step('escalate-esc');
259
+ quiet = await awaitQuiescence({
260
+ terminal,
261
+ clock,
262
+ quietWindowMs,
263
+ timeoutMs: quiescePostEscalationTimeoutMs,
264
+ pollIntervalMs,
265
+ });
266
+ if (!quiet.quiet) {
267
+ // No third attempt, no "clear anyway". Aborting leaves a builder with its
268
+ // context and a saved state file — recoverable. Clearing a busy builder
269
+ // does not.
270
+ return {
271
+ outcome: 'aborted',
272
+ steps,
273
+ abortReason: `Builder did not go quiet within ${quiescePostEscalationTimeoutMs}ms of the ESC ` +
274
+ `escalation. Refusing to clear a builder that is still mid-turn (R4). Its state ` +
275
+ `file is saved at ${statePath}; retry once it settles, or raise --quiet-window.`,
276
+ nonce,
277
+ statePath,
278
+ reorientPath,
279
+ payload,
280
+ saveRequest,
281
+ stateBytes: receipt.bytes,
282
+ };
283
+ }
284
+ }
285
+ step('quiescent');
286
+ // --------------------------------------------------------------------
287
+ // 7–9. Clear, confirm best-effort, re-orient.
288
+ // --------------------------------------------------------------------
289
+ // Snapshot the buffer size BEFORE clearing, so confirmation can distinguish
290
+ // the harness's response from the echo of our own keystroke.
291
+ const totalBeforeClear = terminal.readOutput
292
+ ? ((await terminal.readOutput())?.total ?? 0)
293
+ : 0;
294
+ await terminal.sendRaw('/clear');
295
+ step('clear');
296
+ const confirmed = await confirmClear(terminal, totalBeforeClear);
297
+ step(confirmed ? 'clear-confirmed' : 'clear-unconfirmed');
298
+ await terminal.sendMessage(payload.inline);
299
+ step('send-reorientation');
300
+ return {
301
+ outcome: 'completed',
302
+ steps,
303
+ nonce,
304
+ statePath,
305
+ reorientPath,
306
+ payload,
307
+ saveRequest,
308
+ stateBytes: receipt.bytes,
309
+ };
310
+ }
311
+ /**
312
+ * Poll the state file until it is accepted or the wait expires.
313
+ *
314
+ * Returns the LAST observation rather than a boolean, so the abort message can
315
+ * name the specific gate that failed — "wrote a 200-byte stub" and "never wrote
316
+ * anything" call for different responses from the architect.
317
+ */
318
+ async function awaitReceipt(options) {
319
+ const { fs, clock, statePath, nonce, minBytes, stabilityWindowMs, pollIntervalMs, timeoutMs } = options;
320
+ const deadline = clock.now() + timeoutMs;
321
+ let previous = null;
322
+ let previousAt = clock.now();
323
+ let latest = { status: 'missing' };
324
+ for (;;) {
325
+ const now = clock.now();
326
+ latest = verifyReceipt({
327
+ fs,
328
+ statePath,
329
+ nonce,
330
+ minBytes,
331
+ previous,
332
+ msSincePrevious: now - previousAt,
333
+ stabilityWindowMs,
334
+ });
335
+ if (latest.status === 'accepted')
336
+ return latest;
337
+ // Only advance the stability baseline when the gap has actually been
338
+ // consumed. Resetting `previousAt` on every poll would make the two
339
+ // observations always "too close together" and stability unreachable.
340
+ if (now - previousAt >= stabilityWindowMs) {
341
+ previous = latest;
342
+ previousAt = now;
343
+ }
344
+ if (clock.now() >= deadline)
345
+ return latest;
346
+ await clock.sleep(pollIntervalMs);
347
+ if (clock.now() >= deadline) {
348
+ // Re-evaluate once after the final sleep so a file that landed during it
349
+ // is not discarded on a technicality.
350
+ const now2 = clock.now();
351
+ latest = verifyReceipt({
352
+ fs,
353
+ statePath,
354
+ nonce,
355
+ minBytes,
356
+ previous,
357
+ msSincePrevious: now2 - previousAt,
358
+ stabilityWindowMs,
359
+ });
360
+ return latest;
361
+ }
362
+ }
363
+ }
364
+ /**
365
+ * Wait until the terminal has produced no output for `quietWindowMs`.
366
+ *
367
+ * `lastDataAt === undefined` is reported as `unobservable`, NOT as quiet. An
368
+ * older Tower omits the field, and defaulting it to 0 would compute an age of
369
+ * ~56 years and clear a busy builder instantly.
370
+ */
371
+ async function awaitQuiescence(options) {
372
+ const { terminal, clock, quietWindowMs, timeoutMs, pollIntervalMs } = options;
373
+ const deadline = clock.now() + timeoutMs;
374
+ for (;;) {
375
+ const observation = await terminal.observe();
376
+ // Checked BEFORE lastDataAt. A terminal that vanished mid-run also reports
377
+ // no lastDataAt, and conflating the two sends the architect to check their
378
+ // Tower version when the real event is that the builder's terminal died.
379
+ // The two need different responses, so they get different reasons.
380
+ if (!observation.exists) {
381
+ return { quiet: false, reason: 'terminal-gone' };
382
+ }
383
+ if (observation.lastDataAt === undefined) {
384
+ return { quiet: false, reason: 'unobservable' };
385
+ }
386
+ if (clock.now() - observation.lastDataAt >= quietWindowMs) {
387
+ return { quiet: true };
388
+ }
389
+ if (clock.now() >= deadline)
390
+ return { quiet: false, reason: 'timeout' };
391
+ await clock.sleep(pollIntervalMs);
392
+ if (clock.now() >= deadline) {
393
+ const final = await terminal.observe();
394
+ if (!final.exists)
395
+ return { quiet: false, reason: 'terminal-gone' };
396
+ if (final.lastDataAt === undefined)
397
+ return { quiet: false, reason: 'unobservable' };
398
+ if (clock.now() - final.lastDataAt >= quietWindowMs)
399
+ return { quiet: true };
400
+ return { quiet: false, reason: 'timeout' };
401
+ }
402
+ }
403
+ }
404
+ /**
405
+ * Best-effort check that `/clear` took effect.
406
+ *
407
+ * Deliberately advisory. There is no reliable cross-version signal that Claude
408
+ * Code cleared its context, and an unconfirmed clear is reported as unconfirmed
409
+ * rather than as failure — the re-orientation that follows is correct either
410
+ * way. The worst case of a silent no-op is a builder that kept its context and
411
+ * also received a re-orientation, which loses nothing.
412
+ */
413
+ async function confirmClear(terminal, totalBeforeClear) {
414
+ if (!terminal.readOutput)
415
+ return false;
416
+ try {
417
+ const output = await terminal.readOutput();
418
+ if (!output)
419
+ return false;
420
+ // Consider ONLY lines produced after the clear was sent. Everything the
421
+ // refresh itself wrote is at or before `totalBeforeClear`, so this excludes
422
+ // its own text by construction rather than by hoping the pattern avoids it.
423
+ const newLineCount = output.total - totalBeforeClear;
424
+ if (newLineCount <= 0)
425
+ return false;
426
+ const fresh = output.lines.slice(-newLineCount).join('\n');
427
+ return /context (?:cleared|reset)|conversation (?:cleared|reset)|cleared conversation/i.test(fresh);
428
+ }
429
+ catch {
430
+ // Confirmation must never be able to fail the run — it is a report field.
431
+ return false;
432
+ }
433
+ }
434
+ // ============================================================================
435
+ // Helpers
436
+ // ============================================================================
437
+ /**
438
+ * Reject a timing/threshold parameter that would weaken a gate.
439
+ *
440
+ * `Number.isFinite` rather than a bare `> 0` comparison: `NaN > 0` is false but
441
+ * so is `NaN <= 0`, so a NaN slips through any single comparison written the
442
+ * obvious way. Infinity is rejected too — an infinite deadline is a hang.
443
+ */
444
+ function requirePositive(value, name) {
445
+ if (!Number.isFinite(value) || value <= 0) {
446
+ throw new ResetPreflightError(`Invalid ${name}: ${value}. Must be a positive, finite number. ` +
447
+ `This parameter gates a safety check (R2/R4) — a bad value would disable it silently.`);
448
+ }
449
+ }
450
+ /**
451
+ * Resolve the state-file path, refusing anything that escapes the worktree.
452
+ *
453
+ * The path is handed to the builder as a write instruction, so an override of
454
+ * `../../../etc/whatever` would have the builder write outside its own worktree.
455
+ * Containment is checked on the resolved path, not the raw string, so `..`
456
+ * segments cannot slip through.
457
+ */
458
+ function resolveStatePath(worktree, stateFileName) {
459
+ const candidate = stateFilePath(worktree, stateFileName);
460
+ if (!stateFileName)
461
+ return candidate;
462
+ const normalizedWorktree = worktree.endsWith('/') ? worktree : `${worktree}/`;
463
+ if (!candidate.startsWith(normalizedWorktree)) {
464
+ throw new ResetPreflightError(`State-file override '${stateFileName}' resolves to ${candidate}, outside the builder's ` +
465
+ `worktree (${worktree}). Refusing: the path is sent to the builder as a write instruction.`);
466
+ }
467
+ return candidate;
468
+ }
469
+ /**
470
+ * Render the step log as the run report.
471
+ *
472
+ * Each line carries its EVIDENCE, not just a tick. "Receipt accepted" alone is
473
+ * the kind of reassurance that hides a stale file; "accepted — 8,432 bytes
474
+ * carrying nonce a1b2c3" is checkable.
475
+ */
476
+ export function formatResetReport(result) {
477
+ const lines = [];
478
+ for (const s of result.steps) {
479
+ lines.push(s.detail ? ` ✓ ${s.name} — ${s.detail}` : ` ✓ ${s.name}`);
480
+ }
481
+ if (result.outcome === 'aborted') {
482
+ lines.push('');
483
+ lines.push(` ✗ ABORTED: ${result.abortReason}`);
484
+ lines.push(' The builder\'s context was NOT cleared.');
485
+ }
486
+ return lines.join('\n');
487
+ }
488
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent-farm/commands/reset/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAKH,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAK3B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,aAAa,GAGd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,0CAA0C,EAC1C,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAwIxB,+EAA+E;AAC/E,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AA+BD,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAwB;IACrD,MAAM,EACJ,OAAO,EACP,EAAE,EACF,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,EACL,QAAQ,EACR,MAAM,GAAG,KAAK,EACd,cAAc,GAAG,KAAK,EACtB,gBAAgB,GAAG,0BAA0B,EAC7C,cAAc,GAAG,wBAAwB,EACzC,QAAQ,GAAG,iBAAiB,EAC5B,iBAAi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C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,gBAAgB,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QACjD,KAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The reset receipt gate — invariant R2 (Spec 1273).
3
+ *
4
+ * `afx refresh` clears a builder's context, which is irreversible. The manual
5
+ * version of this flow guarded that step by eyeballing the state file ("ours was
6
+ * 203 lines"). This module replaces the eyeball with evidence: a state file is
7
+ * accepted only if it proves it is *this run's* save, is substantive, and has
8
+ * stopped growing.
9
+ *
10
+ * Freshness comes from a nonce written INSIDE the file, not from mtime. mtime
11
+ * was rejected deliberately: filesystem timestamp granularity and clock skew
12
+ * make it fragile, and it cannot distinguish "rewritten in response to this
13
+ * request" from "touched". A nonce the builder must reproduce can only appear
14
+ * in a file written after the request that carried it.
15
+ *
16
+ * Pure: all filesystem access arrives through injected ports, so every rejection
17
+ * path is testable without a real builder, a real worktree, or real time.
18
+ */
19
+ /** Filesystem access needed by the gate. Injected so tests need no real files. */
20
+ export interface ReceiptFsPort {
21
+ /** Byte length of the file, or null when it does not exist. */
22
+ sizeOf(path: string): number | null;
23
+ /** Full contents, or null when the file does not exist. */
24
+ read(path: string): string | null;
25
+ }
26
+ /**
27
+ * Generate a per-run nonce.
28
+ *
29
+ * Short enough that a builder reproduces it without transcription errors, long
30
+ * enough that a stale file from a previous reset cannot collide with it.
31
+ */
32
+ export declare function generateNonce(): string;
33
+ /**
34
+ * The marker line the builder is asked to reproduce verbatim.
35
+ *
36
+ * An HTML comment so it is invisible in rendered markdown but trivially
37
+ * greppable, and harmless if the file is later read by a human.
38
+ */
39
+ export declare function nonceMarker(nonce: string): string;
40
+ /**
41
+ * Build the message asking the builder to write its working state.
42
+ *
43
+ * The checklist is the quality bar. It cannot be enforced programmatically (see
44
+ * `verifyReceipt` — the gate is structural on purpose), so it has to be explicit
45
+ * enough that a builder writing in good faith produces something a cold reader
46
+ * can actually use.
47
+ */
48
+ export declare function buildSaveRequest(nonce: string, statePath: string): string;
49
+ /** Why a candidate state file was not accepted, or that it was. */
50
+ export type ReceiptStatus = 'accepted' | 'missing' | 'wrong-nonce' | 'too-small' | 'still-growing';
51
+ export interface ReceiptObservation {
52
+ status: ReceiptStatus;
53
+ /** Size at the moment of observation, when the file existed. */
54
+ bytes?: number;
55
+ }
56
+ export interface VerifyReceiptOptions {
57
+ fs: ReceiptFsPort;
58
+ statePath: string;
59
+ nonce: string;
60
+ minBytes?: number;
61
+ /** A previous observation, for the stability comparison. */
62
+ previous?: ReceiptObservation | null;
63
+ /** ms since `previous` was taken. Stability needs a real gap, not two reads in a row. */
64
+ msSincePrevious?: number;
65
+ stabilityWindowMs?: number;
66
+ }
67
+ /**
68
+ * Evaluate the state file once.
69
+ *
70
+ * Checks run in escalating order so the reported reason is the *most specific*
71
+ * one true: existence, then freshness, then substance, then stability. A caller
72
+ * polls this and only proceeds on `accepted`.
73
+ *
74
+ * Stability requires agreement between two observations separated by at least
75
+ * `stabilityWindowMs`. Without the time gap, a builder mid-write would look
76
+ * stable simply because two reads landed between the same two `write()` calls.
77
+ */
78
+ export declare function verifyReceipt(options: VerifyReceiptOptions): ReceiptObservation;
79
+ /**
80
+ * Human-readable explanation of a non-acceptance, for the abort message.
81
+ *
82
+ * Reset aborts loudly rather than clearing on a doubtful file, so the architect
83
+ * needs to know which gate failed — "timed out" alone would not distinguish a
84
+ * builder that never responded from one that wrote a stub.
85
+ */
86
+ export declare function describeReceiptFailure(observation: ReceiptObservation, statePath: string, minBytes?: number): string;
87
+ /**
88
+ * Absolute path of the state file for a worktree.
89
+ *
90
+ * Uses `path.join` rather than string concatenation: this path is handed to the
91
+ * builder verbatim in the save request, so on Windows a hand-built
92
+ * `C:\repo\wt\` + `/` + name would instruct the builder to write to a path that
93
+ * is not the one the gate then stats. `path.join` also collapses redundant
94
+ * separators, so a trailing slash on the worktree is harmless.
95
+ */
96
+ export declare function stateFilePath(worktreePath: string, fileName?: string): string;
97
+ //# sourceMappingURL=receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt.d.ts","sourceRoot":"","sources":["../../../../src/agent-farm/commands/reset/receipt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAcH,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,2DAA2D;IAC3D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACnC;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA2BzE;AAMD,mEAAmE;AACnE,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,SAAS,GACT,aAAa,GACb,WAAW,GACX,eAAe,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,aAAa,CAAC;IACtB,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,aAAa,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