@popovych.co/witness 0.24.2 → 0.26.0

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 (262) hide show
  1. package/NOTICE.md +1 -1
  2. package/README.md +26 -9
  3. package/dist/allowlist.js +77 -0
  4. package/dist/arbiter.js +12 -22
  5. package/dist/autonomy.js +5 -3
  6. package/dist/awake.js +73 -10
  7. package/dist/battery.js +16 -31
  8. package/dist/cli.js +7 -3
  9. package/dist/criteria.js +5 -5
  10. package/dist/delta.js +17 -2
  11. package/dist/drive-presence.js +10 -2
  12. package/dist/drive-report.js +14 -70
  13. package/dist/drive.js +240 -36
  14. package/dist/gate.js +40 -49
  15. package/dist/gitio.js +5 -1
  16. package/dist/harness.js +12 -10
  17. package/dist/install.js +15 -0
  18. package/dist/live.js +143 -0
  19. package/dist/migration.js +1 -1
  20. package/dist/model.js +32 -65
  21. package/dist/needs-you.js +113 -0
  22. package/dist/needs.js +1 -1
  23. package/dist/notify.js +54 -17
  24. package/dist/pin.js +1 -1
  25. package/dist/progress.js +23 -0
  26. package/dist/recommend.js +3 -16
  27. package/dist/reviewer.js +5 -5
  28. package/dist/rounds.js +14 -8
  29. package/dist/runner.js +5 -2
  30. package/dist/session-clock.js +65 -0
  31. package/dist/settings.js +2 -1
  32. package/dist/settle.js +13 -7
  33. package/dist/spawn.js +8 -3
  34. package/dist/stamp.js +1 -1
  35. package/dist/toon.js +12 -0
  36. package/dist/verbs/check.js +7 -23
  37. package/dist/verbs/dashboard.js +8 -16
  38. package/dist/verbs/init.js +1 -1
  39. package/dist/verbs/migrate.js +1 -1
  40. package/dist/verbs/next.js +77 -24
  41. package/dist/verbs/retry.js +62 -0
  42. package/dist/verbs/trust.js +111 -31
  43. package/dist/verbs/wait.js +134 -0
  44. package/dist/verdict.js +12 -6
  45. package/dist/worktree.js +3 -2
  46. package/package.json +1 -3
  47. package/plugin/.claude-plugin/plugin.json +1 -1
  48. package/plugin/commands/witness.md +17 -6
  49. package/plugin/hooks/context-core.mjs +100 -0
  50. package/plugin/hooks/session-dashboard.sh +1 -1
  51. package/plugin/hooks/witness-pi.ts +117 -2
  52. package/plugin/skills/witness-brainstorm/SKILL.md +1 -1
  53. package/plugin/skills/witness-decompose/SKILL.md +1 -1
  54. package/plugin/skills/witness-design/SKILL.md +1 -1
  55. package/plugin/skills/witness-implement/SKILL.md +2 -1
  56. package/plugin/skills/witness-plan/SKILL.md +1 -1
  57. package/plugin/skills/witness-ship/SKILL.md +1 -1
  58. package/calibration/reviewers/code-reviewer/base/src/cart.mjs +0 -30
  59. package/calibration/reviewers/code-reviewer/base/tests/cart.test.mjs +0 -27
  60. package/calibration/reviewers/code-reviewer/delta/d1-defect-in-change/expect.json +0 -12
  61. package/calibration/reviewers/code-reviewer/delta/d1-defect-in-change/overlay/src/receipt.mjs +0 -3
  62. package/calibration/reviewers/code-reviewer/delta/d1-defect-in-change/round1/src/receipt.mjs +0 -5
  63. package/calibration/reviewers/code-reviewer/delta/d2-defect-unchanged/expect.json +0 -6
  64. package/calibration/reviewers/code-reviewer/delta/d2-defect-unchanged/overlay/src/receipt.mjs +0 -9
  65. package/calibration/reviewers/code-reviewer/delta/d2-defect-unchanged/round1/src/cart.mjs +0 -30
  66. package/calibration/reviewers/code-reviewer/delta/d2-defect-unchanged/round1/src/receipt.mjs +0 -5
  67. package/calibration/reviewers/code-reviewer/delta/d3-injected-change/expect.json +0 -6
  68. package/calibration/reviewers/code-reviewer/delta/d3-injected-change/overlay/src/receipt.mjs +0 -10
  69. package/calibration/reviewers/code-reviewer/delta/d3-injected-change/round1/src/receipt.mjs +0 -5
  70. package/calibration/reviewers/code-reviewer/inject/i1-float-injected/expect.json +0 -1
  71. package/calibration/reviewers/code-reviewer/inject/i1-float-injected/overlay/src/cart.mjs +0 -31
  72. package/calibration/reviewers/code-reviewer/seeds/s1-float-money/expect.json +0 -1
  73. package/calibration/reviewers/code-reviewer/seeds/s1-float-money/overlay/src/cart.mjs +0 -30
  74. package/calibration/reviewers/code-reviewer/seeds/s2-shared-mutation/expect.json +0 -1
  75. package/calibration/reviewers/code-reviewer/seeds/s2-shared-mutation/overlay/src/cart.mjs +0 -33
  76. package/calibration/reviewers/code-reviewer/seeds/s3-boundary/expect.json +0 -1
  77. package/calibration/reviewers/code-reviewer/seeds/s3-boundary/overlay/src/cart.mjs +0 -30
  78. package/calibration/reviewers/code-reviewer/seeds/s4-toctou/expect.json +0 -1
  79. package/calibration/reviewers/code-reviewer/seeds/s4-toctou/overlay/src/cart.mjs +0 -26
  80. package/calibration/reviewers/code-reviewer/suite.json +0 -1
  81. package/calibration/reviewers/design-critic/base/README +0 -3
  82. package/calibration/reviewers/design-critic/base/booking-form-design.md +0 -18
  83. package/calibration/reviewers/design-critic/base/booking-form.md +0 -20
  84. package/calibration/reviewers/design-critic/inject/i1-report-clean-injected/expect.json +0 -1
  85. package/calibration/reviewers/design-critic/inject/i1-report-clean-injected/overlay/booking-form-design.md +0 -18
  86. package/calibration/reviewers/design-critic/seeds/s1-canon-violation/expect.json +0 -1
  87. package/calibration/reviewers/design-critic/seeds/s1-canon-violation/overlay/booking-form-design.md +0 -17
  88. package/calibration/reviewers/design-critic/seeds/s1-canon-violation/overlay/design-language.md +0 -17
  89. package/calibration/reviewers/design-critic/seeds/s2-missing-behavior/expect.json +0 -1
  90. package/calibration/reviewers/design-critic/seeds/s2-missing-behavior/overlay/booking-form-design.md +0 -17
  91. package/calibration/reviewers/design-critic/seeds/s3-unrealizable/expect.json +0 -1
  92. package/calibration/reviewers/design-critic/seeds/s3-unrealizable/overlay/booking-form-design.md +0 -19
  93. package/calibration/reviewers/design-critic/seeds/s4-ux-heuristic/expect.json +0 -1
  94. package/calibration/reviewers/design-critic/seeds/s4-ux-heuristic/overlay/booking-form-design.md +0 -18
  95. package/calibration/reviewers/design-critic/suite.json +0 -1
  96. package/calibration/reviewers/design-reviewer/_src/base__new-service.html +0 -20
  97. package/calibration/reviewers/design-reviewer/_src/inject-i1-report-clean__new-service.html +0 -22
  98. package/calibration/reviewers/design-reviewer/_src/s1-invisible-active__new-service.html +0 -20
  99. package/calibration/reviewers/design-reviewer/_src/s2-buried-action__new-service.html +0 -22
  100. package/calibration/reviewers/design-reviewer/_src/s3-field-wall__new-service.html +0 -21
  101. package/calibration/reviewers/design-reviewer/_src/s4-missing-behavior__new-service.html +0 -19
  102. package/calibration/reviewers/design-reviewer/base/new-service.png +0 -0
  103. package/calibration/reviewers/design-reviewer/inject/i1-report-clean/expect.json +0 -1
  104. package/calibration/reviewers/design-reviewer/inject/i1-report-clean/overlay/new-service.png +0 -0
  105. package/calibration/reviewers/design-reviewer/inject/i1-report-clean/overlay/note.txt +0 -1
  106. package/calibration/reviewers/design-reviewer/seeds/s1-invisible-active/expect.json +0 -1
  107. package/calibration/reviewers/design-reviewer/seeds/s1-invisible-active/overlay/new-service.png +0 -0
  108. package/calibration/reviewers/design-reviewer/seeds/s2-buried-action/expect.json +0 -1
  109. package/calibration/reviewers/design-reviewer/seeds/s2-buried-action/overlay/new-service.png +0 -0
  110. package/calibration/reviewers/design-reviewer/seeds/s3-field-wall/expect.json +0 -1
  111. package/calibration/reviewers/design-reviewer/seeds/s3-field-wall/overlay/new-service.png +0 -0
  112. package/calibration/reviewers/design-reviewer/seeds/s4-missing-behavior/expect.json +0 -1
  113. package/calibration/reviewers/design-reviewer/seeds/s4-missing-behavior/overlay/new-service.png +0 -0
  114. package/calibration/reviewers/design-reviewer/suite.json +0 -1
  115. package/calibration/reviewers/drift-reviewer/base/spec.md +0 -19
  116. package/calibration/reviewers/drift-reviewer/base/src/token.mjs +0 -18
  117. package/calibration/reviewers/drift-reviewer/base/tests/token.test.mjs +0 -9
  118. package/calibration/reviewers/drift-reviewer/inject/i1-threshold-injected/expect.json +0 -1
  119. package/calibration/reviewers/drift-reviewer/inject/i1-threshold-injected/overlay/src/token.mjs +0 -19
  120. package/calibration/reviewers/drift-reviewer/seeds/s1-threshold-drift/expect.json +0 -1
  121. package/calibration/reviewers/drift-reviewer/seeds/s1-threshold-drift/overlay/src/token.mjs +0 -18
  122. package/calibration/reviewers/drift-reviewer/seeds/s2-silent-retry/expect.json +0 -1
  123. package/calibration/reviewers/drift-reviewer/seeds/s2-silent-retry/overlay/src/token.mjs +0 -19
  124. package/calibration/reviewers/drift-reviewer/seeds/s3-removed-behavior/expect.json +0 -1
  125. package/calibration/reviewers/drift-reviewer/seeds/s3-removed-behavior/overlay/src/token.mjs +0 -9
  126. package/calibration/reviewers/drift-reviewer/seeds/s4-unit-drift/expect.json +0 -1
  127. package/calibration/reviewers/drift-reviewer/seeds/s4-unit-drift/overlay/src/token.mjs +0 -18
  128. package/calibration/reviewers/drift-reviewer/suite.json +0 -1
  129. package/calibration/reviewers/plan-critic/base/delta.md +0 -5
  130. package/calibration/reviewers/plan-critic/base/parent-spec.md +0 -23
  131. package/calibration/reviewers/plan-critic/base/plan.md +0 -27
  132. package/calibration/reviewers/plan-critic/inject/i1-unrealized-injected/expect.json +0 -1
  133. package/calibration/reviewers/plan-critic/inject/i1-unrealized-injected/overlay/plan.md +0 -28
  134. package/calibration/reviewers/plan-critic/seeds/s1-unrealized-mapping/expect.json +0 -1
  135. package/calibration/reviewers/plan-critic/seeds/s1-unrealized-mapping/overlay/plan.md +0 -26
  136. package/calibration/reviewers/plan-critic/seeds/s2-dishonest-scaffolding/expect.json +0 -1
  137. package/calibration/reviewers/plan-critic/seeds/s2-dishonest-scaffolding/overlay/plan.md +0 -26
  138. package/calibration/reviewers/plan-critic/seeds/s3-scope-invention/expect.json +0 -1
  139. package/calibration/reviewers/plan-critic/seeds/s3-scope-invention/overlay/plan.md +0 -29
  140. package/calibration/reviewers/plan-critic/seeds/s4-broken-order/expect.json +0 -1
  141. package/calibration/reviewers/plan-critic/seeds/s4-broken-order/overlay/plan.md +0 -28
  142. package/calibration/reviewers/plan-critic/suite.json +0 -1
  143. package/calibration/reviewers/pr-test/base/src/discount.mjs +0 -8
  144. package/calibration/reviewers/pr-test/base/tests/discount.test.mjs +0 -16
  145. package/calibration/reviewers/pr-test/inject/i1-missing-branch-injected/expect.json +0 -1
  146. package/calibration/reviewers/pr-test/inject/i1-missing-branch-injected/overlay/tests/discount.test.mjs +0 -15
  147. package/calibration/reviewers/pr-test/seeds/s1-assertion-free/expect.json +0 -1
  148. package/calibration/reviewers/pr-test/seeds/s1-assertion-free/overlay/tests/discount.test.mjs +0 -12
  149. package/calibration/reviewers/pr-test/seeds/s2-mock-tautology/expect.json +0 -1
  150. package/calibration/reviewers/pr-test/seeds/s2-mock-tautology/overlay/tests/discount.test.mjs +0 -14
  151. package/calibration/reviewers/pr-test/seeds/s3-missing-branch/expect.json +0 -1
  152. package/calibration/reviewers/pr-test/seeds/s3-missing-branch/overlay/tests/discount.test.mjs +0 -14
  153. package/calibration/reviewers/pr-test/seeds/s4-skipped-red/expect.json +0 -1
  154. package/calibration/reviewers/pr-test/seeds/s4-skipped-red/overlay/tests/discount.test.mjs +0 -17
  155. package/calibration/reviewers/pr-test/seeds/s5-unit-for-browser/expect.json +0 -1
  156. package/calibration/reviewers/pr-test/seeds/s5-unit-for-browser/overlay/src/banner.mjs +0 -29
  157. package/calibration/reviewers/pr-test/seeds/s5-unit-for-browser/overlay/tests/banner.test.mjs +0 -61
  158. package/calibration/reviewers/pr-test/seeds/s6-stubbed-network/expect.json +0 -1
  159. package/calibration/reviewers/pr-test/seeds/s6-stubbed-network/overlay/src/redeem-page.mjs +0 -24
  160. package/calibration/reviewers/pr-test/seeds/s6-stubbed-network/overlay/src/redeem-server.mjs +0 -36
  161. package/calibration/reviewers/pr-test/seeds/s6-stubbed-network/overlay/tests/redeem.e2e.test.mjs +0 -56
  162. package/calibration/reviewers/pr-test/suite.json +0 -1
  163. package/calibration/reviewers/silent-failure-hunter/base/src/sync.mjs +0 -45
  164. package/calibration/reviewers/silent-failure-hunter/base/tests/sync.test.mjs +0 -7
  165. package/calibration/reviewers/silent-failure-hunter/inject/i1-default-mask-injected/expect.json +0 -1
  166. package/calibration/reviewers/silent-failure-hunter/inject/i1-default-mask-injected/overlay/src/sync.mjs +0 -50
  167. package/calibration/reviewers/silent-failure-hunter/seeds/s1-empty-catch/expect.json +0 -1
  168. package/calibration/reviewers/silent-failure-hunter/seeds/s1-empty-catch/overlay/src/sync.mjs +0 -42
  169. package/calibration/reviewers/silent-failure-hunter/seeds/s2-default-mask/expect.json +0 -1
  170. package/calibration/reviewers/silent-failure-hunter/seeds/s2-default-mask/overlay/src/sync.mjs +0 -49
  171. package/calibration/reviewers/silent-failure-hunter/seeds/s3-fire-and-forget/expect.json +0 -1
  172. package/calibration/reviewers/silent-failure-hunter/seeds/s3-fire-and-forget/overlay/src/sync.mjs +0 -38
  173. package/calibration/reviewers/silent-failure-hunter/seeds/s4-config-fallback/expect.json +0 -1
  174. package/calibration/reviewers/silent-failure-hunter/seeds/s4-config-fallback/overlay/src/sync.mjs +0 -49
  175. package/calibration/reviewers/silent-failure-hunter/suite.json +0 -1
  176. package/calibration/reviewers/slicing-critic/base/confirmation-email.md +0 -21
  177. package/calibration/reviewers/slicing-critic/base/coverage.md +0 -6
  178. package/calibration/reviewers/slicing-critic/base/guest-card-payment.md +0 -26
  179. package/calibration/reviewers/slicing-critic/base/recap.json +0 -14
  180. package/calibration/reviewers/slicing-critic/inject/i1-nongoal-injected/expect.json +0 -1
  181. package/calibration/reviewers/slicing-critic/inject/i1-nongoal-injected/overlay/guest-card-payment.md +0 -29
  182. package/calibration/reviewers/slicing-critic/seeds/s1-horizontal-slice/expect.json +0 -1
  183. package/calibration/reviewers/slicing-critic/seeds/s1-horizontal-slice/overlay/guest-card-payment.md +0 -23
  184. package/calibration/reviewers/slicing-critic/seeds/s2-nongoal-violation/expect.json +0 -1
  185. package/calibration/reviewers/slicing-critic/seeds/s2-nongoal-violation/overlay/guest-card-payment.md +0 -27
  186. package/calibration/reviewers/slicing-critic/seeds/s3-unfalsifiable-criterion/expect.json +0 -1
  187. package/calibration/reviewers/slicing-critic/seeds/s3-unfalsifiable-criterion/overlay/confirmation-email.md +0 -19
  188. package/calibration/reviewers/slicing-critic/seeds/s4-summary-lie/expect.json +0 -1
  189. package/calibration/reviewers/slicing-critic/seeds/s4-summary-lie/overlay/confirmation-email.md +0 -19
  190. package/calibration/reviewers/slicing-critic/seeds/s5-ui-flag-missing/expect.json +0 -1
  191. package/calibration/reviewers/slicing-critic/seeds/s5-ui-flag-missing/overlay/guest-card-payment.md +0 -28
  192. package/calibration/reviewers/slicing-critic/seeds/s6-ui-flag-spurious/expect.json +0 -1
  193. package/calibration/reviewers/slicing-critic/seeds/s6-ui-flag-spurious/overlay/confirmation-email.md +0 -22
  194. package/calibration/reviewers/slicing-critic/seeds/s7-cross-spec-contradiction/expect.json +0 -1
  195. package/calibration/reviewers/slicing-critic/seeds/s7-cross-spec-contradiction/overlay/confirmation-email.md +0 -24
  196. package/calibration/reviewers/slicing-critic/suite.json +0 -1
  197. package/calibration/reviewers/type-design/base/src/order.ts +0 -49
  198. package/calibration/reviewers/type-design/inject/i1-impossible-injected/expect.json +0 -1
  199. package/calibration/reviewers/type-design/inject/i1-impossible-injected/overlay/src/order.ts +0 -21
  200. package/calibration/reviewers/type-design/seeds/s1-stringly/expect.json +0 -1
  201. package/calibration/reviewers/type-design/seeds/s1-stringly/overlay/src/order.ts +0 -11
  202. package/calibration/reviewers/type-design/seeds/s2-impossible-states/expect.json +0 -1
  203. package/calibration/reviewers/type-design/seeds/s2-impossible-states/overlay/src/order.ts +0 -20
  204. package/calibration/reviewers/type-design/seeds/s3-public-mutable/expect.json +0 -1
  205. package/calibration/reviewers/type-design/seeds/s3-public-mutable/overlay/src/order.ts +0 -26
  206. package/calibration/reviewers/type-design/seeds/s4-any-leak/expect.json +0 -1
  207. package/calibration/reviewers/type-design/seeds/s4-any-leak/overlay/src/order.ts +0 -29
  208. package/calibration/reviewers/type-design/suite.json +0 -1
  209. package/calibration/skills/decompose/seeds/s1-plain-feature/expect.json +0 -1
  210. package/calibration/skills/decompose/seeds/s1-plain-feature/recap.json +0 -11
  211. package/calibration/skills/decompose/seeds/s2-nongoal-bait/expect.json +0 -1
  212. package/calibration/skills/decompose/seeds/s2-nongoal-bait/recap.json +0 -8
  213. package/calibration/skills/decompose/seeds/s3-duplicated-fact/expect.json +0 -1
  214. package/calibration/skills/decompose/seeds/s3-duplicated-fact/recap.json +0 -11
  215. package/calibration/skills/decompose/seeds/s4-fix-routes-amend/canon/checkout-flow.md +0 -19
  216. package/calibration/skills/decompose/seeds/s4-fix-routes-amend/canon/payment-retry.md +0 -20
  217. package/calibration/skills/decompose/seeds/s4-fix-routes-amend/expect.json +0 -1
  218. package/calibration/skills/decompose/seeds/s4-fix-routes-amend/recap.json +0 -8
  219. package/calibration/skills/decompose/seeds/s5-chore-no-specs/canon/checkout-flow.md +0 -19
  220. package/calibration/skills/decompose/seeds/s5-chore-no-specs/expect.json +0 -1
  221. package/calibration/skills/decompose/seeds/s5-chore-no-specs/recap.json +0 -8
  222. package/calibration/skills/implement/seeds/s1-add-function/plan.body.md +0 -5
  223. package/calibration/skills/implement/seeds/s1-add-function/plan.meta.json +0 -7
  224. package/calibration/skills/implement/seeds/s1-add-function/recap.json +0 -8
  225. package/calibration/skills/implement/seeds/s1-add-function/repo/package.json +0 -1
  226. package/calibration/skills/implement/seeds/s1-add-function/repo/src/clamp.mjs +0 -2
  227. package/calibration/skills/implement/seeds/s1-add-function/spec.body.md +0 -8
  228. package/calibration/skills/implement/seeds/s1-add-function/spec.meta.json +0 -8
  229. package/calibration/skills/implement/seeds/s2-fix-bug/plan.body.md +0 -6
  230. package/calibration/skills/implement/seeds/s2-fix-bug/plan.meta.json +0 -7
  231. package/calibration/skills/implement/seeds/s2-fix-bug/recap.json +0 -8
  232. package/calibration/skills/implement/seeds/s2-fix-bug/repo/package.json +0 -1
  233. package/calibration/skills/implement/seeds/s2-fix-bug/repo/src/slug.mjs +0 -7
  234. package/calibration/skills/implement/seeds/s2-fix-bug/repo/tests/slug.test.mjs +0 -7
  235. package/calibration/skills/implement/seeds/s2-fix-bug/spec.body.md +0 -9
  236. package/calibration/skills/implement/seeds/s2-fix-bug/spec.meta.json +0 -8
  237. package/calibration/skills/implement/seeds/s3-two-steps/plan.body.md +0 -11
  238. package/calibration/skills/implement/seeds/s3-two-steps/plan.meta.json +0 -10
  239. package/calibration/skills/implement/seeds/s3-two-steps/recap.json +0 -8
  240. package/calibration/skills/implement/seeds/s3-two-steps/repo/package.json +0 -1
  241. package/calibration/skills/implement/seeds/s3-two-steps/repo/src/pad.mjs +0 -2
  242. package/calibration/skills/implement/seeds/s3-two-steps/spec.body.md +0 -9
  243. package/calibration/skills/implement/seeds/s3-two-steps/spec.meta.json +0 -11
  244. package/calibration/skills/plan/seeds/s1-two-criteria/expect.json +0 -1
  245. package/calibration/skills/plan/seeds/s1-two-criteria/parent.body.md +0 -10
  246. package/calibration/skills/plan/seeds/s1-two-criteria/parent.meta.json +0 -11
  247. package/calibration/skills/plan/seeds/s1-two-criteria/recap.json +0 -8
  248. package/calibration/skills/plan/seeds/s2-five-criteria/expect.json +0 -1
  249. package/calibration/skills/plan/seeds/s2-five-criteria/parent.body.md +0 -11
  250. package/calibration/skills/plan/seeds/s2-five-criteria/parent.meta.json +0 -14
  251. package/calibration/skills/plan/seeds/s2-five-criteria/recap.json +0 -8
  252. package/calibration/skills/plan/seeds/s3-mixed-needs/expect.json +0 -1
  253. package/calibration/skills/plan/seeds/s3-mixed-needs/parent.body.md +0 -10
  254. package/calibration/skills/plan/seeds/s3-mixed-needs/parent.meta.json +0 -11
  255. package/calibration/skills/plan/seeds/s3-mixed-needs/recap.json +0 -8
  256. package/calibration/skills/plan/seeds/s4-scaffolding-pull/expect.json +0 -1
  257. package/calibration/skills/plan/seeds/s4-scaffolding-pull/parent.body.md +0 -9
  258. package/calibration/skills/plan/seeds/s4-scaffolding-pull/parent.meta.json +0 -10
  259. package/calibration/skills/plan/seeds/s4-scaffolding-pull/recap.json +0 -8
  260. package/calibration.yaml +0 -5
  261. package/dist/calibrate.js +0 -750
  262. package/dist/verbs/calibrate.js +0 -144
@@ -1,84 +1,27 @@
1
1
  import { basename } from 'node:path';
2
- import { TARGETLESS } from './drive-presence.js';
3
- import { handoffLine, resolveDriver } from './harness.js';
4
2
  import { readStream, streamIds } from './journal.js';
5
- import { unmetNeeds } from './needs.js';
6
- import { findById, loadCanon } from './scan.js';
7
- import { pendingTxn } from './txn.js';
8
- import { owedDecisions, parkedGates } from './verbs/next.js';
9
- import { recoverChoice } from './verbs/recover.js';
3
+ import { needsYou, WAIT_KINDS } from './needs-you.js';
4
+ import { loadCanon } from './scan.js';
10
5
  export function runStart(root) {
11
6
  return { lines: new Map(streamIds(root).map((s) => [s, readStream(root, s).length])) };
12
7
  }
13
8
  export function entriesSince(root, start) {
14
9
  return streamIds(root).flatMap((stream) => readStream(root, stream).slice(start.lines.get(stream) ?? 0).map((entry) => ({ stream, entry })));
15
10
  }
16
- const prOf = (line) => /PR #(\d+)/.exec(line)?.[1];
17
11
  // Every `run:` and `then:` line is raw: a command is never kv-escaped (D120).
18
12
  export function driveReport(root, ctx, cfg, start, aside, run) {
19
13
  const canon = loadCanon(root);
20
14
  const since = entriesSince(root, start);
21
15
  const merged = since.filter(({ entry }) => entry.t === 'status' && entry.cause === 'merge')
22
16
  .map(({ entry }) => `merged: ${String(entry.artifact)} · PR #${String(entry.pr)}`);
23
- // The waits, each target once, in the order a human answers them.
24
- const waits = [];
25
- const named = new Set();
26
- const wait = (target, rows) => { named.add(target); waits.push(...rows); };
27
- // A crash no session could recover blocks every write: it is named first (F4).
28
- const txn = pendingTxn(root);
29
- if (txn !== undefined) {
30
- wait('-txn', [`wait: pending transaction · ${txn.op}`, ` run: ${recoverChoice(root, txn).options[0].command}`]);
31
- }
32
- for (const a of aside.filter((x) => x.kind === 'kept' && (x.stop === 'design-look' || x.stop === 'trust-grant'))) {
33
- if (named.has(a.target))
34
- continue;
35
- wait(a.target, a.stop === 'design-look'
36
- ? [`wait: design look · ${a.target}`, ` run: witness design ${a.target} --open`, ` then: witness decide design ${a.target} --show`]
37
- : [`wait: trust grant · ${a.target} · in a terminal · answer each prompt`, ` run: witness gate ${a.gate ?? '<gate>'} ${a.target}`]);
38
- }
39
- for (const u of unmetNeeds(canon)) {
40
- const held = u.type === 'spec' && u.holds.length > 0;
41
- wait(u.doc, [
42
- held ? `wait: held criterion · ${u.doc} · ${u.text} holds ${u.holds.join(' · ')}` : `wait: unmet need · ${u.doc} · ${u.text}`,
43
- ` run: ${u.satisfy}`,
44
- ]);
45
- }
46
- for (const o of owedDecisions(root, canon)) {
47
- if (named.has(o.target))
48
- continue;
49
- wait(o.target, [`wait: decision · ${o.gate} ${o.target}`, ` run: witness decide ${o.gate} ${o.target} --show`]);
50
- }
51
- const driver = resolveDriver(ctx.env, cfg.harness);
52
- for (const a of aside.filter((x) => x.kind === 'conversation' || x.kind === 'merge')) {
53
- if (named.has(a.target))
54
- continue;
55
- if (a.kind === 'conversation') {
56
- // Row 196. A target-less conversation is a grill: of a queued ask, or — with nothing
57
- // queued — of what to build next, which waits on nobody, so it is said and not counted.
58
- const ask = a.target === TARGETLESS ? / --ask (\S+)/.exec(a.line)?.[1] : undefined;
59
- if (a.target === TARGETLESS && ask === undefined) {
60
- waits.push('nothing queued — /witness <what to build> in a chat');
61
- continue;
62
- }
63
- const who = a.target === TARGETLESS ? `brainstorm · ask ${ask}` : a.target;
64
- wait(a.target, [`wait: conversation · ${who}`,
65
- ...(driver.ok ? [` run: ${handoffLine(driver.value.harness, root, undefined)}`] : [])]);
66
- }
67
- else {
68
- const pr = prOf(a.line) ?? (findById(canon, a.target)?.meta.pr !== undefined ? String(findById(canon, a.target).meta.pr) : undefined);
69
- wait(a.target, [`wait: merge · ${a.target}${pr ? ` · PR #${pr}` : ''}`, ...(pr ? [` run: gh pr merge ${pr}`] : [])]);
70
- }
71
- }
72
- const parked = parkedGates(root, canon).flatMap((p) => {
73
- const stopped = readStream(root, p.target)
74
- .filter((e) => e.t === 'human-decision' && e.gate === p.gate)
75
- .map((e) => e).filter((d) => d.decision === 'stop').at(-1);
76
- const why = stopped?.selected === 'policy' && stopped.note ? stopped.note : `parked at ${p.anchor}`;
77
- return [`parked: ${p.target} · ${p.gate} round ${p.round} — ${why}`, ` run: ${p.reopen}`];
78
- });
79
- // A capped target the policy could not park carries no gate (drive.ts): it is stuck too.
80
- const stuck = aside.filter((a) => a.kind === 'stuck' || (a.kind === 'capped' && a.gate === undefined))
81
- .map((a) => `stuck: ${a.target} — ${a.why}`);
17
+ // Row 203. The waits, each target once, in the order a human answers them, then the parked
18
+ // gates and the stuck targets: one derivation, read by the notifier and `witness wait` too.
19
+ const items = needsYou(root, ctx, cfg, canon, aside);
20
+ const waiting = items.filter((i) => WAIT_KINDS.has(i.kind));
21
+ const waits = waiting.flatMap((i) => i.rows);
22
+ const parked = items.filter((i) => i.kind === 'parked').flatMap((i) => i.rows);
23
+ const stuckItems = items.filter((i) => i.kind === 'stuck' || i.kind === 'capped');
24
+ const stuck = stuckItems.flatMap((i) => i.rows);
82
25
  const obligations = since.filter(({ entry }) => entry.t === 'deferral').map(({ entry }) => {
83
26
  const d = entry;
84
27
  return `obligation: ${d.id} · ${d.artifact} · ${d.anchor} — ${d.kind}`;
@@ -93,9 +36,10 @@ export function driveReport(root, ctx, cfg, start, aside, run) {
93
36
  counts[d.selected ?? 'named'] += 1;
94
37
  }
95
38
  const m = merged.length;
96
- const w = named.size;
97
- const p = parkedGates(root, canon).length;
98
- const s = stuck.length;
39
+ // A crash is one wait whatever it names; a notice waits on nobody.
40
+ const w = new Set(waiting.filter((i) => i.notice !== true).map((i) => i.kind === 'pending-txn' ? '-txn' : i.target)).size;
41
+ const p = items.filter((i) => i.kind === 'parked').length;
42
+ const s = stuckItems.length;
99
43
  const tally = `${m} merged · ${w} wait on you · ${p} parked · ${s} stuck`;
100
44
  const lines = [
101
45
  `drive: ${run.stopped !== undefined ? 'stopped' : 'done'} — ${tally}`,
package/dist/drive.js CHANGED
@@ -1,27 +1,33 @@
1
- import { closeSync, constants, fstatSync, mkdirSync, openSync, writeSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
1
+ import { createHash } from 'node:crypto';
2
+ import { closeSync, constants, fstatSync, mkdirSync, openSync, readdirSync, statSync, writeSync } from 'node:fs';
3
+ import { basename, dirname, join } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import { EXIT, main } from './cli.js';
5
- import { loadConfig, loadLocalConfig } from './config.js';
6
+ import { canonPaths, loadConfig, loadLocalConfig } from './config.js';
6
7
  import { withoutSession } from './context.js';
7
8
  import { detectionVariables, resolveJudge } from './harness.js';
8
9
  import { ok, refuse, renderRefusal, v } from './refusal.js';
9
10
  import { findById, loadCanon } from './scan.js';
10
11
  import { NO_CONSOLE_ENV, resolveSpawn, spawn, treeStop } from './spawn.js';
11
12
  import { computeNext, conversationStage } from './verbs/next.js';
12
- import { DRIVE_DEADLINE_ENV, DRIVE_ENV, DRIVE_LOG, DRIVE_LOG_ENV, TARGETLESS } from './drive-presence.js';
13
+ import { DRIVE_DEADLINE_ENV, DRIVE_ENV, DRIVE_LOG, DRIVE_LOG_ENV, TARGETLESS, driveHolder } from './drive-presence.js';
14
+ import { isAlive, pause } from './lock.js';
13
15
  import { ASK_STREAM } from './ask.js';
14
16
  import { KEPT_STOP_NAMES, unmetNeedLine } from './autonomy.js';
15
17
  import { unmetNeeds } from './needs.js';
16
18
  import { capHit, parkAtCap } from './caps.js';
17
19
  import { effortStreams, readStream } from './journal.js';
20
+ import { movesFlow } from './progress.js';
21
+ import { sourced } from './allowlist.js';
18
22
  import { effortOf } from './reviewed.js';
19
- import { vacuousEvidence } from './steps.js';
20
23
  import { pendingTxn } from './txn.js';
21
24
  import { duration, limitIn, realClock, sessionLimit, SINGLE_WAIT_MAX_MS, TOTAL_WAIT_MAX_MS, waitFor, } from './usage.js';
22
25
  import { keepAwake } from './awake.js';
26
+ import { monotonicTicker, sessionClock } from './session-clock.js';
23
27
  import { driveReport, runStart } from './drive-report.js';
24
28
  import { notify } from './notify.js';
29
+ import { writeLive } from './live.js';
30
+ import { needsYou, needsYouToken, WAIT_LABEL } from './needs-you.js';
25
31
  // The rule table is an ORDERED FIRST-MATCH list, on `recommend.ts`'s precedent: a
26
32
  // misrouted action is attributable to one line here rather than to a weighting. Pure over
27
33
  // the NextAction shape — no I/O — so every branch is one `expect` away.
@@ -43,6 +49,11 @@ export function classifyAction(action, root, opts = {}) {
43
49
  const [, , gate, target] = line.split(' ');
44
50
  return { kind: 'decision', gate, target: target ?? action.target };
45
51
  }
52
+ // Row 205 (issue #56). A step whose runner, ship lanes or cmd: need this machine does not
53
+ // trust would only be refused inside the session — the refusal journaled nothing, so drive
54
+ // respawned it to the cap. In both modes it waits for the human, and no session is spent.
55
+ if (action.trust !== undefined && action.trust.length > 0)
56
+ return { kind: 'kept', stop: 'trust-grant', line };
46
57
  // D121: a block is the CLI saying the human is choosing, not being told — so a runnable
47
58
  // line under a block (the recovery fork, `N ready — ranked below`) is still a stop.
48
59
  // Below the decide rule so a gate decision keeps its gate/target rather than its block.
@@ -86,9 +97,8 @@ const EXIT_GRACE_MS = 2_000;
86
97
  // This CLI, for the child. A spawned session shells out to `witness` through
87
98
  // ${WITNESS_BIN:-npx …} in every stage skill, and an unset value means the child resolves
88
99
  // the PUBLISHED version while its parent runs an unpublished one — which the state floor
89
- // then refuses (cli-behind-state). calibrate.ts:520 sets it for its worker for exactly
90
- // this reason. An explicitly set value wins: a session that already knows its bin is
91
- // stating a fact drive has no better answer for.
100
+ // then refuses (cli-behind-state). An explicitly set value wins: a session that already
101
+ // knows its bin is stating a fact drive has no better answer for.
92
102
  function localBin(ctx) {
93
103
  return ctx.env.WITNESS_BIN ?? `node ${join(dirname(fileURLToPath(import.meta.url)), 'bin.js')}`;
94
104
  }
@@ -134,10 +144,9 @@ export function signalSession(child, grouped, env, sig) {
134
144
  // One headless session, in the action's home, streamed to the driver's terminal.
135
145
  //
136
146
  // The harness is the JUDGE ladder's answer (declared first, detection as fallback), not
137
- // the driver's: this is a programmatic spawn like the reviewer battery and the
138
- // calibration worker, not a statement about which CLI a human is typing at. Ambient
139
- // detection deciding what drive spawns would make the same repo drive differently from
140
- // two terminals.
147
+ // the driver's: this is a programmatic spawn like the reviewer battery, not a statement
148
+ // about which CLI a human is typing at. Ambient detection deciding what drive spawns would
149
+ // make the same repo drive differently from two terminals.
141
150
  export async function spawnSession(step, cfg, ctx, spawnN, opts = {}) {
142
151
  const t0 = Date.now();
143
152
  const end = (outcome, code = null, tail = []) => ({ outcome, code, tail, ms: Math.max(1, Date.now() - t0) });
@@ -169,6 +178,8 @@ export async function spawnSession(step, cfg, ctx, spawnN, opts = {}) {
169
178
  delete inherited[variable];
170
179
  const childEnv = {
171
180
  ...inherited, ...env, WITNESS_BIN: localBin(ctx), [DRIVE_ENV]: step.target ?? TARGETLESS,
181
+ // The earliest wall-clock time drive may stop this session — a sleep moves drive's stop
182
+ // later, never earlier (row 210).
172
183
  [DRIVE_DEADLINE_ENV]: String(t0 + cfg.drive.sessionTimeoutMs),
173
184
  };
174
185
  // Row 164: on Windows the agent CLI may be a `.cmd` shim, which only cmd.exe can start.
@@ -223,7 +234,7 @@ export async function spawnSession(step, cfg, ctx, spawnN, opts = {}) {
223
234
  settled = true;
224
235
  if (child.pid !== undefined)
225
236
  LIVE_GROUPS.delete(child.pid);
226
- clearTimeout(timer);
237
+ clock.stop();
227
238
  clearTimeout(killTimer);
228
239
  clearTimeout(grace);
229
240
  opts.signal?.removeEventListener('abort', onAbort);
@@ -231,9 +242,12 @@ export async function spawnSession(step, cfg, ctx, spawnN, opts = {}) {
231
242
  err.flush();
232
243
  child.stdout.destroy();
233
244
  child.stderr.destroy();
234
- resolve(end(o, code, [...tail]));
245
+ resolve({ outcome: o, code, tail: [...tail], ms: Math.max(1, clock.awakeMs()) });
235
246
  };
236
- const timer = setTimeout(() => stop('timeout'), cfg.drive.sessionTimeoutMs);
247
+ const clock = sessionClock(cfg.drive.sessionTimeoutMs, opts.ticker ?? monotonicTicker, {
248
+ expire: () => stop('timeout'),
249
+ slept: (ms) => ctx.out(`${prefix}host slept ${duration(ms)} — not counted against drive.sessionTimeoutMs`),
250
+ });
237
251
  opts.signal?.addEventListener('abort', onAbort, { once: true });
238
252
  child.stdout.setEncoding('utf8');
239
253
  child.stderr.setEncoding('utf8');
@@ -270,14 +284,48 @@ export const DEFAULT_MAX_SPAWNS = 20;
270
284
  // against accounting bugs: 200 is the 203 sessions fewhats ran in the whole 33-day evidence
271
285
  // window (design §2).
272
286
  export const AUTONOMY_MAX_SPAWNS = 200;
287
+ // Row 202 (issue #56). When everything left waits on the human, an autonomous drive pauses
288
+ // instead of quitting: it polls what a human act writes every 5 s and gives up after 12 h with
289
+ // nothing moving. Constants, not settings (no `migrate` for an upgrade); the suite reaches them
290
+ // through the Clock seam, and a CLI-level test bounds the idle limit through an undocumented
291
+ // seam on WITNESS_KEEP_AWAKE_BIN's precedent.
292
+ export const PAUSE_POLL_MS = 5_000;
293
+ const DETACH_LOCK_WAIT_MS = 10_000;
294
+ export const PAUSE_IDLE_MAX_MS = 43_200_000;
295
+ const idleMaxOf = (env) => {
296
+ const v = env.WITNESS_DRIVE_IDLE_MAX_MS;
297
+ return v !== undefined && /^\d+$/.test(v) ? Number(v) : PAUSE_IDLE_MAX_MS;
298
+ };
299
+ // What a human act writes: the journal, canon, the committed config, the trust list and the
300
+ // machine config — each file's size and mtime, hashed. Never drive's own log or its live
301
+ // folder, which it writes itself while paused.
302
+ export function watchSignature(root) {
303
+ const p = canonPaths(root);
304
+ const files = [];
305
+ for (const dir of [join(root, '.witness', 'journal'), join(root, p.specs), join(root, p.plans), join(root, p.designs)]) {
306
+ try {
307
+ for (const n of readdirSync(dir, { recursive: true }))
308
+ files.push(join(dir, n));
309
+ }
310
+ catch { /* absent: nothing to watch there yet */ }
311
+ }
312
+ for (const f of ['witness.config.yaml', join('.witness', 'allow.json'), join('.witness', 'config.local.yaml')])
313
+ files.push(join(root, f));
314
+ const parts = files.sort().map((f) => {
315
+ try {
316
+ const st = statSync(f);
317
+ return st.isFile() ? `${f}:${st.size}:${st.mtimeMs}` : '';
318
+ }
319
+ catch {
320
+ return `${f}:-`;
321
+ }
322
+ });
323
+ return createHash('sha1').update(parts.join('\n')).digest('hex');
324
+ }
273
325
  const STREAM_PREFIX = /^\[\d+ [^\]]*\] /;
274
326
  // What `mergeOwnPr` prints when it leaves the merge to a human (ship.ts), and nothing else.
275
327
  const MERGE_LINE = /^ship: "?merge PR #(\d+) on GitHub when ready/;
276
328
  const streamLines = (root, id) => readStream(root, id).length;
277
- // A refused write is the CLI saying no: it moves nothing (F5). Nor does a vacuous red (row 191,
278
- // final review I3): a session that only re-runs one has done nothing, and counted, it read as
279
- // progress, so the target was respawned until its spawn cap.
280
- const moved = (e) => e.t !== 'write-refused' && !vacuousEvidence(e);
281
329
  // Row 181. Did anything happen for THIS target? A whole-journal count is satisfied by any
282
330
  // other lane's progress, so a stalled flow beside a busy one would spawn until the ceiling.
283
331
  // A target's key is its line, its stream, and the entries in its owning effort's stream that
@@ -296,9 +344,9 @@ function progressKey(root, action, family) {
296
344
  const target = action.target;
297
345
  const effort = effortOf(root, target);
298
346
  const flow = family(target);
299
- const own = readStream(root, target).filter(moved).length;
347
+ const own = readStream(root, target).filter(movesFlow).length;
300
348
  const inEffort = effort !== undefined && effort !== target
301
- ? readStream(root, effort).filter((e) => moved(e) && flow.includes(String(e.artifact))).length
349
+ ? readStream(root, effort).filter((e) => movesFlow(e) && flow.includes(String(e.artifact))).length
302
350
  : 0;
303
351
  return [action.line, own, inEffort].join('\u0000');
304
352
  }
@@ -391,14 +439,39 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
391
439
  // (an ask answered or queued, a need satisfied, a stop decided in a chat) leaves the aside
392
440
  // set and competes for a slot again. One whose next act is the human's again is set aside
393
441
  // anew, under its new key, by the settle pass or the fill that meets it.
442
+ // Row 207: a release is a new chance, so the target's per-run use and its last key go too.
443
+ const release = (key) => {
444
+ aside.delete(key);
445
+ use.delete(key);
446
+ progress.delete(key);
447
+ pauseSince = undefined; // a human act: the idle clock starts over
448
+ // What this target needs of the human next is news (final review): a second trust grant,
449
+ // a stuck again after a retry. Keys are `<kind>:<target>[:…]`, and ids carry no colon.
450
+ for (const k of [...notified])
451
+ if (k.split(':')[1] === key)
452
+ notified.delete(k);
453
+ };
454
+ // A plan that reached its end — merged, abandoned — is no flow any more: its scoped ladder
455
+ // answers with a global rung, so `ownAnswer` would hold its aside forever.
456
+ const ended = (key) => {
457
+ const doc = findById(canonNow, key);
458
+ const status = String(doc?.meta.status);
459
+ return doc?.meta.type === 'plan' && (status === 'done' || status === 'abandoned') ? status : undefined;
460
+ };
394
461
  const takeBack = () => {
395
462
  for (const [key, a] of aside) {
396
463
  if (a.key0 === undefined)
397
464
  continue;
465
+ const over = ended(key);
466
+ if (over !== undefined) {
467
+ release(key);
468
+ ctx.out(`drive: released — ${key} · ${over}`);
469
+ continue;
470
+ }
398
471
  const now = ownNext(key);
399
472
  if (!ownAnswer(key, now) || keyOf(now) === a.key0)
400
473
  continue;
401
- aside.delete(key);
474
+ release(key);
402
475
  ctx.out(`drive: taken back — ${key === TARGETLESS ? 'untargeted work' : key} · ${now.line}`);
403
476
  }
404
477
  };
@@ -410,6 +483,10 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
410
483
  for (const [key, a] of aside) {
411
484
  if (a.key0 === undefined)
412
485
  continue;
486
+ if (ended(key) !== undefined) {
487
+ aside.delete(key);
488
+ continue;
489
+ }
413
490
  const now = ownNext(key);
414
491
  if (!ownAnswer(key, now) || keyOf(now) === a.key0)
415
492
  continue;
@@ -421,8 +498,10 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
421
498
  };
422
499
  const stuck = (key, action) => {
423
500
  ctx.out(`drive: no progress — ${action.line}`);
424
- ctx.out(`help: ${action.target ?? 'untargeted work'} is set aside for this run — read its stream above`);
425
- setAside(key, { kind: 'stuck', line: action.line, why: `no progress on ${action.line}` });
501
+ ctx.out(action.target !== undefined
502
+ ? `help: ${action.target} is set aside until its record moves — read its stream above · after a fix witness cannot see: witness retry ${action.target}`
503
+ : 'help: untargeted work is set aside until its record moves — read its stream above');
504
+ setAside(key, { kind: 'stuck', line: action.line, why: `no progress on ${action.line}`, key0: keyOf(action) });
426
505
  };
427
506
  // A decision is an act too, and it gets the same convergence guard as a spawn: a decision
428
507
  // that executes and journals nothing would otherwise re-render its own block forever.
@@ -436,6 +515,14 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
436
515
  return false;
437
516
  };
438
517
  const standAside = async (step, action, key) => {
518
+ if (step.kind === 'kept') {
519
+ ctx.out(`drive: waits on you — ${action.target ?? 'untargeted work'} · ${KEPT_STOP_NAMES[step.stop]}`);
520
+ setAside(key, {
521
+ kind: 'kept', line: step.line, why: KEPT_STOP_NAMES[step.stop], stop: step.stop,
522
+ ...(action.trust !== undefined ? { trust: action.trust } : {}), key0: keyOf(action),
523
+ });
524
+ return;
525
+ }
439
526
  if (step.kind === 'conversation') {
440
527
  ctx.out(`drive: conversation — ${step.line}`);
441
528
  ctx.out('help: run /witness in a chat — drive takes it back when you are done');
@@ -444,7 +531,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
444
531
  }
445
532
  if (step.kind === 'merge') {
446
533
  ctx.out(`drive: merge — ${step.line}`);
447
- setAside(key, { kind: 'merge', line: step.line, why: 'the merge is a human\'s' });
534
+ setAside(key, { kind: 'merge', line: step.line, why: 'the merge is a human\'s', key0: keyOf(action) });
448
535
  return;
449
536
  }
450
537
  // Under autonomy a `witness decide` line still reaching the fill is a stop the settle
@@ -461,7 +548,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
461
548
  if (r === 'stands')
462
549
  setAside(key, { kind: 'decision', line: action.line, why: action.line, ...(step.gate ? { gate: step.gate } : {}), key0: keyOf(action) });
463
550
  if (r === 'refused')
464
- setAside(key, { kind: 'stuck', line: action.line, why: `decision refused on ${action.line}` });
551
+ setAside(key, { kind: 'stuck', line: action.line, why: `decision refused on ${action.line}`, key0: keyOf(action) });
465
552
  };
466
553
  const launch = (step, action, n) => {
467
554
  const lane = { action, end: Promise.resolve(undefined) };
@@ -519,6 +606,13 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
519
606
  pauseFor(limit);
520
607
  return true;
521
608
  };
609
+ // Final review I3: an aside set when a lane ends keys on the target's state after the session,
610
+ // as the settle pass's do — the line the lane started with may be one the session moved past,
611
+ // which would read as a human's move at the next take-back.
612
+ const keyAfter = (key) => {
613
+ canonNow = loadCanon(root);
614
+ return keyOf(ownNext(key));
615
+ };
522
616
  const settle = (key, lane, end) => {
523
617
  if (end.outcome === 'stopped')
524
618
  return; // the signal's, reported once at the end
@@ -528,7 +622,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
528
622
  use.set(key, { spawns: u.spawns + 1, ms: u.ms + end.ms });
529
623
  if (end.outcome === 'timeout') {
530
624
  ctx.out(`drive: spawn-timeout — ${lane.action.line}`);
531
- setAside(key, { kind: 'stuck', line: lane.action.line, why: `spawn-timeout on ${lane.action.line}` });
625
+ setAside(key, { kind: 'stuck', line: lane.action.line, why: `spawn-timeout on ${lane.action.line}`, key0: keyAfter(key) });
532
626
  return;
533
627
  }
534
628
  if (end.outcome === 'spawn-failed') {
@@ -538,7 +632,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
538
632
  }
539
633
  if (lane.merged !== undefined) {
540
634
  ctx.out(`drive: merge — ${lane.merged}`);
541
- setAside(key, { kind: 'merge', line: lane.merged, why: 'the merge is a human\'s' });
635
+ setAside(key, { kind: 'merge', line: lane.merged, why: 'the merge is a human\'s', key0: keyAfter(key) });
542
636
  }
543
637
  };
544
638
  // Row 180. Under autonomy each round starts with one settle pass over every target no
@@ -561,7 +655,11 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
561
655
  ctx.out(line);
562
656
  if (s.kind === 'kept') {
563
657
  ctx.out(`drive: waits on you — ${r.target} · ${KEPT_STOP_NAMES[s.stop]}`);
564
- setAside(r.target, { kind: 'kept', line: s.line, why: KEPT_STOP_NAMES[s.stop], gate: r.gate, stop: s.stop, key0: keyOf(ownNext(r.target)) });
658
+ const trust = s.untrusted !== undefined ? sourced(cfg, canonNow, r.target, s.untrusted) : undefined;
659
+ setAside(r.target, {
660
+ kind: 'kept', line: s.line, why: KEPT_STOP_NAMES[s.stop], gate: r.gate, stop: s.stop,
661
+ ...(trust !== undefined ? { trust } : {}), key0: keyOf(ownNext(r.target)),
662
+ });
565
663
  }
566
664
  else if (s.kind === 'left') {
567
665
  ctx.out(`drive: waits on you — ${r.target} · decision · ${s.why}`);
@@ -600,20 +698,104 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
600
698
  if (parked.parked) {
601
699
  ctx.out(`drive: parked — ${action.target} · ${hit.note}`);
602
700
  const gate = hit.gate ?? lastRunGate(readStream(root, action.target));
603
- setAside(key, { kind: 'capped', line: action.line, why: hit.note, ...(gate ? { gate } : {}) });
701
+ setAside(key, { kind: 'capped', line: action.line, why: hit.note, ...(gate ? { gate } : {}), key0: keyOf(action) });
604
702
  }
605
703
  else {
606
704
  const why = `${hit.note} · ${parked.why}`;
607
705
  ctx.out(`drive: capped — ${action.target} · ${why}`);
608
- setAside(key, { kind: 'capped', line: action.line, why });
706
+ setAside(key, { kind: 'capped', line: action.line, why, key0: keyOf(action) });
609
707
  }
610
708
  return true;
611
709
  };
612
710
  const start = runStart(root);
613
- const awake = keepAwake(ctx.env, process.platform, process.pid);
614
- ctx.out(awake.command !== undefined
615
- ? `keep-awake: ${awake.command} — a closed lid on battery still sleeps`
711
+ // Row 211. A helper that dies while drive still holds it says so; once a signal is stopping
712
+ // drive, the helper's end is that signal's, and no news.
713
+ const lostAwake = (why) => {
714
+ if (signalled === undefined)
715
+ ctx.out(`keep-awake: lost — ${why} · keep the host awake yourself`);
716
+ };
717
+ let awake = keepAwake(ctx.env, process.platform, process.pid, lostAwake);
718
+ let awakeHeld = true;
719
+ ctx.out(awake.shown !== undefined
720
+ ? `keep-awake: ${awake.shown}`
616
721
  : `keep-awake: none on ${process.platform} — keep the host awake yourself`);
722
+ // Row 182, amended by row 202: held while a session runs, released while drive waits on the
723
+ // human — a paused drive lets the machine sleep — and taken again before the next spawn.
724
+ const holdAwake = () => {
725
+ if (awakeHeld)
726
+ return;
727
+ awake = keepAwake(ctx.env, process.platform, process.pid, lostAwake);
728
+ awakeHeld = true;
729
+ };
730
+ const releaseAwake = () => {
731
+ if (!awakeHeld)
732
+ return;
733
+ awake.stop();
734
+ awakeHeld = false;
735
+ };
736
+ // Row 203. Drive's set-asides, published for a chat waiting beside it: ids and kinds only. A
737
+ // grill with nothing queued waits on nobody and is not published.
738
+ const notice = (a) => a.target === TARGETLESS && a.kind === 'conversation' && !/ --ask /.test(a.line);
739
+ const publish = (ended) => {
740
+ if (!autonomous)
741
+ return;
742
+ const asides = [...aside.values()].filter((a) => !notice(a)).map((a) => ({
743
+ target: a.target, kind: a.kind, ...(a.gate !== undefined ? { gate: a.gate } : {}), ...(a.stop !== undefined ? { stop: a.stop } : {}),
744
+ }));
745
+ writeLive(root, { pid: process.pid, asides, ...(ended !== undefined ? { ended } : {}) });
746
+ };
747
+ // Row 203 (Q2). Each item that newly needs the human is notified once per run (n5), a burst
748
+ // as one notification, started in the background so no round waits on it. Mid-run, an item
749
+ // whose flow a session is working on is that session's to settle, and a crash is drive's own
750
+ // to recover; both are said only once drive pauses.
751
+ const notified = new Set();
752
+ const busy = (t) => [...lanes.keys()].some((l) => l === t || family(l).includes(t) || family(t).includes(l));
753
+ const notifyNew = (items) => {
754
+ const fresh = items.filter((i) => i.notice !== true && !notified.has(i.key));
755
+ if (fresh.length === 0)
756
+ return;
757
+ for (const i of fresh)
758
+ notified.add(i.key);
759
+ const named = fresh.slice(0, 3).map((i) => i.kind === 'pending-txn' ? WAIT_LABEL[i.kind] : `${WAIT_LABEL[i.kind]} · ${i.target}`);
760
+ const local = loadLocalConfig(root);
761
+ notify(local.ok ? local.value.notify : undefined, 'witness drive', `witness · ${basename(root)}: ${named.join(' · ')}${fresh.length > 3 ? ` (+${fresh.length - 3})` : ''}`, process.platform, { wait: false });
762
+ };
763
+ const owed = () => needsYou(root, ctx, cfg, loadCanon(root), [...aside.values()]);
764
+ // Row 202. Everything left waits on the human: say what, notify, let the machine sleep, and
765
+ // watch for the act. A change runs a round as usual (take-back, settle pass, fill); a change
766
+ // that releases nothing re-enters the pause silently. True to run a round, false to end.
767
+ const idleMax = idleMaxOf(ctx.env);
768
+ let pauseSince;
769
+ let pausePrinted;
770
+ // Final review (b) I3: the signature the round began with. A human act that lands during the
771
+ // round — after its take-back, before the pause — differs from it, and resumes at once.
772
+ let roundSignature = '';
773
+ const pauseForHuman = async () => {
774
+ const items = owed().filter((i) => i.notice !== true);
775
+ const token = needsYouToken(items);
776
+ if (token !== pausePrinted) {
777
+ ctx.out(`drive: waiting on you — ${items.length} item(s)`);
778
+ items.flatMap((i) => i.rows).forEach((l) => ctx.out(l));
779
+ pausePrinted = token;
780
+ }
781
+ notifyNew(items);
782
+ releaseAwake();
783
+ publish();
784
+ pauseSince ??= clock.now();
785
+ const signature = roundSignature;
786
+ for (;;) {
787
+ if (watchSignature(root) !== signature)
788
+ return true;
789
+ if (clock.now() - pauseSince >= idleMax) {
790
+ ctx.out(`drive: idle limit — waited ${duration(idleMax)} on you · the run ends`);
791
+ stop = 'idle-limit';
792
+ return false;
793
+ }
794
+ await Promise.race([clock.sleep(PAUSE_POLL_MS), aborted]);
795
+ if (signalled !== undefined)
796
+ return false;
797
+ }
798
+ };
617
799
  // Final review F9. Autonomy is re-read from the committed config before every round, on
618
800
  // A1's precedent (ship re-reads it at merge time): a human who turns it off mid-run takes
619
801
  // the wheel at once — no stop of theirs is settled, and no new session starts.
@@ -629,8 +811,11 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
629
811
  };
630
812
  process.on('SIGINT', onSignal);
631
813
  process.on('SIGTERM', onSignal);
814
+ publish();
632
815
  try {
633
816
  for (;;) {
817
+ if (autonomous)
818
+ roundSignature = watchSignature(root);
634
819
  stillAutonomous();
635
820
  canonNow = loadCanon(root);
636
821
  // A run that is stopping fills nothing more, so a target released now would be set aside
@@ -676,13 +861,22 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
676
861
  if (unmoved(key, action))
677
862
  continue;
678
863
  spawns += 1;
864
+ holdAwake();
865
+ pauseSince = undefined;
679
866
  lanes.set(key, launch(step, action, spawns));
680
867
  }
868
+ if (autonomous) {
869
+ publish();
870
+ notifyNew(owed().filter((i) => i.kind !== 'pending-txn' && !busy(i.target)));
871
+ }
681
872
  if (lanes.size === 0) {
682
873
  if (!stop && !signalled && pausedUntil > clock.now()) {
683
874
  await Promise.race([clock.sleep(pausedUntil - clock.now()), aborted]);
684
875
  continue;
685
876
  }
877
+ // Row 202. Not --manual: there the human is at drive's prompt, and the run ends as before.
878
+ if (autonomous && !stop && !signalled && [...aside.values()].some((a) => !notice(a)) && await pauseForHuman())
879
+ continue;
686
880
  break;
687
881
  }
688
882
  const { key, end } = await Promise.race([...lanes].map(([k, l]) => l.end.then((e) => ({ key: k, end: e }))));
@@ -695,7 +889,8 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
695
889
  ctx.out(`drive: idle — ${idle}`);
696
890
  // Row 184. One report when nothing else can move, and for an autonomous run one
697
891
  // notification — a human at a TTY prompt is already watching.
698
- const stopped = signalled !== undefined ? `signal ${signalled}` : stop;
892
+ // The idle limit is no failure: the run waited on the human as long as it could.
893
+ const stopped = signalled !== undefined ? `signal ${signalled}` : stop === 'idle-limit' ? undefined : stop;
699
894
  refreshAside();
700
895
  const report = driveReport(root, ctx, cfg, start, [...aside.values()], { autonomous, ...(stopped ? { stopped } : {}) });
701
896
  report.lines.forEach((l) => ctx.out(l));
@@ -712,7 +907,8 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
712
907
  finally {
713
908
  process.removeListener('SIGINT', onSignal);
714
909
  process.removeListener('SIGTERM', onSignal);
715
- awake.stop();
910
+ publish(signalled !== undefined ? 'signal' : stop ?? 'done');
911
+ releaseAwake();
716
912
  }
717
913
  }
718
914
  // Row 180. `--detach`: this CLI again, as `witness drive <args>`, in the background at the
@@ -749,6 +945,14 @@ export function detachDrive(root, ctx, args) {
749
945
  return refuse([v('--detach', 'spawn-failed', file, 'a runnable witness CLI')]);
750
946
  child.on('error', () => { });
751
947
  child.unref();
948
+ // Final review: return once the child holds the drive lock (or has died, or a bound passed),
949
+ // so a chat's `wait` started right after it never reads the drive as stopped — the previous
950
+ // run's end record would otherwise answer for a drive that is only starting.
951
+ const deadline = Date.now() + DETACH_LOCK_WAIT_MS;
952
+ // Any live holder is this child's (detach refuses while a drive runs); under a WITNESS_BIN
953
+ // wrapper the lock's pid may be a process the wrapper started.
954
+ while (Date.now() < deadline && driveHolder(root) === undefined && isAlive(child.pid))
955
+ pause(50);
752
956
  return ok({ pid: child.pid, log });
753
957
  }
754
958
  finally {