@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.
Files changed (82) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +15 -4
  3. package/README.md +25 -3
  4. package/bin/cckit +91 -8
  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 +73 -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-metrics.sh +14 -1
  25. package/scripts/lib/effort-ops-test.sh +54 -2
  26. package/scripts/lib/effort-ops.sh +243 -23
  27. package/scripts/lib/effort-parity-test.sh +5 -3
  28. package/scripts/lib/effort-slug.sh +16 -2
  29. package/scripts/lib/effort.sh +49 -15
  30. package/scripts/lib/gh-project.sh +14 -0
  31. package/scripts/lib/gh-rest-test.sh +301 -0
  32. package/scripts/lib/gh-rest.sh +289 -0
  33. package/scripts/lib/hook-refresh-test.sh +65 -0
  34. package/scripts/lib/hook-refresh.sh +62 -0
  35. package/scripts/lib/kit-config.sh +6 -0
  36. package/scripts/lib/kit-gc-test.sh +178 -1
  37. package/scripts/lib/kit-gc.sh +251 -55
  38. package/scripts/lib/kit-task-ops-test.sh +15 -0
  39. package/scripts/lib/kit-task-ops.sh +231 -58
  40. package/scripts/lib/kto-task-close-test.sh +83 -0
  41. package/scripts/lib/kto-task-pr-merge-test.sh +129 -0
  42. package/scripts/lib/kto-task-pr-test.sh +59 -0
  43. package/scripts/lib/orchestration-runtime-test.sh +142 -0
  44. package/scripts/lib/orchestration-runtime.sh +171 -0
  45. package/scripts/lib/review-stage-test.sh +241 -0
  46. package/scripts/lib/review-stage.sh +259 -0
  47. package/scripts/lib/stage-receipt-test.sh +252 -0
  48. package/scripts/lib/stage-receipt.sh +442 -0
  49. package/scripts/lib/test-env-test.sh +25 -0
  50. package/scripts/lib/test-env.sh +33 -0
  51. package/scripts/lib/worker-brief-test.sh +120 -0
  52. package/scripts/lib/worker-brief.sh +185 -0
  53. package/scripts/lib/worktree-issue.sh +14 -0
  54. package/scripts/lib/worktree-ports-test.sh +146 -0
  55. package/scripts/lib/worktree-start.sh +153 -8
  56. package/scripts/lib/zsh-safety-test.sh +67 -0
  57. package/scripts/orchestrate.sh +124 -22
  58. package/scripts/portable-test.sh +22 -1
  59. package/scripts/review-lint-baseline.txt +28 -0
  60. package/scripts/review-lint-test.sh +271 -0
  61. package/scripts/review-lint.sh +259 -0
  62. package/scripts/review-rules.conf +55 -0
  63. package/scripts/setup-labels.sh +21 -1
  64. package/scripts/skill-frontmatter-baseline.txt +24 -0
  65. package/scripts/skill-frontmatter-lint-test.sh +156 -0
  66. package/scripts/skill-frontmatter-lint.sh +182 -0
  67. package/scripts/task-sync.sh +8 -0
  68. package/scripts/test.sh +10 -1
  69. package/skills/kit-autopilot/SKILL.md +13 -1
  70. package/skills/kit-cleanup/SKILL.md +5 -3
  71. package/skills/kit-contribute/SKILL.md +6 -5
  72. package/skills/kit-effort-close/SKILL.md +8 -3
  73. package/skills/kit-effort-pr/SKILL.md +16 -95
  74. package/skills/kit-gc/SKILL.md +15 -10
  75. package/skills/kit-security-sweep/SKILL.md +4 -6
  76. package/skills/kit-ship/SKILL.md +1 -1
  77. package/skills/kit-task-pr/SKILL.md +2 -0
  78. package/templates/hooks/guard-raw-git-ops.sh.tmpl +193 -0
  79. package/templates/rules/branch-naming.md +6 -0
  80. package/templates/rules/effort-model.md +3 -0
  81. package/templates/rules/naming-and-ids.md +4 -1
  82. package/templates/settings/settings.json.tmpl +4 -2
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env bash
2
+ # guard-raw-git-ops-test.sh — end-to-end test of the raw-git guard hook (#364): feed it the
3
+ # PreToolUse JSON Claude Code sends, in a throwaway cckit repo and a non-cckit repo.
4
+ # Run: bash scripts/guard-raw-git-ops-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
+ set -u
7
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
8
+ HOOK="$ROOT/templates/hooks/guard-raw-git-ops.sh.tmpl"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ command -v jq >/dev/null 2>&1 || { echo "guard-raw-git-ops-test: jq required" >&2; exit 1; }
12
+
13
+ bash "$HOOK" --selftest >/dev/null || { echo "FAIL: classifier self-test (run: bash $HOOK --selftest)"; fail=1; }
14
+
15
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
16
+ kit="$tmp/kit"; plain="$tmp/plain"
17
+ for r in "$kit" "$plain"; do
18
+ git init -q -b develop "$r" && git -C "$r" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
19
+ done
20
+ mkdir -p "$kit/.claude"; printf '{"github":{"baseBranch":"develop"}}\n' > "$kit/.claude/kit.config.json"
21
+
22
+ run() { # <cwd> <command> -> echoes the hook's exit code
23
+ jq -n --arg c "$2" --arg d "$1" '{tool_input:{command:$c},cwd:$d}' | bash "$HOOK" >/dev/null 2>&1
24
+ echo $?
25
+ }
26
+
27
+ t "blocks gh issue create in a cckit repo" "$(run "$kit" 'gh issue create -t x -b y')" 2
28
+ t "blocks gh pr create in a cckit repo" "$(run "$kit" 'gh pr create --fill')" 2
29
+ t "blocks gh pr merge in a cckit repo" "$(run "$kit" 'gh pr merge 3 --squash')" 2
30
+ t "blocks gh issue close in a cckit repo" "$(run "$kit" 'gh issue close 3')" 2
31
+ t "blocks git checkout -b on the base branch" "$(run "$kit" 'git checkout -b feat/1-x')" 2
32
+ t "allows read-only gh" "$(run "$kit" 'gh pr view 3 --json body')" 0
33
+ t "allows the verbs" "$(run "$kit" 'cckit pr 3 "summary"')" 0
34
+ t "ignores a repo with no cckit config" "$(run "$plain" 'gh pr create --fill')" 0
35
+ t "resolves the repo from cd <dir>" "$(run "$plain" "cd $kit && gh pr create --fill")" 2
36
+
37
+ git -C "$kit" checkout -q -b feat/1-x
38
+ t "allows a branch cut off a non-base branch" "$(run "$kit" 'git checkout -b scratch')" 0
39
+ git -C "$kit" checkout -q develop
40
+
41
+ out="$(jq -n --arg c 'gh issue create -t x' --arg d "$kit" '{tool_input:{command:$c},cwd:$d}' | bash "$HOOK" 2>&1)"
42
+ case "$out" in *"cckit new --role"*) echo "ok: the block names the verb to run" ;; *) echo "FAIL: no verb hint in: $out"; fail=1 ;; esac
43
+
44
+ # #376/#377: the hint names the verb flag matching the raw command's flag
45
+ hint() { jq -n --arg c "$1" --arg d "$kit" '{tool_input:{command:$c},cwd:$d}' | bash "$HOOK" 2>&1 | sed -n 's/^Run instead: //p'; }
46
+ case "$(hint 'gh pr merge 5 --merge')" in "cckit merge [<pr>] --merge"*) echo "ok: gh pr merge --merge -> cckit merge --merge" ;; *) echo "FAIL: merge hint: $(hint 'gh pr merge 5 --merge')"; fail=1 ;; esac
47
+ case "$(hint 'gh pr merge 5 --rebase')" in "cckit merge [<pr>] --rebase"*) echo "ok: gh pr merge --rebase -> cckit merge --rebase" ;; *) echo "FAIL: rebase hint"; fail=1 ;; esac
48
+ case "$(hint 'gh issue close 9 --duplicate-of 4')" in "cckit close <issue> --duplicate-of 4"*) echo "ok: gh issue close --duplicate-of N -> cckit close --duplicate-of N" ;; *) echo "FAIL: duplicate hint: $(hint 'gh issue close 9 --duplicate-of 4')"; fail=1 ;; esac
49
+ case "$(hint 'gh issue close 9 --reason "not planned"')" in *"--reason not-planned"*) echo "ok: gh issue close --reason 'not planned' -> --reason not-planned" ;; *) echo "FAIL: not-planned hint"; fail=1 ;; esac
50
+ t "gh issue close --help is not blocked" "$(run "$kit" 'gh issue close --help')" 0
51
+
52
+ t "KIT_ALLOW_RAW=1 lets one command through" "$(run "$kit" 'KIT_ALLOW_RAW=1 gh pr create --fill')" 0
53
+ t "the bypass is recorded" "$(grep -c 'pr-create' "$kit/.git/cckit/raw-bypass.log" 2>/dev/null)" 1
54
+
55
+ # ── init / init --upgrade wire the guard into the TRACKED settings.json, once ─────────────────
56
+ proj="$tmp/proj"
57
+ git init -q "$proj" && git -C "$proj" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
58
+ mkdir -p "$proj/.claude"
59
+ printf '{"kitVersion":"0.0.1","profile":"software","project":{"name":"G","slug":"g"},"github":{"repo":"e/g","owner":"e","projectsV2":false}}\n' > "$proj/.claude/kit.config.json"
60
+ # a project's own PreToolUse hooks must survive the merge
61
+ printf '{"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"own-guard.sh"}]}]}}\n' > "$proj/.claude/settings.json"
62
+ for _ in 1 2; do
63
+ CLAUDE_PLUGIN_ROOT="$ROOT" bash "$ROOT/scripts/init.sh" --upgrade --target "$proj" --force >/dev/null 2>&1 \
64
+ || { echo "FAIL: init.sh --upgrade exited non-zero"; fail=1; }
65
+ done
66
+ S="$proj/.claude/settings.json"
67
+ t "init --upgrade copies the hook" "$([ -x "$proj/.claude/hooks/guard-raw-git-ops.sh" ] && echo yes)" yes
68
+ t "the guard is wired exactly once (2 upgrades)" "$(jq '[.hooks.PreToolUse[].hooks[] | select(.command | endswith("guard-raw-git-ops.sh"))] | length' "$S")" 1
69
+ t "the wiring uses \$CLAUDE_PROJECT_DIR" "$(jq -r '[.hooks.PreToolUse[].hooks[].command | select(endswith("guard-raw-git-ops.sh"))][0]' "$S")" '$CLAUDE_PROJECT_DIR/.claude/hooks/guard-raw-git-ops.sh'
70
+ t "the project's own hook is kept" "$(jq '[.hooks.PreToolUse[].hooks[] | select(.command == "own-guard.sh")] | length' "$S")" 1
71
+
72
+ [ "$fail" -eq 0 ] && echo "guard-raw-git-ops: all passed" || echo "guard-raw-git-ops: FAILURES"
73
+ exit "$fail"
package/scripts/init.sh CHANGED
@@ -356,6 +356,8 @@ BASENAME="$(basename "$TARGET")"
356
356
  # different name — and only fall back to the directory basename (#73).
357
357
  # shellcheck source=/dev/null
358
358
  . "$KIT_ROOT/scripts/lib/git-remote.sh"
359
+ # shellcheck source=/dev/null
360
+ . "$KIT_ROOT/scripts/lib/hook-refresh.sh" # hook_refresh_state — refresh unmodified hooks (#370)
359
361
  NAME_SRC="$(git_remote_repo_name "$TARGET" 2>/dev/null || true)"; NAME_SRC="${NAME_SRC:-$BASENAME}"
360
362
  [[ -z "$NAME" ]] && NAME="$NAME_SRC"
361
363
  [[ -z "$SLUG" ]] && SLUG="$(echo "$NAME_SRC" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-|-$//g')"
@@ -557,6 +559,22 @@ safe_copy() { # <src> <dest> [exec]
557
559
  return 0
558
560
  }
559
561
 
562
+ # hook_write: safe_write for a kit-owned HOOK (#370). In --upgrade an existing hook is refreshed when
563
+ # it is an unmodified copy of an earlier template version (hook_refresh_state: the manifest hash or
564
+ # cckit's own template history), and reported as drifted — never overwritten — when the repo
565
+ # customized it. Everything else (new file, config-excluded path, normal init) is safe_write.
566
+ hook_write() { # <src> <dest>
567
+ local rel="${2#"$TARGET"/}" state
568
+ if [[ $UPGRADE -ne 1 || ! -e "$2" ]] || _upgrade_excluded "$rel"; then safe_write "$1" "$2"; return 0; fi
569
+ state="$(hook_refresh_state "$2" "$1" "$KIT_ROOT" "$TARGET/.claude/kit.manifest.json" "$rel")"
570
+ case "$state" in
571
+ refresh) emit "$1" "$2"; UPGRADE_REFRESHED+=("$rel") ;;
572
+ drifted) UPGRADE_DRIFTED+=("$rel") ;;
573
+ *) UPGRADE_PRESERVED+=("$rel") ;;
574
+ esac
575
+ return 0
576
+ }
577
+
560
578
  # ---- dry run: print the plan and exit, writing nothing -------------------
561
579
  if [[ $DRY_RUN -eq 1 ]]; then
562
580
  echo "-> DRY RUN — nothing will be written. Plan for $TARGET:"
@@ -577,6 +595,7 @@ if [[ $DRY_RUN -eq 1 ]]; then
577
595
  echo " .claude/settings.local.json"
578
596
  echo " .claude/hooks/repo-hygiene.sh (SessionStart: read-only repo-hygiene report)"
579
597
  echo " .claude/hooks/guard-base-branch-commit.sh (PreToolUse Bash: block commits to base branch)"
598
+ echo " .claude/hooks/guard-raw-git-ops.sh (PreToolUse Bash, tracked settings.json: raw gh/git -> cckit verb)"
580
599
  echo " .claude/hooks/kit_version_check.sh (SessionStart: update check)"
581
600
  for r in $RULES; do
582
601
  case "$r" in
@@ -594,7 +613,7 @@ if [[ $DRY_RUN -eq 1 ]]; then
594
613
  [[ -f "$KIT_ROOT/templates/skills/$s/SKILL.md" ]] && echo " .claude/skills/$_dn/SKILL.md"
595
614
  [[ -d "$KIT_ROOT/templates/skills/$s/references" ]] && echo " .claude/skills/$_dn/references/"
596
615
  done
597
- echo " scripts/ (kit-config.sh, gh-project.sh, kit-version-check.sh, setup-labels.sh, setup-milestones.sh, capture-project-ids.sh, task-sync.sh, knowledge-lint.sh)"
616
+ echo " scripts/ (kit-config.sh, gh-project.sh, kit-version-check.sh, setup-labels.sh, setup-milestones.sh, capture-project-ids.sh, task-sync.sh, knowledge-lint.sh, review-lint.sh + review-rules.conf, skill-frontmatter-lint.sh)"
598
617
  echo " knowledge/INDEX.md (knowledge-base manifest — rules/knowledge-base.md)"
599
618
  echo " .claude/lib/kit-sigil.sh (claude-kit attribution sigil helper, sourced by task-* footers)"
600
619
  [[ "$MEMORY_BOOL" == "true" ]] && echo " .claude/hooks/mempal_session_start.sh + mempal_save.sh + mempal_precompact.sh + mempal_followup.sh (SessionStart / Stop / PreCompact / SessionEnd)"
@@ -621,7 +640,7 @@ if [[ $UPGRADE -eq 0 ]]; then
621
640
  _kit_init_banner "$PLUGIN_VERSION"
622
641
  fi
623
642
 
624
- UPGRADE_ADDED=(); UPGRADE_PRESERVED=(); UPGRADE_SKIPPED=()
643
+ UPGRADE_ADDED=(); UPGRADE_PRESERVED=(); UPGRADE_SKIPPED=(); UPGRADE_REFRESHED=(); UPGRADE_DRIFTED=()
625
644
  echo "-> $([[ $UPGRADE -eq 1 ]] && echo Upgrading || echo Scaffolding) $PROFILE profile $([[ $UPGRADE -eq 1 ]] && echo in || echo into) $TARGET"
626
645
  mkdir -p "$TARGET/.claude/agents" "$TARGET/.claude/skills" "$TARGET/.claude/rules" "$TARGET/scripts/lib"
627
646
 
@@ -747,10 +766,34 @@ safe_copy "$KIT_ROOT/scripts/lib/gh-log.sh" "$TARGET/scripts/lib/gh-log.
747
766
  safe_copy "$KIT_ROOT/scripts/lib/kit-events.sh" "$TARGET/scripts/lib/kit-events.sh"
748
767
  safe_copy "$KIT_ROOT/scripts/lib/worktree-start.sh" "$TARGET/scripts/lib/worktree-start.sh"
749
768
  safe_copy "$KIT_ROOT/scripts/kit-version-check.sh" "$TARGET/scripts/kit-version-check.sh" exec
750
- for sc in setup-labels.sh setup-milestones.sh capture-project-ids.sh task-sync.sh knowledge-lint.sh; do
769
+ for sc in setup-labels.sh setup-milestones.sh capture-project-ids.sh task-sync.sh knowledge-lint.sh \
770
+ review-lint.sh skill-frontmatter-lint.sh; do
751
771
  safe_copy "$KIT_ROOT/scripts/$sc" "$TARGET/scripts/$sc" exec
752
772
  done
753
- echo " + scripts/ (libs + setup + task-sync + version-check + knowledge-lint)"
773
+ # review-lint is table-driven: the engine is useless without a rule table, so the starter table
774
+ # travels with it. Both lints self-disable when they do not apply (no rule table / no skills dir),
775
+ # so shipping them to every project is safe.
776
+ safe_copy "$KIT_ROOT/scripts/review-rules.conf" "$TARGET/scripts/review-rules.conf"
777
+ # Seed each baseline ONCE so a fresh project starts green and only *new* defects fail. Never
778
+ # regenerate an existing baseline - that would silently re-grandfather drift on upgrade.
779
+ #
780
+ # ASK for the path, never reconstruct it. This used to test "$_lint-baseline.txt", which is right
781
+ # for review-lint and wrong for skill-frontmatter-lint (it writes skill-frontmatter-baseline.txt, no
782
+ # "-lint"). The guessed name never existed, so the "already seeded" guard never matched and every
783
+ # upgrade re-baselined it - exactly what the line above forbids.
784
+ #
785
+ # KIT_LINT_WALK=1 so the seed sees the files just written. init.sh usually scaffolds into a repo
786
+ # that already has commits, where `git ls-files` is non-empty and the untracked kit files are
787
+ # invisible to it; the baseline would come out empty and the gate would go red on the user's first
788
+ # commit of the scaffold.
789
+ for _lint in review-lint skill-frontmatter-lint; do
790
+ [[ -f "$TARGET/scripts/$_lint.sh" ]] || continue
791
+ _baseline="$( cd "$TARGET" && bash "scripts/$_lint.sh" --baseline-path 2>/dev/null )"
792
+ [[ -n "$_baseline" ]] || continue
793
+ [[ -e "$TARGET/$_baseline" ]] && continue
794
+ ( cd "$TARGET" && KIT_LINT_WALK=1 bash "scripts/$_lint.sh" --update ) >/dev/null 2>&1 || true
795
+ done
796
+ echo " + scripts/ (libs + setup + task-sync + version-check + knowledge-lint + review-lint + skill-frontmatter-lint)"
754
797
 
755
798
  # ---- benchmark harness (generic machinery; kit-owned) + example dataset ----
756
799
  # The harness measures how well THIS project's own canonical docs can be found + used by a cold
@@ -836,7 +879,7 @@ fi
836
879
  # ---- local model layer SessionStart hook (opt-in; idempotent, also on --upgrade) ----
837
880
  if [[ "$LOCAL_ON" == "true" ]]; then
838
881
  mkdir -p "$TARGET/.claude/hooks"
839
- safe_write "$KIT_ROOT/templates/hooks/kit-local-status.sh.tmpl" "$TARGET/.claude/hooks/kit-local-status.sh"
882
+ hook_write "$KIT_ROOT/templates/hooks/kit-local-status.sh.tmpl" "$TARGET/.claude/hooks/kit-local-status.sh"
840
883
  chmod +x "$TARGET/.claude/hooks/kit-local-status.sh" 2>/dev/null || true
841
884
  merge_settings --arg ls "$TARGET/.claude/hooks/kit-local-status.sh" \
842
885
  '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $ls))) + [{matcher:"",hooks:[{type:"command",command:$ls,timeout:10}]}])'
@@ -845,7 +888,7 @@ fi
845
888
 
846
889
  # ---- repo-hygiene SessionStart hook (all projects; read-only; idempotent) ----
847
890
  mkdir -p "$TARGET/.claude/hooks"
848
- safe_write "$KIT_ROOT/templates/hooks/repo-hygiene.sh.tmpl" "$TARGET/.claude/hooks/repo-hygiene.sh"
891
+ hook_write "$KIT_ROOT/templates/hooks/repo-hygiene.sh.tmpl" "$TARGET/.claude/hooks/repo-hygiene.sh"
849
892
  chmod +x "$TARGET/.claude/hooks/repo-hygiene.sh" 2>/dev/null || true
850
893
  merge_settings --arg rh "$TARGET/.claude/hooks/repo-hygiene.sh" \
851
894
  '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $rh))) + [{matcher:"",hooks:[{type:"command",command:$rh,timeout:10}]}])'
@@ -853,15 +896,30 @@ HOOK_NOTE="$HOOK_NOTE + repo-hygiene"
853
896
 
854
897
  # ---- base-branch commit guard PreToolUse(Bash) hook (all projects; idempotent) ----
855
898
  mkdir -p "$TARGET/.claude/hooks"
856
- safe_write "$KIT_ROOT/templates/hooks/guard-base-branch-commit.sh.tmpl" "$TARGET/.claude/hooks/guard-base-branch-commit.sh"
899
+ hook_write "$KIT_ROOT/templates/hooks/guard-base-branch-commit.sh.tmpl" "$TARGET/.claude/hooks/guard-base-branch-commit.sh"
857
900
  chmod +x "$TARGET/.claude/hooks/guard-base-branch-commit.sh" 2>/dev/null || true
858
901
  merge_settings --arg gd "$TARGET/.claude/hooks/guard-base-branch-commit.sh" \
859
902
  '.hooks.PreToolUse = (((.hooks.PreToolUse // []) | map(select((.hooks[0].command // "") != $gd))) + [{matcher:"Bash",hooks:[{type:"command",command:$gd,timeout:10}]}])'
860
903
  HOOK_NOTE="$HOOK_NOTE + commit-guard"
861
904
 
905
+ # ---- raw-git guard PreToolUse(Bash) hook (all projects; init AND --upgrade; idempotent) ----
906
+ # Blocks raw gh issue create / pr create / pr merge / issue close and branch-from-base, and names the
907
+ # cckit verb to run instead (#364). Wired in the TRACKED settings.json with $CLAUDE_PROJECT_DIR, not
908
+ # settings.local.json: the local file is per-checkout and gitignored, so a guard wired there never
909
+ # reaches a worktree — which is exactly where agents work.
910
+ hook_write "$KIT_ROOT/templates/hooks/guard-raw-git-ops.sh.tmpl" "$TARGET/.claude/hooks/guard-raw-git-ops.sh"
911
+ chmod +x "$TARGET/.claude/hooks/guard-raw-git-ops.sh" 2>/dev/null || true
912
+ _TRACKED="$TARGET/.claude/settings.json"
913
+ [[ -f "$_TRACKED" ]] || echo '{}' > "$_TRACKED"
914
+ jq --arg g '$CLAUDE_PROJECT_DIR/.claude/hooks/guard-raw-git-ops.sh' \
915
+ '.hooks.PreToolUse = (((.hooks.PreToolUse // []) | map(.hooks |= map(select(.command != $g))) | map(select((.hooks | length) > 0)))
916
+ + [{matcher:"Bash",hooks:[{type:"command",command:$g,timeout:10}]}])' \
917
+ "$_TRACKED" > "$_TRACKED.tmp" && mv "$_TRACKED.tmp" "$_TRACKED"
918
+ echo " + .claude/hooks/guard-raw-git-ops.sh (PreToolUse Bash, wired in tracked settings.json: raw gh/git -> cckit verb)"
919
+
862
920
  # ---- version-check SessionStart hook (all projects; idempotent) ---------
863
921
  mkdir -p "$TARGET/.claude/hooks"
864
- safe_write "$KIT_ROOT/templates/hooks/kit_version_check.sh.tmpl" "$TARGET/.claude/hooks/kit_version_check.sh"
922
+ hook_write "$KIT_ROOT/templates/hooks/kit_version_check.sh.tmpl" "$TARGET/.claude/hooks/kit_version_check.sh"
865
923
  chmod +x "$TARGET/.claude/hooks/kit_version_check.sh" 2>/dev/null || true
866
924
  merge_settings --arg vc "$TARGET/.claude/hooks/kit_version_check.sh" \
867
925
  '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $vc))) + [{matcher:"",hooks:[{type:"command",command:$vc,timeout:10}]}])'
@@ -910,6 +968,8 @@ if [[ $UPGRADE -eq 1 ]]; then
910
968
  if [[ ${#UPGRADE_ADDED[@]} -gt 0 ]]; then echo " Added (new in this kit version):"; printf ' + %s\n' "${UPGRADE_ADDED[@]}"; fi
911
969
  if [[ ${#UPGRADE_PRESERVED[@]} -gt 0 ]]; then echo " Preserved (your edits, untouched):"; printf ' = %s\n' "${UPGRADE_PRESERVED[@]}"; fi
912
970
  if [[ ${#UPGRADE_SKIPPED[@]} -gt 0 ]]; then echo " Skipped (removed/renamed via kit.config upgrade):"; printf ' - %s\n' "${UPGRADE_SKIPPED[@]}"; fi
971
+ if [[ ${#UPGRADE_REFRESHED[@]} -gt 0 ]]; then echo " Refreshed (unmodified hook, now the current template):"; printf ' ~ %s\n' "${UPGRADE_REFRESHED[@]}"; fi
972
+ if [[ ${#UPGRADE_DRIFTED[@]} -gt 0 ]]; then echo " Drifted (customized hook, kept — diff it against templates/hooks/ by hand):"; printf ' ! %s\n' "${UPGRADE_DRIFTED[@]}"; fi
913
973
  else
914
974
  echo ""
915
975
  echo "Next steps:"
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env bash
2
+ # agent-profile-test.sh — the agent-profile declaration contract (#325).
3
+ #
4
+ # Fixtures only: every assertion runs against a config written into a temp dir, so the suite never
5
+ # depends on this repo's own cckit.config.json (which declares no profiles) and stays hermetic.
6
+ # Run: bash scripts/lib/agent-profile-test.sh
7
+ # errors: strict — a test runner: rc 1 on any failed assertion
8
+ # shellcheck shell=bash
9
+ set -u
10
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
11
+ # shellcheck source=/dev/null
12
+ source "$ROOT/scripts/lib/agent-profile.sh"
13
+
14
+ command -v jq >/dev/null 2>&1 || { echo "agent-profile-test: jq absent — skipping"; exit 0; }
15
+
16
+ fail=0
17
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
18
+ rc() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '[$2]' want '[$3]'"; fail=1; fi; }
19
+
20
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
21
+ CFG="$tmp/kit.config.json"
22
+ cat > "$CFG" <<'JSON'
23
+ {
24
+ "agents": {
25
+ "default": "build",
26
+ "profiles": {
27
+ "build": {
28
+ "kind": "claude",
29
+ "tier": "high",
30
+ "permissions": "acceptEdits",
31
+ "stages": ["build"],
32
+ "write": true,
33
+ "contextBudget": 8000,
34
+ "args": ["--flag", "two words"]
35
+ },
36
+ "review": {
37
+ "kind": "codex",
38
+ "tier": "low",
39
+ "stages": ["review", "design"]
40
+ },
41
+ "nostages": { "kind": "claude" }
42
+ }
43
+ }
44
+ }
45
+ JSON
46
+
47
+ # ── readers ────────────────────────────────────────────────────────────────────────────────────
48
+ t "names lists every declared profile" "$(ap_profile_names "$CFG" | tr '\n' ' ')" "build nostages review "
49
+ t "field reads kind" "$(ap_profile_field "$CFG" build kind)" "claude"
50
+ t "field reads the spend tier" "$(ap_profile_field "$CFG" build tier)" "high"
51
+ t "field reads permissions" "$(ap_profile_field "$CFG" build permissions)" "acceptEdits"
52
+ t "field reads a numeric budget" "$(ap_profile_field "$CFG" build contextBudget)" "8000"
53
+ t "field is empty for an absent key" "$(ap_profile_field "$CFG" review permissions)" ""
54
+ t "field is empty for an absent profile" "$(ap_profile_field "$CFG" ghost kind)" ""
55
+
56
+ # An arg containing a space must survive as ONE argument — the reason args is an argv array in the
57
+ # schema and one-per-line here, rather than a shell string something would re-split.
58
+ t "args keep a space-bearing argument intact" "$(ap_profile_args "$CFG" build | sed -n '2p')" "two words"
59
+ t "args count" "$(ap_profile_args "$CFG" build | wc -l | tr -d ' ')" "2"
60
+ t "args empty when undeclared" "$(ap_profile_args "$CFG" review | wc -l | tr -d ' ')" "0"
61
+
62
+ t "stages read" "$(ap_profile_stages "$CFG" review | tr '\n' ' ')" "review design "
63
+
64
+ # ── write ownership ────────────────────────────────────────────────────────────────────────────
65
+ ap_profile_writes "$CFG" build; rc "an explicit write:true profile may write" "$?" "0"
66
+ ap_profile_writes "$CFG" review; rc "write defaults to false when unstated" "$?" "1"
67
+
68
+ # ── stage gating ───────────────────────────────────────────────────────────────────────────────
69
+ ap_stage_allows "$CFG" review review; rc "a listed stage is allowed" "$?" "0"
70
+ ap_stage_allows "$CFG" review build; rc "an unlisted stage is refused" "$?" "1"
71
+ # An unstated permission is not a granted one: no `stages` key means allowed nowhere, not everywhere.
72
+ ap_stage_allows "$CFG" nostages build; rc "a profile with no stages is allowed nowhere" "$?" "1"
73
+
74
+ # ── the stage vocabulary ───────────────────────────────────────────────────────────────────────
75
+ t "built-in stage vocabulary" "$(ap_stages "$CFG" | tr '\n' ' ')" "build review design docs "
76
+ cat > "$tmp/stages.json" <<'JSON'
77
+ { "agents": { "stages": ["build", "qa"], "profiles": { "b": { "kind": "claude", "stages": ["qa"] } } } }
78
+ JSON
79
+ t "config replaces the vocabulary" "$(ap_stages "$tmp/stages.json" | tr '\n' ' ')" "build qa "
80
+ t "env wins per invocation" "$(CCKIT_AGENT_STAGES='only' ap_stages "$CFG" | tr '\n' ' ')" "only "
81
+
82
+ # ── spend tier: the cheap default is structural, not a convention ──────────────────────────────
83
+ t "tier is read" "$(ap_profile_tier "$CFG" build)" "high"
84
+ t "tier defaults to low when unstated" "$(ap_profile_tier "$CFG" nostages)" "low"
85
+ t "rank orders low < mid < high" "$(ap_tier_rank low)$(ap_tier_rank mid)$(ap_tier_rank high)" "012"
86
+ t "an unknown tier ranks as cheap" "$(ap_tier_rank bogus)" "0"
87
+ t "cheapest wins over an expensive one" "$(ap_cheapest_profile "$CFG")" "nostages"
88
+
89
+ cat > "$tmp/tiers.json" <<'JSON'
90
+ { "agents": { "profiles": {
91
+ "zeta": { "kind": "claude", "tier": "low" },
92
+ "alpha": { "kind": "claude", "tier": "low" },
93
+ "pricey": { "kind": "claude", "tier": "high" }
94
+ } } }
95
+ JSON
96
+ t "ties break alphabetically, not by jq key order" "$(ap_cheapest_profile "$tmp/tiers.json")" "alpha"
97
+
98
+ # ── validation refuses BEFORE anything is created ──────────────────────────────────────────────
99
+ ap_profile_validate "$CFG" build build 2>/dev/null; rc "a declared profile at an allowed stage passes" "$?" "0"
100
+ ap_profile_validate "$CFG" ghost 2>/dev/null; rc "an undeclared profile is refused" "$?" "2"
101
+ ap_profile_validate "$CFG" "" 2>/dev/null; rc "an empty name is refused" "$?" "2"
102
+ ap_profile_validate "$CFG" review build 2>/dev/null; rc "a profile barred from the stage is refused" "$?" "2"
103
+ ap_profile_validate "$CFG" build nosuch 2>/dev/null; rc "a stage outside the vocabulary is refused" "$?" "2"
104
+
105
+ cat > "$tmp/nokind.json" <<'JSON'
106
+ { "agents": { "profiles": { "k": { "model": "x" } } } }
107
+ JSON
108
+ ap_profile_validate "$tmp/nokind.json" k 2>/dev/null; rc "a profile with no kind is refused" "$?" "2"
109
+
110
+ cat > "$tmp/badstage.json" <<'JSON'
111
+ { "agents": { "profiles": { "k": { "kind": "claude", "stages": ["nope"] } } } }
112
+ JSON
113
+ ap_profile_validate "$tmp/badstage.json" k 2>/dev/null; rc "a profile listing an unknown stage is refused" "$?" "2"
114
+
115
+ # The refusal must name the profile, so an operator can act on it without reading the source.
116
+ case "$(ap_profile_validate "$CFG" ghost 2>&1 >/dev/null)" in
117
+ *ghost*) echo "ok: the refusal names the offending profile" ;;
118
+ *) echo "FAIL: the refusal does not name the profile"; fail=1 ;;
119
+ esac
120
+
121
+ # ── the default ────────────────────────────────────────────────────────────────────────────────
122
+ t "default is echoed when it resolves" "$(ap_default_profile "$CFG" 2>/dev/null)" "build"
123
+ cat > "$tmp/dangling.json" <<'JSON'
124
+ { "agents": { "default": "missing", "profiles": { "b": { "kind": "claude" } } } }
125
+ JSON
126
+ ap_default_profile "$tmp/dangling.json" >/dev/null 2>&1
127
+ rc "a default naming no declared profile is refused, not silently ignored" "$?" "2"
128
+ # No agents.default must NOT mean "no profile" — it means the cheapest, so an unconfigured project
129
+ # runs the inexpensive path instead of failing or picking whatever jq listed first.
130
+ cat > "$tmp/nodefault.json" <<'JSON'
131
+ { "agents": { "profiles": {
132
+ "spendy": { "kind": "claude", "tier": "high" },
133
+ "thrifty": { "kind": "claude", "tier": "low" }
134
+ } } }
135
+ JSON
136
+ t "no agents.default falls back to the CHEAPEST profile" "$(ap_default_profile "$tmp/nodefault.json" 2>/dev/null)" "thrifty"
137
+
138
+ # ── a config with no agents block at all stays inert ───────────────────────────────────────────
139
+ echo '{}' > "$tmp/empty.json"
140
+ t "no agents block yields no profiles" "$(ap_profile_names "$tmp/empty.json" | wc -l | tr -d ' ')" "0"
141
+ t "no agents block yields no default" "$(ap_default_profile "$tmp/empty.json" 2>/dev/null)" ""
142
+
143
+ # ── the acceptance that matters: no vendor model id is hard-coded in kit logic ──────────────────
144
+ # cckit must never name a model — not in code, and (since the schema dropped `model`) not in the
145
+ # config shape either. A kit that suggests an expensive model pushes every user toward spending
146
+ # more. A grep for any vendor id across the shipped libs must come back empty.
147
+ hits="$(grep -rEl 'claude-(opus|sonnet|haiku)-[0-9]|gpt-[0-9]|gemini-[0-9]' "$ROOT/scripts/lib" "$ROOT/bin" 2>/dev/null | grep -v -- '-test\.sh$' | wc -l | tr -d ' ')"
148
+ t "no vendor model id appears in shipped lib or bin code" "$hits" "0"
149
+
150
+ [ "$fail" -eq 0 ] && echo "agent-profile-test: PASS" || echo "agent-profile-test: FAILED"
151
+ exit "$fail"
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env bash
2
+ # agent-profile.sh — read and validate the named agent profiles declared in kit config (#325).
3
+ #
4
+ # A profile is project DATA, not workflow logic: it carries the agent kind, a SPEND TIER, extra CLI
5
+ # argv, a permission policy, the stages it may run at, and whether it may write to a branch.
6
+ #
7
+ # cckit deliberately does NOT name models. A kit that suggests an expensive model in its own config
8
+ # schema pushes every user toward spending more, which is the opposite of the point. The project
9
+ # spells its own flags in `args`; `tier` is the only cost signal the kit reads, and the cheapest
10
+ # profile is what runs when nothing else is chosen. This file reads and validates the declaration —
11
+ # choosing WHICH profile an issue resolves to is #319, and launching one is #320.
12
+ #
13
+ # Everything here refuses early and loudly: a profile selected for a stage it does not list, or a
14
+ # `default` naming a profile that was never declared, is an error before a worktree or pane exists,
15
+ # not a silent fallback to something plausible.
16
+ # errors: mixed — the readers are pure jq over a config file and echo empty for an absent key;
17
+ # ap_profile_validate / ap_default_profile propagate rc 2 on an undeclared profile, a missing kind,
18
+ # or a stage outside the vocabulary. rc 3 is reserved for "jq is not installed".
19
+ # shellcheck shell=bash
20
+
21
+ # The built-in stage vocabulary. `agents.stages` in the config replaces it; CCKIT_AGENT_STAGES wins
22
+ # per invocation. Kept as a space-separated string, not an array, for bash 3.2.
23
+ AP_STAGES_DEFAULT="build review design docs"
24
+
25
+ _ap_need_jq() {
26
+ command -v jq >/dev/null 2>&1 || { echo "agent-profile: jq is required to read agent profiles" >&2; return 3; }
27
+ }
28
+
29
+ # ap_stages <cfg> — echo the stage vocabulary, one per line.
30
+ ap_stages() {
31
+ local cfg="${1:-}" declared=""
32
+ if [ -n "${CCKIT_AGENT_STAGES:-}" ]; then
33
+ printf '%s\n' $CCKIT_AGENT_STAGES
34
+ return 0
35
+ fi
36
+ if [ -n "$cfg" ] && [ -f "$cfg" ] && command -v jq >/dev/null 2>&1; then
37
+ declared="$(jq -r '(.agents.stages // [])[]' "$cfg" 2>/dev/null)"
38
+ fi
39
+ if [ -n "$declared" ]; then printf '%s\n' "$declared"; else printf '%s\n' $AP_STAGES_DEFAULT; fi
40
+ }
41
+
42
+ # ap_profile_names <cfg> — echo every declared profile name, one per line. Empty when none.
43
+ ap_profile_names() {
44
+ local cfg="${1:-}"
45
+ [ -n "$cfg" ] && [ -f "$cfg" ] || return 0
46
+ _ap_need_jq || return $?
47
+ jq -r '(.agents.profiles // {}) | keys[]' "$cfg" 2>/dev/null
48
+ }
49
+
50
+ # ap_profile_exists <cfg> <name> — rc 0 when the profile is declared.
51
+ ap_profile_exists() {
52
+ local cfg="${1:-}" name="${2:-}"
53
+ [ -n "$name" ] || return 1
54
+ [ -n "$cfg" ] && [ -f "$cfg" ] || return 1
55
+ _ap_need_jq || return $?
56
+ jq -e --arg n "$name" '(.agents.profiles // {}) | has($n)' "$cfg" >/dev/null 2>&1
57
+ }
58
+
59
+ # ap_profile_field <cfg> <name> <field> — echo one scalar field, empty when absent.
60
+ # Scalars only (kind, tier, permissions, contextBudget, write); `args`/`stages` are arrays.
61
+ ap_profile_field() {
62
+ local cfg="${1:-}" name="${2:-}" field="${3:-}"
63
+ [ -n "$cfg" ] && [ -f "$cfg" ] && [ -n "$name" ] && [ -n "$field" ] || return 0
64
+ _ap_need_jq || return $?
65
+ jq -r --arg n "$name" --arg f "$field" \
66
+ '(.agents.profiles[$n][$f]) // "" | if type == "boolean" then (if . then "1" else "0" end) else tostring end' \
67
+ "$cfg" 2>/dev/null | sed 's/^null$//'
68
+ }
69
+
70
+ # ap_profile_args <cfg> <name> — echo the profile's extra CLI argv, ONE PER LINE so an argument
71
+ # containing spaces survives. A caller builds an array with: while IFS= read -r a; do ...; done
72
+ ap_profile_args() {
73
+ local cfg="${1:-}" name="${2:-}"
74
+ [ -n "$cfg" ] && [ -f "$cfg" ] && [ -n "$name" ] || return 0
75
+ _ap_need_jq || return $?
76
+ jq -r --arg n "$name" '(.agents.profiles[$n].args // [])[]' "$cfg" 2>/dev/null
77
+ }
78
+
79
+ # ap_profile_stages <cfg> <name> — echo the stages the profile lists, one per line.
80
+ ap_profile_stages() {
81
+ local cfg="${1:-}" name="${2:-}"
82
+ [ -n "$cfg" ] && [ -f "$cfg" ] && [ -n "$name" ] || return 0
83
+ _ap_need_jq || return $?
84
+ jq -r --arg n "$name" '(.agents.profiles[$n].stages // [])[]' "$cfg" 2>/dev/null
85
+ }
86
+
87
+ # ap_profile_writes <cfg> <name> — rc 0 when the profile may write to a branch (default: it may not).
88
+ ap_profile_writes() {
89
+ [ "$(ap_profile_field "${1:-}" "${2:-}" write)" = "1" ]
90
+ }
91
+
92
+ # ap_stage_allows <cfg> <name> <stage> — rc 0 when the profile lists that stage. A profile with NO
93
+ # `stages` key is allowed nowhere: an unstated permission is not a granted one.
94
+ ap_stage_allows() {
95
+ local cfg="${1:-}" name="${2:-}" want="${3:-}" s
96
+ [ -n "$want" ] || return 1
97
+ while IFS= read -r s; do
98
+ [ "$s" = "$want" ] && return 0
99
+ done <<EOF
100
+ $(ap_profile_stages "$cfg" "$name")
101
+ EOF
102
+ return 1
103
+ }
104
+
105
+ # ap_profile_validate <cfg> <name> [<stage>] — rc 0 when the profile is declared, names a kind, and
106
+ # lists only stages in the vocabulary. With <stage>, also requires the profile to allow it.
107
+ # Every refusal prints the reason and the fix, because this runs before any worktree exists and the
108
+ # operator needs to know which of the four things was wrong.
109
+ ap_profile_validate() {
110
+ local cfg="${1:-}" name="${2:-}" stage="${3:-}" kind s known found
111
+ [ -n "$name" ] || { echo "agent-profile: a profile name is required" >&2; return 2; }
112
+ ap_profile_exists "$cfg" "$name" || {
113
+ echo "agent-profile: no profile named '$name' in $cfg" >&2
114
+ echo " declared: $(ap_profile_names "$cfg" | tr '\n' ' ')" >&2
115
+ return 2
116
+ }
117
+ kind="$(ap_profile_field "$cfg" "$name" kind)"
118
+ [ -n "$kind" ] || { echo "agent-profile: profile '$name' declares no kind (the agent CLI to run)" >&2; return 2; }
119
+
120
+ known="$(ap_stages "$cfg" | tr '\n' ' ')"
121
+ while IFS= read -r s; do
122
+ [ -n "$s" ] || continue
123
+ case " $known " in
124
+ *" $s "*) : ;;
125
+ *) echo "agent-profile: profile '$name' lists stage '$s', which is not in the vocabulary ($known)" >&2; return 2 ;;
126
+ esac
127
+ done <<EOF
128
+ $(ap_profile_stages "$cfg" "$name")
129
+ EOF
130
+
131
+ if [ -n "$stage" ]; then
132
+ case " $known " in
133
+ *" $stage "*) : ;;
134
+ *) echo "agent-profile: stage '$stage' is not in the vocabulary ($known)" >&2; return 2 ;;
135
+ esac
136
+ ap_stage_allows "$cfg" "$name" "$stage" || {
137
+ found="$(ap_profile_stages "$cfg" "$name" | tr '\n' ' ')"
138
+ echo "agent-profile: profile '$name' is not allowed at stage '$stage' (it lists: ${found:-none})" >&2
139
+ return 2
140
+ }
141
+ fi
142
+ return 0
143
+ }
144
+
145
+ # ap_tier_rank <tier> — echo a sortable rank for a spend tier. Unstated means `low`: assuming the
146
+ # CHEAP end when a profile says nothing is the safe direction to be wrong in.
147
+ ap_tier_rank() {
148
+ case "${1:-low}" in
149
+ low|"") printf '0\n' ;;
150
+ mid) printf '1\n' ;;
151
+ high) printf '2\n' ;;
152
+ *) printf '0\n' ;;
153
+ esac
154
+ }
155
+
156
+ # ap_profile_tier <cfg> <name> — echo the profile's spend tier, `low` when unstated.
157
+ ap_profile_tier() {
158
+ local t; t="$(ap_profile_field "${1:-}" "${2:-}" tier)"
159
+ printf '%s\n' "${t:-low}"
160
+ }
161
+
162
+ # ap_cheapest_profile <cfg> — echo the lowest-tier declared profile. Ties break alphabetically so
163
+ # the answer is deterministic rather than dependent on jq's key order.
164
+ ap_cheapest_profile() {
165
+ local cfg="${1:-}" p best="" best_rank=99 r
166
+ while IFS= read -r p; do
167
+ [ -n "$p" ] || continue
168
+ r="$(ap_tier_rank "$(ap_profile_tier "$cfg" "$p")")"
169
+ if [ "$r" -lt "$best_rank" ]; then best="$p"; best_rank="$r"; fi
170
+ done <<EOF
171
+ $(ap_profile_names "$cfg" | sort)
172
+ EOF
173
+ [ -n "$best" ] || return 0
174
+ printf '%s\n' "$best"
175
+ }
176
+
177
+ # ap_default_profile <cfg> — echo the profile to use when nothing more specific resolves.
178
+ #
179
+ # With `agents.default` set, that name is used and a dangling one is a config error: silently
180
+ # falling back would run a different agent while the operator believed the default applied.
181
+ # With NO `agents.default`, the CHEAPEST declared profile wins. That is the whole point — the
182
+ # inexpensive path is the default by construction, not by remembering to configure it.
183
+ ap_default_profile() {
184
+ local cfg="${1:-}" name
185
+ name="$(jq -r '.agents.default // ""' "$cfg" 2>/dev/null)"
186
+ if [ -z "$name" ]; then
187
+ ap_cheapest_profile "$cfg"
188
+ return 0
189
+ fi
190
+ ap_profile_exists "$cfg" "$name" || {
191
+ echo "agent-profile: agents.default is '$name', which is not a declared profile" >&2
192
+ return 2
193
+ }
194
+ printf '%s\n' "$name"
195
+ }