@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
@@ -0,0 +1,134 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { EXIT } from '../cli.js';
3
+ import { loadConfig } from '../config.js';
4
+ import { PAUSE_IDLE_MAX_MS } from '../drive.js';
5
+ import { driveHolder, sessionMarker } from '../drive-presence.js';
6
+ import { resolveDriver } from '../harness.js';
7
+ import { primaryRoot } from '../gitio.js';
8
+ import { lastEnd, liveDrive, takeWaiter, waiterState } from '../live.js';
9
+ import { needsYou, needsYouToken } from '../needs-you.js';
10
+ import { renderRefusal, v } from '../refusal.js';
11
+ import { findById, loadCanon } from '../scan.js';
12
+ import { prState } from '../stamp.js';
13
+ import { duration, realClock } from '../usage.js';
14
+ import { computeNext, driveHasWork } from './next.js';
15
+ // Row 204. The chat sleeps until something new needs the human, and is woken: on Claude Code
16
+ // this runs in the background and its exit re-invokes the chat; on Pi witness's add-on runs it
17
+ // and posts what it printed. It returns when something joins the needs-you list (an item the
18
+ // human settled never wakes the chat), when the drive it waits beside is gone with work left —
19
+ // the chat never restarts drive itself — when a merge left to the human landed on GitHub, or
20
+ // when a newer chat took over. It journals nothing, and every line it prints is rendered here:
21
+ // from the live folder only validated ids and kinds are used.
22
+ export const WAIT_POLL_MS = 5_000;
23
+ export const WAIT_PR_POLL_MS = 120_000;
24
+ const WHY = {
25
+ 'idle-limit': `waited ${duration(PAUSE_IDLE_MAX_MS)} on you`,
26
+ ceiling: 'spawn ceiling',
27
+ usage: 'usage limit',
28
+ 'autonomy-off': 'autonomy is off',
29
+ 'spawn-failed': 'this machine could not start a session',
30
+ signal: 'stopped by a signal',
31
+ done: 'its run ended',
32
+ };
33
+ export async function waitLoop(root, ctx, cfg, opts, clock) {
34
+ const me = process.pid;
35
+ // The chat this wait belongs to, by its harness's session variable (final review C2).
36
+ const driver = resolveDriver(ctx.env, cfg.harness);
37
+ const session = driver.ok ? ctx.env[driver.value.harness.session] : undefined;
38
+ takeWaiter(root, me, session); // one waiter per repo: the newest
39
+ const read = () => {
40
+ const canon = loadCanon(root);
41
+ return { canon, items: needsYou(root, ctx, cfg, canon, liveDrive(root, canon)?.asides ?? []).filter((i) => i.notice !== true) };
42
+ };
43
+ let { canon, items } = read();
44
+ const say = (head, rows) => {
45
+ ctx.out(head);
46
+ rows.forEach((l) => ctx.out(l));
47
+ ctx.out(`token: ${needsYouToken(items)}`);
48
+ return EXIT.OK;
49
+ };
50
+ // The token names the list the chat last saw: anything else is news, said at once.
51
+ if (opts.since !== undefined && needsYouToken(items) !== opts.since) {
52
+ return say(`wait: needs you — ${items.length} item(s)`, items.flatMap((i) => i.rows));
53
+ }
54
+ const seen = new Set(items.map((i) => i.key));
55
+ let prAt = clock.now();
56
+ for (;;) {
57
+ // Superseded for good: the engine row tells that chat never to wait again, so two chats
58
+ // never trade the lock.
59
+ // This chat's own newer wait only ends this one.
60
+ const state = waiterState(root, me, session);
61
+ if (state === 'replaced') {
62
+ ctx.out("wait: replaced by this chat's newer wait");
63
+ return EXIT.OK;
64
+ }
65
+ if (state === 'taken') {
66
+ ctx.out('wait: taken over by another chat');
67
+ return EXIT.OK;
68
+ }
69
+ // A 0.24.x drive writes no live file but holds the lock: running, its waits unknown.
70
+ if (driveHolder(root) === undefined) {
71
+ if (driveHasWork(root, ctx, canon, cfg, computeNext(root, ctx, canon, cfg))) {
72
+ const end = lastEnd(root, canon);
73
+ return say(`wait: drive stopped — ${end !== undefined ? WHY[end] : 'ended unexpectedly'}`, []);
74
+ }
75
+ if (items.length === 0) {
76
+ ctx.out('wait: nothing owed');
77
+ return EXIT.OK;
78
+ }
79
+ }
80
+ const fresh = items.filter((i) => !seen.has(i.key));
81
+ if (fresh.length > 0)
82
+ return say(`wait: needs you — ${fresh.length} item(s)`, fresh.flatMap((i) => i.rows));
83
+ for (const k of [...seen])
84
+ if (!items.some((i) => i.key === k))
85
+ seen.delete(k); // settled: silent
86
+ // A merge left to the human: drive stamps nothing, so the chat is told and its `next`
87
+ // stamps it. Read-only and slow.
88
+ if (clock.now() - prAt >= WAIT_PR_POLL_MS) {
89
+ prAt = clock.now();
90
+ for (const i of items.filter((x) => x.kind === 'merge')) {
91
+ const pr = findById(canon, i.target)?.meta.pr;
92
+ if (pr !== undefined && prState(ctx, root, Number(pr)) === 'MERGED') {
93
+ return say(`wait: merged on GitHub — ${i.target} · PR #${Number(pr)}`, []);
94
+ }
95
+ }
96
+ }
97
+ await clock.sleep(WAIT_POLL_MS);
98
+ ({ canon, items } = read());
99
+ }
100
+ }
101
+ export async function run(ctx, argv) {
102
+ let since;
103
+ try {
104
+ since = parseArgs({ args: argv, options: { since: { type: 'string' } } }).values.since;
105
+ }
106
+ catch (e) {
107
+ renderRefusal([v('usage', 'bad-flag', e.message, 'witness wait [--since <token>]')]).forEach((l) => ctx.err(l));
108
+ return EXIT.REFUSED;
109
+ }
110
+ if (since !== undefined && !/^[0-9a-f]{12}$/.test(since)) {
111
+ renderRefusal([v('--since', 'bad-token', since, 'the 12-hex token a wait: line printed')]).forEach((l) => ctx.err(l));
112
+ return EXIT.REFUSED;
113
+ }
114
+ const marker = sessionMarker(ctx.env);
115
+ if (marker !== undefined) {
116
+ renderRefusal([v('wait', 'wait-in-session', marker, "the human's chat")]).forEach((l) => ctx.err(l));
117
+ return EXIT.REFUSED;
118
+ }
119
+ const rootR = primaryRoot(ctx.cwd);
120
+ if (!rootR.ok) {
121
+ renderRefusal(rootR.violations).forEach((l) => ctx.err(l));
122
+ return EXIT.REFUSED;
123
+ }
124
+ const cfgR = loadConfig(rootR.value);
125
+ if (!cfgR.ok) {
126
+ renderRefusal(cfgR.violations).forEach((l) => ctx.err(l));
127
+ return EXIT.REFUSED;
128
+ }
129
+ if (!cfgR.value.autonomy) {
130
+ renderRefusal([v('wait', 'needs-autonomy', 'autonomy off', 'autonomy: on in witness.config.yaml')]).forEach((l) => ctx.err(l));
131
+ return EXIT.REFUSED;
132
+ }
133
+ return waitLoop(rootR.value, ctx, cfgR.value, since !== undefined ? { since } : {}, realClock);
134
+ }
package/dist/verdict.js CHANGED
@@ -30,7 +30,7 @@ export function parseVerdict(raw) {
30
30
  obj.findings.forEach((f, i) => {
31
31
  const item = f;
32
32
  if (typeof item?.blocking !== 'boolean')
33
- violations.push(v(`findings[${i}].blocking`, 'blocking-shape', String(item?.blocking), 'true | false — the one calibrated bit'));
33
+ violations.push(v(`findings[${i}].blocking`, 'blocking-shape', String(item?.blocking), 'true | false — whether this finding blocks the gate'));
34
34
  if (!isAnchor(item?.anchor))
35
35
  violations.push(v(`findings[${i}].anchor`, 'anchor-shape', JSON.stringify(item?.anchor), 'a heading path, file[#symbol], or {kind: "omission", scope}'));
36
36
  if (typeof item?.claim !== 'string' || item.claim.trim() === '')
@@ -140,6 +140,8 @@ export function sectionText(body, segments) {
140
140
  }
141
141
  return lines.slice(cursor, end).join('\n').replace(/\s+$/, '');
142
142
  }
143
+ // Every path a tree review counts as changed: the diff vs base, plus a delta floor's (row 208).
144
+ const changedOf = (r) => r.floor ? [...r.files, ...r.floor.paths] : r.files;
143
145
  function safeRel(rel) {
144
146
  return !isAbsolute(rel) && !normalize(rel).split(/[\\/]/).includes('..');
145
147
  }
@@ -224,7 +226,7 @@ export function resolveAnchor(anchor, reviewed) {
224
226
  return `omission scope escapes the reviewed tree: ${scope}`;
225
227
  // D162: a changed path is reviewed content even when nothing is left on disk (a deleted
226
228
  // file's un-migrated export is an omission scoped exactly there).
227
- if (reviewed.kind === 'tree' && reviewed.files.includes(scope))
229
+ if (reviewed.kind === 'tree' && changedOf(reviewed).includes(scope))
228
230
  return undefined;
229
231
  return existsSync(join(reviewed.root, scope))
230
232
  ? undefined
@@ -234,7 +236,7 @@ export function resolveAnchor(anchor, reviewed) {
234
236
  const canon = reviewed.canonRoot !== undefined && reviewed.canonDirs !== undefined
235
237
  ? { root: reviewed.canonRoot, dirs: reviewed.canonDirs }
236
238
  : undefined;
237
- return resolveCodeAnchor(anchor, reviewed.root, reviewed.files, canon);
239
+ return resolveCodeAnchor(anchor, reviewed.root, changedOf(reviewed), canon);
238
240
  }
239
241
  const segments = anchor.split(' > ');
240
242
  if (!segments[0].startsWith('#')) {
@@ -306,13 +308,17 @@ export function verdictViolations(verdict, reviewed) {
306
308
  }
307
309
  }
308
310
  else {
311
+ const floor = reviewed.floor;
312
+ const pool = floor?.paths ?? reviewed.files;
309
313
  const distinct = new Set(verdict.coverage
310
314
  .filter((c) => typeof c.anchor === 'string')
311
315
  .map((c) => c.anchor.split('#')[0] ?? '')
312
- .filter((f) => reviewed.files.includes(f)));
313
- const want = Math.min(5, reviewed.files.length);
316
+ .filter((f) => pool.includes(f)));
317
+ const want = Math.min(5, pool.length);
314
318
  if (distinct.size < want) {
315
- violations.push(v('coverage', 'coverage-minimum', `${distinct.size} distinct changed files covered`, `≥ ${want} coverage anchors naming distinct changed files`));
319
+ violations.push(floor
320
+ ? v('coverage', 'coverage-minimum', `${distinct.size} distinct files the change touched covered`, `≥ ${want} coverage anchors naming distinct files listed under "Files changed since round ${floor.round}"`)
321
+ : v('coverage', 'coverage-minimum', `${distinct.size} distinct changed files covered`, `≥ ${want} coverage anchors naming distinct changed files`));
316
322
  }
317
323
  }
318
324
  return violations;
package/dist/worktree.js CHANGED
@@ -58,8 +58,9 @@ export function ensureExcluded(root) {
58
58
  // screens are witnessed evidence, regenerable, never committed — ignored in every
59
59
  // worktree so they stay out of changedFiles() and the reviewed tree-sha. Drafts (row 199)
60
60
  // are a conversation's local memory, never committed: a repo whose .gitignore predates
61
- // them would otherwise show each one to `git status` and to a human's `git add -A`
62
- const missing = ['.witness/worktrees/', '.witness/screens/', '.witness/drafts/'].filter((l) => !lines.includes(l));
61
+ // them would otherwise show each one to `git status` and to a human's `git add -A`; drive's
62
+ // live folder (row 203) is the same kind
63
+ const missing = ['.witness/worktrees/', '.witness/screens/', '.witness/drafts/', '.witness/live/'].filter((l) => !lines.includes(l));
63
64
  // A file a human left without a final newline keeps its last line whole.
64
65
  const sep = current !== '' && !current.endsWith('\n') ? '\n' : '';
65
66
  if (missing.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popovych.co/witness",
3
- "version": "0.24.2",
3
+ "version": "0.26.0",
4
4
  "description": "Evidence-gated spec-driven development pipeline for AI coding agents: brainstorm to PR in six stages, where specs are state, plans are motion, and no transition passes without evidence. Drives from Claude Code or Pi.",
5
5
  "keywords": [
6
6
  "spec-driven-development",
@@ -46,8 +46,6 @@
46
46
  "files": [
47
47
  "dist",
48
48
  "prompts",
49
- "calibration.yaml",
50
- "calibration",
51
49
  "plugin",
52
50
  "LICENSES",
53
51
  "NOTICE.md"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "witness",
3
3
  "description": "Spec-driven development with evidence gates: brainstorm → PR through six stages and five gates. Skills author, the pinned witness CLI writes state and witnesses evidence; gates stop where judgment is owed.",
4
- "version": "0.24.2",
4
+ "version": "0.26.0",
5
5
  "author": {
6
6
  "name": "Kostiantyn Popovych"
7
7
  },
@@ -12,7 +12,7 @@ Any other words in `$ARGUMENTS` are the human's ask: run `$WITNESS ask "<those w
12
12
  Resolve the CLI once:
13
13
 
14
14
  ```bash
15
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
15
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
16
16
  ```
17
17
 
18
18
  If the repo has no `witness.config.yaml`, run `$WITNESS init` first (one bootstrap commit), then proceed. If init or any verb refuses on a dirty tree, the human commits or cleans it — **never `git commit` yourself, anywhere, at any stage**: the CLI makes its own state commits, and the ship phase makes the sole code commit.
@@ -27,13 +27,22 @@ Every turn is `witness next`, read, act on the first matching row, repeat:
27
27
 
28
28
  | Signal | Action |
29
29
  |---|---|
30
- | `kept-stop: trust grant` or `kept-stop: unmet need` lines are printed above `next:` | The human settles these outside this chat — a trust grant in a terminal, an unmet need with its `witness satisfy` command: render each verbatim once and never ask about them. A `kept-stop: design look` line is the chat's own stop: the `witness decide` row below shows it. Then keep matching the rows below — they act on `next:`. |
31
- | `launch:` is printed and this session is not `--manual`-armed | Autonomy is on and no `witness drive` runs for this repo. Run the `launch:` command via Bash as you run a `next:` line. It starts drive in the background and prints a `watch:` line; print it for the human. Then, if `next:` names `witness decide`, or `stage:` is `brainstorm` or `design`, act on it by the rows below — this chat keeps the human's work while drive runs the rest; otherwise **END YOUR TURN**: every other stage is drive's, which starts every session from here and reports when nothing else can move. |
32
- | `watch:` is printed and no `launch:` | A `witness drive` already runs this repo. Print the `watch:` line for the human. Then, if `next:` names `witness decide`, or `stage:` is `brainstorm` or `design`, act on it by the rows below — this chat keeps the human's work while drive runs the rest; otherwise **END YOUR TURN**: every other stage is drive's. |
30
+ | `kept-stop: trust grant` lines are printed above `next:` | Answered in this chat. Show each command and its source exactly as printed; the `next: witness trust` or `witness decide` row below asks the human and ends the turn. For each command the human **names** ("trust pnpm test"), run the grant printed after its `·` — `witness trust <target>` with a `--cmd` naming that one command — byte-for-byte: a bare "y" grants nothing, and a command they did not name is never granted. A line that says `never granted here` cannot be granted: say so. Then keep matching the rows below — a `launch:` still starts drive for the work that needs no grant. |
31
+ | `waiting:` lines are printed above `next:` | Under autonomy: what only the human can move and no `next:` routes — a target drive set aside as stuck or capped, a merge, a parked gate. Tell the human each once, with its command; run a command only when they ask for it (`witness retry <target>` after a fix witness cannot see, for example). Then keep matching the rows below. |
32
+ | `kept-stop: unmet need` lines are printed above `next:` | Answered in this chat, one need at a time: show its text and ask whether it is done. On "done", run the `witness satisfy …` text printed after its `·`; on "not yet", leave it — it does not wake this chat again. Then keep matching the rows below — they act on `next:`. A `kept-stop: design look` line is the chat's own stop: the `witness decide` row below shows it. |
33
+ | `launch:` is printed and this session is not `--manual`-armed | Autonomy is on and no `witness drive` runs for this repo. Run the `launch:` command via Bash as you run a `next:` line. It starts drive in the background and prints a `watch:` line; print it for the human. Then, if `next:` names `witness decide` or `witness trust`, or `stage:` is `brainstorm` or `design`, act on it by the rows below — this chat keeps the human's work while drive runs the rest; every other stage is drive's, which starts every session from here. Otherwise wait, by the `wait-mode:` line: `background` — run the `wait:` command in the background (Claude Code: the Bash tool's `run_in_background`) and **END YOUR TURN**, and its exit wakes this chat; `add-on` — **END YOUR TURN**, and witness's add-on wakes this chat; `foreground` — run the `wait:` command and act on what it prints. With no `wait:` line, **END YOUR TURN**. |
34
+ | `watch:` is printed and no `launch:` | A `witness drive` already runs this repo. Print the `watch:` line for the human. Then, if `next:` names `witness decide` or `witness trust`, or `stage:` is `brainstorm` or `design`, act on it by the rows below — this chat keeps the human's work while drive runs the rest; every other stage is drive's. Otherwise wait, by the `wait-mode:` line: `background` — run the `wait:` command in the background (Claude Code: the Bash tool's `run_in_background`) and **END YOUR TURN**, and its exit wakes this chat; `add-on` — **END YOUR TURN**, and witness's add-on wakes this chat; `foreground` — run the `wait:` command and act on what it prints. With no `wait:` line, **END YOUR TURN**. |
33
35
  | `drive: done` is printed | `witness drive` started this session for one target and that target needs nothing more from it. **END YOUR TURN**. |
36
+ | `wait: needs you` is printed | Something new needs the human. Tell the human the rows it printed, then run `$WITNESS next` and act on the first item it routes, one at a time; after the human's answer, loop. |
37
+ | `wait: drive stopped — <why>` is printed | Drive is gone with work left. Tell the human, with the why, and **END YOUR TURN** — never restart drive yourself. When they say "go", run `$WITNESS next`: its `launch:` restarts it. |
38
+ | `wait: replaced by this chat's newer wait` is printed | A newer wait of this same chat now runs. **END YOUR TURN** — that wait wakes you. |
39
+ | `wait: taken over by another chat` is printed | A newer `/witness` chat now waits for this repo. **END YOUR TURN**, and never wait again in this chat. |
40
+ | `wait: merged on GitHub` is printed | A merge left to the human landed. Run `$WITNESS next` — its stamp records the merge — and loop. |
41
+ | `wait: nothing owed` is printed | Nothing is left for drive or the human. **END YOUR TURN**. |
34
42
  | a `relay:` line is printed with no `run:` (by `next`, `gate`, `decide` or `ship`) | This session reached its context limit where the journal carries the position. Print the `relay:` line verbatim, say the work continues in a fresh session in this directory, and **END YOUR TURN**. Leave the `next:` action to that session: it re-derives position from the CLI. |
35
43
  | A `choose:` block is printed (`note:` says `N ready — ranked below`) | Several specs are ready and the CLI has ranked them. Render the whole block verbatim and in full — the recommendation, its why, each alternative's when and tradeoff, and the `judge-first:` line — then ask the human which to plan. Then use the `witness-plan` skill with the id they name. Never collapse the block to a bare list of ids: the ranking and its costs are the part they are deciding with. |
36
44
  | `next:` names `witness decide` | A gate is stopped and the decision is the human's. Run `$WITNESS decide <gate> <target> --show`, render everything it emits verbatim and in full — the checks, the findings, and its ranked options — and **END YOUR TURN**. Never substitute a command set you remember: it is wrong at the round bound, in the reopened and stale states, and wherever a repair grant is unspent. Never run `--approve`, `--revise` or `--stop` on your own judgment. If the human answers a `design look` stop with a note that changes what the screen does, use the `witness-design` skill's **A behavior answer**. |
45
+ | `next:` names `witness trust` | A command this step runs is not trusted on this machine. Run the line: it lists each command with its source and grants nothing. Ask the human which to trust; for each command they **name**, run its `run: witness trust … --cmd …` line from that listing, byte-for-byte — a bare "y" grants nothing. **END YOUR TURN** to wait for their answer. |
37
46
  | a `run:` line is printed | This stage belongs to a different session; the CLI already compared `home:` against your cwd. Print the `run:` line verbatim for the human (if this session is `--manual`-armed, change the argument to `'/witness --manual'`), say that work continues in the fresh session, and **END YOUR TURN**. Never use a stage skill or run the `next:` command from the wrong `home:` — a fresh session is the execution model, and it is the only one. A `home:` line with **no** `run:` under it means you are already there: read on and act, unless a `relay:` printed alone (its row is above). |
38
47
  | `stage: brainstorm` | Use the `witness-brainstorm` skill — with `target` (the effort) when `next` printed one: that is an amendment. |
39
48
  | `stage: decompose` | Use the `witness-decompose` skill with `target` (the effort slug). |
@@ -50,6 +59,8 @@ Every turn is `witness next`, read, act on the first matching row, repeat:
50
59
  - **Decisions are the CLI's.** It settles each stop itself — through its policy, or the arbiter it launches — and prints who decided (`decided: … · policy` or `· arbiter`). Never run `witness decide`. Outside the grill and the design session, which stay conversations, never end your turn to ask and never put options of your own to the human: when a stage owes a call of yours, make it, state it in one line, and continue.
51
60
  - **A `witness decide` line from `next` belongs to a human.** The CLI left that stop for a person, and the `kept-stop:` line or the refusal above it says why. Run `$WITNESS decide <gate> <target> --show`, render it verbatim, name the human's act, and END YOUR TURN.
52
61
  - **The merge is the CLI's.** `witness ship` merges its own PR on green CI and prints `merged:`. You still never merge.
62
+ - **Trust grants and unmet needs are answered here.** The human names each command to trust, and you run its `--cmd` grant; a "done" for a need runs its `witness satisfy`. Never grant a command they did not name — no session grants trust.
63
+ - **The chat waits instead of ending for good.** With nothing for the human and drive at work, `next` prints a `wait:` line and its `wait-mode:`; wait as its row says, and act on what wakes you. One waiting chat per repo: the newest takes over.
53
64
 
54
65
  `run:` handoffs, relays (a `relay:` with or without `run:`), refusals you cannot mechanically repair and no progress end your turn exactly as above.
55
66
 
@@ -59,7 +70,7 @@ Every turn is `witness next`, read, act on the first matching row, repeat:
59
70
  - A `decide` line surfaced — the standing stops (ship always; feature scope; fix-created-spec) and every blocking finding land here by design.
60
71
  - A `relay:` line printed with no `run:` — by `next`, `gate`, `decide` (a `--revise` the human named included) or `ship`: the session reached its context limit, and the table's row applies.
61
72
  - The same `next:` line came back twice with nothing changed in between → report `no progress: <line>`, what you tried, and hand off.
62
- - An exit 2/3 you cannot mechanically satisfy — `needs-unmet` (show the human the witness satisfy command the refusal names), `slug-reuse`, lock contention, calibration floor stops under `--manual`.
73
+ - An exit 2/3 you cannot mechanically satisfy — `needs-unmet` (show the human the witness satisfy command the refusal names), `slug-reuse`, lock contention, `pin-unanswered` when the refusal calls it a human's decision (the harness says the pinned reviewer model does not exist or is out of reach — show the human the pin it names).
63
74
  - A skill ended its turn for a gate stop — that stop is yours too; do not restart the loop until the human decides.
64
75
 
65
- **Never merge a PR** — merging is the human's act on GitHub; the lazy stamp finishes the lifecycle on the next scan. **Never edit `specs/` or `plans/`** (or wherever the repo's `paths:` config relocates them) — that is what the skills' write path is for. Run `$WITNESS status` — the orientation screen (flows, blocked docs, reconcile rows, pending gates) — when you need position rather than the next action; bare `$WITNESS` prints the same screen. If it reports the reviewer model is uncalibrated, surface that; under `--manual` treat it as a stop.
76
+ **Never merge a PR** — merging is the human's act on GitHub; the lazy stamp finishes the lifecycle on the next scan. **Never edit `specs/` or `plans/`** (or wherever the repo's `paths:` config relocates them) — that is what the skills' write path is for. Run `$WITNESS status` — the orientation screen (flows, blocked docs, reconcile rows, pending gates) — when you need position rather than the next action; bare `$WITNESS` prints the same screen.
@@ -238,3 +238,103 @@ export function warnLine(tokens, window, limit) {
238
238
  if (tokens * 100 < limit * window) return undefined;
239
239
  return `witness: context ${pctOf(tokens, window)}% of ${windowLabel(window)} has reached the ${limit}% limit — finish what you are in (implement: the red→green), then hand over`;
240
240
  }
241
+
242
+ // ── The waker (row 204) ──────────────────────────────────────────────────────────────────────
243
+ //
244
+ // On Pi the waiting chat ends its turn, and witness's add-on runs `witness wait` for it and
245
+ // posts what it printed, which wakes the chat. These are its decisions, pure so both are
246
+ // unit-tested. Nothing from any command's output is run: the output contributes only a token
247
+ // checked against a 12-hex shape, and the command is always the one built here.
248
+
249
+ const WAIT_LINE = /^wait: witness wait --since ([0-9a-f]{12})$/m;
250
+ const ADD_ON = /^wait-mode: add-on$/m;
251
+ const TOKEN = /^[0-9a-f]{12}$/;
252
+ const PIN = /^\d+\.\d+\.\d+$/;
253
+
254
+ /**
255
+ * @param {unknown} output what a witness command printed
256
+ * @returns {{ token: string } | undefined} the wait it asks this chat's add-on to run
257
+ */
258
+ export function waitRequest(output) {
259
+ if (typeof output !== 'string') return undefined;
260
+ const m = WAIT_LINE.exec(output);
261
+ return m !== null && ADD_ON.test(output) ? { token: m[1] } : undefined;
262
+ }
263
+
264
+ /**
265
+ * Final review C1. Only a `next` decides whether this chat waits: the engine runs other witness
266
+ * commands after it in the same turn (`drive --detach` from a `launch:` line), and those print
267
+ * no `wait:` line of their own.
268
+ *
269
+ * @param {unknown} output what a witness command printed
270
+ * @returns {boolean} whether it is `next`'s routing output
271
+ */
272
+ export function routesNext(output) {
273
+ return typeof output === 'string' && /^next: /m.test(output);
274
+ }
275
+
276
+ /**
277
+ * @param {unknown} text the installed engine file
278
+ * @returns {string | undefined} the exact CLI version its `$WITNESS` resolves to
279
+ */
280
+ export function pinOf(text) {
281
+ if (typeof text !== 'string') return undefined;
282
+ const m = /@popovych\.co\/witness@(\d+\.\d+\.\d+)(?![\w.])/.exec(text);
283
+ return m === null ? undefined : m[1];
284
+ }
285
+
286
+ /**
287
+ * The user's own WITNESS_BIN, else the engine's pinned package. On Windows `npx` is a `.cmd`
288
+ * shim (row 164), so the line runs through System32's cmd.exe by its absolute path (row 201) —
289
+ * a line that carries only the validated pin and token beside the user's own WITNESS_BIN.
290
+ *
291
+ * @param {{ bin?: string, pin?: string, token: string, platform: string, systemRoot?: string }} o
292
+ * @returns {string[] | undefined}
293
+ */
294
+ export function waitArgv({ bin, pin, token, platform, systemRoot }) {
295
+ if (typeof token !== 'string' || !TOKEN.test(token)) return undefined;
296
+ let argv;
297
+ let line;
298
+ if (typeof bin === 'string' && bin !== '') {
299
+ line = `${bin} wait --since ${token}`;
300
+ argv = ['sh', '-c', `exec ${line}`];
301
+ } else {
302
+ if (typeof pin !== 'string' || !PIN.test(pin)) return undefined;
303
+ argv = ['npx', '-y', `@popovych.co/witness@${pin}`, 'wait', '--since', token];
304
+ line = argv.join(' ');
305
+ }
306
+ if (platform === 'win32') return [`${systemRoot ?? 'C:\\Windows'}\\System32\\cmd.exe`, '/d', '/s', '/c', line];
307
+ return argv;
308
+ }
309
+
310
+ /**
311
+ * A chat with a screen waits; drive's headless sessions and reviewers never do.
312
+ *
313
+ * @param {{ hasUI: unknown, env: Record<string, string | undefined> }} o
314
+ * @returns {boolean}
315
+ */
316
+ export function wakeAllowed({ hasUI, env }) {
317
+ return hasUI === true && (env.WITNESS_DRIVE ?? '') === '' && (env.WITNESS_REVIEWER ?? '') === '';
318
+ }
319
+
320
+ // ── The fresh chat (row 204, Q5) ─────────────────────────────────────────────────────────────
321
+ //
322
+ // A `relay:` printed with no `run:` beside it says this session reached its fill limit where it
323
+ // stands. On Pi the add-on then opens the fresh session itself and runs `/witness` there. A
324
+ // `relay:` beside `run:` hands work to another directory and never opens one.
325
+
326
+ /**
327
+ * @param {unknown} output what a witness command printed
328
+ * @returns {boolean}
329
+ */
330
+ export function freshDue(output) {
331
+ return typeof output === 'string' && /^relay: /m.test(output) && !/^run: /m.test(output);
332
+ }
333
+
334
+ /**
335
+ * @param {unknown} input a prompt the human typed
336
+ * @returns {boolean} whether it armed this session with `/witness --manual`
337
+ */
338
+ export function armedBy(input) {
339
+ return typeof input === 'string' && /^\/witness(?:\s|$)/.test(input) && /(?:^|\s)--manual(?:\s|$)/.test(input);
340
+ }
@@ -3,4 +3,4 @@
3
3
  # context). Silent everywhere that isn't a witness repo; failures swallowed:
4
4
  # session start must never hang or die on this.
5
5
  [ -f witness.config.yaml ] || exit 0
6
- ${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2} 2>/dev/null || true
6
+ ${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0} 2>/dev/null || true
@@ -16,13 +16,17 @@
16
16
  // scoped to exactly the event the guard uses. So the try/catch below is load-bearing,
17
17
  // not garnish: without it an unparseable witness.config.yaml would refuse every write
18
18
  // in the repo, `src/` included. Do not remove it because canonGuard already catches.
19
- import { spawnSync } from "node:child_process";
19
+ import { spawn, spawnSync, type ChildProcess } from "node:child_process";
20
20
  import { existsSync, readFileSync } from "node:fs";
21
21
  import { dirname, join } from "node:path";
22
22
  import { fileURLToPath } from "node:url";
23
23
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
24
24
  import { canonGuard } from "./canon-guard.mjs";
25
- import { configCandidates, contextLimitOf, invokesWitness, readingJson, warnLine } from "./context-core.mjs";
25
+ import {
26
+ armedBy, configCandidates, contextLimitOf, freshDue, invokesWitness, pinOf, readingJson, routesNext, waitArgv, waitRequest,
27
+ wakeAllowed,
28
+ warnLine,
29
+ } from "./context-core.mjs";
26
30
 
27
31
  const here = dirname(fileURLToPath(import.meta.url));
28
32
 
@@ -53,7 +57,56 @@ function configuredLimit(cwd: string): number | undefined {
53
57
  }
54
58
  }
55
59
 
60
+ // Row 204: the CLI version the engine resolves `$WITNESS` to, read from the engine installed
61
+ // beside this file (.pi/prompts/witness.md), or the plugin's own copy when run from it.
62
+ function enginePin(): string | undefined {
63
+ for (const p of [join(here, "..", "prompts", "witness.md"), join(here, "..", "commands", "witness.md")]) {
64
+ try {
65
+ const pin = pinOf(readFileSync(p, "utf8"));
66
+ if (pin !== undefined) return pin;
67
+ } catch {
68
+ /* next candidate */
69
+ }
70
+ }
71
+ return undefined;
72
+ }
73
+
74
+ const textOf = (content: unknown): string =>
75
+ Array.isArray(content)
76
+ ? content.flatMap((c) => (c !== null && typeof c === "object" && (c as { type?: unknown }).type === "text" ? [String((c as { text?: unknown }).text)] : [])).join("\n")
77
+ : "";
78
+
56
79
  export default function (pi: ExtensionAPI) {
80
+ // Row 204, keyed by session id: the wait the last witness command asked for, and the one
81
+ // waiter this session runs. A newer request replaces the waiter; a replaced or shut-down
82
+ // waiter posts nothing.
83
+ const requests = new Map<string, { token: string } | undefined>();
84
+ const waiters = new Map<string, ChildProcess>();
85
+ // Row 204 (Q5): sessions whose last witness command asked for a fresh session, and sessions
86
+ // armed with `/witness --manual`, whose fresh session continues armed.
87
+ const fresh = new Set<string>();
88
+ const armed = new Set<string>();
89
+
90
+ // Only a command handler may open a session (`ctx.newSession`), so the add-on runs its own
91
+ // command as a follow-up once the turn settles — Pi's reload-runtime example's shape.
92
+ pi.registerCommand("witness-fresh", {
93
+ description: "continue witness in a fresh session",
94
+ handler: async (_args, ctx) => {
95
+ const next = armed.has(ctx.sessionManager.getSessionId()) ? "/witness --manual" : "/witness";
96
+ await ctx.newSession({
97
+ parentSession: ctx.sessionManager.getSessionFile(),
98
+ withSession: async (c) => { await c.sendUserMessage(next); },
99
+ });
100
+ },
101
+ });
102
+ pi.on("input", async (event, ctx) => {
103
+ try {
104
+ if (armedBy(event.text)) armed.add(ctx.sessionManager.getSessionId());
105
+ } catch {
106
+ /* not armed */
107
+ }
108
+ return undefined;
109
+ });
57
110
  // Row 191 §4.6, keyed by session id: after `new_session` the session id moves (P7), and
58
111
  // the new session latches and warns afresh.
59
112
  const latched = new Set<string>();
@@ -98,6 +151,19 @@ export default function (pi: ExtensionAPI) {
98
151
  // that has run the witness CLI carries one more text block, which the model reads with the
99
152
  // output (P2). Never in a gate reviewer's spawn, never without a witness.config.yaml.
100
153
  pi.on("tool_result", async (event, ctx) => {
154
+ // Row 204: the last `next` decides whether this chat waits (final review C1). Its own try/catch:
155
+ // the warning below must never be lost to it.
156
+ try {
157
+ if (event.toolName === "bash" && invokesWitness((event.input as { command?: unknown } | undefined)?.command)) {
158
+ const session = ctx.sessionManager.getSessionId();
159
+ const text = textOf(event.content);
160
+ if (routesNext(text)) requests.set(session, waitRequest(text));
161
+ if (freshDue(text)) fresh.add(session);
162
+ else fresh.delete(session);
163
+ }
164
+ } catch {
165
+ /* no wait this time */
166
+ }
101
167
  try {
102
168
  if (event.toolName !== "bash") return undefined;
103
169
  const session = ctx.sessionManager.getSessionId();
@@ -115,6 +181,55 @@ export default function (pi: ExtensionAPI) {
115
181
  }
116
182
  });
117
183
 
184
+ // Row 204. Once a turn has fully settled — no retry, compaction or queued continuation left —
185
+ // a chat whose last witness command printed a `wait:` line in the add-on mode is woken by
186
+ // the wait's own output when it exits. Every failure path falls open: no wake, never a block.
187
+ pi.on("agent_settled", async (_event, ctx) => {
188
+ try {
189
+ const session = ctx.sessionManager.getSessionId();
190
+ const request = requests.get(session);
191
+ requests.delete(session);
192
+ if (!wakeAllowed({ hasUI: ctx.hasUI, env: process.env })) return;
193
+ // A full chat continues in a fresh one, which waits there itself if it has to.
194
+ if (fresh.delete(session)) {
195
+ pi.sendUserMessage("/witness-fresh", { deliverAs: "followUp" });
196
+ return;
197
+ }
198
+ if (request === undefined) return;
199
+ const argv = waitArgv({
200
+ bin: process.env.WITNESS_BIN, pin: enginePin(), token: request.token, platform: process.platform,
201
+ systemRoot: process.env.SystemRoot ?? process.env.SYSTEMROOT,
202
+ });
203
+ if (argv === undefined) return;
204
+ waiters.get(session)?.kill();
205
+ const child = spawn(argv[0]!, argv.slice(1), { cwd: ctx.cwd, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
206
+ waiters.set(session, child);
207
+ let out = "";
208
+ child.stdout?.on("data", (d) => { out += String(d); });
209
+ child.on("error", () => { if (waiters.get(session) === child) waiters.delete(session); });
210
+ child.on("close", (_code, signal) => {
211
+ if (waiters.get(session) !== child) return;
212
+ waiters.delete(session);
213
+ if (signal !== null) return;
214
+ try {
215
+ pi.sendMessage({ customType: "witness-wait", content: out.trim() || "wait: ended", display: true },
216
+ { triggerTurn: true, deliverAs: "followUp" });
217
+ } catch {
218
+ /* no wake */
219
+ }
220
+ });
221
+ } catch {
222
+ /* falls open */
223
+ }
224
+ });
225
+ pi.on("session_shutdown", async () => {
226
+ const all = [...waiters.values()];
227
+ waiters.clear();
228
+ for (const child of all) {
229
+ try { child.kill(); } catch { /* gone */ }
230
+ }
231
+ });
232
+
118
233
  let injected = false;
119
234
  pi.on("session_start", async () => {
120
235
  injected = false;
@@ -16,7 +16,7 @@ recap, keeps a local draft, writes no document. See NOTICE.md. -->
16
16
  Resolve the CLI once per session:
17
17
 
18
18
  ```bash
19
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
19
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
20
20
  ```
21
21
 
22
22
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
@@ -10,7 +10,7 @@ description: Slice a witness effort's confirmed recap into vertical spec slices,
10
10
  Resolve the CLI once per session:
11
11
 
12
12
  ```bash
13
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
13
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
14
14
  ```
15
15
 
16
16
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
@@ -16,7 +16,7 @@ No text copied verbatim; the design-critic lens is new material. -->
16
16
  Resolve the CLI once per session:
17
17
 
18
18
  ```bash
19
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
19
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
20
20
  ```
21
21
 
22
22
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
@@ -15,7 +15,7 @@ tests carry the parent spec's tag in their NAME. See NOTICE.md. -->
15
15
  Resolve the CLI once per session:
16
16
 
17
17
  ```bash
18
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
18
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
19
19
  ```
20
20
 
21
21
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
@@ -25,6 +25,7 @@ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
25
25
  - **Read a file before your first edit of it in this session.** Relay boundaries, `verify-red`'s stash cycle, and worktree re-attach all change files under you — an edit against a remembered copy is how "modified since read" and partial applies happen. The CLI now prints `stale-reads:` when it churns the tree; treat that list as unread.
26
26
  - **Never invoke gate reviewers or relay verdicts.** `witness gate` runs reviewers itself and journals what they said; your summary of a verdict is not evidence.
27
27
  - **Refusal repair loop:** a `witness` verb exiting 2 prints structured violations (`field · rule · got · want`). Fix your input and retry — **3 total attempts** per artifact, then stop, show the human the violation list verbatim, and end your turn.
28
+ - **An `untrusted-` refusal is the human's.** Stop, show the rows verbatim, end your turn. Never run `witness trust` — no session grants trust.
28
29
  - **A refused or hook-blocked command is a stop, not a step to drop.** Re-issue it on its own; if it still refuses, tell the human what was blocked and why. Never proceed by deleting the refused half of a compound command — a dropped step is silent, and silence is how a skipped check becomes a shipped defect.
29
30
  - **Re-entrancy:** derive position from CLI output (`$WITNESS next`, the dashboard, `log`, `index`) — never from conversation memory. Killed and re-run, you must converge.
30
31
 
@@ -15,7 +15,7 @@ parent's criteria. See NOTICE.md. -->
15
15
  Resolve the CLI once per session:
16
16
 
17
17
  ```bash
18
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
18
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
19
19
  ```
20
20
 
21
21
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
@@ -15,7 +15,7 @@ model can. See NOTICE.md. -->
15
15
  Resolve the CLI once per session:
16
16
 
17
17
  ```bash
18
- WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.24.2}"
18
+ WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.0}"
19
19
  ```
20
20
 
21
21
  - **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.