@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.
- package/README.md +14 -13
- package/assets/agents/goal-critic.md +76 -0
- package/assets/agents/product-strategist.md +95 -0
- package/assets/agents/qa-engineer.md +3 -0
- package/assets/checks/check-specs.mjs +11 -2
- package/assets/checks/rt-kit-checks.config.mjs +6 -0
- package/assets/checks/spec-common.mjs +6 -3
- package/assets/checks/spec-scenarios.mjs +9 -1
- package/assets/checks/task-new.github.mjs +6 -0
- package/assets/defaults/project.sh +49 -81
- package/assets/defaults/push.sh +100 -0
- package/assets/docs/GLOSSARY.md +4 -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 +7 -3
- package/assets/hooks/browser-guard-require-select.sh +1 -0
- package/assets/hooks/claim-guard.sh +7 -6
- package/assets/hooks/dev-server-guard.sh +1 -0
- package/assets/hooks/dispatch.sh +56 -3
- 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 +6 -1
- package/assets/hooks/git-guard-delivery-body.sh +25 -3
- package/assets/hooks/git-guard-delivery-draft.sh +23 -0
- package/assets/hooks/git-guard-delivery-folder.sh +38 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
- package/assets/hooks/git-guard-delivery-signature.sh +19 -0
- package/assets/hooks/git-guard-delivery.sh +15 -19
- package/assets/hooks/git-guard-discard.sh +1 -0
- package/assets/hooks/git-guard-main.sh +18 -4
- package/assets/hooks/git-guard-no-verify.sh +1 -0
- package/assets/hooks/git-guard-push-ahead.sh +98 -0
- package/assets/hooks/git-guard-push-marks.sh +99 -0
- package/assets/hooks/git-guard-push-tests.sh +102 -83
- 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/pre-push.sh +113 -0
- package/assets/hooks/prose-style-guard.sh +1 -0
- package/assets/hooks/pull-outcomes.sh +59 -0
- package/assets/hooks/push-set.sh +160 -0
- package/assets/hooks/push-sign.sh +433 -0
- package/assets/hooks/qa-dataid-guard.sh +1 -0
- package/assets/hooks/rerun-guard.sh +15 -6
- 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 +3 -23
- package/assets/hooks/turn-exit-patterns.sh +4 -3
- package/assets/hooks/turn-exit-verdict.sh +18 -1
- package/assets/hooks/waiting-turn-guard.sh +3 -1
- package/assets/hooks/window-fill-guard.sh +1 -0
- package/assets/hooks/work-start-guard.sh +1 -0
- package/assets/hooks/write-targets.sh +21 -0
- package/assets/patterns/git-workflow-commit.azure.md +5 -3
- package/assets/patterns/git-workflow-commit.github.md +16 -3
- package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
- package/assets/patterns/git-workflow-pr-body.github.md +20 -3
- package/assets/patterns/git-workflow-pr.azure.md +30 -0
- package/assets/patterns/git-workflow-pr.github.md +57 -1
- package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
- package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
- package/assets/patterns/task-flow-close.md +32 -22
- package/assets/patterns/task-flow-cycle.md +72 -0
- package/assets/patterns/task-flow-start.md +3 -3
- package/assets/rules/browser-verification.md +4 -0
- package/assets/rules/deploy-flow.azure.md +5 -0
- package/assets/rules/deploy-flow.github.md +5 -0
- package/assets/rules/deploy-flow.gitlab.md +5 -0
- package/assets/rules/git-workflow.azure.md +15 -0
- package/assets/rules/git-workflow.github.md +15 -0
- package/assets/rules/git-workflow.gitlab.md +15 -0
- package/assets/rules/mockups.needs-mockups.md +13 -5
- package/assets/rules/task-flow.md +31 -25
- package/assets/samples/tasks/_template/plan.md +8 -0
- package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
- package/assets/skills/interface-review-icons.needs-app.md +136 -0
- package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
- package/assets/skills/interface-review-motion.needs-app.md +209 -0
- package/assets/skills/interface-review-performance.needs-app.md +110 -0
- package/assets/skills/interface-review-principles.needs-app.md +263 -0
- package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
- package/assets/skills/interface-review.needs-app.md +199 -0
- package/assets/skills/write-a-skill.md +16 -3
- package/assets/templates/postmortem.md +2 -0
- package/assets/workflows/feature.js +33 -5
- package/assets/workflows/plan.js +71 -4
- 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
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The checks before a push, as a hook of git itself, not of the agent.
|
|
3
|
+
#
|
|
4
|
+
# Requires: hooks/push-set.sh, hooks/git-guard-push-marks.sh
|
|
5
|
+
#
|
|
6
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The version control
|
|
7
|
+
# calls it before every push, whatever sent it: the session guard of the push stands only on the
|
|
8
|
+
# agent's tools, and a push from a terminal outside the session, from another session through
|
|
9
|
+
# `git -C` or from an environment without the agent hooks used to leave with no check at all. That
|
|
10
|
+
# is how a kit branch left from a foreign session and broke the kit's main branch.
|
|
11
|
+
#
|
|
12
|
+
# A versioned template: the git hooks directory of the working copy is not versioned, so the tree
|
|
13
|
+
# wires the file to git itself — by its hooks manager, or by hand. The hook stays where the layout
|
|
14
|
+
# put it, next to `push-set.sh`, and git calls it through a line that names it:
|
|
15
|
+
# printf '#!/bin/sh\nexec bash .claude/hooks/pre-push.sh "$@"\n' > .git/hooks/pre-push
|
|
16
|
+
# chmod +x .git/hooks/pre-push
|
|
17
|
+
#
|
|
18
|
+
# What it runs is the same set the session guard runs, by the same code in `push-set.sh`:
|
|
19
|
+
# `rt_push_checks <base>` from the package default and the tree profile, every red one named, a
|
|
20
|
+
# skipped one named apart, no heavy one started after a red one.
|
|
21
|
+
#
|
|
22
|
+
# A push the session guard already judged runs no second set. The guard writes the commit it found
|
|
23
|
+
# green into the mark `rt-kit-push-green` of the shared git directory, and a push of exactly that
|
|
24
|
+
# commit passes here at once: a second fifteen-minute run inside a session push would cut the
|
|
25
|
+
# session off. The mark is written only on a working copy without uncommitted edits.
|
|
26
|
+
#
|
|
27
|
+
# A dry run is judged like a real push: git calls the hook for `--dry-run` too and does not say so.
|
|
28
|
+
#
|
|
29
|
+
# The set judges the tree the working copy stands on, so the hook lets through only a push of that
|
|
30
|
+
# commit. A push of another branch, of a tag or of an older commit is refused: a green set would
|
|
31
|
+
# then read as a check of what left, though it checked something else. A deletion sends no tree
|
|
32
|
+
# and is not judged.
|
|
33
|
+
#
|
|
34
|
+
# The pipeline is its own gate: under `CI` the hook passes. A hooks manager installs the hook on
|
|
35
|
+
# the runner too, and the pipeline's own pushes would wait for the whole set there.
|
|
36
|
+
#
|
|
37
|
+
# FAIL-OPEN: not a repository, no file `push-set.sh`, no profile or no `rt_push_checks`, an empty
|
|
38
|
+
# set, under `CI` — pass.
|
|
39
|
+
|
|
40
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
41
|
+
|
|
42
|
+
[ -n "${CI:-}" ] && exit 0
|
|
43
|
+
|
|
44
|
+
repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
|
|
45
|
+
cd "$repo_root" 2>/dev/null || exit 0
|
|
46
|
+
|
|
47
|
+
tip="$(git rev-parse --verify --quiet HEAD 2>/dev/null)"
|
|
48
|
+
|
|
49
|
+
# The refs being pushed come on the input, a line each: local ref, local sha, remote ref, remote
|
|
50
|
+
# sha. What is judged is the commit each one sends. A deletion comes with a sha of zeros only, of
|
|
51
|
+
# any length; a real commit that merely starts with zeros is judged like any other.
|
|
52
|
+
sends=0
|
|
53
|
+
foreign=""
|
|
54
|
+
while read -r local_ref local_sha _remote_ref _remote_sha; do
|
|
55
|
+
[ -z "$local_sha" ] && continue
|
|
56
|
+
[ -z "$(printf '%s' "$local_sha" | tr -d 0)" ] && continue
|
|
57
|
+
sends=$((sends + 1))
|
|
58
|
+
commit="$(git rev-parse --verify --quiet "${local_sha}^{commit}" 2>/dev/null)"
|
|
59
|
+
[ -n "$commit" ] && [ "$commit" = "$tip" ] && continue
|
|
60
|
+
foreign="${foreign}${foreign:+
|
|
61
|
+
} ${local_ref}"
|
|
62
|
+
done
|
|
63
|
+
|
|
64
|
+
[ "$sends" -eq 0 ] && exit 0
|
|
65
|
+
|
|
66
|
+
if [ -n "$foreign" ]; then
|
|
67
|
+
printf '%s\n' "pre-push: refused — the push sends a commit the working copy does not stand on:" >&2
|
|
68
|
+
printf '%s\n' "$foreign" >&2
|
|
69
|
+
printf '%s\n' "The checks run on the tree that lies here, so they would judge something else than what leaves. Switch to the branch and push it from there, one branch per push." >&2
|
|
70
|
+
exit 1
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
74
|
+
# shellcheck disable=SC1091
|
|
75
|
+
if ! . "$hooks_dir/push-set.sh" 2>/dev/null; then
|
|
76
|
+
printf '%s\n' "pre-push: no file push-set.sh next to the hook in ${hooks_dir} — no check ran. The hook is called where the layout put it, not copied away from it." >&2
|
|
77
|
+
exit 0
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
rt_push_mark_covers "$tip" && exit 0
|
|
81
|
+
|
|
82
|
+
# The root is this repository's, whatever the caller exported: a push through `git -C` from a session
|
|
83
|
+
# of another copy carries that copy's root, and the profile would read its files instead.
|
|
84
|
+
rt_push_set_profile "$hooks_dir" "$repo_root"
|
|
85
|
+
command -v rt_push_checks >/dev/null 2>&1 || exit 0
|
|
86
|
+
|
|
87
|
+
base="$(rt_push_set_base)"
|
|
88
|
+
total="$(rt_push_checks "$base" | grep -c .)"
|
|
89
|
+
[ "${total:-0}" -eq 0 ] && exit 0
|
|
90
|
+
|
|
91
|
+
printf 'pre-push: running the checks before the push, %s of them\n' "$total" >&2
|
|
92
|
+
|
|
93
|
+
rt_push_set_run "$base"
|
|
94
|
+
|
|
95
|
+
[ -n "$rt_push_set_skipped" ] && printf 'pre-push: these checks had nothing to look at:\n%s\n' "$rt_push_set_skipped" >&2
|
|
96
|
+
|
|
97
|
+
if [ -z "$rt_push_set_failed" ]; then
|
|
98
|
+
if [ "$rt_push_set_passed" -eq 0 ]; then
|
|
99
|
+
printf '%s\n' "pre-push: no check of the set judged the tree — the push passes, and no mark of green is written." >&2
|
|
100
|
+
fi
|
|
101
|
+
rt_push_mark_write
|
|
102
|
+
exit 0
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
held_line=""
|
|
106
|
+
[ -n "$rt_push_set_held" ] && held_line="
|
|
107
|
+
|
|
108
|
+
Not started after the red ones — heavy, and the push is refused anyway:
|
|
109
|
+
${rt_push_set_held}"
|
|
110
|
+
|
|
111
|
+
printf '\npre-push: refused — red checks: %s\n%s%s\n\nThe tail of every red output:\n\n%s\n' \
|
|
112
|
+
"$(printf '%s\n' "$rt_push_set_failed" | grep -c .)" "$rt_push_set_failed" "$held_line" "$rt_push_set_output" >&2
|
|
113
|
+
exit 1
|
|
@@ -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
|