@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.
- package/README.md +6 -6
- package/assets/agents/goal-critic.md +9 -0
- package/assets/agents/product-strategist.md +5 -0
- package/assets/defaults/project.sh +39 -0
- package/assets/hooks/browser-guard-device-id.sh +1 -0
- package/assets/hooks/browser-guard-no-asking.sh +1 -0
- package/assets/hooks/browser-guard-no-listing.sh +1 -0
- package/assets/hooks/browser-guard-no-other-drivers.sh +1 -0
- package/assets/hooks/browser-guard-require-select.sh +1 -0
- package/assets/hooks/claim-guard.sh +1 -0
- package/assets/hooks/dev-server-guard.sh +1 -0
- package/assets/hooks/docs-guard.sh +1 -0
- package/assets/hooks/end-conversation-guard.sh +1 -0
- package/assets/hooks/epic-stop-guard.sh +1 -0
- package/assets/hooks/exam-guard.sh +5 -0
- package/assets/hooks/git-guard-delivery-draft.sh +23 -0
- package/assets/hooks/git-guard-delivery-folder.sh +25 -4
- package/assets/hooks/git-guard-delivery-signature.sh +19 -0
- package/assets/hooks/git-guard-delivery.sh +7 -18
- package/assets/hooks/git-guard-discard.sh +1 -0
- package/assets/hooks/git-guard-main.sh +1 -0
- package/assets/hooks/git-guard-no-verify.sh +1 -0
- package/assets/hooks/git-guard-push-ahead.sh +9 -0
- package/assets/hooks/git-guard-push-tests.sh +1 -0
- package/assets/hooks/grill-gate.sh +1 -0
- package/assets/hooks/guard-note.sh +11 -3
- package/assets/hooks/handover-mark.sh +37 -0
- package/assets/hooks/metric-marks.sh +233 -0
- package/assets/hooks/metric-send-start.sh +38 -0
- package/assets/hooks/observe.sh +103 -0
- package/assets/hooks/owner-corrections.sh +36 -0
- package/assets/hooks/prose-style-guard.sh +1 -0
- package/assets/hooks/pull-outcomes.sh +59 -0
- package/assets/hooks/push-set.sh +11 -1
- package/assets/hooks/qa-dataid-guard.sh +1 -0
- package/assets/hooks/rerun-guard.sh +1 -0
- package/assets/hooks/reuse-first-guard.sh +1 -0
- package/assets/hooks/role-calls.sh +120 -0
- package/assets/hooks/rule-source-guard.sh +16 -0
- package/assets/hooks/skill-gate.sh +11 -0
- package/assets/hooks/task-flow-draft-guard.sh +1 -0
- package/assets/hooks/task-flow-guard.sh +1 -0
- package/assets/hooks/tree-assignment-guard.sh +1 -0
- package/assets/hooks/turn-exit-epic.sh +24 -0
- package/assets/hooks/turn-exit-guard.sh +1 -21
- package/assets/hooks/waiting-turn-guard.sh +1 -0
- package/assets/hooks/window-fill-guard.sh +1 -0
- package/assets/hooks/work-start-guard.sh +1 -0
- package/assets/patterns/git-workflow-commit.azure.md +5 -3
- package/assets/patterns/git-workflow-commit.github.md +5 -3
- package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
- package/assets/patterns/task-flow-close.md +5 -6
- package/assets/patterns/task-flow-cycle.md +72 -0
- package/assets/rules/task-flow.md +10 -9
- package/assets/samples/tasks/_template/plan.md +1 -0
- package/assets/templates/postmortem.md +2 -0
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +28 -0
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo.d.ts +35 -0
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +76 -0
- package/lib/cargo.js.map +1 -1
- package/lib/commands.d.ts +9 -0
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +32 -19
- package/lib/commands.js.map +1 -1
- package/lib/config.d.ts +5 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -0
- package/lib/config.js.map +1 -1
- package/lib/file-lock.d.ts +4 -0
- package/lib/file-lock.d.ts.map +1 -0
- package/lib/file-lock.js +23 -0
- package/lib/file-lock.js.map +1 -0
- package/lib/metric-lines.d.ts +20 -0
- package/lib/metric-lines.d.ts.map +1 -0
- package/lib/metric-lines.js +117 -0
- package/lib/metric-lines.js.map +1 -0
- package/lib/metric-send-mark.d.ts +52 -0
- package/lib/metric-send-mark.d.ts.map +1 -0
- package/lib/metric-send-mark.js +69 -0
- package/lib/metric-send-mark.js.map +1 -0
- package/lib/metric-send.d.ts +18 -0
- package/lib/metric-send.d.ts.map +1 -0
- package/lib/metric-send.js +226 -0
- package/lib/metric-send.js.map +1 -0
- package/lib/metric-usage.d.ts +34 -0
- package/lib/metric-usage.d.ts.map +1 -0
- package/lib/metric-usage.js +111 -0
- package/lib/metric-usage.js.map +1 -0
- package/lib/metrics.d.ts +92 -0
- package/lib/metrics.d.ts.map +1 -0
- package/lib/metrics.js +263 -0
- package/lib/metrics.js.map +1 -0
- package/lib/observations-cargo.d.ts +2 -0
- package/lib/observations-cargo.d.ts.map +1 -1
- package/lib/observations-cargo.js +1 -1
- package/lib/observations-cargo.js.map +1 -1
- package/lib/observations.d.ts +22 -2
- package/lib/observations.d.ts.map +1 -1
- package/lib/observations.js +40 -13
- package/lib/observations.js.map +1 -1
- package/lib/outcomes.d.ts +89 -0
- package/lib/outcomes.d.ts.map +1 -0
- package/lib/outcomes.js +274 -0
- package/lib/outcomes.js.map +1 -0
- package/lib/ship.js +1 -1
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +7 -1
- package/lib/shipment.js.map +1 -1
- package/lib/snapshot.d.ts +2 -0
- package/lib/snapshot.d.ts.map +1 -1
- package/lib/snapshot.js +6 -0
- package/lib/snapshot.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Signs of content and of calls for the package metrics. NOT a guard: it has no `rt-hook:`
|
|
3
|
+
# declaration and hooks into no agent event. The refusal record and the push set source it.
|
|
4
|
+
#
|
|
5
|
+
# WHY A FILE OF ITS OWN. An observation names a resource and a number, and it leaves the tree. To
|
|
6
|
+
# tell an empty refusal from an honest one, and a wasted run from a needed one, the tree has to
|
|
7
|
+
# compare what it judged, and that sign must not leave. So the tree decides here and writes only the
|
|
8
|
+
# answer into the observation.
|
|
9
|
+
#
|
|
10
|
+
# WHERE IT LIVES. In `.marks` inside the observations directory: git ignores that directory, and
|
|
11
|
+
# the digest reads day files only.
|
|
12
|
+
#
|
|
13
|
+
# FAIL-OPEN. No directory, no git, no `cksum`: the answer is empty and the caller records nothing.
|
|
14
|
+
# A metric is side work, and a guard that fell over on it would stop the work for statistics.
|
|
15
|
+
|
|
16
|
+
# The record itself: the push set runs in a git hook too, where nothing else has sourced it.
|
|
17
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/observe.sh" 2>/dev/null || true
|
|
18
|
+
|
|
19
|
+
# How long a mark about a refusal or a run lives. It compares neighbours, and a month covers them.
|
|
20
|
+
RT_MARKS_KEEP_DAYS=30
|
|
21
|
+
|
|
22
|
+
# The marks directory of this tree. An empty string — observations are off. The directory ignores
|
|
23
|
+
# itself: a fresh tree has no line about it, and `git add -A` would carry the signs into its history.
|
|
24
|
+
rt_marks_dir() {
|
|
25
|
+
local dir
|
|
26
|
+
dir="$(rt_observe_dir 2>/dev/null)"
|
|
27
|
+
[ -n "$dir" ] || return 0
|
|
28
|
+
mkdir -p "$dir/.marks" 2>/dev/null || return 0
|
|
29
|
+
[ -f "$dir/.gitignore" ] || printf '*\n' > "$dir/.gitignore" 2>/dev/null
|
|
30
|
+
printf '%s' "$dir/.marks"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# The marks one tree shares across its copies. A request is handed over from one copy and read by
|
|
34
|
+
# another, and a sign left in the first one would put the request outside the main metric for good.
|
|
35
|
+
rt_shared_marks_dir() {
|
|
36
|
+
local CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR:-}" main
|
|
37
|
+
main="$(git -C "$(rt_sign_root)" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
|
|
38
|
+
[ -n "$main" ] && CLAUDE_PROJECT_DIR="$(dirname "$main")"
|
|
39
|
+
rt_marks_dir
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# The copy a guard judges: the session may stand in a working copy other than the project root, and
|
|
43
|
+
# a sign of the root would call a real edit in that copy no change at all.
|
|
44
|
+
rt_sign_root() {
|
|
45
|
+
local cwd
|
|
46
|
+
cwd="$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -r '.cwd // empty' 2>/dev/null)"
|
|
47
|
+
if [ -n "$cwd" ] && [ -d "$cwd" ]; then
|
|
48
|
+
printf '%s' "$cwd"
|
|
49
|
+
else
|
|
50
|
+
printf '%s' "${CLAUDE_PROJECT_DIR:-.}"
|
|
51
|
+
fi
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# The sign of a working copy: the commit, the uncommitted edits and the untracked files. Without
|
|
55
|
+
# the edits a red run fixed in the working copy would read as a repeat of the same content. The
|
|
56
|
+
# observations themselves stay out of it: a tree that does not ignore them would change its sign
|
|
57
|
+
# with every refusal, and no repeat would ever be seen.
|
|
58
|
+
#
|
|
59
|
+
# rt_tree_sign <any directory of the copy>
|
|
60
|
+
rt_tree_sign() {
|
|
61
|
+
local top
|
|
62
|
+
top="$(git -C "$1" rev-parse --show-toplevel 2>/dev/null)" || return 0
|
|
63
|
+
{
|
|
64
|
+
git -C "$top" rev-parse HEAD 2>/dev/null
|
|
65
|
+
git -C "$top" diff HEAD 2>/dev/null
|
|
66
|
+
git -C "$top" ls-files -o --exclude-standard -- . ':(exclude).claude/rt-kit/observations' 2>/dev/null \
|
|
67
|
+
| while IFS= read -r file; do
|
|
68
|
+
printf '%s ' "$file"
|
|
69
|
+
cksum < "$top/$file" 2>/dev/null
|
|
70
|
+
done
|
|
71
|
+
} | cksum 2>/dev/null | cut -d' ' -f1
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Is this refusal the same as the previous refusal of this guard in this session: `1` or `0`. The
|
|
75
|
+
# refused call and the content are both compared. Empty — there is nothing to compare by.
|
|
76
|
+
#
|
|
77
|
+
# rt_refusal_empty <guard> <session> <call>
|
|
78
|
+
rt_refusal_empty() {
|
|
79
|
+
local guard="$1" session="$2" call="$3" dir file sign previous=''
|
|
80
|
+
[ -n "$guard" ] && [ -n "$session" ] || return 0
|
|
81
|
+
dir="$(rt_marks_dir)"
|
|
82
|
+
[ -n "$dir" ] || return 0
|
|
83
|
+
|
|
84
|
+
sign="$(rt_tree_sign "$(rt_sign_root)") $(printf '%s' "$call" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
85
|
+
file="$dir/refusal-$(printf '%s' "$session $guard" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
86
|
+
[ -f "$file" ] && previous="$(cat "$file" 2>/dev/null)"
|
|
87
|
+
printf '%s' "$sign" > "$file" 2>/dev/null
|
|
88
|
+
|
|
89
|
+
if [ "$sign" = "$previous" ]; then printf '1'; else printf '0'; fi
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# The mark of a branch, by name of kind. The name of a branch is the tree's own, so it stays out of
|
|
93
|
+
# the file name too.
|
|
94
|
+
rt_branch_mark() {
|
|
95
|
+
local dir
|
|
96
|
+
dir="$(rt_shared_marks_dir)"
|
|
97
|
+
[ -n "$dir" ] && [ -n "$2" ] && printf '%s/%s-%s' "$dir" "$1" "$(printf '%s' "$2" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# The sign of a handover: the commit and the tree of the head at the moment a request is ready and
|
|
101
|
+
# has a reviewer. The first one stays: the work is judged against what was handed over first, and a
|
|
102
|
+
# later hand-over of the same branch would wash the change out of the count. The copy on the
|
|
103
|
+
# hosting goes first, because that is what the reviewer reads.
|
|
104
|
+
#
|
|
105
|
+
# rt_handover_mark <branch>
|
|
106
|
+
rt_handover_mark() {
|
|
107
|
+
local branch="$1" file root ref commit tree
|
|
108
|
+
file="$(rt_branch_mark handover "$branch")"
|
|
109
|
+
[ -n "$file" ] && [ ! -f "$file" ] || return 0
|
|
110
|
+
root="$(rt_sign_root)"
|
|
111
|
+
for ref in "refs/remotes/origin/$branch" "refs/heads/$branch"; do
|
|
112
|
+
commit="$(git -C "$root" rev-parse --verify --quiet "$ref^{commit}" 2>/dev/null)"
|
|
113
|
+
tree="$(git -C "$root" rev-parse --verify --quiet "$ref^{tree}" 2>/dev/null)"
|
|
114
|
+
if [ -n "$commit" ] && [ -n "$tree" ]; then
|
|
115
|
+
printf '%s %s\n' "$commit" "$tree" > "$file" 2>/dev/null
|
|
116
|
+
printf '%s\n' "$branch" > "$(dirname "$file")/handover-last" 2>/dev/null
|
|
117
|
+
return 0
|
|
118
|
+
fi
|
|
119
|
+
done
|
|
120
|
+
return 0
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Was this branch handed over. The default of `rt_pull_outcomes` asks the hosting only about those: a
|
|
124
|
+
# request without a sign counts apart, and asking about each of a hundred took two minutes.
|
|
125
|
+
rt_handover_known() {
|
|
126
|
+
local file
|
|
127
|
+
file="$(rt_branch_mark handover "$1")"
|
|
128
|
+
[ -n "$file" ] && [ -f "$file" ]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# The file of a handover about to happen. A guard passes the call before it runs, and another guard
|
|
132
|
+
# may still refuse it, so the guard only announces the branch, and the hook after the call keeps it.
|
|
133
|
+
rt_handover_pending_file() {
|
|
134
|
+
local dir
|
|
135
|
+
dir="$(rt_marks_dir)"
|
|
136
|
+
[ -n "$dir" ] && printf '%s/pending-%s' "$dir" "$(printf '%s %s' "$1" "$2" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
# One owner correction on the current branch: a line of the counter, `before` or `after` the
|
|
140
|
+
# handover, with its day. The message itself never gets here. First-pass acceptance reads the days
|
|
141
|
+
# of the `after` lines, because a correction counts for three days after the merge. The
|
|
142
|
+
# executor takes the next task right after a handover, so the last branch handed over gets the line
|
|
143
|
+
# too: by the current branch alone a correction of the handed work would count against nothing.
|
|
144
|
+
#
|
|
145
|
+
# rt_correction_mark <session>
|
|
146
|
+
rt_correction_mark() {
|
|
147
|
+
local session="$1" branch file handover last='' day
|
|
148
|
+
day="$(date -u +%Y-%m-%d 2>/dev/null)"
|
|
149
|
+
branch="$(git -C "$(rt_sign_root)" symbolic-ref --quiet --short HEAD 2>/dev/null)"
|
|
150
|
+
file="$(rt_branch_mark corrections "$branch")"
|
|
151
|
+
handover="$(rt_branch_mark handover "$branch")"
|
|
152
|
+
if [ -n "$file" ]; then
|
|
153
|
+
if [ -f "$handover" ]; then printf 'after %s\n' "$day"; else printf 'before %s\n' "$day"; fi >> "$file" 2>/dev/null
|
|
154
|
+
fi
|
|
155
|
+
handover="$(rt_shared_marks_dir)/handover-last"
|
|
156
|
+
[ -f "$handover" ] && last="$(cat "$handover" 2>/dev/null)"
|
|
157
|
+
if [ -n "$last" ] && [ "$last" != "$branch" ]; then
|
|
158
|
+
printf 'after %s\n' "$day" >> "$(rt_branch_mark corrections "$last")" 2>/dev/null
|
|
159
|
+
fi
|
|
160
|
+
command -v rt_note >/dev/null 2>&1 || return 0
|
|
161
|
+
rt_note owner-correction "sid=$session"
|
|
162
|
+
return 0
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
# The kind of a step by the command of the check. The list is closed: a kind leaves the tree, and
|
|
166
|
+
# the command itself must not.
|
|
167
|
+
rt_run_kind() {
|
|
168
|
+
case "$1" in
|
|
169
|
+
*e2e*) printf 'e2e' ;;
|
|
170
|
+
*visual* | *snapshot*) printf 'shots' ;;
|
|
171
|
+
*'docker build'*) printf 'image' ;;
|
|
172
|
+
*serve:*) printf 'stand' ;;
|
|
173
|
+
*test* | *lint* | *build*) printf 'tests' ;;
|
|
174
|
+
*) printf 'check' ;;
|
|
175
|
+
esac
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
# Old marks go by age. Only these kinds: a file that counts something once must outlive them.
|
|
179
|
+
rt_marks_prune() {
|
|
180
|
+
find "$1" -type f \( -name 'refusal-*' -o -name 'runs-*' -o -name 'exam-*' -o -name 'pending-*' \) \
|
|
181
|
+
-mtime "+$RT_MARKS_KEEP_DAYS" -delete 2>/dev/null
|
|
182
|
+
return 0
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
# The verdict of an exam, once per session and verdict: the guard reads the whole session on every
|
|
186
|
+
# call it judges, and each of those calls would otherwise read as a new exam.
|
|
187
|
+
#
|
|
188
|
+
# rt_exam_note <passed|failed> <session>
|
|
189
|
+
rt_exam_note() {
|
|
190
|
+
local verdict="$1" session="$2" dir mark
|
|
191
|
+
case "$verdict" in passed | failed) ;; *) return 0 ;; esac
|
|
192
|
+
[ -n "$session" ] || return 0
|
|
193
|
+
dir="$(rt_marks_dir)"
|
|
194
|
+
[ -n "$dir" ] || return 0
|
|
195
|
+
mark="$dir/exam-$(printf '%s' "$session $verdict" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
196
|
+
[ ! -f "$mark" ] || return 0
|
|
197
|
+
: > "$mark" 2>/dev/null
|
|
198
|
+
command -v rt_note >/dev/null 2>&1 || return 0
|
|
199
|
+
rt_note exam-verdict "res=$verdict" "sid=$session"
|
|
200
|
+
return 0
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# One run of one check: an observation with the outcome, the seconds and the kind of step. The line
|
|
204
|
+
# of the check that was red on this same content last time carries the seconds of that red run: a
|
|
205
|
+
# chain of reds counts every link once. The marks of the day hold the content sign, and the
|
|
206
|
+
# observation holds only the answer.
|
|
207
|
+
#
|
|
208
|
+
# rt_run_note <content sign> <started, epoch seconds> <green|red|skipped> <check command>
|
|
209
|
+
rt_run_note() {
|
|
210
|
+
local sign="$1" started="$2" outcome="$3" check="$4" now seconds dir file id last wasted=''
|
|
211
|
+
# Every copy writes into the main one: the heavy steps run from a second copy, and their minutes
|
|
212
|
+
# are the ones the report exists for. One tree has one report, whichever copy ran the check.
|
|
213
|
+
local CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR:-}" main
|
|
214
|
+
main="$(git -C "$(rt_sign_root)" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
|
|
215
|
+
[ -n "$main" ] && CLAUDE_PROJECT_DIR="$(dirname "$main")"
|
|
216
|
+
now="$(date +%s 2>/dev/null)"
|
|
217
|
+
seconds=$((${now:-0} - ${started:-0}))
|
|
218
|
+
[ "$seconds" -ge 0 ] || seconds=0
|
|
219
|
+
|
|
220
|
+
dir="$(rt_marks_dir)"
|
|
221
|
+
if [ -n "$dir" ] && [ -n "$sign" ]; then
|
|
222
|
+
rt_marks_prune "$dir"
|
|
223
|
+
file="$dir/runs-$(date -u +%Y-%m-%d 2>/dev/null)"
|
|
224
|
+
id="$(printf '%s' "$check" | cksum 2>/dev/null | cut -d' ' -f1)"
|
|
225
|
+
last="$(grep "^$sign $id " "$file" 2>/dev/null | tail -n 1)"
|
|
226
|
+
case "$last" in *' red '*) wasted="${last##* }" ;; esac
|
|
227
|
+
printf '%s %s %s %s\n' "$sign" "$id" "$outcome" "$seconds" >> "$file" 2>/dev/null
|
|
228
|
+
fi
|
|
229
|
+
|
|
230
|
+
command -v rt_note >/dev/null 2>&1 || return 0
|
|
231
|
+
rt_note run "res=$outcome" "kind=$(rt_run_kind "$check")" "secs=$seconds" "wasted=$wasted"
|
|
232
|
+
return 0
|
|
233
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# rt-hook: SessionStart startup|resume|compact|clear
|
|
3
|
+
# rt-hook: Stop
|
|
4
|
+
# rt-hook: SessionEnd
|
|
5
|
+
# Requires: hooks/observe.sh, hooks/hook-input.sh
|
|
6
|
+
# The start and the end of a session send the day lines: a guard starts the sending only when it
|
|
7
|
+
# records something, and a quiet session or a dead one would leave its numbers on the disk.
|
|
8
|
+
#
|
|
9
|
+
# The start also names a send that failed more than a day ago. The sending itself stays silent: it
|
|
10
|
+
# runs behind the work, and the only place its failure can reach a person is the opening of a session.
|
|
11
|
+
#
|
|
12
|
+
# A second copy has no command of its own more often than not, so the main copy is asked as well,
|
|
13
|
+
# and a tree with an address and nothing to send with is named at the start too.
|
|
14
|
+
#
|
|
15
|
+
# FAIL-OPEN: no `jq`, no mark, no address, no package command — the session goes on. A side job has no
|
|
16
|
+
# right to stop it, so this hook prints no refusal at all and always exits with zero.
|
|
17
|
+
|
|
18
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
19
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/observe.sh" 2>/dev/null || true
|
|
20
|
+
|
|
21
|
+
command -v rt_send_start >/dev/null 2>&1 || exit 0
|
|
22
|
+
rt_hook_read
|
|
23
|
+
event="$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -r '.hook_event_name // empty' 2>/dev/null)"
|
|
24
|
+
|
|
25
|
+
case "$event" in
|
|
26
|
+
SessionEnd)
|
|
27
|
+
rt_send_start --session-end
|
|
28
|
+
;;
|
|
29
|
+
SessionStart)
|
|
30
|
+
rt_send_keys_note
|
|
31
|
+
rt_send_start
|
|
32
|
+
rt_send_fault_line
|
|
33
|
+
;;
|
|
34
|
+
*)
|
|
35
|
+
rt_send_start
|
|
36
|
+
;;
|
|
37
|
+
esac
|
|
38
|
+
exit 0
|
package/assets/hooks/observe.sh
CHANGED
|
@@ -90,5 +90,108 @@ rt_note() {
|
|
|
90
90
|
line="$line,\"v\":\"$(rt_observe_version)\"}"
|
|
91
91
|
|
|
92
92
|
printf '%s\n' "$line" >> "$dir/$day.jsonl" 2>/dev/null || return 0
|
|
93
|
+
rt_send_start 2>/dev/null
|
|
94
|
+
return 0
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# The package command of this tree: a consumer has it installed, the tree of sources has it built. A
|
|
98
|
+
# second copy often has neither, so the main copy is asked too. An empty string means there is
|
|
99
|
+
# nothing to send with. The answer is one path, whatever its spaces: `rt_send_start` adds `node`.
|
|
100
|
+
rt_send_command() {
|
|
101
|
+
local root="$1" main where
|
|
102
|
+
main="$(git -C "$root" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
|
|
103
|
+
for where in "$root" "${main%/*}"; do
|
|
104
|
+
[ -n "$where" ] || continue
|
|
105
|
+
if [ -x "$where/node_modules/.bin/agent-kit" ]; then
|
|
106
|
+
printf '%s' "$where/node_modules/.bin/agent-kit"
|
|
107
|
+
return 0
|
|
108
|
+
fi
|
|
109
|
+
if [ -f "$where/dist/agent-kit/bin/agent-kit.js" ]; then
|
|
110
|
+
printf '%s' "$where/dist/agent-kit/bin/agent-kit.js"
|
|
111
|
+
return 0
|
|
112
|
+
fi
|
|
113
|
+
done
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Starts the sending in a process of its own and returns at once: a guard stands on every call and
|
|
117
|
+
# never waits for the network. The start is marked before the process, whatever comes of it: a
|
|
118
|
+
# tree with an address and no token file exits before it writes anything, and without this line it
|
|
119
|
+
# would start a process on every observation. So a guard pays for one `find`, not for a process.
|
|
120
|
+
#
|
|
121
|
+
# rt_send_start [--session-end]
|
|
122
|
+
rt_send_start() {
|
|
123
|
+
local root="${CLAUDE_PROJECT_DIR:-.}" config command dir mark runner
|
|
124
|
+
# A run of the suites marks itself: a fixture with an address must not reach the network.
|
|
125
|
+
[ -z "${RT_KIT_TEST:-}" ] || return 0
|
|
126
|
+
config="$root/.claude/rt-kit.json"
|
|
127
|
+
dir="$(rt_observe_dir)"
|
|
128
|
+
[ -n "$dir" ] && [ -f "$config" ] || return 0
|
|
129
|
+
if [ -z "${1:-}" ] && [ -n "$(find "$dir/.marks/send.try" -mmin -15 2>/dev/null)" ]; then
|
|
130
|
+
return 0
|
|
131
|
+
fi
|
|
132
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
133
|
+
[ "$(jq -r 'if (.intake // "") == "" or .send == false then "off" else "on" end' "$config" 2>/dev/null)" = "on" ] || return 0
|
|
134
|
+
command="$(rt_send_command "$root")"
|
|
135
|
+
[ -n "$command" ] || return 0
|
|
136
|
+
mkdir -p "$dir/.marks" 2>/dev/null && touch "$dir/.marks/send.try" 2>/dev/null
|
|
137
|
+
|
|
138
|
+
# The quiet command answers zero whatever the network said, so a non-zero code means it did not
|
|
139
|
+
# run at all: an older build of the package does not know the word.
|
|
140
|
+
mark="$dir/.marks/send.broken"
|
|
141
|
+
case "$command" in
|
|
142
|
+
*.js) runner=node ;;
|
|
143
|
+
*) runner=env ;;
|
|
144
|
+
esac
|
|
145
|
+
# shellcheck disable=SC2016
|
|
146
|
+
(nohup bash -c '"$1" "$2" send --quiet $3 --root "$4" >/dev/null 2>&1 && rm -f "$5" || : > "$5"' _ \
|
|
147
|
+
"$runner" "$command" "${1:-}" "$root" "$mark" >/dev/null 2>&1 &) >/dev/null 2>&1
|
|
148
|
+
return 0
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# A line about a send that failed more than a day ago, or about a tree with an address and nothing
|
|
152
|
+
# to send with. Silence: nothing failed, or it is too fresh to bother a person with.
|
|
153
|
+
rt_send_fault_line() {
|
|
154
|
+
local root="${CLAUDE_PROJECT_DIR:-.}" config="${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit.json" dir mark token
|
|
155
|
+
dir="$(rt_observe_dir)"
|
|
156
|
+
[ -n "$dir" ] || return 0
|
|
157
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
158
|
+
if [ "$(jq -r '(.intake // "") != "" and .send != false' "$config" 2>/dev/null)" = "true" ]; then
|
|
159
|
+
[ -n "$(rt_send_command "$root")" ] \
|
|
160
|
+
|| printf 'The numbers of this tree are not leaving: it has an intake address and no package command.\n'
|
|
161
|
+
token="$(jq -r '.token // ""' "$config" 2>/dev/null)"
|
|
162
|
+
case "$token" in
|
|
163
|
+
'' | /*) ;;
|
|
164
|
+
'~/'*) token="$HOME/${token#'~/'}" ;;
|
|
165
|
+
*) token="$root/$token" ;;
|
|
166
|
+
esac
|
|
167
|
+
[ -n "$token" ] && [ -f "$token" ] \
|
|
168
|
+
|| printf 'The numbers of this tree are not leaving: it has an intake address and no token file on this machine.\n'
|
|
169
|
+
fi
|
|
170
|
+
[ -f "$dir/.marks/send.broken" ] \
|
|
171
|
+
&& printf 'The numbers of this tree are not leaving: the package command did not run the sending. Build or update the package.\n'
|
|
172
|
+
mark="$dir/.marks/send.json"
|
|
173
|
+
[ -f "$mark" ] || return 0
|
|
174
|
+
jq -r --argjson now "$(date +%s)" \
|
|
175
|
+
'select(.fault != 0 and ($now * 1000 - .faultSince) > 86400000)
|
|
176
|
+
| "The numbers of this tree have not reached the intake: \(.reason). `agent-kit doctor` names the way out."' \
|
|
177
|
+
"$mark" 2>/dev/null
|
|
178
|
+
return 0
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# A change of the two keys is an observation of its own: a tree that stopped sending reads the same
|
|
182
|
+
# as a tree that stopped working. Nothing is recorded with `observe: false`, and that is said by the
|
|
183
|
+
# silence of the tree.
|
|
184
|
+
rt_send_keys_note() {
|
|
185
|
+
local root="${CLAUDE_PROJECT_DIR:-.}" dir keys file known
|
|
186
|
+
dir="$(rt_observe_dir)"
|
|
187
|
+
[ -n "$dir" ] || return 0
|
|
188
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
189
|
+
keys="$(jq -r '"\(.send != false) \(.observe != false)"' "$root/.claude/rt-kit.json" 2>/dev/null)"
|
|
190
|
+
[ -n "$keys" ] || return 0
|
|
191
|
+
mkdir -p "$dir/.marks" 2>/dev/null || return 0
|
|
192
|
+
file="$dir/.marks/send-keys"
|
|
193
|
+
[ -f "$file" ] && known="$(cat "$file" 2>/dev/null)"
|
|
194
|
+
printf '%s' "$keys" > "$file" 2>/dev/null
|
|
195
|
+
[ -n "${known:-}" ] && [ "$known" != "$keys" ] && rt_note settings-change res=send sid=settings
|
|
93
196
|
return 0
|
|
94
197
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# rt-hook: UserPromptSubmit
|
|
3
|
+
# Requires: hooks/hook-input.sh, hooks/metric-marks.sh
|
|
4
|
+
#
|
|
5
|
+
# Counts the owner's corrections for the package metrics. A number the executor reports about itself
|
|
6
|
+
# is worth nothing, so the hook counts and the executor takes no part.
|
|
7
|
+
#
|
|
8
|
+
# WHAT IS KEPT. A line of the branch counter and one observation. The message is matched and thrown
|
|
9
|
+
# away: its text reaches no file.
|
|
10
|
+
#
|
|
11
|
+
# THE SET OF PATTERNS is fixed and stands here in full, so a person can read what counts. It was
|
|
12
|
+
# widened on a sample the owner read, and a change of it restarts a baseline. It holds no swearing:
|
|
13
|
+
# the package lands in foreign trees. A message that opens with a tag comes from the application, not
|
|
14
|
+
# from a person.
|
|
15
|
+
#
|
|
16
|
+
# FAIL-OPEN: no input, no parser, no mark file — exit with zero and no output. This hook never refuses
|
|
17
|
+
# and never adds to the context.
|
|
18
|
+
|
|
19
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
20
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || exit 0
|
|
21
|
+
|
|
22
|
+
RT_CORRECTION_PATTERNS='не так|неправильно|неверно|переделай|переделать|исправь|поправь|откати|ты ошиб|это ошибка|зря |почему|зачем|опять|снова|не работа|сломал|верни|а где|забыл|пропустил|я же сказал|я же просил|я же писал|поправляй|исправляй|криво|кривая|кривой|ерунд|бред|wrong|redo|not what i|that.s not|fix this|revert|why did|why is|broken'
|
|
23
|
+
|
|
24
|
+
rt_hook_read
|
|
25
|
+
[ -n "$RT_HOOK_INPUT" ] || exit 0
|
|
26
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
27
|
+
|
|
28
|
+
message="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.prompt // empty' 2>/dev/null)"
|
|
29
|
+
case "$message" in
|
|
30
|
+
'' | '<'*) exit 0 ;;
|
|
31
|
+
esac
|
|
32
|
+
printf '%s' "$message" | grep -qiE "$RT_CORRECTION_PATTERNS" || exit 0
|
|
33
|
+
|
|
34
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/metric-marks.sh" 2>/dev/null || exit 0
|
|
35
|
+
rt_correction_mark "$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)"
|
|
36
|
+
exit 0
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
# Its own name in the observations: the refusal is recorded by the shared deny tail, not by the
|
|
22
22
|
# guard itself.
|
|
23
23
|
RT_GUARD_NAME=prose-style-guard
|
|
24
|
+
RT_GUARD_RULE=doc-style
|
|
24
25
|
|
|
25
26
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
26
27
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The facts about closed requests, one JSON object per line. NOT a guard: it has no `rt-hook:`
|
|
3
|
+
# declaration and hooks into no agent event. The report and the sending call it.
|
|
4
|
+
#
|
|
5
|
+
# Why here and not in the reader. A merge often happens in a browser with no session open, so the
|
|
6
|
+
# outcome is read later. The hosting side lives in the tree profile, `rt_pull_outcomes <day>`: the
|
|
7
|
+
# package ships a default for GitHub, and another hosting names its own. The marks live here, and a
|
|
8
|
+
# branch name is hashed by the same code that wrote the mark. So this file joins the two, and the
|
|
9
|
+
# reader never sees a branch name.
|
|
10
|
+
#
|
|
11
|
+
# bash pull-outcomes.sh <day, YYYY-MM-DD>
|
|
12
|
+
#
|
|
13
|
+
# A line of the profile: `{number, merged, task, revert, epic, closed, head, commits}`, where `commits`
|
|
14
|
+
# holds `{sha, tree, parents}` from the oldest. What leaves here: the same without `head`, plus
|
|
15
|
+
# `handover` (`{commit, tree}` or null) and `corrections` (the owner corrections after the handover).
|
|
16
|
+
#
|
|
17
|
+
# Exit code 3 — nobody to ask: no profile function, or it failed. A tree without outcomes is counted
|
|
18
|
+
# apart, so silence must not read as «nothing was closed».
|
|
19
|
+
|
|
20
|
+
hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
21
|
+
root="${CLAUDE_PROJECT_DIR:-$PWD}"
|
|
22
|
+
export CLAUDE_PROJECT_DIR="$root"
|
|
23
|
+
cd "$root" 2>/dev/null || exit 3
|
|
24
|
+
|
|
25
|
+
for profile in "$hooks_dir/../rt-kit/defaults/project.sh" "$hooks_dir/../defaults/project.sh" \
|
|
26
|
+
"$root/.claude/rt-kit/defaults/project.sh" "$root/.claude/rt-kit/project.sh"; do
|
|
27
|
+
# shellcheck disable=SC1090
|
|
28
|
+
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
29
|
+
done
|
|
30
|
+
|
|
31
|
+
. "$hooks_dir/metric-marks.sh" 2>/dev/null || exit 3
|
|
32
|
+
command -v rt_pull_outcomes >/dev/null 2>&1 || exit 3
|
|
33
|
+
command -v jq >/dev/null 2>&1 || exit 3
|
|
34
|
+
|
|
35
|
+
# The function is there, so a failure of it is a broken read, and a broken read is not «nobody to
|
|
36
|
+
# ask»: code 4 keeps the day of the last read where it was, and the next read takes the request again.
|
|
37
|
+
pulls="$(rt_pull_outcomes "$1" 2>/dev/null)"
|
|
38
|
+
code=$?
|
|
39
|
+
[ "$code" = 3 ] && exit 3
|
|
40
|
+
[ "$code" = 0 ] || exit 4
|
|
41
|
+
|
|
42
|
+
printf '%s\n' "$pulls" | while IFS= read -r pull; do
|
|
43
|
+
[ -n "$pull" ] || continue
|
|
44
|
+
head="$(printf '%s' "$pull" | jq -r '.head // empty' 2>/dev/null)"
|
|
45
|
+
handover=''
|
|
46
|
+
corrections='[]'
|
|
47
|
+
if [ -n "$head" ]; then
|
|
48
|
+
file="$(rt_branch_mark handover "$head")"
|
|
49
|
+
[ -f "$file" ] && handover="$(cat "$file" 2>/dev/null)"
|
|
50
|
+
file="$(rt_branch_mark corrections "$head")"
|
|
51
|
+
[ -f "$file" ] && corrections="$(sed -n 's/^after //p' "$file" 2>/dev/null | jq -R . | jq -cs . 2>/dev/null)"
|
|
52
|
+
fi
|
|
53
|
+
printf '%s' "$pull" | jq -c --arg sign "$handover" --argjson after "${corrections:-[]}" '
|
|
54
|
+
del(.head)
|
|
55
|
+
+ { corrections: $after,
|
|
56
|
+
handover: (if $sign == "" then null
|
|
57
|
+
else ($sign | split(" ") | { commit: .[0], tree: .[1] }) end) }' 2>/dev/null
|
|
58
|
+
done
|
|
59
|
+
exit 0
|
package/assets/hooks/push-set.sh
CHANGED
|
@@ -37,6 +37,11 @@ rt_push_set_profile() {
|
|
|
37
37
|
command -v rt_push_mark_clean >/dev/null 2>&1 || rt_push_mark_clean() { return 1; }
|
|
38
38
|
command -v rt_push_mark_key >/dev/null 2>&1 || rt_push_mark_key() { return 1; }
|
|
39
39
|
command -v rt_push_heavy_ahead >/dev/null 2>&1 || rt_push_heavy_ahead() { return 1; }
|
|
40
|
+
# The line of a run for the metrics. No file — the set runs and records nothing.
|
|
41
|
+
# shellcheck disable=SC1091
|
|
42
|
+
[ -f "$hooks_dir/metric-marks.sh" ] && . "$hooks_dir/metric-marks.sh" 2>/dev/null
|
|
43
|
+
command -v rt_run_note >/dev/null 2>&1 || rt_run_note() { return 0; }
|
|
44
|
+
command -v rt_tree_sign >/dev/null 2>&1 || rt_tree_sign() { return 0; }
|
|
40
45
|
return 0
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -64,9 +69,10 @@ rt_push_set_base() {
|
|
|
64
69
|
# named in `rt_push_set_ahead` instead of being started. The git hook has no such limit, leaves the
|
|
65
70
|
# variable empty and runs the step itself.
|
|
66
71
|
rt_push_set_run() {
|
|
67
|
-
local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}"
|
|
72
|
+
local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}" sign started
|
|
68
73
|
case "$skip_code" in '' | 0 | 1 | *[!0-9]*) skip_code=7 ;; esac
|
|
69
74
|
command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
|
|
75
|
+
sign="$(rt_tree_sign .)"
|
|
70
76
|
|
|
71
77
|
rt_push_set_failed=""
|
|
72
78
|
rt_push_set_output=""
|
|
@@ -95,18 +101,22 @@ rt_push_set_run() {
|
|
|
95
101
|
rt_push_set_ran=$((rt_push_set_ran + 1))
|
|
96
102
|
key_before=""
|
|
97
103
|
rt_push_mark_clean && key_before="$(rt_push_mark_key "$check" "$base" 2>/dev/null)"
|
|
104
|
+
started="$(date +%s 2>/dev/null)"
|
|
98
105
|
out="$(eval "$check" 2>&1 </dev/null)"
|
|
99
106
|
status=$?
|
|
100
107
|
if [ "$status" -eq 0 ]; then
|
|
101
108
|
rt_push_set_passed=$((rt_push_set_passed + 1))
|
|
102
109
|
rt_push_mark_put "$check" "$base" "$key_before"
|
|
110
|
+
rt_run_note "$sign" "$started" green "$check"
|
|
103
111
|
continue
|
|
104
112
|
fi
|
|
105
113
|
if [ "$status" -eq "$skip_code" ]; then
|
|
106
114
|
rt_push_set_skipped="${rt_push_set_skipped}${rt_push_set_skipped:+
|
|
107
115
|
}${check}"
|
|
116
|
+
rt_run_note "$sign" "$started" skipped "$check"
|
|
108
117
|
continue
|
|
109
118
|
fi
|
|
119
|
+
rt_run_note "$sign" "$started" red "$check"
|
|
110
120
|
rt_push_set_failed="${rt_push_set_failed}${rt_push_set_failed:+
|
|
111
121
|
}${check}"
|
|
112
122
|
rt_push_set_output="${rt_push_set_output}${rt_push_set_output:+
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
29
29
|
# guard itself.
|
|
30
30
|
RT_GUARD_NAME=qa-dataid-guard
|
|
31
|
+
RT_GUARD_RULE=component-structure
|
|
31
32
|
|
|
32
33
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
33
34
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
24
24
|
# guard itself.
|
|
25
25
|
RT_GUARD_NAME=rerun-guard
|
|
26
|
+
RT_GUARD_RULE=testing
|
|
26
27
|
|
|
27
28
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
28
29
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
40
40
|
# guard itself.
|
|
41
41
|
RT_GUARD_NAME=reuse-first-guard
|
|
42
|
+
RT_GUARD_RULE=reuse-first
|
|
42
43
|
|
|
43
44
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
44
45
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|