@jeiemgi/cckit 0.7.1 → 0.9.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/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +15 -4
- package/README.md +25 -3
- package/bin/cckit +91 -8
- package/cckit.config.json +1 -1
- package/kit.config.schema.json +43 -2
- package/package.json +1 -1
- package/scripts/autopilot-test.sh +68 -0
- package/scripts/autopilot.sh +16 -10
- package/scripts/check.sh +14 -1
- package/scripts/copilot-loop-test.sh +3 -0
- package/scripts/guard-raw-git-ops-test.sh +73 -0
- package/scripts/init.sh +68 -8
- package/scripts/lib/agent-profile-test.sh +151 -0
- package/scripts/lib/agent-profile.sh +195 -0
- package/scripts/lib/agent-resolve-test.sh +156 -0
- package/scripts/lib/agent-resolve.sh +177 -0
- package/scripts/lib/branch-owner-test.sh +99 -0
- package/scripts/lib/branch-owner.sh +194 -0
- package/scripts/lib/captain-test.sh +86 -0
- package/scripts/lib/captain.sh +142 -7
- package/scripts/lib/contribute-root-test.sh +40 -0
- package/scripts/lib/contribute-root.sh +22 -0
- package/scripts/lib/effort-metrics.sh +14 -1
- package/scripts/lib/effort-ops-test.sh +54 -2
- package/scripts/lib/effort-ops.sh +243 -23
- package/scripts/lib/effort-parity-test.sh +5 -3
- package/scripts/lib/effort-slug.sh +16 -2
- package/scripts/lib/effort.sh +49 -15
- package/scripts/lib/gh-project.sh +14 -0
- package/scripts/lib/gh-rest-test.sh +301 -0
- package/scripts/lib/gh-rest.sh +289 -0
- package/scripts/lib/hook-refresh-test.sh +65 -0
- package/scripts/lib/hook-refresh.sh +62 -0
- package/scripts/lib/kit-config.sh +6 -0
- package/scripts/lib/kit-gc-test.sh +178 -1
- package/scripts/lib/kit-gc.sh +251 -55
- package/scripts/lib/kit-task-ops-test.sh +15 -0
- package/scripts/lib/kit-task-ops.sh +231 -58
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +129 -0
- package/scripts/lib/kto-task-pr-test.sh +59 -0
- package/scripts/lib/orchestration-runtime-test.sh +142 -0
- package/scripts/lib/orchestration-runtime.sh +171 -0
- package/scripts/lib/review-stage-test.sh +241 -0
- package/scripts/lib/review-stage.sh +259 -0
- package/scripts/lib/stage-receipt-test.sh +252 -0
- package/scripts/lib/stage-receipt.sh +442 -0
- package/scripts/lib/test-env-test.sh +25 -0
- package/scripts/lib/test-env.sh +33 -0
- package/scripts/lib/worker-brief-test.sh +120 -0
- package/scripts/lib/worker-brief.sh +185 -0
- package/scripts/lib/worktree-issue.sh +14 -0
- package/scripts/lib/worktree-ports-test.sh +146 -0
- package/scripts/lib/worktree-start.sh +153 -8
- package/scripts/lib/zsh-safety-test.sh +67 -0
- package/scripts/orchestrate.sh +124 -22
- package/scripts/portable-test.sh +22 -1
- package/scripts/review-lint-baseline.txt +28 -0
- package/scripts/review-lint-test.sh +271 -0
- package/scripts/review-lint.sh +259 -0
- package/scripts/review-rules.conf +55 -0
- package/scripts/setup-labels.sh +21 -1
- package/scripts/skill-frontmatter-baseline.txt +24 -0
- package/scripts/skill-frontmatter-lint-test.sh +156 -0
- package/scripts/skill-frontmatter-lint.sh +182 -0
- package/scripts/task-sync.sh +8 -0
- package/scripts/test.sh +10 -1
- package/skills/kit-autopilot/SKILL.md +13 -1
- package/skills/kit-cleanup/SKILL.md +5 -3
- package/skills/kit-contribute/SKILL.md +6 -5
- package/skills/kit-effort-close/SKILL.md +8 -3
- package/skills/kit-effort-pr/SKILL.md +16 -95
- package/skills/kit-gc/SKILL.md +15 -10
- package/skills/kit-security-sweep/SKILL.md +4 -6
- package/skills/kit-ship/SKILL.md +1 -1
- package/skills/kit-task-pr/SKILL.md +2 -0
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +193 -0
- package/templates/rules/branch-naming.md +6 -0
- package/templates/rules/effort-model.md +3 -0
- package/templates/rules/naming-and-ids.md +4 -1
- package/templates/settings/settings.json.tmpl +4 -2
|
@@ -28,6 +28,16 @@ if ! command -v effort_slug_resolve >/dev/null 2>&1; then
|
|
|
28
28
|
unset _eo_dir
|
|
29
29
|
fi
|
|
30
30
|
|
|
31
|
+
# The GitHub transport switch (#396): in rest mode the lifecycle calls below are `gh api repos/…`.
|
|
32
|
+
if ! command -v cckit_gh_rest >/dev/null 2>&1; then
|
|
33
|
+
_eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
34
|
+
# shellcheck source=/dev/null
|
|
35
|
+
[ -f "$_eo_dir/gh-rest.sh" ] && . "$_eo_dir/gh-rest.sh"
|
|
36
|
+
unset _eo_dir
|
|
37
|
+
fi
|
|
38
|
+
command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
|
|
39
|
+
command -v cckit_board_skipped >/dev/null 2>&1 || cckit_board_skipped() { return 1; }
|
|
40
|
+
|
|
31
41
|
_eff_repo() { printf '%s' "${EFFORT_REPO:-${KIT_REPO:-}}"; }
|
|
32
42
|
_eff_base() { printf '%s' "${KIT_BASE_BRANCH:-main}"; }
|
|
33
43
|
_eff_need() { command -v "$1" >/dev/null 2>&1 || { echo "effort: $1 is required" >&2; return 1; }; }
|
|
@@ -96,6 +106,7 @@ _eff_relations_add() {
|
|
|
96
106
|
# before `gh issue create --label` uses it (which fails hard on a missing label, #153). Idempotent:
|
|
97
107
|
# creating an existing label is a silent no-op.
|
|
98
108
|
_eff_ensure_label() {
|
|
109
|
+
if cckit_gh_rest; then gh_rest_label_create "$(_eff_repo)" "$1" "$2" "$3"; return 0; fi
|
|
99
110
|
gh label create "$1" --repo "$(_eff_repo)" --color "$2" \
|
|
100
111
|
--description "$3" >/dev/null 2>&1 || true
|
|
101
112
|
}
|
|
@@ -106,6 +117,7 @@ _eff_ensure_label() {
|
|
|
106
117
|
_eff_board_add() {
|
|
107
118
|
local n="$1" role="${2:-}" repo node item ropt
|
|
108
119
|
[ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
|
|
120
|
+
cckit_board_skipped && return 0
|
|
109
121
|
command -v project_add_item >/dev/null 2>&1 || return 0
|
|
110
122
|
repo="$(_eff_repo)"
|
|
111
123
|
node="$(gh api "repos/$repo/issues/$n" --jq .node_id 2>/dev/null)" || return 0
|
|
@@ -214,7 +226,13 @@ effort_new() {
|
|
|
214
226
|
_eff_ensure_label "$ctx" bfd4f2 "effort session weight"
|
|
215
227
|
_eff_ensure_label "kind:task" d4c5f9 "kit issue kind"
|
|
216
228
|
_eff_ensure_label "priority:$priority" e99695 "kit priority"
|
|
217
|
-
|
|
229
|
+
# `effort` is what marks the parent AS an effort, and it is the label `effort_plan` queries
|
|
230
|
+
# (`gh issue list --label effort`, effort-plan.sh). It was read and never written: the label did
|
|
231
|
+
# not exist in this repo at all, so `cckit effort plan` answered "no open efforts found" for
|
|
232
|
+
# every effort ever created here. A label something reads and nothing writes is the same defect
|
|
233
|
+
# as one something writes and nothing reads — see rules/naming-and-ids.md § Labels.
|
|
234
|
+
_eff_ensure_label "effort" 5319e7 "an effort parent issue"
|
|
235
|
+
local labels="effort,$ctx,kind:task,priority:$priority"
|
|
218
236
|
if [ -n "$role" ]; then
|
|
219
237
|
_eff_ensure_label "role:$role" 0e8a16 "kit role lane"
|
|
220
238
|
labels="$labels,role:$role"
|
|
@@ -230,15 +248,24 @@ effort_new() {
|
|
|
230
248
|
fi
|
|
231
249
|
|
|
232
250
|
local url num slug
|
|
251
|
+
if cckit_gh_rest; then
|
|
252
|
+
url="$(gh_rest_issue_create "$repo" "[Effort] · ${flow_tag}${name}" "$body" "$labels" "$milestone" 0)" \
|
|
253
|
+
|| { echo "effort_new: failed to create the parent issue" >&2; return 1; }
|
|
254
|
+
else
|
|
233
255
|
url="$(gh issue create --repo "$repo" --title "[Effort] · ${flow_tag}${name}" --body "$body" \
|
|
234
256
|
--label "$labels" ${milestone:+--milestone "$milestone"})" \
|
|
235
257
|
|| { echo "effort_new: failed to create the parent issue" >&2; return 1; }
|
|
258
|
+
fi
|
|
236
259
|
num="${url##*/}"
|
|
237
|
-
|
|
260
|
+
if cckit_gh_rest; then gh_rest_issue_edit_title "$repo" "$num" "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1
|
|
261
|
+
else gh issue edit "$num" --repo "$repo" --title "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1; fi
|
|
238
262
|
# The human handle (#93): explicit --slug if given, else derived from the title (number/flow peeled).
|
|
239
263
|
if [ -n "$explicit_slug" ]; then slug="$(_eff_slug "$explicit_slug")"
|
|
240
264
|
else slug="$(_eff_title_slug "[Effort] $num · ${flow_tag}${name}")"; fi
|
|
241
|
-
if [ -n "$slug" ]; then
|
|
265
|
+
if [ -n "$slug" ] && cckit_gh_rest; then
|
|
266
|
+
gh_rest_label_create "$repo" "slug:$slug" ededed "effort slug handle"
|
|
267
|
+
gh_rest_issue_add_labels "$repo" "$num" "slug:$slug" >/dev/null 2>&1 || true
|
|
268
|
+
elif [ -n "$slug" ]; then
|
|
242
269
|
gh label create "slug:$slug" --repo "$repo" --color ededed \
|
|
243
270
|
--description "effort slug handle" >/dev/null 2>&1 || true # idempotent: ok if it exists
|
|
244
271
|
gh issue edit "$num" --repo "$repo" --add-label "slug:$slug" >/dev/null 2>&1 || true
|
|
@@ -265,9 +292,14 @@ effort_new() {
|
|
|
265
292
|
sub_title="[Effort $num] $i · $sub_name"
|
|
266
293
|
local sub_labels="kind:task,priority:$priority"
|
|
267
294
|
[ -n "$role" ] && sub_labels="$sub_labels,role:$role"
|
|
295
|
+
if cckit_gh_rest; then
|
|
296
|
+
child="$(gh_rest_issue_create "$repo" "$sub_title" \
|
|
297
|
+
"$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" "$sub_labels" "$milestone" 0)" || continue
|
|
298
|
+
else
|
|
268
299
|
child="$(gh issue create --repo "$repo" --title "$sub_title" \
|
|
269
300
|
--body "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" \
|
|
270
301
|
--label "$sub_labels" ${milestone:+--milestone "$milestone"})" || continue
|
|
302
|
+
fi
|
|
271
303
|
child_num="${child##*/}"
|
|
272
304
|
effort_link_sub "$num" "$child_num" || true
|
|
273
305
|
_eff_board_add "$child_num" "$role" || true
|
|
@@ -285,6 +317,17 @@ _eo_source_effort() {
|
|
|
285
317
|
[ -f "$d/effort.sh" ] && . "$d/effort.sh"
|
|
286
318
|
}
|
|
287
319
|
|
|
320
|
+
# _eff_issue_body <repo> <n> / _eff_issue_set_body <repo> <n> <body> — read and replace an issue
|
|
321
|
+
# body on the chosen transport (#396). A failed read returns non-zero, never an empty body.
|
|
322
|
+
_eff_issue_body() {
|
|
323
|
+
if cckit_gh_rest; then gh api "repos/$1/issues/$2" --jq '.body // ""'
|
|
324
|
+
else gh issue view "$2" --repo "$1" --json body --jq .body; fi
|
|
325
|
+
}
|
|
326
|
+
_eff_issue_set_body() {
|
|
327
|
+
if cckit_gh_rest; then gh_rest_issue_set_body "$1" "$2" "$3"
|
|
328
|
+
else gh issue edit "$2" --repo "$1" --body "$3"; fi
|
|
329
|
+
}
|
|
330
|
+
|
|
288
331
|
# _eff_blockers <issue> — echo the issue's CURRENT blocked_by numbers, one per line. Empty when the
|
|
289
332
|
# issue has no edges or the API call fails (the caller treats that as "no known edge").
|
|
290
333
|
_eff_blockers() {
|
|
@@ -395,13 +438,13 @@ effort_chain() {
|
|
|
395
438
|
|
|
396
439
|
# A FAILED read is not an empty body: writing the composed body after a failed fetch would
|
|
397
440
|
# wipe the issue. Only a successful read is edited.
|
|
398
|
-
if ! body="$(
|
|
441
|
+
if ! body="$(_eff_issue_body "$repo" "$next" 2>/dev/null)"; then
|
|
399
442
|
echo " ✗ could not read #$next's body — 'Depends on #$prev' not recorded" >&2; rc=1
|
|
400
443
|
elif printf '%s\n' "$body" | grep -qE "^[[:space:]]*- Depends on #${prev}[[:space:]]*$"; then
|
|
401
444
|
echo " · #$next already records 'Depends on #$prev'" >&2
|
|
402
445
|
else
|
|
403
446
|
newbody="$(_eff_relations_add "$body" "$prev")"
|
|
404
|
-
|
|
447
|
+
_eff_issue_set_body "$repo" "$next" "$newbody" >/dev/null 2>&1 \
|
|
405
448
|
&& echo " ✓ #$next records 'Depends on #$prev'" >&2 \
|
|
406
449
|
|| { echo " ✗ could not update #$next's body" >&2; rc=1; }
|
|
407
450
|
fi
|
|
@@ -614,7 +657,8 @@ effort_start() {
|
|
|
614
657
|
|
|
615
658
|
if [ -n "$slug_override" ]; then slug="$(_eff_slug "$slug_override")"
|
|
616
659
|
else
|
|
617
|
-
title="$(gh
|
|
660
|
+
if cckit_gh_rest; then title="$(gh api "repos/$repo/issues/$num" --jq .title 2>/dev/null)" || title=""
|
|
661
|
+
else title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"; fi
|
|
618
662
|
slug="$(_eff_title_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
|
|
619
663
|
fi
|
|
620
664
|
# Worktree dir follows the kind+N-slug convention (branch-naming.md) so kit-gc's issue-open
|
|
@@ -648,8 +692,25 @@ effort_start() {
|
|
|
648
692
|
|
|
649
693
|
# effort_pr [<slug|N>] — open the single PR effort/<N> → base. Defaults to the current effort branch.
|
|
650
694
|
effort_pr() {
|
|
695
|
+
# The ONE effort-PR implementation (#363). The kit-effort-pr skill calls this; before, the skill
|
|
696
|
+
# carried its own inline copy, so agents hand-copied the script and the copy drifted (a PR missing
|
|
697
|
+
# from the board, a mangled body). Args: [<slug|N>] [--summary S|--summary-file F]
|
|
698
|
+
# [--for-agents A|--for-agents-file F] [--message M] [--title T]. SUMMARY / FOR_AGENTS / COMMIT_MSG env are
|
|
699
|
+
# honoured as fallbacks.
|
|
651
700
|
_eff_need gh || return 1
|
|
652
|
-
local raw="${
|
|
701
|
+
local raw="" summary="${SUMMARY:-}" for_agents="${FOR_AGENTS:-}" msg="${COMMIT_MSG:-}" title_override=""
|
|
702
|
+
while [ $# -gt 0 ]; do
|
|
703
|
+
case "$1" in
|
|
704
|
+
--summary) summary="${2:-}"; shift 2 ;;
|
|
705
|
+
--summary-file) summary="$(cat "${2:-/dev/null}")"; shift 2 ;;
|
|
706
|
+
--for-agents) for_agents="${2:-}"; shift 2 ;;
|
|
707
|
+
--for-agents-file) for_agents="$(cat "${2:-/dev/null}")"; shift 2 ;;
|
|
708
|
+
--message|-m) msg="${2:-}"; shift 2 ;;
|
|
709
|
+
--title) title_override="${2:-}"; shift 2 ;;
|
|
710
|
+
*) [ -z "$raw" ] && raw="$1"; shift ;;
|
|
711
|
+
esac
|
|
712
|
+
done
|
|
713
|
+
local num repo base branch meta title labels milestone role role_disp name pr_title body url author
|
|
653
714
|
repo="$(_eff_repo)"; base="$(_eff_base)"
|
|
654
715
|
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
|
|
655
716
|
if [ -n "$raw" ]; then
|
|
@@ -660,16 +721,114 @@ effort_pr() {
|
|
|
660
721
|
[ -n "$num" ] || { echo "effort_pr: not on an effort/<N>-… branch and no <slug|N> given" >&2; return 1; }
|
|
661
722
|
case "$branch" in effort/"$num"-*) : ;; *) echo "effort_pr: current branch ($branch) is not effort/$num-…" >&2; return 1 ;; esac
|
|
662
723
|
|
|
663
|
-
|
|
664
|
-
|
|
724
|
+
# Parent metadata: the PR inherits its labels + milestone, and the role names the title.
|
|
725
|
+
if cckit_gh_rest; then meta="$(gh_rest_issue_json "$repo" "$num" 2>/dev/null)"
|
|
726
|
+
else meta="$(gh issue view "$num" --repo "$repo" --json title,labels,milestone 2>/dev/null)"; fi
|
|
727
|
+
title="$(printf '%s' "$meta" | jq -r '.title // ""' 2>/dev/null)"
|
|
728
|
+
labels="$(printf '%s' "$meta" | jq -r '[.labels[]?.name] | join(",")' 2>/dev/null)"
|
|
729
|
+
milestone="$(printf '%s' "$meta" | jq -r '.milestone.title // ""' 2>/dev/null)"
|
|
730
|
+
role="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^role://p' | head -1)"
|
|
731
|
+
role_disp=""
|
|
732
|
+
if [ -n "$role" ] && command -v role_display >/dev/null 2>&1; then
|
|
733
|
+
role_disp="$(role_display "$role" 2>/dev/null || true)"
|
|
734
|
+
fi
|
|
665
735
|
name="$(printf '%s' "$title" | sed -E 's/^\[Effort\] [0-9]+ · ?//')"
|
|
666
|
-
|
|
667
|
-
#
|
|
668
|
-
|
|
736
|
+
|
|
737
|
+
# Commit pending changes. Role identity is a Co-authored-by TRAILER, never the git author (some
|
|
738
|
+
# deploy providers refuse commits whose author email matches no account). TRACKED changes only:
|
|
739
|
+
# `git add -A` here would sweep a copied .env.local into the PR. Untracked files are listed, not
|
|
740
|
+
# committed — an effort's new files land in its per-sub commits.
|
|
741
|
+
if [ -n "$(git ls-files --others --exclude-standard 2>/dev/null)" ]; then
|
|
742
|
+
echo "effort_pr: untracked files NOT committed (commit them in their sub's commit if they belong):" >&2
|
|
743
|
+
git ls-files --others --exclude-standard 2>/dev/null | sed 's/^/ /' >&2
|
|
744
|
+
fi
|
|
745
|
+
if [ -n "$(git status --porcelain --untracked-files=no 2>/dev/null)" ]; then
|
|
746
|
+
author=""
|
|
747
|
+
git add -u
|
|
748
|
+
if [ -n "$role" ] && command -v role_git_author >/dev/null 2>&1; then
|
|
749
|
+
author="$(role_git_author "$role" 2>/dev/null || true)"
|
|
750
|
+
fi
|
|
751
|
+
if [ -n "$author" ]; then
|
|
752
|
+
git commit -q -m "${msg:-$role: ${name:-effort $num}}" -m "Co-authored-by: ${author%%|*} <${author##*|}>" || return 1
|
|
753
|
+
else
|
|
754
|
+
git commit -q -m "${msg:-${role:-chore}: ${name:-effort $num}}" || return 1
|
|
755
|
+
fi
|
|
756
|
+
fi
|
|
757
|
+
git push -u origin "$branch" >/dev/null 2>&1 || echo "effort_pr: push of $branch failed — continuing (the PR may already be current)" >&2
|
|
758
|
+
|
|
759
|
+
# ONE shared composer (effort.sh) so every surface titles identically, then the mandatory-[#N]
|
|
760
|
+
# check before we ever call gh — refuse rather than open an id-less PR (#121).
|
|
761
|
+
# --title serves a repo whose PR titles follow another convention (Conventional Commits under a
|
|
762
|
+
# commitlint gate); it must still carry the [#N] id, checked below.
|
|
763
|
+
pr_title="${title_override:-$(effort_pr_title "$num" "${name:-effort}" "$role_disp")}"
|
|
669
764
|
effort_pr_title_check "$pr_title" "$num" || { echo "effort_pr: refusing to open a PR without the [#$num] effort id" >&2; return 1; }
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
765
|
+
body="$(_eff_pr_body "$num" "$summary" "$for_agents" "$role")"
|
|
766
|
+
|
|
767
|
+
# Four explicit forms, not ${x:+--flag "$x"}: that idiom word-splits under zsh, and this file is
|
|
768
|
+
# sourced from zsh too.
|
|
769
|
+
if cckit_gh_rest; then
|
|
770
|
+
url="$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" "$body" "$labels" "$milestone")" || return 1
|
|
771
|
+
elif [ -n "$labels" ] && [ -n "$milestone" ]; then
|
|
772
|
+
url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
|
|
773
|
+
--label "$labels" --milestone "$milestone" --assignee "@me")" || return 1
|
|
774
|
+
elif [ -n "$labels" ]; then
|
|
775
|
+
url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
|
|
776
|
+
--label "$labels" --assignee "@me")" || return 1
|
|
777
|
+
elif [ -n "$milestone" ]; then
|
|
778
|
+
url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
|
|
779
|
+
--milestone "$milestone" --assignee "@me")" || return 1
|
|
780
|
+
else
|
|
781
|
+
url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
|
|
782
|
+
--assignee "@me")" || return 1
|
|
783
|
+
fi
|
|
784
|
+
echo "✓ $url"
|
|
785
|
+
_eff_pr_board "$num" "$url" "$role"
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
# _eff_pr_body <num> <summary> <for-agents> [role] — the effort PR body: the orchestrator header,
|
|
789
|
+
# `Closes #N`, a human Summary, the agent-facing For agents block, and a Verification checklist.
|
|
790
|
+
# An empty section prints a visible placeholder, never nothing, so a reviewer sees what is missing.
|
|
791
|
+
_eff_pr_body() {
|
|
792
|
+
local num="$1" summary="$2" for_agents="$3" role="${4:-}" sig=""
|
|
793
|
+
if [ -n "$role" ] && command -v role_signature >/dev/null 2>&1; then
|
|
794
|
+
sig="$(role_signature "$role" 2>/dev/null || true)"
|
|
795
|
+
fi
|
|
796
|
+
printf '## For the orchestrator\n\nEffort #%s — one PR for the whole effort. Review: the summary below + the diff.\n\nCloses #%s\n\n' "$num" "$num"
|
|
797
|
+
printf '## Summary\n\n%s\n\n' "${summary:-_(no summary given — pass --summary)_}"
|
|
798
|
+
printf '## For agents\n\n%s\n\n' "${for_agents:-See #$num for the goal, scope, and entry points.}"
|
|
799
|
+
printf '## Verification\n\n- [ ] Each sub-issue change is present in the diff\n- [ ] No unrelated files in the diff\n- [ ] Labels + milestone match the parent issue\n- [ ] Local lint/typecheck pass\n'
|
|
800
|
+
[ -n "$sig" ] && printf '\n%s\n' "$sig"
|
|
801
|
+
return 0
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
# _eff_pr_board <num> <pr-url> [role] — add the PR to the board at In Review (+ Role) and move the
|
|
805
|
+
# parent to In Review. A no-op unless Projects v2 is on; a failed PR add is reported, never silent.
|
|
806
|
+
_eff_pr_board() {
|
|
807
|
+
local num="$1" url="$2" role="${3:-}" repo pr_num node item ropt parent
|
|
808
|
+
[ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
|
|
809
|
+
cckit_board_skipped && return 0
|
|
810
|
+
_eo_source_board
|
|
811
|
+
command -v project_add_item >/dev/null 2>&1 || return 0
|
|
812
|
+
repo="$(_eff_repo)"; pr_num="${url##*/}"
|
|
813
|
+
node="$(gh api "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)"
|
|
814
|
+
item=""
|
|
815
|
+
[ -n "$node" ] && item="$(project_add_item "$node" 2>/dev/null || true)"
|
|
816
|
+
if [ -z "$item" ]; then
|
|
817
|
+
echo "⚠ PR #$pr_num was opened but NOT added to the board — add it by hand" >&2
|
|
818
|
+
else
|
|
819
|
+
if [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_IN_REVIEW:-}" ]; then
|
|
820
|
+
project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_REVIEW" >/dev/null 2>&1 || true
|
|
821
|
+
fi
|
|
822
|
+
if [ -n "$role" ] && [ -n "${ROLE_FIELD_ID:-}" ] && command -v role_option_id >/dev/null 2>&1; then
|
|
823
|
+
ropt="$(role_option_id "$role" 2>/dev/null || true)"
|
|
824
|
+
[ -n "$ropt" ] && { project_set_single_select "$item" "$ROLE_FIELD_ID" "$ropt" >/dev/null 2>&1 || true; }
|
|
825
|
+
fi
|
|
826
|
+
fi
|
|
827
|
+
parent="$(project_find_item_by_issue "$num" 2>/dev/null || true)"
|
|
828
|
+
if [ -n "$parent" ] && [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_IN_REVIEW:-}" ]; then
|
|
829
|
+
project_set_single_select "$parent" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_REVIEW" >/dev/null 2>&1 || true
|
|
830
|
+
fi
|
|
831
|
+
return 0
|
|
673
832
|
}
|
|
674
833
|
|
|
675
834
|
# _eo_source_metrics — lazily source effort-metrics.sh so effort_close can call the shipped
|
|
@@ -682,12 +841,23 @@ _eo_source_metrics() {
|
|
|
682
841
|
[ -f "$d/effort-metrics.sh" ] && . "$d/effort-metrics.sh"
|
|
683
842
|
}
|
|
684
843
|
|
|
844
|
+
# _eo_source_gc — lazily source kit-gc.sh so effort_close can collect the effort's `sub/<N>…`
|
|
845
|
+
# worktrees + branches through the LANDED prune path (#388) — the ONE classifier, never a second
|
|
846
|
+
# `git branch -D` loop here. No-op if already loaded; a missing file degrades to "no sub GC".
|
|
847
|
+
_eo_source_gc() {
|
|
848
|
+
command -v kit_gc_prune >/dev/null 2>&1 && return 0
|
|
849
|
+
local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
850
|
+
# shellcheck source=/dev/null
|
|
851
|
+
[ -f "$d/kit-gc.sh" ] && . "$d/kit-gc.sh"
|
|
852
|
+
}
|
|
853
|
+
|
|
685
854
|
# _eo_source_board — lazily source the board helpers (gh-project.sh) + captured field ids so
|
|
686
855
|
# effort_close can set Status=Done from any shell, with no caller wiring (bin/cckit sources the
|
|
687
856
|
# board helpers only for `effort new`). Guarded: a no-op unless Projects v2 is on; a missing
|
|
688
857
|
# gh-project.sh or ids file degrades to a no-op (the board steps below are themselves guarded).
|
|
689
858
|
_eo_source_board() {
|
|
690
859
|
[ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
|
|
860
|
+
cckit_board_skipped && return 0
|
|
691
861
|
if ! command -v project_find_item_by_issue >/dev/null 2>&1; then
|
|
692
862
|
local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
693
863
|
# shellcheck source=/dev/null
|
|
@@ -699,12 +869,19 @@ _eo_source_board() {
|
|
|
699
869
|
return 0
|
|
700
870
|
}
|
|
701
871
|
|
|
872
|
+
# _eo_issue_close_completed <repo> <n> — close as completed on the chosen transport (#396), quietly.
|
|
873
|
+
_eo_issue_close_completed() {
|
|
874
|
+
if cckit_gh_rest; then gh_rest_issue_close "$1" "$2" completed >/dev/null 2>&1
|
|
875
|
+
else gh issue close "$2" --repo "$1" --reason completed >/dev/null 2>&1; fi
|
|
876
|
+
}
|
|
877
|
+
|
|
702
878
|
# _eo_board_done <issue #> — set the board Status=Done for one issue. Guarded like _eff_board_add:
|
|
703
879
|
# a no-op unless Projects v2 is on AND the board helpers + field ids are loaded. Best-effort — a
|
|
704
880
|
# board hiccup never fails the close (the merge already landed).
|
|
705
881
|
_eo_board_done() {
|
|
706
882
|
local n="$1" item
|
|
707
883
|
[ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
|
|
884
|
+
cckit_board_skipped && return 0
|
|
708
885
|
command -v project_find_item_by_issue >/dev/null 2>&1 || return 0
|
|
709
886
|
[ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_DONE:-}" ] || return 0
|
|
710
887
|
item="$(project_find_item_by_issue "$n" 2>/dev/null)" || return 0
|
|
@@ -736,7 +913,9 @@ _eo_knowledge_ingest() {
|
|
|
736
913
|
case "$hook" in /*) : ;; *) hook="$root/$hook" ;; esac # resolve a relative hook against the root
|
|
737
914
|
[ -x "$hook" ] || { echo "effort_close: knowledge-ingest hook '$hook' not executable — skipping" >&2; return 0; }
|
|
738
915
|
echo " → knowledge-ingest hook: $hook $num" >&2
|
|
739
|
-
|
|
916
|
+
# Run it from the main checkout (#371): the close has just removed the worktree it was invoked from,
|
|
917
|
+
# so the inherited cwd no longer exists and a hook's relative paths / bare git calls would fail.
|
|
918
|
+
( cd "${root:-/}" && "$hook" "$num" "$trace" ) >/dev/null 2>&1 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
|
|
740
919
|
}
|
|
741
920
|
|
|
742
921
|
# effort_close <N> — the SINGLE close implementation (#148): the /kit-effort-close skill is a thin
|
|
@@ -774,7 +953,10 @@ effort_close() {
|
|
|
774
953
|
|
|
775
954
|
# (a2) refuse-squash-without-trace backstop: the squash is irreversible and collapses the per-sub
|
|
776
955
|
# commits that ARE the work record. If nothing was snapshotted, refuse — unless KIT_FORCE=1.
|
|
777
|
-
|
|
956
|
+
# index.jsonl is the marker, not the presence of a .diff: the snapshot moves it into place only
|
|
957
|
+
# after every record is written, so a non-empty index means a complete trace. The old `ls *.diff`
|
|
958
|
+
# test passed on the empty NN-.diff a collapsed run left behind (#339).
|
|
959
|
+
if [ -z "$trace_dir" ] || [ ! -s "$trace_dir/index.jsonl" ]; then
|
|
778
960
|
if [ "${KIT_FORCE:-0}" = "1" ]; then
|
|
779
961
|
echo "effort_close: no per-sub work trace captured — proceeding anyway (KIT_FORCE=1)" >&2
|
|
780
962
|
else
|
|
@@ -783,6 +965,21 @@ effort_close() {
|
|
|
783
965
|
fi
|
|
784
966
|
fi
|
|
785
967
|
|
|
968
|
+
# (a2) refuse a conflicting PR before anything is written (#394). The capture below appends a
|
|
969
|
+
# records.jsonl row and consumes the effort's start marker, so a merge that fails after it leaves a
|
|
970
|
+
# row the retry duplicates with build_seconds null. UNKNOWN (GitHub still computing) proceeds.
|
|
971
|
+
local rest_pr="" mergeable
|
|
972
|
+
if cckit_gh_rest; then
|
|
973
|
+
rest_pr="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null)"
|
|
974
|
+
mergeable=""; [ -n "$rest_pr" ] && mergeable="$(gh_rest_pr_json "$repo" "$rest_pr" 2>/dev/null | jq -r .mergeable)"
|
|
975
|
+
else
|
|
976
|
+
mergeable="$(gh pr view "$branch" --repo "$repo" --json mergeable -q .mergeable 2>/dev/null)"
|
|
977
|
+
fi
|
|
978
|
+
if [ "$mergeable" = "CONFLICTING" ]; then
|
|
979
|
+
echo "effort_close: the PR for $branch conflicts with $base — merge or rebase $base into it, then rerun (nothing was written)" >&2
|
|
980
|
+
return 1
|
|
981
|
+
fi
|
|
982
|
+
|
|
786
983
|
# (b) capture effort metrics PRE-squash (needs the live-branch diff + commit signals).
|
|
787
984
|
command -v capture_effort_metrics >/dev/null 2>&1 && capture_effort_metrics "$num" "origin/$base" || true
|
|
788
985
|
|
|
@@ -791,10 +988,18 @@ effort_close() {
|
|
|
791
988
|
kit_touched="$(git diff --name-only "origin/$base"...HEAD 2>/dev/null \
|
|
792
989
|
| grep -E "$_EO_KIT_MANAGED_RE" | sort -u || true)"
|
|
793
990
|
|
|
794
|
-
# (c) squash-merge the effort PR.
|
|
991
|
+
# (c) squash-merge the effort PR. Over REST the remote branch stays: the cloud proxy rejects branch
|
|
992
|
+
# deletion (#396).
|
|
993
|
+
if cckit_gh_rest; then
|
|
994
|
+
{ [ -n "$rest_pr" ] && gh_rest_pr_merge "$repo" "$rest_pr" squash >/dev/null 2>&1; } \
|
|
995
|
+
|| { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
|
|
996
|
+
echo " ✓ merged $branch" >&2
|
|
997
|
+
echo " (remote branch $branch kept — branch deletion is unavailable here; delete it on GitHub)" >&2
|
|
998
|
+
else
|
|
795
999
|
gh pr merge "$branch" --repo "$repo" --squash --delete-branch >/dev/null 2>&1 \
|
|
796
1000
|
|| { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
|
|
797
1001
|
echo " ✓ merged $branch" >&2
|
|
1002
|
+
fi
|
|
798
1003
|
|
|
799
1004
|
# (d) judge + sync the metrics (judge reads the durable trace dir; sync no-ops when the engine is off).
|
|
800
1005
|
command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
|
|
@@ -805,11 +1010,12 @@ effort_close() {
|
|
|
805
1010
|
# issue + record state are owned by this ONE op (effort-model.md) — never a separate "mark done".
|
|
806
1011
|
_eo_source_board
|
|
807
1012
|
local sub
|
|
808
|
-
|
|
809
|
-
|
|
1013
|
+
while IFS= read -r sub; do
|
|
1014
|
+
[ -n "$sub" ] || continue
|
|
1015
|
+
_eo_issue_close_completed "$repo" "$sub" && echo " ✓ closed sub #$sub" >&2
|
|
810
1016
|
_eo_board_done "$sub"
|
|
811
|
-
done
|
|
812
|
-
|
|
1017
|
+
done < <(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null)
|
|
1018
|
+
_eo_issue_close_completed "$repo" "$num" && echo " ✓ closed effort #$num" >&2
|
|
813
1019
|
_eo_board_done "$num"
|
|
814
1020
|
|
|
815
1021
|
# (f) GC: switch the main checkout to base, remove the effort worktree, delete the local branch,
|
|
@@ -818,6 +1024,16 @@ effort_close() {
|
|
|
818
1024
|
if [ -n "$root" ]; then
|
|
819
1025
|
git -C "$root" checkout "$base" >/dev/null 2>&1 || true
|
|
820
1026
|
git -C "$root" pull origin "$base" --quiet >/dev/null 2>&1 || true
|
|
1027
|
+
# (f2) the effort's sub worktrees + branches (#388): the squash just put their work on base, so
|
|
1028
|
+
# kit_gc_prune's LANDED path deletes them — same classifier and recover-before-prune guards as
|
|
1029
|
+
# `cckit cleanup` (a dirty sub worktree, or a sub ahead of its remote, stays). Runs in a subshell
|
|
1030
|
+
# from the main checkout, BEFORE this worktree is removed, with the base `origin/<base>` just
|
|
1031
|
+
# pulled above. A sub that fails both LANDED checks is left as an ORPHAN for `cckit gc` to show.
|
|
1032
|
+
_eo_source_gc
|
|
1033
|
+
if command -v kit_gc_prune >/dev/null 2>&1; then
|
|
1034
|
+
( cd "$root" && KIT_GC_REPO="$repo" KIT_BASE_BRANCH="$base" kit_gc_prune --yes --only "^sub/${num}[a-z]-" 2>&1 \
|
|
1035
|
+
| grep -E '^ (removed worktree|deleted local branch|SKIP)' | sed 's/^ / ✓ sub gc: /' >&2 ) || true
|
|
1036
|
+
fi
|
|
821
1037
|
if [ -n "$self_wt" ] && [ "$self_wt" != "$root" ]; then
|
|
822
1038
|
case "$self_wt" in "$root"/.claude/worktrees/*)
|
|
823
1039
|
git -C "$root" worktree remove "$self_wt" --force >/dev/null 2>&1 && echo " ✓ removed worktree $self_wt" >&2 ;;
|
|
@@ -862,6 +1078,9 @@ _eo_close_wave() {
|
|
|
862
1078
|
|
|
863
1079
|
# (a) read every sub + the merged PR that closed it, one "sub|state|pr|merge-oid|title" line each
|
|
864
1080
|
# (title LAST so a stray "|" in it can't shift the fields awk/read split on).
|
|
1081
|
+
if cckit_gh_rest; then
|
|
1082
|
+
rows="$(gh_rest_wave_rows "$repo" "$num" 2>/dev/null)"
|
|
1083
|
+
else
|
|
865
1084
|
rows="$(gh api graphql -f query='
|
|
866
1085
|
query($o:String!,$r:String!,$n:Int!){ repository(owner:$o,name:$r){ issue(number:$n){
|
|
867
1086
|
subIssues(first:50){ nodes { number state
|
|
@@ -870,6 +1089,7 @@ _eo_close_wave() {
|
|
|
870
1089
|
.data.repository.issue.subIssues.nodes[]
|
|
871
1090
|
| (((.closedByPullRequestsReferences.nodes // []) | map(select(.merged)) | .[0]) // null) as $pr
|
|
872
1091
|
| "\(.number)|\(.state)|\($pr.number // "")|\($pr.mergeCommit.oid // "")|\($pr.title // "")"' 2>/dev/null)"
|
|
1092
|
+
fi
|
|
873
1093
|
[ -n "$rows" ] || { echo "effort_close: no effort/$num-… branch and no readable sub-issues — nothing to close (wave-style needs merged subs, #164)" >&2; return 1; }
|
|
874
1094
|
|
|
875
1095
|
# (b) every sub must be CLOSED with a merged closing PR — otherwise the effort is not done.
|
|
@@ -906,7 +1126,7 @@ _eo_close_wave() {
|
|
|
906
1126
|
for sub in $(printf '%s\n' "$rows" | cut -d'|' -f1); do
|
|
907
1127
|
_eo_board_done "$sub"
|
|
908
1128
|
done
|
|
909
|
-
|
|
1129
|
+
_eo_issue_close_completed "$repo" "$num" && echo " ✓ closed effort #$num" >&2
|
|
910
1130
|
_eo_board_done "$num"
|
|
911
1131
|
|
|
912
1132
|
# (g) GC: the sub branches/worktrees were GC'd by their own merges — just prune stragglers.
|
|
@@ -71,9 +71,11 @@ tc "$GH_LOG" 'scripts/lib/effort-ops\.sh and skills' "body fills ## For agents"
|
|
|
71
71
|
tc "$GH_LOG" 'the verb and skill produce identical' "body fills ## Verification"
|
|
72
72
|
tn "$GH_LOG" '<!--' "no template placeholder left in a filled body"
|
|
73
73
|
|
|
74
|
-
# Label set on the parent: ctx + kind + priority + role + flow (flow lowercased).
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
# Label set on the parent: effort + ctx + kind + priority + role + flow (flow lowercased).
|
|
75
|
+
# `effort` leads: it is the one `effort_plan` queries, and it was read by that verb while nothing
|
|
76
|
+
# wrote it — so `cckit effort plan` answered "no open efforts found" on every repo.
|
|
77
|
+
tc "$GH_LOG" 'issue create .*--label effort,ctx:[SMLX]+,kind:task,priority:p2,role:tech-lead,flow:core' \
|
|
78
|
+
"parent carries effort/ctx/kind/priority/role/flow labels"
|
|
77
79
|
# Flow tag on the composed title.
|
|
78
80
|
tc "$GH_LOG" 'issue edit 1 .*--title \[Effort\] 1 · \[Core\] demo parity effort' \
|
|
79
81
|
"parent title carries the [Core] flow tag + injected number"
|
|
@@ -28,6 +28,15 @@
|
|
|
28
28
|
# errors: mixed — _eff_slug/effort_display are pure; effort_slug_resolve needs gh;
|
|
29
29
|
# effort_branch_rows_origin reaches the network and returns rc 1 when it cannot
|
|
30
30
|
|
|
31
|
+
# The GitHub transport switch (#396): rest mode routes the gh calls below through gh-rest.sh.
|
|
32
|
+
if ! command -v cckit_gh_rest >/dev/null 2>&1; then
|
|
33
|
+
_ghr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/gh-rest.sh"
|
|
34
|
+
# shellcheck source=/dev/null
|
|
35
|
+
[ -f "$_ghr_lib" ] && . "$_ghr_lib"
|
|
36
|
+
unset _ghr_lib
|
|
37
|
+
fi
|
|
38
|
+
command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
|
|
39
|
+
|
|
31
40
|
# Repo for the gh fallback — resolved from the same env effort.sh/kit-config populate.
|
|
32
41
|
_eff_slug_repo() { printf '%s' "${EFFORT_REPO:-${KIT_REPO:-}}"; }
|
|
33
42
|
|
|
@@ -143,12 +152,17 @@ effort_slug_resolve() {
|
|
|
143
152
|
if [ -z "$matches" ] && command -v gh >/dev/null 2>&1; then
|
|
144
153
|
local repo; repo="$(_eff_slug_repo)"
|
|
145
154
|
if [ -n "$repo" ]; then
|
|
155
|
+
if cckit_gh_rest; then
|
|
156
|
+
matches="$(gh_rest_issue_numbers_by_label "$repo" "slug:$norm" 2>/dev/null | grep -E '^[0-9]+$' | sort -un)"
|
|
157
|
+
else
|
|
146
158
|
matches="$(gh issue list --repo "$repo" --state open --label "slug:$norm" \
|
|
147
159
|
--json number -q '.[].number' 2>/dev/null | grep -E '^[0-9]+$' | sort -un)"
|
|
160
|
+
fi
|
|
148
161
|
if [ -z "$matches" ]; then
|
|
149
162
|
local in it
|
|
150
|
-
matches="$(
|
|
151
|
-
|
|
163
|
+
matches="$( { if cckit_gh_rest; then gh_rest_open_issue_titles "$repo" | grep -F '[Effort]'
|
|
164
|
+
else gh issue list --repo "$repo" --state open --search '[Effort] in:title' --limit 200 \
|
|
165
|
+
--json number,title -q '.[] | "\(.number)\t\(.title)"'; fi; } 2>/dev/null \
|
|
152
166
|
| while IFS="$(printf '\t')" read -r in it; do
|
|
153
167
|
[ "$(_eff_title_slug "$it")" = "$norm" ] && printf '%s\n' "$in"
|
|
154
168
|
done | grep -E '^[0-9]+$' | sort -un)"
|
package/scripts/lib/effort.sh
CHANGED
|
@@ -15,6 +15,15 @@
|
|
|
15
15
|
# Requires: gh, jq, git. bash 3.2 compatible.
|
|
16
16
|
# errors: strict — git mechanics: a failed link, snapshot or lint propagates
|
|
17
17
|
|
|
18
|
+
# The GitHub transport switch (#396): rest mode routes the gh calls below through gh-rest.sh.
|
|
19
|
+
if ! command -v cckit_gh_rest >/dev/null 2>&1; then
|
|
20
|
+
_ghr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/gh-rest.sh"
|
|
21
|
+
# shellcheck source=/dev/null
|
|
22
|
+
[ -f "$_ghr_lib" ] && . "$_ghr_lib"
|
|
23
|
+
unset _ghr_lib
|
|
24
|
+
fi
|
|
25
|
+
command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
|
|
26
|
+
|
|
18
27
|
# Repo resolves from kit.config.json (KIT_REPO) — load it if a caller hasn't already.
|
|
19
28
|
if [[ -z "${KIT_REPO:-}" ]]; then
|
|
20
29
|
_eff_root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
@@ -80,29 +89,50 @@ effort_snapshot_subs() {
|
|
|
80
89
|
return 0
|
|
81
90
|
fi
|
|
82
91
|
|
|
83
|
-
#
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
# Split on newlines EXPLICITLY. `for sha in $shas` relied on the shell word-splitting an unquoted
|
|
93
|
+
# expansion: bash does, zsh does not. Sourced into zsh the loop ran once with every SHA as one
|
|
94
|
+
# argument, `git rev-parse --short` failed, and the run still printed "✓ snapshotted 1 commit(s)"
|
|
95
|
+
# and exited 0 — a silently collapsed work record that effort_close's no-trace backstop accepts,
|
|
96
|
+
# because the empty NN-.diff it leaves behind satisfies that check (#339).
|
|
97
|
+
local -a sha_list=()
|
|
98
|
+
local line
|
|
99
|
+
while IFS= read -r line; do
|
|
100
|
+
[[ -n "$line" ]] && sha_list+=("$line")
|
|
101
|
+
done <<EOF_SHAS
|
|
102
|
+
$shas
|
|
103
|
+
EOF_SHAS
|
|
86
104
|
|
|
87
|
-
|
|
88
|
-
|
|
105
|
+
# Build the index beside the real one and move it into place only once every record is written.
|
|
106
|
+
# Truncating index.jsonl up front made a failed re-run destroy the previous trace's pairing while
|
|
107
|
+
# leaving its NN-<short>.diff files on disk — readable bytes nothing could tie to a sub-issue.
|
|
108
|
+
local index="$dir/index.jsonl" staged="$dir/.index.jsonl.part"
|
|
109
|
+
: > "$staged"
|
|
110
|
+
|
|
111
|
+
local sha sub subj body short stub
|
|
112
|
+
for sha in "${sha_list[@]}"; do
|
|
113
|
+
short="$(git rev-parse --short "$sha" 2>/dev/null)"
|
|
114
|
+
if [[ -z "$short" ]]; then
|
|
115
|
+
echo "effort_snapshot_subs: '$sha' is not a commit — refusing to write a partial trace" >&2
|
|
116
|
+
rm -f "$staged"; return 1
|
|
117
|
+
fi
|
|
89
118
|
seq=$((seq + 1))
|
|
90
119
|
subj="$(git log -1 --format='%s' "$sha")"
|
|
91
120
|
body="$(git log -1 --format='%b' "$sha")"
|
|
92
121
|
# Last #<num> mentioned = the sub-issue this commit closes/implements (effort-model convention).
|
|
93
122
|
sub="$(printf '%s\n%s' "$subj" "$body" | grep -oE '#[0-9]+' | tail -1 | tr -d '#')"
|
|
94
|
-
|
|
95
|
-
stub="$(printf '%02d-%s' "$seq" "$(git rev-parse --short "$sha")")"
|
|
123
|
+
stub="$(printf '%02d-%s' "$seq" "$short")"
|
|
96
124
|
git show --no-color --format=fuller "$sha" > "$dir/$stub.diff" 2>/dev/null
|
|
97
|
-
# meta: commit→sub-issue pairing + outcome hint for the record.
|
|
98
|
-
|
|
125
|
+
# meta: commit→sub-issue pairing + outcome hint for the record. -c so one record is one line —
|
|
126
|
+
# index.jsonl is read line-wise by exporters, and pretty-printed records spanned ~9 lines each.
|
|
127
|
+
jq -c -n --arg parent "$parent" --arg sub "${sub:-}" --arg sha "$sha" \
|
|
99
128
|
--arg subject "$subj" --arg branch "$branch" --arg file "$stub.diff" \
|
|
100
129
|
'{parent:($parent|tonumber), sub_issue:(if $sub=="" then null else ($sub|tonumber) end),
|
|
101
130
|
commit:$sha, subject:$subject, branch:$branch, diff_file:$file, outcome:"merged"}' \
|
|
102
131
|
> "$dir/$stub.meta"
|
|
103
|
-
cat "$dir/$stub.meta" >> "$
|
|
132
|
+
cat "$dir/$stub.meta" >> "$staged"
|
|
104
133
|
done
|
|
105
134
|
|
|
135
|
+
mv "$staged" "$index"
|
|
106
136
|
echo " ✓ snapshotted $seq commit(s) to $dir (index.jsonl)" >&2
|
|
107
137
|
printf '%s' "$dir"
|
|
108
138
|
}
|
|
@@ -118,8 +148,10 @@ effort_snapshot_merged_subs() {
|
|
|
118
148
|
[[ -n "$parent" && -n "$rows" ]] || { echo "effort_snapshot_merged_subs: parent + sub rows required" >&2; return 1; }
|
|
119
149
|
dir="$(effort_trace_dir "$parent")" || { echo "effort_snapshot_merged_subs: could not create trace dir" >&2; return 1; }
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
151
|
+
# Same staged-then-moved index as effort_snapshot_subs: a failed re-run must not leave the
|
|
152
|
+
# previous trace unreadable (#339).
|
|
153
|
+
local index="$dir/index.jsonl" staged="$dir/.index.jsonl.part"
|
|
154
|
+
: > "$staged"
|
|
123
155
|
|
|
124
156
|
local sub state pr oid title stub short
|
|
125
157
|
while IFS='|' read -r sub state pr oid title; do
|
|
@@ -127,19 +159,21 @@ effort_snapshot_merged_subs() {
|
|
|
127
159
|
seq=$((seq + 1))
|
|
128
160
|
short="$(printf '%.7s' "$oid")"; [[ -n "$short" ]] || short="pr$pr"
|
|
129
161
|
stub="$(printf '%02d-%s' "$seq" "$short")"
|
|
130
|
-
|
|
162
|
+
if cckit_gh_rest; then gh_rest_pr_diff "$EFFORT_REPO" "$pr" > "$dir/$stub.diff" 2>/dev/null || rm -f "$dir/$stub.diff"
|
|
163
|
+
else gh pr diff "$pr" --repo "$EFFORT_REPO" > "$dir/$stub.diff" 2>/dev/null || rm -f "$dir/$stub.diff"; fi
|
|
131
164
|
[[ -s "$dir/$stub.diff" ]] || { rm -f "$dir/$stub.diff"; seq=$((seq - 1)); continue; }
|
|
132
|
-
jq -n --arg parent "$parent" --arg sub "${sub:-}" --arg sha "${oid:-}" \
|
|
165
|
+
jq -c -n --arg parent "$parent" --arg sub "${sub:-}" --arg sha "${oid:-}" \
|
|
133
166
|
--arg subject "$title" --arg pr "$pr" --arg file "$stub.diff" \
|
|
134
167
|
'{parent:($parent|tonumber), sub_issue:(if $sub=="" then null else ($sub|tonumber) end),
|
|
135
168
|
commit:(if $sha=="" then null else $sha end), pr:($pr|tonumber), subject:$subject,
|
|
136
169
|
branch:null, diff_file:$file, outcome:"merged"}' \
|
|
137
170
|
> "$dir/$stub.meta"
|
|
138
|
-
cat "$dir/$stub.meta" >> "$
|
|
171
|
+
cat "$dir/$stub.meta" >> "$staged"
|
|
139
172
|
done <<EOF_ROWS
|
|
140
173
|
$rows
|
|
141
174
|
EOF_ROWS
|
|
142
175
|
|
|
176
|
+
mv "$staged" "$index"
|
|
143
177
|
echo " ✓ snapshotted $seq merged sub PR diff(s) to $dir (index.jsonl)" >&2
|
|
144
178
|
printf '%s' "$dir"
|
|
145
179
|
}
|