@rt-tools/agent-kit 0.37.0 → 0.38.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 (436) hide show
  1. package/README.md +5 -5
  2. package/assets/checks/action-of.mjs +154 -0
  3. package/assets/checks/board-pull-state.github.mjs +82 -13
  4. package/assets/checks/board-runs.github.mjs +40 -5
  5. package/assets/checks/board.github.mjs +1 -1
  6. package/assets/checks/check-board.github.mjs +58 -19
  7. package/assets/checks/check-specs.mjs +2 -2
  8. package/assets/checks/check-state-next.mjs +22 -10
  9. package/assets/checks/check-turn-map.mjs +26 -6
  10. package/assets/checks/check-work-steps.mjs +4 -173
  11. package/assets/checks/decide.mjs +285 -0
  12. package/assets/checks/decision-table.json +21365 -0
  13. package/assets/checks/decision-table.mjs +495 -0
  14. package/assets/checks/epic-table.github.mjs +4 -3
  15. package/assets/checks/epic-window.mjs +98 -0
  16. package/assets/checks/flow-condition.mjs +64 -0
  17. package/assets/checks/flow-data.mjs +136 -0
  18. package/assets/checks/flow-forecast.mjs +330 -0
  19. package/assets/checks/flow-guard-run.mjs +90 -0
  20. package/assets/checks/flow-guard.mjs +294 -0
  21. package/assets/checks/flow-model.mjs +271 -0
  22. package/assets/checks/flow-override.mjs +130 -0
  23. package/assets/checks/flow-plan.mjs +206 -0
  24. package/assets/checks/flow-scaffold.mjs +224 -0
  25. package/assets/checks/flow-step.mjs +365 -0
  26. package/assets/checks/flow-sync.mjs +296 -0
  27. package/assets/checks/flow-syntax.mjs +292 -0
  28. package/assets/checks/flow-verdict.mjs +112 -0
  29. package/assets/checks/lib-common.mjs +10 -2
  30. package/assets/checks/lib-domains.mjs +1 -1
  31. package/assets/checks/lib-manifests.mjs +34 -2
  32. package/assets/checks/merge-read.mjs +239 -0
  33. package/assets/checks/owner-nudges.mjs +389 -0
  34. package/assets/checks/push-inputs.mjs +444 -0
  35. package/assets/checks/push-trace.mjs +108 -0
  36. package/assets/checks/record-count.mjs +410 -0
  37. package/assets/checks/record-recount.mjs +187 -0
  38. package/assets/checks/record-turn.mjs +155 -0
  39. package/assets/checks/rt-kit-checks.config.mjs +17 -2
  40. package/assets/checks/spec-anchors.mjs +4 -4
  41. package/assets/checks/spec-contract.mjs +5 -5
  42. package/assets/checks/task-flow-script.mjs +292 -0
  43. package/assets/checks/tree-assignment.mjs +26 -7
  44. package/assets/checks/work-result.mjs +281 -0
  45. package/assets/checks/work-steps-lib.mjs +205 -0
  46. package/assets/commands/next-session.md +3 -1
  47. package/assets/commands/night.md +28 -18
  48. package/assets/defaults/gate-map.sh +39 -12
  49. package/assets/defaults/merges.sh +48 -0
  50. package/assets/defaults/project.sh +43 -13
  51. package/assets/defaults/push.sh +23 -0
  52. package/assets/defaults/turn-map.md +24 -21
  53. package/assets/docs/GLOSSARY.md +6 -2
  54. package/assets/hooks/ask-judge.md +65 -0
  55. package/assets/hooks/browser-guard-device-id.sh +11 -9
  56. package/assets/hooks/browser-guard-no-asking.sh +12 -6
  57. package/assets/hooks/browser-guard-no-listing.sh +13 -7
  58. package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
  59. package/assets/hooks/browser-guard-require-select.sh +15 -15
  60. package/assets/hooks/commit-msg.sh +13 -3
  61. package/assets/hooks/conscience-guard.sh +9 -25
  62. package/assets/hooks/decide.sh +141 -0
  63. package/assets/hooks/deny-tail.sh +16 -11
  64. package/assets/hooks/dev-server-guard.sh +27 -20
  65. package/assets/hooks/dispatch.sh +47 -4
  66. package/assets/hooks/docs-guard.sh +31 -200
  67. package/assets/hooks/end-conversation-guard.sh +12 -21
  68. package/assets/hooks/epic-stop-guard.sh +54 -105
  69. package/assets/hooks/exam-guard.sh +32 -65
  70. package/assets/hooks/facts-docs.sh +221 -0
  71. package/assets/hooks/facts-flow.sh +173 -0
  72. package/assets/hooks/facts.sh +308 -0
  73. package/assets/hooks/flow-step-guard.sh +93 -0
  74. package/assets/hooks/git-guard-delivery-body.sh +4 -4
  75. package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
  76. package/assets/hooks/git-guard-delivery-draft.sh +3 -3
  77. package/assets/hooks/git-guard-delivery-epic.sh +18 -9
  78. package/assets/hooks/git-guard-delivery-folder.sh +32 -7
  79. package/assets/hooks/git-guard-delivery-merge.sh +2 -2
  80. package/assets/hooks/git-guard-delivery-merged.sh +12 -1
  81. package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
  82. package/assets/hooks/git-guard-delivery-rerun.sh +32 -0
  83. package/assets/hooks/git-guard-delivery-signature.sh +82 -45
  84. package/assets/hooks/git-guard-delivery-task.sh +47 -0
  85. package/assets/hooks/git-guard-delivery.sh +112 -101
  86. package/assets/hooks/git-guard-discard.sh +8 -18
  87. package/assets/hooks/git-guard-main.sh +13 -19
  88. package/assets/hooks/git-guard-no-verify.sh +56 -16
  89. package/assets/hooks/git-guard-push-ahead.sh +46 -5
  90. package/assets/hooks/git-guard-push-marks.sh +227 -31
  91. package/assets/hooks/git-guard-push-tests.sh +51 -53
  92. package/assets/hooks/git-guard-tree-assignment.sh +7 -4
  93. package/assets/hooks/guard-note.sh +8 -6
  94. package/assets/hooks/handoff-entry-guard.sh +20 -39
  95. package/assets/hooks/handoff-write.sh +3 -1
  96. package/assets/hooks/hook-input.sh +0 -41
  97. package/assets/hooks/metric-marks.sh +19 -7
  98. package/assets/hooks/observe.sh +1 -1
  99. package/assets/hooks/override-write-guard.sh +27 -9
  100. package/assets/hooks/pre-push.sh +20 -10
  101. package/assets/hooks/prose-style-guard.sh +6 -19
  102. package/assets/hooks/pull-merges.sh +76 -0
  103. package/assets/hooks/push-set.sh +39 -7
  104. package/assets/hooks/qa-dataid-guard.sh +7 -17
  105. package/assets/hooks/record-turn.sh +52 -0
  106. package/assets/hooks/rerun-guard.sh +11 -16
  107. package/assets/hooks/reuse-first-guard.sh +7 -21
  108. package/assets/hooks/role-calls.sh +25 -3
  109. package/assets/hooks/rule-source-guard.sh +54 -21
  110. package/assets/hooks/skill-gate-rearm.sh +18 -5
  111. package/assets/hooks/skill-gate.sh +156 -20
  112. package/assets/hooks/skill-loaded.sh +18 -3
  113. package/assets/hooks/sql-guard-target.sh +2 -2
  114. package/assets/hooks/sql-guard-write.sh +12 -12
  115. package/assets/hooks/sql-guard.sh +58 -16
  116. package/assets/hooks/task-context-load.sh +3 -1
  117. package/assets/hooks/task-flow-context.sh +20 -22
  118. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  119. package/assets/hooks/task-flow-guard.sh +28 -129
  120. package/assets/hooks/tree-assignment-guard.sh +25 -14
  121. package/assets/hooks/turn-entry-load.sh +3 -1
  122. package/assets/hooks/turn-exit-guard.sh +92 -452
  123. package/assets/hooks/turn-exit-role.sh +47 -0
  124. package/assets/hooks/turn-judge.md +103 -0
  125. package/assets/hooks/window-fill-guard.sh +22 -41
  126. package/assets/laws/work-conduct.md +9 -8
  127. package/assets/patterns/autonomous-work-run.md +35 -10
  128. package/assets/patterns/browser-verification-measure.md +10 -20
  129. package/assets/patterns/browser-verification-stand.md +30 -42
  130. package/assets/patterns/doc-style-human.md +0 -6
  131. package/assets/patterns/doc-style-sweep.md +7 -7
  132. package/assets/patterns/doc-style-trace.md +5 -4
  133. package/assets/patterns/doc-style-write.md +7 -7
  134. package/assets/patterns/epic-flow-declare.md +15 -8
  135. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  136. package/assets/patterns/git-workflow-commit.github.md +11 -269
  137. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  138. package/assets/patterns/git-workflow-docker.md +8 -231
  139. package/assets/patterns/git-workflow-freshness.md +9 -56
  140. package/assets/patterns/git-workflow-merge.md +7 -174
  141. package/assets/patterns/git-workflow-migration.md +5 -73
  142. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  143. package/assets/patterns/git-workflow-pr-ready.md +9 -69
  144. package/assets/patterns/git-workflow-pr.azure.md +14 -220
  145. package/assets/patterns/git-workflow-pr.github.md +13 -253
  146. package/assets/patterns/git-workflow-pr.gitlab.md +14 -241
  147. package/assets/patterns/git-workflow-restart.md +5 -41
  148. package/assets/patterns/git-workflow-secrets.md +10 -76
  149. package/assets/patterns/git-workflow-stack.md +9 -205
  150. package/assets/patterns/lib-layers-new.md +7 -3
  151. package/assets/patterns/queue-audit-read.github.md +9 -3
  152. package/assets/patterns/spec-driven-domain.md +50 -48
  153. package/assets/patterns/spec-driven-rule.md +18 -19
  154. package/assets/patterns/status-report-table.github.md +2 -2
  155. package/assets/patterns/task-flow-archive.md +15 -256
  156. package/assets/patterns/task-flow-close.md +16 -291
  157. package/assets/patterns/task-flow-cycle.md +13 -39
  158. package/assets/patterns/task-flow-graph.needs-graph.md +8 -58
  159. package/assets/patterns/task-flow-handoff.md +13 -161
  160. package/assets/patterns/task-flow-resume.md +19 -183
  161. package/assets/patterns/task-flow-start.md +9 -248
  162. package/assets/patterns/testing-e2e.md +14 -18
  163. package/assets/patterns/testing-unit.md +9 -13
  164. package/assets/patterns/turn-entry-map.md +15 -5
  165. package/assets/pitfalls/agent-kit-extend.md +200 -0
  166. package/assets/pitfalls/agent-kit.2.md +323 -0
  167. package/assets/pitfalls/angular-patterns.md +98 -0
  168. package/assets/pitfalls/autonomous-work.md +15 -0
  169. package/assets/pitfalls/browser-verification.md +265 -0
  170. package/assets/pitfalls/component-structure.md +98 -0
  171. package/assets/pitfalls/dependencies.md +92 -0
  172. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  173. package/assets/pitfalls/deploy-flow.github.md +211 -0
  174. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  175. package/assets/pitfalls/doc-style.2.md +286 -0
  176. package/assets/pitfalls/doc-style.md +3 -3
  177. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  178. package/assets/pitfalls/entity-models.md +89 -0
  179. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  180. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  181. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  182. package/assets/pitfalls/git-workflow-docker.md +275 -0
  183. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  184. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  185. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  186. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  187. package/assets/pitfalls/git-workflow-merge.md +220 -0
  188. package/assets/pitfalls/git-workflow-migration.md +103 -0
  189. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  190. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  191. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  192. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  193. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  194. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  195. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  196. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  197. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  198. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  199. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  200. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  201. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  202. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  203. package/assets/pitfalls/git-workflow-restart.md +72 -0
  204. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  205. package/assets/pitfalls/git-workflow-stack.md +254 -0
  206. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  207. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  208. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  209. package/assets/pitfalls/git-workflow.github.md +5 -9
  210. package/assets/pitfalls/lib-layers.md +114 -0
  211. package/assets/pitfalls/lists.md +117 -0
  212. package/assets/pitfalls/navigation.md +94 -0
  213. package/assets/pitfalls/reuse-first.md +201 -0
  214. package/assets/pitfalls/spec-driven.2.md +318 -0
  215. package/assets/pitfalls/spec-driven.md +9 -7
  216. package/assets/pitfalls/styling-bem.2.md +125 -0
  217. package/assets/pitfalls/task-flow-archive.md +264 -0
  218. package/assets/pitfalls/task-flow-close.2.md +165 -0
  219. package/assets/pitfalls/task-flow-close.md +167 -0
  220. package/assets/pitfalls/task-flow-cycle.md +73 -0
  221. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  222. package/assets/pitfalls/task-flow-handoff.md +200 -0
  223. package/assets/pitfalls/task-flow-handover.md +30 -0
  224. package/assets/pitfalls/task-flow-owner.md +29 -0
  225. package/assets/pitfalls/task-flow-plan.md +29 -0
  226. package/assets/pitfalls/task-flow-resume.md +257 -0
  227. package/assets/pitfalls/task-flow-start.md +287 -0
  228. package/assets/pitfalls/task-flow.2.md +303 -0
  229. package/assets/pitfalls/task-flow.md +18 -29
  230. package/assets/pitfalls/testing.2.md +279 -0
  231. package/assets/pitfalls/testing.md +11 -12
  232. package/assets/pitfalls/turn-conduct.md +17 -18
  233. package/assets/pitfalls/typescript-conventions.md +161 -0
  234. package/assets/pitfalls/write-a-skill.md +128 -0
  235. package/assets/rules/angular-patterns.md +21 -86
  236. package/assets/rules/autonomous-work.md +37 -29
  237. package/assets/rules/browser-verification.md +28 -251
  238. package/assets/rules/component-structure.md +25 -87
  239. package/assets/rules/dependencies.md +20 -78
  240. package/assets/rules/deploy-flow.azure.md +27 -134
  241. package/assets/rules/deploy-flow.github.md +34 -196
  242. package/assets/rules/deploy-flow.gitlab.md +28 -137
  243. package/assets/rules/doc-style.md +32 -282
  244. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  245. package/assets/rules/entity-models.md +14 -63
  246. package/assets/rules/epic-flow.md +5 -3
  247. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  248. package/assets/rules/git-workflow-hosting.github.md +38 -0
  249. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  250. package/assets/rules/git-workflow-push.azure.md +28 -0
  251. package/assets/rules/git-workflow-push.github.md +28 -0
  252. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  253. package/assets/rules/git-workflow-queue.azure.md +23 -0
  254. package/assets/rules/git-workflow-queue.github.md +30 -0
  255. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  256. package/assets/rules/git-workflow.azure.md +21 -264
  257. package/assets/rules/git-workflow.github.md +24 -285
  258. package/assets/rules/git-workflow.gitlab.md +21 -258
  259. package/assets/rules/lib-layers.md +30 -103
  260. package/assets/rules/lists.md +21 -105
  261. package/assets/rules/navigation.md +10 -69
  262. package/assets/rules/queue-audit.github.md +5 -3
  263. package/assets/rules/reuse-first.md +20 -195
  264. package/assets/rules/spec-driven.md +35 -316
  265. package/assets/rules/status-report.md +5 -3
  266. package/assets/rules/styling-bem.md +20 -117
  267. package/assets/rules/task-flow-handover.md +24 -0
  268. package/assets/rules/task-flow-owner.md +34 -0
  269. package/assets/rules/task-flow-plan.md +38 -0
  270. package/assets/rules/task-flow.md +22 -289
  271. package/assets/rules/testing.md +32 -270
  272. package/assets/rules/turn-conduct.md +109 -111
  273. package/assets/rules/turn-entry.md +2 -2
  274. package/assets/rules/typescript-conventions.md +41 -147
  275. package/assets/samples/tasks/_template/plan.md +30 -6
  276. package/assets/samples/tasks/_template/progress.md +0 -1
  277. package/assets/skills/agent-kit-extend.md +25 -168
  278. package/assets/skills/agent-kit.md +27 -299
  279. package/assets/skills/write-a-skill.md +20 -106
  280. package/assets/task-flow/flow.js +188 -0
  281. package/assets/task-flow/flow.md +102 -0
  282. package/assets/task-flow/measure/agreement.mjs +24 -0
  283. package/assets/task-flow/measure/copy.mjs +22 -0
  284. package/assets/task-flow/measure/epic-of.mjs +50 -0
  285. package/assets/task-flow/measure/epic-text.mjs +35 -0
  286. package/assets/task-flow/measure/epic.mjs +114 -0
  287. package/assets/task-flow/measure/folder.mjs +16 -0
  288. package/assets/task-flow/measure/footprint.mjs +28 -0
  289. package/assets/task-flow/measure/grill.mjs +21 -0
  290. package/assets/task-flow/measure/host.mjs +8 -0
  291. package/assets/task-flow/measure/owner.mjs +20 -0
  292. package/assets/task-flow/measure/plan.mjs +27 -0
  293. package/assets/task-flow/measure/pr.mjs +20 -0
  294. package/assets/task-flow/measure/progress.mjs +50 -0
  295. package/assets/task-flow/measure/session.mjs +175 -0
  296. package/assets/task-flow/measure/task.mjs +23 -0
  297. package/assets/task-flow/measure/text.mjs +77 -0
  298. package/assets/task-flow/source/git.mjs +86 -0
  299. package/assets/task-flow/source/host.mjs +172 -0
  300. package/assets/task-flow/source/marks.mjs +56 -0
  301. package/assets/task-flow/source/owner.mjs +74 -0
  302. package/assets/task-flow/source/records.mjs +116 -0
  303. package/assets/task-flow/source/session.mjs +232 -0
  304. package/assets/task-flow/source/steps.mjs +28 -0
  305. package/assets/task-flow/source/tree.mjs +42 -0
  306. package/assets/templates/rule.md +2 -2
  307. package/bin/agent-kit.d.ts.map +1 -1
  308. package/bin/agent-kit.js +30 -0
  309. package/bin/agent-kit.js.map +1 -1
  310. package/lib/agent-checks.d.ts +55 -0
  311. package/lib/agent-checks.d.ts.map +1 -0
  312. package/lib/agent-checks.js +209 -0
  313. package/lib/agent-checks.js.map +1 -0
  314. package/lib/assets.d.ts.map +1 -1
  315. package/lib/assets.js +7 -2
  316. package/lib/assets.js.map +1 -1
  317. package/lib/cargo-prose.d.ts +2 -1
  318. package/lib/cargo-prose.d.ts.map +1 -1
  319. package/lib/cargo-prose.js.map +1 -1
  320. package/lib/cargo.d.ts +29 -0
  321. package/lib/cargo.d.ts.map +1 -1
  322. package/lib/cargo.js +27 -1
  323. package/lib/cargo.js.map +1 -1
  324. package/lib/cascade.d.ts.map +1 -1
  325. package/lib/cascade.js +3 -1
  326. package/lib/cascade.js.map +1 -1
  327. package/lib/commands.d.ts.map +1 -1
  328. package/lib/commands.js +78 -2
  329. package/lib/commands.js.map +1 -1
  330. package/lib/companion.d.ts +0 -5
  331. package/lib/companion.d.ts.map +1 -1
  332. package/lib/companion.js +1 -1
  333. package/lib/companion.js.map +1 -1
  334. package/lib/config.d.ts +18 -0
  335. package/lib/config.d.ts.map +1 -1
  336. package/lib/config.js +18 -1
  337. package/lib/config.js.map +1 -1
  338. package/lib/cost.d.ts +0 -8
  339. package/lib/cost.d.ts.map +1 -1
  340. package/lib/cost.js +4 -4
  341. package/lib/cost.js.map +1 -1
  342. package/lib/epic-window-send.d.ts +74 -0
  343. package/lib/epic-window-send.d.ts.map +1 -0
  344. package/lib/epic-window-send.js +166 -0
  345. package/lib/epic-window-send.js.map +1 -0
  346. package/lib/hooks-map.d.ts +4 -12
  347. package/lib/hooks-map.d.ts.map +1 -1
  348. package/lib/hooks-map.js +4 -27
  349. package/lib/hooks-map.js.map +1 -1
  350. package/lib/integrity.d.ts +3 -0
  351. package/lib/integrity.d.ts.map +1 -1
  352. package/lib/integrity.js +7 -0
  353. package/lib/integrity.js.map +1 -1
  354. package/lib/metric-lines.d.ts +2 -1
  355. package/lib/metric-lines.d.ts.map +1 -1
  356. package/lib/metric-lines.js +49 -1
  357. package/lib/metric-lines.js.map +1 -1
  358. package/lib/metric-send-mark.d.ts +6 -3
  359. package/lib/metric-send-mark.d.ts.map +1 -1
  360. package/lib/metric-send-mark.js +15 -5
  361. package/lib/metric-send-mark.js.map +1 -1
  362. package/lib/metric-send.d.ts +6 -2
  363. package/lib/metric-send.d.ts.map +1 -1
  364. package/lib/metric-send.js +47 -13
  365. package/lib/metric-send.js.map +1 -1
  366. package/lib/metrics.d.ts +17 -0
  367. package/lib/metrics.d.ts.map +1 -1
  368. package/lib/metrics.js +26 -15
  369. package/lib/metrics.js.map +1 -1
  370. package/lib/observations-cargo.d.ts +1 -5
  371. package/lib/observations-cargo.d.ts.map +1 -1
  372. package/lib/observations-cargo.js +2 -2
  373. package/lib/observations-cargo.js.map +1 -1
  374. package/lib/observations.d.ts +0 -2
  375. package/lib/observations.d.ts.map +1 -1
  376. package/lib/observations.js +3 -3
  377. package/lib/observations.js.map +1 -1
  378. package/lib/order.d.ts +0 -2
  379. package/lib/order.d.ts.map +1 -1
  380. package/lib/order.js +0 -4
  381. package/lib/order.js.map +1 -1
  382. package/lib/outcomes.d.ts +7 -9
  383. package/lib/outcomes.d.ts.map +1 -1
  384. package/lib/outcomes.js +8 -7
  385. package/lib/outcomes.js.map +1 -1
  386. package/lib/proposals.d.ts +0 -1
  387. package/lib/proposals.d.ts.map +1 -1
  388. package/lib/proposals.js +1 -1
  389. package/lib/proposals.js.map +1 -1
  390. package/lib/push-gate.d.ts +13 -0
  391. package/lib/push-gate.d.ts.map +1 -1
  392. package/lib/push-gate.js +11 -7
  393. package/lib/push-gate.js.map +1 -1
  394. package/lib/push-set-usefulness.d.ts +78 -0
  395. package/lib/push-set-usefulness.d.ts.map +1 -0
  396. package/lib/push-set-usefulness.js +225 -0
  397. package/lib/push-set-usefulness.js.map +1 -0
  398. package/lib/shipment.d.ts +2 -11
  399. package/lib/shipment.d.ts.map +1 -1
  400. package/lib/shipment.fixture.d.ts +0 -3
  401. package/lib/shipment.fixture.d.ts.map +1 -1
  402. package/lib/shipment.fixture.js +3 -3
  403. package/lib/shipment.fixture.js.map +1 -1
  404. package/lib/shipment.js +2 -2
  405. package/lib/shipment.js.map +1 -1
  406. package/lib/sync.d.ts +10 -0
  407. package/lib/sync.d.ts.map +1 -1
  408. package/lib/sync.js +14 -1
  409. package/lib/sync.js.map +1 -1
  410. package/lib/traits.d.ts +0 -3
  411. package/lib/traits.d.ts.map +1 -1
  412. package/lib/traits.js +2 -2
  413. package/lib/traits.js.map +1 -1
  414. package/lib/variants.d.ts +0 -1
  415. package/lib/variants.d.ts.map +1 -1
  416. package/lib/variants.js +1 -1
  417. package/lib/variants.js.map +1 -1
  418. package/lib/work-result.d.ts +43 -0
  419. package/lib/work-result.d.ts.map +1 -0
  420. package/lib/work-result.js +39 -0
  421. package/lib/work-result.js.map +1 -0
  422. package/package.json +1 -1
  423. package/assets/checks/signals/ui-kit.json +0 -11
  424. package/assets/hooks/claim-guard.sh +0 -212
  425. package/assets/hooks/grill-gate-ask.sh +0 -26
  426. package/assets/hooks/grill-gate-bypass.sh +0 -61
  427. package/assets/hooks/grill-gate-options.sh +0 -50
  428. package/assets/hooks/grill-gate.sh +0 -482
  429. package/assets/hooks/postmortem-guard.sh +0 -124
  430. package/assets/hooks/proposal-guard.sh +0 -154
  431. package/assets/hooks/stand-login-guard.sh +0 -107
  432. package/assets/hooks/turn-exit-epic.sh +0 -173
  433. package/assets/hooks/turn-exit-patterns.sh +0 -123
  434. package/assets/hooks/turn-exit-verdict.sh +0 -149
  435. package/assets/hooks/waiting-turn-guard.sh +0 -320
  436. package/assets/hooks/work-start-guard.sh +0 -175
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: PreToolUse Edit|Write|MultiEdit|mcp__webstorm__create_new_file|Bash|mcp__webstorm__execute_terminal_command
3
- # Requires: agents/strict-teacher.md, hooks/roles.sh, hooks/deny-tail.sh, hooks/write-targets.sh
3
+ # Requires: checks/decide.mjs, hooks/decide.sh, hooks/facts.sh, agents/strict-teacher.md, hooks/roles.sh, hooks/deny-tail.sh, hooks/write-targets.sh
4
4
  # Exam guard: no edit goes through until the exam on the loaded rules has been passed this session.
5
5
  #
6
6
  # Why this way. The rules gate demands that a rule be loaded before an edit, and ends there: to
@@ -40,6 +40,7 @@ RT_GUARD_NAME=exam-guard
40
40
 
41
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
42
42
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
43
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null || true
43
44
 
44
45
  rt_hook_read
45
46
  input="$RT_HOOK_INPUT"
@@ -81,6 +82,17 @@ case "$tool" in
81
82
  Edit | Write | MultiEdit | mcp__webstorm__create_new_file)
82
83
  target="$(printf '%s' "$input" | jq -r '.tool_input.file_path // .tool_input.pathInProject // empty' 2>/dev/null)"
83
84
  [ -n "$target" ] && [ "$(printf '%s\n' "$target" | rt_exam_free_paths)" = "yes" ] && exit 0
85
+ # A window past its stop threshold: the window guard lets through only the closing — the
86
+ # progress and the handover — and refuses the examiner role itself. Holding the progress
87
+ # for an exam then names a move the window guard denies, and the session cannot close.
88
+ # The window fact reads the mark of the window guard, and before the mark it counts the fill
89
+ # the way the window guard counts it.
90
+ case "$target" in
91
+ */docs/tasks/*/progress.md | docs/tasks/*/progress.md)
92
+ exam_sid="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
93
+ [ "$(rt_fact_window_over_stop "$exam_sid" "$(rt_fact_transcript "$input")")" = yes ] && exit 0
94
+ ;;
95
+ esac
84
96
  ;;
85
97
  Bash | mcp__webstorm__execute_terminal_command)
86
98
  cmd="$(rt_hook_cmd)"
@@ -102,17 +114,10 @@ case "$tool" in
102
114
  *) exit 0 ;;
103
115
  esac
104
116
 
105
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
117
+ transcript="$(rt_fact_transcript "$input")"
106
118
  [ -z "$transcript" ] && exit 0
107
119
  [ -f "$transcript" ] || exit 0
108
120
 
109
- # The shared deny tail: two lawful moves and the lawful form of bypass, if the refusal has one.
110
- # The file may not be laid out — then there is no tail, and the reason for the refusal stays.
111
- # shellcheck disable=SC1090
112
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
113
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
114
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
115
-
116
121
  # The second way out of the refusal — one that does not require lifting protection.
117
122
  #
118
123
  # The guard used to name the list of disabled roles in the tree settings as the only way out. The
@@ -128,68 +133,30 @@ rt_exam_declared_skip() {
128
133
  | grep -qE '^Exam-skip:[[:space:]]*[^[:space:]<]'
129
134
  }
130
135
 
131
- deny() {
136
+ # The decision, the move and the text come from the decision table. A declared bypass lets the call
137
+ # through before the table is asked: it is the lawful way out the refusal itself names.
138
+ # Parameters: the action (empty — the decider takes it from the call), the facts.
139
+ decide_exam() {
132
140
  if rt_exam_declared_skip; then
133
141
  printf 'the exam guard: a bypass is declared in the body of the last commit by the line Exam-skip. The call is let through, the record stays in the history.\n' >&2
134
142
  exit 0
135
143
  fi
136
-
137
- reason="$1"
138
- tail_text="$(rt_deny_tail "$2")"
139
- [ -n "$tail_text" ] && reason="$1 ${tail_text}"
140
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
141
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"%s"}}\n' "$reason"
144
+ # The named move is the call of the exam role; the window guard judges it by the window and by
145
+ # the rule of the course of work loaded for the closing edits.
146
+ exam_sid="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
147
+ exam_facts="$(jq -cn --argjson f "$2" \
148
+ --arg w "$(rt_fact_window_over_stop "$exam_sid" "$transcript")" \
149
+ --arg r "$(rt_fact_rule_loaded "${RT_TASK_FLOW_RULE:-task-flow}" "$exam_sid")" \
150
+ '$f + {window_over_stop:$w, rule_loaded:$r}')"
151
+ # shellcheck disable=SC1091
152
+ . "$rt_hooks_dir/decide.sh" 2>/dev/null
153
+ command -v rt_decide >/dev/null 2>&1 && rt_decide exam-guard.sh "$1" "$exam_facts" '{}' PreToolUse "$input"
142
154
  exit 0
143
155
  }
144
156
 
145
157
  # The whole session is judged, not the last turn: the exam is passed once at the start and holds
146
158
  # to the end.
147
- verdict="$(jq -s -r '
148
- def textof:
149
- if type == "string" then .
150
- elif type == "array" then (map(if type == "object" then (.text // "") else tostring end) | join("\n"))
151
- else tostring end;
152
-
153
- # The call whose answer is discarded is recognised by its identifier, and the identifier is
154
- # bound by a name: a dot after a pipe means the list itself, the search over it answers zero
155
- # on any non-empty list, and every answer of every tool gets muted at once — that is, the
156
- # verdict is looked for in the host records alone.
157
- #
158
- # Tools that read and write files: their result does not count as a verdict — otherwise
159
- # echoing the same line or reading a file with it passes the guard, and the real verdict
160
- # does not.
161
- ["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
162
- | ([.[] | select(.type == "assistant") | (.message.content // [])[]
163
- | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
164
- | {key: (.id // ""), value: true}] | from_entries) as $muted
165
-
166
- | [ .[]
167
- # The assistant text is never a verdict: writing the needed line in a reply costs one
168
- # move.
169
- | if .type == "assistant" then ""
170
- elif .type == "user" then
171
- ([ ((.message.content // []) | if type == "array" then .[] else empty end
172
- | select(.type == "tool_result")
173
- | select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
174
- | .content | textof),
175
- ((.message.content // "") | if type == "string" then . else "" end),
176
- # The call result field: the same record, another form. Discarded only when
177
- # this result belongs to a reading or writing tool.
178
- (. as $rec
179
- | if ($rec.toolUseResult // null) == null then ""
180
- elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
181
- | select(.type == "tool_result") | (.tool_use_id // "")]
182
- | map($muted[.] // false) | any) then ""
183
- else ($rec.toolUseResult | textof) end)
184
- ] | join("\n"))
185
- # Host records — the role completion notice and the attachment: the host chooses their
186
- # form, and they count whole.
187
- else tostring end ] | join("\n")
188
- | [scan("(ЭКЗАМЕН:[[:space:]]*сдано|EXAM:[[:space:]]*passed)[[:space:]]*([0-9]+)[[:space:]]*(из|of)[[:space:]]*([0-9]+)")]
189
- | if length == 0 then "none"
190
- else (.[-1] | if .[1] == .[3] then "passed" else "failed" end)
191
- end
192
- ' "$transcript" 2>/dev/null)"
159
+ verdict="$(rt_fact_exam "$transcript")"
193
160
 
194
161
  # The second exam is the one placed after the PR is opened. The first does not replace it: they
195
162
  # ask about different things, and the whole work lies between them.
@@ -247,7 +214,7 @@ if [ "$ready" = "1" ]; then
247
214
  case "$after" in
248
215
  passed | no-pr) exit 0 ;;
249
216
  *)
250
- deny "BLOCKED by exam-guard: the draft is lifted after the second exam, and there was none in this session. Call the role strict-teacher with the rules of delivery and with what the task demanded: a whole session passed between reading those rules and lifting the draft. The way out through the list of switched-off roles requires removing the protection, and the runtime may forbid such an edit; the second way out does not require it — declare the bypass by the line «Exam-skip: причина» in the body of the last commit of the branch: it stays in the history and is visible to the owner on the page of the request."
217
+ decide_exam pr_ready '{"exam_after_pr":"none"}'
251
218
  ;;
252
219
  esac
253
220
  fi
@@ -260,9 +227,9 @@ fi
260
227
  case "$verdict" in
261
228
  passed) exit 0 ;;
262
229
  failed)
263
- deny "BLOCKED by exam-guard: the exam on the loaded rules is failed. Read the rule whole again — not the piece that was asked about — and call the role strict-teacher anew. The answer shown gives knowledge of one line, not of the rule. The way out through the list of switched-off roles requires removing the protection, and the runtime may forbid such an edit; the second way out does not require it — the bypass is declared by the line «Exam-skip: причина» in the body of the last commit of the branch."
230
+ decide_exam "?edit_code" '{"exam":"failed"}'
264
231
  ;;
265
232
  *)
266
- deny "BLOCKED by exam-guard: there was no exam on the loaded rules in this session. Call the role strict-teacher, hand it the list of loaded rules, answer its questions from memory and return the answers to it — the verdict it gives by the line «ЭКЗАМЕН: сдано N из 5». It counts from the answer of the role in whatever form the host delivered it, but not from the output of the shell and not from your own text: printing that line as an echo does not release the guard. The role was already called and the verdict received — then it arrived in a form the guard does not see: that is a defect of the guard, and an edit of «.claude/rt-kit.json» is taken out from under it. A loaded rule and a read rule are different things, and the price of that difference is paid by the owner."
233
+ decide_exam "?edit_code" '{"exam":"none"}'
267
234
  ;;
268
235
  esac
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env bash
2
+ # The fact of the document pair: what a commit edits without the document that describes it. NOT a
3
+ # guard: it has no `rt-hook:` declaration and hooks into no agent event. The document guard decides
4
+ # by it, and the hooks of delivery name it first when their refusal names a commit.
5
+ #
6
+ # rt_fact_doc_problems <command>
7
+ #
8
+ # Returns 1 when there is nothing to judge — not a commit of this tree, a declared bypass, no edits;
9
+ # otherwise 0, with `problems` holding the list of what is missing (empty — the pair holds),
10
+ # `first_doc` the first document awaited and `paths` the paths of the commit. Reads the tree profile
11
+ # the caller has loaded: `laws_dir`, `lib_marker`, `overrides_dir` and the profile functions.
12
+ #
13
+ # FAIL-OPEN: no git, not a repository — returns 1, and the caller judges nothing.
14
+
15
+ rt_fact_doc_problems() {
16
+ # The names the analysis uses stay its own: the caller keeps its command, root and work directory.
17
+ local cmd="$1" root companion dir from gone kept moved_added moved_deleted need_readme spec spec_paths spec_prefix to want workdir changes source_mode rule
18
+ problems=''
19
+ first_doc=''
20
+ paths=''
21
+ laws_dir="${laws_dir:-${RT_LAWS_DIR:-docs/constitution}}"
22
+ lib_marker="${lib_marker:-${RT_LIB_MARKER:-project.json}}"
23
+ overrides_dir="${overrides_dir:-${RT_OVERRIDES_DIR:-.claude/rt-kit/overrides}}"
24
+ command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
25
+ # The reason for the bypass stays in the history, so the bypass is lawful. An empty line does not
26
+ # count as a bypass: "Docs-skip:" without a reason is the same silent skip, only with a colon.
27
+ #
28
+ # The line starts a line — its own in the commit body, or a comment at the end of the command — and
29
+ # takes no substitutions. The same condition as for the bypass at the merge: otherwise a text that
30
+ # EXPLAINS the bypass lifts the requirement all by itself. A commit body about an edit of the guard
31
+ # names exactly this line, and without the binding to the start the guard would let such a commit
32
+ # through silently.
33
+ if printf '%s' "$cmd" | grep -qiE '(^|#)[[:space:]]*Docs-skip:[[:space:]]*[^[:space:]<"'"'"'][^[:space:]"'"'"']{2,}'; then
34
+ return 1
35
+ fi
36
+
37
+ workdir="$(rt_hook_cwd)"
38
+ [ -z "$workdir" ] && workdir="${CLAUDE_PROJECT_DIR:-.}"
39
+ cd "$workdir" 2>/dev/null || return 1
40
+ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 1
41
+
42
+ # `-a` takes all tracked edits, `--amend` takes the files of the rewritten commit as well. Always
43
+ # counting by the index would mean checking a set other than the one that travels into the history.
44
+ changes=''
45
+ source_mode='index'
46
+ case "$cmd" in
47
+ *' -a'* | *--all*)
48
+ changes="$(git diff HEAD --name-status -M 2>/dev/null)"
49
+ source_mode='worktree'
50
+ ;;
51
+ *) changes="$(git diff --cached --name-status -M 2>/dev/null)" ;;
52
+ esac
53
+ case "$cmd" in
54
+ *--amend*) changes="$(printf '%s\n%s' "$changes" "$(git show --name-status --format= HEAD 2>/dev/null)")" ;;
55
+ esac
56
+
57
+ changes="$(printf '%s\n' "$changes" | grep -v '^[[:space:]]*$')"
58
+
59
+ # `git commit -- <paths>` commits those paths alone, whatever else the index holds: the guard counts
60
+ # the set that travels, and a staged file left out of this commit is judged by the commit that takes
61
+ # it. The paths are given from the directory of the call, the list of edits from the root.
62
+ spec_paths="$(printf '%s\n' "$cmd" | sed -nE 's/.*git[[:space:]]+commit[^;&|]*[[:space:]]--[[:space:]]+([^;&|]+).*/\1/p' | head -1)"
63
+ if [ -n "$spec_paths" ]; then
64
+ spec_prefix="$(git rev-parse --show-prefix 2>/dev/null)"
65
+ kept=''
66
+ for spec in $spec_paths; do
67
+ spec="$(printf '%s' "$spec" | tr -d "\"'")"
68
+ spec="${spec_prefix}${spec%/}"
69
+ kept="${kept}$(printf '%s\n' "$changes" | awk -F'\t' -v s="$spec" '{ for (i = 2; i <= NF; i++) if ($i == s || index($i, s "/") == 1) { print; next } }')
70
+ "
71
+ done
72
+ changes="$(printf '%s' "$kept" | grep -v '^[[:space:]]*$' | sort -u)"
73
+ fi
74
+ [ -z "$changes" ] && return 1
75
+
76
+ # The paths of the commit without the statuses. A rename comes as three fields — we take both sides.
77
+ paths="$(printf '%s\n' "$changes" | awk -F'\t' '{ for (i = 2; i <= NF; i++) if ($i != "") print $i }' | sort -u)"
78
+
79
+ has_path() { printf '%s\n' "$paths" | grep -qxF "$1"; }
80
+
81
+ # The content as it will travel into the commit. The source is the same one the list of edits was
82
+ # collected by: `-a` takes the working tree, an ordinary commit takes the index. Always reading the
83
+ # index is not allowed — under `-a` the previous edition lies there, and the guard would hold the
84
+ # very commit that fixes the divergence; always reading the working tree is not allowed either — an
85
+ # unstaged edit will not get into the commit.
86
+ content_of() {
87
+ if [ "$source_mode" = 'worktree' ]; then
88
+ cat "$1" 2>/dev/null
89
+ else
90
+ git show ":$1" 2>/dev/null || cat "$1" 2>/dev/null
91
+ fi
92
+ }
93
+
94
+ problems=''
95
+ # The first document the refusal awaits: the edit of it is the move the refusal names, and a
96
+ # neighbouring guard may hold that edit — the exam, the rule of the file, the handover entry.
97
+ first_doc=''
98
+ add() { problems="${problems}
99
+ • $1"; }
100
+
101
+ # ── 1. A rule and its companion ───────────────────────────────────────────────
102
+ #
103
+ # The statements of a rule are keyed by their own text, and a rewording without an edit of the
104
+ # companion breaks the link silently. The spec audit catches this, but it is run at the push gate —
105
+ # here the same pair meets a commit earlier, while the edit is still in the author's head.
106
+ #
107
+ # The section with the statements is the only thing linked to the companion; an edit of "Pitfalls"
108
+ # or of the "Where it lives" table does not touch it, so only this section is compared. The name of
109
+ # the section is double: English in a package rule, Russian in a rule written by the tree before the
110
+ # layer was translated. The end of the range is any heading not starting with their first letter.
111
+ STATEMENTS='/^## (How the law applies here|Как закон применяется здесь)$/,/^## [^КH]/'
112
+ statements_of() { content_of "$1" | awk "$STATEMENTS"; }
113
+
114
+ for rule in $(printf '%s\n' "$paths" | grep -E '/SKILL\.md$'); do
115
+ grep -q '^kind: rule$' "$rule" 2>/dev/null || continue
116
+ companion="${rule%/SKILL.md}/implementation.md"
117
+
118
+ [ -f "$companion" ] || continue
119
+ has_path "$companion" && continue
120
+
121
+ if [ "$(statements_of "$rule")" != "$(git show "HEAD:$rule" 2>/dev/null | awk "$STATEMENTS")" ]; then
122
+ add "the statements of \`$rule\` are edited without the companion — add \`$companion\` to the commit"
123
+ [ -n "$first_doc" ] || first_doc="$companion"
124
+ fi
125
+ done
126
+
127
+ # ── 2. The pairs the tree names ───────────────────────────────────────────────
128
+ #
129
+ # The contract and the domain spec, a guard and its scenarios — which exactly, the profile knows:
130
+ # every tree has a link of its own, and the mechanics are one.
131
+ if rt_needs rt_docs_pair_for docs-guard; then
132
+ while IFS= read -r file; do
133
+ [ -z "$file" ] && continue
134
+
135
+ # A file put in place by the layout demands no pair: it has one author in a consuming tree
136
+ # — the package, and the document about it lies there as well. Otherwise the very first
137
+ # layout demands a bypass over its whole volume, and a bypass declared over a hundred files
138
+ # lifts the requirement from future hand edits of those files too. The sign is the layout
139
+ # header: it stands in every laid-out file and tells it apart more reliably than any list
140
+ # of paths.
141
+ if [ -f "$file" ] && head -12 "$file" 2>/dev/null | grep -qE 'rt-kit v[^ ]+ · [^ ]+ · [0-9a-f]+'; then
142
+ continue
143
+ fi
144
+
145
+ want="$(rt_docs_pair_for "$file" 2>/dev/null)"
146
+ [ -z "$want" ] && continue
147
+ # The pair counts as arrived if at least one file of the commit fits the pattern.
148
+ printf '%s\n' "$paths" | grep -qE "$want" && continue
149
+ add "\`$file\` is edited without its document — the same commit awaits \`$want\`"
150
+ [ -n "$first_doc" ] || first_doc="$(git ls-files -co --exclude-standard 2>/dev/null | grep -E "^${want}\$" | head -1)"
151
+ done <<EOF
152
+ $paths
153
+ EOF
154
+ fi
155
+
156
+ # ── 3. A lib and its README ───────────────────────────────────────────────────
157
+
158
+ lib_root() {
159
+ dir="${1%/*}"
160
+ while [ -n "$dir" ] && [ "$dir" != "." ]; do
161
+ [ -f "$dir/$lib_marker" ] && { printf '%s' "$dir"; return 0; }
162
+ case "$dir" in */*) dir="${dir%/*}" ;; *) dir='' ;; esac
163
+ done
164
+
165
+ return 1
166
+ }
167
+
168
+ need_readme=''
169
+ want_readme() {
170
+ root="$1"
171
+ [ -n "$root" ] || return 0
172
+ case " $need_readme " in *" $root "*) return 0 ;; esac
173
+ need_readme="$need_readme $root"
174
+ }
175
+
176
+ # Creating and removing a lib: the README is the only place where it is written what lies in it and
177
+ # who calls it, and it survives the layout only together with an edit of that text.
178
+ while IFS="$(printf '\t')" read -r status first second; do
179
+ case "$status" in
180
+ A* | D*)
181
+ case "$first" in */"$lib_marker") want_readme "${first%/"$lib_marker"}" ;; esac
182
+ ;;
183
+ R*)
184
+ # A move of a file changes both sides: from one lib it disappeared, in the other it
185
+ # appeared.
186
+ from="$(lib_root "$first")" && to="$(lib_root "$second")"
187
+ if [ -n "$from" ] && [ -n "$to" ] && [ "$from" != "$to" ]; then
188
+ want_readme "$from"
189
+ want_readme "$to"
190
+ fi
191
+ ;;
192
+ esac
193
+ done <<EOF
194
+ $changes
195
+ EOF
196
+
197
+ # A move given as the pair "deleted there, added here": not everything that is a rename counts as
198
+ # one — an edit of the content while moving throws the search off.
199
+ moved_added="$(printf '%s\n' "$changes" | awk -F'\t' '$1 ~ /^A/ { n = split($2, p, "/"); print p[n] "\t" $2 }' | sort -u)"
200
+ moved_deleted="$(printf '%s\n' "$changes" | awk -F'\t' '$1 ~ /^D/ { n = split($2, p, "/"); print p[n] "\t" $2 }' | sort -u)"
201
+ if [ -n "$moved_added" ] && [ -n "$moved_deleted" ]; then
202
+ while IFS="$(printf '\t')" read -r base added; do
203
+ [ -n "$base" ] || continue
204
+ gone="$(printf '%s\n' "$moved_deleted" | awk -F'\t' -v b="$base" '$1 == b { print $2; exit }')"
205
+ [ -n "$gone" ] || continue
206
+ to="$(lib_root "$added")" || continue
207
+ from="$(lib_root "$gone")" || continue
208
+ [ "$from" = "$to" ] && continue
209
+ want_readme "$from"
210
+ want_readme "$to"
211
+ done <<EOF
212
+ $moved_added
213
+ EOF
214
+ fi
215
+
216
+ for root in $need_readme; do
217
+ [ -d "$root" ] || continue # the lib was deleted whole — there is nothing to edit in it
218
+ has_path "$root/README.md" || { add "the content of the lib \`$root\` changed without an edit of \`$root/README.md\`"; [ -n "$first_doc" ] || first_doc="$root/README.md"; }
219
+ done
220
+ return 0
221
+ }
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env bash
2
+ # The facts of the course of work for one edit. NOT a guard: it has no `rt-hook:` declaration and is
3
+ # not attached to any agent event. The work-conduct guards source it after `rt_task_flow_context`,
4
+ # and so does a guard whose refusal names an edit of another file: it asks these facts of that edit
5
+ # instead of running the work-conduct guards on it.
6
+ #
7
+ # rt_fact_flow {"facts":{…},"params":{…}} — the branch, the plan, the progress, the state
8
+ # and whether the task folder is in the history; empty when the edit is not
9
+ # judged: a merge conflict being resolved, or a folder already taken apart
10
+ # rt_fact_agreement {"facts":{…},"params":{…}} — whether the plan names the product agreement
11
+ # and whether it exists; empty when there is no plan
12
+ # rt_fact_flow_of <tool> <tool input> <hook input>
13
+ # both of the above for a move another guard names, merged; empty when the
14
+ # work-conduct guards do not judge that move
15
+ #
16
+ # Both read the variables `rt_task_flow_context` sets. FAIL-OPEN: no jq, no git → empty answer, and
17
+ # the caller judges nothing.
18
+
19
+ # shellcheck disable=SC1091
20
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/profile-check.sh" ] \
21
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/profile-check.sh"
22
+ command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
23
+
24
+ # Resolving a merge conflict is the merge itself, not an edit of the product. Main is merged into
25
+ # the epic branch while the work runs, and that branch carries no task folder by the rule. So a call
26
+ # passes while a merge stands and every code path it writes is still unmerged.
27
+ rt_flow_merge_conflict_only() {
28
+ local seen=0 candidate
29
+ git -C "$RT_TF_ROOT" rev-parse -q --verify MERGE_HEAD >/dev/null 2>&1 || return 1
30
+ while IFS= read -r candidate; do
31
+ [ -z "$candidate" ] && continue
32
+ case "$candidate" in
33
+ /*) ;;
34
+ *) candidate="${rt_tf_askdir:-${CLAUDE_PROJECT_DIR:-.}}/$candidate" ;;
35
+ esac
36
+ rt_is_app_code "$candidate" || rt_tf_laid_out "$candidate" || continue
37
+ [ -n "$(git -C "$RT_TF_ROOT" ls-files -u -- "$candidate" 2>/dev/null | head -1)" ] || return 1
38
+ seen=1
39
+ done <<EOF
40
+ ${RT_TF_CANDIDATES:-$RT_TF_PATH}
41
+ EOF
42
+ [ "$seen" = 1 ]
43
+ }
44
+
45
+ # The folder is gone from HEAD but stood at the base or was added by a commit of the branch: the
46
+ # work is handed in, and the plan is taken from the history.
47
+ rt_flow_folder_archived() {
48
+ local base had
49
+ [ -n "$(git -C "$RT_TF_ROOT" ls-tree -d --name-only HEAD -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)" ] && return 1
50
+ base="$(git -C "$RT_TF_ROOT" merge-base "$RT_TF_MAIN_BRANCH" HEAD 2>/dev/null)"
51
+ [ -z "$base" ] && return 1
52
+ had="$(git -C "$RT_TF_ROOT" ls-tree -d --name-only "$base" -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)"
53
+ [ -z "$had" ] && had="$(git -C "$RT_TF_ROOT" log "$base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)"
54
+ [ -n "$had" ]
55
+ }
56
+
57
+ # The task folder travels into the branch by a commit, it does not live in one working copy: a folder
58
+ # never committed passes every check of the disk, while the sign of handed-over work is taken from the
59
+ # history. No git history — the folder counts as committed: there is nothing to ask it with.
60
+ rt_flow_in_tree() {
61
+ [ -n "$(git -C "$RT_TF_ROOT" rev-parse --verify HEAD 2>/dev/null)" ] || return 0
62
+ [ -n "$(git -C "$RT_TF_ROOT" ls-tree -d --name-only HEAD -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)" ]
63
+ }
64
+
65
+ # The mandatory action of a state in which code is not edited.
66
+ rt_flow_state_action() {
67
+ case "$1" in
68
+ просьба-не-разобрана) printf '%s' 'exploration over the tree, then questions to the owner' ;;
69
+ разбор-закрыт) printf '%s' 'a product agreement or a named reason there is none' ;;
70
+ договорённость-записана) printf '%s' 'create the task, the branch and the task folder' ;;
71
+ задача-взята) printf '%s' 'write the plan' ;;
72
+ замысел-записан) printf '%s' 'do the first stage' ;;
73
+ папка-разобрана) printf '%s' 'the work queue audit, then open the PR' ;;
74
+ влито) printf '%s' 'merge the PRs of the chain bottom-up, mark the merged tasks by the branch of the next one' ;;
75
+ *) printf '%s' '' ;;
76
+ esac
77
+ }
78
+
79
+ rt_fact_flow() {
80
+ local progress state kind folder="yes"
81
+ command -v jq >/dev/null 2>&1 || return 0
82
+ rt_flow_merge_conflict_only && return 0
83
+ if rt_needs rt_task_branch_ok task-flow-guard && ! rt_task_branch_ok "$RT_TF_BRANCH"; then
84
+ printf '%s' '{"facts":{"branch":"other"},"params":{}}'
85
+ return 0
86
+ fi
87
+ rt_flow_folder_archived && return 0
88
+ if [ ! -f "$RT_TF_PLAN" ]; then
89
+ printf '%s' '{"facts":{"branch":"task","plan":"no"},"params":{}}'
90
+ return 0
91
+ fi
92
+ progress="$RT_TF_DIR/progress.md"
93
+ if [ ! -f "$progress" ]; then
94
+ printf '%s' '{"facts":{"branch":"task","plan":"yes","progress":"no"},"params":{}}'
95
+ return 0
96
+ fi
97
+ state="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(State|Состояние):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$progress" 2>/dev/null | head -1)"
98
+ case "$state" in
99
+ '') kind=none ;;
100
+ # States in which the code is edited. The last three are not about the first session: a run
101
+ # happens to be red and a review comes with remarks, and the fix goes into the same branch.
102
+ этап-идёт | этапы-кончились | работа-отдана | разбор-кончился) kind=code ;;
103
+ просьба-не-разобрана | разбор-закрыт | договорённость-записана | задача-взята | замысел-записан | папка-разобрана | влито) kind=other ;;
104
+ *) kind=unknown ;;
105
+ esac
106
+ [ "$kind" = code ] && ! rt_flow_in_tree && folder=no
107
+ jq -cn --arg k "$kind" --arg f "$folder" --arg s "$state" --arg a "$(rt_flow_state_action "$state")" \
108
+ '{facts:({branch:"task", plan:"yes", progress:"yes", state:$k} + (if $k == "code" then {folder_committed:$f} else {} end)), params:{state:$s, state_action:$a}}'
109
+ }
110
+
111
+ rt_fact_agreement() {
112
+ local draft draft_path domain_dir feature file
113
+ command -v jq >/dev/null 2>&1 || return 0
114
+ [ -f "$RT_TF_PLAN" ] || return 0
115
+ if grep -qE '^\*\*(Behaviour|Поведение):\*\*[[:space:]]*(unchanged|не меняется)[[:space:]]*—[[:space:]]*\S' "$RT_TF_PLAN" 2>/dev/null; then
116
+ printf '%s' '{"facts":{"agreement":"waived"},"params":{}}'
117
+ return 0
118
+ fi
119
+ draft="$(sed -nE 's/^\*\*(Draft|Драфт):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$RT_TF_PLAN" 2>/dev/null | head -1)"
120
+ [ -z "$draft" ] && draft="$(sed -nE 's/^\*\*(Spec|Спек):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$RT_TF_PLAN" 2>/dev/null | head -1)"
121
+ if [ -z "$draft" ]; then
122
+ printf '%s' '{"facts":{"agreement":"unnamed"},"params":{}}'
123
+ return 0
124
+ fi
125
+ case "$draft" in
126
+ /*) draft_path="$draft" ;;
127
+ *) draft_path="$RT_TF_ROOT/$draft" ;;
128
+ esac
129
+ # On disk, in the history of the branch, or merged into the domain spec: a merged agreement does
130
+ # not lock the branch.
131
+ if [ -e "$draft_path" ] || git -C "$RT_TF_ROOT" log --oneline -1 -- "$draft" 2>/dev/null | grep -q .; then
132
+ printf '%s' '{"facts":{"agreement":"exists"},"params":{}}'
133
+ return 0
134
+ fi
135
+ case "$draft" in
136
+ */proposed/*)
137
+ domain_dir="${draft%%/proposed/*}"
138
+ feature="${draft##*/proposed/}"
139
+ feature="${feature%/}"
140
+ if [ -n "$feature" ] && [ -d "$RT_TF_ROOT/$domain_dir" ] \
141
+ && grep -rq -- "$feature" "$RT_TF_ROOT/$domain_dir" 2>/dev/null; then
142
+ printf '%s' '{"facts":{"agreement":"exists"},"params":{}}'
143
+ return 0
144
+ fi
145
+ ;;
146
+ esac
147
+ case "$draft_path" in
148
+ */) file="${draft_path}spec.md" ;;
149
+ *.md) file="$draft_path" ;;
150
+ *) file="$draft_path/spec.md" ;;
151
+ esac
152
+ jq -cn --arg d "$draft" --arg f "$file" '{facts:{agreement:"missing"}, params:{draft:$d, agreement_file:$f}}'
153
+ }
154
+
155
+ # The facts of the course of work for a move another guard names. The parse runs in a subshell over
156
+ # the input of that move: the variables of the calling guard stay as they were.
157
+ rt_fact_flow_of() {
158
+ (
159
+ unset RT_HOOK_CMD RT_HOOK_CWD RT_HOOK_FILE RT_HOOK_PARSED RT_HOOK_TOOL
160
+ RT_HOOK_INPUT="$(jq -cn --arg t "$1" --argjson i "$2" --argjson h "$3" '{tool_name:$t, tool_input:$i, cwd:($h.cwd // null), session_id:($h.session_id // null)}' 2>/dev/null)"
161
+ export RT_HOOK_INPUT
162
+ _rt_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
163
+ # shellcheck disable=SC1091
164
+ . "$_rt_here/task-flow-context.sh" 2>/dev/null || exit 0
165
+ rt_task_flow_context </dev/null || exit 0
166
+ _rt_flow="$(rt_fact_flow)"
167
+ [ -n "$_rt_flow" ] || exit 0
168
+ _rt_agreement="$(rt_fact_agreement)"
169
+ [ -n "$_rt_agreement" ] || _rt_agreement='{"facts":{},"params":{}}'
170
+ jq -cn --argjson f "$_rt_flow" --argjson a "$_rt_agreement" \
171
+ '{facts:($f.facts + (if $f.facts.state == "code" and $f.facts.folder_committed == "yes" then $a.facts else {} end)), params:($f.params + $a.params)}'
172
+ )
173
+ }