@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
@@ -37,13 +37,21 @@ device_id="$("${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/browser-device-id.sh" 2>/de
37
37
  tool="$(rt_hook_tool)"
38
38
 
39
39
  # shellcheck disable=SC1090
40
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
41
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
42
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
43
-
44
- deny() {
45
- echo "$1 Drive the browser by the pinned extension: select the profile ${device_id} and work by its tools. $(rt_deny_tail)" >&2
46
- exit 2
40
+ # The decision and the words come from the decision table; the hook names what it caught. The
41
+ # named move is the selection, and the rules gate refuses it while its rule is not loaded: that is
42
+ # a fact of the state.
43
+ # shellcheck disable=SC1091
44
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
45
+ # shellcheck disable=SC1091
46
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
47
+ sid="$(printf '%s' "$input" | jq -r '.session_id // "nosession"' 2>/dev/null)"
48
+
49
+ refuse() {
50
+ command -v rt_decide >/dev/null 2>&1 || exit 0
51
+ rt_decide browser-guard-no-other-drivers.sh other_driver \
52
+ "$(jq -cn --arg r "$(rt_fact_rule_loaded browser-verification "$sid")" '{pinned:"yes", rule_loaded:$r}')" \
53
+ "$(jq -cn --arg s "$1" --arg d "$device_id" '{said:$s, device_id:$d}')" stderr "$input"
54
+ exit $?
47
55
  }
48
56
 
49
57
  # A driver installed as a plugin carries the plugin name in front of the server name —
@@ -51,9 +59,9 @@ deny() {
51
59
  # matched by a sample: the plain name alone let the same driver open the browser past the profile.
52
60
  case "$tool" in
53
61
  mcp__playwright__* | mcp__plugin_*_playwright__*)
54
- deny "The second browser driver is not used in this project — no sign-in was made in its profile." ;;
62
+ refuse "The second browser driver is not used in this project — no sign-in was made in its profile." ;;
55
63
  mcp__chrome-devtools__* | mcp__plugin_*_chrome-devtools__*)
56
- deny "The third browser driver is not used in this project — it does not ask for the pinned profile." ;;
64
+ refuse "The third browser driver is not used in this project — it does not ask for the pinned profile." ;;
57
65
  esac
58
66
 
59
67
  # The IDE terminal launches the same drivers with the same command line.
@@ -77,16 +85,16 @@ fi
77
85
  # A run of end-to-end specs is the lawful route, and it is never refused.
78
86
  case "$cmd" in
79
87
  *playwright\ open*|*playwright\ codegen*|*playwright\ screenshot*|*playwright\ cr*)
80
- deny "Driving the browser from the driver command line bypasses the pinned profile." ;;
88
+ refuse "Driving the browser from the driver command line bypasses the pinned profile." ;;
81
89
  esac
82
90
 
83
91
  case "$cmd" in
84
92
  *open\ http*|*open\ -a\ *Chrome*|*open\ -a\ *chrome*)
85
- deny "Opening an address by the means of the system raises the default browser, not the pinned profile." ;;
93
+ refuse "Opening an address by the means of the system raises the default browser, not the pinned profile." ;;
86
94
  *osascript*Chrome*|*osascript*chrome*)
87
- deny "Driving the browser by an automation script bypasses the pinned profile." ;;
95
+ refuse "Driving the browser by an automation script bypasses the pinned profile." ;;
88
96
  *chrome-cli*)
89
- deny "This utility bypasses the pinned profile." ;;
97
+ refuse "This utility bypasses the pinned profile." ;;
90
98
  esac
91
99
 
92
100
  # The browser binary — and only in the command position.
@@ -96,10 +104,10 @@ esac
96
104
  # itself on the day it appeared. Hence the anchor at the command boundary and the demand for a
97
105
  # word that looks like an executable, not a flag value.
98
106
  printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(/[^[:space:]]*/)?(google-chrome|chromium)([[:space:]]|\$)" \
99
- && deny "A direct launch of the browser binary bypasses the pinned profile."
107
+ && refuse "A direct launch of the browser binary bypasses the pinned profile."
100
108
 
101
109
  printf '%s' "$cmd" | grep -qF 'Google Chrome.app/Contents/MacOS' \
102
- && deny "A direct launch of the browser binary bypasses the pinned profile."
110
+ && refuse "A direct launch of the browser binary bypasses the pinned profile."
103
111
 
104
112
  # Entry points of browser libraries — what a browser is raised with from code. Listed are both
105
113
  # the launch verb and the verb of attaching to an already raised one: the second bypasses the
@@ -113,7 +121,7 @@ launch='(chromium|firefox|webkit|browserType|puppeteer|chromeLauncher)[[:space:]
113
121
  # is merely looked for.
114
122
  if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(node|bun|deno|python3?)([[:space:]]+-[^[:space:]]+)*[[:space:]]+(-e|--eval|-c|-p|--print)[[:space:]]" \
115
123
  && printf '%s' "$cmd" | grep -qE "$launch"; then
116
- deny "A browser raised by a library from the code of the argument does not ask for the pinned profile."
124
+ refuse "A browser raised by a library from the code of the argument does not ask for the pinned profile."
117
125
  fi
118
126
 
119
127
  # Files the command runs with an interpreter. Package manager wrappers are stripped: under them
@@ -132,7 +140,7 @@ for file in $launched; do
132
140
  path="${base}${file}"
133
141
  [ -f "$path" ] || continue
134
142
  if head -c 200000 "$path" 2>/dev/null | grep -qE "$launch"; then
135
- deny "A browser raised by a library from inside ${file} does not ask for the pinned profile."
143
+ refuse "A browser raised by a library from inside ${file} does not ask for the pinned profile."
136
144
  fi
137
145
  break
138
146
  done
@@ -48,25 +48,24 @@ marker="${TMPDIR:-/tmp}/claude-browser-guard/${sid}"
48
48
  # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
49
49
  # The file may not be laid out — then there is no tail, and the refusal reason stays as it is.
50
50
  # shellcheck disable=SC1090
51
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
52
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
53
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
51
+ # The decision and the words come from the decision table; the hook names what it found about the
52
+ # selection. The named move is the selection, and the rules gate refuses it while its rule is not
53
+ # loaded: that is a fact of the state.
54
+ # shellcheck disable=SC1091
55
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
56
+ # shellcheck disable=SC1091
57
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
54
58
 
55
- # The reason for the refusal goes as a field of the answer, not into the error stream.
56
- #
57
- # What is said into the error stream the executor does not see: "No stderr output" reaches him
58
- # without a single word about what happened, and browser calls failing one after another read as a
59
- # breakage of the extension. Half an hour spent looking for what the guard already knows and says is
60
- # the price of one chosen channel.
61
- deny() {
62
- reason="$1 $(rt_deny_tail)"
63
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
64
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"%s"}}\n' "$1"
59
+ refuse() {
60
+ command -v rt_decide >/dev/null 2>&1 || exit 0
61
+ rt_decide browser-guard-require-select.sh browser_call \
62
+ "$(jq -cn --arg r "$(rt_fact_rule_loaded browser-verification "$sid")" --arg s "$1" '{pinned:"yes", rule_loaded:$r, selection:$s}')" \
63
+ "$(jq -cn --arg s "$2" --arg t "$3" '{said:$s, then:$t}')" PreToolUse "$input"
65
64
  exit 0
66
65
  }
67
66
 
68
67
  if [ ! -f "$marker" ]; then
69
- deny "No browser is selected in this session. Call the browser selection with the profile ${device_id} before any other call."
68
+ refuse none "No browser is selected in this session." "Call the browser selection with the profile ${device_id} before any other call."
70
69
  fi
71
70
 
72
71
  now="$(date +%s)"
@@ -75,7 +74,8 @@ age=$(( now - stamped ))
75
74
 
76
75
  if [ "$age" -gt "$ttl" ]; then
77
76
  rm -f "$marker" 2>/dev/null
78
- deny "The last browser selection was ${age} s ago (the limit is ${ttl} s) — over such a break the active browser of the extension drifts away, and it may no longer be the pinned profile. Call the selection with the profile ${device_id} anew and repeat."
77
+ refuse stale "The last browser selection was ${age} s ago (the limit is ${ttl} s) — over such a break the active browser of the extension drifts away, and it may no longer be the pinned profile." \
78
+ "Call the selection with the profile ${device_id} anew and repeat."
79
79
  fi
80
80
 
81
81
  : >"$marker" 2>/dev/null
@@ -21,12 +21,22 @@
21
21
 
22
22
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
23
23
 
24
- msg_file="$1"
25
- [ -z "$msg_file" ] && exit 0
24
+ # Git names the message file; called by hand, the hook reads the message git keeps for the last commit.
25
+ msg_file="${1:-$(git rev-parse --absolute-git-dir 2>/dev/null)/COMMIT_EDITMSG}"
26
+ [ -f "$msg_file" ] || exit 0
26
27
 
27
28
  repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
28
29
  cd "$repo_root" 2>/dev/null || exit 0
29
30
 
30
31
  [ -x node_modules/.bin/commitlint ] || exit 0
31
32
 
32
- node_modules/.bin/commitlint --edit "$msg_file"
33
+ said="$(node_modules/.bin/commitlint --edit "$msg_file" 2>&1)" && { [ -n "$said" ] && printf '%s\n' "$said" >&2; exit 0; }
34
+ # The linter refused: the decision and the words come from the decision table, the linter's own
35
+ # lines go inside them, and the exit code is the table's answer.
36
+ # shellcheck disable=SC1091
37
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
38
+ command -v rt_decide >/dev/null 2>&1 || { printf '%s\n' "$said" >&2; exit 0; }
39
+ # The facts are those of the state git runs this hook in: the commit has passed the guards of the
40
+ # agent — not on the main branch, signed as declared, its document pair whole, the rule loaded.
41
+ rt_decide commit-msg.sh commit_bad_message '{"rule_loaded":"yes","branch_is_main":"no","commits_signed_declared":"yes","doc_pair":"yes"}' "$(jq -cn --arg s "$said" '{said:$s}')" git
42
+ exit $?
@@ -43,7 +43,9 @@ command -v rt_role_off >/dev/null 2>&1 && rt_role_off conscience && exit 0
43
43
  active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
44
44
  [ "$active" = "true" ] && exit 0
45
45
 
46
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
46
+ # shellcheck disable=SC1091
47
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
48
+ transcript="$(rt_fact_transcript "$input")"
47
49
  [ -z "$transcript" ] && exit 0
48
50
  [ -f "$transcript" ] || exit 0
49
51
 
@@ -125,28 +127,10 @@ verdict="$(printf '%s\n' "$found" | head -1)"
125
127
 
126
128
  detail="$(printf '%s\n' "$found" | tail -n +2)"
127
129
 
128
- reason="BLOCKED by conscience-guard: the conscience found in this turn a repeat of a miss already analysed, and nothing was done about it.
129
-
130
- ${detail}
131
-
132
- A turn does not end at the finding. Do one of three things in this same turn: fix the work, create an analysis of the incident if the mechanism is new, or name the repeat to the owner in words — what repeats and how it ended last time.
133
-
134
- The finding is wrong — then say so to the owner: a false finding also costs a turn, and silence does not fix it.
135
-
136
- The guard judges one turn: the next session is not refused."
137
-
138
- # The shared deny tail: two lawful moves. The file may not be laid out — then there is no tail, and
139
- # the refusal reason stays as it is.
140
- # shellcheck disable=SC1090
141
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
142
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
143
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
144
- deny_tail_text="$(rt_deny_tail "")"
145
- [ -n "$deny_tail_text" ] && reason="${reason}
146
-
147
- ${deny_tail_text}"
148
-
149
- jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
150
- || printf '{"decision":"block","reason":"conscience-guard: a repeat of an analysed miss is found — analyse it or name it to the owner."}\n'
151
-
130
+ # The decision and the words come from the decision table; the hook names what the conscience found.
131
+ # shellcheck disable=SC1091
132
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
133
+ command -v rt_decide >/dev/null 2>&1 && rt_decide conscience-guard.sh end_turn \
134
+ '{"conscience_repeat_found":"yes","repeat_dealt_with":"no","stop_hook_active":"no"}' \
135
+ "$(jq -cn --arg d "$detail" '{detail:$d}')" Stop
152
136
  exit 0
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env bash
2
+ # The call of the decider from a guard. NOT a guard: it has no `rt-hook:` declaration and hooks into
3
+ # no agent event. A guard gathers the facts of the state, sources this file and asks `rt_decide`;
4
+ # the decision, the move a refusal names and its text come from the decision table.
5
+ #
6
+ # Why a file of its own. Every guard emitted its refusal by itself — a JSON of its own, exit 2 with a
7
+ # text on stderr, a `deny()` of its own — and the table only described what they did. One call keeps
8
+ # the decision in one place: a row edited in the table is what the guard does.
9
+ #
10
+ # WHAT IS HERE. One call, `rt_decide`, and the lookup of the decider.
11
+ #
12
+ # rt_decide <hook> <action> <facts JSON> [params JSON] [event] [hook input JSON]
13
+ #
14
+ # An empty action with the hook input given lets the decider find the action from the call itself;
15
+ # «?<action>» does the same and names the hook's own action for a call no class fits.
16
+ # «<class>><action>» names the plain action that decides when no row of the class fits the facts.
17
+ #
18
+ # It prints the answer for the agent and returns 1 when the table refuses or asks; prints nothing and
19
+ # returns 0 when it allows. The event is `PreToolUse` unless named: a Stop hook gets the block form,
20
+ # and the event `git` — a hook of git itself — gets the bare text on the error stream. The event
21
+ # `stderr` is the same form for a guard of the agent that refuses by the code 2: the text goes to the
22
+ # error stream, and the guard exits with what `rt_decide` returned.
23
+ #
24
+ # FAIL-OPEN, IN FAVOUR OF WORK: no node, no decider, no table, a decider that fails — nothing is
25
+ # printed and 0 is returned: the guard lets the action through. A broken decider has no right to jam
26
+ # the work.
27
+
28
+ # Where the decider lies: next to the hooks in the package source, otherwise in the checks directory
29
+ # the tree named in its settings — the same way the neighbouring helpers find a program of the tree.
30
+ rt_decide_cmd() {
31
+ # A path named by the caller wins: a suite that copies hooks apart from the package names it.
32
+ if [ -n "${RT_DECIDE_CMD:-}" ] && [ -f "$RT_DECIDE_CMD" ]; then
33
+ printf '%s' "$RT_DECIDE_CMD"
34
+ return 0
35
+ fi
36
+ _here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37
+ if [ -f "$_here/../checks/decide.mjs" ]; then
38
+ printf '%s/../checks/decide.mjs' "$_here"
39
+ return 0
40
+ fi
41
+ _root="${CLAUDE_PROJECT_DIR:-$PWD}"
42
+ _checks="$(jq -r '.layout.checks // "tools"' "$_root/.claude/rt-kit.json" 2>/dev/null)"
43
+ [ -n "$_checks" ] && [ "$_checks" != null ] || _checks=tools
44
+ printf '%s/%s/decide.mjs' "$_root" "$_checks"
45
+ }
46
+
47
+ rt_decide() {
48
+ _hook="$1"
49
+ _action="$2"
50
+ _facts="${3:-"{}"}"
51
+ _params="${4:-"{}"}"
52
+ _event="${5:-PreToolUse}"
53
+ _input="${6:-null}"
54
+ # The guard note names the hook that asked, when the hook named nobody itself.
55
+ RT_GUARD_NAME="${RT_GUARD_NAME:-${_hook%.sh}}"
56
+
57
+ command -v node >/dev/null 2>&1 || return 0
58
+ _cmd="$(rt_decide_cmd)"
59
+ [ -f "$_cmd" ] || return 0
60
+
61
+ [ "$_input" != null ] || _input="${RT_HOOK_INPUT:-null}"
62
+ printf '%s' "$_input" | jq -e . >/dev/null 2>&1 || _input=null
63
+
64
+ # The slots every hook's text may hold, the neighbours' included: the branch and the tasks
65
+ # directory. The caller's own params win.
66
+ _dir="$(printf '%s' "$_input" | jq -r '.cwd // empty' 2>/dev/null)"
67
+ [ -d "$_dir" ] || _dir="${CLAUDE_PROJECT_DIR:-.}"
68
+ # shellcheck disable=SC1091
69
+ command -v rt_fact_branch >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
70
+ _shared="$(jq -cn --arg b "$(rt_fact_branch "$_dir" 2>/dev/null)" --arg t "${RT_TASKS_DIR:-docs/tasks}" '{branch:$b, tasks_dir:$t}')"
71
+ _params="$(jq -cn --argjson s "$_shared" --argjson p "$_params" '$s + $p' 2>/dev/null || printf '%s' "$_params")"
72
+
73
+ # A refusal past the window threshold names the numbers of the window, and it stands first in the
74
+ # refusals of the neighbours too: the numbers are filled here for whichever hook asks.
75
+ if [ "$(printf '%s' "$_facts" | jq -r '.window_over_stop // empty' 2>/dev/null)" = yes ]; then
76
+ # shellcheck disable=SC1091
77
+ command -v rt_fact_window_params >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
78
+ _wp="$(rt_fact_window_params "$(printf '%s' "$_input" | jq -r '.transcript_path // empty' 2>/dev/null)")"
79
+ [ -n "$_wp" ] && _params="$(jq -cn --argjson w "$_wp" --argjson p "$_params" '$w + $p' 2>/dev/null || printf '%s' "$_params")"
80
+ fi
81
+
82
+ # «?<action>» asks the decider to take the class of the call and names the hook's own action for
83
+ # a call no class fits.
84
+ _fallback=''
85
+ case "$_action" in "?"*) _fallback="${_action#\?}"; _action='' ;; esac
86
+ _base=''
87
+ case "$_action" in *">"*) _base="${_action#*>}"; _action="${_action%%>*}" ;; esac
88
+ _query="$(jq -cn --arg h "$_hook" --arg a "$_action" --arg fb "$_fallback" --arg bs "$_base" --argjson f "$_facts" --argjson p "$_params" --argjson i "$_input" \
89
+ '{hook:$h, action:$a, facts:$f, params:$p} + (if $i == null then {} else {input:$i} end) + (if $fb == "" then {} else {fallback:$fb} end) + (if $bs == "" then {} else {base:$bs} end)' 2>/dev/null)" || return 0
90
+ _answer="$(node "$_cmd" "$_query" 2>/dev/null)"
91
+ [ -n "$_answer" ] || return 0
92
+
93
+ _decision="$(printf '%s' "$_answer" | jq -r '.decision // empty' 2>/dev/null)"
94
+ _text="$(printf '%s' "$_answer" | jq -r '.text // empty' 2>/dev/null)"
95
+ [ -n "$_decision" ] || return 0
96
+
97
+ # The closing words of a refusal and the record of it come from the shared tail, as before. A
98
+ # row whose text carries its own closing words still gets the record.
99
+ # shellcheck disable=SC1090
100
+ command -v rt_deny_tail >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
101
+ # The param `bypass` names the lawful form of a bypass for the tail; `after` is a word the hook
102
+ # adds below the whole refusal — a neighbour's note that travels inside it.
103
+ _bypass="$(printf '%s' "$_params" | jq -r '.bypass // empty' 2>/dev/null)"
104
+ _after="$(printf '%s' "$_params" | jq -r '.after // empty' 2>/dev/null)"
105
+ if [ "$(printf '%s' "$_answer" | jq -r '.tail // false' 2>/dev/null)" = true ]; then
106
+ command -v rt_deny_tail >/dev/null 2>&1 && _text="$_text
107
+
108
+ $(rt_deny_tail "$_bypass")"
109
+ fi
110
+
111
+ # The record of the decision: every refusal and every question of a guard passes through here,
112
+ # and the event is named by the decision the table took — `guard-deny` or `guard-ask`.
113
+ # shellcheck disable=SC1090
114
+ command -v rt_guard_note >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/guard-note.sh" 2>/dev/null
115
+ command -v rt_guard_note >/dev/null 2>&1 && RT_HOOK_INPUT="${RT_HOOK_INPUT:-$_input}" rt_guard_note "guard-$_decision"
116
+ [ -n "$_after" ] && _text="$_text
117
+
118
+ $_after"
119
+
120
+ # A hook that keeps its own observation of a refusal names it in `RT_DECIDE_NOTE`: the event
121
+ # prefix and its fields. The event is named by the decision the table took.
122
+ if [ -n "${RT_DECIDE_NOTE:-}" ]; then
123
+ # shellcheck disable=SC1090
124
+ command -v rt_note >/dev/null 2>&1 || . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/observe.sh" 2>/dev/null
125
+ # shellcheck disable=SC2086
126
+ command -v rt_note >/dev/null 2>&1 && rt_note "${RT_DECIDE_NOTE%% *}-${_decision}" ${RT_DECIDE_NOTE#* }
127
+ fi
128
+
129
+ if [ "$_event" = git ] || [ "$_event" = stderr ]; then
130
+ # A hook of git itself: the text goes to the error stream, and the non-zero code stops git.
131
+ printf '%s\n' "$_text" >&2
132
+ elif [ "$_event" = Stop ] || [ "$_event" = SubagentStop ]; then
133
+ jq -cn --arg r "$_text" '{decision:"block", reason:$r}'
134
+ else
135
+ jq -cn --arg d "$_decision" --arg r "$_text" --arg e "$_event" \
136
+ '{hookSpecificOutput:{hookEventName:$e, permissionDecision:$d, permissionDecisionReason:$r}}'
137
+ fi
138
+ # Git reads any code but zero as a refusal; 2 is the code the agent's hooks refuse with too.
139
+ [ "$_event" = git ] || [ "$_event" = stderr ] && return 2
140
+ return 1
141
+ }
@@ -19,24 +19,29 @@
19
19
  # that. And it does not replace the refusal reason — that stands before it and names the miss by
20
20
  # name.
21
21
  #
22
- # THE REFUSAL RECORD GOES FROM HERE TOO. The tail is the one place every refusal passes through: the
23
- # tree's rule demands that the two lawful moves be named at every refusal, and a guard that refuses
24
- # past the tail breaks that rule before it loses count. Written inside the guard itself, the record
25
- # stood in five guards out of thirty, and the digest answered by that fifth. A guard declares itself
26
- # by the line `RT_GUARD_NAME=<name>` at its top; one that has not declared writes nothing — that is
27
- # how the rules gate counts its own refusals by itself.
22
+ # THE REFUSAL RECORD IS NOT HERE. Every refusal passes through the decider call, `rt_decide` in
23
+ # `decide.sh`: it knows the decision the table took and writes the record.
28
24
 
29
25
  # The deny tail as a string. The first parameter is the lawful form of bypass, if the refusal has
30
26
  # one; empty means there is no lawful form at all, and this is said outright.
31
27
  #
32
28
  # reason="BLOCKED: <reason>. $(rt_deny_tail 'the line `Docs-skip: <reason>` in the commit body')"
33
29
  # reason="BLOCKED: <reason>. $(rt_deny_tail)"
34
- rt_deny_tail() {
35
- # shellcheck disable=SC1090
36
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/guard-note.sh" ] \
37
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/guard-note.sh" 2>/dev/null
38
- command -v rt_guard_note >/dev/null 2>&1 && rt_guard_note
30
+ # The rule the rules gate still waits for in this session, or nothing. A refusal names a move, and
31
+ # the gate refuses that very move while its rule is not loaded: the executor then walks from one
32
+ # refusal to the next. A guard that names a move the gate judges asks here first and names the
33
+ # loading of the rule instead. The gate's own reading is repeated, not called: the gate is a hook
34
+ # with input of its own, and the record and the rule directory are the whole of its answer.
35
+ # Parameters: the rule name, the session id.
36
+ rt_gate_pending() {
37
+ local rule="$1" sid="${2:-nosession}"
38
+ local loaded="${TMPDIR:-/tmp}/claude-skill-gate/${sid}.loaded"
39
+ [ -f "${CLAUDE_PROJECT_DIR:-.}/${RT_RULES_DIR:-.claude/skills}/${rule}/SKILL.md" ] || return 1
40
+ [ -f "$loaded" ] && grep -qE "^([^:]*:)?${rule}$" "$loaded" 2>/dev/null && return 1
41
+ printf '%s' "$rule"
42
+ }
39
43
 
44
+ rt_deny_tail() {
40
45
  if [ -n "$1" ]; then
41
46
  printf 'Two moves from here: fix what is named and repeat the call, or bring the owner the price of a bypass and wait for their word. The lawful form of bypass: %s. An edit is not laid past the guard in silence: it refuses one call, and a bypassed one lifts the requirement from the whole tree and says nothing about it.' "$1"
42
47
  return 0
@@ -52,10 +52,12 @@ stands="${RT_STANDS:-}"
52
52
  raiser="${RT_STANDS_RAISED_BY:-owner}"
53
53
 
54
54
  # shellcheck disable=SC1090
55
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
56
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
57
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
58
-
55
+ # The decision and the words come from the decision table; the hook names the action it caught,
56
+ # who raises the stands and whether a stand port is taken.
57
+ # shellcheck disable=SC1091
58
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/decide.sh" 2>/dev/null
59
+ # shellcheck disable=SC1091
60
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
59
61
  # A port of the stand list somebody is listening on. Only these are judged under `session`: a port
60
62
  # the tree never named belongs to no stand of it, and a refusal over it would refuse the session's
61
63
  # own work.
@@ -68,21 +70,26 @@ taken_stand_port() {
68
70
  return 1
69
71
  }
70
72
 
71
- deny() {
72
- local port
73
+ refuse() {
74
+ local port="" facts load="" sid
75
+ command -v rt_decide >/dev/null 2>&1 || exit 0
76
+ sid="$(printf '%s' "$input" | jq -r '.session_id // "nosession"' 2>/dev/null)"
73
77
  if [ "$raiser" = "session" ]; then
74
78
  # Nobody raises the stands here but the session: a free port is its own business, and only
75
79
  # a taken one is worth a refusal.
76
80
  port="$(taken_stand_port)" || exit 0
77
- echo "$1 On port ${port} somebody is already listening — a second instance answers with a build of its own and leads the investigation astray. Ask what it is: lsof -nP -iTCP:${port} -sTCP:LISTEN. $(rt_deny_tail)" >&2
78
- exit 2
79
- fi
80
- if [ -n "$stands" ]; then
81
- echo "$1 The applications are already raised by the owner: ${stands} — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
81
+ facts='{"stands_raised_by":"session","stand_port_taken":"yes"}'
82
82
  else
83
- echo "$1 The applications are already raised by the owner — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
83
+ # The named move is a check of a raised stand, and the rules gate refuses it while the rule
84
+ # of the browser check is not loaded.
85
+ facts="$(jq -cn --arg r "$(rt_fact_rule_loaded browser-verification "$sid")" '{stands_raised_by:"owner", rule_loaded:$r}')"
86
+ [ "$(rt_fact_rule_loaded browser-verification "$sid")" = yes ] \
87
+ || load="Load the rule «browser-verification» by the tool Skill first — the rules gate refuses a check of a stand until then. "
84
88
  fi
85
- exit 2
89
+ rt_decide dev-server-guard.sh "$1" "$facts" \
90
+ "$(jq -cn --arg s "$2" --arg p "$port" --arg l "$load" --arg st "${stands:+: $stands}" '{said:$s, port:$p, load:$l, stands:$st}')" \
91
+ stderr "$input"
92
+ exit $?
86
93
  }
87
94
  case "$tool" in
88
95
  Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
@@ -98,14 +105,14 @@ case "$tool" in
98
105
  file="$(printf '%s' "$input" | jq -r '.tool_input.filePath // empty' 2>/dev/null)"
99
106
  case "$file" in
100
107
  */package.json|package.json)
101
- deny "A launch of a script straight from the manifest: the guard sees only the file and the line, not the script itself, so it cannot tell raising a server from a build. If a build or a test is needed, run them by a command in the terminal." ;;
108
+ refuse run_manifest_script "A launch of a script straight from the manifest: the guard sees only the file and the line, not the script itself, so it cannot tell raising a server from a build. If a build or a test is needed, run them by a command in the terminal." ;;
102
109
  esac
103
110
  exit 0
104
111
  fi
105
112
  # The word "start" without a boundary also caught "restart", which raises no server.
106
113
  case "$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" in
107
114
  *serve*|*dev*|start*|*\ start*|*:start*)
108
- deny "The configuration «${name}» looks like raising a development server. If the configuration does something else, run it by a command: by the name alone the guard does not see the content." ;;
115
+ refuse run_config_serve "The configuration «${name}» looks like raising a development server. If the configuration does something else, run it by a command: by the name alone the guard does not see the content." ;;
109
116
  esac
110
117
  exit 0 ;;
111
118
  *) exit 0 ;;
@@ -142,24 +149,24 @@ RUNNER='((npx|pnpm|yarn|bun|npm)([[:space:]]+(exec|run|dlx))?[[:space:]]+)?'
142
149
  BOUND="$RT_CMD_BOUND"
143
150
 
144
151
  printf '%s' "$cmd" | grep -qE "${BOUND}${RUNNER}(nx|ng)[[:space:]]+(run[[:space:]]+[^[:space:]]*:)?(serve|dev)" \
145
- && deny "A launch of one more development server through the framework."
152
+ && refuse raise_dev_server "A launch of one more development server through the framework."
146
153
 
147
154
  # Requiring a space right after the name broke the match on a colon: the guard let through scripts
148
155
  # like "serve:site" — that is, exactly the commands it is written for.
149
156
  printf '%s' "$cmd" | grep -qE "${BOUND}(npm|pnpm|yarn|bun)([[:space:]]+run)?[[:space:]]+(dev|start|serve)([:._-][A-Za-z0-9:._-]*)?([[:space:]]|\$)" \
150
- && deny "A launch of one more development server through the package runner."
157
+ && refuse raise_dev_server "A launch of one more development server through the package runner."
151
158
 
152
159
  # The subcommand is mandatory: while it was optional, the bare name of the bundler fell under the
153
160
  # rule — that is, any one-liner where it occurs inside the text.
154
161
  printf '%s' "$cmd" | grep -qE "${BOUND}${RUNNER}vite([[:space:]]+(dev|serve|preview))?[[:space:]]*(\$|[;&|\"'])" \
155
- && deny "A launch of one more development server."
162
+ && refuse raise_dev_server "A launch of one more development server."
156
163
  printf '%s' "$cmd" | grep -qE "${BOUND}${RUNNER}(next|astro|nuxt)[[:space:]]+(dev|start|preview)([[:space:]]|\$)" \
157
- && deny "A launch of one more development server."
164
+ && refuse raise_dev_server "A launch of one more development server."
158
165
 
159
166
  # Static files served over a build are the same second instance. Every name sits under the shared
160
167
  # anchor of the command start: without it a package listing and a search through documents read as
161
168
  # a start.
162
169
  printf '%s' "$cmd" | grep -qE "${BOUND}(python3?[[:space:]]+-m[[:space:]]+http\.server|${RUNNER}(http-server|live-server|serve)([[:space:]]|\$))" \
163
- && deny "Raising a static server on top of a build — the same second instance."
170
+ && refuse raise_static "Raising a static server on top of a build — the same second instance."
164
171
 
165
172
  exit 0
@@ -46,14 +46,47 @@ if [ -n "$assignments" ]; then
46
46
  fi
47
47
  export RT_HOOK_INPUT="$input"
48
48
 
49
+ collected=""
50
+
51
+ # The journal of the turn exit: a Stop branch that failed or ran past its limit writes «движок упал»
52
+ # here, and the next turn starts with that line, so a released turn is never released in silence.
53
+ journal_file=""
54
+ journal_common="$(git -C "${RT_HOOK_CWD:-${CLAUDE_PROJECT_DIR:-.}}" rev-parse --git-common-dir 2>/dev/null)"
55
+ case "$journal_common" in
56
+ '') ;;
57
+ /*) journal_file="$journal_common/rt-kit/turn-exit.log" ;;
58
+ *) journal_file="${RT_HOOK_CWD:-${CLAUDE_PROJECT_DIR:-.}}/$journal_common/rt-kit/turn-exit.log" ;;
59
+ esac
60
+ rt_dispatch_journal() {
61
+ [ -n "$journal_file" ] || return 0
62
+ mkdir -p "$(dirname "$journal_file")" 2>/dev/null || return 0
63
+ printf '%s\t%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" >> "$journal_file" 2>/dev/null
64
+ }
65
+ if [ "$event" = UserPromptSubmit ] && [ -s "$journal_file" ]; then
66
+ read_mark="${journal_file%.log}.read"
67
+ seen="$(cat "$read_mark" 2>/dev/null || echo 0)"
68
+ total="$(wc -l < "$journal_file" | tr -d ' ')"
69
+ if [ "$total" -gt "$seen" ] 2>/dev/null; then
70
+ fresh="$(tail -n "$((total - seen))" "$journal_file" | grep 'движок упал' | cut -f2- | tail -3)"
71
+ printf '%s\n' "$total" > "$read_mark" 2>/dev/null
72
+ if [ -n "$fresh" ]; then
73
+ notice="The previous turn was released by a failure of the exit check, not by the scenario: ${fresh}. Measure the branch first — node tools/task-flow-script.mjs measure."
74
+ answers="${answers:-}$(jq -cn --arg c "$notice" '{hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:$c}}' | jq -Rsc . 2>/dev/null)
75
+ "
76
+ collected="${collected}$(jq -cn --arg c "$notice" '{hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:$c}}')
77
+ "
78
+ count=$((${count:-0} + 1))
79
+ fi
80
+ fi
81
+ fi
49
82
  branches="$(grep -l '^# rt-hook:' "$here"/*.sh 2>/dev/null | sort)"
50
- [ -z "$branches" ] && exit 0
83
+ [ -z "$branches" ] && [ -z "$collected" ] && exit 0
51
84
 
52
85
  # A file happens to have several declarations: a guard standing both on a tool call and on the end
53
86
  # of a turn names both events by lines of its own. Before, only the first was read — and the second
54
87
  # branch was never called, silently: from the outside that is indistinguishable from a guard that
55
88
  # looked and let through.
56
- collected=""
89
+
57
90
  for branch in $branches; do
58
91
  matched=0
59
92
  while IFS= read -r declaration; do
@@ -94,17 +127,27 @@ EOF
94
127
  # is noise and does not go out, and on a refusal it is the reason itself. A guard that prints
95
128
  # its refusal there reached the executor as a line about a broken file — with the file whole and
96
129
  # the text plain, which nobody saw. In one session two refusals in a row were lost that way.
130
+ # A branch names its own limit by `# rt-hook-timeout: <seconds>`; past it the branch is stopped.
131
+ limit="$(sed -n 's/^# rt-hook-timeout:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$branch" 2>/dev/null | head -1)"
132
+ run=(bash "$branch")
133
+ [ -n "$limit" ] && command -v perl >/dev/null 2>&1 && run=(perl -e 'alarm shift; exec @ARGV' "$limit" bash "$branch")
97
134
  branch_err="$(mktemp 2>/dev/null)"
98
135
  if [ -n "$branch_err" ]; then
99
- branch_out="$(printf '%s' "$input" | bash "$branch" 2>"$branch_err")"
136
+ branch_out="$(printf '%s' "$input" | "${run[@]}" 2>"$branch_err")"
100
137
  code=$?
101
138
  said_err="$(cat "$branch_err" 2>/dev/null)"
102
139
  rm -f "$branch_err" 2>/dev/null
103
140
  else
104
- branch_out="$(printf '%s' "$input" | bash "$branch" 2>/dev/null)"
141
+ branch_out="$(printf '%s' "$input" | "${run[@]}" 2>/dev/null)"
105
142
  code=$?
106
143
  said_err=""
107
144
  fi
145
+ # On Stop a branch that failed or ran past its limit releases the turn and says so in the journal:
146
+ # a stop the engine did not decide is written, never taken for a verdict.
147
+ if [ "$code" -ne 0 ] && [ "$event" = Stop ]; then
148
+ rt_dispatch_journal "движок упал: $(basename "$branch") exited $code"
149
+ continue
150
+ fi
108
151
  if [ "$code" -ne 0 ]; then
109
152
  if [ -n "$branch_out" ]; then
110
153
  refusal="$branch_out"