@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
@@ -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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: PreToolUse Edit|Write|MultiEdit|Bash|mcp__webstorm__create_new_file|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool|mcp__claude-in-chrome__.*|mcp__figma__use_figma
3
- # Requires: hooks/deny-tail.sh
3
+ # Requires: checks/decide.mjs, hooks/decide.sh, hooks/deny-tail.sh
4
4
  # The rules gate: it does not let a file be edited until the rule it falls under has been loaded.
5
5
  #
6
6
  # A law and a rule nobody opens do not act. A reminder in the prompt helps right up to the first
@@ -173,7 +173,10 @@ esac
173
173
  # The map may name several rules: the domain rule and the one that acts as a second layer. The
174
174
  # first unloaded one is demanded, not all at once: a refusal listing three rules reads as "load
175
175
  # three", and they get loaded one after another, losing that very one-time-ness.
176
- loaded="${TMPDIR:-/tmp}/claude-skill-gate/${sid}.loaded"
176
+ # A subagent has a context of its own: a rule delivered there is recorded under its id, never for
177
+ # the parent, or the parent's edits would pass unread.
178
+ agent="$(printf '%s' "$input" | jq -r '.agent_id // empty' 2>/dev/null)"
179
+ loaded="${TMPDIR:-/tmp}/claude-skill-gate/${agent:-$sid}.loaded"
177
180
  root="${CLAUDE_PROJECT_DIR:-.}"
178
181
  rules_dir="${RT_RULES_DIR:-.claude/skills}"
179
182
  want=""
@@ -199,6 +202,8 @@ done
199
202
  ahead=""
200
203
  for name in $req; do
201
204
  [ "$name" = "$want" ] && continue
205
+ # Two writes of one command may name the same rule: it is named once.
206
+ case ", $ahead, " in *", $name, "*) continue ;; esac
202
207
  [ -f "$root/$rules_dir/${name}/SKILL.md" ] || continue
203
208
  if [ -f "$loaded" ] && grep -qE "^([^:]*:)?$(printf '%s' "$name" | sed 's/[][\.*^$/]/\\&/g')$" "$loaded" 2>/dev/null; then
204
209
  continue
@@ -206,13 +211,136 @@ for name in $req; do
206
211
  ahead="${ahead}${ahead:+, }${name}"
207
212
  done
208
213
 
214
+ # The delivery. Every rule of the call not yet loaded arrives in the session by this very answer,
215
+ # and the call goes on: a refusal "load and repeat" was followed by a load almost every time and
216
+ # caught nothing. The text is the tree's SKILL.md byte for byte; the host puts a context field of
217
+ # up to the limit into the session whole and cuts a longer one, so a text over the limit is not
218
+ # delivered — the refusal below stays for it. A call without a session id has no record to write
219
+ # into and is refused too: every call of it would deliver anew.
220
+ gate_limit="${RT_GATE_CONTEXT_LIMIT:-10000}"
221
+ case "$gate_limit" in '' | *[!0-9]*) gate_limit=10000 ;; esac
222
+ # Reads a file into `gate_body` byte for byte: a command substitution strips trailing newlines,
223
+ # so the text is read with a marker after it and the marker is cut off in place.
224
+ rt_gate_read() {
225
+ gate_body=""
226
+ [ -r "$1" ] || return 1
227
+ gate_body="$(cat "$1" 2>/dev/null && printf x)" || return 1
228
+ gate_body="${gate_body%x}"
229
+ }
230
+ rt_gate_law_path() {
231
+ local law path
232
+ law="$(sed -n 's/^law:[[:space:]]*//p' "$root/$rules_dir/$1/SKILL.md" 2>/dev/null | head -1)"
233
+ [ -z "$law" ] && return 0
234
+ path="${RT_LAWS_DIR:-docs/constitution}/${law}.md"
235
+ [ -f "$root/$path" ] || path="${RT_LAWS_DIR:-docs/constitution}/application/${law}.md"
236
+ [ -f "$root/$path" ] && printf '%s' "$path"
237
+ return 0
238
+ }
239
+ need=()
240
+ for name in $req; do
241
+ [ -f "$root/$rules_dir/${name}/SKILL.md" ] || continue
242
+ if [ -f "$loaded" ] && grep -qE "^([^:]*:)?$(printf '%s' "$name" | sed 's/[][\.*^$/]/\\&/g')$" "$loaded" 2>/dev/null; then
243
+ continue
244
+ fi
245
+ # Two writes of one command may name the same rule: it is delivered once.
246
+ case " ${need[*]} " in *" $name "*) continue ;; esac
247
+ need+=("$name")
248
+ done
249
+ gate_unread=""
250
+ gate_why=""
251
+ if [ "$sid" != "nosession" ] && [ "${#need[@]}" -gt 0 ]; then
252
+ head_line="Passed by the rules gate: the call went through, and the text of"
253
+ i=0
254
+ for name in "${need[@]}"; do
255
+ lp="$(rt_gate_law_path "$name")"
256
+ [ "$i" -gt 0 ] && head_line="${head_line},"
257
+ head_line="${head_line} the rule «${name}»${lp:+ (it applies the law ${lp} to this tree)}"
258
+ i=$((i + 1))
259
+ done
260
+ head_line="${head_line} arrived below whole, the same as a load by the tool Skill. For this area it happens once per session."
261
+ rules=()
262
+ comps=()
263
+ for name in "${need[@]}"; do
264
+ rt_gate_read "$root/$rules_dir/${name}/SKILL.md" || { gate_unread="$name"; break; }
265
+ rules+=("
266
+
267
+ === ${rules_dir}/${name}/SKILL.md ===
268
+ ${gate_body}")
269
+ comps+=("")
270
+ done
271
+ # Assembles the delivered text into `text`, in place: a substitution would cut its tail.
272
+ rt_gate_text() {
273
+ local k
274
+ text="$head_line"
275
+ for k in "${!rules[@]}"; do text="${text}${rules[$k]}${comps[$k]}"; done
276
+ }
277
+ rt_gate_text
278
+ if [ -z "$gate_unread" ] && [ "${#text}" -le "$gate_limit" ]; then
279
+ # The companions go after the rules fit: a companion falls back to its path before a rule
280
+ # is dropped. Each is placed whole right after its rule while the whole text still fits.
281
+ for k in "${!need[@]}"; do
282
+ comp="$rules_dir/${need[$k]}/implementation.md"
283
+ [ -f "$root/$comp" ] || continue
284
+ if rt_gate_read "$root/$comp"; then
285
+ comps[k]="
286
+
287
+ === ${comp} ===
288
+ ${gate_body}"
289
+ rt_gate_text
290
+ [ "${#text}" -le "$gate_limit" ] && continue
291
+ fi
292
+ comps[k]="
293
+
294
+ The companion of the rule — ${comp} — did not fit here and is read as a file: the rule says what must be true, the companion — by what that is true here."
295
+ rt_gate_text
296
+ if [ "${#text}" -gt "$gate_limit" ]; then
297
+ comps[k]=""
298
+ rt_gate_text
299
+ fi
300
+ done
301
+ dir="${TMPDIR:-/tmp}/claude-skill-gate"
302
+ recorded=1
303
+ mkdir -p "$dir" 2>/dev/null || recorded=0
304
+ if [ "$recorded" = 1 ]; then
305
+ printf '%s\n' "${need[@]}" >> "$loaded" 2>/dev/null || recorded=0
306
+ fi
307
+ # shellcheck disable=SC1091
308
+ . "$rt_hooks_dir/observe.sh" 2>/dev/null
309
+ if command -v rt_note >/dev/null 2>&1; then
310
+ # An unwritten name costs one more delivery of the same rule; the note says so.
311
+ unrec=""
312
+ [ "$recorded" = 1 ] || unrec="unrecorded=yes"
313
+ for name in "${need[@]}"; do
314
+ rt_note gate-deliver "res=$name" "kind=$kind" "sid=$sid" $unrec
315
+ done
316
+ fi
317
+ jq -cn --arg c "$text" '{hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:$c}}'
318
+ exit 0
319
+ fi
320
+ # Why nothing was delivered: the refusal names it, and the week report counts by it.
321
+ if [ -n "$gate_unread" ]; then
322
+ gate_why="not-read"
323
+ want="$gate_unread"
324
+ else
325
+ gate_why="together"
326
+ for k in "${!rules[@]}"; do
327
+ alone="${head_line}${rules[$k]}"
328
+ if [ "${#alone}" -gt "$gate_limit" ]; then
329
+ gate_why="too-long"
330
+ want="${need[$k]}"
331
+ break
332
+ fi
333
+ done
334
+ fi
335
+ fi
336
+
209
337
  req="$want"
210
338
 
211
339
  # A refusal is an observation: the rule that has to be demanded more often than the rest, and the
212
340
  # edit kind on which that happens, say more about the rules layer than a list of what was loaded.
213
- # shellcheck disable=SC1090
214
- [ -f "$rt_hooks_dir/observe.sh" ] && . "$rt_hooks_dir/observe.sh" 2>/dev/null
215
- command -v rt_note >/dev/null 2>&1 && rt_note gate-deny "res=$req" "kind=$kind" "sid=$sid"
341
+ # The decider writes it when the table refuses, named by the decision: «gate-<decision>».
342
+ [ "$sid" = "nosession" ] && gate_why="no-session"
343
+ RT_DECIDE_NOTE="gate res=$req kind=$kind sid=$sid${gate_why:+ why=$gate_why}"
216
344
 
217
345
  # The fallback move is named in the refusal itself: a rule created in this same branch is unknown
218
346
  # to the rules registry — it is assembled at session start, while the gate reads the disk. Without
@@ -257,6 +385,22 @@ fi
257
385
  # branches: there are three of them, and each rewrites the reason whole.
258
386
  [ -n "$ahead" ] && reason="${reason} Further along this same command these will be needed: ${ahead}."
259
387
 
388
+ # Why the gate did not put the rule into the session itself. Rules that do not fit together are
389
+ # refused together and named all at once: nothing was delivered, so they are loaded in one turn.
390
+ case "$gate_why" in
391
+ too-long)
392
+ reason="${reason} The rule «${req}» is longer than the host limit of ${gate_limit} characters, so the gate does not put it into the session: read ${rules_dir}/${req}/SKILL.md by the tool Read, and the read counts as a load."
393
+ ;;
394
+ not-read)
395
+ reason="${reason} The gate could not read ${rules_dir}/${req}/SKILL.md, so it did not put the rule into the session."
396
+ ;;
397
+ together)
398
+ names=""
399
+ for name in "${need[@]}"; do names="${names}${names:+, }«${name}»"; done
400
+ reason="Refused by the rules gate: the rules ${names} of this call do not fit the host limit of ${gate_limit} characters together, so none of them arrived: load all of them by the tool Skill in one turn and repeat the action. ${fallback}"
401
+ ;;
402
+ esac
403
+
260
404
  # The companion is called by a sentence of its own and for all kinds of refusal at once. Before,
261
405
  # it was named only as a fallback move — "if the tool does not know such a name" — and a reader
262
406
  # who had the name known never got to it at all. The price of that: the rule names a way, and the
@@ -268,19 +412,11 @@ companion="$rules_dir/${req}/implementation.md"
268
412
 
269
413
  The companion of the rule — ${companion} — is read together with it: the rule says what must be true, the companion — by what that is true here and what is named impossible here. It is not loaded by the tool, it is read as a file."
270
414
 
271
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
272
- # The file may not be laid out — then there is no tail, and the reason for the refusal stays as it
273
- # was.
274
- # shellcheck disable=SC1090
275
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
276
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
277
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
278
- deny_tail_text="$(rt_deny_tail "")"
279
- [ -n "$deny_tail_text" ] && reason="${reason}
280
-
281
- ${deny_tail_text}"
282
-
283
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
284
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Load the rule %s and repeat."}}\n' "$req"
285
-
415
+ # The decision and the move come from the decision table; the text is built here — the rule, its
416
+ # law, the articles of the edit and the companion are read from the tree — and the table carries it
417
+ # as the slot `{reason}`. The action is the class of this call.
418
+ # shellcheck disable=SC1091
419
+ . "$rt_hooks_dir/decide.sh" 2>/dev/null
420
+ command -v rt_decide >/dev/null 2>&1 \
421
+ && rt_decide skill-gate.sh "?edit_code" '{"rule_loaded":"no"}' "$(jq -cn --arg r "$reason" '{reason:$r}')" PreToolUse "$input"
286
422
  exit 0
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
- # rt-hook: PostToolUse Skill
3
- # The record of a loaded rule. PostToolUse on the `Skill` tool.
2
+ # rt-hook: PostToolUse Skill|Read
3
+ # The record of a loaded rule. PostToolUse on the `Skill` tool and on a read of a rule file.
4
4
  #
5
5
  # The gate has to know whether a rule is loaded or not, and it has nobody to ask: the tool does not
6
6
  # tell about its past calls. So the load is recorded here, per session.
@@ -20,11 +20,26 @@ input="$RT_HOOK_INPUT"
20
20
 
21
21
  sid="$(printf '%s' "$input" | jq -r '.session_id // "nosession"' 2>/dev/null)"
22
22
  skill="$(printf '%s' "$input" | jq -r '.tool_input.skill // empty' 2>/dev/null)"
23
+ # A read of a rule file by the tool `Read` is a load too: the gate names that read for a rule
24
+ # longer than the host limit, and for a rule created after the session began the registry of the
25
+ # tool `Skill` does not know the name. Only the rule file itself counts, not its companion.
26
+ if [ -z "$skill" ]; then
27
+ read_path="$(printf '%s' "$input" | jq -r 'select(.tool_name == "Read") | .tool_input.file_path // empty' 2>/dev/null)"
28
+ rules_dir="${RT_RULES_DIR:-.claude/skills}"
29
+ case "$read_path" in
30
+ */"$rules_dir"/*/SKILL.md)
31
+ skill="${read_path%/SKILL.md}"
32
+ skill="${skill##*/}"
33
+ ;;
34
+ esac
35
+ fi
23
36
  [ -z "$skill" ] && exit 0
24
37
 
38
+ # A subagent's load lands in the subagent's own record: its context is not the parent's.
39
+ agent="$(printf '%s' "$input" | jq -r '.agent_id // empty' 2>/dev/null)"
25
40
  dir="${TMPDIR:-/tmp}/claude-skill-gate"
26
41
  mkdir -p "$dir" 2>/dev/null || exit 0
27
- printf '%s\n' "$skill" >> "$dir/${sid}.loaded" 2>/dev/null
42
+ printf '%s\n' "$skill" >> "$dir/${agent:-$sid}.loaded" 2>/dev/null
28
43
 
29
44
  # The same load at a second address — the tree's observations. The record above lives until context
30
45
  # compaction and dies with it: it answers the gate's question "is it loaded", and nothing else.
@@ -102,7 +102,7 @@ sql_pass_scratch() {
102
102
  # psql -l / --version / --help — a connection check without a query
103
103
  sql_check_prod() {
104
104
  if [ -n "$is_prod" ] && [ -n "$is_write" ]; then
105
- deny "BLOCKED: a write into the PRODUCTION storage (${context}). The address leads to production — data is restored from there by nothing but a copy. The schema in production is changed by a migration through the rollout, the data — through the panel of the owner. If an edit of production data really is needed, the owner makes it by hand, having taken a copy first; the guard cannot be bypassed."
105
+ sql_refuse "a write into the PRODUCTION storage (${context}). The address leads to production — data is restored from there by nothing but a copy. The schema in production is changed by a migration through the rollout, the data — through the panel of the owner. If an edit of production data really is needed, the owner makes it by hand, having taken a copy first; the guard cannot be bypassed."
106
106
  fi
107
107
 
108
108
  if [ -n "$is_prod" ]; then
@@ -139,7 +139,7 @@ $segments
139
139
  EOF
140
140
 
141
141
  if [ -n "$unproven" ]; then
142
- deny "BLOCKED: a call of the database client against the PRODUCTION database (${context}). In production only a proven read is allowed — \`pg_dump\` without \`--clean\`, a single SELECT through \`-c\`, or \`-l\`/\`--version\`. Everything else is refused, even when the guard simply did not parse the command: the content of files (\`-f\`, \`< dump.sql\`), \`\\copy\` and restoring a dump are invisible to it. If an analysis of production data is needed — take a dump and work with a local copy."
142
+ sql_refuse "a call of the database client against the PRODUCTION database (${context}). In production only a proven read is allowed — \`pg_dump\` without \`--clean\`, a single SELECT through \`-c\`, or \`-l\`/\`--version\`. Everything else is refused, even when the guard simply did not parse the command: the content of files (\`-f\`, \`< dump.sql\`), \`\\copy\` and restoring a dump are invisible to it. If an analysis of production data is needed — take a dump and work with a local copy." prod_session prod
143
143
  fi
144
144
  fi
145
145
  }