@rt-tools/agent-kit 0.37.1 → 0.39.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 (371) hide show
  1. package/README.md +5 -5
  2. package/assets/checks/action-of.mjs +154 -0
  3. package/assets/checks/board-runs.github.mjs +40 -5
  4. package/assets/checks/check-board.github.mjs +38 -7
  5. package/assets/checks/check-state-next.mjs +22 -10
  6. package/assets/checks/check-turn-map.mjs +26 -6
  7. package/assets/checks/check-work-steps.mjs +4 -173
  8. package/assets/checks/decide.mjs +285 -0
  9. package/assets/checks/decision-table.json +21432 -0
  10. package/assets/checks/decision-table.mjs +495 -0
  11. package/assets/checks/epic-window.mjs +98 -0
  12. package/assets/checks/flow-condition.mjs +64 -0
  13. package/assets/checks/flow-data.mjs +135 -0
  14. package/assets/checks/flow-forecast.mjs +334 -0
  15. package/assets/checks/flow-guard-run.mjs +90 -0
  16. package/assets/checks/flow-guard.mjs +496 -0
  17. package/assets/checks/flow-model.mjs +271 -0
  18. package/assets/checks/flow-override.mjs +130 -0
  19. package/assets/checks/flow-plan.mjs +206 -0
  20. package/assets/checks/flow-scaffold.mjs +224 -0
  21. package/assets/checks/flow-step.mjs +495 -0
  22. package/assets/checks/flow-sync.mjs +296 -0
  23. package/assets/checks/flow-syntax.mjs +292 -0
  24. package/assets/checks/flow-verdict.mjs +227 -0
  25. package/assets/checks/merge-read.mjs +239 -0
  26. package/assets/checks/owner-nudges.mjs +389 -0
  27. package/assets/checks/push-inputs.mjs +59 -16
  28. package/assets/checks/record-count.mjs +437 -0
  29. package/assets/checks/record-recount.mjs +187 -0
  30. package/assets/checks/record-turn.mjs +155 -0
  31. package/assets/checks/task-flow-script.mjs +318 -0
  32. package/assets/checks/tree-assignment.mjs +26 -7
  33. package/assets/checks/work-result.mjs +362 -0
  34. package/assets/checks/work-steps-lib.mjs +205 -0
  35. package/assets/commands/night.md +6 -6
  36. package/assets/defaults/gate-map.sh +39 -12
  37. package/assets/defaults/merges.sh +48 -0
  38. package/assets/defaults/project.sh +6 -5
  39. package/assets/defaults/turn-map.md +23 -22
  40. package/assets/docs/GLOSSARY.md +5 -1
  41. package/assets/hooks/ask-judge.md +67 -0
  42. package/assets/hooks/browser-guard-device-id.sh +11 -9
  43. package/assets/hooks/browser-guard-no-asking.sh +12 -6
  44. package/assets/hooks/browser-guard-no-listing.sh +13 -7
  45. package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
  46. package/assets/hooks/browser-guard-require-select.sh +15 -15
  47. package/assets/hooks/commit-msg.sh +13 -3
  48. package/assets/hooks/conscience-guard.sh +9 -25
  49. package/assets/hooks/decide.sh +141 -0
  50. package/assets/hooks/deny-tail.sh +16 -11
  51. package/assets/hooks/dev-server-guard.sh +27 -20
  52. package/assets/hooks/dispatch.sh +47 -4
  53. package/assets/hooks/docs-guard.sh +31 -200
  54. package/assets/hooks/end-conversation-guard.sh +12 -21
  55. package/assets/hooks/epic-stop-guard.sh +54 -152
  56. package/assets/hooks/exam-guard.sh +32 -65
  57. package/assets/hooks/facts-docs.sh +221 -0
  58. package/assets/hooks/facts-flow.sh +173 -0
  59. package/assets/hooks/facts.sh +374 -0
  60. package/assets/hooks/flow-step-guard.sh +93 -0
  61. package/assets/hooks/git-guard-delivery-body.sh +4 -4
  62. package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
  63. package/assets/hooks/git-guard-delivery-draft.sh +3 -3
  64. package/assets/hooks/git-guard-delivery-epic.sh +18 -9
  65. package/assets/hooks/git-guard-delivery-folder.sh +32 -7
  66. package/assets/hooks/git-guard-delivery-merge.sh +2 -2
  67. package/assets/hooks/git-guard-delivery-merged.sh +12 -1
  68. package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
  69. package/assets/hooks/git-guard-delivery-rerun.sh +44 -0
  70. package/assets/hooks/git-guard-delivery-signature.sh +82 -45
  71. package/assets/hooks/git-guard-delivery-task.sh +47 -0
  72. package/assets/hooks/git-guard-delivery.sh +112 -101
  73. package/assets/hooks/git-guard-discard.sh +8 -18
  74. package/assets/hooks/git-guard-main.sh +13 -19
  75. package/assets/hooks/git-guard-no-verify.sh +56 -16
  76. package/assets/hooks/git-guard-push-ahead.sh +39 -6
  77. package/assets/hooks/git-guard-push-marks.sh +262 -13
  78. package/assets/hooks/git-guard-push-tests.sh +58 -52
  79. package/assets/hooks/git-guard-tree-assignment.sh +7 -4
  80. package/assets/hooks/guard-note.sh +8 -6
  81. package/assets/hooks/handoff-entry-guard.sh +19 -38
  82. package/assets/hooks/handoff-write.sh +3 -1
  83. package/assets/hooks/hook-input.sh +0 -41
  84. package/assets/hooks/metric-marks.sh +19 -7
  85. package/assets/hooks/observe.sh +1 -1
  86. package/assets/hooks/override-write-guard.sh +27 -9
  87. package/assets/hooks/pre-push.sh +40 -12
  88. package/assets/hooks/prose-style-guard.sh +6 -19
  89. package/assets/hooks/pull-merges.sh +76 -0
  90. package/assets/hooks/push-ahead-call-guard.sh +447 -0
  91. package/assets/hooks/push-set.sh +38 -8
  92. package/assets/hooks/qa-dataid-guard.sh +7 -17
  93. package/assets/hooks/record-turn.sh +52 -0
  94. package/assets/hooks/rerun-guard.sh +11 -16
  95. package/assets/hooks/reuse-first-guard.sh +7 -21
  96. package/assets/hooks/role-calls.sh +25 -3
  97. package/assets/hooks/rule-source-guard.sh +54 -21
  98. package/assets/hooks/skill-gate-rearm.sh +18 -5
  99. package/assets/hooks/skill-gate.sh +156 -20
  100. package/assets/hooks/skill-loaded.sh +18 -3
  101. package/assets/hooks/sql-guard-target.sh +2 -2
  102. package/assets/hooks/sql-guard-write.sh +12 -12
  103. package/assets/hooks/sql-guard.sh +58 -16
  104. package/assets/hooks/task-context-load.sh +3 -1
  105. package/assets/hooks/task-flow-context.sh +5 -18
  106. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  107. package/assets/hooks/task-flow-guard.sh +28 -130
  108. package/assets/hooks/tree-assignment-guard.sh +25 -14
  109. package/assets/hooks/turn-entry-load.sh +3 -1
  110. package/assets/hooks/turn-exit-guard.sh +92 -452
  111. package/assets/hooks/turn-exit-role.sh +3 -1
  112. package/assets/hooks/turn-judge.md +113 -0
  113. package/assets/hooks/window-fill-guard.sh +22 -41
  114. package/assets/patterns/doc-style-human.md +36 -76
  115. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  116. package/assets/patterns/git-workflow-commit.github.md +11 -269
  117. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  118. package/assets/patterns/git-workflow-docker.md +8 -231
  119. package/assets/patterns/git-workflow-freshness.md +8 -56
  120. package/assets/patterns/git-workflow-merge.md +6 -176
  121. package/assets/patterns/git-workflow-migration.md +5 -75
  122. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  123. package/assets/patterns/git-workflow-pr-ready.md +9 -70
  124. package/assets/patterns/git-workflow-pr.azure.md +13 -285
  125. package/assets/patterns/git-workflow-pr.github.md +13 -251
  126. package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
  127. package/assets/patterns/git-workflow-restart.md +5 -42
  128. package/assets/patterns/git-workflow-secrets.md +10 -76
  129. package/assets/patterns/git-workflow-stack.md +7 -207
  130. package/assets/patterns/status-report-table.github.md +1 -1
  131. package/assets/patterns/task-flow-archive.md +12 -233
  132. package/assets/patterns/task-flow-close.md +16 -292
  133. package/assets/patterns/task-flow-cycle.md +13 -39
  134. package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
  135. package/assets/patterns/task-flow-handoff.md +13 -161
  136. package/assets/patterns/task-flow-resume.md +18 -218
  137. package/assets/patterns/task-flow-start.md +9 -247
  138. package/assets/patterns/turn-entry-map.md +2 -2
  139. package/assets/pitfalls/agent-kit-extend.md +200 -0
  140. package/assets/pitfalls/agent-kit.2.md +323 -0
  141. package/assets/pitfalls/angular-patterns.md +98 -0
  142. package/assets/pitfalls/browser-verification.md +265 -0
  143. package/assets/pitfalls/component-structure.md +98 -0
  144. package/assets/pitfalls/dependencies.md +92 -0
  145. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  146. package/assets/pitfalls/deploy-flow.github.md +211 -0
  147. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  148. package/assets/pitfalls/doc-style-human.md +112 -0
  149. package/assets/pitfalls/doc-style.2.md +286 -0
  150. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  151. package/assets/pitfalls/entity-models.md +89 -0
  152. package/assets/pitfalls/epic-flow.md +92 -0
  153. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  154. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  155. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  156. package/assets/pitfalls/git-workflow-docker.md +275 -0
  157. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  158. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  159. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  160. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  161. package/assets/pitfalls/git-workflow-merge.md +220 -0
  162. package/assets/pitfalls/git-workflow-migration.md +103 -0
  163. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  164. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  165. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  166. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  167. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  168. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  169. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  170. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  171. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  172. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  173. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  174. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  175. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  176. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  177. package/assets/pitfalls/git-workflow-restart.md +72 -0
  178. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  179. package/assets/pitfalls/git-workflow-stack.md +254 -0
  180. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  181. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  182. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  183. package/assets/pitfalls/lib-layers.md +114 -0
  184. package/assets/pitfalls/lists.md +117 -0
  185. package/assets/pitfalls/mockups.needs-mockups.md +87 -0
  186. package/assets/pitfalls/navigation.md +94 -0
  187. package/assets/pitfalls/observability.needs-app.md +186 -0
  188. package/assets/pitfalls/platform-access.md +94 -0
  189. package/assets/pitfalls/queue-audit.github.md +78 -0
  190. package/assets/pitfalls/reuse-first.md +201 -0
  191. package/assets/pitfalls/spec-driven.2.md +318 -0
  192. package/assets/pitfalls/styling-bem.2.md +125 -0
  193. package/assets/pitfalls/task-flow-archive.md +265 -0
  194. package/assets/pitfalls/task-flow-close.2.md +166 -0
  195. package/assets/pitfalls/task-flow-close.md +167 -0
  196. package/assets/pitfalls/task-flow-cycle.md +73 -0
  197. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  198. package/assets/pitfalls/task-flow-handoff.md +200 -0
  199. package/assets/pitfalls/task-flow-handover.md +30 -0
  200. package/assets/pitfalls/task-flow-owner.md +58 -0
  201. package/assets/pitfalls/task-flow-plan.md +29 -0
  202. package/assets/pitfalls/task-flow-resume.md +257 -0
  203. package/assets/pitfalls/task-flow-start.md +287 -0
  204. package/assets/pitfalls/task-flow.2.md +303 -0
  205. package/assets/pitfalls/task-flow.md +4 -4
  206. package/assets/pitfalls/testing.2.md +279 -0
  207. package/assets/pitfalls/turn-conduct.md +16 -17
  208. package/assets/pitfalls/typescript-conventions.md +161 -0
  209. package/assets/pitfalls/write-a-skill.md +128 -0
  210. package/assets/rules/angular-patterns.md +21 -86
  211. package/assets/rules/autonomous-work.md +2 -2
  212. package/assets/rules/browser-verification.md +28 -256
  213. package/assets/rules/component-structure.md +25 -87
  214. package/assets/rules/dependencies.md +20 -78
  215. package/assets/rules/deploy-flow.azure.md +26 -156
  216. package/assets/rules/deploy-flow.github.md +34 -200
  217. package/assets/rules/deploy-flow.gitlab.md +27 -159
  218. package/assets/rules/doc-style.md +32 -286
  219. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  220. package/assets/rules/entity-models.md +14 -63
  221. package/assets/rules/epic-flow.md +24 -63
  222. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  223. package/assets/rules/git-workflow-hosting.github.md +38 -0
  224. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  225. package/assets/rules/git-workflow-push.azure.md +28 -0
  226. package/assets/rules/git-workflow-push.github.md +28 -0
  227. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  228. package/assets/rules/git-workflow-queue.azure.md +23 -0
  229. package/assets/rules/git-workflow-queue.github.md +30 -0
  230. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  231. package/assets/rules/git-workflow.azure.md +21 -282
  232. package/assets/rules/git-workflow.github.md +24 -284
  233. package/assets/rules/git-workflow.gitlab.md +21 -269
  234. package/assets/rules/lib-layers.md +30 -103
  235. package/assets/rules/lists.md +21 -105
  236. package/assets/rules/mockups.needs-mockups.md +25 -64
  237. package/assets/rules/navigation.md +10 -69
  238. package/assets/rules/observability.needs-app.md +43 -172
  239. package/assets/rules/platform-access.md +28 -75
  240. package/assets/rules/queue-audit.github.md +25 -52
  241. package/assets/rules/reuse-first.md +20 -195
  242. package/assets/rules/spec-driven.md +35 -308
  243. package/assets/rules/styling-bem.md +20 -117
  244. package/assets/rules/task-flow-handover.md +24 -0
  245. package/assets/rules/task-flow-owner.md +34 -0
  246. package/assets/rules/task-flow-plan.md +38 -0
  247. package/assets/rules/task-flow.md +22 -300
  248. package/assets/rules/testing.md +32 -273
  249. package/assets/rules/turn-conduct.md +105 -106
  250. package/assets/rules/turn-entry.md +2 -2
  251. package/assets/rules/typescript-conventions.md +41 -147
  252. package/assets/samples/tasks/_template/plan.md +30 -6
  253. package/assets/samples/tasks/_template/progress.md +0 -1
  254. package/assets/skills/agent-kit-extend.md +25 -168
  255. package/assets/skills/agent-kit.md +27 -299
  256. package/assets/skills/write-a-skill.md +20 -106
  257. package/assets/task-flow/flow.js +184 -0
  258. package/assets/task-flow/flow.md +101 -0
  259. package/assets/task-flow/measure/agreement.mjs +24 -0
  260. package/assets/task-flow/measure/ci.mjs +184 -0
  261. package/assets/task-flow/measure/copy.mjs +22 -0
  262. package/assets/task-flow/measure/epic-of.mjs +50 -0
  263. package/assets/task-flow/measure/epic-text.mjs +35 -0
  264. package/assets/task-flow/measure/epic.mjs +114 -0
  265. package/assets/task-flow/measure/folder.mjs +16 -0
  266. package/assets/task-flow/measure/footprint.mjs +28 -0
  267. package/assets/task-flow/measure/grill.mjs +21 -0
  268. package/assets/task-flow/measure/host.mjs +8 -0
  269. package/assets/task-flow/measure/owner.mjs +27 -0
  270. package/assets/task-flow/measure/plan.mjs +27 -0
  271. package/assets/task-flow/measure/pr.mjs +20 -0
  272. package/assets/task-flow/measure/progress.mjs +50 -0
  273. package/assets/task-flow/measure/session.mjs +252 -0
  274. package/assets/task-flow/measure/task.mjs +23 -0
  275. package/assets/task-flow/measure/text.mjs +77 -0
  276. package/assets/task-flow/source/git.mjs +254 -0
  277. package/assets/task-flow/source/host.mjs +277 -0
  278. package/assets/task-flow/source/marks.mjs +56 -0
  279. package/assets/task-flow/source/owner.mjs +94 -0
  280. package/assets/task-flow/source/records.mjs +116 -0
  281. package/assets/task-flow/source/session.mjs +269 -0
  282. package/assets/task-flow/source/steps.mjs +28 -0
  283. package/assets/task-flow/source/tree.mjs +42 -0
  284. package/bin/agent-kit.d.ts.map +1 -1
  285. package/bin/agent-kit.js +30 -0
  286. package/bin/agent-kit.js.map +1 -1
  287. package/lib/agent-checks.d.ts +55 -0
  288. package/lib/agent-checks.d.ts.map +1 -0
  289. package/lib/agent-checks.js +221 -0
  290. package/lib/agent-checks.js.map +1 -0
  291. package/lib/assets.d.ts.map +1 -1
  292. package/lib/assets.js +7 -2
  293. package/lib/assets.js.map +1 -1
  294. package/lib/cargo.d.ts +29 -0
  295. package/lib/cargo.d.ts.map +1 -1
  296. package/lib/cargo.js +27 -1
  297. package/lib/cargo.js.map +1 -1
  298. package/lib/cascade.d.ts.map +1 -1
  299. package/lib/cascade.js +3 -1
  300. package/lib/cascade.js.map +1 -1
  301. package/lib/commands.d.ts.map +1 -1
  302. package/lib/commands.js +78 -2
  303. package/lib/commands.js.map +1 -1
  304. package/lib/config.d.ts +18 -0
  305. package/lib/config.d.ts.map +1 -1
  306. package/lib/config.js +18 -1
  307. package/lib/config.js.map +1 -1
  308. package/lib/epic-window-send.d.ts +74 -0
  309. package/lib/epic-window-send.d.ts.map +1 -0
  310. package/lib/epic-window-send.js +166 -0
  311. package/lib/epic-window-send.js.map +1 -0
  312. package/lib/hooks-map.d.ts +4 -0
  313. package/lib/hooks-map.d.ts.map +1 -1
  314. package/lib/hooks-map.js +2 -2
  315. package/lib/hooks-map.js.map +1 -1
  316. package/lib/integrity.d.ts +3 -0
  317. package/lib/integrity.d.ts.map +1 -1
  318. package/lib/integrity.js +7 -0
  319. package/lib/integrity.js.map +1 -1
  320. package/lib/metric-lines.d.ts +2 -1
  321. package/lib/metric-lines.d.ts.map +1 -1
  322. package/lib/metric-lines.js +49 -1
  323. package/lib/metric-lines.js.map +1 -1
  324. package/lib/metric-send-mark.d.ts +6 -3
  325. package/lib/metric-send-mark.d.ts.map +1 -1
  326. package/lib/metric-send-mark.js +15 -5
  327. package/lib/metric-send-mark.js.map +1 -1
  328. package/lib/metric-send.d.ts +6 -2
  329. package/lib/metric-send.d.ts.map +1 -1
  330. package/lib/metric-send.js +47 -13
  331. package/lib/metric-send.js.map +1 -1
  332. package/lib/metrics.d.ts +17 -0
  333. package/lib/metrics.d.ts.map +1 -1
  334. package/lib/metrics.js +26 -15
  335. package/lib/metrics.js.map +1 -1
  336. package/lib/observations.js +3 -3
  337. package/lib/observations.js.map +1 -1
  338. package/lib/outcomes.d.ts +5 -2
  339. package/lib/outcomes.d.ts.map +1 -1
  340. package/lib/outcomes.js +5 -4
  341. package/lib/outcomes.js.map +1 -1
  342. package/lib/push-gate.d.ts +13 -0
  343. package/lib/push-gate.d.ts.map +1 -1
  344. package/lib/push-gate.js +11 -7
  345. package/lib/push-gate.js.map +1 -1
  346. package/lib/push-set-usefulness.d.ts +78 -0
  347. package/lib/push-set-usefulness.d.ts.map +1 -0
  348. package/lib/push-set-usefulness.js +225 -0
  349. package/lib/push-set-usefulness.js.map +1 -0
  350. package/lib/sync.d.ts +10 -0
  351. package/lib/sync.d.ts.map +1 -1
  352. package/lib/sync.js +14 -1
  353. package/lib/sync.js.map +1 -1
  354. package/lib/work-result.d.ts +43 -0
  355. package/lib/work-result.d.ts.map +1 -0
  356. package/lib/work-result.js +39 -0
  357. package/lib/work-result.js.map +1 -0
  358. package/package.json +1 -1
  359. package/assets/hooks/claim-guard.sh +0 -212
  360. package/assets/hooks/grill-gate-ask.sh +0 -26
  361. package/assets/hooks/grill-gate-bypass.sh +0 -61
  362. package/assets/hooks/grill-gate-options.sh +0 -50
  363. package/assets/hooks/grill-gate.sh +0 -482
  364. package/assets/hooks/postmortem-guard.sh +0 -124
  365. package/assets/hooks/proposal-guard.sh +0 -154
  366. package/assets/hooks/stand-login-guard.sh +0 -107
  367. package/assets/hooks/turn-exit-epic.sh +0 -173
  368. package/assets/hooks/turn-exit-patterns.sh +0 -123
  369. package/assets/hooks/turn-exit-verdict.sh +0 -149
  370. package/assets/hooks/waiting-turn-guard.sh +0 -320
  371. package/assets/hooks/work-start-guard.sh +0 -175
@@ -0,0 +1,374 @@
1
+ #!/usr/bin/env bash
2
+ # The facts of the state the guards decide by, each computed in one place. NOT a guard: it has no
3
+ # `rt-hook:` declaration and hooks into no agent event. A guard sources it and calls `rt_fact_*`.
4
+ #
5
+ # Why a file of its own. The same fact was computed by a dozen hooks, three different ways: the
6
+ # branch by `git branch --show-current`, by `git symbolic-ref` and by `git rev-parse --abbrev-ref`,
7
+ # which answer a detached head differently. A fact the decider reads has one definition, or the table
8
+ # describes a state no hook agrees on.
9
+ #
10
+ # WHAT IS HERE.
11
+ # rt_fact_branch [dir] the current branch; empty and 1 on a detached head
12
+ # rt_fact_default_branch the default branch the remote names, without «origin/»
13
+ # rt_fact_remote_head <branch> the commit of the branch on the remote, asked over the network
14
+ # rt_fact_transcript <input> the path of the conversation record named by the hook input
15
+ # rt_fact_agent_transcript <input> the path of a subagent's record named by the hook input
16
+ # rt_fact_window_stop_file <sid> the mark the window guard leaves past the stop threshold
17
+ # rt_fact_window_fill <record> the fill of the window in tokens
18
+ # rt_fact_window_over_stop <sid> <record> yes when the window is past its stop threshold
19
+ # rt_fact_window_params <record> the numbers a window refusal names, as JSON
20
+ # rt_fact_exam <record> the exam on the loaded rules: passed, failed or none
21
+ # rt_fact_exam_holds <record> the exam as the exam guard holds it: a switched-off role and a
22
+ # declared bypass count as passed
23
+ # rt_fact_move_rule_loaded <tool> <tool input> <sid>
24
+ # yes when every rule the rules gate wants for that move is loaded
25
+ # rt_fact_move_gate_rule <tool> <tool input> <sid>
26
+ # the first rule the gate waits for before that move, or nothing
27
+ # rt_fact_from_handoff <record> yes when the session began from a handover
28
+ # rt_move_rules <tool> <input> the rules the rules gate wants for a move, one per line
29
+ # rt_fact_rule_loaded <rule> <sid> yes when the rule is loaded or absent from the tree
30
+ # rt_fact_move <tool> <tool input> <hook input>
31
+ # the facts the neighbours judge a named move by, as JSON: the
32
+ # exam, the window, the rules the gate wants for the move, the
33
+ # rule of the course of work and the entry from a handover
34
+ # rt_node_pinned_dir [root] the bin directory of the node `.nvmrc` pins, installed by nvm
35
+ # rt_node_pin_mismatch [root] one line when no installed node serves the pin and the node
36
+ # of PATH does not either; empty otherwise
37
+ #
38
+ # FAIL-OPEN: a fact that cannot be read is empty. The guard decides by an empty fact as it did when
39
+ # its own call failed.
40
+
41
+ rt_fact_branch() {
42
+ if [ -n "${1:-}" ]; then
43
+ _rt_b="$(git -C "$1" branch --show-current 2>/dev/null)"
44
+ else
45
+ _rt_b="$(git branch --show-current 2>/dev/null)"
46
+ fi
47
+ [ -n "$_rt_b" ] || return 1
48
+ printf '%s\n' "$_rt_b"
49
+ }
50
+
51
+ rt_fact_default_branch() {
52
+ git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##'
53
+ }
54
+
55
+ # A slow network gives no answer rather than a stalled guard: the limits end a call that crawls.
56
+ rt_fact_remote_head() {
57
+ GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=5 GIT_TERMINAL_PROMPT=0 \
58
+ git ls-remote origin "refs/heads/$1" 2>/dev/null | cut -f1
59
+ }
60
+
61
+ rt_fact_transcript() {
62
+ printf '%s' "$1" | jq -r '.transcript_path // empty' 2>/dev/null
63
+ }
64
+
65
+ rt_fact_agent_transcript() {
66
+ printf '%s' "$1" | jq -r '.agent_transcript_path // empty' 2>/dev/null
67
+ }
68
+
69
+ rt_fact_window_stop_file() {
70
+ printf '%s/claude-window-stop/%s' "${TMPDIR:-/tmp}" "$1"
71
+ }
72
+
73
+ # The verdict of the exam on the loaded rules over the whole session: passed, failed or none. Only a
74
+ # tool that cannot read or write files gives a verdict, and the assistant's own text never does: the
75
+ # reasons stand at the exam guard, which refuses by this fact.
76
+ rt_fact_exam() {
77
+ [ -f "$1" ] || { printf 'none'; return 0; }
78
+ jq -s -r '
79
+
80
+ def textof:
81
+ if type == "string" then .
82
+ elif type == "array" then (map(if type == "object" then (.text // "") else tostring end) | join("\n"))
83
+ else tostring end;
84
+
85
+ # The call whose answer is discarded is recognised by its identifier, and the identifier is
86
+ # bound by a name: a dot after a pipe means the list itself, the search over it answers zero
87
+ # on any non-empty list, and every answer of every tool gets muted at once — that is, the
88
+ # verdict is looked for in the host records alone.
89
+ #
90
+ # Tools that read and write files: their result does not count as a verdict — otherwise
91
+ # echoing the same line or reading a file with it passes the guard, and the real verdict
92
+ # does not.
93
+ ["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
94
+ | ([.[] | select(.type == "assistant") | (.message.content // [])[]
95
+ | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
96
+ | {key: (.id // ""), value: true}] | from_entries) as $muted
97
+
98
+ | [ .[]
99
+ # The assistant text is never a verdict: writing the needed line in a reply costs one
100
+ # move.
101
+ | if .type == "assistant" then ""
102
+ elif .type == "user" then
103
+ ([ ((.message.content // []) | if type == "array" then .[] else empty end
104
+ | select(.type == "tool_result")
105
+ | select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
106
+ | .content | textof),
107
+ ((.message.content // "") | if type == "string" then . else "" end),
108
+ # The call result field: the same record, another form. Discarded only when
109
+ # this result belongs to a reading or writing tool.
110
+ (. as $rec
111
+ | if ($rec.toolUseResult // null) == null then ""
112
+ elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
113
+ | select(.type == "tool_result") | (.tool_use_id // "")]
114
+ | map($muted[.] // false) | any) then ""
115
+ else ($rec.toolUseResult | textof) end)
116
+ ] | join("\n"))
117
+ # Host records — the role completion notice and the attachment: the host chooses their
118
+ # form, and they count whole.
119
+ else tostring end ] | join("\n")
120
+ | [scan("(ЭКЗАМЕН:[[:space:]]*сдано|EXAM:[[:space:]]*passed)[[:space:]]*([0-9]+)[[:space:]]*(из|of)[[:space:]]*([0-9]+)")]
121
+ | if length == 0 then "none"
122
+ else (.[-1] | if .[1] == .[3] then "passed" else "failed" end)
123
+ end
124
+ ' "$1" 2>/dev/null
125
+ }
126
+
127
+ # Whether the session began from a handover: a word of the owner names it. yes or no.
128
+ rt_fact_from_handoff() {
129
+ [ -f "$1" ] || { printf 'no'; return 0; }
130
+ jq -s -r '
131
+ [.[] | select(.type == "user") | .message.content
132
+ | if type == "string" then . elif type == "array"
133
+ then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end]
134
+ | join("\n") | if test("handoff|передач[аи][[:space:]]+захода") then "yes" else "no" end
135
+ ' "$1" 2>/dev/null || printf 'no'
136
+ }
137
+
138
+ # Whether a rule is loaded in this session, read the way the rules gate reads it: yes, or no while the
139
+ # rule exists in the tree and the session has not loaded it.
140
+ rt_fact_rule_loaded() {
141
+ _rt_rule="$1"
142
+ _rt_loaded="${TMPDIR:-/tmp}/claude-skill-gate/${2:-nosession}.loaded"
143
+ [ -f "${CLAUDE_PROJECT_DIR:-.}/${RT_RULES_DIR:-.claude/skills}/${_rt_rule}/SKILL.md" ] || { printf 'yes'; return 0; }
144
+ if [ -f "$_rt_loaded" ] && grep -qE "^([^:]*:)?${_rt_rule}$" "$_rt_loaded" 2>/dev/null; then
145
+ printf 'yes'
146
+ elif rt_fact_rule_deliverable "$_rt_rule" "${2:-nosession}"; then
147
+ printf 'yes'
148
+ else
149
+ printf 'no'
150
+ fi
151
+ }
152
+
153
+ # A rule the rules gate puts into the session by the same call: readable, and within the host limit
154
+ # with the frame of its delivery. The hooks of one call run side by side, and the record of the
155
+ # delivery may not be written yet when a neighbour reads it; naming the load of such a rule sends
156
+ # the session into the round the gate removed. A call without a session id gets no delivery.
157
+ rt_fact_rule_deliverable() {
158
+ [ "${2:-nosession}" != nosession ] || return 1
159
+ _rt_file="${CLAUDE_PROJECT_DIR:-.}/${RT_RULES_DIR:-.claude/skills}/$1/SKILL.md"
160
+ [ -r "$_rt_file" ] || return 1
161
+ _rt_limit="${RT_GATE_CONTEXT_LIMIT:-10000}"
162
+ case "$_rt_limit" in '' | *[!0-9]*) _rt_limit=10000 ;; esac
163
+ _rt_size="$(wc -m < "$_rt_file" 2>/dev/null | tr -d ' ')"
164
+ [ -n "$_rt_size" ] || return 1
165
+ # The frame of a delivery — its opening line and the file heading — weighs under 400 characters.
166
+ [ $((_rt_size + 400)) -le "$_rt_limit" ]
167
+ }
168
+
169
+ # The fill of the window in tokens: the last usage record of a reply — the input, the one-off write
170
+ # into the cache, what was read from the cache and the output. A sum over all records will not do:
171
+ # what was read from the cache repeats in each of them. A tail of 200 lines holds the last one.
172
+ rt_fact_window_fill() {
173
+ tail -n 200 "$1" 2>/dev/null | jq -s -r '
174
+ [.[] | select(.type == "assistant") | .message.usage | select(. != null)]
175
+ | last
176
+ | if . == null then empty
177
+ else ((.input_tokens // 0) + (.cache_creation_input_tokens // 0)
178
+ + (.cache_read_input_tokens // 0) + (.output_tokens // 0))
179
+ end
180
+ ' 2>/dev/null
181
+ }
182
+
183
+ # Whether the window is past its stop threshold: yes or no. The mark of the window guard answers
184
+ # first; without it the fill is counted against the window size of the tree profile, the way the
185
+ # window guard counts it. Parameters: the session id, the conversation record.
186
+ rt_fact_window_over_stop() {
187
+ if [ -f "$(rt_fact_window_stop_file "$1")" ]; then printf 'yes'; return 0; fi
188
+ (
189
+ _rt_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
190
+ for _rt_p in "$_rt_here/../rt-kit/defaults/project.sh" "$_rt_here/../defaults/project.sh" \
191
+ "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
192
+ # shellcheck disable=SC1090
193
+ [ -f "$_rt_p" ] && . "$_rt_p" 2>/dev/null
194
+ done
195
+ _rt_w="${RT_WINDOW_TOKENS:-}"
196
+ _rt_f="$(rt_fact_window_fill "${2:-}")"
197
+ case "$_rt_w$_rt_f" in '' | *[!0-9]*) printf 'no'; exit 0 ;; esac
198
+ [ -n "$_rt_f" ] && [ "$_rt_w" -gt 0 ] 2>/dev/null || { printf 'no'; exit 0; }
199
+ if [ $((_rt_f * 100 / _rt_w)) -ge "${RT_WINDOW_STOP_PCT:-50}" ]; then printf 'yes'; else printf 'no'; fi
200
+ )
201
+ }
202
+
203
+ # The numbers a refusal past the window threshold names: the fill, the window, the threshold and the
204
+ # directories that stay open. JSON for the slots of the decision table.
205
+ rt_fact_window_params() {
206
+ (
207
+ _rt_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
208
+ for _rt_p in "$_rt_here/../rt-kit/defaults/project.sh" "$_rt_here/../defaults/project.sh" \
209
+ "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
210
+ # shellcheck disable=SC1090
211
+ [ -f "$_rt_p" ] && . "$_rt_p" 2>/dev/null
212
+ done
213
+ _rt_w="${RT_WINDOW_TOKENS:-0}"
214
+ _rt_f="$(rt_fact_window_fill "${1:-}")"
215
+ case "$_rt_w" in '' | *[!0-9]*) _rt_w=0 ;; esac
216
+ case "$_rt_f" in '' | *[!0-9]*) _rt_f=0 ;; esac
217
+ _rt_pct=0
218
+ [ "$_rt_w" -gt 0 ] && _rt_pct=$((_rt_f * 100 / _rt_w))
219
+ jq -cn --arg pct "$_rt_pct" --arg fill_k "$((_rt_f / 1000))" --arg window_k "$((_rt_w / 1000))" \
220
+ --arg stop_pct "${RT_WINDOW_STOP_PCT:-50}" --arg tasks_dir "${RT_TASKS_DIR:-docs/tasks}" \
221
+ --arg handoff_dir "${RT_HANDOFF_DIR:-.claude/handoff}" \
222
+ '{pct:$pct, fill_k:$fill_k, window_k:$window_k, stop_pct:$stop_pct, tasks_dir:$tasks_dir, handoff_dir:$handoff_dir}'
223
+ )
224
+ }
225
+
226
+ # The exam as the exam guard holds it: the role switched off by the tree, or the bypass declared in
227
+ # the body of the last commit, hold nothing — the exam counts as passed.
228
+ rt_fact_exam_holds() {
229
+ # No record of the conversation: the exam guard has nothing to judge by and lets the call through.
230
+ [ -f "${1:-}" ] || { printf 'passed'; return 0; }
231
+ _rt_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
232
+ # shellcheck disable=SC1091
233
+ if [ -f "$_rt_here/roles.sh" ] && . "$_rt_here/roles.sh" 2>/dev/null && rt_role_off strict-teacher; then
234
+ printf 'passed'
235
+ return 0
236
+ fi
237
+ if git -C "${CLAUDE_PROJECT_DIR:-.}" log -1 --format=%B 2>/dev/null | grep -qE '^Exam-skip:[[:space:]]*[^[:space:]<]'; then
238
+ printf 'passed'
239
+ return 0
240
+ fi
241
+ _rt_e="$(rt_fact_exam "$1")"
242
+ printf '%s' "${_rt_e:-none}"
243
+ }
244
+
245
+ # Whether the rules gate lets a move through: every rule its map wants for the move is loaded.
246
+ # Parameters: the tool of the move, its tool input as JSON, the session id.
247
+ rt_fact_move_rule_loaded() {
248
+ if [ -n "$(rt_fact_move_gate_rule "$@")" ]; then printf 'no'; else printf 'yes'; fi
249
+ }
250
+
251
+ # The first rule the rules gate waits for before a move, or nothing when the move passes it.
252
+ # Parameters: the tool of the move, its tool input as JSON, the session id.
253
+ rt_fact_move_gate_rule() {
254
+ _rt_in="$(jq -cn --arg t "$1" --argjson i "$2" '{tool_name:$t, tool_input:$i}' 2>/dev/null)"
255
+ for _rt_r in $(rt_move_rules "$1" "$_rt_in"); do
256
+ [ "$(rt_fact_rule_loaded "$_rt_r" "$3")" = yes ] || { printf '%s' "$_rt_r"; return 0; }
257
+ done
258
+ }
259
+
260
+ # The facts the neighbours judge a named move by. A guard that names a move hands them to the decider,
261
+ # and the decider puts first what a neighbour wants before that move.
262
+ # Parameters: the tool of the move, its tool input as JSON, the hook input.
263
+ rt_fact_move() {
264
+ _rt_sid="$(printf '%s' "$3" | jq -r '.session_id // "nosession"' 2>/dev/null)"
265
+ _rt_rec="$(rt_fact_transcript "$3")"
266
+ jq -cn --arg exam "$(rt_fact_exam_holds "$_rt_rec")" \
267
+ --arg window "$(rt_fact_window_over_stop "$_rt_sid" "$_rt_rec")" \
268
+ --arg rule "$(rt_fact_move_rule_loaded "$1" "$2" "$_rt_sid")" \
269
+ --arg gate "$(rt_fact_move_gate_rule "$1" "$2" "$_rt_sid")" \
270
+ --arg handoff "$(rt_fact_from_handoff "$_rt_rec")" \
271
+ --arg flow "$(rt_fact_rule_loaded "${RT_TASK_FLOW_RULE:-task-flow}" "$_rt_sid")" \
272
+ '{exam:$exam, window_over_stop:$window, rule_loaded:$rule, gate_rule:$gate, task_flow_loaded:$flow, from_handoff:$handoff}'
273
+ }
274
+
275
+ # The rules the gate wants for a move: the map read the way the gate reads it, a shell command
276
+ # with the files it writes. Parameters: the tool of the move, the whole input of the move.
277
+ rt_move_rules() {
278
+ local mr_dir mr_root mr_map mr_profile mr_target mr_path
279
+ mr_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
280
+ mr_root="${CLAUDE_PROJECT_DIR:-.}"
281
+ (
282
+ for mr_map in "$mr_dir/../rt-kit/defaults/gate-map.sh" "$mr_dir/../defaults/gate-map.sh" "$mr_root/.claude/rt-kit/defaults/gate-map.sh" "$mr_root/.claude/rt-kit/gate-map.sh"; do
283
+ # shellcheck disable=SC1090
284
+ [ -f "$mr_map" ] && . "$mr_map" 2>/dev/null
285
+ done
286
+ command -v skill_for >/dev/null 2>&1 || exit 0
287
+ case "$1" in
288
+ Edit | Write | MultiEdit)
289
+ mr_target="$(printf '%s' "$2" | jq -r '.tool_input.file_path // empty' 2>/dev/null)"
290
+ case "$mr_target" in /*) ;; ?*) mr_target="$mr_root/$mr_target" ;; *) exit 0 ;; esac
291
+ skill_for edit "$mr_target" "" 2>/dev/null
292
+ ;;
293
+ Bash)
294
+ mr_target="$(printf '%s' "$2" | jq -r '.tool_input.command // empty' 2>/dev/null)"
295
+ [ -n "$mr_target" ] || exit 0
296
+ skill_for bash "$mr_target" "" 2>/dev/null
297
+ for mr_profile in "$mr_dir/../rt-kit/defaults/project.sh" "$mr_dir/../defaults/project.sh" "$mr_root/.claude/rt-kit/defaults/project.sh" "$mr_root/.claude/rt-kit/project.sh"; do
298
+ # shellcheck disable=SC1090
299
+ [ -f "$mr_profile" ] && . "$mr_profile" 2>/dev/null
300
+ done
301
+ command -v rt_shell_writes >/dev/null 2>&1 && command -v rt_shell_paths >/dev/null 2>&1 || exit 0
302
+ rt_shell_writes "$mr_target" || exit 0
303
+ rt_shell_paths "$mr_target" | while IFS= read -r mr_path; do
304
+ [ -n "$mr_path" ] || continue
305
+ case "$mr_path" in /*) ;; *) mr_path="$mr_root/$mr_path" ;; esac
306
+ skill_for edit "$mr_path" "" 2>/dev/null
307
+ done
308
+ ;;
309
+ esac
310
+ ) | tr '\n' ' '
311
+ }
312
+
313
+ # The version `.nvmrc` of the tree pins, without the `v`: a full version, a major or a major and a
314
+ # minor. The first line that is not a comment counts, spaces and tabs aside. An alias — `lts/*`,
315
+ # `node` — and a tree with no `.nvmrc` give nothing.
316
+ rt_node_pin() {
317
+ local pin
318
+ # A byte order mark ahead of the version is dropped with the rest of the blank.
319
+ pin="$({ LC_ALL=C sed -e "s/^$(printf '\357\273\277')//" -e 's/#.*//' -e 's/[[:space:]]//g' "${1:-.}/.nvmrc" | grep -m 1 .; } 2>/dev/null)"
320
+ pin="${pin#v}"
321
+ case "$pin" in '' | *[!0-9.]* | .* | *..* | *.) return 0 ;; esac
322
+ printf '%s' "$pin"
323
+ }
324
+
325
+ # Whether version $1 is not lower than version $2, part by part as numbers: 22.01 equals 22.1.
326
+ rt_node_at_least() {
327
+ awk -v a="$1" -v b="$2" 'BEGIN { n = split(a, x, "."); m = split(b, y, "."); if (m > n) n = m
328
+ for (i = 1; i <= n; i++) { if (x[i] + 0 > y[i] + 0) exit 0; if (x[i] + 0 < y[i] + 0) exit 1 } exit 0 }'
329
+ }
330
+
331
+ # Whether node $1 serves pin $2: the pinned version itself; for a major or a major and a minor, any
332
+ # version under it; for a full version, a newer one of the same major too.
333
+ rt_node_serves() {
334
+ local have="$1" pin="$2"
335
+ case "$have" in "$pin" | "$pin".*) return 0 ;; esac
336
+ case "$pin" in *.*.*) [ "${have%%.*}" = "${pin%%.*}" ] && rt_node_at_least "$have" "$pin" ;; *) return 1 ;; esac
337
+ }
338
+
339
+ # The bin directory of the pinned node under nvm. A full version takes its own directory, and with
340
+ # none — the highest installed one of the same major above it; a major or a major and a minor takes
341
+ # the highest installed version under it. An install with no executable node is passed over. The
342
+ # steps of a set run on it: the node the hook inherits may be another one, and a tree that demands
343
+ # its node refuses that.
344
+ rt_node_pinned_dir() {
345
+ local pin base found version
346
+ pin="$(rt_node_pin "${1:-.}")"
347
+ [ -n "$pin" ] || return 0
348
+ base="${NVM_DIR:-$HOME/.nvm}/versions/node"
349
+ [ -x "$base/v$pin/bin/node" ] && printf '%s' "$base/v$pin/bin" && return 0
350
+ for found in "$base"/v*/bin/node; do
351
+ [ -x "$found" ] || continue
352
+ version="${found%/bin/node}"
353
+ printf '%s\n' "${version##*/v}"
354
+ done | grep -E '^[0-9]+(\.[0-9]+)*$' | sort -t. -k1,1nr -k2,2nr -k3,3nr | while IFS= read -r version; do
355
+ rt_node_serves "$version" "$pin" && printf '%s' "$base/v$version/bin" && break
356
+ done || true
357
+ return 0
358
+ }
359
+
360
+ # One line when no installed node serves the pin and the node of PATH does not serve it either: no
361
+ # step of a set runs then, and the line names the command that installs it. A node of PATH that
362
+ # serves the pin runs the steps as before.
363
+ rt_node_pin_mismatch() {
364
+ local root="${1:-.}" pin have shown
365
+ pin="$(rt_node_pin "$root")"
366
+ [ -n "$pin" ] || return 0
367
+ [ -n "$(rt_node_pinned_dir "$root")" ] && return 0
368
+ have="$(node --version 2>/dev/null)"
369
+ have="${have#v}"
370
+ [ -n "$have" ] && rt_node_serves "$have" "$pin" && return 0
371
+ shown="${have:+v$have}"
372
+ printf 'node v%s is pinned in .nvmrc and not installed; PATH gives %s — nvm install %s' \
373
+ "$pin" "${shown:-no node}" "$pin"
374
+ }
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PreToolUse Edit|Write|MultiEdit|Bash
3
+ # Requires: checks/task-flow-script.mjs, checks/decide.mjs, hooks/decide.sh, hooks/facts.sh
4
+ # PreToolUse guard of the course of work: the scenario moves by a measurement, not by a declaration.
5
+ #
6
+ # The progress used to say what was done, and the guards believed the line. Now a step is done when
7
+ # the engine measured its check and wrote a green mark, and a state is reached when the engine
8
+ # measures it. The guard refuses the edits that would move the scenario past the measurement: a done
9
+ # mark without a green mark, done and current marks out of order, a state line ahead of the measured
10
+ # state, a shell write into the progress, the plan, the epic plan or the marks, «отложено» without the
11
+ # owner's word naming the task, and an edit of the description of the task flow outside a task whose
12
+ # approved plan names it.
13
+ #
14
+ # The decisions live in the engine — `task-flow-script.mjs guard` — and this file only hands it the
15
+ # input and turns its line into a refusal. The whole rule — rule `task-flow`.
16
+ #
17
+ # FAIL-OPEN: no node, no engine, not a git repository, broken input, an engine that fails or prints
18
+ # nothing → pass. A broken guard must not get in the way of work.
19
+
20
+ RT_GUARD_NAME=flow-step-guard
21
+ RT_GUARD_RULE=task-flow
22
+
23
+ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24
+ command -v node >/dev/null 2>&1 || exit 0
25
+
26
+ input="${RT_HOOK_INPUT:-$(cat 2>/dev/null)}"
27
+ [ -n "$input" ] || exit 0
28
+
29
+ # A shell command that names none of the guarded files is not handed to the engine: every command
30
+ # passes here, and a start of node costs each of them. The sign errs towards firing — a name in any
31
+ # place of the command hands it over. An edit is always handed over: the epic plans may lie in a
32
+ # directory of the tree's own name.
33
+ tool="$(printf '%s' "$input" | jq -r '.tool_name // empty' 2>/dev/null)"
34
+ if [ "$tool" = Bash ]; then
35
+ printf '%s' "$input" | grep -qE 'progress\.md|plan\.md|plans/|rt-kit|task-flow|flow-[a-z-]+\.mjs|\.claude/projects/' || exit 0
36
+ fi
37
+
38
+ # The engine lies next to the hooks in the package and in tools/ where it is laid out.
39
+ engine=""
40
+ for candidate in "$rt_hooks_dir/../checks/task-flow-script.mjs" "${CLAUDE_PROJECT_DIR:-.}/tools/task-flow-script.mjs"; do
41
+ [ -f "$candidate" ] && engine="$candidate" && break
42
+ done
43
+ [ -n "$engine" ] || exit 0
44
+
45
+ # The engine reads the tree of the call: the directory the hook names, or the project.
46
+ dir="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null)"
47
+ [ -d "$dir" ] || dir="${CLAUDE_PROJECT_DIR:-.}"
48
+
49
+ verdict="$(cd "$dir" && printf '%s' "$input" | timeout 60 node "$engine" guard 2>/dev/null)" || exit 0
50
+ [ -n "$verdict" ] || exit 0
51
+
52
+ # The decision, the move and the text come from the decision table. The engine gives its reason;
53
+ # the kind of the reason is the action the table knows, and the facts are those the neighbours
54
+ # judge the named move by — the decider puts first what they want.
55
+ case "$verdict" in
56
+ *"has no green mark"* | *"marked done after"* | *"marked current after"* | *"done steps go first"*) action=mark_step_done ;;
57
+ *"is ahead of the measured one"*) action=set_state ;;
58
+ *"are written only by the engine"* | *"are written only by the harness"*) action=write_marks ;;
59
+ *"is edited by the edit tool, not by a shell command"* | *"are edited by the edit tool, not by a shell command"*) action=shell_write_progress ;;
60
+ *"override of the description is edited by the edit tool"*) action=shell_write_progress ;;
61
+ *"belongs to the description of the task flow"*) action=edit_flow_description ;;
62
+ *"the replacement of the check of step"*"is the owner's decision"*) action=replace_step_check ;;
63
+ *"шаг владельца"*"is not written into a row"*) action=owner_step_row ;;
64
+ *) action=defer_task ;;
65
+ esac
66
+
67
+ # shellcheck disable=SC1091
68
+ . "$rt_hooks_dir/facts.sh" 2>/dev/null
69
+ sid="$(printf '%s' "$input" | jq -r '.session_id // "nosession"' 2>/dev/null)"
70
+ transcript="$(rt_fact_transcript "$input")"
71
+ exam="$(rt_fact_exam_holds "$transcript")"
72
+ # The move the refusal names is an edit of the progress or of the plan; the gate is asked about that
73
+ # file, and the window and the handover entry about the rule of the course of work.
74
+ tasks_root="$(git -C "$dir" rev-parse --show-toplevel 2>/dev/null)/${RT_TASKS_DIR:-docs/tasks}/$(rt_fact_branch "$dir")"
75
+ case "$action" in
76
+ edit_flow_description) move_file="$tasks_root/plan.md" ;;
77
+ *) move_file="$tasks_root/progress.md" ;;
78
+ esac
79
+ move_input="$(jq -cn --arg f "$move_file" '{file_path:$f,old_string:"",new_string:""}')"
80
+ facts="$(jq -cn \
81
+ --arg exam "$exam" \
82
+ --arg window "$(rt_fact_window_over_stop "$sid" "$transcript")" \
83
+ --arg rule "$(rt_fact_move_rule_loaded Edit "$move_input" "$sid")" \
84
+ --arg gate "$(rt_fact_move_gate_rule Edit "$move_input" "$sid")" \
85
+ --arg flow "$(rt_fact_rule_loaded "${RT_TASK_FLOW_RULE:-task-flow}" "$sid")" \
86
+ --arg handoff "$(rt_fact_from_handoff "$transcript")" \
87
+ '{exam:$exam, window_over_stop:$window, rule_loaded:$rule, gate_rule:$gate, from_handoff:$handoff,
88
+ task_flow_loaded:$flow, step_green:"no", measured:"earlier", owner_named_task:"no", flow_desc_approved:"no"}')"
89
+ params="$(jq -cn --arg v "$verdict" '{verdict:$v}')"
90
+ # shellcheck disable=SC1091
91
+ . "$rt_hooks_dir/decide.sh" 2>/dev/null
92
+ command -v rt_decide >/dev/null 2>&1 && rt_decide flow-step-guard.sh "$action" "$facts" "$params" PreToolUse "$input"
93
+ exit 0
@@ -37,13 +37,13 @@ rt_delivery_pull_body() {
37
37
  # The section about the remaining step: without it the owner merges the PR by the button while
38
38
  # the run is still going.
39
39
  if [ -n "$pull_body_section" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
40
- fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
40
+ unmet_class pr_create_thin_body "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
41
41
  fi
42
42
 
43
43
  # The table of points: without it the owner learns whether the work reached its point only after
44
44
  # the merge. The guard sees the heading, not whether the signs were run.
45
45
  if [ -n "$pull_points_section" ] && ! printf '%s' "$body" | grep -qE "$pull_points_section"; then
46
- fault "the body of the request carries no section with the table of points. The owner decides on the request page whether the work reached its point. Run the role product-strategist and put its table of points into the body; a sign not run is written as not run."
46
+ unmet_class pr_create_thin_body "the body of the request carries no section with the table of points. The owner decides on the request page whether the work reached its point. Run the role product-strategist and put its table of points into the body; a sign not run is written as not run."
47
47
  fi
48
48
 
49
49
  # The table of the critic: the session's own points prove nothing about what the owner asked for.
@@ -57,7 +57,7 @@ rt_delivery_pull_body() {
57
57
  END { print rows + 0 }
58
58
  ')"
59
59
  [ "$goal_rows" -ge 3 ] \
60
- || fault "the body of the request carries no section with the table of the critic. Give the role goal-critic the owner's words verbatim and the result, and put its table into the body word for word."
60
+ || unmet_class pr_create_thin_body "the body of the request carries no section with the table of the critic. Give the role goal-critic the owner's words verbatim and the result, and put its table into the body word for word."
61
61
  fi
62
62
 
63
63
  # The line that closes the task. Without it the merged task stays open on the board, and the
@@ -67,7 +67,7 @@ rt_delivery_pull_body() {
67
67
  if [ -n "$pull_closes_line" ] && [ -n "$number" ]; then
68
68
  closes="${pull_closes_line//\{number\}/$number}"
69
69
  printf '%s' "$body" | grep -qE "$closes" \
70
- || fault "the body of the request carries no line that closes the task #${number}. Without it the task stays open after the merge, and the board shows the merged work as not done. Write the line by the sample of the tree: ${closes}"
70
+ || unmet_class pr_create_thin_body "the body of the request carries no line that closes the task #${number}. Without it the task stays open after the merge, and the board shows the merged work as not done. Write the line by the sample of the tree: ${closes}"
71
71
  fi
72
72
  return 0
73
73
  }
@@ -53,7 +53,7 @@
53
53
  rt_delivery_led_branch() {
54
54
  named="$1"
55
55
  [ -z "$named" ] && return 0
56
- [ "$named" = "$(git -C "$root" rev-parse --abbrev-ref HEAD 2>/dev/null)" ] && return 0
56
+ [ "$named" = "$(rt_fact_branch "$root")" ] && return 0
57
57
  git -C "$root" reflog HEAD -n 400 2>/dev/null \
58
58
  | awk -v branch="$named" '
59
59
  /checkout: moving from / { if ($NF == branch) { found = 1 } }
@@ -74,8 +74,11 @@ rt_delivery_note_out() {
74
74
  rt_delivery_conflict() {
75
75
  # The sign of taking work is read from the text of the command and stands first: the query goes
76
76
  # to the network, and paying for it on every shell command is not allowed.
77
- taking=''
78
- case "$cmd" in
77
+ #
78
+ # A caller whose own refusal is about to name new work passes what that work is: the push into a
79
+ # merged branch names a new task, and that move is refused here while a conflict stands.
80
+ taking="${1:-}"
81
+ [ -n "$taking" ] || case "$cmd" in
79
82
  *"${task_new}"*) taking='creating a task' ;;
80
83
  esac
81
84
  # Moving the column is judged together with the name of the work column: a move into review and
@@ -132,11 +135,14 @@ The branch is led by another session and holds its own commits: a merge of the m
132
135
  fi
133
136
  [ -z "$listed" ] && return 0
134
137
 
135
- deny "BLOCKED: ${taking} while a conflicting request of your own stands. What was handed over conflicts with the main branch, and a person cannot merge it:
136
-
137
- ${listed}
138
-
139
- The conflict arrives by someone else's merge, without a single action by the author of the request: it stands until it is caught up with. New work does not fix it — it adds one more branch to the queue, growing from the same main and falling behind the same way.
140
-
141
- There is one move from here: pull the main branch, merge it into the named branch, resolve the conflict and send it — and only then take new work. What is fixed by what — the pattern git-workflow-freshness."
138
+ # The action of the table is the move being taken; the words are the table's.
139
+ case "$taking" in
140
+ 'creating a task') _action=task_new ;;
141
+ 'moving the column into work') _action=task_move ;;
142
+ 'creating a branch for a task') _action=branch_create ;;
143
+ 'opening a request') _action=pr_create ;;
144
+ *) _action=push ;;
145
+ esac
146
+ fact own_pr_conflicting yes
147
+ refuse "$_action" "$(jq -cn --arg t "$taking" --arg l "$listed" '{taking:$t, listed:$l}')"
142
148
  }
@@ -78,7 +78,7 @@ rt_delivery_draft_ready() {
78
78
  # The head branch of the PR goes to the folder condition below.
79
79
  pull_head="$(printf '%s' "$pull" | jq -r '.branch // empty' 2>/dev/null)"
80
80
  printf '%s' "$pull" | jq -e '.reviewed' >/dev/null 2>&1 \
81
- || fault "the request${pull_name} has no review: no reviewer was requested and nobody left a review. A lifted draft reads as «ready to merge», and there is nobody to merge — set a reviewer and repeat."
81
+ || unmet pr_reviewed no "the request${pull_name} has no review: no reviewer was requested and nobody left a review. A lifted draft reads as «ready to merge», and there is nobody to merge — set a reviewer and repeat."
82
82
 
83
83
  # A conflict arrives into a handed-over PR through someone else's merge, without
84
84
  # a single action by its author: the base checked at opening is yesterday's by the
@@ -87,7 +87,7 @@ rt_delivery_draft_ready() {
87
87
  # unknown mergeability stays: the hosting recomputes it after every edit of the
88
88
  # main branch, and "not computed yet" is not "conflicts".
89
89
  printf '%s' "$pull" | jq -e '.conflicting' >/dev/null 2>&1 \
90
- && fault "the request${pull_name} conflicts with the main branch. Merge it into your branch, resolve the conflict and repeat: a lifted draft reads as «ready to merge», and this request cannot be merged."
90
+ && unmet pr_conflicting yes "the request${pull_name} conflicts with the main branch. Merge it into your branch, resolve the conflict and repeat: a lifted draft reads as «ready to merge», and this request cannot be merged."
91
91
 
92
92
  # The author of the PR. The clash that breaks the review — the author named as the
93
93
  # reviewer — is already caught by the condition above: the hosting silently does not
@@ -108,7 +108,7 @@ rt_delivery_draft_ready() {
108
108
  # the network tier above.
109
109
  command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder "$pull_head"
110
110
 
111
- deny_faults
111
+ refuse_unmet pr_ready
112
112
  # The head comes from the hosting: without its answer the number may name another branch.
113
113
  [ -z "$pull_head" ] || rt_delivery_handover "$pull_head"
114
114
  fi