@rt-tools/agent-kit 0.28.0 → 0.29.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 (55) hide show
  1. package/assets/checks/board-epic-link.github.mjs +13 -1
  2. package/assets/checks/board-runs.github.mjs +102 -2
  3. package/assets/checks/check-board.github.mjs +63 -3
  4. package/assets/checks/main-run.github.mjs +69 -0
  5. package/assets/checks/rt-kit-checks.config.mjs +15 -0
  6. package/assets/checks/tree-assignment.mjs +169 -0
  7. package/assets/hooks/end-conversation-guard.sh +59 -0
  8. package/assets/hooks/epic-over.sh +11 -2
  9. package/assets/hooks/git-guard-delivery-epic.sh +7 -0
  10. package/assets/hooks/git-guard-delivery.sh +2 -1
  11. package/assets/hooks/git-guard-tree-assignment.sh +77 -0
  12. package/assets/hooks/hook-input.sh +8 -1
  13. package/assets/hooks/main-run-context.sh +45 -0
  14. package/assets/hooks/tree-assignment-guard.sh +101 -0
  15. package/assets/hooks/turn-exit-epic.sh +110 -0
  16. package/assets/hooks/turn-exit-guard.sh +34 -20
  17. package/assets/hooks/turn-exit-patterns.sh +0 -9
  18. package/assets/hooks/turn-exit-verdict.sh +20 -8
  19. package/assets/laws/delivery.md +6 -0
  20. package/assets/laws/work-conduct.md +4 -0
  21. package/assets/patterns/git-workflow-merge.md +13 -0
  22. package/assets/patterns/git-workflow-pr-body.github.md +156 -0
  23. package/assets/patterns/git-workflow-pr.github.md +6 -104
  24. package/assets/patterns/git-workflow-stack.md +19 -2
  25. package/assets/patterns/task-flow-close.md +1 -1
  26. package/assets/patterns/task-flow-resume.md +8 -0
  27. package/assets/pitfalls/git-workflow.github.md +6 -0
  28. package/assets/pitfalls/turn-conduct.md +18 -0
  29. package/assets/rules/doc-style.md +3 -2
  30. package/assets/rules/git-workflow.github.md +35 -37
  31. package/assets/rules/task-flow.md +33 -33
  32. package/assets/rules/turn-conduct.md +31 -32
  33. package/assets/samples/tasks/_template/progress.md +1 -1
  34. package/bin/agent-kit.d.ts.map +1 -1
  35. package/bin/agent-kit.js +2 -1
  36. package/bin/agent-kit.js.map +1 -1
  37. package/lib/cargo.d.ts +49 -1
  38. package/lib/cargo.d.ts.map +1 -1
  39. package/lib/cargo.js +9 -2
  40. package/lib/cargo.js.map +1 -1
  41. package/lib/observations-cargo.d.ts +20 -0
  42. package/lib/observations-cargo.d.ts.map +1 -0
  43. package/lib/observations-cargo.js +88 -0
  44. package/lib/observations-cargo.js.map +1 -0
  45. package/lib/shipment.d.ts +8 -20
  46. package/lib/shipment.d.ts.map +1 -1
  47. package/lib/shipment.js +22 -39
  48. package/lib/shipment.js.map +1 -1
  49. package/lib/tree-mark.d.ts +17 -0
  50. package/lib/tree-mark.d.ts.map +1 -0
  51. package/lib/tree-mark.js +41 -0
  52. package/lib/tree-mark.js.map +1 -0
  53. package/package.json +1 -1
  54. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
  55. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
@@ -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
+ }
@@ -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
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
+ # Requires: hooks/deny-tail.sh, checks/tree-assignment.mjs
4
+ # Guard of the assignment of an epic to a working copy. PreToolUse on a call that takes new work
5
+ # past the branch: creating a task under an epic and moving a card into the working column.
6
+ #
7
+ # The branch is judged by the delivery guard — there the epic of the task comes from the queue, and
8
+ # the base is judged along with it. But work is taken by three calls, not one, and the other two go
9
+ # past that guard entirely: a task created under someone else's epic and a card moved into work are
10
+ # both work taken, and both were silent.
11
+ #
12
+ # What this cost. A session found the freshest epic of the open list, decided it was its own and
13
+ # worked the whole day on it: a branch, a task folder, a plan, a written agreement — the owner
14
+ # stopped that, not a check, and said plainly they had never given that epic into work.
15
+ #
16
+ # FAIL-OPEN: no `jq`, no `node`, no reading command, an unreadable table — the call is ALLOWED. A
17
+ # guard that jams the work when a file is missing is switched off on the first day, and the price of
18
+ # a miss here is one turn of the owner's attention.
19
+
20
+ # Its own name in the observations: the refusal is written by the shared deny tail, not by the
21
+ # guard itself.
22
+ RT_GUARD_NAME=tree-assignment-guard
23
+
24
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
25
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
26
+
27
+ rt_hook_read
28
+ input="$RT_HOOK_INPUT"
29
+ [ -z "$input" ] && exit 0
30
+
31
+ command -v jq >/dev/null 2>&1 || exit 0
32
+ command -v node >/dev/null 2>&1 || exit 0
33
+
34
+ tool="$(rt_hook_tool)"
35
+ case "$tool" in
36
+ Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
37
+ *) exit 0 ;;
38
+ esac
39
+
40
+ cmd="$(rt_hook_cmd)"
41
+ [ -z "$cmd" ] && exit 0
42
+
43
+ # The universal executor of the environment passes the real command as a nested string: it is the
44
+ # one to judge, not the wrapper.
45
+ if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
46
+ inner="$(printf '%s' "$cmd" | perl -0ne '
47
+ if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
48
+ print defined $1 ? $1 : (defined $2 ? $2 : $3);
49
+ }
50
+ ' 2>/dev/null)"
51
+ [ -n "$inner" ] && cmd="$inner"
52
+ fi
53
+
54
+ root="$(git rev-parse --show-toplevel 2>/dev/null)"
55
+ [ -n "$root" ] || exit 0
56
+ cd "$root" 2>/dev/null || exit 0
57
+
58
+ checks="$(jq -r '.layout.checks // "tools"' ".claude/rt-kit.json" 2>/dev/null)"
59
+ [ -n "$checks" ] && [ "$checks" != null ] || checks=tools
60
+ reader="${checks}/tree-assignment.mjs"
61
+ [ -f "$reader" ] || exit 0
62
+
63
+ # What is judged, and what the epic of the work is taken from. Creating a task names its epic in the
64
+ # call itself; a card moved into work does not name it at all, and for that the table alone answers:
65
+ # a copy with no assignment takes no work whatever epic it belongs to.
66
+ takes_work() {
67
+ printf '%s' "$cmd" | grep -qE '(task:new|task-new\.mjs)' 2>/dev/null && return 0
68
+ printf '%s' "$cmd" \
69
+ | grep -qE '(task:move|board\.mjs[[:space:]]+move)([^|;&]*)in-progress' 2>/dev/null
70
+ }
71
+
72
+ # Creating an epic is not taking work: it is the owner's order written down, and the assignment for
73
+ # it is given after, by the owner, in the table.
74
+ creates_epic() {
75
+ printf '%s' "$cmd" \
76
+ | grep -qE '(task:new|task-new\.mjs)[^|;&]*--epic([[:space:]]|$)' 2>/dev/null
77
+ }
78
+
79
+ takes_work || exit 0
80
+ creates_epic && exit 0
81
+
82
+ epic="$(printf '%s' "$cmd" | sed -nE 's/.*--epic-of[[:space:]]+([0-9]+).*/\1/p' | head -1)"
83
+
84
+ said="$(node "$reader" --fault "$epic" 2>/dev/null)"
85
+ [ -n "$said" ] || exit 0
86
+
87
+ reason="Refused: this call takes work, and ${said}."
88
+
89
+ # shellcheck disable=SC1090
90
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
91
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
92
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
93
+ deny_tail_text="$(rt_deny_tail "")"
94
+ [ -n "$deny_tail_text" ] && reason="${reason}
95
+
96
+ ${deny_tail_text}"
97
+
98
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
99
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"This copy has no assignment: work is not taken by guesswork."}}\n'
100
+
101
+ exit 0
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env bash
2
+ # The tiers of the open epic for the turn-exit guard. NOT a guard: it has no `rt-hook:` declaration
3
+ # and hooks into no agent event. The guard sources it right after the root of the tree is known.
4
+ #
5
+ # Why they live apart. Under an open epic a turn does not end by itself: the owner said it outright
6
+ # — until the epic is closed the executor does not stop on its own. Two ends the guard used to
7
+ # release are stops all the same: a turn that ended with work, and a second pass over the same turn.
8
+ # The work stands where it stood, and the owner sees the executor standing still with the epic open.
9
+ # The reading of the epic and the refusals about it lie here because the guard reached the file
10
+ # length limit.
11
+ #
12
+ # The state of the epic is asked by the same command that prints the table for the owner, and only
13
+ # on the way to a refusal: the call goes to the hosting and costs seconds. It is asked once per turn.
14
+ #
15
+ # FAIL-OPEN: no epic behind the branch, no table, no way to ask the hosting — the epic reads as not
16
+ # open, and the guard works as it did before these tiers existed.
17
+
18
+ # The unfinished tasks of the epic in one line; empty when the epic is over or cannot be read.
19
+ rt_te_epic_left() {
20
+ if [ -z "${rt_te_epic_asked:-}" ]; then
21
+ rt_te_epic_asked=1
22
+ rt_te_epic_left_cache=""
23
+ rt_te_epic_read=""
24
+ # shellcheck disable=SC1090
25
+ if . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/epic-over.sh" 2>/dev/null \
26
+ && command -v rt_epic_unfinished >/dev/null 2>&1; then
27
+ rt_te_epic_raw="$(rt_epic_unfinished 2>/dev/null)" && rt_te_epic_read=1
28
+ rt_te_epic_left_cache="$(printf '%s' "$rt_te_epic_raw" | tr -s '[:space:]' ' ' | sed 's/^ //; s/ $//')"
29
+ fi
30
+ fi
31
+ printf '%s' "$rt_te_epic_left_cache"
32
+ }
33
+
34
+ # The standing word of the owner about a stop, quoted in « » in the line «Waiting for the owner» of
35
+ # the progress. The guard reads their word, not a retelling: a line without a quote releases
36
+ # nothing, and the quote holds until the owner rewrites the line. Expects `$progress` to be set.
37
+ rt_te_owner_word_quoted() {
38
+ [ -n "${progress:-}" ] || return 1
39
+ local waiting
40
+ # The first waiting line of the progress is read, in either language of the heading.
41
+ waiting="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(Waiting for the owner|Ждём владельца|Ждём от владельца):\*\*[[:space:]]*(.*)/\2/p' "$progress" 2>/dev/null | head -1)"
42
+ # Three characters and more inside « » count as a word.
43
+ printf '%s' "$waiting" | grep -q '«[^»]\{3,\}»' 2>/dev/null
44
+ }
45
+
46
+ # The epic is open: at least one of its tasks is left unfinished.
47
+ rt_te_epic_open() {
48
+ [ -n "$(rt_te_epic_left)" ]
49
+ }
50
+
51
+ # The epic is over: the table was read and printed not a single task. At that point the stop is
52
+ # lawful — waiting for the word of the owner is the work itself — and the refusal releases the turn
53
+ # whatever tier reached it. An epic that cannot be read — no table, the main branch, no way to ask
54
+ # the hosting — is not over, and the turn is judged as before. Reads the same cache: one call per turn.
55
+ rt_te_epic_over() {
56
+ rt_te_epic_left >/dev/null
57
+ [ -n "${rt_te_epic_read:-}" ] && [ -z "${rt_te_epic_left_cache:-}" ]
58
+ }
59
+
60
+ # The epic branch: named by the header line of an epic plan in the plans directory of the tree. It
61
+ # has the shape of a task branch and by the rule carries no task folder, so the tier of the taken
62
+ # task would read every turn on it as work taken and not begun. The plan is written by the command
63
+ # that creates the epic and outlives the merge; the directory is named by the settings, `docs/plans`
64
+ # by default. Expects `$root` and `$branch` to be set. FAIL-OPEN: no directory, no plan — not an
65
+ # epic branch.
66
+ rt_te_epic_branch() {
67
+ [ -n "${root:-}" ] && [ -n "${branch:-}" ] || return 1
68
+ local plans
69
+ plans="$(jq -r ".plansDir // empty" "$root/.claude/rt-kit/checks.json" 2>/dev/null)"
70
+ [ -n "$plans" ] || plans="docs/plans"
71
+ [ -d "$root/$plans" ] || return 1
72
+ grep -lE "^\\*\\*[^|]*\`$branch\`" "$root/$plans"/*.md 2>/dev/null | grep -q .
73
+ }
74
+
75
+ # The refusal of a stop under an open epic. The kind names what the turn ended with.
76
+ rt_te_epic_deny() {
77
+ local kind="$1" ended short
78
+ case "$kind" in
79
+ handed-by-hand)
80
+ ended="the turn ended with a handover written by the hand of the executor, and no window guard refused in it"
81
+ short="a handover by hand under an open epic."
82
+ ;;
83
+ *)
84
+ ended="the turn ended with work, and the work stands where it stood"
85
+ short="the turn ended with work under an open epic."
86
+ ;;
87
+ esac
88
+ rt_te_deny "BLOCKED by turn-exit-guard: the epic is open — its unfinished tasks: $(rt_te_epic_left) — and ${ended}.
89
+
90
+ Until the epic is closed the executor does not stop on its own: the owner said so outright. A turn ends in four ways and no others: a question to the owner through the question tool, when the work does not go without the answer; a refusal of a guard as the last action of the turn; the session handover written by the hook on window fill, or the refusal of the window guard; the word of the owner about stopping, said in this turn. The end of the epic is the fifth: not one task of it is left.
91
+
92
+ The next step is written in the progress: ${next_step}
93
+
94
+ Do it in this same turn. The work of this task is done — take the next task of the epic. The owner said to stop — then write so: the guard reads their word, not a retelling.
95
+
96
+ While the epic is open the guard judges every pass over the turn, not the first one alone." "$short"
97
+ }
98
+
99
+ # A question to the owner at the head of an empty turn in a running stage.
100
+ rt_te_question_without_work_deny() {
101
+ rt_te_deny "BLOCKED by turn-exit-guard: the work stands in the state 'этап-идёт', and the turn asked the owner without doing a single piece of the stage — neither an edit nor a command changing the tree.
102
+
103
+ Waiting for one part of a stage is never a stop of the stage: the parts that do not depend on the answer are done in the same turn, and the question goes after them. A question at the head of an empty turn is a stop with a question attached.
104
+
105
+ The next step is written in the progress: ${next_step}
106
+
107
+ Do what does not depend on the answer in this same turn, then ask by the tool.
108
+
109
+ The guard judges one turn: the next session is not refused." "a question without work in a running stage."
110
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: Stop
3
- # Requires: hooks/deny-tail.sh, hooks/epic-over.sh, hooks/turn-exit-patterns.sh
3
+ # Requires: hooks/deny-tail.sh, hooks/epic-over.sh, hooks/turn-exit-patterns.sh, hooks/turn-exit-epic.sh
4
4
  # Turn exit guard: a turn in which nothing was done on the work does not end until the work is
5
5
  # handed over. Stop.
6
6
  #
@@ -25,6 +25,9 @@
25
25
  # 5. The session handover is written — the window has run out.
26
26
  # 6. The owner said to stop.
27
27
  #
28
+ # Under an open epic the second and the fifth do not release, and a second pass is judged again:
29
+ # until the epic is closed the executor does not stop on its own. The tiers lie in `turn-exit-epic.sh`.
30
+ #
28
31
  # Work without a branch and without a task folder is judged by the second sign. It has no state,
29
32
  # and there is nowhere to take the first sign from — but a turn without a single edit of the tree
30
33
  # does not end here either: the owner's request "lay it out", "update it", "take a look" lives
@@ -48,6 +51,8 @@ rt_hook_read
48
51
  # fallback line in case there is no parser. These twelve lines used to stand as eight copies — the
49
52
  # file grew faster on every new tier than on the requirement itself.
50
53
  rt_te_deny() {
54
+ # The end of an epic releases the turn whatever tier came here: the epic is read only on this road.
55
+ command -v rt_te_epic_over >/dev/null 2>&1 && rt_te_epic_over && exit 0
51
56
  rt_te_reason="$1"
52
57
  rt_te_short="$2"
53
58
  # shellcheck disable=SC1090
@@ -68,9 +73,7 @@ input="$RT_HOOK_INPUT"
68
73
  [ -z "$input" ] && exit 0
69
74
  command -v jq >/dev/null 2>&1 || exit 0
70
75
 
71
- # A second pass over the same turn is not judged: the guard has said its piece once and lets go.
72
76
  active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
73
- [ "$active" = "true" ] && exit 0
74
77
 
75
78
  transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
76
79
  [ -z "$transcript" ] && exit 0
@@ -84,6 +87,12 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
84
87
  root="$(git rev-parse --show-toplevel 2>/dev/null)"
85
88
  [ -z "$root" ] && exit 0
86
89
 
90
+ # The tiers of the open epic lie in a neighbouring file. A second pass over the same turn is judged
91
+ # only under an open epic: outside it the guard has said its piece once and lets go.
92
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-epic.sh" 2>/dev/null || exit 0
93
+ command -v rt_te_epic_open >/dev/null 2>&1 || exit 0
94
+ [ "$active" = "true" ] && ! rt_te_epic_open && exit 0
95
+
87
96
  # The branch, the task folder and the state line are taken while they are there. Empty — the turn
88
97
  # is judged by the second sign, not released: this is where it used to leave with zero, and work by
89
98
  # the owner's word ended with an announcement of intent, silently.
@@ -101,6 +110,7 @@ fi
101
110
  case "$state" in
102
111
  работа-отдана | влито) exit 0 ;;
103
112
  esac
113
+ rt_te_owner_word_quoted && exit 0 # the owner's standing word quoted in the waiting line
104
114
 
105
115
  # A written plan is never the end of a turn at all. The mandatory action of this state is to do the
106
116
  # first stage, and whoever starts it moves the state by the same edit: a turn left in the previous
@@ -171,20 +181,15 @@ rt_te_verdict
171
181
 
172
182
  [ -z "$verdict" ] && exit 0
173
183
 
174
- worked="$(printf '%s' "$verdict" | jq -r '.worked // false' 2>/dev/null)"
175
- waited="$(printf '%s' "$verdict" | jq -r '.waited // false' 2>/dev/null)"
176
- handed_over="$(printf '%s' "$verdict" | jq -r '.handed_over // false' 2>/dev/null)"
177
- started_next="$(printf '%s' "$verdict" | jq -r '.started_next // false' 2>/dev/null)"
178
- ended_working="$(printf '%s' "$verdict" | jq -r '.ended_working // false' 2>/dev/null)"
179
- released="$(printf '%s' "$verdict" | jq -r '.released // false' 2>/dev/null)"
184
+ # Every sign of the verdict becomes a variable of its own name; the commands go apart, they are text.
185
+ eval "$(printf '%s' "$verdict" | jq -r 'del(.ran) | to_entries[] | "\(.key)=\(.value | tostring | @sh)"' 2>/dev/null)"
180
186
  commands="$(printf '%s' "$verdict" | jq -r '.ran // ""' 2>/dev/null)"
181
187
 
182
188
  # A question refused by the conversation guard and asked as prose in the same turn. A guard refusal
183
189
  # releases the turn — it is the lawful end itself — but there is nothing to release here: the same
184
190
  # question came back a line later, and the work stalled on what the tree had already answered. The
185
191
  # tier stands before the lawful exits on purpose: a guard refusal covers exactly this case.
186
- asked_in_prose="$(printf '%s' "$verdict" | jq -r '.asked_in_prose // false' 2>/dev/null)"
187
- if [ "$asked_in_prose" = "true" ]; then
192
+ if [ "${asked_in_prose:-false}" = "true" ]; then
188
193
  rt_te_deny "BLOCKED by turn-exit-guard: in this turn the conversation guard refused a question to the owner, and the reply ends with a question in prose — the same question, asked in another form.
189
194
 
190
195
  The refusal of the guard named the reason: the answer lies in the tree or the owner has already given it. Read the place it named and work on; what is asked is what the tree does not hold.
@@ -200,11 +205,6 @@ fi
200
205
  # named a refusal to the owner, not a turn that said "waiting".
201
206
  # Incident analysis — the record
202
207
  # "2026-09-04-hod-konchalsya-ozhidaniem-pri-deystvuyushchem-ukazanii" in the intake.
203
- awaits_word="$(printf '%s' "$verdict" | jq -r '.awaits_word // false' 2>/dev/null)"
204
- standing_work="$(printf '%s' "$verdict" | jq -r '.standing_work // false' 2>/dev/null)"
205
- promised="$(printf '%s' "$verdict" | jq -r '.promised // false' 2>/dev/null)"
206
- only_took="$(printf '%s' "$verdict" | jq -r '.only_took // false' 2>/dev/null)"
207
-
208
208
  # A promise to do the work in the next turn. The same announcement of intent as a command named and
209
209
  # not run: the tier stands before the lawful exits, because the promise most often stands next to a
210
210
  # report about what was done, and by the fullness of the turn it is indistinguishable from a finish.
@@ -232,9 +232,6 @@ Write the plan and begin its first stage in this same turn.
232
232
 
233
233
  The guard judges one turn: the next session is not refused." "the turn ended with taking a task."
234
234
  fi
235
- # At the end of an epic waiting for the word of the owner is the work itself: the reading of that
236
- # lies with the patterns and is shared with the guard of the stop.
237
- [ "$awaits_word" = "true" ] && rt_te_epic_over && awaits_word=false
238
235
 
239
236
  # The owner said to work without stops and did not cancel it. Their word holds until they cancel
240
237
  # it, and a turn ending with waiting for that same word invents the cancellation. Judged whether or
@@ -259,6 +256,19 @@ The next step is written in the progress: ${next_step}
259
256
  The guard judges one turn: the next session is not refused." "the turn ended with waiting for the word of the owner."
260
257
  fi
261
258
 
259
+ # A question without a single piece of work in a running stage: the parts that do not depend on
260
+ # the answer go first, and the question after them.
261
+ if [ "${asked:-false}" = "true" ] && [ "$worked" != "true" ] && [ "$state" = "этап-идёт" ]; then
262
+ rt_te_question_without_work_deny
263
+ fi
264
+
265
+ # A handover written by the hand of the executor before the window filled is a stop announced by
266
+ # the one it suits: under an open epic it releases nothing. The window guard's refusal releases as
267
+ # any refusal, and the handover on compaction is written by the hook, not by a command in the turn.
268
+ if [ "${handed_by_hand:-false}" = "true" ] && rt_te_epic_open; then
269
+ rt_te_epic_deny handed-by-hand
270
+ fi
271
+
262
272
  [ "$released" = "true" ] && exit 0
263
273
 
264
274
  # Work that has reached the handover and has not been handed over. The two states in the `case`
@@ -308,7 +318,8 @@ esac
308
318
  # A folder taken apart by a branch commit does not get here: `archived` means handed-over work, and
309
319
  # the previous tier judges it. A branch without a task number is not judged at all — such ones are
310
320
  # created for a trial too.
311
- if [ "$archived" != "true" ] && [ -z "$progress" ] && [ -n "$branch" ] && [ ! -d "$root/$tasks_dir/$branch" ]; then
321
+ # An epic branch is not judged either: it carries no folder by the rule, and the epic plan names it.
322
+ if [ "$archived" != "true" ] && [ -z "$progress" ] && [ -n "$branch" ] && [ ! -d "$root/$tasks_dir/$branch" ] && ! rt_te_epic_branch; then
312
323
  task_key="${RT_TASK_KEY:-}"
313
324
  if [ -z "$task_key" ] && [ -f "$root/.claude/rt-kit/checks.json" ]; then
314
325
  task_key="$(jq -r '.board.taskKey // empty' "$root/.claude/rt-kit/checks.json" 2>/dev/null)"
@@ -445,6 +456,9 @@ The guard judges one turn: the next session is not refused."
445
456
  fi
446
457
  fi
447
458
 
459
+ # There was work in the turn, and the epic is open: the turn is released outside an epic and under a
460
+ # closed one alone. Under an open epic the work stands where it stood, and the next step is named.
461
+ [ "$worked" = "true" ] && rt_te_epic_open && rt_te_epic_deny worked
448
462
  [ "$worked" = "true" ] && exit 0
449
463
 
450
464
  if [ "$archived" = "true" ]; then
@@ -69,12 +69,3 @@ standing_work_re='работай[^.]{0,40}(без остановок|без па
69
69
  handover_re='gh[[:space:]]+pr[[:space:]]+create'
70
70
  started_re='task:new|task:move|board\.mjs[[:space:]]+move|git[[:space:]]+checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|git[[:space:]]+switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c'
71
71
 
72
- # The end of an epic: there waiting for the word of the owner is the work itself, and the guard of
73
- # the stop refuses taking the next task. The reading lies apart and is shared by the three guards;
74
- # it goes to the hosting, so the guard asks it right before a refusal, not on every turn.
75
- rt_te_epic_over() {
76
- # shellcheck disable=SC1090
77
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/epic-over.sh" 2>/dev/null || return 1
78
- command -v rt_epic_over >/dev/null 2>&1 || return 1
79
- rt_epic_over
80
- }
@@ -9,9 +9,16 @@
9
9
 
10
10
  rt_te_verdict() {
11
11
  verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re" --arg read "$read_re" --arg part "$part_re" --arg wait "$wait_re" --arg handover "$handover_re" --arg started "$started_re" --arg promise "$promise_re" --arg standing "$standing_work_re" '
12
+ # A service message — a skill load, a compaction summary — carries the user type and is not the word
13
+ # of the owner: it neither starts a turn nor is read as one.
14
+ def is_service:
15
+ ((.isCompactSummary // false) or (.isMeta // false))
16
+ or ((.message.content // "") | if type == "string" then . elif type == "array"
17
+ then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
18
+ | test("^[[:space:]]*Stop hook feedback"));
12
19
  def is_input:
13
20
  .type == "user"
14
- and ((.isCompactSummary // false) | not)
21
+ and (is_service | not)
15
22
  and (((.message.content // []) | if type == "array"
16
23
  then ([.[] | select(.type == "tool_result")] | length)
17
24
  else 0 end) == 0);
@@ -47,23 +54,28 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
47
54
  | ([$uses[] | (.name // "")] | last // "") as $last_tool
48
55
  | (($last_tool | test("^(Edit|Write|MultiEdit|NotebookEdit)$"))
49
56
  or ([$last | splits($part)] | map(test($work) and (test($read) | not)) | any)) as $ended_working
50
- # A guard refusal and a session handover — both end the turn by the rule.
57
+ # A guard refusal and a session handover — both end the turn by the rule. The refusal is read
58
+ # from the LAST tool result: a refusal in the middle of the turn was answered by the work that
59
+ # followed it, and a turn that went on after it is judged by how it ended.
51
60
  | ([$turn[] | select(.type == "user") | .message.content // [] | select(type == "array") | .[]
52
61
  | select(.type == "tool_result") | .content
53
62
  | if type == "string" then .
54
63
  elif type == "array" then (map(if type == "object" then (.text // "") else tostring end) | join("\n"))
55
- else tostring end] | join("\n")) as $out
56
- | (($out | test("BLOCKED by|Refused by the rules gate|Отбито гейтом")) or ($ran | test("BLOCKED by"))) as $denied
64
+ else tostring end]) as $outs
65
+ | ($outs | join("\n")) as $out
66
+ | ($outs | last // "") as $last_out
67
+ # The refusal of the closing tool is left out: the refused call was itself the stop, not work.
68
+ | ($last_out | test("BLOCKED by (?!end-conversation-guard)|Refused by the rules gate|Отбито гейтом")) as $denied
57
69
  | ($ran | test("handoff")) as $handed
58
70
  # The word of the owner about stopping: the reply itself is judged, not its retelling.
59
- | ([$turn[] | select(.type == "user") | .message.content
71
+ | ([$turn[] | select(.type == "user") | select(is_service | not) | .message.content
60
72
  | if type == "string" then . elif type == "array"
61
73
  then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end] | join("\n")) as $said
62
- | ([.[] | select(.type == "user") | .message.content
74
+ | ([.[] | select(.type == "user") | select(is_service | not) | .message.content
63
75
  | if type == "string" then . elif type == "array"
64
76
  then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end] | join("\n")) as $session_said
65
77
  | ($session_said | test($standing)) as $standing_work
66
- | (($said | test("останов|стоп|хватит|подожди|не надо|прерв|отложи")) and ($said | test($standing) | not)) as $told_stop
78
+ | (($said | test("останов|стоп|хватит|подожди|не надо|прерв|отложи|не двигайся|не продолжай|прекрати")) and ($said | test($standing) | not)) as $told_stop
67
79
  # A question refused by the conversation guard, and a question appended as prose at the end of
68
80
  # the reply. The conversation guard judges the call of the question tool and does not see prose
69
81
  # at all: a refused question came back in the same wording one turn later and passed freely.
@@ -79,6 +91,6 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
79
91
  and (($asked or $told_stop or $handed) | not)) as $awaits_word
80
92
  | ($last_say | test($promise)) as $promised
81
93
  | (($last_name == "Bash") and ($last | test($started)) and ($handed_over | not)) as $only_took
82
- | { promised: $promised, only_took: $only_took, standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, ran: $ran }
94
+ | { promised: $promised, only_took: $only_took, asked: $asked, handed_by_hand: ($handed and (($asked or $denied or $told_stop) | not)), standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, ran: $ran }
83
95
  ' 2>/dev/null)"
84
96
  }
@@ -102,6 +102,12 @@ application stops responding, and the reason is found from the history.
102
102
  shown as taken, one waiting for review as waiting. Otherwise untouched, in progress and done look
103
103
  the same: the work is taken a second time, and the PR stands unreviewed. The state is moved at the
104
104
  moment the work goes to the next step: the queue is read between those moments, not after them.
105
+ - **The state of an epic card in the work queue matches the epic's work the same way.** The epic
106
+ is taken into work with its first task and waits for review with its own change into the main
107
+ branch; its card says so at those two moments, the same as a task's card. Otherwise an epic with
108
+ half its tasks merged stands in the queue as never taken, and the owner watching one card per
109
+ epic sees no work at all. The share of tasks done the queue shows on the epic card by itself,
110
+ once the tasks are linked to it; the column it does not move.
105
111
  - **A change entering the main branch means a rollout.** Everything the change depends on outside
106
112
  the code — environment variables, secrets, name records — is put in place before that moment, not
107
113
  after.
@@ -158,6 +158,10 @@ one session and keeps its whole context and state when it passes to the next.
158
158
  looks at it. An epic with one card out of ten looks there like one step of work. The card number
159
159
  goes into the plan by the same edit: otherwise the plan answers "take the next one" with a title,
160
160
  and the card is created again under a new number.
161
+ - **Taking the first task of an epic takes the epic itself into work, and the epic card says so.**
162
+ The owner follows the epic by one card, not by its tasks; a card that stays where the epic was
163
+ declared reads as an epic nobody started, however many of its tasks are already done. The card
164
+ moves by the same motion as the first task's, not by a separate step remembered later.
161
165
  - **An executor's session does not end together with the task.** The end of a task is not a sign to
162
166
  stop: only the window fill limit allows stopping. A session closed on a finished task leaves the
163
167
  owner a blank and costs a whole session to return to what was at hand.
@@ -131,6 +131,19 @@ repository refuses about Projects (classic) and never reaches the edit:
131
131
  /opt/homebrew/bin/gh api -X PATCH repos/<владелец>/<репозиторий>/pulls/<номер> -f body="$(cat тело.md)"
132
132
  ```
133
133
 
134
+ ## The task of a merged PR is asked, not assumed closed
135
+
136
+ The host closes the task by the `Closes` line only when the base is the default branch. A PR
137
+ merged into an epic branch or into the previous branch of a chain leaves its task open unless the
138
+ tree closes it by a pipeline of its own — and the column of the board lags the work until then.
139
+ After every known merge with such a base the task's state is asked by a command; one still open
140
+ is closed by hand with a comment naming the PR — the calls are in the pattern
141
+ `git-workflow-stack`.
142
+
143
+ ```bash
144
+ gh issue view <номер> --json state --jq .state
145
+ ```
146
+
134
147
  ## A green run ages together with the main branch
135
148
 
136
149
  A run speaks about the base it went on. While it goes and the PR awaits review, the main branch