@rt-tools/agent-kit 0.33.1 → 0.35.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 (159) hide show
  1. package/README.md +14 -13
  2. package/assets/agents/goal-critic.md +76 -0
  3. package/assets/agents/product-strategist.md +95 -0
  4. package/assets/agents/qa-engineer.md +3 -0
  5. package/assets/checks/check-specs.mjs +11 -2
  6. package/assets/checks/rt-kit-checks.config.mjs +6 -0
  7. package/assets/checks/spec-common.mjs +6 -3
  8. package/assets/checks/spec-scenarios.mjs +9 -1
  9. package/assets/checks/task-new.github.mjs +6 -0
  10. package/assets/defaults/project.sh +49 -81
  11. package/assets/defaults/push.sh +100 -0
  12. package/assets/docs/GLOSSARY.md +4 -0
  13. package/assets/hooks/browser-guard-device-id.sh +1 -0
  14. package/assets/hooks/browser-guard-no-asking.sh +1 -0
  15. package/assets/hooks/browser-guard-no-listing.sh +1 -0
  16. package/assets/hooks/browser-guard-no-other-drivers.sh +7 -3
  17. package/assets/hooks/browser-guard-require-select.sh +1 -0
  18. package/assets/hooks/claim-guard.sh +7 -6
  19. package/assets/hooks/dev-server-guard.sh +1 -0
  20. package/assets/hooks/dispatch.sh +56 -3
  21. package/assets/hooks/docs-guard.sh +1 -0
  22. package/assets/hooks/end-conversation-guard.sh +1 -0
  23. package/assets/hooks/epic-stop-guard.sh +1 -0
  24. package/assets/hooks/exam-guard.sh +6 -1
  25. package/assets/hooks/git-guard-delivery-body.sh +25 -3
  26. package/assets/hooks/git-guard-delivery-draft.sh +23 -0
  27. package/assets/hooks/git-guard-delivery-folder.sh +38 -1
  28. package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
  29. package/assets/hooks/git-guard-delivery-signature.sh +19 -0
  30. package/assets/hooks/git-guard-delivery.sh +15 -19
  31. package/assets/hooks/git-guard-discard.sh +1 -0
  32. package/assets/hooks/git-guard-main.sh +18 -4
  33. package/assets/hooks/git-guard-no-verify.sh +1 -0
  34. package/assets/hooks/git-guard-push-ahead.sh +98 -0
  35. package/assets/hooks/git-guard-push-marks.sh +99 -0
  36. package/assets/hooks/git-guard-push-tests.sh +102 -83
  37. package/assets/hooks/grill-gate.sh +1 -0
  38. package/assets/hooks/guard-note.sh +11 -3
  39. package/assets/hooks/handover-mark.sh +37 -0
  40. package/assets/hooks/metric-marks.sh +233 -0
  41. package/assets/hooks/metric-send-start.sh +38 -0
  42. package/assets/hooks/observe.sh +103 -0
  43. package/assets/hooks/owner-corrections.sh +36 -0
  44. package/assets/hooks/pre-push.sh +113 -0
  45. package/assets/hooks/prose-style-guard.sh +1 -0
  46. package/assets/hooks/pull-outcomes.sh +59 -0
  47. package/assets/hooks/push-set.sh +160 -0
  48. package/assets/hooks/push-sign.sh +433 -0
  49. package/assets/hooks/qa-dataid-guard.sh +1 -0
  50. package/assets/hooks/rerun-guard.sh +15 -6
  51. package/assets/hooks/reuse-first-guard.sh +1 -0
  52. package/assets/hooks/role-calls.sh +120 -0
  53. package/assets/hooks/rule-source-guard.sh +16 -0
  54. package/assets/hooks/skill-gate.sh +11 -0
  55. package/assets/hooks/task-flow-draft-guard.sh +1 -0
  56. package/assets/hooks/task-flow-guard.sh +1 -0
  57. package/assets/hooks/tree-assignment-guard.sh +1 -0
  58. package/assets/hooks/turn-exit-epic.sh +24 -0
  59. package/assets/hooks/turn-exit-guard.sh +3 -23
  60. package/assets/hooks/turn-exit-patterns.sh +4 -3
  61. package/assets/hooks/turn-exit-verdict.sh +18 -1
  62. package/assets/hooks/waiting-turn-guard.sh +3 -1
  63. package/assets/hooks/window-fill-guard.sh +1 -0
  64. package/assets/hooks/work-start-guard.sh +1 -0
  65. package/assets/hooks/write-targets.sh +21 -0
  66. package/assets/patterns/git-workflow-commit.azure.md +5 -3
  67. package/assets/patterns/git-workflow-commit.github.md +16 -3
  68. package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
  69. package/assets/patterns/git-workflow-pr-body.github.md +20 -3
  70. package/assets/patterns/git-workflow-pr.azure.md +30 -0
  71. package/assets/patterns/git-workflow-pr.github.md +57 -1
  72. package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
  73. package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
  74. package/assets/patterns/task-flow-close.md +32 -22
  75. package/assets/patterns/task-flow-cycle.md +72 -0
  76. package/assets/patterns/task-flow-start.md +3 -3
  77. package/assets/rules/browser-verification.md +4 -0
  78. package/assets/rules/deploy-flow.azure.md +5 -0
  79. package/assets/rules/deploy-flow.github.md +5 -0
  80. package/assets/rules/deploy-flow.gitlab.md +5 -0
  81. package/assets/rules/git-workflow.azure.md +15 -0
  82. package/assets/rules/git-workflow.github.md +15 -0
  83. package/assets/rules/git-workflow.gitlab.md +15 -0
  84. package/assets/rules/mockups.needs-mockups.md +13 -5
  85. package/assets/rules/task-flow.md +31 -25
  86. package/assets/samples/tasks/_template/plan.md +8 -0
  87. package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
  88. package/assets/skills/interface-review-icons.needs-app.md +136 -0
  89. package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
  90. package/assets/skills/interface-review-motion.needs-app.md +209 -0
  91. package/assets/skills/interface-review-performance.needs-app.md +110 -0
  92. package/assets/skills/interface-review-principles.needs-app.md +263 -0
  93. package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
  94. package/assets/skills/interface-review.needs-app.md +199 -0
  95. package/assets/skills/write-a-skill.md +16 -3
  96. package/assets/templates/postmortem.md +2 -0
  97. package/assets/workflows/feature.js +33 -5
  98. package/assets/workflows/plan.js +71 -4
  99. package/bin/agent-kit.d.ts.map +1 -1
  100. package/bin/agent-kit.js +28 -0
  101. package/bin/agent-kit.js.map +1 -1
  102. package/lib/cargo.d.ts +35 -0
  103. package/lib/cargo.d.ts.map +1 -1
  104. package/lib/cargo.js +76 -0
  105. package/lib/cargo.js.map +1 -1
  106. package/lib/commands.d.ts +9 -0
  107. package/lib/commands.d.ts.map +1 -1
  108. package/lib/commands.js +32 -19
  109. package/lib/commands.js.map +1 -1
  110. package/lib/config.d.ts +5 -0
  111. package/lib/config.d.ts.map +1 -1
  112. package/lib/config.js +1 -0
  113. package/lib/config.js.map +1 -1
  114. package/lib/file-lock.d.ts +4 -0
  115. package/lib/file-lock.d.ts.map +1 -0
  116. package/lib/file-lock.js +23 -0
  117. package/lib/file-lock.js.map +1 -0
  118. package/lib/metric-lines.d.ts +20 -0
  119. package/lib/metric-lines.d.ts.map +1 -0
  120. package/lib/metric-lines.js +117 -0
  121. package/lib/metric-lines.js.map +1 -0
  122. package/lib/metric-send-mark.d.ts +52 -0
  123. package/lib/metric-send-mark.d.ts.map +1 -0
  124. package/lib/metric-send-mark.js +69 -0
  125. package/lib/metric-send-mark.js.map +1 -0
  126. package/lib/metric-send.d.ts +18 -0
  127. package/lib/metric-send.d.ts.map +1 -0
  128. package/lib/metric-send.js +226 -0
  129. package/lib/metric-send.js.map +1 -0
  130. package/lib/metric-usage.d.ts +34 -0
  131. package/lib/metric-usage.d.ts.map +1 -0
  132. package/lib/metric-usage.js +111 -0
  133. package/lib/metric-usage.js.map +1 -0
  134. package/lib/metrics.d.ts +92 -0
  135. package/lib/metrics.d.ts.map +1 -0
  136. package/lib/metrics.js +263 -0
  137. package/lib/metrics.js.map +1 -0
  138. package/lib/observations-cargo.d.ts +2 -0
  139. package/lib/observations-cargo.d.ts.map +1 -1
  140. package/lib/observations-cargo.js +1 -1
  141. package/lib/observations-cargo.js.map +1 -1
  142. package/lib/observations.d.ts +22 -2
  143. package/lib/observations.d.ts.map +1 -1
  144. package/lib/observations.js +40 -13
  145. package/lib/observations.js.map +1 -1
  146. package/lib/outcomes.d.ts +89 -0
  147. package/lib/outcomes.d.ts.map +1 -0
  148. package/lib/outcomes.js +274 -0
  149. package/lib/outcomes.js.map +1 -0
  150. package/lib/ship.js +1 -1
  151. package/lib/ship.js.map +1 -1
  152. package/lib/shipment.d.ts.map +1 -1
  153. package/lib/shipment.js +7 -1
  154. package/lib/shipment.js.map +1 -1
  155. package/lib/snapshot.d.ts +2 -0
  156. package/lib/snapshot.d.ts.map +1 -1
  157. package/lib/snapshot.js +6 -0
  158. package/lib/snapshot.js.map +1 -1
  159. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PostToolUse Agent|Task
3
+ # rt-hook: UserPromptSubmit
4
+ # rt-hook: SubagentStop
5
+ # Requires: hooks/hook-input.sh, hooks/observe.sh
6
+ #
7
+ # Counts the calls of roles and commands for the package metrics. A role nobody calls is judged the
8
+ # same way as a rule nobody loads, and only the host sees the call.
9
+ #
10
+ # WHAT IS RECORDED. The name of a package role or command, and a constant word for what is the tree's
11
+ # own: its name may name the tree, and an observation leaves it. A role is the package's when its
12
+ # laid-out file carries the layout header. A built-in role has no file and is not counted.
13
+ #
14
+ # THE VERDICT. A role that gives one says it in its first line, and the table below is the whole
15
+ # knowledge about it: the words of a refusal, in both languages a role answers in. A role outside the
16
+ # table is counted by calls. Only the answer goes into the record, the text stays where it is. It is
17
+ # read when the role ends, not when it is called: a role usually runs in the background, and at the
18
+ # call its answer is only the fact of the launch.
19
+ #
20
+ # FAIL-OPEN: no input, no parser, no record — exit with zero and no output. This hook never refuses.
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 || exit 0
24
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/observe.sh" 2>/dev/null || exit 0
25
+
26
+ rt_hook_read
27
+ [ -n "$RT_HOOK_INPUT" ] || exit 0
28
+ command -v jq >/dev/null 2>&1 || exit 0
29
+
30
+ root="${CLAUDE_PROJECT_DIR:-.}"
31
+ sid="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)"
32
+
33
+ # The name a resource goes under: its own for the package, a constant word for the tree. Empty — the
34
+ # host's built-in, with no file at all.
35
+ rt_called_name() {
36
+ local file="$1" name="$2"
37
+ [ -f "$file" ] || return 0
38
+ # The layout header stands after the front matter of the file, so the top lines are not enough.
39
+ if head -n 12 "$file" 2>/dev/null | grep -q 'rt-kit v'; then
40
+ printf '%s' "$name"
41
+ else
42
+ printf 'tree-own'
43
+ fi
44
+ }
45
+
46
+ # The words of a verdict by role: the refusal first, because it holds the words of a pass. No line —
47
+ # the role gives no verdict the report counts.
48
+ rt_refusal_words() {
49
+ case "$1" in
50
+ goal-critic) printf '%s' 'not met|partly met|не достигнут|не выполнен|частично' ;;
51
+ product-strategist) printf '%s' 'does not reach|longer route|не достигает|не ведёт|длинн' ;;
52
+ esac
53
+ }
54
+ rt_pass_words() {
55
+ case "$1" in
56
+ goal-critic) printf '%s' 'is met|достигнут|выполнен' ;;
57
+ product-strategist) printf '%s' 'reaches|достигает|ведёт' ;;
58
+ esac
59
+ }
60
+
61
+ # The answer of a role. A role that hands its report back by a tool ends with no text, so the host
62
+ # gives the event an empty last message, and the answer is the last report in its record.
63
+ rt_role_answer() {
64
+ local answer path
65
+ answer="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.last_assistant_message // empty' 2>/dev/null)"
66
+ if [ -n "$answer" ]; then
67
+ printf '%s' "$answer"
68
+ return 0
69
+ fi
70
+ path="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.agent_transcript_path // empty' 2>/dev/null)"
71
+ [ -f "$path" ] || return 0
72
+ tail -n 20 "$path" 2>/dev/null \
73
+ | jq -c 'select(.message.content? | type == "array") | .message.content[]
74
+ | select(.type? == "tool_use" and .name? == "SubagentHandback") | .input.message // empty' 2>/dev/null \
75
+ | tail -n 1 | jq -r '.' 2>/dev/null
76
+ }
77
+
78
+ # The verdict by the first line of the answer of the role. Neither word — no verdict.
79
+ rt_verdict_of() {
80
+ local refusal pass line
81
+ refusal="$(rt_refusal_words "$1")"
82
+ pass="$(rt_pass_words "$1")"
83
+ [ -n "$refusal" ] || return 0
84
+ line="$(rt_role_answer | awk 'NF { print; exit }')"
85
+ if printf '%s' "$line" | grep -qiE "$refusal"; then
86
+ printf 'refused'
87
+ elif printf '%s' "$line" | grep -qiE "$pass"; then
88
+ printf 'passed'
89
+ fi
90
+ }
91
+
92
+ prompt="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.prompt // empty' 2>/dev/null)"
93
+ if [ -n "$prompt" ]; then
94
+ case "$prompt" in
95
+ /*) ;;
96
+ *) exit 0 ;;
97
+ esac
98
+ command="$(printf '%s' "$prompt" | sed -E 's#^/([A-Za-z0-9_-]+).*#\1#' | head -n 1)"
99
+ name="$(rt_called_name "$root/.claude/commands/$command.md" "$command")"
100
+ [ -z "$name" ] || rt_note command-call "res=$name" "sid=$sid"
101
+ exit 0
102
+ fi
103
+
104
+ # A role that ended: only the verdict is written here, the call was counted when it was made. The
105
+ # event is asked by name: a call made inside a role carries the type of that role too.
106
+ if [ "$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.hook_event_name // empty' 2>/dev/null)" = SubagentStop ]; then
107
+ ended="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.agent_type // empty' 2>/dev/null)"
108
+ name="$(rt_called_name "$root/.claude/agents/$ended.md" "$ended")"
109
+ verdict="$(rt_verdict_of "$name")"
110
+ [ -z "$verdict" ] || rt_note role-verdict "res=$name" "sid=$sid" "verdict=$verdict"
111
+ exit 0
112
+ fi
113
+
114
+ role="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.tool_input.subagent_type // empty' 2>/dev/null)"
115
+ [ -n "$role" ] || exit 0
116
+ name="$(rt_called_name "$root/.claude/agents/$role.md" "$role")"
117
+ [ -n "$name" ] || exit 0
118
+
119
+ rt_note role-call "res=$name" "sid=$sid"
120
+ exit 0
@@ -102,6 +102,22 @@ while IFS= read -r candidate; do
102
102
  /*) ;;
103
103
  *) candidate="$root/$candidate" ;;
104
104
  esac
105
+ # The observations are what the numbers of the package are counted from, and a hand in them
106
+ # turns a report into a statement of the one who edited it. Only the guards write here.
107
+ case "$candidate" in
108
+ */.claude/rt-kit/observations/*)
109
+ deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» lies in the observations directory, and only the guards write there. An edit by hand makes the numbers of the package a statement of the one who wrote them." \
110
+ "the way out is to do the work the observation records, not to write the observation"
111
+ ;;
112
+ */.claude/rt-kit.json)
113
+ # Both keys decide what the numbers of the package are, and the one those numbers judge
114
+ # must not switch them off. The owner edits them by hand.
115
+ if printf '%s' "$input" | jq -r '.tool_input | tostring' 2>/dev/null | grep -qE '(^|[^[:alnum:]_-])(send|observe)([^[:alnum:]_-]|$)'; then
116
+ deny "BLOCKED by rule-source-guard: the keys «send» and «observe» of «${candidate#"$root"/}» decide what the numbers of the package are, and a session does not edit them." \
117
+ "the way out is to name the change to the owner: they edit these two keys by hand"
118
+ fi
119
+ ;;
120
+ esac
105
121
  [ -f "$candidate" ] || continue
106
122
 
107
123
  # The header stands at the beginning of the file, but not on the first line: in a script `#!`
@@ -145,6 +145,17 @@ EOF
145
145
  *) exit 0 ;;
146
146
  esac
147
147
 
148
+ # Every file edit the gate sees, with a rule or without one: the share of edits that met a rule not
149
+ # yet loaded needs its denominator. A call of a tool is not an edit.
150
+ case "$kind" in
151
+ command | browser | design | '') ;;
152
+ *)
153
+ # shellcheck disable=SC1091
154
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/observe.sh" 2>/dev/null \
155
+ && rt_note edit-seen "kind=$kind" "sid=$sid"
156
+ ;;
157
+ esac
158
+
148
159
  [ -z "$req" ] && exit 0
149
160
 
150
161
  # The map may name several rules: the domain rule and the one that acts as a second layer. The
@@ -27,6 +27,7 @@
27
27
  # Own name in the observations: the refusal is written by the shared refusal tail, not by the
28
28
  # guard itself.
29
29
  RT_GUARD_NAME=task-flow-draft-guard
30
+ RT_GUARD_RULE=task-flow
30
31
 
31
32
  rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
32
33
 
@@ -26,6 +26,7 @@
26
26
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
27
27
  # guard itself.
28
28
  RT_GUARD_NAME=task-flow-guard
29
+ RT_GUARD_RULE=task-flow
29
30
 
30
31
  rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
31
32
 
@@ -20,6 +20,7 @@
20
20
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
21
21
  # guard itself.
22
22
  RT_GUARD_NAME=tree-assignment-guard
23
+ RT_GUARD_RULE=task-flow
23
24
 
24
25
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
25
26
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -147,3 +147,27 @@ Do it in this same turn; the launch may stand anywhere in the turn but last.
147
147
 
148
148
  The guard judges one turn: the next session is not refused." "the turn ended on a launch in the background."
149
149
  }
150
+
151
+ # The state requirement after the folder is gone. It reads the history of the branch, as the tiers
152
+ # above do, and lives here because the guard reached the file length limit.
153
+ #
154
+ # The same thing, but there is nothing left on disk to declare it with: the task folder is taken
155
+ # apart before the PR opens, and the progress goes away with it. The sign is taken from the branch
156
+ # history — the folder removed by its commit.
157
+ #
158
+ # A turn must not be released by that sign: the folder is removed BEFORE the PR, and between these
159
+ # two movements the work is handed over to nobody. A turn caught in that gap used to leave here
160
+ # with zero — and it was exactly one step short of the handover, and it did not make it. The sign
161
+ # therefore only lifts the state requirement: from there the turn is judged by the second sign,
162
+ # like any other. A turn in which the PR was opened or read passes the second sign by itself — it
163
+ # counts a call of the hosting client as work.
164
+ folder_archived() {
165
+ [ -n "$branch" ] || return 1
166
+ [ -n "$(git ls-tree -d --name-only HEAD -- "$tasks_dir/$branch" 2>/dev/null | head -1)" ] && return 1
167
+ main_branch="${RT_MAIN_BRANCH:-main}"
168
+ base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
169
+ [ -z "$base" ] && return 1
170
+ had="$(git ls-tree -d --name-only "$base" -- "$tasks_dir/$branch" 2>/dev/null | head -1)"
171
+ [ -z "$had" ] && had="$(git log "$base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$tasks_dir/$branch" 2>/dev/null | head -1)"
172
+ [ -n "$had" ]
173
+ }
@@ -41,6 +41,7 @@
41
41
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
42
42
  # guard itself.
43
43
  RT_GUARD_NAME=turn-exit-guard
44
+ RT_GUARD_RULE=turn-conduct
44
45
 
45
46
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
46
47
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -136,27 +137,6 @@ The guard judges one turn: the next session is not refused."
136
137
  rt_te_deny "$reason" "the plan is written and the first stage is not begun."
137
138
  fi
138
139
 
139
- # The same thing, but there is nothing left on disk to declare it with: the task folder is taken
140
- # apart before the PR opens, and the progress goes away with it. The sign is taken from the branch
141
- # history — the folder removed by its commit.
142
- #
143
- # A turn must not be released by that sign: the folder is removed BEFORE the PR, and between these
144
- # two movements the work is handed over to nobody. A turn caught in that gap used to leave here
145
- # with zero — and it was exactly one step short of the handover, and it did not make it. The sign
146
- # therefore only lifts the state requirement: from there the turn is judged by the second sign,
147
- # like any other. A turn in which the PR was opened or read passes the second sign by itself — it
148
- # counts a call of the hosting client as work.
149
- folder_archived() {
150
- [ -n "$branch" ] || return 1
151
- [ -n "$(git ls-tree -d --name-only HEAD -- "$tasks_dir/$branch" 2>/dev/null | head -1)" ] && return 1
152
- main_branch="${RT_MAIN_BRANCH:-main}"
153
- base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
154
- [ -z "$base" ] && return 1
155
- had="$(git ls-tree -d --name-only "$base" -- "$tasks_dir/$branch" 2>/dev/null | head -1)"
156
- [ -z "$had" ] && had="$(git log "$base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$tasks_dir/$branch" 2>/dev/null | head -1)"
157
- [ -n "$had" ]
158
- }
159
-
160
140
  archived=false
161
141
  [ -z "$progress" ] && folder_archived && archived=true
162
142
 
@@ -179,7 +159,7 @@ next_step=""
179
159
  command -v rt_te_verdict >/dev/null 2>&1 || exit 0
180
160
  rt_te_verdict
181
161
 
182
- [ -z "$verdict" ] && exit 0
162
+ [ -z "$verdict" ] && exit 0 # also a turn woken while an own background task runs, SC-AK-1247
183
163
 
184
164
  # Every sign of the verdict becomes a variable of its own name; the commands go apart, they are text.
185
165
  eval "$(printf '%s' "$verdict" | jq -r 'del(.ran) | to_entries[] | "\(.key)=\(.value | tostring | @sh)"' 2>/dev/null)"
@@ -282,7 +262,7 @@ fi
282
262
  # state is not allowed.
283
263
  case "$state" in
284
264
  этапы-кончились | разбор-кончился)
285
- if ! printf '%s' "$commands" | grep -qE 'gh[[:space:]]+pr[[:space:]]+create'; then
265
+ if ! printf '%s' "$commands" | grep -qE "$handover_re"; then
286
266
  if [ "$state" = "этапы-кончились" ]; then
287
267
  action="merge the agreement, bring the texts up to what was done and run the suite"
288
268
  else
@@ -17,7 +17,7 @@
17
17
  # of the two changes the tree, and to the pattern they were indistinguishable from writing to a
18
18
  # working file: it saw the arrow itself and did not ask where it led. What stays as the sign is an
19
19
  # edit of a file by the editing tool and the commands listed here.
20
- work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
20
+ work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|glab (mr|ci|issue|api)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
21
21
 
22
22
  # Exploration. The same words as in the work pattern, but the subcommand is a reading one:
23
23
  # switching a branch, pulling, looking through the history, reading PRs and runs. The work pattern
@@ -29,7 +29,7 @@ work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (bui
29
29
  # Exploration looks like work better than anything else: it has commands, numbers and exact answers.
30
30
  # That is what makes it dangerous — a turn stuffed with it reads as full both to the owner and to
31
31
  # the session itself.
32
- read_re='^[[:space:]]*(([^[:space:]]*/)?git[[:space:]]+(show|log|ls-tree|ls-files|ls-remote|diff|status|branch|tag|rev-parse|remote|describe|blame|fetch|pull|(checkout|switch)(?!([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-[bc][[:space:]]))|([^[:space:]]*/)?gh[[:space:]]+(pr|issue|run|repo)[[:space:]]+(list|view|status|checks|diff|download|logs))([[:space:]]|$)'
32
+ read_re='^[[:space:]]*(([^[:space:]]*/)?git[[:space:]]+(show|log|ls-tree|ls-files|ls-remote|diff|status|branch|tag|rev-parse|remote|describe|blame|fetch|pull|(checkout|switch)(?!([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-[bc][[:space:]]))|([^[:space:]]*/)?gh[[:space:]]+(pr|issue|run|repo)[[:space:]]+(list|view|status|checks|diff|download|logs)|([^[:space:]]*/)?glab[[:space:]]+(mr|issue|ci|repo)[[:space:]]+(list|view|status|diff|trace|get))([[:space:]]|$)'
33
33
 
34
34
  # The parts of a compound command are judged one by one: a turn gathers reading and work into one
35
35
  # line through `&&`, and judging it whole would release exploration on the very first changing part.
@@ -66,7 +66,8 @@ standing_work_re='работай[^.]{0,40}(без остановок|без па
66
66
 
67
67
  # Handing work over and starting the next. The rule calls handed-over work a lawful end of a turn —
68
68
  # but on a condition: the next one is started, and an ACTION has been done on it, not spoken.
69
- handover_re='gh[[:space:]]+pr[[:space:]]+create'
69
+ # The GitLab client opens a merge request — the same handing over.
70
+ handover_re='gh[[:space:]]+pr[[:space:]]+create|glab[^|;&]*mr[[:space:]]+create'
70
71
  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
72
 
72
73
  # How many steps of the plan are not done yet. The progress mirrors the steps of the plan with a
@@ -42,6 +42,23 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
42
42
  # depend on it is done while it runs — the turn does not end on the launch itself.
43
43
  | (($last_name | test("^(Agent|Task)$")) or (($last_name == "Bash") and ($last | test("&[[:space:]]*$")))) as $launched_last
44
44
  | (($last_name == "Bash") and ($last | test($wait))) as $waited
45
+ # A turn woken by a notification about an own background task. The notification is written under
46
+ # the role of the owner, and the turn it opens holds nothing to do while another own task still
47
+ # runs. The launches are read over the whole window; a launch ends with a notification naming its
48
+ # call, whether it woke a turn or arrived as an attachment in the middle of one. Such a turn
49
+ # gets no verdict at all, and the guard lets an empty verdict through: the guard has no room.
50
+ | (if $i == null then false else
51
+ ((.[$i].origin.kind // "") == "task-notification")
52
+ or ((.[$i].message.content // "") | if type == "string" then test("^[[:space:]]*<task-notification>") else false end)
53
+ end) as $woken
54
+ | ([.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")
55
+ | select(((.name // "") | test("^(Agent|Task)$")) or (((.name // "") == "Bash") and (.input.run_in_background // false)))
56
+ | (.id // empty)]) as $launches
57
+ | ([.[] | ((.message.content // "") | if type == "string" then . else "" end), (.attachment.prompt // "")
58
+ | select(test("<task-notification>"))
59
+ | select(test("<status>(completed|failed|killed|stopped)</status>"))
60
+ | (capture("<tool-use-id>(?<id>[^<]+)</tool-use-id>").id // empty)]) as $finished
61
+ | ($woken and (($uses | length) == 0) and (($launches - $finished) | length) > 0) as $woken_waiting
45
62
  # Handing the work over: the tail of the turn after the PR was opened. Everything before it was
46
63
  # done on the task handed in and says nothing about the next one.
47
64
  | ([$uses[] | select((.name // "") == "Bash") | (.input.command // "")]) as $cmds
@@ -127,6 +144,6 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
127
144
  or (((.name // "") == "Bash") and ([(.input.command // "") | splits($part)] | map(test($work) and (test($read) | not) and (test("^[[:space:]]*([^[:space:]]*/)?git[[:space:]]+(add|commit|push)") | not)) | any))
128
145
  ) | any) as $after_progress
129
146
  | (($last_name == "Bash") and ($last | test($started)) and ($handed_over | not)) as $only_took
130
- | { 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, progress_edited: $progress_edited, after_progress: $after_progress, launched_last: $launched_last, ran: $ran, unpushed_named: $unpushed_named }
147
+ | if $woken_waiting then empty else { 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, progress_edited: $progress_edited, after_progress: $after_progress, launched_last: $launched_last, ran: $ran, unpushed_named: $unpushed_named } end
131
148
  ' 2>/dev/null)"
132
149
  }
@@ -34,6 +34,7 @@
34
34
 
35
35
  # Its own name in observations: the refusal is written by the shared deny tail, not by the guard.
36
36
  RT_GUARD_NAME=waiting-turn-guard
37
+ RT_GUARD_RULE=turn-conduct
37
38
 
38
39
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
39
40
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -84,7 +85,8 @@ taken_path_re='/tasks/'
84
85
  # Lifting the draft is the obvious case; reading the run is the one where there is nothing to lift
85
86
  # yet, but the executor looked instead of saying "waiting". Two ready PRs stood as drafts precisely
86
87
  # because the next task was taken instead of this, not on top of it.
87
- ready_re='pr[[:space:]]+ready|run[[:space:]]+(list|view|watch)|pr[[:space:]]+checks|check-runs|check:board|board\.mjs'
88
+ # The GitLab client lifts the draft by an update with a flag and reads the pipeline by `ci`.
89
+ ready_re='pr[[:space:]]+ready|run[[:space:]]+(list|view|watch)|pr[[:space:]]+checks|check-runs|check:board|board\.mjs|glab[^|;&]*mr[[:space:]]+update[^|;&]*(--ready|[[:space:]]-r)([[:space:]]|$)|glab[^|;&]*ci[[:space:]]+(status|view|list|trace|get)'
88
90
 
89
91
  # A run started or rerun in the turn. Its outcome does not call by itself: a rerun went through in
90
92
  # one line between other things, its state was read once — «queued» — and the turn ended by a lawful
@@ -34,6 +34,7 @@
34
34
 
35
35
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
36
36
  RT_GUARD_NAME=window-fill-guard
37
+ RT_GUARD_RULE=turn-conduct
37
38
 
38
39
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
39
40
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -32,6 +32,7 @@
32
32
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
33
33
  # guard itself.
34
34
  RT_GUARD_NAME=work-start-guard
35
+ RT_GUARD_RULE=task-flow
35
36
 
36
37
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
37
38
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -64,6 +64,27 @@ rt_write_targets() {
64
64
  }
65
65
  ')"
66
66
 
67
+ # An arrow inside quotes is text of the command, not a redirection: `echo "a->b"` and the code
68
+ # of `node -e "[1].map(x => x)"` read as writes into `b` and `x)` and were refused as edits.
69
+ # The quote state is kept per line; a backslash outside single quotes escapes the next sign.
70
+ rt_wt_shell="$(printf '%s\n' "$rt_wt_shell" | awk -v sq="'" '
71
+ function drop_quoted_arrows(s, out, i, c, q, n) {
72
+ out = ""; q = ""; n = length(s)
73
+ for (i = 1; i <= n; i++) {
74
+ c = substr(s, i, 1)
75
+ if (c == "\\" && q != sq && i < n) { out = out c substr(s, i + 1, 1); i++; continue }
76
+ if (q != "") {
77
+ if (c == q) { q = "" } else if (c == ">") { continue }
78
+ } else if (c == "\"" || c == sq || c == "`") {
79
+ q = c
80
+ }
81
+ out = out c
82
+ }
83
+ return out
84
+ }
85
+ { print drop_quoted_arrows($0) }
86
+ ')"
87
+
67
88
  {
68
89
  printf '%s' "$rt_wt_shell" \
69
90
  | tr "\"'\`" ' ' \
@@ -133,9 +133,11 @@ The move is not put off for later: the work queue is read between steps, not aft
133
133
 
134
134
  ## The commit is signed by the machine account
135
135
 
136
- The token is read into a variable and not printed; author and committer are set by variables of
137
- the same command. `git config` will not do — the config is shared with the main tree and would
138
- rewrite the signature to the owner:
136
+ The token is read into a variable and not printed; author and committer are set by variables
137
+ prefixed to `git commit` itself. `git config` will not do — the config is shared with the main tree
138
+ and would rewrite the signature to the owner. `export` will not do either: it reaches every later
139
+ command of the call, and a set before a push started by the same call runs the hook scenarios under
140
+ the bot's mail — the ones comparing a mail fall on a sound tree:
139
141
 
140
142
  ```bash
141
143
  TOKEN=$(tr -d '\n' < ~/.config/<дерево>-bot-token)
@@ -169,6 +169,17 @@ A name without a number (`feat/…`, `fix/…`) is legitimate while the branch l
169
169
  trial and an analysis. No PR opens from it: an edit that reaches the main branch starts with a
170
170
  task.
171
171
 
172
+ **A local branch that continues an open PR under another name is tied to the PR's branch before
173
+ the first push.** Otherwise it has no upstream: the push goes nowhere by itself, and the turn-exit
174
+ guard counts every commit as not handed over while all of them already stand in the PR. The tie
175
+ and the push name the PR's branch:
176
+
177
+ ```bash
178
+ git branch --set-upstream-to=origin/<ветка PR>
179
+ git push origin HEAD:<ветка PR>
180
+ git rev-list --count @{u}..HEAD # 0 — everything is on the host
181
+ ```
182
+
172
183
  ## The task column moves together with the work
173
184
 
174
185
  Branch created — the task is no longer in `📋 Backlog` but in progress. PR opened — it awaits
@@ -190,9 +201,11 @@ and nobody was waiting to review it.
190
201
 
191
202
  ## The commit is signed by the bot
192
203
 
193
- The token is read into a variable and not printed; author and committer are set by variables of
194
- the same command. `git config` will not do — the config is shared with the main tree and would
195
- rewrite the signature to the owner:
204
+ The token is read into a variable and not printed; author and committer are set by variables
205
+ prefixed to `git commit` itself. `git config` will not do — the config is shared with the main tree
206
+ and would rewrite the signature to the owner. `export` will not do either: it reaches every later
207
+ command of the call, and a set before a push started by the same call runs the hook scenarios under
208
+ the bot's mail — the ones comparing a mail fall on a sound tree:
196
209
 
197
210
  ```bash
198
211
  TOKEN=$(tr -d '\n' < ~/.config/<дерево>-bot-token)
@@ -135,9 +135,11 @@ The move is not put off for later: the work queue is read between steps, not aft
135
135
 
136
136
  ## The commit is signed by the machine account
137
137
 
138
- The token is read into a variable and not printed; author and committer are set by variables of
139
- the same command. `git config` will not do — the config is shared with the main tree and would
140
- rewrite the signature to the owner:
138
+ The token is read into a variable and not printed; author and committer are set by variables
139
+ prefixed to `git commit` itself. `git config` will not do — the config is shared with the main tree
140
+ and would rewrite the signature to the owner. `export` will not do either: it reaches every later
141
+ command of the call, and a set before a push started by the same call runs the hook scenarios under
142
+ the bot's mail — the ones comparing a mail fall on a sound tree:
141
143
 
142
144
  ```bash
143
145
  TOKEN=$(tr -d '\n' < ~/.config/<дерево>-bot-token)
@@ -98,9 +98,14 @@ things about the tree, and the tree has changed since.
98
98
 
99
99
  ## PR body sample
100
100
 
101
- Four sections, and one order between them: the link line, what was done, what confirms it, the
102
- remaining step. A section with nothing to say says so in words — an empty heading and a removed
103
- heading read alike and mean different things.
101
+ Six sections, and one order between them: the link line, what was done, the points, the goal, what
102
+ confirms it, the remaining step. A section with nothing to say says so in words — an empty heading
103
+ and a removed heading read alike and mean different things.
104
+
105
+ The table of points comes from the reply of the role `product-strategist`: a sign not run is
106
+ written as not run, and its point as not reached. The table of the goal comes from the reply of the
107
+ role `goal-critic`. Both go in word for word, and the critic reads the finished body against the
108
+ replies.
104
109
 
105
110
  ```markdown
106
111
  Closes #86
@@ -109,6 +114,18 @@ Closes #86
109
114
 
110
115
  - <правка, названная тем, что она меняет для читателя, а не тем, какие файлы задела>
111
116
 
117
+ ## Точки
118
+
119
+ | Точка | Признак | Результат |
120
+ | --- | --- | --- |
121
+ | <изменение, которое увидит человек> | <команда, страница или число> | <вывод признака: достигнута или промах> |
122
+
123
+ ## Цель
124
+
125
+ | Слова владельца | Что показывает результат | Итог |
126
+ | --- | --- | --- |
127
+ | <дословная цитата> | <что видно в результате> | <выполнено или нет> |
128
+
112
129
  ## Чем подтверждено
113
130
 
114
131
  - <проверка>: <её вывод одной строкой>
@@ -160,6 +160,36 @@ An open PR means the work item awaits review — the state is moved in the same
160
160
  npm run task:move -- 86 in-review
161
161
  ```
162
162
 
163
+ ## Answering under remarks
164
+
165
+ Remarks on a PR live in threads, and the client has no command for them, so they go through the
166
+ REST call of the same client. They are read at once, before the first edit:
167
+
168
+ ```bash
169
+ az devops invoke --area git --resource pullRequestThreads \
170
+ --route-parameters project=<проект> repositoryId=<репозиторий> pullRequestId=<номер> \
171
+ --api-version 7.1 --query "value[?comments[0].commentType=='text'].{id:id, text:comments[0].content}"
172
+ ```
173
+
174
+ The person is asked by the asking tool whether to answer under them, in the turn the remarks were
175
+ read. The answer holds for this PR. Silence is not a yes: a message on the host stays there, and
176
+ it goes out under an account the person answers for.
177
+
178
+ After a yes every thread gets its own answer, once the edit has reached the host: a commit named
179
+ before the push does not exist for the reader yet.
180
+
181
+ ```bash
182
+ az devops invoke --area git --resource pullRequestThreadComments --http-method POST \
183
+ --route-parameters project=<проект> repositoryId=<репозиторий> pullRequestId=<номер> threadId=<id> \
184
+ --in-file ответ.json --api-version 7.1
185
+ ```
186
+
187
+ The file holds `{"content": "<текст>", "commentType": 1}`.
188
+
189
+ An answer is written in the owner's language and names one of two things: the commit that closes
190
+ the remark, or why the remark is declined. The count of answers is compared with the count of
191
+ threads read at the start: a remark left without one is a remark the person checks again by hand.
192
+
163
193
  ## What is checked before the PR is published
164
194
 
165
195
  The pipeline sees only what was sent, and it is sent by a push. Linters, unit tests and hook
@@ -139,6 +139,25 @@ no longer on the server: the push will not update it but create it anew, and the
139
139
  stays outside the main branch. The push answer says this with a new-branch mark instead of a list
140
140
  of commits — otherwise it looks exactly like a successful push.
141
141
 
142
+ **After a push that carries a merge of the base, the PR's count is matched against the comparison
143
+ of the branches.** The host counts the commits and files of a PR from the base commit it stored
144
+ when the PR opened or was last retargeted, and a push does not always move it. The base merged into
145
+ the branch then shows inside the PR as its own work: a PR with 30 commits of its own read as 153
146
+ with 371 files, while the comparison of the same branches answered 30 at the same minute. The count
147
+ is asked from both sides:
148
+
149
+ ```bash
150
+ $GH api "repos/$REPO/pulls/321" --jq '{base: .base.sha[0:9], commits: .commits, files: .changed_files}'
151
+ $GH api "repos/$REPO/compare/<база>...<ветка>" --jq '{ahead: .ahead_by, behind: .behind_by}'
152
+ ```
153
+
154
+ `commits` other than `ahead` is cured by setting the same base again — the host recounts the PR in
155
+ the same answer:
156
+
157
+ ```bash
158
+ $GH api -X PATCH "repos/$REPO/pulls/321" -f base=<база> --jq '{base: .base.sha[0:9], commits: .commits}'
159
+ ```
160
+
142
161
  **The run's outcome is read by a separate call, not by the wait's return code.** The client
143
162
  command that waits for the run's end returns zero on red too: it waited for the end, not for
144
163
  success. Read as an outcome, this zero makes green what fell, and what was said to the owner
@@ -155,6 +174,42 @@ This is not written as bare GraphQL by project, item and field option ids: the c
155
174
  them itself, and a query assembled from memory silently sets the wrong column — the board has no
156
175
  refusal for that.
157
176
 
177
+ ## Answering under remarks
178
+
179
+ Remarks arrive on a PR in three places: a comment on a line, the text of a review and a comment in
180
+ the conversation. All three are read at once, before the first edit:
181
+
182
+ ```bash
183
+ gh api repos/<владелец>/<репозиторий>/pulls/<номер>/comments --paginate \
184
+ --jq '.[] | {id, user: .user.login, path, body}'
185
+ gh api repos/<владелец>/<репозиторий>/pulls/<номер>/reviews --paginate \
186
+ --jq '.[] | select(.body != "") | {id, user: .user.login, body}'
187
+ gh api repos/<владелец>/<репозиторий>/issues/<номер>/comments --paginate \
188
+ --jq '.[] | {id, user: .user.login, body}'
189
+ ```
190
+
191
+ The person is asked by the asking tool whether to answer under them, in the turn the remarks were
192
+ read. The answer holds for this PR. Silence is not a yes: a message on the host stays there, and
193
+ it goes out under an account the person answers for.
194
+
195
+ After a yes every remark gets its own answer, once the edit has reached the host: a commit named
196
+ before the push does not exist for the reader yet.
197
+
198
+ ```bash
199
+ gh api -X POST repos/<владелец>/<репозиторий>/pulls/<номер>/comments/<id>/replies \
200
+ -F body=@ответ.md
201
+ ```
202
+
203
+ The text of a review has no thread of its own, so the answer to it goes into the PR conversation:
204
+
205
+ ```bash
206
+ gh api -X POST repos/<владелец>/<репозиторий>/issues/<номер>/comments -F body=@ответ.md
207
+ ```
208
+
209
+ An answer is written in the owner's language and names one of two things: the commit that closes
210
+ the remark, or why the remark is declined. The count of answers is compared with the count of
211
+ remarks read at the start: a remark left without one is a remark the person checks again by hand.
212
+
158
213
  ## What is checked before the PR is published
159
214
 
160
215
  There are no checks on the PR itself: the rollout starts with a push into the main branch, and
@@ -195,7 +250,8 @@ push gate — below is what it does not know.
195
250
  12. **The work queue matches** — `npm run check:board`. The task is on the board, with an
196
251
  assignee and the number in the title; one PR per task, and it closes the task whole.
197
252
  13. **The PR state is read, not derived from return codes** — author `<бот>`, reviewer — the
198
- owner, labels the same as on the task. The owner is told what was read.
253
+ owner, labels the same as on the task, the commit count equal to `ahead_by` of the branch
254
+ comparison. The owner is told what was read.
199
255
  14. **The set is taken from the pipeline file, not assembled from memory.** The push gate is
200
256
  narrower by design: it stands between the command and the push, and everything longer than
201
257
  seconds is taken out of it. What the pipeline runs is written in its file — that list is