@rt-tools/agent-kit 0.37.1 → 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 (357) 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 +21365 -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 +136 -0
  14. package/assets/checks/flow-forecast.mjs +330 -0
  15. package/assets/checks/flow-guard-run.mjs +90 -0
  16. package/assets/checks/flow-guard.mjs +294 -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 +365 -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 +112 -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 +410 -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 +292 -0
  32. package/assets/checks/tree-assignment.mjs +26 -7
  33. package/assets/checks/work-result.mjs +281 -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 +21 -22
  40. package/assets/docs/GLOSSARY.md +5 -1
  41. package/assets/hooks/ask-judge.md +65 -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 +308 -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 +32 -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 +15 -4
  77. package/assets/hooks/git-guard-push-marks.sh +53 -1
  78. package/assets/hooks/git-guard-push-tests.sh +30 -51
  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 +14 -10
  88. package/assets/hooks/prose-style-guard.sh +6 -19
  89. package/assets/hooks/pull-merges.sh +76 -0
  90. package/assets/hooks/push-set.sh +11 -4
  91. package/assets/hooks/qa-dataid-guard.sh +7 -17
  92. package/assets/hooks/record-turn.sh +52 -0
  93. package/assets/hooks/rerun-guard.sh +11 -16
  94. package/assets/hooks/reuse-first-guard.sh +7 -21
  95. package/assets/hooks/role-calls.sh +25 -3
  96. package/assets/hooks/rule-source-guard.sh +54 -21
  97. package/assets/hooks/skill-gate-rearm.sh +18 -5
  98. package/assets/hooks/skill-gate.sh +156 -20
  99. package/assets/hooks/skill-loaded.sh +18 -3
  100. package/assets/hooks/sql-guard-target.sh +2 -2
  101. package/assets/hooks/sql-guard-write.sh +12 -12
  102. package/assets/hooks/sql-guard.sh +58 -16
  103. package/assets/hooks/task-context-load.sh +3 -1
  104. package/assets/hooks/task-flow-context.sh +5 -18
  105. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  106. package/assets/hooks/task-flow-guard.sh +28 -130
  107. package/assets/hooks/tree-assignment-guard.sh +25 -14
  108. package/assets/hooks/turn-entry-load.sh +3 -1
  109. package/assets/hooks/turn-exit-guard.sh +92 -452
  110. package/assets/hooks/turn-exit-role.sh +3 -1
  111. package/assets/hooks/turn-judge.md +103 -0
  112. package/assets/hooks/window-fill-guard.sh +22 -41
  113. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  114. package/assets/patterns/git-workflow-commit.github.md +11 -269
  115. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  116. package/assets/patterns/git-workflow-docker.md +8 -231
  117. package/assets/patterns/git-workflow-freshness.md +8 -56
  118. package/assets/patterns/git-workflow-merge.md +6 -176
  119. package/assets/patterns/git-workflow-migration.md +5 -75
  120. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  121. package/assets/patterns/git-workflow-pr-ready.md +9 -70
  122. package/assets/patterns/git-workflow-pr.azure.md +13 -285
  123. package/assets/patterns/git-workflow-pr.github.md +13 -251
  124. package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
  125. package/assets/patterns/git-workflow-restart.md +5 -42
  126. package/assets/patterns/git-workflow-secrets.md +10 -76
  127. package/assets/patterns/git-workflow-stack.md +7 -207
  128. package/assets/patterns/status-report-table.github.md +1 -1
  129. package/assets/patterns/task-flow-archive.md +12 -233
  130. package/assets/patterns/task-flow-close.md +16 -292
  131. package/assets/patterns/task-flow-cycle.md +13 -39
  132. package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
  133. package/assets/patterns/task-flow-handoff.md +13 -161
  134. package/assets/patterns/task-flow-resume.md +18 -218
  135. package/assets/patterns/task-flow-start.md +9 -247
  136. package/assets/patterns/turn-entry-map.md +2 -2
  137. package/assets/pitfalls/agent-kit-extend.md +200 -0
  138. package/assets/pitfalls/agent-kit.2.md +323 -0
  139. package/assets/pitfalls/angular-patterns.md +98 -0
  140. package/assets/pitfalls/browser-verification.md +265 -0
  141. package/assets/pitfalls/component-structure.md +98 -0
  142. package/assets/pitfalls/dependencies.md +92 -0
  143. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  144. package/assets/pitfalls/deploy-flow.github.md +211 -0
  145. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  146. package/assets/pitfalls/doc-style.2.md +286 -0
  147. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  148. package/assets/pitfalls/entity-models.md +89 -0
  149. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  150. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  151. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  152. package/assets/pitfalls/git-workflow-docker.md +275 -0
  153. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  154. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  155. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  156. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  157. package/assets/pitfalls/git-workflow-merge.md +220 -0
  158. package/assets/pitfalls/git-workflow-migration.md +103 -0
  159. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  160. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  161. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  162. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  163. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  164. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  165. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  166. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  167. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  168. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  169. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  170. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  171. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  172. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  173. package/assets/pitfalls/git-workflow-restart.md +72 -0
  174. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  175. package/assets/pitfalls/git-workflow-stack.md +254 -0
  176. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  177. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  178. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  179. package/assets/pitfalls/lib-layers.md +114 -0
  180. package/assets/pitfalls/lists.md +117 -0
  181. package/assets/pitfalls/navigation.md +94 -0
  182. package/assets/pitfalls/reuse-first.md +201 -0
  183. package/assets/pitfalls/spec-driven.2.md +318 -0
  184. package/assets/pitfalls/styling-bem.2.md +125 -0
  185. package/assets/pitfalls/task-flow-archive.md +264 -0
  186. package/assets/pitfalls/task-flow-close.2.md +165 -0
  187. package/assets/pitfalls/task-flow-close.md +167 -0
  188. package/assets/pitfalls/task-flow-cycle.md +73 -0
  189. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  190. package/assets/pitfalls/task-flow-handoff.md +200 -0
  191. package/assets/pitfalls/task-flow-handover.md +30 -0
  192. package/assets/pitfalls/task-flow-owner.md +29 -0
  193. package/assets/pitfalls/task-flow-plan.md +29 -0
  194. package/assets/pitfalls/task-flow-resume.md +257 -0
  195. package/assets/pitfalls/task-flow-start.md +287 -0
  196. package/assets/pitfalls/task-flow.2.md +303 -0
  197. package/assets/pitfalls/task-flow.md +4 -4
  198. package/assets/pitfalls/testing.2.md +279 -0
  199. package/assets/pitfalls/turn-conduct.md +16 -17
  200. package/assets/pitfalls/typescript-conventions.md +161 -0
  201. package/assets/pitfalls/write-a-skill.md +128 -0
  202. package/assets/rules/angular-patterns.md +21 -86
  203. package/assets/rules/autonomous-work.md +2 -2
  204. package/assets/rules/browser-verification.md +28 -256
  205. package/assets/rules/component-structure.md +25 -87
  206. package/assets/rules/dependencies.md +20 -78
  207. package/assets/rules/deploy-flow.azure.md +26 -156
  208. package/assets/rules/deploy-flow.github.md +34 -200
  209. package/assets/rules/deploy-flow.gitlab.md +27 -159
  210. package/assets/rules/doc-style.md +32 -286
  211. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  212. package/assets/rules/entity-models.md +14 -63
  213. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  214. package/assets/rules/git-workflow-hosting.github.md +38 -0
  215. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  216. package/assets/rules/git-workflow-push.azure.md +28 -0
  217. package/assets/rules/git-workflow-push.github.md +28 -0
  218. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  219. package/assets/rules/git-workflow-queue.azure.md +23 -0
  220. package/assets/rules/git-workflow-queue.github.md +30 -0
  221. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  222. package/assets/rules/git-workflow.azure.md +21 -282
  223. package/assets/rules/git-workflow.github.md +24 -284
  224. package/assets/rules/git-workflow.gitlab.md +21 -269
  225. package/assets/rules/lib-layers.md +30 -103
  226. package/assets/rules/lists.md +21 -105
  227. package/assets/rules/navigation.md +10 -69
  228. package/assets/rules/reuse-first.md +20 -195
  229. package/assets/rules/spec-driven.md +35 -308
  230. package/assets/rules/styling-bem.md +20 -117
  231. package/assets/rules/task-flow-handover.md +24 -0
  232. package/assets/rules/task-flow-owner.md +34 -0
  233. package/assets/rules/task-flow-plan.md +38 -0
  234. package/assets/rules/task-flow.md +22 -300
  235. package/assets/rules/testing.md +32 -273
  236. package/assets/rules/turn-conduct.md +100 -104
  237. package/assets/rules/turn-entry.md +2 -2
  238. package/assets/rules/typescript-conventions.md +41 -147
  239. package/assets/samples/tasks/_template/plan.md +30 -6
  240. package/assets/samples/tasks/_template/progress.md +0 -1
  241. package/assets/skills/agent-kit-extend.md +25 -168
  242. package/assets/skills/agent-kit.md +27 -299
  243. package/assets/skills/write-a-skill.md +20 -106
  244. package/assets/task-flow/flow.js +188 -0
  245. package/assets/task-flow/flow.md +102 -0
  246. package/assets/task-flow/measure/agreement.mjs +24 -0
  247. package/assets/task-flow/measure/copy.mjs +22 -0
  248. package/assets/task-flow/measure/epic-of.mjs +50 -0
  249. package/assets/task-flow/measure/epic-text.mjs +35 -0
  250. package/assets/task-flow/measure/epic.mjs +114 -0
  251. package/assets/task-flow/measure/folder.mjs +16 -0
  252. package/assets/task-flow/measure/footprint.mjs +28 -0
  253. package/assets/task-flow/measure/grill.mjs +21 -0
  254. package/assets/task-flow/measure/host.mjs +8 -0
  255. package/assets/task-flow/measure/owner.mjs +20 -0
  256. package/assets/task-flow/measure/plan.mjs +27 -0
  257. package/assets/task-flow/measure/pr.mjs +20 -0
  258. package/assets/task-flow/measure/progress.mjs +50 -0
  259. package/assets/task-flow/measure/session.mjs +175 -0
  260. package/assets/task-flow/measure/task.mjs +23 -0
  261. package/assets/task-flow/measure/text.mjs +77 -0
  262. package/assets/task-flow/source/git.mjs +86 -0
  263. package/assets/task-flow/source/host.mjs +172 -0
  264. package/assets/task-flow/source/marks.mjs +56 -0
  265. package/assets/task-flow/source/owner.mjs +74 -0
  266. package/assets/task-flow/source/records.mjs +116 -0
  267. package/assets/task-flow/source/session.mjs +232 -0
  268. package/assets/task-flow/source/steps.mjs +28 -0
  269. package/assets/task-flow/source/tree.mjs +42 -0
  270. package/bin/agent-kit.d.ts.map +1 -1
  271. package/bin/agent-kit.js +30 -0
  272. package/bin/agent-kit.js.map +1 -1
  273. package/lib/agent-checks.d.ts +55 -0
  274. package/lib/agent-checks.d.ts.map +1 -0
  275. package/lib/agent-checks.js +209 -0
  276. package/lib/agent-checks.js.map +1 -0
  277. package/lib/assets.d.ts.map +1 -1
  278. package/lib/assets.js +7 -2
  279. package/lib/assets.js.map +1 -1
  280. package/lib/cargo.d.ts +29 -0
  281. package/lib/cargo.d.ts.map +1 -1
  282. package/lib/cargo.js +27 -1
  283. package/lib/cargo.js.map +1 -1
  284. package/lib/cascade.d.ts.map +1 -1
  285. package/lib/cascade.js +3 -1
  286. package/lib/cascade.js.map +1 -1
  287. package/lib/commands.d.ts.map +1 -1
  288. package/lib/commands.js +78 -2
  289. package/lib/commands.js.map +1 -1
  290. package/lib/config.d.ts +18 -0
  291. package/lib/config.d.ts.map +1 -1
  292. package/lib/config.js +18 -1
  293. package/lib/config.js.map +1 -1
  294. package/lib/epic-window-send.d.ts +74 -0
  295. package/lib/epic-window-send.d.ts.map +1 -0
  296. package/lib/epic-window-send.js +166 -0
  297. package/lib/epic-window-send.js.map +1 -0
  298. package/lib/hooks-map.d.ts +4 -0
  299. package/lib/hooks-map.d.ts.map +1 -1
  300. package/lib/hooks-map.js +2 -2
  301. package/lib/hooks-map.js.map +1 -1
  302. package/lib/integrity.d.ts +3 -0
  303. package/lib/integrity.d.ts.map +1 -1
  304. package/lib/integrity.js +7 -0
  305. package/lib/integrity.js.map +1 -1
  306. package/lib/metric-lines.d.ts +2 -1
  307. package/lib/metric-lines.d.ts.map +1 -1
  308. package/lib/metric-lines.js +49 -1
  309. package/lib/metric-lines.js.map +1 -1
  310. package/lib/metric-send-mark.d.ts +6 -3
  311. package/lib/metric-send-mark.d.ts.map +1 -1
  312. package/lib/metric-send-mark.js +15 -5
  313. package/lib/metric-send-mark.js.map +1 -1
  314. package/lib/metric-send.d.ts +6 -2
  315. package/lib/metric-send.d.ts.map +1 -1
  316. package/lib/metric-send.js +47 -13
  317. package/lib/metric-send.js.map +1 -1
  318. package/lib/metrics.d.ts +17 -0
  319. package/lib/metrics.d.ts.map +1 -1
  320. package/lib/metrics.js +26 -15
  321. package/lib/metrics.js.map +1 -1
  322. package/lib/observations.js +3 -3
  323. package/lib/observations.js.map +1 -1
  324. package/lib/outcomes.d.ts +5 -2
  325. package/lib/outcomes.d.ts.map +1 -1
  326. package/lib/outcomes.js +5 -4
  327. package/lib/outcomes.js.map +1 -1
  328. package/lib/push-gate.d.ts +13 -0
  329. package/lib/push-gate.d.ts.map +1 -1
  330. package/lib/push-gate.js +11 -7
  331. package/lib/push-gate.js.map +1 -1
  332. package/lib/push-set-usefulness.d.ts +78 -0
  333. package/lib/push-set-usefulness.d.ts.map +1 -0
  334. package/lib/push-set-usefulness.js +225 -0
  335. package/lib/push-set-usefulness.js.map +1 -0
  336. package/lib/sync.d.ts +10 -0
  337. package/lib/sync.d.ts.map +1 -1
  338. package/lib/sync.js +14 -1
  339. package/lib/sync.js.map +1 -1
  340. package/lib/work-result.d.ts +43 -0
  341. package/lib/work-result.d.ts.map +1 -0
  342. package/lib/work-result.js +39 -0
  343. package/lib/work-result.js.map +1 -0
  344. package/package.json +1 -1
  345. package/assets/hooks/claim-guard.sh +0 -212
  346. package/assets/hooks/grill-gate-ask.sh +0 -26
  347. package/assets/hooks/grill-gate-bypass.sh +0 -61
  348. package/assets/hooks/grill-gate-options.sh +0 -50
  349. package/assets/hooks/grill-gate.sh +0 -482
  350. package/assets/hooks/postmortem-guard.sh +0 -124
  351. package/assets/hooks/proposal-guard.sh +0 -154
  352. package/assets/hooks/stand-login-guard.sh +0 -107
  353. package/assets/hooks/turn-exit-epic.sh +0 -173
  354. package/assets/hooks/turn-exit-patterns.sh +0 -123
  355. package/assets/hooks/turn-exit-verdict.sh +0 -149
  356. package/assets/hooks/waiting-turn-guard.sh +0 -320
  357. package/assets/hooks/work-start-guard.sh +0 -175
@@ -51,7 +51,7 @@ tip="$(git rev-parse --verify --quiet HEAD 2>/dev/null)"
51
51
  # any length; a real commit that merely starts with zeros is judged like any other.
52
52
  sends=0
53
53
  foreign=""
54
- while read -r local_ref local_sha _remote_ref _remote_sha; do
54
+ while read -r local_ref local_sha _remote_ref _remote_sha || [ -n "$local_ref" ]; do
55
55
  [ -z "$local_sha" ] && continue
56
56
  [ -z "$(printf '%s' "$local_sha" | tr -d 0)" ] && continue
57
57
  sends=$((sends + 1))
@@ -64,10 +64,12 @@ done
64
64
  [ "$sends" -eq 0 ] && exit 0
65
65
 
66
66
  if [ -n "$foreign" ]; then
67
- printf '%s\n' "pre-push: refused — the push sends a commit the working copy does not stand on:" >&2
68
- printf '%s\n' "$foreign" >&2
69
- printf '%s\n' "The checks run on the tree that lies here, so they would judge something else than what leaves. Switch to the branch and push it from there, one branch per push." >&2
70
- exit 1
67
+ # shellcheck disable=SC1091
68
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
69
+ # The decision and the words come from the decision table; the exit code is its answer.
70
+ command -v rt_decide >/dev/null 2>&1 || exit 0
71
+ rt_decide pre-push.sh push '{"push_sends_tip":"no"}' "$(jq -cn --arg f "$foreign" '{foreign:$f}')" git
72
+ exit $?
71
73
  fi
72
74
 
73
75
  hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -110,10 +112,12 @@ fi
110
112
 
111
113
  held_line=""
112
114
  [ -n "$rt_push_set_held" ] && held_line="
113
-
114
115
  Not started after the red ones — heavy, and the push is refused anyway:
115
116
  ${rt_push_set_held}"
116
-
117
- printf '\npre-push: refused — red checks: %s\n%s%s\n\nThe tail of every red output:\n\n%s\n' \
118
- "$(printf '%s\n' "$rt_push_set_failed" | grep -c .)" "$rt_push_set_failed" "$held_line" "$rt_push_set_output" >&2
119
- exit 1
117
+ # shellcheck disable=SC1091
118
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
119
+ command -v rt_decide >/dev/null 2>&1 || exit 0
120
+ rt_decide pre-push.sh push '{"push_sends_tip":"yes","push_checks_green":"no"}' \
121
+ "$(jq -cn --arg n "$(printf '%s\n' "$rt_push_set_failed" | grep -c .)" --arg f "$rt_push_set_failed" --arg h "$held_line" --arg o "$rt_push_set_output" \
122
+ '{red_count:$n, failed:$f, held_line:$h, tail_out:$o}')" git
123
+ exit $?
@@ -130,23 +130,10 @@ found="$(node "$check" "$tmp" 2>&1 | grep -- '—' | sed 's|.*proba*[^:]*:| lin
130
130
  rm -f "$tmp"
131
131
  [ -z "$found" ] && exit 0
132
132
 
133
- reason="BLOCKED by prose-style-guard: the new text carries officialese or a word not written in this tree.
134
-
135
- ${found}
136
-
137
- Edit the text instead of bypassing the finding: a replacement is named at each of them. Wording is a rule about texts, and the check sees the listed signs, not style at large: a paragraph clean by it may still be bad, a dirty one is bad for certain."
138
-
139
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
140
- # The file may not be laid out — then there is no tail, and the refusal reason stays as it is.
141
- # shellcheck disable=SC1090
142
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
143
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
144
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
145
- deny_tail_text="$(rt_deny_tail "")"
146
- [ -n "$deny_tail_text" ] && reason="${reason}
147
-
148
- ${deny_tail_text}"
149
-
150
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
151
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"prose-style-guard: officialese in the new text."}}\n'
133
+ # The decision and the words come from the decision table; the check above is the fact, and the
134
+ # hook names what it found.
135
+ # shellcheck disable=SC1091
136
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
137
+ command -v rt_decide >/dev/null 2>&1 || exit 0
138
+ rt_decide prose-style-guard.sh write_dirty_md '{}' "$(jq -cn --arg s "$found" '{found:$s}')" PreToolUse "$input"
152
139
  exit 0
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env bash
2
+ # The merges of requests and the editions of packages, read from the hosting and the registry into
3
+ # the observations. NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The
4
+ # sending calls it.
5
+ #
6
+ # bash pull-merges.sh [YYYY-MM-DD]
7
+ #
8
+ # A day named on the command line reads from it, past the mark: a fact read before is replaced, so a
9
+ # read that judges it anew corrects the observation.
10
+ # The hosting side lives in the tree profile: `rt_merge_facts <day>` prints the requests merged since
11
+ # the day and the open ones, `{number, state, headRefName, baseRefName, title, mergedAt, files}` one
12
+ # per line, `rt_package_dirs` names the package directories and `rt_package_ignored` the pattern of
13
+ # the files under them that are never published. A package is published when the
14
+ # registry knows an edition of it; one the registry does not know is not a package of an epic.
15
+ #
16
+ # The reading has a mark of its own, the day of the last read: the next read starts from it. A first
17
+ # read starts from the keeping term of the observations, not from the mark of the outcomes. A broken
18
+ # answer of the hosting or the registry writes nothing and keeps the day: the next read takes it again.
19
+ #
20
+ # Exit code 3 — nobody to ask: no profile function, no hosting client. Code 4 — a broken read.
21
+
22
+ hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23
+ root="${CLAUDE_PROJECT_DIR:-$PWD}"
24
+ export CLAUDE_PROJECT_DIR="$root"
25
+ cd "$root" 2>/dev/null || exit 3
26
+
27
+ for profile in "$hooks_dir/../rt-kit/defaults/project.sh" "$hooks_dir/../defaults/project.sh" \
28
+ "$root/.claude/rt-kit/defaults/project.sh" "$root/.claude/rt-kit/project.sh"; do
29
+ # shellcheck disable=SC1090
30
+ [ -f "$profile" ] && . "$profile" 2>/dev/null
31
+ done
32
+
33
+ . "$hooks_dir/metric-marks.sh" 2>/dev/null || exit 3
34
+ command -v rt_merge_facts >/dev/null 2>&1 || exit 3
35
+ command -v jq >/dev/null 2>&1 || exit 3
36
+ command -v node >/dev/null 2>&1 || exit 3
37
+
38
+ reader=''
39
+ for candidate in "$hooks_dir/../../tools/merge-read.mjs" "$hooks_dir/../checks/merge-read.mjs"; do
40
+ [ -f "$candidate" ] && reader="$candidate" && break
41
+ done
42
+ [ -n "$reader" ] || exit 3
43
+
44
+ dir="$(rt_observe_dir)"
45
+ marks="$(rt_marks_dir)"
46
+ [ -n "$dir" ] && [ -n "$marks" ] || exit 3
47
+
48
+ today="$(date -u +%Y-%m-%d)"
49
+ since="${1:-$(cat "$marks/merges-read-day" 2>/dev/null)}"
50
+ if [ -z "$since" ]; then
51
+ since="$(node -e 'console.log(new Date(Date.now() - Number(process.argv[1]) * 86400000).toISOString().slice(0, 10))' "${RT_MARKS_KEEP_DAYS:-30}")"
52
+ fi
53
+
54
+ work="$(mktemp -d)"
55
+ trap 'rm -rf "$work"' EXIT
56
+
57
+ rt_merge_facts "$since" > "$work/pulls.jsonl" 2>/dev/null
58
+ code=$?
59
+ [ "$code" = 3 ] && exit 3
60
+ [ "$code" = 0 ] || exit 4
61
+
62
+ packages=''
63
+ editions=()
64
+ for pkg_dir in $(rt_package_dirs 2>/dev/null); do
65
+ name="$(jq -r '.name // empty' "$pkg_dir/package.json" 2>/dev/null)"
66
+ [ -n "$name" ] || continue
67
+ times="$work/$(basename "$pkg_dir").json"
68
+ npm view "$name" time --json > "$times" 2>/dev/null || continue
69
+ packages="${packages:+$packages,}$pkg_dir"
70
+ editions+=(--editions "$(basename "$pkg_dir")=$times")
71
+ done
72
+
73
+ node "$reader" --pulls "$work/pulls.jsonl" --observations "$dir" \
74
+ --packages "$packages" --ignore "$(rt_package_ignored 2>/dev/null)" "${editions[@]}" || exit 4
75
+ printf '%s\n' "$today" > "$marks/merges-read-day"
76
+ exit 0
@@ -41,6 +41,9 @@ rt_push_set_profile() {
41
41
  command -v rt_push_set_over_budget >/dev/null 2>&1 || rt_push_set_over_budget() { return 0; }
42
42
  command -v rt_push_mark_drop >/dev/null 2>&1 || rt_push_mark_drop() { return 0; }
43
43
  command -v rt_push_select >/dev/null 2>&1 || rt_push_select() { cat; }
44
+ command -v rt_push_subjects >/dev/null 2>&1 || rt_push_subjects() { cat >/dev/null; }
45
+ command -v rt_push_subject_of >/dev/null 2>&1 || rt_push_subject_of() { printf unknown; }
46
+ command -v rt_push_note_not_run >/dev/null 2>&1 || rt_push_note_not_run() { return 0; }
44
47
  # The line of a run for the metrics. No file — the set runs and records nothing.
45
48
  # shellcheck disable=SC1091
46
49
  [ -f "$hooks_dir/metric-marks.sh" ] && . "$hooks_dir/metric-marks.sh" 2>/dev/null
@@ -73,10 +76,14 @@ rt_push_set_base() {
73
76
  # named in `rt_push_set_ahead` instead of being started. The git hook has no such limit, leaves the
74
77
  # variable empty and runs the step itself.
75
78
  rt_push_set_run() {
76
- local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}" sign started set_started set_took set_over over marked=""
79
+ local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}" sign started set_started set_took set_over over marked="" subjects
77
80
  case "$skip_code" in '' | 0 | 1 | *[!0-9]*) skip_code=7 ;; esac
78
81
  command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
79
82
  sign="$(rt_tree_sign .)"
83
+ # Whether the change touched the subject of each step, for the run lines; a step the selection
84
+ # drops leaves a line of its own.
85
+ subjects="$(rt_push_checks "$base" | rt_push_subjects "$base")"
86
+ rt_push_note_not_run "$sign" "$base" "$subjects"
80
87
 
81
88
  rt_push_set_failed=""
82
89
  rt_push_set_output=""
@@ -119,16 +126,16 @@ rt_push_set_run() {
119
126
  rt_push_mark_put "$check" "$base" "$key_before"
120
127
  marked="${marked}${marked:+
121
128
  }${check}"
122
- rt_run_note "$sign" "$started" green "$check"
129
+ rt_run_note "$sign" "$started" green "$check" "$base" "$(rt_push_subject_of "$subjects" "$check")"
123
130
  continue
124
131
  fi
125
132
  if [ "$status" -eq "$skip_code" ]; then
126
133
  rt_push_set_skipped="${rt_push_set_skipped}${rt_push_set_skipped:+
127
134
  }${check}"
128
- rt_run_note "$sign" "$started" skipped "$check"
135
+ rt_run_note "$sign" "$started" skipped "$check" "$base" "$(rt_push_subject_of "$subjects" "$check")"
129
136
  continue
130
137
  fi
131
- rt_run_note "$sign" "$started" red "$check"
138
+ rt_run_note "$sign" "$started" red "$check" "$base" "$(rt_push_subject_of "$subjects" "$check")"
132
139
  rt_push_set_failed="${rt_push_set_failed}${rt_push_set_failed:+
133
140
  }${check}"
134
141
  rt_push_set_output="${rt_push_set_output}${rt_push_set_output:+
@@ -152,21 +152,11 @@ missing="$(printf '%s' "$added" | RT_QA_DECORATIVE="$decorative" RT_QA_COMPONENT
152
152
 
153
153
  [ -z "$missing" ] && exit 0
154
154
 
155
- reason="BLOCKED: interactive elements without a test anchor in ${path##*/}: ${missing}. Tests address elements only through this attribute: styling classes change together with the markup, and a search by role and text breaks on translations — both kinds of selection make end-to-end tests brittle. Set the anchor through a dash by the meaning of the element; repeating elements of a list carry ONE anchor and differ by data attributes. If an element is purely decorative and a test will never touch it — put the skip attribute ON THAT VERY TAG, the neighbouring elements of the edit keep being checked."
156
-
157
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has
158
- # one. The file may not be laid out — then there is no tail, and the reason for the refusal stays
159
- # the same.
160
- # shellcheck disable=SC1090
161
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
162
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
163
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
164
- deny_tail_text="$(rt_deny_tail "the skip attribute on the decorative tag itself")"
165
- [ -n "$deny_tail_text" ] && reason="${reason}
166
-
167
- ${deny_tail_text}"
168
-
169
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
170
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"An interactive element without a test anchor."}}\n'
171
-
155
+ # The decision and the words come from the decision table; the analysis above is the fact, and the
156
+ # hook names the elements it found.
157
+ # shellcheck disable=SC1091
158
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
159
+ command -v rt_decide >/dev/null 2>&1 || exit 0
160
+ rt_decide qa-dataid-guard.sh template_no_anchor '{}' \
161
+ "$(jq -cn --arg f "${path##*/}" --arg m "$missing" '{file:$f, missing:$m}')" PreToolUse "$input"
172
162
  exit 0
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: Stop
3
+ # rt-hook: SessionEnd
4
+ # Requires: hooks/observe.sh, hooks/hook-input.sh, hooks/metric-marks.sh, hooks/owner-corrections.sh, checks/record-turn.mjs, checks/record-count.mjs
5
+ #
6
+ # Counts the turn from the session record for the metrics of the work result: the calls, the refusals
7
+ # with their class and check, the changes of the tree, the owner's words, the interrupts and the menu
8
+ # questions. The observations of the guards miss part of the refusals — a check that refuses without
9
+ # writing one — and know no calls at all; the record holds both.
10
+ #
11
+ # WHAT IS KEPT. Observation lines with the moment, the kind of event, the task key of the branch, the
12
+ # check and the session sign. No text of the conversation reaches a file: a word of the owner leaves
13
+ # only its kind and whether a correction pattern matched it. A mark per session keeps the offset read.
14
+ #
15
+ # The session end counts once more: the refusal of the last stop hook is written into the record after
16
+ # the stop hooks of that turn have run.
17
+ #
18
+ # FAIL-OPEN: no input, no parser, no record, no node, no counter — exit with zero and no output. This
19
+ # hook never refuses and never adds to the context.
20
+
21
+ here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22
+ . "$here/hook-input.sh" 2>/dev/null || exit 0
23
+ . "$here/observe.sh" 2>/dev/null || exit 0
24
+ . "$here/metric-marks.sh" 2>/dev/null || exit 0
25
+
26
+ rt_hook_read
27
+ [ -n "${RT_HOOK_INPUT:-}" ] || exit 0
28
+ command -v jq >/dev/null 2>&1 || exit 0
29
+ command -v node >/dev/null 2>&1 || exit 0
30
+
31
+ record="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.transcript_path // empty' 2>/dev/null)"
32
+ session="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)"
33
+ [ -n "$session" ] || exit 0
34
+
35
+ dir="$(rt_observe_dir)"
36
+ [ -n "$dir" ] || exit 0
37
+ marks="$(rt_marks_dir)"
38
+ [ -n "$marks" ] || exit 0
39
+ sign="$(rt_observe_session "$session")"
40
+
41
+ counter=''
42
+ for candidate in "$here/../../tools/record-turn.mjs" "$here/../checks/record-turn.mjs"; do
43
+ [ -f "$candidate" ] && counter="$candidate" && break
44
+ done
45
+ [ -n "$counter" ] || exit 0
46
+
47
+ # The set of correction patterns is read from the hook that declares it, not held here as a copy.
48
+ patterns="$(sed -n "s/^RT_CORRECTION_PATTERNS='\(.*\)'$/\1/p" "$here/owner-corrections.sh" 2>/dev/null)"
49
+
50
+ node "$counter" --record "$record" --observations "$dir" --mark "$marks/record-$sign.json" --sid "$sign" \
51
+ --patterns "$patterns" --version "$(rt_observe_version)" >/dev/null 2>&1
52
+ exit 0
@@ -70,7 +70,9 @@ fi
70
70
  run_id="$(printf '%s' "$cmd" | grep -oE '(^|[[:space:]])[0-9]{6,}([[:space:]]|$)' | tr -d ' ' | head -1)"
71
71
  [ -z "$run_id" ] && exit 0
72
72
 
73
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
73
+ # shellcheck disable=SC1091
74
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
75
+ transcript="$(rt_fact_transcript "$input")"
74
76
  [ -z "$transcript" ] && exit 0
75
77
  [ -f "$transcript" ] || exit 0
76
78
 
@@ -85,19 +87,12 @@ seen="$(jq -s -r --arg id "$run_id" '
85
87
 
86
88
  [ "$seen" = "read" ] && exit 0
87
89
 
88
- reason="BLOCKED by rerun-guard: a rerun of the run ${run_id} without its output read. Red on a run comes in two kinds, and in the list they look the same: a hosting refusal on the preparation step is cured by a rerun, a defect of the branch is not cured by it at all, and the circle repeats until the output is opened. Read the output of this run — ${log_cmd} ${run_id}$([ "$log_cmd" = "glab ci trace" ] || printf ' --log-failed') — and repeat the call. The guard judges the order, not the cause of the fall: what is written in the output you judge yourself."
89
-
90
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
91
- # The file may not be laid out — then there is no tail, and the refusal reason stays as it is.
92
- # shellcheck disable=SC1090
93
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
94
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
95
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
96
- deny_tail_text="$(rt_deny_tail "")"
97
- [ -n "$deny_tail_text" ] && reason="${reason}
98
-
99
- ${deny_tail_text}"
100
-
101
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
102
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"rerun-guard: the output of the run was not read in this turn."}}\n'
90
+ # The decision and the words come from the decision table; the hook names the run and how its output
91
+ # is read.
92
+ log="${log_cmd} ${run_id}$([ "$log_cmd" = "glab ci trace" ] || printf ' --log-failed')"
93
+ # shellcheck disable=SC1091
94
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
95
+ command -v rt_decide >/dev/null 2>&1 || exit 0
96
+ rt_decide rerun-guard.sh rerun_run '{"run_log_read":"no"}' \
97
+ "$(jq -cn --arg r "$run_id" --arg l "$log" '{run_id:$r, log:$l}')" PreToolUse "$input"
103
98
  exit 0
@@ -359,25 +359,11 @@ fi
359
359
 
360
360
  [ -z "$found" ] && exit 0
361
361
 
362
- reason="BLOCKED: this is already written. File: ${path##*/}
363
- ${found}
364
-
365
- The order of moves: 1) open the ready-made — the barrel of the kit or the base class — and use it; 2) find in the tree a screen where this case is already assembled, and repeat that assembly; 3) if the ready-made really is not enough — extend it in place, at the ready-made, instead of cloning it alongside: a clone takes the edits onto itself and drifts from the original from the very first one.
366
- A primitive of one's own, a base of one's own and inline styles of one's own are created only with the explicit approval of the owner, and it is asked before the first file is written. A one-off exception is marked by a departure marker on the same line, with an explanation of what exactly the ready-made lacks. Renaming the file does not bypass this."
367
-
368
- # The shared refusal tail: the two lawful moves and the lawful form of the bypass, if the refusal
369
- # has one. The file may be not laid out — then there is no tail, and the reason for the refusal
370
- # stays as it was.
371
- # shellcheck disable=SC1090
372
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
373
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
374
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
375
- deny_tail_text="$(rt_deny_tail "a departure marker on the same line, with an explanation of what exactly the ready-made lacks")"
376
- [ -n "$deny_tail_text" ] && reason="${reason}
377
-
378
- ${deny_tail_text}"
379
-
380
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
381
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Something of its own is written where the ready-made already exists."}}\n'
382
-
362
+ # The decision and the words come from the decision table; the analysis above is the fact, and the
363
+ # hook names what it found.
364
+ # shellcheck disable=SC1091
365
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
366
+ command -v rt_decide >/dev/null 2>&1 || exit 0
367
+ rt_decide reuse-first-guard.sh template_own_primitive '{}' \
368
+ "$(jq -cn --arg f "${path##*/}" --arg s "$found" '{file:$f, found:$s}')" PreToolUse "$input"
383
369
  exit 0
@@ -15,7 +15,9 @@
15
15
  # knowledge about it: the words of a refusal, in both languages a role answers in. A role outside the
16
16
  # table is counted by calls. Only the answer goes into the record, the text stays where it is. It is
17
17
  # read when the role ends, not when it is called: a role usually runs in the background, and at the
18
- # call its answer is only the fact of the launch.
18
+ # call its answer is only the fact of the launch. A verdict carries the task of its moment: the key
19
+ # of the branch, and on the main branch the epic number of the copy's assignment, read by
20
+ # `checks/tree-assignment.mjs` where it is laid out.
19
21
  #
20
22
  # FAIL-OPEN: no input, no parser, no record — exit with zero and no output. This hook never refuses.
21
23
 
@@ -45,6 +47,24 @@ rt_called_name() {
45
47
 
46
48
  # The words of a verdict by role: the refusal first, because it holds the words of a pass. No line —
47
49
  # the role gives no verdict the report counts.
50
+ # The task a verdict counts against: the task key of the branch at the moment of the verdict. On a
51
+ # branch with no key — the main branch — it is the epic the tree assignment names for the copy, and
52
+ # with none it is `none`: the report prints such a verdict under «без задачи».
53
+ rt_verdict_task() {
54
+ local branch key checks epic
55
+ branch="$(git -C "$root" branch --show-current 2>/dev/null)"
56
+ key="$(printf '%s' "$branch" | sed -nE 's/^([A-Z]+-[0-9]+)(-.*)?$/\1/p')"
57
+ if [ -n "$key" ]; then
58
+ printf 'task=%s' "$key"
59
+ return 0
60
+ fi
61
+ checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
62
+ [ -n "$checks" ] && [ "$checks" != null ] || checks=tools
63
+ epic=''
64
+ [ -f "$root/$checks/tree-assignment.mjs" ] && epic="$(cd "$root" && node "$checks/tree-assignment.mjs" --assigned 2>/dev/null)"
65
+ if [ -n "$epic" ]; then printf 'epic=%s' "$epic"; else printf 'task=none'; fi
66
+ }
67
+
48
68
  rt_refusal_words() {
49
69
  case "$1" in
50
70
  goal-critic) printf '%s' 'not met|partly met|не достигнут|не выполнен|частично' ;;
@@ -67,7 +87,9 @@ rt_role_answer() {
67
87
  printf '%s' "$answer"
68
88
  return 0
69
89
  fi
70
- path="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.agent_transcript_path // empty' 2>/dev/null)"
90
+ # shellcheck disable=SC1091
91
+ command -v rt_fact_agent_transcript >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
92
+ path="$(rt_fact_agent_transcript "$RT_HOOK_INPUT")"
71
93
  [ -f "$path" ] || return 0
72
94
  tail -n 20 "$path" 2>/dev/null \
73
95
  | jq -c 'select(.message.content? | type == "array") | .message.content[]
@@ -107,7 +129,7 @@ if [ "$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.hook_event_name // empty' 2>/dev/
107
129
  ended="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.agent_type // empty' 2>/dev/null)"
108
130
  name="$(rt_called_name "$root/.claude/agents/$ended.md" "$ended")"
109
131
  verdict="$(rt_verdict_of "$name")"
110
- [ -z "$verdict" ] || rt_note role-verdict "res=$name" "sid=$sid" "verdict=$verdict"
132
+ [ -z "$verdict" ] || rt_note role-verdict "res=$name" "sid=$sid" "verdict=$verdict" $(rt_verdict_task)
111
133
  exit 0
112
134
  fi
113
135
 
@@ -43,15 +43,31 @@ done
43
43
  [ -f "$rt_hooks_dir/profile-check.sh" ] && . "$rt_hooks_dir/profile-check.sh"
44
44
  command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
45
45
 
46
- # shellcheck disable=SC1090
47
- [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
48
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { printf ''; }
49
-
50
- deny() {
51
-
52
- reason="$1 $(rt_deny_tail "$2")"
53
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
54
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"The guard of the place of the edit."}}\n'
46
+ # The decision and the words come from the decision table. A refusal that names an edit of another
47
+ # file hands the decider the facts its neighbours judge that edit by — the exam, the window, the rules
48
+ # gate, the handover and the course of work — and the decider puts first what they want.
49
+ # shellcheck disable=SC1091
50
+ . "$rt_hooks_dir/decide.sh" 2>/dev/null
51
+ # shellcheck disable=SC1091
52
+ . "$rt_hooks_dir/facts.sh" 2>/dev/null
53
+ # shellcheck disable=SC1091
54
+ . "$rt_hooks_dir/facts-flow.sh" 2>/dev/null
55
+
56
+ # refuse <action> <own facts JSON> <params JSON> [file of the named edit]
57
+ refuse() {
58
+ local move='{}' flow='{"facts":{},"params":{}}' named
59
+ command -v rt_decide >/dev/null 2>&1 || exit 0
60
+ if [ -n "${4:-}" ]; then
61
+ named="$(jq -cn --arg f "$4" '{file_path:$f,old_string:"",new_string:""}')"
62
+ move="$(rt_fact_move Edit "$named" "$input")"
63
+ if command -v rt_fact_flow_of >/dev/null 2>&1; then
64
+ flow="$(rt_fact_flow_of Edit "$named" "$input")"
65
+ [ -n "$flow" ] || flow='{"facts":{},"params":{}}'
66
+ fi
67
+ fi
68
+ rt_decide "$RT_GUARD_NAME.sh" "$1" \
69
+ "$(jq -cn --argjson m "$move" --argjson f "$flow" --argjson o "$2" '$m + $f.facts + $o')" \
70
+ "$(jq -cn --argjson f "$flow" --argjson p "$3" '$f.params + $p')" PreToolUse "$input"
55
71
  exit 0
56
72
  }
57
73
 
@@ -88,6 +104,9 @@ esac
88
104
  [ -z "$candidates" ] && exit 0
89
105
 
90
106
  root="${CLAUDE_PROJECT_DIR:-.}"
107
+ root_abs="$(cd "$root" 2>/dev/null && pwd -P)"
108
+ [ -n "$root_abs" ] || root_abs="$root"
109
+
91
110
 
92
111
  # The directory of package sources in this tree. Only the tree that carries the package has one; a
93
112
  # consumer has no source at all, and has a single address for an edit — the override.
@@ -106,25 +125,32 @@ while IFS= read -r candidate; do
106
125
  # turns a report into a statement of the one who edited it. Only the guards write here.
107
126
  case "$candidate" in
108
127
  */.claude/rt-kit/observations/*)
109
- deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» lies in the observations directory, and only the guards write there. An edit by hand makes the numbers of the package a statement of the one who wrote them." \
110
- "the way out is to do the work the observation records, not to write the observation"
128
+ refuse edit_observations '{}' "$(jq -cn --arg p "${candidate#"$root"/}" '{path:$p}')"
111
129
  ;;
112
130
  */.claude/rt-kit.json)
113
131
  # Both keys decide what the numbers of the package are, and the one those numbers judge
114
132
  # must not switch them off. The owner edits them by hand.
115
133
  if printf '%s' "$input" | jq -r '.tool_input | tostring' 2>/dev/null | grep -qE '(^|[^[:alnum:]_-])(send|observe)([^[:alnum:]_-]|$)'; then
116
- deny "BLOCKED by rule-source-guard: the keys «send» and «observe» of «${candidate#"$root"/}» decide what the numbers of the package are, and a session does not edit them." \
117
- "the way out is to name the change to the owner: they edit these two keys by hand"
134
+ refuse edit_rtkit_send '{}' "$(jq -cn --arg p "${candidate#"$root"/}" '{path:$p}')"
118
135
  fi
119
136
  ;;
120
137
  esac
121
138
  [ -f "$candidate" ] || continue
139
+ # A laid-out file is a file of this tree. One outside it — a scratch copy, a neighbouring
140
+ # repository — is laid out by nobody here, even when it quotes a header. The two checks above
141
+ # judge by the end of the path and stay before this one.
142
+ case "$candidate" in
143
+ "$root"/* | "$root_abs"/*) ;;
144
+ *) continue ;;
145
+ esac
122
146
 
123
147
  # The header stands at the beginning of the file, but not on the first line: in a script `#!`
124
148
  # pushes it down, in a rule the title with the name and the kind of the resource does. Ten
125
149
  # lines are enough for both, and the whole file must not be read: the guard stands on every
126
150
  # edit.
127
- resource="$(head -12 "$candidate" 2>/dev/null | sed -nE 's/.*rt-kit v[^ ]+ · ([^ ]+) · [0-9a-f]+.*/\1/p' | head -1)"
151
+ # Only a comment line of the header form counts: a file that quotes the header inside a string
152
+ # or a sentence is not laid out.
153
+ resource="$(head -12 "$candidate" 2>/dev/null | sed -nE 's/^[[:space:]]*(<!--|\/\/|#|\/\*|\*)[[:space:]]*rt-kit v[^ ]+ · ([^ ]+) · [0-9a-f]+.*/\2/p' | head -1)"
128
154
  [ -z "$resource" ] && continue
129
155
 
130
156
  # A file in conflict is skipped on a par with a removed one. Resolving a conflict does not
@@ -148,19 +174,26 @@ while IFS= read -r candidate; do
148
174
  *.md) override_way="an edit true only to this tree goes to the override .claude/rt-kit/overrides/${resource} — it merges by the section «## » and outlives the layout" ;;
149
175
  *) override_way="there is no override by sections for a resource of this kind: it has no «## » sections at all, and the edit goes into the package itself" ;;
150
176
  esac
177
+ said="$(jq -cn --arg p "${candidate#"$root"/}" --arg r "$resource" --arg w "$override_way" '{path:$p, resource:$r, override_way:$w}')"
151
178
 
152
179
  if [ -n "$sources" ] && [ -f "$root/$sources/$resource" ]; then
153
- deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» is laid out by the package, and an edit in its place is lost on the next layout — and until then the layout refuses this file whole, and the price is paid by whoever edits a neighbouring resource that day. The resource is «${resource}». Edit the source: ${sources}/${resource} — then build the package and lay it out." \
154
- "$override_way"
180
+ refuse edit_laid_out '{"package_source":"present"}' \
181
+ "$(printf '%s' "$said" | jq -c --arg s "$sources/$resource" '. + {source:$s}')" "$root/$sources/$resource"
155
182
  fi
156
183
 
184
+ # The override merges by the section «## »; a resource of another kind has no override at all.
157
185
  case "$resource" in
158
- *.md) where="Edit the override: .claude/rt-kit/overrides/${resource} — it merges by the section «## » and outlives the layout." ;;
159
- *) where="A resource of this kind has no override by sections — it has no «## » sections at all. The edit goes into the package itself and arrives here by a new edition." ;;
186
+ *.md)
187
+ refuse edit_laid_out '{"package_source":"absent"}' \
188
+ "$(printf '%s' "$said" | jq -c --arg w "Edit the override: .claude/rt-kit/overrides/${resource} — it merges by the section «## » and outlives the layout." '. + {where:$w}')" \
189
+ "$root/.claude/rt-kit/overrides/${resource}"
190
+ ;;
191
+ *)
192
+ refuse edit_laid_out '{"package_source":"absent"}' \
193
+ "$(printf '%s' "$said" | jq -c --arg w "A resource of this kind has no override by sections — it has no «## » sections at all. The edit goes into the package itself and arrives here by a new edition." '. + {where:$w}')" \
194
+ "$candidate"
195
+ ;;
160
196
  esac
161
-
162
- deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» is laid out by the package @rt-tools/agent-kit, and an edit in its place is lost on the next layout. The resource is «${resource}». ${where}" \
163
- "what is true of any tree is edited in the package itself and arrives here by a new edition"
164
197
  done <<EOF
165
198
  $candidates
166
199
  EOF
@@ -27,9 +27,22 @@ record="${TMPDIR:-/tmp}/claude-skill-gate/${sid}.loaded"
27
27
  # per refusal, and a session that does not know which rules it had loaded meets them one refusal at
28
28
  # a time: one edit after a compaction went through six refusals in a row. An empty or missing record
29
29
  # gives no names, and the line stays as it was.
30
- loaded=""
30
+ #
31
+ # The gate puts a rule within the host limit into the session itself at the next edit of its area,
32
+ # so only the rules longer than the limit are named: asking to load the rest in one turn is the
33
+ # round the delivery removed.
34
+ # shellcheck disable=SC1091
35
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
36
+ over=""
31
37
  if [ -s "$record" ]; then
32
- loaded="$(awk 'NF && !seen[$0]++ { printf "%s%s", (n++ ? ", " : ""), $0 }' "$record" 2>/dev/null)"
38
+ while IFS= read -r name; do
39
+ [ -z "$name" ] && continue
40
+ name="${name##*:}"
41
+ case ", $over, " in *", $name, "*) continue ;; esac
42
+ command -v rt_fact_rule_deliverable >/dev/null 2>&1 && rt_fact_rule_deliverable "$name" "$sid" && continue
43
+ [ -f "${CLAUDE_PROJECT_DIR:-.}/${RT_RULES_DIR:-.claude/skills}/$name/SKILL.md" ] || continue
44
+ over="${over}${over:+, }${name}"
45
+ done < "$record"
33
46
  fi
34
47
 
35
48
  rm -f "$record" 2>/dev/null
@@ -40,9 +53,9 @@ rm -f "$record" 2>/dev/null
40
53
  # the gate answers that they were not — and the session spends a turn finding out which of the two
41
54
  # is right. A turn was spent that way four times in one session. The line removes the contradiction:
42
55
  # the rule text is no longer in the context, which is why it is asked for again.
43
- context="The rules gate is armed anew: the compaction carried the text of the rules themselves out of the session, and every area will ask for its rule once more. The former loading does not count — load the rule and work on."
44
- if [ -n "$loaded" ]; then
45
- context="${context} Loaded before the compaction: ${loaded}. Load in one turn every one of them that the current stage touches, before the first edit."
56
+ context="The rules gate is armed anew: the compaction carried the text of the rules themselves out of the session. Every rule within the host limit comes back by itself, whole, at the next edit of its area — the gate puts it into the session."
57
+ if [ -n "$over" ]; then
58
+ context="${context} Longer than the host limit, and so not delivered: ${over}. Load these by the tool Skill, or read their SKILL.md by the tool Read, before the first edit of their area."
46
59
  fi
47
60
 
48
61
  jq -n --arg c "$context" '{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:$c}}' 2>/dev/null