@rt-tools/agent-kit 0.28.0 → 0.29.1

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 (81) hide show
  1. package/assets/checks/board-epic-link.github.mjs +13 -1
  2. package/assets/checks/board-epic-plan.github.mjs +128 -9
  3. package/assets/checks/board-epics.github.mjs +6 -10
  4. package/assets/checks/board-folders.mjs +50 -0
  5. package/assets/checks/board-runs.github.mjs +102 -2
  6. package/assets/checks/check-board.github.mjs +63 -3
  7. package/assets/checks/check-lib-layers.mjs +4 -2
  8. package/assets/checks/check-spec-coverage.mjs +65 -0
  9. package/assets/checks/check-work-steps.mjs +238 -0
  10. package/assets/checks/epic-table.github.mjs +15 -6
  11. package/assets/checks/lib-common.mjs +9 -4
  12. package/assets/checks/lib-domains.mjs +7 -4
  13. package/assets/checks/main-run.github.mjs +69 -0
  14. package/assets/checks/rt-kit-checks.config.mjs +16 -1
  15. package/assets/checks/task-new.github.mjs +6 -6
  16. package/assets/checks/tree-assignment.mjs +169 -0
  17. package/assets/defaults/project.sh +15 -1
  18. package/assets/hooks/end-conversation-guard.sh +59 -0
  19. package/assets/hooks/epic-over.sh +11 -2
  20. package/assets/hooks/git-guard-delivery-epic.sh +15 -1
  21. package/assets/hooks/git-guard-delivery.sh +4 -2
  22. package/assets/hooks/git-guard-push-tests.sh +31 -8
  23. package/assets/hooks/git-guard-tree-assignment.sh +77 -0
  24. package/assets/hooks/grill-gate.sh +63 -2
  25. package/assets/hooks/hook-input.sh +8 -1
  26. package/assets/hooks/main-run-context.sh +45 -0
  27. package/assets/hooks/prose-style-guard.sh +49 -3
  28. package/assets/hooks/tree-assignment-guard.sh +101 -0
  29. package/assets/hooks/turn-exit-epic.sh +149 -0
  30. package/assets/hooks/turn-exit-guard.sh +40 -24
  31. package/assets/hooks/turn-exit-patterns.sh +50 -8
  32. package/assets/hooks/turn-exit-verdict.sh +39 -8
  33. package/assets/hooks/waiting-turn-guard.sh +56 -1
  34. package/assets/hooks/write-targets.sh +23 -1
  35. package/assets/laws/delivery.md +6 -0
  36. package/assets/laws/work-conduct.md +26 -0
  37. package/assets/patterns/doc-style-human.md +6 -0
  38. package/assets/patterns/git-workflow-merge.md +14 -0
  39. package/assets/patterns/git-workflow-pr-body.github.md +161 -0
  40. package/assets/patterns/git-workflow-pr.github.md +6 -104
  41. package/assets/patterns/git-workflow-stack.md +19 -2
  42. package/assets/patterns/spec-driven-domain.md +4 -0
  43. package/assets/patterns/status-report-table.github.md +6 -0
  44. package/assets/patterns/task-flow-close.md +1 -1
  45. package/assets/patterns/task-flow-resume.md +8 -0
  46. package/assets/patterns/task-flow-start.md +26 -22
  47. package/assets/patterns/testing-e2e.md +14 -0
  48. package/assets/pitfalls/git-workflow.github.md +6 -0
  49. package/assets/pitfalls/turn-conduct.md +46 -0
  50. package/assets/rules/doc-style.md +3 -2
  51. package/assets/rules/git-workflow.github.md +37 -38
  52. package/assets/rules/observability.needs-app.md +5 -0
  53. package/assets/rules/reuse-first.md +33 -11
  54. package/assets/rules/task-flow.md +57 -56
  55. package/assets/rules/testing.md +15 -0
  56. package/assets/rules/turn-conduct.md +70 -73
  57. package/assets/rules/typescript-conventions.md +8 -0
  58. package/assets/samples/tasks/_template/plan.md +7 -1
  59. package/assets/samples/tasks/_template/progress.md +14 -1
  60. package/bin/agent-kit.d.ts.map +1 -1
  61. package/bin/agent-kit.js +2 -1
  62. package/bin/agent-kit.js.map +1 -1
  63. package/lib/cargo.d.ts +49 -1
  64. package/lib/cargo.d.ts.map +1 -1
  65. package/lib/cargo.js +9 -2
  66. package/lib/cargo.js.map +1 -1
  67. package/lib/observations-cargo.d.ts +32 -0
  68. package/lib/observations-cargo.d.ts.map +1 -0
  69. package/lib/observations-cargo.js +105 -0
  70. package/lib/observations-cargo.js.map +1 -0
  71. package/lib/shipment.d.ts +8 -20
  72. package/lib/shipment.d.ts.map +1 -1
  73. package/lib/shipment.js +22 -39
  74. package/lib/shipment.js.map +1 -1
  75. package/lib/tree-mark.d.ts +17 -0
  76. package/lib/tree-mark.d.ts.map +1 -0
  77. package/lib/tree-mark.js +41 -0
  78. package/lib/tree-mark.js.map +1 -0
  79. package/package.json +1 -1
  80. package/rt-tools-agent-kit-0.29.1.tgz +0 -0
  81. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
@@ -101,13 +101,26 @@ rt_push_checks_default() {
101
101
 
102
102
  for check in check-doc-paths check-specs check-file-size check-dupes check-styles \
103
103
  check-glossary check-lib-layers check-reuse check-schema-drift check-states check-state-next \
104
- check-turn-map check-archive-age check-profile-drift check-hook-scope check-push-gate; do
104
+ check-turn-map check-work-steps check-spec-coverage check-archive-age check-profile-drift \
105
+ check-hook-scope check-push-gate; do
105
106
  [ -f "$root/$RT_CHECKS_DIR/$check.mjs" ] && printf '%s\n' "node $RT_CHECKS_DIR/$check.mjs"
106
107
  done
107
108
 
108
109
  return 0
109
110
  }
110
111
 
112
+ # Is a check of the gate set heavy: success — it builds, raises or shoots, and costs minutes. After
113
+ # the first red check the gate still runs the light ones, so that one refusal names every red among
114
+ # them; a heavy one is not started then — its minutes buy nothing while the push is refused anyway.
115
+ # Before, the gate left on the first red, and every fix opened the next reason by a push of its own.
116
+ rt_push_check_heavy_default() {
117
+ case "$1" in
118
+ *' nx '* | *'nx affected'* | *'nx run'* | *'docker '* | *playwright* | *e2e*) return 0 ;;
119
+ esac
120
+
121
+ return 1
122
+ }
123
+
111
124
  # Which document must travel by the same commit as this file. Prints a path pattern or stays silent.
112
125
  rt_docs_pair_for_default() {
113
126
  case "$1" in
@@ -456,6 +469,7 @@ rt_qa_decorative_default() {
456
469
  # Defaults under the shared names. The project override will declare any of them anew — and call the
457
470
  # same name from here with the `_default` suffix for everything it did not name itself.
458
471
  rt_push_checks() { rt_push_checks_default "$@"; }
472
+ rt_push_check_heavy() { rt_push_check_heavy_default "$@"; }
459
473
  rt_push_docs_only() { rt_push_docs_only_default "$@"; }
460
474
 
461
475
  rt_docs_pair_for() { rt_docs_pair_for_default "$@"; }
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PreToolUse .*EndConversation.*
3
+ # Requires: hooks/deny-tail.sh
4
+ # The guard of the end of the conversation: the executor does not end the session. PreToolUse on
5
+ # the tool that closes the conversation — refused always.
6
+ #
7
+ # Why. The session is ended by the owner and by nobody else. On 17 September 2026 the executor
8
+ # closed the session by that tool with the work open and tasks assigned, and the owner named it
9
+ # unlawful. A ban in the settings of one machine holds one machine; this guard travels with the
10
+ # package. There is no lawful form of bypass: no state of the work, no word in the turn and no
11
+ # insult from the owner cancels it — a session that must close is closed by the owner.
12
+ #
13
+ # The name of the tool is read by jq, and without jq by grep over the raw input: a missing parser
14
+ # must not turn into silence here. A tool name with a vendor prefix is matched by its tail.
15
+ #
16
+ # FAIL-OPEN only where there is nothing to judge: an empty input or a name that is not the closing
17
+ # tool passes. A readable call of the closing tool is refused with or without a JSON parser.
18
+
19
+ # Its own name in the observations: the refusal is recorded by the shared deny tail.
20
+ RT_GUARD_NAME=end-conversation-guard
21
+
22
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
23
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
24
+
25
+ if command -v rt_hook_read >/dev/null 2>&1; then
26
+ rt_hook_read
27
+ input="$RT_HOOK_INPUT"
28
+ else
29
+ input="$(cat)"
30
+ fi
31
+
32
+ tool="$(printf '%s' "$input" | jq -r '.tool_name // ""' 2>/dev/null)"
33
+ if [ -z "$tool" ] && printf '%s' "$input" | grep -q '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*EndConversation'; then
34
+ tool=EndConversation
35
+ fi
36
+
37
+ # Called by the dispatcher for the closing tool alone; a foreign name still passes, so a direct
38
+ # call with another tool costs nothing.
39
+ case "$tool" in
40
+ *EndConversation*) ;;
41
+ *) exit 0 ;;
42
+ esac
43
+
44
+ # shellcheck disable=SC1090
45
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
46
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
47
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
48
+
49
+ reason="BLOCKED by end-conversation-guard: the executor does not end the conversation. The session is ended by the owner and by nobody else.
50
+
51
+ An assignment stands until the owner cancels it, and an insult cancels nothing: do what was assigned, and where the work stands on the owner's word, wait for the word. A session that must close is closed by the owner — say so in words and go on working. There is no lawful form of bypass for this refusal."
52
+ tail_text="$(rt_deny_tail "")"
53
+ [ -n "$tail_text" ] && reason="${reason}
54
+
55
+ ${tail_text}"
56
+
57
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
58
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"BLOCKED by end-conversation-guard: the session is ended by the owner and by nobody else."}}\n'
59
+ exit 0
@@ -16,7 +16,10 @@
16
16
  # work, no epic behind the branch, no way to ask the hosting — is not zero, and the caller works as
17
17
  # it did before this reading existed.
18
18
 
19
- rt_epic_over() {
19
+ # The unfinished tasks of the epic as the table prints them. A non-zero code means the epic could
20
+ # not be read — no table, no epic behind the branch, no way to ask the hosting — and the caller
21
+ # tells that apart from an empty answer, which means the epic is over.
22
+ rt_epic_unfinished() {
20
23
  command -v jq >/dev/null 2>&1 || return 1
21
24
  command -v node >/dev/null 2>&1 || return 1
22
25
 
@@ -43,7 +46,13 @@ rt_epic_over() {
43
46
  [ -f "$table" ] || return 1
44
47
 
45
48
  left="$(cd "$root" && node "$table" --unfinished 2>/dev/null)" || return 1
46
- [ -n "$left" ] && return 1
49
+ printf '%s' "$left"
50
+ return 0
51
+ }
47
52
 
53
+ rt_epic_over() {
54
+ local left
55
+ left="$(rt_epic_unfinished)" || return 1
56
+ [ -n "$left" ] && return 1
48
57
  return 0
49
58
  }
@@ -10,6 +10,13 @@
10
10
  #
11
11
  # WHAT IS HERE. Two calls, both called from the delivery guard, where `fault`, `main_branch` and
12
12
  # the profile calls are already declared. The helper reads neither the input nor the settings.
13
+ #
14
+ # The assignment of an epic to this working copy is read next to this: it judges the same subject
15
+ # one step earlier — whether this copy leads the epic at all — so its helper is sourced here. The
16
+ # guard calls it in the branch block before the base: a fresh base does not cure a branch of
17
+ # someone else's epic, and a refusal about the base would send the executor to fix what is in order.
18
+ # shellcheck disable=SC1090
19
+ [ -f "$rt_hooks_dir/git-guard-tree-assignment.sh" ] && . "$rt_hooks_dir/git-guard-tree-assignment.sh" 2>/dev/null
13
20
 
14
21
  # The branch of an epic by its number: the same form as a task branch — the profile pulls the
15
22
  # number out of a name, and the epic branch is the one whose number is the epic's.
@@ -69,8 +76,15 @@ rt_epic_base() {
69
76
 
70
77
  # The main branch is asked of the epic, not of the base: there it is fixed by one merge, and the
71
78
  # branches of all its tasks get it at once.
79
+ #
80
+ # The base answers for the epic when it already carries the tip. The merge of the main branch
81
+ # reaches the remote copy of the epic branch only through a push, and a push is sometimes
82
+ # refused by a check over code that a task of this epic is meant to fix — the task whose branch
83
+ # is being created right here. Judged by the remote copy alone, the guard closes the only road
84
+ # to that fix and names no other: the epic stands until a person lifts a check by hand.
72
85
  if git rev-parse --verify --quiet "origin/${main_branch}" >/dev/null 2>&1 \
73
- && ! git merge-base --is-ancestor "origin/${main_branch}" "origin/${_epic_branch}" 2>/dev/null; then
86
+ && ! git merge-base --is-ancestor "origin/${main_branch}" "origin/${_epic_branch}" 2>/dev/null \
87
+ && ! git merge-base --is-ancestor "origin/${main_branch}" "$_base_ref" 2>/dev/null; then
74
88
  _behind="$(git rev-list --count "origin/${_epic_branch}..origin/${main_branch}" 2>/dev/null)"
75
89
  fault "the branch of the epic «${_epic_branch}» does not carry the tip of «${main_branch}» — it has moved ahead by ${_behind:-several} commits. The main branch is merged into the branch of the epic, not bypassed by taking the base from the main one: git checkout ${_epic_branch}, git merge origin/${main_branch}, and send the branch."
76
90
  fi
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
- # Requires: hooks/git-guard-delivery-folder.sh, hooks/git-guard-delivery-epic.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
3
+ # Requires: hooks/git-guard-delivery-folder.sh, hooks/git-guard-delivery-epic.sh, hooks/git-guard-tree-assignment.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
4
4
  # Delivery guard. PreToolUse on creating a branch, on the push and on opening a PR.
5
5
  #
6
6
  # The delivery law demands three things nothing usually checks: an edit starts from a task visible
@@ -274,6 +274,7 @@ if [ -n "$branch_arg" ]; then
274
274
  # base fresh — `git checkout -b <branch> origin/<main>` — would be forbidden.
275
275
  base_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]+[^[:space:];&|]+[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\4/p' | head -1)"
276
276
  base_ref="${base_arg:-HEAD}"
277
+ command -v rt_assignment_fault >/dev/null 2>&1 && rt_assignment_fault "$epic_arg" "the branch «${branch_arg}»"
277
278
  if [ -n "$epic_arg" ] && command -v rt_epic_base >/dev/null 2>&1; then
278
279
  rt_epic_base "$epic_arg" "$base_ref" "$branch_arg"
279
280
  elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
@@ -367,7 +368,8 @@ command -v rt_epic_own_pull >/dev/null 2>&1 && rt_epic_own_pull "$state"
367
368
  title=''
368
369
  if command -v perl >/dev/null 2>&1; then
369
370
  title="$(printf '%s' "$cmd" | perl -0ne '
370
- if (/(?:--title|-t)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
371
+ my $v = qr/(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/;
372
+ if (/--title(?:=|\s+)$v/s || /(?<![-\w])-t(?:=|\s+)$v/s) {
371
373
  print defined $1 ? $1 : (defined $2 ? $2 : $3);
372
374
  }
373
375
  ' 2>/dev/null)"
@@ -176,12 +176,24 @@ fi
176
176
  # breakage.
177
177
  rt_skip_code="${RT_SKIP_CODE:-7}"
178
178
 
179
+ # Every red among the light checks is named by one refusal. The gate used to leave on the first red
180
+ # one, and each fix opened the next reason by a push of its own: three pushes in a row went so on one
181
+ # branch — a repeated function, a name shared by two kits, a paint probe. After the first red a
182
+ # heavy check is not started: the push is refused anyway, and its minutes buy nothing.
183
+ command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
184
+
179
185
  failed=""
180
186
  output=""
181
187
  skipped=""
188
+ held=""
182
189
  ran=0
183
190
  while IFS= read -r check; do
184
191
  [ -z "$check" ] && continue
192
+ if [ -n "$failed" ] && rt_push_check_heavy "$check"; then
193
+ held="${held}${held:+
194
+ }${check}"
195
+ continue
196
+ fi
185
197
  ran=$((ran + 1))
186
198
  out="$(eval "$check" 2>&1)"
187
199
  status=$?
@@ -191,9 +203,12 @@ while IFS= read -r check; do
191
203
  }${check}"
192
204
  continue
193
205
  fi
194
- failed="$check"
195
- output="$out"
196
- break
206
+ failed="${failed}${failed:+
207
+ }${check}"
208
+ output="${output}${output:+
209
+
210
+ }── ${check}
211
+ $(printf '%s' "$out" | tail -n 25)"
197
212
  done <<EOF
198
213
  $(rt_push_checks "$base")
199
214
  EOF
@@ -245,19 +260,27 @@ fi
245
260
 
246
261
  rt_push_gate_note red
247
262
 
248
- # The tail of the output, not all of it: the runner prints a long one, and what is needed is the
249
- # reason for the refusal.
250
- tail_out="$(printf '%s' "$output" | tail -n 40 | tr -d '\000')"
263
+ # The tail of every red output, not all of it: the runner prints a long one, and what is needed is
264
+ # the reason for the refusal.
265
+ tail_out="$(printf '%s' "$output" | tr -d '\000')"
266
+ red_count="$(printf '%s\n' "$failed" | grep -c .)"
267
+ held_line=""
268
+ [ -n "$held" ] && held_line="
269
+
270
+ Not started after the red ones — heavy, and the push is refused anyway:
271
+ ${held}"
251
272
  # Red comes in two kinds, and the guard does not tell them apart: it checks only the return code.
252
273
  # When a check of the code fails, "fix it and push again" is right. When the check itself is wrong,
253
274
  # the same text orders fixing code nobody touched: a refusal once taken apart lay wholly in
254
275
  # documents untouched by any commit of the branch. The verifiability law says a broken check does
255
276
  # not stop the work, and until this line there was no such option in the refusal.
256
- reason="BLOCKED: a push without a green local run. «${failed}» failed — fix it and push again, the guard must not be bypassed. A push is the entry into the pipeline, and red from here is checked already in production.
277
+ reason="BLOCKED: a push without a green local run. Red checks: ${red_count} — fix them and push again, the guard must not be bypassed. A push is the entry into the pipeline, and red from here is checked already in production.
278
+
279
+ ${failed}${held_line}
257
280
 
258
281
  Three moves from here: fix what is named and repeat the call; fix the check itself, if it is the one that is wrong — take the refusals apart one by one, show the analysis to the owner and correct the check; or bring the owner the price of a bypass and wait for their word. What is in dispute is not added to the known list: it holds what was accepted, not the results of a broken check.
259
282
 
260
- The tail of the output:
283
+ The tail of every red output:
261
284
 
262
285
  ${tail_out}"
263
286
 
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env bash
2
+ # The assignment of an epic to this working copy. NOT a guard: it has no `rt-hook:` declaration and
3
+ # hooks into no agent event. The delivery guard sources it, the same way it sources the conditions
4
+ # about the epic of a task.
5
+ #
6
+ # Why at all. A machine holds several working copies of one tree, and the work queue answers only
7
+ # what is open: it holds no owner of a card, and by topic one epic cannot be told from another. A
8
+ # session that took the freshest epic of the list did work nobody had ordered — the whole day of it,
9
+ # up to a written agreement, and it was the owner who stopped that, not a check.
10
+ #
11
+ # WHAT IS HERE. Two calls, made from the delivery guard, where `fault` is already declared. The
12
+ # answer is computed by the tree's command: the table of assignments and the name of this copy are
13
+ # read in one place, by the audit and by the guard alike.
14
+
15
+ # Where the reading command lies. The layout directory of a tree is its own, and the path is taken
16
+ # from the tree settings the same way the neighbouring guards take it.
17
+ rt_assignment_cmd() {
18
+ _checks="$(jq -r '.layout.checks // "tools"' ".claude/rt-kit.json" 2>/dev/null)"
19
+ [ -n "$_checks" ] && [ "$_checks" != null ] || _checks=tools
20
+ printf '%s/tree-assignment.mjs' "$_checks"
21
+ }
22
+
23
+ # The refusal about the assignment, or silence. Arguments: the number of the epic of the work being
24
+ # taken (empty where the work has no epic) and what exactly is being taken, for the refusal text.
25
+ #
26
+ # The tree that declares no assignments answers with silence: it has nothing to divide, and a
27
+ # requirement invented for it would refuse every branch of a tree with one working copy.
28
+ rt_assignment_fault() {
29
+ _epic="$1"
30
+ _what="$2"
31
+ _said=''
32
+ _reader="$(rt_assignment_cmd)"
33
+
34
+ [ -f "$_reader" ] || return 0
35
+ command -v node >/dev/null 2>&1 || return 0
36
+
37
+ _said="$(node "$_reader" --fault "$_epic" 2>/dev/null)"
38
+ if [ -n "$_said" ]; then
39
+ fault "${_what} is not taken: ${_said}."
40
+ return 0
41
+ fi
42
+
43
+ rt_assignment_stale "$_what"
44
+ }
45
+
46
+ # The assignment that outlived its epic.
47
+ #
48
+ # An assignment goes stale by itself: the epic ends, and the row stays as it was. That is exactly
49
+ # how a session got no order at all — the table named an epic all seven tasks of which had been
50
+ # closed for days, and the session, finding nothing alive there, chose the work by itself.
51
+ #
52
+ # The staleness is not readable from the table: the table says what was given, and only the queue
53
+ # says whether it is still alive. No answer from the queue — no refusal: the call goes to the
54
+ # network, and a tree without one keeps working.
55
+ rt_assignment_stale() {
56
+ _what="$1"
57
+ _assigned=''
58
+ _state=''
59
+ _reader="$(rt_assignment_cmd)"
60
+
61
+ command -v rt_task_state >/dev/null 2>&1 || return 0
62
+ [ -f "$_reader" ] || return 0
63
+
64
+ _assigned="$(node "$_reader" --assigned 2>/dev/null)"
65
+ [ -n "$_assigned" ] || return 0
66
+
67
+ _state="$(rt_task_state "$_assigned" 2>/dev/null)" || return 0
68
+ [ -n "$_state" ] || return 0
69
+
70
+ # The field is read by an explicit comparison: `.open // empty` gives the right side both for
71
+ # a missing field and for `false`, that is, exactly for the state this refusal is written for.
72
+ case "$(printf '%s' "$_state" | jq -r 'if .open == false then "false" else "" end' 2>/dev/null)" in
73
+ false)
74
+ fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order."
75
+ ;;
76
+ esac
77
+ }
@@ -105,6 +105,7 @@ if command -v skill_for >/dev/null 2>&1 && [ -n "$rules_dir" ]; then
105
105
  def is_input:
106
106
  .type == "user"
107
107
  and ((.isCompactSummary // false) | not)
108
+ and ((.isMeta // false) | not)
108
109
  and (((.message.content // []) | if type == "array"
109
110
  then ([.[] | select(.type == "tool_result")] | length)
110
111
  else 0 end) == 0);
@@ -128,6 +129,9 @@ fi
128
129
  # A turn is everything recorded after the last real input from the owner. A tool answer comes in
129
130
  # under the same `user` role, so lines with `tool_result` do not count as input: otherwise the turn
130
131
  # would be the piece after the last tool call, and reading the rules at its start would be lost.
132
+ # The text of a loaded rule and the report of a subagent come in under that role too, marked
133
+ # `isMeta`. Taken for input, a rule loaded right before a question cut the turn after its own
134
+ # loading, and its text stood as the owner's last reply.
131
135
  #
132
136
  # A tail of 400 lines: the turn record grows all session, and only the last turn is judged.
133
137
  # On the tool call event the question is already known — it is the call; only whether the rules
@@ -137,6 +141,7 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re"
137
141
  def is_input:
138
142
  .type == "user"
139
143
  and ((.isCompactSummary // false) | not)
144
+ and ((.isMeta // false) | not)
140
145
  and (((.message.content // []) | if type == "array"
141
146
  then ([.[] | select(.type == "tool_result")] | length)
142
147
  else 0 end) == 0);
@@ -184,11 +189,16 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re"
184
189
  # FAIL-OPEN: no question in the call, no reply from the owner, no earlier question — the sign stays
185
190
  # silent.
186
191
  if [ -n "$tool" ]; then
187
- asked_json="$(printf '%s' "$input" | jq -r '(.tool_input.questions // []) | tostring' 2>/dev/null)"
188
- seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_json" '
192
+ # The words are taken from what the owner reads — the question, the options and their
193
+ # descriptions — and not from the serialised menu: its keys `question`, `label` and
194
+ # `description` stand in every call and matched any English text by two words of the three.
195
+ asked_text="$(printf '%s' "$input" | jq -r '[(.tool_input.questions // [])[]
196
+ | (.question // ""), ((.options // [])[] | (.label // ""), (.description // ""))] | join(" ")' 2>/dev/null)"
197
+ seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_text" '
189
198
  def is_input:
190
199
  .type == "user"
191
200
  and ((.isCompactSummary // false) | not)
201
+ and ((.isMeta // false) | not)
192
202
  and (((.message.content // []) | if type == "array"
193
203
  then ([.[] | select(.type == "tool_result")] | length)
194
204
  else 0 end) == 0);
@@ -232,6 +242,57 @@ ${deny_tail_text}"
232
242
  fi
233
243
  fi
234
244
 
245
+ # The third sign of the same guard: the owner answered the recommended option twice in a row.
246
+ #
247
+ # Every menu carries a recommended option, and an owner who takes it twice running has shown that
248
+ # the decisions are not theirs: the questions are answered by the tree, and the menu only asks them
249
+ # to confirm it. A grill went on to a fifth menu after four such answers, and the owner closed it
250
+ # with the name of a ready-made module that answered all five. From the second answer on, the
251
+ # remaining questions are closed by an assumption written into the grill, and the owner gets the
252
+ # list in one line — not a menu.
253
+ #
254
+ # What is judged is the record of the question tool: the last two of its answers, each with every
255
+ # option taken marked as recommended. Any other answer breaks the streak, and a menu after it goes
256
+ # out as usual. The mark is the word the menu itself carries, in either language of the tree.
257
+ #
258
+ # FAIL-OPEN: fewer than two answers in the record, no record, no parser — the sign stays silent.
259
+ if [ -n "$tool" ]; then
260
+ streak="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
261
+ def answer_texts: [.[] | select(.type == "user") | (.message.content // [])
262
+ | select(type == "array") | .[] | select(.type == "tool_result") | .content
263
+ | if type == "string" then . elif type == "array"
264
+ then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
265
+ | select(test("^The user answered:"))];
266
+ def recommended: ([match("\"=\"[^\"]*\""; "g")] | length) as $all
267
+ | ([match("\\((Recommended|Рекомендую|Рекомендован[^)]*)\\)\"(,|\\.|[[:space:]]|$)"; "g")] | length) as $marked
268
+ | $all > 0 and $all == $marked;
269
+ (answer_texts) as $answers
270
+ | if ($answers | length) < 2 then "no"
271
+ elif ($answers[-1] | recommended) and ($answers[-2] | recommended) then "streak"
272
+ else "no" end
273
+ ' 2>/dev/null)"
274
+
275
+ if [ "$streak" = "streak" ]; then
276
+ reason="BLOCKED by grill-gate: the owner took the recommended option on the last two menus in a row — the remaining questions are closed by assumption, not by a menu.
277
+
278
+ Two answers «recommended» running say the decisions are not the owner's: the tree answers these questions, and the menu only asks them to confirm it. Write what is taken into the grill as decisions, name the list to the owner in one line, and go on with the work. Before that, look for a ready-made module of the same kind — in this tree and in the trees recorded as samples: one grill of five menus was closed by the owner naming such a module.
279
+
280
+ A menu goes out again only for a question no assumption closes, and it says so in its first line."
281
+
282
+ # shellcheck disable=SC1090
283
+ [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
284
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
285
+ deny_tail_text="$(rt_deny_tail "")"
286
+ [ -n "$deny_tail_text" ] && reason="${reason}
287
+
288
+ ${deny_tail_text}"
289
+
290
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
291
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: two recommended answers in a row close the remaining questions by assumption."}}\n'
292
+ exit 0
293
+ fi
294
+ fi
295
+
235
296
  [ "$verdict" = "ask" ] || exit 0
236
297
 
237
298
  if [ -n "$tool" ]; then
@@ -85,9 +85,16 @@ rt_hook_field() {
85
85
  # is how PRs went out opened not by the machine record. A path part does not cross a space, so it
86
86
  # stays inside one word and glues nothing extra to the call.
87
87
  #
88
+ # A runner standing before the call is the same call. `timeout`, `nohup`, `env`, `sudo` and their
89
+ # kin take a command and run it as their own argument: the call is there, and the sign, looking only
90
+ # at the start of the line, did not see it. One push with `timeout` before it went past the whole
91
+ # gate set — the branch left with two red checks, and the pipeline caught them a minute later. The
92
+ # list is closed: any word before the call would count `echo git push` as a push.
93
+ #
88
94
  # This is declared in a SINGLE place, not as a literal in every guard: having diverged, the copies
89
95
  # are fixed one at a time and say nothing about the rest staying blind.
90
- RT_CMD_BOUND='(^|[;&|(]|&&|\|\|)[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=([^[:space:]]*|\$\([^)]*\)|"[^"]*"|'"'"'[^'"'"']*'"'"')[[:space:]]+)*([^[:space:]]*/)?'
96
+ RT_CMD_RUNNER='((timeout|nohup|time|command|nice|stdbuf|sudo|env|caffeinate|setsid|ionice)([[:space:]]+(-[^[:space:]]+|[0-9]+(\.[0-9]+)?[smhd]?|[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*))*[[:space:]]+)*'
97
+ RT_CMD_BOUND='(^|[;&|(]|&&|\|\|)[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=([^[:space:]]*|\$\([^)]*\)|"[^"]*"|'"'"'[^'"'"']*'"'"')[[:space:]]+)*'"$RT_CMD_RUNNER"'([^[:space:]]*/)?'
91
98
 
92
99
  # The fields that all guards ask for.
93
100
  rt_hook_tool() { rt_hook_field RT_HOOK_TOOL '.tool_name'; }
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: SessionStart startup|resume|compact|clear
3
+ # SessionStart: the last run of the main branch goes into the context in one line, at every start.
4
+ #
5
+ # A merge reads as the end of the work, and a red main branch after it lives until the owner
6
+ # notices: a run of the main branch is opened by nobody, so nobody reads its outcome. The line is
7
+ # printed here so that the session starts from it, not from memory of a green PR; after a merge made
8
+ # mid-session the same command is called by hand — the rule `task-flow` names it.
9
+ #
10
+ # The reading itself lies among the checks laid out in the tree — the same reading the work queue
11
+ # audit uses. It goes to the hosting, and that costs a second at every start; the alternative is a
12
+ # day and a half of a red main branch nobody saw.
13
+ #
14
+ # FAIL-OPEN: no `jq`, no `node`, not a git repository, no laid-out reading — we exit silently. The
15
+ # session matters more than the line. What the reading itself could not do it says by its own line:
16
+ # no pipeline file, a pipeline asleep on a push, no network.
17
+
18
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
19
+
20
+ command -v jq >/dev/null 2>&1 || exit 0
21
+ command -v node >/dev/null 2>&1 || exit 0
22
+
23
+ root="$(cd "${CLAUDE_PROJECT_DIR:-.}" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null)"
24
+ [ -z "$root" ] && exit 0
25
+
26
+ # Where the checks of the package lie is named by the tree: the directory differs from tree to tree,
27
+ # and a name written here would be right in the first one and wrong in the second.
28
+ checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
29
+ if [ -z "$checks" ] || [ "$checks" = null ]; then
30
+ checks=tools
31
+ fi
32
+ reading="$root/$checks/main-run.mjs"
33
+ [ -f "$reading" ] || exit 0
34
+
35
+ # A non-zero code is the reading's own verdict — red or pushed out — not a breakage: the line is
36
+ # printed all the same. A reading that printed nothing has broken, and silence is all it gets.
37
+ line="$(cd "$root" && node "$reading" 2>/dev/null)"
38
+ [ -z "$line" ] && exit 0
39
+
40
+ {
41
+ printf 'MAIN BRANCH RUN — read before the first action, and again after every known merge.\n\n'
42
+ printf '%s\n\n' "$line"
43
+ printf 'A red or a pushed-out run is fixed before new work is taken: merges on top go out unchecked.\n'
44
+ printf 'The same line by hand: `node %s/main-run.mjs`. The rule — skill `task-flow`.\n' "$checks"
45
+ } | jq -Rs '{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:.}}' 2>/dev/null || exit 0
@@ -40,6 +40,30 @@ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
40
40
  [ -f "$rt_hooks_dir/write-targets.sh" ] && . "$rt_hooks_dir/write-targets.sh" 2>/dev/null
41
41
  command -v rt_write_targets >/dev/null 2>&1 || rt_write_targets() { cat >/dev/null; }
42
42
 
43
+ # The bodies of the heredocs of a command, one after another. The delimiter is taken as the shell
44
+ # takes it — quoted or bare — and everything up to the closing line is the written text.
45
+ rt_prose_heredoc_bodies() {
46
+ awk -v q="'" '
47
+ inside {
48
+ if ($0 == tag) { inside = 0 } else { print }
49
+ next
50
+ }
51
+ {
52
+ s = $0
53
+ re = "<<-?[ \t]*(\"[^\"]+\"|" q "[^" q "]+" q "|[A-Za-z_][A-Za-z0-9_]*)"
54
+ while (match(s, re)) {
55
+ t = substr(s, RSTART, RLENGTH)
56
+ s = substr(s, RSTART + RLENGTH)
57
+ sub(/^<<-?[ \t]*/, "", t)
58
+ gsub(/\"/, "", t)
59
+ gsub(q, "", t)
60
+ tag = t
61
+ inside = 1
62
+ }
63
+ }
64
+ '
65
+ }
66
+
43
67
  tool="$(rt_hook_tool)"
44
68
  case "$tool" in
45
69
  Edit | Write | MultiEdit)
@@ -52,9 +76,13 @@ case "$tool" in
52
76
  # The first document among the write targets. A command writing several is judged by one of
53
77
  # them: the text is one for the whole command, and a second refusal would repeat the first.
54
78
  path="$(printf '%s' "$cmd" | rt_write_targets | grep -m1 '\.md$')"
55
- # The new text is the body of the command: the written text stands inside it, and the
56
- # findings of the check name the very lines that go into the file.
57
- added="$cmd"
79
+ # The new text is taken from the heredoc bodies of the command, not from the whole call.
80
+ # A rewrite carrying the previous wording inside the call would otherwise be refused by
81
+ # the words of that previous wording, and the refusal repeats at the second attempt. No
82
+ # heredoc in the command — the whole text is judged, as before: a redirect of a printf
83
+ # holds the written text and nothing else.
84
+ added="$(printf '%s' "$cmd" | rt_prose_heredoc_bodies)"
85
+ [ -z "$added" ] && added="$cmd"
58
86
  ;;
59
87
  *) exit 0 ;;
60
88
  esac
@@ -64,6 +92,24 @@ case "$path" in
64
92
  *) exit 0 ;;
65
93
  esac
66
94
 
95
+ # The judgement's boundary is the project root. A scratch document written outside it belongs to no
96
+ # repository, and the wording conventions of this tree are nobody's convention there: a fixture in
97
+ # the system temporary directory was refused over a word in it.
98
+ if [ -n "${CLAUDE_PROJECT_DIR:-}" ]; then
99
+ case "$path" in
100
+ /*)
101
+ rt_root="$(cd "$CLAUDE_PROJECT_DIR" 2>/dev/null && pwd)"
102
+ # A root that cannot be entered is taken as it was declared: the directory may be
103
+ # absent on this machine, and that says nothing about where the document lies.
104
+ [ -n "$rt_root" ] || rt_root="$CLAUDE_PROJECT_DIR"
105
+ case "$path" in
106
+ "$rt_root"/*) ;;
107
+ *) exit 0 ;;
108
+ esac
109
+ ;;
110
+ esac
111
+ fi
112
+
67
113
  # The archive and the task folders are not judged: the archive is not edited at all, and the
68
114
  # progress is written in haste and lives until the merge.
69
115
  case "$path" in