@jeiemgi/cckit 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +15 -4
  3. package/README.md +11 -3
  4. package/bin/cckit +86 -7
  5. package/cckit.config.json +1 -1
  6. package/kit.config.schema.json +43 -2
  7. package/package.json +1 -1
  8. package/scripts/autopilot-test.sh +68 -0
  9. package/scripts/autopilot.sh +16 -10
  10. package/scripts/check.sh +14 -1
  11. package/scripts/copilot-loop-test.sh +3 -0
  12. package/scripts/guard-raw-git-ops-test.sh +65 -0
  13. package/scripts/init.sh +68 -8
  14. package/scripts/lib/agent-profile-test.sh +151 -0
  15. package/scripts/lib/agent-profile.sh +195 -0
  16. package/scripts/lib/agent-resolve-test.sh +156 -0
  17. package/scripts/lib/agent-resolve.sh +177 -0
  18. package/scripts/lib/branch-owner-test.sh +99 -0
  19. package/scripts/lib/branch-owner.sh +194 -0
  20. package/scripts/lib/captain-test.sh +86 -0
  21. package/scripts/lib/captain.sh +142 -7
  22. package/scripts/lib/contribute-root-test.sh +40 -0
  23. package/scripts/lib/contribute-root.sh +22 -0
  24. package/scripts/lib/effort-ops-test.sh +42 -2
  25. package/scripts/lib/effort-ops.sh +157 -14
  26. package/scripts/lib/effort-parity-test.sh +5 -3
  27. package/scripts/lib/effort.sh +38 -14
  28. package/scripts/lib/hook-refresh-test.sh +65 -0
  29. package/scripts/lib/hook-refresh.sh +62 -0
  30. package/scripts/lib/kit-config.sh +6 -0
  31. package/scripts/lib/kit-gc-test.sh +178 -1
  32. package/scripts/lib/kit-gc.sh +233 -55
  33. package/scripts/lib/kit-task-ops-test.sh +15 -0
  34. package/scripts/lib/kit-task-ops.sh +65 -21
  35. package/scripts/lib/kto-task-pr-merge-test.sh +72 -0
  36. package/scripts/lib/kto-task-pr-test.sh +59 -0
  37. package/scripts/lib/orchestration-runtime-test.sh +142 -0
  38. package/scripts/lib/orchestration-runtime.sh +171 -0
  39. package/scripts/lib/review-stage-test.sh +241 -0
  40. package/scripts/lib/review-stage.sh +259 -0
  41. package/scripts/lib/stage-receipt-test.sh +252 -0
  42. package/scripts/lib/stage-receipt.sh +442 -0
  43. package/scripts/lib/test-env-test.sh +25 -0
  44. package/scripts/lib/test-env.sh +30 -0
  45. package/scripts/lib/worker-brief-test.sh +120 -0
  46. package/scripts/lib/worker-brief.sh +185 -0
  47. package/scripts/lib/worktree-ports-test.sh +146 -0
  48. package/scripts/lib/worktree-start.sh +137 -7
  49. package/scripts/lib/zsh-safety-test.sh +67 -0
  50. package/scripts/orchestrate.sh +124 -22
  51. package/scripts/portable-test.sh +22 -1
  52. package/scripts/review-lint-baseline.txt +28 -0
  53. package/scripts/review-lint-test.sh +271 -0
  54. package/scripts/review-lint.sh +259 -0
  55. package/scripts/review-rules.conf +55 -0
  56. package/scripts/setup-labels.sh +21 -1
  57. package/scripts/skill-frontmatter-baseline.txt +24 -0
  58. package/scripts/skill-frontmatter-lint-test.sh +156 -0
  59. package/scripts/skill-frontmatter-lint.sh +182 -0
  60. package/scripts/task-sync.sh +8 -0
  61. package/scripts/test.sh +10 -1
  62. package/skills/kit-autopilot/SKILL.md +13 -1
  63. package/skills/kit-cleanup/SKILL.md +5 -3
  64. package/skills/kit-contribute/SKILL.md +6 -5
  65. package/skills/kit-effort-close/SKILL.md +8 -3
  66. package/skills/kit-effort-pr/SKILL.md +16 -95
  67. package/skills/kit-gc/SKILL.md +15 -10
  68. package/skills/kit-security-sweep/SKILL.md +4 -6
  69. package/skills/kit-ship/SKILL.md +1 -1
  70. package/skills/kit-task-pr/SKILL.md +2 -0
  71. package/templates/hooks/guard-raw-git-ops.sh.tmpl +180 -0
  72. package/templates/rules/branch-naming.md +6 -0
  73. package/templates/rules/effort-model.md +3 -0
  74. package/templates/rules/naming-and-ids.md +4 -1
  75. package/templates/settings/settings.json.tmpl +4 -2
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env bash
2
+ # guard-raw-git-ops.sh — PreToolUse(Bash) hook. Scaffolded by cckit (#364).
3
+ #
4
+ # In a repo with a cckit config, the verbs own the side effects of the GitHub lifecycle: board add,
5
+ # Role/Status fields, labels, milestone, the worktree claim, the trace. A raw `gh issue create`
6
+ # skips every one of them, silently. This hook blocks the raw form and prints the verb to run:
7
+ #
8
+ # gh issue create -> cckit new --role <role> "<title>" (multi-part: cckit effort new)
9
+ # gh pr create -> cckit pr <issue> "<summary>" (effort: cckit effort pr <N>)
10
+ # gh pr merge -> cckit merge [<pr>] (effort: cckit effort close <N>)
11
+ # gh issue close -> cckit close <issue> "<summary>"
12
+ # git checkout -b / switch -c / worktree add, on the base branch
13
+ # -> cckit start <issue> (effort: cckit effort start <N>)
14
+ #
15
+ # Only the agent's OWN command is inspected. The gh/git calls the verbs make internally run in a
16
+ # child process, which this hook never sees, so the verbs cannot trip it.
17
+ #
18
+ # Escape hatch, recorded: prefix the command with KIT_ALLOW_RAW=1 (or export it). Each bypass is
19
+ # appended to <git-common-dir>/cckit/raw-bypass.log, so the trail survives worktree removal.
20
+ #
21
+ # Exit 2 blocks (the agent sees stderr). Fails OPEN on anything ambiguous: no jq, no command, no
22
+ # git repo, no cckit config. A guard must never block work it cannot read.
23
+ # Self-test: bash <this file> --selftest
24
+
25
+ set -uo pipefail
26
+
27
+ # _grg_strip <cmd> — drop the text that is never executed: single-quoted strings and heredoc
28
+ # bodies. A commit message or a doc snippet that MENTIONS `gh pr create` is not a call to it.
29
+ _grg_strip() {
30
+ printf '%s\n' "$1" | awk '
31
+ term != "" { t=$0; sub(/^[ \t]+/, "", t); if (t == term) term=""; next }
32
+ {
33
+ line=$0
34
+ if (match(line, /<<-?[ \t]*["\x27]?[A-Za-z_][A-Za-z0-9_]*/)) {
35
+ h=substr(line, RSTART, RLENGTH); gsub(/^<<-?[ \t]*["\x27]?/, "", h); term=h
36
+ }
37
+ gsub(/\x27[^\x27]*\x27/, "\x27\x27", line)
38
+ print line
39
+ }'
40
+ }
41
+
42
+ # _grg_segments <cmd> — one simple command per line: split on ; & | ( ) { } ` and newlines, trim,
43
+ # then drop leading VAR=value assignments and wrapper words (command exec env time nohup sudo).
44
+ _grg_segments() {
45
+ _grg_strip "$1" | tr ';&|(){}`' '\n\n\n\n\n\n\n\n' | sed -E \
46
+ -e 's/^[[:space:]]+//' \
47
+ -e ':a' -e 's/^[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*[[:space:]]+//' -e 'ta' \
48
+ -e ':b' -e 's/^(command|exec|env|time|nohup|sudo)[[:space:]]+//' -e 'tb' \
49
+ -e 's/^\$//' -e 's/^[[:space:]]+//'
50
+ }
51
+
52
+ # _grg_classify <segment> — print the raw-op key for one simple command, or nothing.
53
+ _grg_classify() {
54
+ local s="$1"
55
+ if printf '%s' "$s" | grep -qE '^gh([[:space:]]+(-R|--repo)[[:space:]]+[^[:space:]]+|[[:space:]]+--repo=[^[:space:]]+)*[[:space:]]+issue[[:space:]]+create([[:space:]]|$)'; then echo issue-create
56
+ elif printf '%s' "$s" | grep -qE '^gh([[:space:]]+(-R|--repo)[[:space:]]+[^[:space:]]+|[[:space:]]+--repo=[^[:space:]]+)*[[:space:]]+issue[[:space:]]+close([[:space:]]|$)'; then echo issue-close
57
+ elif printf '%s' "$s" | grep -qE '^gh([[:space:]]+(-R|--repo)[[:space:]]+[^[:space:]]+|[[:space:]]+--repo=[^[:space:]]+)*[[:space:]]+pr[[:space:]]+create([[:space:]]|$)'; then echo pr-create
58
+ elif printf '%s' "$s" | grep -qE '^gh([[:space:]]+(-R|--repo)[[:space:]]+[^[:space:]]+|[[:space:]]+--repo=[^[:space:]]+)*[[:space:]]+pr[[:space:]]+merge([[:space:]]|$)'; then echo pr-merge
59
+ elif printf '%s' "$s" | grep -qE '^git([[:space:]]+-C[[:space:]]+[^[:space:]]+)*[[:space:]]+(checkout[[:space:]]+(.*[[:space:]])?-[bB]|switch[[:space:]]+(.*[[:space:]])?(-c|-C|--create)|worktree[[:space:]]+add)([[:space:]]|$)'; then echo branch
60
+ fi
61
+ }
62
+
63
+ # _grg_hint <key> — the verb to run instead.
64
+ _grg_hint() {
65
+ case "$1" in
66
+ issue-create) echo 'cckit new --role <role> [--kind K --priority P --body-file F] "<title>" (multi-part work: cckit effort new)' ;;
67
+ issue-close) echo 'cckit close <issue> "<summary>" (an effort: cckit effort close <N>)' ;;
68
+ pr-create) echo 'cckit pr <issue> "<summary>" (an effort: cckit effort pr <N> --summary-file F --for-agents-file F)' ;;
69
+ pr-merge) echo 'cckit merge [<pr>] (an effort: cckit effort close <N>)' ;;
70
+ branch) echo 'cckit start <issue> (an effort: cckit effort start <N>)' ;;
71
+ esac
72
+ }
73
+
74
+ # _grg_config <dir> — the cckit config governing <dir>, or rc 1 (same walk as config-path.sh).
75
+ _grg_config() {
76
+ local d; d="$(cd "${1:-.}" 2>/dev/null && pwd)" || return 1
77
+ while [ -n "$d" ]; do
78
+ [ -f "$d/cckit.config.json" ] && { printf '%s\n' "$d/cckit.config.json"; return 0; }
79
+ [ -f "$d/.claude/kit.config.json" ] && { printf '%s\n' "$d/.claude/kit.config.json"; return 0; }
80
+ [ "$d" = "/" ] && break
81
+ d="$(dirname "$d")"
82
+ done
83
+ return 1
84
+ }
85
+
86
+ _grg_selftest() {
87
+ local fail=0 c want got
88
+ while IFS='|' read -r want c; do
89
+ [ -z "$c" ] && continue
90
+ got=""
91
+ while IFS= read -r seg; do
92
+ [ -z "$seg" ] && continue
93
+ k="$(_grg_classify "$seg")"; [ -n "$k" ] && { got="$k"; break; }
94
+ done <<< "$(_grg_segments "$c")"
95
+ if [ "$got" = "$want" ]; then echo "ok: [$want] $c"; else echo "FAIL: '$c' -> got '$got' want '$want'"; fail=1; fi
96
+ done <<'CASES'
97
+ issue-create|gh issue create --title x --body y
98
+ issue-create|gh -R o/r issue create -t x
99
+ issue-create|cd /tmp && gh issue create -t x
100
+ issue-create|url=$(gh issue create -t x)
101
+ issue-create|FOO=1 gh issue create -t x
102
+ pr-create|gh pr create --base develop
103
+ pr-create|git push -u origin HEAD; gh pr create --fill
104
+ pr-merge|gh pr merge 12 --squash
105
+ pr-merge|gh --repo o/r pr merge 12
106
+ issue-close|gh issue close 5 --comment done
107
+ branch|git checkout -b feat/1-x
108
+ branch|git -C /tmp/r switch -c feat/1-x
109
+ branch|git worktree add ../wt -b feat/1-x
110
+ branch|git checkout -q -b feat/1-x origin/develop
111
+ |gh issue view 5
112
+ |gh pr list --state open
113
+ |gh pr view 7 --json body
114
+ |git checkout develop
115
+ |git switch feat/1-x
116
+ |git commit -m 'never run gh pr create by hand'
117
+ |rg -n 'gh issue create' .claude
118
+ |cckit pr 12 "summary"
119
+ |cckit new --role tech-lead "title"
120
+ |echo 'gh pr merge 1'
121
+ CASES
122
+ # heredoc bodies are data, not commands
123
+ got=""; while IFS= read -r seg; do k="$(_grg_classify "$seg")"; [ -n "$k" ] && got="$k"; done \
124
+ <<< "$(_grg_segments "$(printf 'cat > f.md <<EOF\ngh pr create --fill\nEOF\necho done')")"
125
+ if [ -z "$got" ]; then echo "ok: heredoc body ignored"; else echo "FAIL: heredoc body classified as $got"; fail=1; fi
126
+ return "$fail"
127
+ }
128
+
129
+ [ "${1:-}" = "--selftest" ] && { _grg_selftest; exit $?; }
130
+
131
+ command -v jq >/dev/null 2>&1 || exit 0
132
+ input="$(cat 2>/dev/null)"
133
+ cmd="$(printf '%s' "$input" | jq -r '.tool_input.command // empty' 2>/dev/null)"
134
+ [ -z "$cmd" ] && exit 0
135
+ # Cheap prefilter: nothing to inspect unless gh or git appears at all.
136
+ printf '%s' "$cmd" | grep -qE '(^|[^A-Za-z0-9_-])(gh|git)[[:space:]]' || exit 0
137
+
138
+ key=""
139
+ while IFS= read -r seg; do
140
+ [ -z "$seg" ] && continue
141
+ key="$(_grg_classify "$seg")"; [ -n "$key" ] && break
142
+ done <<< "$(_grg_segments "$cmd")"
143
+ [ -z "$key" ] && exit 0
144
+
145
+ # Resolve the directory the command runs in (as guard-base-branch-commit does): `git -C <dir>`, a
146
+ # leading `cd <dir>`, else the tool's cwd.
147
+ cwd="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null)"
148
+ dir=""
149
+ if [[ "$cmd" =~ git[[:space:]]+-C[[:space:]]+([^[:space:]]+) ]]; then dir="${BASH_REMATCH[1]}"
150
+ elif [[ "$cmd" =~ (^|[\&\;\|])[[:space:]]*cd[[:space:]]+([^[:space:]\&\;\|]+) ]]; then dir="${BASH_REMATCH[2]}"; fi
151
+ dir="${dir%\"}"; dir="${dir#\"}"; dir="${dir%\'}"; dir="${dir#\'}"
152
+ case "$dir" in ""|*'$'*) dir="${cwd:-${CLAUDE_PROJECT_DIR:-$PWD}}" ;; esac
153
+
154
+ cfg="$(_grg_config "$dir")" || exit 0 # not a cckit repo: not our business
155
+
156
+ # A branch op is only a bypass when it cuts work from the base branch (cckit start's job).
157
+ # Branching inside an issue or effort worktree (a sub branch, a scratch branch) is fine.
158
+ if [ "$key" = branch ]; then
159
+ base="$(jq -r '.github.baseBranch // .git.baseBranch // empty' "$cfg" 2>/dev/null)"
160
+ cur="$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null)" || exit 0
161
+ case "$cur" in "${base:-develop}"|main|master|develop) : ;; *) exit 0 ;; esac
162
+ fi
163
+
164
+ if [ "${KIT_ALLOW_RAW:-}" = 1 ] || printf '%s' "$cmd" | grep -qE '(^|[^A-Za-z0-9_])KIT_ALLOW_RAW=1([[:space:]]|$)'; then
165
+ common="$(git -C "$dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
166
+ if [ -n "$common" ]; then
167
+ mkdir -p "$common/cckit" 2>/dev/null
168
+ printf '%s\t%s\t%s\t%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$key" "$dir" \
169
+ "$(printf '%s' "$cmd" | tr '\n\t' ' ' | cut -c1-300)" >> "$common/cckit/raw-bypass.log" 2>/dev/null
170
+ fi
171
+ echo "cckit: raw $key allowed by KIT_ALLOW_RAW=1 — recorded in ${common:-<no git dir>}/cckit/raw-bypass.log" >&2
172
+ exit 0
173
+ fi
174
+
175
+ {
176
+ echo "BLOCKED: raw '$key' in a cckit repo. The verb owns the side effects (board, labels, worktree); the raw command skips them silently."
177
+ echo "Run instead: $(_grg_hint "$key")"
178
+ echo "If the verb is broken, fix the verb. Deliberate one-off: prefix KIT_ALLOW_RAW=1 (recorded in <git-common-dir>/cckit/raw-bypass.log)."
179
+ } >&2
180
+ exit 2
@@ -81,6 +81,12 @@ Lockfiles (`pnpm-lock.yaml`, `package-lock.json`, …) and manifest config confl
81
81
  **Two agents in the same git checkout corrupt each other.** The working tree, index, and `HEAD` are a single unguarded shared resource: one agent's `mv`/`add`/`stage` is silently clobbered by another's `reset`/`checkout`/`stash`/`rebase`. Git has no locking for this.
82
82
 
83
83
  - **One agent = one git worktree** (or a separate clone). Never two agents in the same directory.
84
+ - **`orchestrate` enforces this with a lease, not just prose.** Git refuses one branch in two
85
+ worktrees; it does not stop two agent processes from driving the branch cckit handed them. Every
86
+ branch in a wave is claimed before any pane starts (`scripts/lib/branch-owner.sh`), a branch a
87
+ live writer already owns refuses the launch, and the wave's other claims are released. A lease is
88
+ reclaimed only on positive evidence — its worktree is gone, or its process died on the host that
89
+ recorded it — never on a process check against another host.
84
90
  - Prefer giving local sub-agents their own worktree.
85
91
  - Remote CI agents (Auto-Dev) are isolated per runner — favor them for parallel fixes.
86
92
  - Before editing shared files, check whether another agent is active.
@@ -197,6 +197,9 @@ The parent issue **is** the plan. Strategy / roadmap narrative lives in your kno
197
197
 
198
198
  - Snapshot each sub-branch diff **before squash** (squash destroys per-sub-issue pairs) — `effort-close`
199
199
  step (a) does this automatically, to a durable dir under the shared git-common-dir.
200
+ - `index.jsonl` is the completeness marker, not the presence of a `.diff`. The snapshot moves it
201
+ into place only once every record is written, and `effort-close` step (a2) refuses the squash
202
+ unless it is non-empty. A `.diff` on disk proves a file was created, not that the trace is whole.
200
203
  - Scrub secrets from diffs/bodies before they enter an issue or any exported record.
201
204
  - Keep client/tenant data out of the dev-workflow record (it is not your development history).
202
205
  - Outcome labels: merged-clean = positive · abandoned/reverted = negative · a manual flag for exemplars.
@@ -165,6 +165,7 @@ nobody consumes.
165
165
  | `flow:` | `core` `docs` … | effort dispatch | which flow owns it |
166
166
  | `role:` | `tech-lead` `docs` … | delegation brief | who it is written for |
167
167
  | `kind:` | must discriminate | board grouping | what sort of work it is |
168
+ | `agent:` | one per declared profile | `ap_profile_from_labels` | which agent profile runs the work |
168
169
  | `slug:` | one per effort | `effort_slug_resolve` | resolve a name to an effort |
169
170
 
170
171
  ### Rules
@@ -177,7 +178,9 @@ nobody consumes.
177
178
  anything unknown, so an `XL` effort with no `ctx:XL` label silently weighs the same as an `M`.
178
179
  A scale the code knows but the board cannot express is a scale that quietly misreports.
179
180
  - **Do not create per-item labels beyond `slug:`.** They grow without bound and match one issue
180
- each, which makes them useless as a board axis.
181
+ each, which makes them useless as a board axis. `agent:<profile>` is not one of these: it is
182
+ bounded by the profiles the config declares, and `scripts/setup-labels.sh` provisions exactly
183
+ those, so the family stays a board axis rather than a per-issue tag.
181
184
  - **Leave `autorelease:*` alone** — release-please owns those.
182
185
 
183
186
  ### Priority means urgency, not membership
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "permissions": {
3
- "comment": "Versioned (checked-in) permissions so they travel to every worktree and scaffolded project. Captain default: merging each green wave PR under an APPROVED plan is pre-authorized execution (kit-autopilot, established-plan autonomy) — the explicit merge rule keeps auto-mode from prompting on a planned merge.",
3
+ "comment": "Versioned (checked-in) permissions so they travel to every worktree and scaffolded project. Captain default: merging each green wave PR under an APPROVED plan is pre-authorized execution (kit-autopilot, established-plan autonomy) — the explicit merge rules keep auto-mode from prompting on a planned merge. Merges go through the verbs: raw gh pr merge is blocked by guard-raw-git-ops.sh.",
4
4
  "allow": [
5
- "Bash(gh pr merge:*)",
5
+ "Bash(cckit merge:*)",
6
+ "Bash(cckit watch:*)",
7
+ "Bash(cckit effort close:*)",
6
8
  "Bash(cckit orchestrate:*)"
7
9
  ]
8
10
  }