@rt-tools/agent-kit 0.34.0 → 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 (117) hide show
  1. package/README.md +6 -6
  2. package/assets/agents/goal-critic.md +9 -0
  3. package/assets/agents/product-strategist.md +5 -0
  4. package/assets/defaults/project.sh +39 -0
  5. package/assets/hooks/browser-guard-device-id.sh +1 -0
  6. package/assets/hooks/browser-guard-no-asking.sh +1 -0
  7. package/assets/hooks/browser-guard-no-listing.sh +1 -0
  8. package/assets/hooks/browser-guard-no-other-drivers.sh +1 -0
  9. package/assets/hooks/browser-guard-require-select.sh +1 -0
  10. package/assets/hooks/claim-guard.sh +1 -0
  11. package/assets/hooks/dev-server-guard.sh +1 -0
  12. package/assets/hooks/docs-guard.sh +1 -0
  13. package/assets/hooks/end-conversation-guard.sh +1 -0
  14. package/assets/hooks/epic-stop-guard.sh +1 -0
  15. package/assets/hooks/exam-guard.sh +5 -0
  16. package/assets/hooks/git-guard-delivery-draft.sh +23 -0
  17. package/assets/hooks/git-guard-delivery-folder.sh +25 -4
  18. package/assets/hooks/git-guard-delivery-signature.sh +19 -0
  19. package/assets/hooks/git-guard-delivery.sh +7 -18
  20. package/assets/hooks/git-guard-discard.sh +1 -0
  21. package/assets/hooks/git-guard-main.sh +1 -0
  22. package/assets/hooks/git-guard-no-verify.sh +1 -0
  23. package/assets/hooks/git-guard-push-ahead.sh +9 -0
  24. package/assets/hooks/git-guard-push-tests.sh +1 -0
  25. package/assets/hooks/grill-gate.sh +1 -0
  26. package/assets/hooks/guard-note.sh +11 -3
  27. package/assets/hooks/handover-mark.sh +37 -0
  28. package/assets/hooks/metric-marks.sh +233 -0
  29. package/assets/hooks/metric-send-start.sh +38 -0
  30. package/assets/hooks/observe.sh +103 -0
  31. package/assets/hooks/owner-corrections.sh +36 -0
  32. package/assets/hooks/prose-style-guard.sh +1 -0
  33. package/assets/hooks/pull-outcomes.sh +59 -0
  34. package/assets/hooks/push-set.sh +11 -1
  35. package/assets/hooks/qa-dataid-guard.sh +1 -0
  36. package/assets/hooks/rerun-guard.sh +1 -0
  37. package/assets/hooks/reuse-first-guard.sh +1 -0
  38. package/assets/hooks/role-calls.sh +120 -0
  39. package/assets/hooks/rule-source-guard.sh +16 -0
  40. package/assets/hooks/skill-gate.sh +11 -0
  41. package/assets/hooks/task-flow-draft-guard.sh +1 -0
  42. package/assets/hooks/task-flow-guard.sh +1 -0
  43. package/assets/hooks/tree-assignment-guard.sh +1 -0
  44. package/assets/hooks/turn-exit-epic.sh +24 -0
  45. package/assets/hooks/turn-exit-guard.sh +1 -21
  46. package/assets/hooks/waiting-turn-guard.sh +1 -0
  47. package/assets/hooks/window-fill-guard.sh +1 -0
  48. package/assets/hooks/work-start-guard.sh +1 -0
  49. package/assets/patterns/git-workflow-commit.azure.md +5 -3
  50. package/assets/patterns/git-workflow-commit.github.md +5 -3
  51. package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
  52. package/assets/patterns/task-flow-close.md +5 -6
  53. package/assets/patterns/task-flow-cycle.md +72 -0
  54. package/assets/rules/task-flow.md +10 -9
  55. package/assets/samples/tasks/_template/plan.md +1 -0
  56. package/assets/templates/postmortem.md +2 -0
  57. package/bin/agent-kit.d.ts.map +1 -1
  58. package/bin/agent-kit.js +28 -0
  59. package/bin/agent-kit.js.map +1 -1
  60. package/lib/cargo.d.ts +35 -0
  61. package/lib/cargo.d.ts.map +1 -1
  62. package/lib/cargo.js +76 -0
  63. package/lib/cargo.js.map +1 -1
  64. package/lib/commands.d.ts +9 -0
  65. package/lib/commands.d.ts.map +1 -1
  66. package/lib/commands.js +32 -19
  67. package/lib/commands.js.map +1 -1
  68. package/lib/config.d.ts +5 -0
  69. package/lib/config.d.ts.map +1 -1
  70. package/lib/config.js +1 -0
  71. package/lib/config.js.map +1 -1
  72. package/lib/file-lock.d.ts +4 -0
  73. package/lib/file-lock.d.ts.map +1 -0
  74. package/lib/file-lock.js +23 -0
  75. package/lib/file-lock.js.map +1 -0
  76. package/lib/metric-lines.d.ts +20 -0
  77. package/lib/metric-lines.d.ts.map +1 -0
  78. package/lib/metric-lines.js +117 -0
  79. package/lib/metric-lines.js.map +1 -0
  80. package/lib/metric-send-mark.d.ts +52 -0
  81. package/lib/metric-send-mark.d.ts.map +1 -0
  82. package/lib/metric-send-mark.js +69 -0
  83. package/lib/metric-send-mark.js.map +1 -0
  84. package/lib/metric-send.d.ts +18 -0
  85. package/lib/metric-send.d.ts.map +1 -0
  86. package/lib/metric-send.js +226 -0
  87. package/lib/metric-send.js.map +1 -0
  88. package/lib/metric-usage.d.ts +34 -0
  89. package/lib/metric-usage.d.ts.map +1 -0
  90. package/lib/metric-usage.js +111 -0
  91. package/lib/metric-usage.js.map +1 -0
  92. package/lib/metrics.d.ts +92 -0
  93. package/lib/metrics.d.ts.map +1 -0
  94. package/lib/metrics.js +263 -0
  95. package/lib/metrics.js.map +1 -0
  96. package/lib/observations-cargo.d.ts +2 -0
  97. package/lib/observations-cargo.d.ts.map +1 -1
  98. package/lib/observations-cargo.js +1 -1
  99. package/lib/observations-cargo.js.map +1 -1
  100. package/lib/observations.d.ts +22 -2
  101. package/lib/observations.d.ts.map +1 -1
  102. package/lib/observations.js +40 -13
  103. package/lib/observations.js.map +1 -1
  104. package/lib/outcomes.d.ts +89 -0
  105. package/lib/outcomes.d.ts.map +1 -0
  106. package/lib/outcomes.js +274 -0
  107. package/lib/outcomes.js.map +1 -0
  108. package/lib/ship.js +1 -1
  109. package/lib/ship.js.map +1 -1
  110. package/lib/shipment.d.ts.map +1 -1
  111. package/lib/shipment.js +7 -1
  112. package/lib/shipment.js.map +1 -1
  113. package/lib/snapshot.d.ts +2 -0
  114. package/lib/snapshot.d.ts.map +1 -1
  115. package/lib/snapshot.js +6 -0
  116. package/lib/snapshot.js.map +1 -1
  117. 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
 
@@ -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
@@ -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
@@ -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)
@@ -201,9 +201,11 @@ and nobody was waiting to review it.
201
201
 
202
202
  ## The commit is signed by the bot
203
203
 
204
- The token is read into a variable and not printed; author and committer are set by variables of
205
- the same command. `git config` will not do — the config is shared with the main tree and would
206
- 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:
207
209
 
208
210
  ```bash
209
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)
@@ -204,12 +204,6 @@ judged at all. Without the guard the section is held only by whoever writes the
204
204
  The work queue audit still does not read the body: the miss is caught at the minute of opening, that
205
205
  is, where one call still fixes it.
206
206
 
207
- An open PR is re-read by the account that will merge it, not by the one that opened it. The host's
208
- answer to the author says only that the call went through: the right to open and the visibility of
209
- what was opened are different things, and the second is checked only from the reader's side. An
210
- invisible PR gives itself away by nothing — it is in the answer to its author, it carries labels,
211
- and the owner's review queue is simply empty.
212
-
213
207
  The difference between the section and the spoken word is one, and it is all. The owner reads a
214
208
  message only if they return to the conversation, and the section they see where they look when
215
209
  pressing the button.
@@ -292,6 +286,11 @@ git fetch origin && git merge origin/main # the main branch is merged in
292
286
  A folder left in the epic branch reaches the main branch with it: what one branch needed becomes the
293
287
  tree's for good. A foreign folder, arrived with a merge of the main branch, is not touched.
294
288
 
289
+ **A step of the milestone that the merge does not make gets a holder before the request opens.** A
290
+ release, a rollout, an install in the consumers and a task taken out of the epic belong to no task
291
+ of it, and after the merge nothing keeps them: each becomes a task in the work queue in the same
292
+ turn, and the body of the request names their numbers.
293
+
295
294
  The body is written the same way as a task's, and its "Что сделано" is the list of the tasks by
296
295
  number: the reviewer opens one page instead of five. The plan of the epic stays in the tree — it
297
296
  outlives the branch.
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: task-flow-cycle
3
+ kind: pattern
4
+ rule: task-flow
5
+ description: Pattern of rule task-flow. Load when an edit of a rule, a hook, a check or a role is chosen and when its result is judged. The worst driver from the report, one metric and its direction in the task, the verdict from the next report, and the plain name of an edit that moved nothing.
6
+ ---
7
+
8
+ # The improvement cycle
9
+
10
+ Pattern of the rule `task-flow`. What must be true meanwhile — the law
11
+ `docs/constitution/work-conduct.md`.
12
+
13
+ ## When to use
14
+
15
+ - An edit of a rule, a hook, a check or a role is being chosen.
16
+ - A task about such an edit is being written.
17
+ - The result of such an edit is being judged.
18
+
19
+ An edit chosen by opinion has no way to be proved wrong, so nobody learns whether it helped. A repair
20
+ of something broken is not an improvement and needs no cycle: its task names the failure instead.
21
+
22
+ ## Order
23
+
24
+ ### The report opens the cycle
25
+
26
+ The cycle begins with the numbers, not with an idea of what to improve.
27
+
28
+ ```bash
29
+ npx agent-kit metrics
30
+ ```
31
+
32
+ The worst driver of the main metric is named with its numbers: which resource, how many refusals,
33
+ runs or minutes. A tree that sends its numbers reads the same in the receiver over all its copies. No
34
+ data means no cycle: the text says so, and nothing is chosen by a guess.
35
+
36
+ ### One task, one metric, one direction
37
+
38
+ The task changes one thing and carries one line:
39
+
40
+ ```markdown
41
+ **Metric:** empty refusals of `git-guard-push`, down. Baseline: 0.42 over 30 days, noise 0.05.
42
+ ```
43
+
44
+ - **The direction is a word, not a target.** A target needs a baseline first, and two weeks of data
45
+ or ten accepted tasks come before one.
46
+ - **Two metrics mean two tasks.** Two edits in one release cannot be told apart in the next report.
47
+ - **The edit does not raise its own numbers.** The observations are not edited, and a metric is not
48
+ redefined by the task that is judged by it.
49
+
50
+ ### The next report gives the verdict
51
+
52
+ The same trees are compared, on a version with the edit against themselves before it. A tree that has
53
+ not installed the version does not count.
54
+
55
+ - **The executor who made the edit gives no verdict.** The role `goal-critic` reads the numbers.
56
+ - **A movement below the noise is not a result.** The noise is the spread of the metric between the
57
+ weeks of the baseline, and it is named with it.
58
+
59
+ ### An edit that moved nothing is named so
60
+
61
+ The report says «не сдвинулось», with the two numbers. It is not reworded as a partial success and not
62
+ explained by the days being unusual. Such an edit is reverted or kept by a decision of the owner, and
63
+ the next cycle starts from the report again.
64
+
65
+ ## Common misses
66
+
67
+ - **A metric picked after the edit.** A number chosen once the result is known finds a movement in any
68
+ edit. The line stands in the task before the first commit.
69
+ - **Reading one's own tree as the package.** One tree is the partial view: it lacks completeness and
70
+ repeated mistakes.
71
+ - **A rising count taken for a worse rule.** More refusals also come from more work. A share is read
72
+ against its denominator.
@@ -195,12 +195,12 @@ flowchart TD
195
195
  rule by rule before the first stage: a rule with no stage is found at the merge review, when the
196
196
  code is written.
197
197
  - **A stage's readiness sign is taken from the output of a command run while the plan is written.**
198
- Written by a guess, it is checked at the stage itself — latest of everything that depended on it.
198
+ Written by a guess, it fails at the stage itself.
199
199
  - **A plan for work that ports a technique from outside is written by a measurement of one's own
200
200
  code.** Reading the sample says how it is built; what is needed here is said by a count over
201
201
  one's own files.
202
202
  - **A count that becomes the measure of the work is bounded by the declaration, not by the file.**
203
- A file holds neighbouring sets too: a count over it came out twice the real measure.
203
+ A file holds neighbouring sets too.
204
204
  - **Waiting for one part of a stage is never a stop of the stage.** The parts independent of what is
205
205
  awaited are done in the same turn; the owner is told what is done and what is left for their step.
206
206
  - **A finding made mid-stage is checked against the plan's exit conditions before the first edit.**
@@ -247,6 +247,8 @@ flowchart TD
247
247
  - **The plan names the points: the epic its milestone, the task the change a person will see.** The
248
248
  role `product-strategist` tries to prove the miss in planning and before the PR. A proved miss is
249
249
  fixed or named to the owner; no pipeline stops. Every PR body carries the table of points.
250
+ - **An edit of a rule names the metric it should move, and the next report judges it.** An edit that
251
+ moved nothing is named so. The technique is the pattern `task-flow-cycle`.
250
252
  - **Work is judged by the role `goal-critic` against the owner's words.** A plan is no evidence to
251
253
  it, its reply is not edited, and the PR body carries its table.
252
254
  - **A mission is set by the owner.** A session only proposes a wording from its analysis and waits
@@ -261,13 +263,11 @@ flowchart TD
261
263
  - **What acts on the tree, not on the edit, lies outside the index.** The path to the sample and the
262
264
  permission to work outside the epic do not belong to the branch and live next to the handover. A
263
265
  number in the permitted list repeats the owner's word, not replaces it.
264
- - **Closed work is reviewed by the rules as a closing step, not as a separate request.** What was
265
- loaded and what was missing is seen only by the session that led the work.
266
- - **The review of closed work goes to the background, and the executor takes the next task.** The
267
- digest is gathered before the launch, the findings are accepted in one turn.
268
- - **The review's findings wait for the owner, and only the digest of observations leaves for the
269
- package.** A proposal sent unreviewed becomes the work of someone who did not order it. The digest
270
- is always sent: it says what was used and is never an opinion.
266
+ - **Closed work is reviewed by the rules in the background, right after the PR, and its findings
267
+ wait for the owner.** Only the session that led the work sees what was loaded and what was
268
+ missing, and it takes the next task meanwhile. A proposal sent unreviewed becomes the work of
269
+ someone who did not order it; only the digest of observations leaves, always. The technique is
270
+ the pattern `task-flow-archive`.
271
271
  - **The cheap closing step goes before the costly one, and the run — after the merge.** A run
272
272
  before the merge checks what will not reach main.
273
273
  - **The agreement merges into the domain spec by one of the last commits of the branch, before the
@@ -321,3 +321,4 @@ nothing counts; it is held by reading both texts in a row on every such edit.
321
321
  - `task-flow-resume` — returning to unfinished work in a new session.
322
322
  - `task-flow-close` — lifting the draft, merging the agreement, bringing the texts up to date.
323
323
  - `task-flow-archive` — taking the task folder apart, the move to the archive, review by the rules.
324
+ - `task-flow-cycle` — an edit chosen by the report and judged by the next one.
@@ -19,6 +19,7 @@ along the way.
19
19
  - **This task reaches:** <the change a person will see>
20
20
  - **Sign:** <the command, the page or the number that shows it, and who sees it>
21
21
  - **Milestone G of the epic:** <the point named in the epic plan>
22
+ - **Metric:** <only for an edit of a rule, a hook, a check or a role: the number, the direction, the baseline — pattern `task-flow-cycle`>
22
23
 
23
24
  ## Task footprint
24
25
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  <date>. <One line: where the work was going and how far it got.>
4
4
 
5
+ **Resource:** <the resource of the package the miss is about, by its identifier, such as `rules/testing.md`>
6
+
5
7
  ## What happened
6
8
 
7
9
  <What the executor did and in what way it was wrong. Without appraisals: the mechanism is
@@ -1 +1 @@
1
- {"version":3,"file":"agent-kit.d.ts","sourceRoot":"","sources":["../../../projects/agent-kit/src/bin/agent-kit.ts"],"names":[],"mappings":";AAeA,OAAO,EAAqC,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;AAgX7G,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAU9E"}
1
+ {"version":3,"file":"agent-kit.d.ts","sourceRoot":"","sources":["../../../projects/agent-kit/src/bin/agent-kit.ts"],"names":[],"mappings":";AAeA,OAAO,EAAqC,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;AA+Y7G,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAU9E"}
package/bin/agent-kit.js CHANGED
@@ -20,6 +20,8 @@ import { httpReadOwn, httpShip } from '../lib/ship.js';
20
20
  import { fate } from '../lib/fate.js';
21
21
  import { propose } from '../lib/shipment.js';
22
22
  import { treeSlugOf } from '../lib/tree-mark.js';
23
+ import { sendMetrics } from '../lib/metric-send.js';
24
+ import { METRICS_DEFAULT_DAYS, metrics } from '../lib/metrics.js';
23
25
  import { DEFAULT_DAYS } from '../lib/observations.js';
24
26
  import { staleBuild } from '../lib/freshness.js';
25
27
  import { packageRootFrom } from '../lib/package-root.js';
@@ -39,6 +41,11 @@ const USAGE = [
39
41
  ' stats свести наблюдения: чем пользовались, чем ни разу, обо что спотыкались',
40
42
  ' stats --days N за сколько дней; без довода — за три',
41
43
  ' stats --json то же машиночитаемо — этим сводку прикладывают к предложению',
44
+ ' metrics метрики дерева: отказы, повторы, мёртвые правила, вес входа',
45
+ ' metrics --days N за сколько дней; без довода — за тридцать',
46
+ ' metrics --json то же машиночитаемо',
47
+ ' send отправить строки дня: только числа, без разборов и предложений',
48
+ ' send --quiet то же молча: так зовут проверки',
42
49
  ' propose отправить груз в приём: сводку со снимком надстроек, предложения и разборы',
43
50
  ' fate судьба своих записей в приёме и надстройки, которые пора снять',
44
51
  ' propose --dry-run показать, что уехало бы, и ничего не отправлять',
@@ -259,6 +266,25 @@ function runStats(env, argv) {
259
266
  json: argv.includes('--json'),
260
267
  });
261
268
  }
269
+ /** Метрики дерева: отрезок из флага, сегодняшний день — с края. */
270
+ function runMetrics(env, argv) {
271
+ const spoken = Number(optionOf(argv, '--days', ''));
272
+ return metrics(env, {
273
+ days: Number.isFinite(spoken) && spoken > 0 ? Math.floor(spoken) : METRICS_DEFAULT_DAYS,
274
+ today: new Date().toISOString().slice(0, 10),
275
+ json: argv.includes('--json'),
276
+ });
277
+ }
278
+ /** Строки дня: только числа, зовут проверки и человек. Часы берутся здесь же, на краю. */
279
+ function runSend(env, argv) {
280
+ return sendMetrics(env, {
281
+ quiet: argv.includes('--quiet'),
282
+ force: argv.includes('--session-end'),
283
+ now: new Date(),
284
+ remote: remoteOf(env.root),
285
+ ship: httpShip,
286
+ });
287
+ }
262
288
  /**
263
289
  * Отправка накопленного.
264
290
  *
@@ -315,6 +341,8 @@ const COMMANDS = {
315
341
  sync: (env, argv) => sync(env, argv.includes('--check')),
316
342
  cost: runCost,
317
343
  stats: runStats,
344
+ metrics: runMetrics,
345
+ send: runSend,
318
346
  propose: runPropose,
319
347
  fate: runFate,
320
348
  enroll: runEnroll,