@jeiemgi/cckit 0.9.0 → 0.10.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 +169 -21
- package/README.md +491 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +182 -17
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +13 -5
- package/commands/kit-export-project.md +0 -2
- package/commands/kit-export-training.md +6 -9
- package/commands/kit-init.md +43 -13
- package/commands/kit-routines.md +1 -1
- package/commands/kit-update.md +11 -6
- package/databases/supabase/guide.html +106 -0
- package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
- package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
- package/databases/supabase.json +70 -0
- package/integrations/emil-design-eng.json +41 -0
- package/integrations/graft.json +81 -0
- package/integrations/impeccable.json +42 -0
- package/integrations/integration.schema.json +215 -0
- package/integrations/lavish.json +43 -0
- package/integrations/mempalace.json +28 -0
- package/integrations/mlx-lm.json +32 -0
- package/integrations/web-design-guidelines.json +42 -0
- package/kit.config.schema.json +183 -5
- package/package.json +4 -1
- package/profiles/automation.json +7 -1
- package/profiles/content.json +10 -2
- package/profiles/marketing.json +57 -0
- package/profiles/minimal.json +7 -1
- package/profiles/research.json +7 -1
- package/profiles/software.json +7 -1
- package/recipes/nextjs-shadcn.json +49 -0
- package/scripts/agent-skills-external.txt +45 -0
- package/scripts/agent-skills-lint-test.sh +131 -0
- package/scripts/agent-skills-lint.sh +115 -0
- package/scripts/agent-template-lint-test.sh +42 -0
- package/scripts/agent-template-lint.sh +58 -0
- package/scripts/annotate-setup.sh +1 -1
- package/scripts/autopilot-run-test.sh +338 -0
- package/scripts/autopilot-run.sh +448 -0
- package/scripts/autopilot-test.sh +8 -0
- package/scripts/autopilot.sh +10 -1
- package/scripts/benchmark/benchmark-test.sh +85 -0
- package/scripts/benchmark/checkpoint-test.sh +314 -0
- package/scripts/benchmark/checkpoint.sh +408 -0
- package/scripts/benchmark/lib/model.sh +31 -6
- package/scripts/benchmark/report.sh +17 -2
- package/scripts/benchmark/run-quality.sh +36 -10
- package/scripts/benchmark/verb-timings-test.sh +124 -0
- package/scripts/benchmark/verb-timings.sh +149 -0
- package/scripts/check.sh +29 -19
- package/scripts/content-skills-test.sh +144 -0
- package/scripts/copilot-loop-test.sh +25 -0
- package/scripts/database-supabase-test.sh +121 -0
- package/scripts/docs-marketing-words-test.sh +73 -0
- package/scripts/docs-record-tables-test.sh +72 -0
- package/scripts/hook-adapter-test.sh +193 -0
- package/scripts/init-content-test.sh +225 -0
- package/scripts/init-guided-test.sh +474 -0
- package/scripts/init-recipes-test.sh +104 -0
- package/scripts/init-upgrade-test.sh +341 -2
- package/scripts/init.sh +746 -95
- package/scripts/instruction-budget-baseline.txt +8 -0
- package/scripts/instruction-budget-lint-test.sh +166 -0
- package/scripts/instruction-budget-lint.sh +219 -0
- package/scripts/integrations-check-test.sh +200 -0
- package/scripts/integrations-check.sh +157 -0
- package/scripts/kit-add-test.sh +214 -0
- package/scripts/kit-add.sh +305 -5
- package/scripts/kit-adopt-test.sh +16 -0
- package/scripts/kit-adopt.sh +3 -2
- package/scripts/kit-digest.sh +2 -2
- package/scripts/kit-doctor-test.sh +293 -0
- package/scripts/kit-doctor.sh +272 -140
- package/scripts/kit-export-project-test.sh +3 -3
- package/scripts/kit-remove-test.sh +19 -0
- package/scripts/kit-routines.sh +2 -2
- package/scripts/kit-self-update.sh +1 -1
- package/scripts/kit-version-check-test.sh +4 -0
- package/scripts/kit-version-check.sh +4 -2
- package/scripts/knowledge-lint.sh +4 -4
- package/scripts/leak-fence-test.sh +89 -0
- package/scripts/lib/adapter-select-test.sh +136 -0
- package/scripts/lib/adapter-select.sh +158 -0
- package/scripts/lib/agent-def-test.sh +69 -0
- package/scripts/lib/agent-def.sh +106 -0
- package/scripts/lib/agent-launch-test.sh +212 -0
- package/scripts/lib/agent-launch.sh +335 -0
- package/scripts/lib/board-view-test.sh +11 -0
- package/scripts/lib/board-view.sh +42 -26
- package/scripts/lib/branch-owner-test.sh +26 -0
- package/scripts/lib/branch-owner.sh +16 -9
- package/scripts/lib/captain-test.sh +105 -0
- package/scripts/lib/captain.sh +87 -8
- package/scripts/lib/codex-hooks-test.sh +100 -0
- package/scripts/lib/codex-hooks.sh +69 -0
- package/scripts/lib/commitlint.sh +1 -1
- package/scripts/lib/content-kinds-gc-test.sh +88 -0
- package/scripts/lib/copilot-test.sh +70 -4
- package/scripts/lib/copilot.sh +66 -14
- package/scripts/lib/effort-dispatch-test.sh +3 -3
- package/scripts/lib/effort-metrics-test.sh +178 -1
- package/scripts/lib/effort-metrics.sh +175 -35
- package/scripts/lib/effort-ops-test.sh +205 -7
- package/scripts/lib/effort-ops.sh +198 -43
- package/scripts/lib/effort-parity-test.sh +49 -13
- package/scripts/lib/effort-plan-test.sh +337 -0
- package/scripts/lib/effort-plan.sh +200 -23
- package/scripts/lib/effort.sh +56 -11
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +23 -16
- package/scripts/lib/gh-rest-test.sh +32 -3
- package/scripts/lib/gh-rest.sh +17 -2
- package/scripts/lib/hook-refresh.sh +1 -1
- package/scripts/lib/init-github.sh +412 -0
- package/scripts/lib/init-guide.sh +630 -0
- package/scripts/lib/integration-install-test.sh +343 -0
- package/scripts/lib/integration-install.sh +257 -0
- package/scripts/lib/integrations-test.sh +366 -0
- package/scripts/lib/integrations.sh +244 -0
- package/scripts/lib/kinds-test.sh +125 -0
- package/scripts/lib/kinds.sh +66 -0
- package/scripts/lib/kit-brief-test.sh +22 -3
- package/scripts/lib/kit-brief.sh +45 -5
- package/scripts/lib/kit-config-resolve.sh +2 -2
- package/scripts/lib/kit-config-test.sh +64 -1
- package/scripts/lib/kit-config.sh +37 -1
- package/scripts/lib/kit-events.sh +7 -0
- package/scripts/lib/kit-gc-test.sh +173 -1
- package/scripts/lib/kit-gc.sh +226 -37
- package/scripts/lib/kit-hotfix.sh +216 -0
- package/scripts/lib/kit-interview-test.sh +93 -0
- package/scripts/lib/kit-interview.sh +117 -8
- package/scripts/lib/kit-lib-test.sh +1 -1
- package/scripts/lib/kit-lib.sh +3 -3
- package/scripts/lib/kit-local.sh +2 -2
- package/scripts/lib/kit-manifest.sh +33 -1
- package/scripts/lib/kit-profile-test.sh +3 -3
- package/scripts/lib/kit-status-test.sh +112 -4
- package/scripts/lib/kit-status.sh +246 -16
- package/scripts/lib/kit-task-ops-test.sh +37 -0
- package/scripts/lib/kit-task-ops.sh +175 -31
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +1 -1
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
- package/scripts/lib/kto-task-pr-test.sh +70 -0
- package/scripts/lib/leak-fence.sh +89 -0
- package/scripts/lib/light-task-run-test.sh +255 -0
- package/scripts/lib/light-task-test.sh +309 -0
- package/scripts/lib/light-task.sh +706 -0
- package/scripts/lib/next-test.sh +99 -0
- package/scripts/lib/next.sh +9 -3
- package/scripts/lib/orchestration-runtime-test.sh +72 -0
- package/scripts/lib/orchestration-runtime.sh +57 -5
- package/scripts/lib/plan-machine-test.sh +15 -2
- package/scripts/lib/plan-machine.sh +20 -7
- package/scripts/lib/plan-next-test.sh +1 -1
- package/scripts/lib/plan-next.sh +4 -4
- package/scripts/lib/pr-evidence-test.sh +3 -3
- package/scripts/lib/pr-evidence.sh +1 -1
- package/scripts/lib/qa-lane-test.sh +626 -0
- package/scripts/lib/qa-lane.sh +1357 -0
- package/scripts/lib/qa-lanes-test.sh +175 -0
- package/scripts/lib/react-detect.sh +1 -1
- package/scripts/lib/render-test.sh +1 -1
- package/scripts/lib/review-page-test.sh +318 -0
- package/scripts/lib/review-page.sh +369 -0
- package/scripts/lib/review-stage-test.sh +62 -11
- package/scripts/lib/review-stage.sh +42 -60
- package/scripts/lib/role-identity-test.sh +65 -0
- package/scripts/lib/role-identity.sh +25 -2
- package/scripts/lib/secret-guard.sh +3 -3
- package/scripts/lib/session-registry-test.sh +111 -0
- package/scripts/lib/session-registry.sh +233 -0
- package/scripts/lib/stage-receipt-test.sh +14 -1
- package/scripts/lib/stage-receipt.sh +13 -8
- package/scripts/lib/task-source-file.sh +309 -0
- package/scripts/lib/task-source.sh +130 -0
- package/scripts/lib/upgrade-report-test.sh +120 -0
- package/scripts/lib/upgrade-report.sh +138 -0
- package/scripts/lib/version-bump.sh +3 -3
- package/scripts/lib/wave-result-test.sh +80 -0
- package/scripts/lib/wave-result.sh +127 -0
- package/scripts/lib/worker-brief-test.sh +5 -0
- package/scripts/lib/worker-brief.sh +2 -2
- package/scripts/lib/worktree-issue-test.sh +30 -1
- package/scripts/lib/worktree-issue.sh +82 -12
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +153 -31
- package/scripts/lib/zsh-safety-test.sh +19 -3
- package/scripts/marketing-walkthrough-test.sh +152 -0
- package/scripts/night-grant-test.sh +37 -0
- package/scripts/night-grant.sh +448 -0
- package/scripts/night-run-test.sh +8 -0
- package/scripts/night-run.mjs +275 -0
- package/scripts/night-run.test.mjs +324 -0
- package/scripts/orchestrate-test.sh +190 -0
- package/scripts/orchestrate.sh +79 -8
- package/scripts/portable-test.sh +11 -2
- package/scripts/publish.sh +28 -3
- package/scripts/review-lint-test.sh +7 -7
- package/scripts/review-lint.sh +2 -2
- package/scripts/review-rules.conf +8 -0
- package/scripts/rule-recipes-test.sh +96 -0
- package/scripts/self-install-test.sh +39 -9
- package/scripts/setup-labels.sh +18 -1
- package/scripts/setup-milestones.sh +1 -1
- package/scripts/showcase.sh +1 -1
- package/scripts/skill-frontmatter-lint-test.sh +4 -4
- package/scripts/skill-frontmatter-lint.sh +1 -1
- package/scripts/status-test.sh +113 -2
- package/scripts/status.sh +16 -3
- package/scripts/task-sync-test.sh +154 -0
- package/scripts/task-sync.sh +243 -32
- package/scripts/test-runner-test.sh +158 -0
- package/scripts/test.sh +131 -23
- package/scripts/update-path-test.sh +279 -0
- package/scripts/ux-ds-audit.sh +1 -1
- package/scripts/ux-graph-scan.sh +6 -6
- package/scripts/wave-worker.sh +54 -0
- package/skills/kit-add/SKILL.md +77 -0
- package/skills/kit-autopilot/SKILL.md +123 -12
- package/skills/kit-cleanup/SKILL.md +5 -2
- package/skills/kit-contribute/SKILL.md +4 -4
- package/skills/kit-docs-writer/SKILL.md +16 -6
- package/skills/kit-effort-close/SKILL.md +17 -8
- package/skills/kit-effort-new/SKILL.md +15 -9
- package/skills/kit-effort-pr/SKILL.md +15 -7
- package/skills/kit-effort-start/SKILL.md +5 -2
- package/skills/kit-gc/SKILL.md +5 -2
- package/skills/kit-next/SKILL.md +5 -1
- package/skills/kit-onboard/SKILL.md +3 -3
- package/skills/kit-page/SKILL.md +93 -0
- package/skills/kit-plan-next/SKILL.md +8 -4
- package/skills/kit-security-sweep/SKILL.md +1 -3
- package/skills/kit-ship/SKILL.md +2 -3
- package/skills/kit-status/SKILL.md +35 -4
- package/skills/kit-task-new/SKILL.md +3 -3
- package/skills/kit-task-pr/SKILL.md +7 -2
- package/skills/kit-task-pr-merge/SKILL.md +7 -2
- package/skills/kit-task-start/SKILL.md +7 -7
- package/skills/kit-task-sync/SKILL.md +19 -3
- package/skills/kit-ux-audit/SKILL.md +3 -2
- package/templates/agents/auto-dev.md +5 -4
- package/templates/agents/backend.md +1 -1
- package/templates/agents/designer.md +2 -0
- package/templates/agents/devops.md +1 -1
- package/templates/agents/editor.md +9 -1
- package/templates/agents/frontend.md +1 -1
- package/templates/agents/local-delegate.md +1 -1
- package/templates/agents/pm.md +5 -5
- package/templates/agents/tech-lead.md +1 -1
- package/templates/benchmarks/SCHEMA.md +9 -3
- package/templates/codex/hooks.json.tmpl +89 -0
- package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
- package/templates/hooks/mempal_followup.sh.tmpl +2 -2
- package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
- package/templates/hooks/prepush_gate.sh.tmpl +4 -2
- package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
- package/templates/instructions.md.tmpl +174 -0
- package/templates/kit.config.json.tmpl +3 -3
- package/templates/knowledge-INDEX.md.tmpl +1 -1
- package/templates/lib/kit-sigil.sh.tmpl +1 -1
- package/templates/rules/authoring.md +106 -0
- package/templates/rules/branch-naming.md +40 -4
- package/templates/rules/code-retrieval.md +63 -0
- package/templates/rules/delegation-brief.md +0 -3
- package/templates/rules/design-routing.md +3 -3
- package/templates/rules/effort-model.md +14 -10
- package/templates/rules/gate-and-review.md +94 -0
- package/templates/rules/issue-lifecycle.md +88 -0
- package/templates/rules/knowledge-base.md +1 -1
- package/templates/rules/mempalace.md +1 -1
- package/templates/rules/merge-safety.md +108 -0
- package/templates/rules/naming-and-ids.md +23 -17
- package/templates/rules/plain-language.md +59 -0
- package/templates/rules/plan-next.md +9 -11
- package/templates/rules/react-annotate.md +6 -0
- package/templates/rules/review-pages.md +49 -0
- package/templates/rules/risk-tiered-review.md +13 -4
- package/templates/rules/shared-checkout.md +106 -0
- package/templates/rules/skill-gaps.md +2 -7
- package/templates/rules/task-management.md +13 -1
- package/templates/skills/brand-voice/SKILL.md +91 -0
- package/templates/skills/brand-voice/references/voice-template.md +61 -0
- package/templates/skills/campaign/SKILL.md +123 -0
- package/templates/skills/campaign/references/plan-template.md +55 -0
- package/templates/skills/concrete/SKILL.md +2 -2
- package/templates/skills/copywriting/SKILL.md +8 -1
- package/templates/skills/feature-build-refine/SKILL.md +2 -4
- package/templates/skills/morning-briefing/SKILL.md +2 -2
- package/templates/skills/page-design/SKILL.md +145 -0
- package/templates/skills/page-design/add.json +5 -0
- package/templates/skills/page-design/references/design-file-template.md +40 -0
- package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
- package/templates/skills/page-design/references/minimum-rules.md +42 -0
- package/templates/skills/speckit/SKILL.md +4 -5
- package/templates/skills/supabase-patterns/SKILL.md +1 -1
- package/commands/kit-add.md +0 -42
- package/templates/CLAUDE.md.tmpl +0 -106
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
|
-
# copilot-test.sh — self-test for copilot.sh
|
|
3
|
-
# Network-free: covers the
|
|
4
|
-
#
|
|
2
|
+
# copilot-test.sh — self-test for copilot.sh under bash AND zsh.
|
|
3
|
+
# Network-free: covers the seed composer, the per-adapter dispatch wording, adapter resolution, and
|
|
4
|
+
# the human brief of copilot_brief run under `set -e` against a stubbed plan machine + stub gh/jq
|
|
5
|
+
# (#316). Run: bash scripts/lib/copilot-test.sh
|
|
5
6
|
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
6
7
|
|
|
7
8
|
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
@@ -18,8 +19,73 @@ if [ -n "${CP_TEST_INNER:-}" ]; then
|
|
|
18
19
|
has "seed has close verb" "$seed" 'cckit close 42'
|
|
19
20
|
has "seed has check gate" "$seed" 'bash scripts/check.sh'
|
|
20
21
|
has "seed forbids asking" "$seed" 'never ask'
|
|
22
|
+
# The seed is wave data: it names no runtime, so the same prompt serves a Claude or a Codex worker.
|
|
23
|
+
no() { case "$2" in *"$3"*) echo "FAIL($CP_TEST_INNER): $1 has unexpected '[$3]'"; fail=1 ;; esac; }
|
|
24
|
+
no "seed names no Claude tool" "$seed" 'Task subagent'
|
|
25
|
+
no "seed names no runtime" "$seed" 'Codex'
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
# Dispatch wording is the adapter's.
|
|
28
|
+
cl="$(_copilot_dispatch claude 2 '101 103')"; cx="$(_copilot_dispatch codex 2 '101 103')"
|
|
29
|
+
has "claude dispatch: Task subagents" "$cl" 'spawn 2 parallel Task subagent(s)'
|
|
30
|
+
has "claude dispatch: Task isolation" "$cl" 'Task isolation: "worktree"'
|
|
31
|
+
no "claude dispatch: no orchestrate launch" "$cl" 'cckit orchestrate --agent codex'
|
|
32
|
+
has "codex dispatch: cckit owns the worktrees" "$cx" 'cckit creates the worktrees'
|
|
33
|
+
has "codex dispatch: launch line names the wave" "$cx" 'cckit orchestrate --agent codex --detach 101 103'
|
|
34
|
+
has "codex dispatch: results are collected" "$cx" 'cckit orchestrate --results'
|
|
35
|
+
no "codex dispatch: no Task tool wording" "$cx" 'Task isolation'
|
|
36
|
+
|
|
37
|
+
# Which adapters the brief speaks for: flag, then env, then the project (claude when unset).
|
|
38
|
+
eq() { if [ "$2" = "$3" ]; then :; else echo "FAIL($CP_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
39
|
+
eq "adapter flag wins" "$(CCKIT_ADAPTER=claude _copilot_adapters codex)" "codex"
|
|
40
|
+
eq "both is canonical order" "$(_copilot_adapters both)" "claude codex"
|
|
41
|
+
eq "env when no flag" "$(CCKIT_ADAPTER=codex _copilot_adapters '')" "codex"
|
|
42
|
+
_copilot_adapters cursor >/dev/null 2>&1; eq "an unknown adapter is refused" "$?" "1"
|
|
43
|
+
cfgd="$(mktemp -d)"
|
|
44
|
+
printf '{"adapters":["codex"]}\n' > "$cfgd/cckit.config.json"
|
|
45
|
+
eq "project selection when neither" "$(cd "$cfgd" && unset CCKIT_ADAPTER && KIT_CONFIG="$cfgd/cckit.config.json" _copilot_adapters '')" "codex"
|
|
46
|
+
rm -rf "$cfgd"
|
|
47
|
+
|
|
48
|
+
# --- the human brief under `set -e` (#316) ---------------------------------------------------
|
|
49
|
+
# The dispatcher runs `set -euo pipefail`, so a failing assignment-only command inside
|
|
50
|
+
# copilot_brief kills the verb with no output. Drive the real function in a child shell with
|
|
51
|
+
# errexit on. copilot_brief sources plan-machine.sh + render.sh from its own directory, so the
|
|
52
|
+
# sandbox holds the real copilot.sh + render.sh + the two adapter-resolution libs beside a stub
|
|
53
|
+
# plan machine that emits two rows.
|
|
54
|
+
box="$(mktemp -d "${TMPDIR:-/tmp}/copilot-test.XXXXXX")"
|
|
55
|
+
mkdir -p "$box/bin"
|
|
56
|
+
cp "$dir/copilot.sh" "$dir/render.sh" "$dir/adapter-select.sh" "$dir/config-path.sh" "$box/"
|
|
57
|
+
cat > "$box/plan-machine.sh" <<'STUB'
|
|
58
|
+
plan_machine() {
|
|
59
|
+
printf '0\t-\t7\tS\t-\t[Effort 5] 1 · first thing\n'
|
|
60
|
+
printf '1\t-\t8\tM\t-\tsecond thing\n'
|
|
61
|
+
}
|
|
62
|
+
STUB
|
|
63
|
+
for tool in gh jq; do
|
|
64
|
+
printf '#!/bin/sh\nexit 0\n' > "$box/bin/$tool"; chmod +x "$box/bin/$tool"
|
|
65
|
+
done
|
|
66
|
+
brief_run() { # brief_run [copilot_brief args…] — prints the brief, returns the child's rc
|
|
67
|
+
( cd "$box" && PATH="$box/bin:$PATH" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human COPILOT_REPO=o/r \
|
|
68
|
+
"$CP_TEST_INNER" -c 'set -e; . ./copilot.sh; copilot_brief "$@"' copilot "$@" )
|
|
69
|
+
}
|
|
70
|
+
hasnt() { case "$2" in *"$3"*) echo "FAIL($CP_TEST_INNER): $1 has '[$3]'"; fail=1 ;; esac; }
|
|
71
|
+
|
|
72
|
+
brief="$(brief_run)"; brc=$?
|
|
73
|
+
[ "$brc" -eq 0 ] || { echo "FAIL($CP_TEST_INNER): brief without --effort rc=$brc (want 0)"; fail=1; }
|
|
74
|
+
has "brief has heading" "$brief" '# cckit wave — o/r'
|
|
75
|
+
has "brief lists wave-0 issue" "$brief" '### #7 · [S] · first thing'
|
|
76
|
+
has "brief has watch line" "$brief" 'cckit watch --merge'
|
|
77
|
+
has "brief carries the default adapter dispatch" "$brief" '### Claude Code — spawn 1 parallel Task subagent(s)'
|
|
78
|
+
hasnt "brief without effort" "$brief" '--effort'
|
|
79
|
+
hasnt "brief heading no effort" "$brief" 'effort #'
|
|
80
|
+
|
|
81
|
+
brief="$(brief_run --effort 5)"; brc=$?
|
|
82
|
+
[ "$brc" -eq 0 ] || { echo "FAIL($CP_TEST_INNER): brief with --effort rc=$brc (want 0)"; fail=1; }
|
|
83
|
+
has "effort brief heading" "$brief" '# cckit wave — o/r · effort #5'
|
|
84
|
+
has "effort brief watch suffix" "$brief" 'cckit watch --merge --effort 5'
|
|
85
|
+
has "effort brief wave suffix" "$brief" 'cckit wave --effort 5'
|
|
86
|
+
rm -rf "$box"
|
|
87
|
+
|
|
88
|
+
if [ "$fail" -eq 0 ]; then echo "PASS($CP_TEST_INNER): copilot seed composer + adapter dispatch + brief under set -e"; fi
|
|
23
89
|
exit "$fail"
|
|
24
90
|
fi
|
|
25
91
|
|
package/scripts/lib/copilot.sh
CHANGED
|
@@ -1,32 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# copilot.sh — the copilot driver: turn the wave plan into a fan-out BRIEF
|
|
2
|
+
# copilot.sh — the copilot driver: turn the wave plan into a fan-out BRIEF the driving agent enacts
|
|
3
3
|
# (Effort 75 · #78). This is cckit's prompt machine.
|
|
4
4
|
#
|
|
5
5
|
# The orchestration brain is the driving agent, not a background launcher. So the copilot does not
|
|
6
6
|
# spawn anything itself — it EMITS the plan-as-instructions: for the current wave, a ready-to-run
|
|
7
|
-
#
|
|
8
|
-
#
|
|
7
|
+
# worker prompt per issue, and the between-waves drive (gate + merge with the captain, then re-run
|
|
8
|
+
# for the next wave). The agent reads the brief and acts.
|
|
9
|
+
#
|
|
10
|
+
# Two layers, kept apart (E257.6, #263). The WAVE DATA — which issues, their ctx, the prompt each
|
|
11
|
+
# worker gets — is the same for every runtime, and `--llm` emits only that. The DISPATCH wording —
|
|
12
|
+
# how this runtime starts N isolated workers — is chosen per adapter: Claude Code fans out Task
|
|
13
|
+
# subagents with worktree isolation; for Codex, cckit creates the worktrees (`cckit orchestrate`).
|
|
9
14
|
#
|
|
10
15
|
# cckit wave brief for the open board: wave 0 fan-out + the loop
|
|
11
16
|
# cckit wave --effort <N> brief scoped to effort #N's sub-issues
|
|
12
17
|
# cckit wave --cap <K> session ctx budget per wave (passed to the plan machine)
|
|
18
|
+
# cckit wave --adapter <claude|codex|both> dispatch wording (default: the project's adapters)
|
|
13
19
|
# cckit wave --llm the fan-out as TOON rows (wave,number,ctx,prompt) for an agent
|
|
14
20
|
#
|
|
15
21
|
# Requires: gh, jq (via the plan machine). bash 3.2 / zsh compatible.
|
|
16
22
|
# errors: strict — refuses to emit a brief without gh + jq
|
|
17
23
|
|
|
18
24
|
COPILOT_REPO="${COPILOT_REPO:-${KIT_REPO:-}}"
|
|
25
|
+
# Resolved at source time: inside a function zsh's $0 is the function's name, not this file.
|
|
26
|
+
_COPILOT_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
|
|
19
27
|
|
|
20
|
-
# _copilot_seed <num> <title> — the headless
|
|
28
|
+
# _copilot_seed <num> <title> — the headless worker prompt for one issue (worktree already isolated).
|
|
29
|
+
# Runtime-neutral on purpose: it is wave data, so it must read the same whichever agent receives it.
|
|
21
30
|
_copilot_seed() {
|
|
22
31
|
local num="$1" title="$2"
|
|
23
|
-
printf 'You are a
|
|
32
|
+
printf 'You are a worker in a cckit wave run — NO human is present, so never ask: decide autonomously and apply effort proportional to the task. Your worktree and branch for issue #%s are already isolated. Do: `gh issue view %s`, implement "%s", run `bash scripts/check.sh` until green, then open the PR with `cckit pr %s "<summary>"`. If it is a no-op, run `cckit close %s "<reason>"` with why. Return a one-line result.' \
|
|
24
33
|
"$num" "$num" "$title" "$num" "$num"
|
|
25
34
|
}
|
|
26
35
|
|
|
36
|
+
# _copilot_adapters <explicit> — the adapters whose dispatch wording the brief carries, as a
|
|
37
|
+
# canonical list ("claude", "codex" or "claude codex"). Precedence: --adapter, then CCKIT_ADAPTER,
|
|
38
|
+
# then the project's stored selection, then claude (every project scaffolded before the key existed).
|
|
39
|
+
_copilot_adapters() {
|
|
40
|
+
local want="${1:-${CCKIT_ADAPTER:-}}" here="$_COPILOT_DIR"
|
|
41
|
+
# shellcheck source=/dev/null
|
|
42
|
+
command -v adapter_normalize >/dev/null 2>&1 || . "$here/adapter-select.sh"
|
|
43
|
+
if [ -n "$want" ]; then adapter_normalize "$want"; return $?; fi
|
|
44
|
+
# shellcheck source=/dev/null
|
|
45
|
+
command -v kit_config_path >/dev/null 2>&1 || . "$here/config-path.sh" 2>/dev/null || true
|
|
46
|
+
adapter_project_list 2>/dev/null || printf 'claude\n'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# _copilot_dispatch <adapter> <count> <issue-numbers> — how THIS runtime starts the wave's workers.
|
|
50
|
+
_copilot_dispatch() {
|
|
51
|
+
local adapter="$1" n0="$2" nums="$3"
|
|
52
|
+
case "$adapter" in
|
|
53
|
+
claude)
|
|
54
|
+
printf '### Claude Code — spawn %s parallel Task subagent(s)\n\n' "$n0"
|
|
55
|
+
printf 'Each in its OWN worktree (Task isolation: "worktree", run in background). Branches are\nfile-disjoint within a wave, so they will not collide.\n\n'
|
|
56
|
+
;;
|
|
57
|
+
codex)
|
|
58
|
+
printf '### Codex — launch %s Codex session(s), one cckit worktree each\n\n' "$n0"
|
|
59
|
+
printf 'cckit creates the worktrees: it has not verified an isolation mode for Codex subagents, so do\nnot fan this wave out as subagents of one session in one checkout. Launch one session per issue,\nthen collect how each one ended:\n\n'
|
|
60
|
+
printf ' ```\n cckit orchestrate --agent codex --detach %s\n cckit orchestrate --results --wait 3600\n ```\n\n' "$nums"
|
|
61
|
+
printf '`orchestrate` skips an issue whose `blocked_by` is open, holds `--cap` (default 4) and seeds each\nworker from `cckit brief <issue>`. The prompts below state the same task for a session you start\nby hand in a worktree from `cckit start <issue>`.\n\n'
|
|
62
|
+
;;
|
|
63
|
+
esac
|
|
64
|
+
}
|
|
65
|
+
|
|
27
66
|
copilot_brief() {
|
|
28
67
|
command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || { echo "copilot: needs gh + jq" >&2; return 1; }
|
|
29
|
-
local repo="$COPILOT_REPO" out="${CCKIT_OUTPUT:-human}" effort="" cap="" planargs=()
|
|
68
|
+
local repo="$COPILOT_REPO" out="${CCKIT_OUTPUT:-human}" effort="" cap="" adapter_arg="" adapters planargs=()
|
|
30
69
|
while [ "$#" -gt 0 ]; do
|
|
31
70
|
case "$1" in
|
|
32
71
|
--llm|--output=json) out="json"; shift ;;
|
|
@@ -34,11 +73,16 @@ copilot_brief() {
|
|
|
34
73
|
--effort=*) effort="${1#*=}"; planargs+=(--effort "${1#*=}"); shift ;;
|
|
35
74
|
--cap) cap="$2"; planargs+=(--cap "$2"); shift 2 ;;
|
|
36
75
|
--cap=*) cap="${1#*=}"; planargs+=(--cap "${1#*=}"); shift ;;
|
|
37
|
-
|
|
76
|
+
--adapter) adapter_arg="${2:-}"; shift 2 ;;
|
|
77
|
+
--adapter=*) adapter_arg="${1#*=}"; shift ;;
|
|
78
|
+
-h|--help) sed -n '15,19p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; return 0 ;;
|
|
38
79
|
*) echo "copilot: unknown arg '$1'" >&2; return 2 ;;
|
|
39
80
|
esac
|
|
40
81
|
done
|
|
41
82
|
[ -n "$repo" ] || { echo "copilot: no repo (set KIT_REPO / COPILOT_REPO)" >&2; return 1; }
|
|
83
|
+
# Resolved before any read, so an unknown adapter name refuses instead of emitting a brief with
|
|
84
|
+
# no dispatch section. --llm carries wave data only, but still validates the flag it was given.
|
|
85
|
+
adapters="$(_copilot_adapters "$adapter_arg")" || { echo "copilot: --adapter takes claude, codex or both" >&2; return 2; }
|
|
42
86
|
|
|
43
87
|
# pull the wave plan as raw rows from the plan machine (#76).
|
|
44
88
|
local here; here="$(dirname "${BASH_SOURCE[0]}")"
|
|
@@ -76,14 +120,19 @@ copilot_brief() {
|
|
|
76
120
|
# in a TTY, verbatim markdown otherwise (renders natively in Claude Code, pipe-safe).
|
|
77
121
|
# shellcheck source=/dev/null
|
|
78
122
|
. "$here/render.sh"
|
|
79
|
-
local n0 esfx; n0="$(printf '%s\n' "$wave0" | grep -c .)"
|
|
80
|
-
esfx="$([ -n "$effort" ] && echo " --effort
|
|
123
|
+
local n0 esfx nums ad; n0="$(printf '%s\n' "$wave0" | grep -c .)"
|
|
124
|
+
# Not `esfx="$([ -n "$effort" ] && echo …)"`: with no --effort the substitution ends on the failed
|
|
125
|
+
# test, the assignment returns 1, and the dispatcher's `set -e` exits before the brief (#316).
|
|
126
|
+
esfx=""
|
|
127
|
+
if [ -n "$effort" ]; then esfx=" --effort $effort"; fi
|
|
128
|
+
nums="$(printf '%s\n' "$wave0" | awk -F'\t' '$3 != "" { printf "%s%s", sep, $3; sep = " " }')"
|
|
81
129
|
{
|
|
82
130
|
printf '# cckit wave — %s%s\n' "$repo" "$([ -n "$effort" ] && echo " · effort #$effort")"
|
|
83
|
-
printf '\nThe plan machine laid out %s wave(s). You are the orchestrator: fan wave 0 out as parallel\
|
|
131
|
+
printf '\nThe plan machine laid out %s wave(s). You are the orchestrator: fan wave 0 out as parallel\nworkers, gate + merge with the captain, then re-run this brief for the next wave.\n' "$((waves_total + 1))"
|
|
84
132
|
|
|
85
|
-
printf '\n## Wave 0 —
|
|
86
|
-
|
|
133
|
+
printf '\n## Wave 0 — %s parallel worker(s)\n\n' "$n0"
|
|
134
|
+
# The dispatch wording is the adapter's; everything after it is wave data shared by both.
|
|
135
|
+
for ad in $(printf '%s\n' "$adapters"); do _copilot_dispatch "$ad" "$n0" "$nums"; done
|
|
87
136
|
printf '%s\n' "$wave0" | awk -F'\t' '{print $3"\t"$4"\t"$6}' \
|
|
88
137
|
| while IFS="$(printf '\t')" read -r num ctx title; do
|
|
89
138
|
[ -n "$num" ] || continue
|
|
@@ -93,10 +142,13 @@ copilot_brief() {
|
|
|
93
142
|
done
|
|
94
143
|
|
|
95
144
|
printf '## Between waves — drive the captain\n\n'
|
|
96
|
-
printf '1. When the wave-0
|
|
145
|
+
printf '1. When the wave-0 workers have opened their PRs, gate + merge them:\n'
|
|
97
146
|
printf ' ```\n cckit watch --merge%s\n ```\n' "$esfx"
|
|
98
147
|
printf '2. Merging unblocks the next wave. Re-run this brief to get it:\n'
|
|
99
148
|
printf ' ```\n cckit wave%s\n ```\n' "$esfx"
|
|
100
|
-
printf '3. Repeat until `cckit wave` reports nothing to drive. To let the captain self-pace the\n gate/merge passes, use `cckit watch --loop`
|
|
149
|
+
printf '3. Repeat until `cckit wave` reports nothing to drive. To let the captain self-pace the\n gate/merge passes, use `cckit watch --loop`'
|
|
150
|
+
# `/loop` is a Claude Code command; a brief for Codex alone must not name it.
|
|
151
|
+
case " $adapters " in *" claude "*) printf ' (or drive this brief under `/loop` in Claude Code)' ;; esac
|
|
152
|
+
printf '.\n\n'
|
|
101
153
|
} | cckit_render
|
|
102
154
|
}
|
|
@@ -17,14 +17,14 @@ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]'
|
|
|
17
17
|
blk="$(awk '/^ effort\)/{f=1} f{print} f && /^ ;;$/{exit}' "$BIN")"
|
|
18
18
|
t "effort) branch found" "$([ -n "$blk" ] && echo yes)" "yes"
|
|
19
19
|
|
|
20
|
-
cfg_ln="$(printf '%s\n' "$blk" | grep -n 'load_kit_config' |
|
|
21
|
-
lib_ln="$(printf '%s\n' "$blk" | grep -n 'source "\$LIB/effort\.sh"' |
|
|
20
|
+
cfg_ln="$(printf '%s\n' "$blk" | grep -n 'load_kit_config' | sed -n 1p | cut -d: -f1)"
|
|
21
|
+
lib_ln="$(printf '%s\n' "$blk" | grep -n 'source "\$LIB/effort\.sh"' | sed -n 1p | cut -d: -f1)"
|
|
22
22
|
t "effort) loads the project config" "$([ -n "$cfg_ln" ] && echo yes)" "yes"
|
|
23
23
|
t "config load precedes the effort libs" "$([ -n "$cfg_ln" ] && [ -n "$lib_ln" ] && [ "$cfg_ln" -lt "$lib_ln" ] && echo yes)" "yes"
|
|
24
24
|
|
|
25
25
|
# #243: every effort subcommand the usage header advertises must actually dispatch, `chain` included
|
|
26
26
|
# — a docs/code drift guard (a subcommand documented but not wired falls through to the usage line).
|
|
27
|
-
usage_subs="$(grep -oE '^# cckit effort <[a-z|]+>' "$BIN" |
|
|
27
|
+
usage_subs="$(grep -oE '^# cckit effort <[a-z|]+>' "$BIN" | sed -n 1p | sed -E 's/.*<//; s/>//; s/\|/ /g')"
|
|
28
28
|
t "usage header lists the effort subcommands" "$usage_subs" "new chain start pr close plan"
|
|
29
29
|
for s in $usage_subs; do
|
|
30
30
|
t "effort) dispatches '$s'" \
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# shellcheck shell=bash
|
|
3
|
-
# effort-metrics-test.sh — covers
|
|
3
|
+
# effort-metrics-test.sh — covers capture_effort_metrics' build-time and token sources (#453, at the
|
|
4
|
+
# end of this file) and _em_token_sum's branch ∪ time-window attribution (#124). Token
|
|
4
5
|
# actuals must count sessions that match the effort BRANCH as well as sessions that fall inside the
|
|
5
6
|
# effort's build WINDOW [start,end] — the window recovers sessions logged before the branch field
|
|
6
7
|
# existed or from a detached/worktree checkout. Hermetic: a throwaway repo + a stubbed usage log +
|
|
@@ -54,5 +55,181 @@ t "window-only counts the in-window session" "$i $o" "50 5"
|
|
|
54
55
|
# no branch, no window: nothing attributable.
|
|
55
56
|
t "no branch + no window sums to zero" "$(_em_token_sum '' 0 0)" "0 0 0 0"
|
|
56
57
|
|
|
58
|
+
# ── #381: helpers resolve from the lib dir, not the caller's — under bash AND zsh ─────────────────
|
|
59
|
+
# Inside a zsh FUNCTION `BASH_SOURCE` is unset and `$0` is the function name, so a per-call
|
|
60
|
+
# `dirname "${BASH_SOURCE[0]:-$0}"` pointed at the caller's directory: engine-adapter.sh was never
|
|
61
|
+
# found and the sync buffered with "engine adapter unavailable". Run from a dir OUTSIDE the repo,
|
|
62
|
+
# with no config, so engine.mode reads "off" and the only way to that message is a found adapter.
|
|
63
|
+
outside="$tmp/outside"; mkdir -p "$outside"
|
|
64
|
+
_helpers_probe() { # _helpers_probe <shell> [flag] — prints the sync's stderr, then DEFINED|UNDEFINED
|
|
65
|
+
( cd "$outside" && env -u KIT_CONFIG LIB="$LIB" "$@" -c '
|
|
66
|
+
source "$LIB/effort-metrics.sh"
|
|
67
|
+
sync_effort_metrics 1 2>&1
|
|
68
|
+
if declare -f engine_enabled >/dev/null 2>&1; then echo DEFINED; else echo UNDEFINED; fi
|
|
69
|
+
_em_judge_call s u >/dev/null 2>&1
|
|
70
|
+
if declare -f kit_local_chat >/dev/null 2>&1; then echo LOCAL-DEFINED; else echo LOCAL-UNDEFINED; fi' 2>&1 )
|
|
71
|
+
}
|
|
72
|
+
_helpers_case() { # _helpers_case <label> <shell> [flag]
|
|
73
|
+
local label="$1" out; shift
|
|
74
|
+
out="$(CCKIT_MODEL_URL='' KIT_LOCAL_ENABLED=false _helpers_probe "$@")"
|
|
75
|
+
case "$out" in *"engine adapter unavailable"*) t "$label: sync finds the engine adapter" "unavailable" "found" ;;
|
|
76
|
+
*) t "$label: sync finds the engine adapter" "found" "found" ;; esac
|
|
77
|
+
case "$out" in *"engine off"*) t "$label: sync reaches the engine-off branch" "off" "off" ;;
|
|
78
|
+
*) t "$label: sync reaches the engine-off branch" "$out" "off" ;; esac
|
|
79
|
+
t "$label: engine_enabled is defined after the sync" "$(printf '%s\n' "$out" | grep -cx 'DEFINED')" "1"
|
|
80
|
+
t "$label: judge fallback finds kit-local.sh" "$(printf '%s\n' "$out" | grep -cx 'LOCAL-DEFINED')" "1"
|
|
81
|
+
}
|
|
82
|
+
_helpers_case bash bash
|
|
83
|
+
if command -v zsh >/dev/null 2>&1; then _helpers_case zsh zsh --no-rcs
|
|
84
|
+
else echo "skip: zsh absent — zsh helper-lookup case not run"; fi
|
|
85
|
+
|
|
86
|
+
# ── #381: the config names the judge's env vars (model.urlEnv / modelEnv / tokenEnv) ─────────────
|
|
87
|
+
# A stubbed curl on PATH records its argv and answers like an OpenAI-compatible endpoint.
|
|
88
|
+
stub="$tmp/stub"; mkdir -p "$stub"
|
|
89
|
+
cat > "$stub/curl" <<'STUB'
|
|
90
|
+
#!/usr/bin/env bash
|
|
91
|
+
printf '%s\n' "$@" > "$CURL_LOG"
|
|
92
|
+
printf '{"choices":[{"message":{"content":"VERDICT"}}]}'
|
|
93
|
+
STUB
|
|
94
|
+
chmod +x "$stub/curl"
|
|
95
|
+
export CURL_LOG="$tmp/curl.log"
|
|
96
|
+
cfg="$tmp/model.config.json"
|
|
97
|
+
printf '{"model":{"urlEnv":"ACME_LLM_URL","modelEnv":"ACME_LLM_NAME","tokenEnv":"ACME_LLM_KEY"}}\n' > "$cfg"
|
|
98
|
+
nocfg="$tmp/empty.config.json"; printf '{}\n' > "$nocfg"
|
|
99
|
+
_judge_probe() { # _judge_probe <config> <shell> [flag] — prints "<model_id>\t<reply>"; argv lands in $CURL_LOG
|
|
100
|
+
local c="$1"; shift; : > "$CURL_LOG"
|
|
101
|
+
( cd "$outside" && PATH="$stub:$PATH" KIT_CONFIG="$c" LIB="$LIB" "$@" -c '
|
|
102
|
+
source "$LIB/effort-metrics.sh"; _em_judge_call sys usr' 2>&1 )
|
|
103
|
+
}
|
|
104
|
+
_judge_case() { # _judge_case <label> <shell> [flag]
|
|
105
|
+
local label="$1" out; shift
|
|
106
|
+
out="$(ACME_LLM_URL='http://acme.test/v1/' ACME_LLM_NAME='acme-judge' ACME_LLM_KEY='acme-secret' \
|
|
107
|
+
CCKIT_MODEL_URL='http://default.test/v1' CCKIT_MODEL='default-model' CCKIT_MODEL_TOKEN='default-secret' \
|
|
108
|
+
_judge_probe "$cfg" "$@")"
|
|
109
|
+
t "$label: named urlEnv is the endpoint requested" "$(grep -c '^http://acme.test/v1/chat/completions$' "$CURL_LOG")" "1"
|
|
110
|
+
t "$label: named modelEnv is the model + model_id" "$out" "$(printf 'acme-judge\tVERDICT')"
|
|
111
|
+
t "$label: named tokenEnv is the bearer token" "$(grep -c '^Authorization: Bearer acme-secret$' "$CURL_LOG")" "1"
|
|
112
|
+
t "$label: the default vars are not read when named" "$(grep -c 'default' "$CURL_LOG")" "0"
|
|
113
|
+
|
|
114
|
+
out="$(CCKIT_MODEL_URL='http://default.test/v1' CCKIT_MODEL='default-model' CCKIT_MODEL_TOKEN='default-secret' \
|
|
115
|
+
_judge_probe "$nocfg" "$@")"
|
|
116
|
+
t "$label: keys unset → CCKIT_MODEL_URL still works" "$(grep -c '^http://default.test/v1/chat/completions$' "$CURL_LOG")" "1"
|
|
117
|
+
t "$label: keys unset → CCKIT_MODEL names the model" "$out" "$(printf 'default-model\tVERDICT')"
|
|
118
|
+
t "$label: keys unset → CCKIT_MODEL_TOKEN is sent" "$(grep -c '^Authorization: Bearer default-secret$' "$CURL_LOG")" "1"
|
|
119
|
+
|
|
120
|
+
out="$(CCKIT_MODEL_URL='http://default.test/v1' _judge_probe "$nocfg" "$@")"
|
|
121
|
+
t "$label: no token → no Authorization header" "$(grep -c '^Authorization' "$CURL_LOG")" "0"
|
|
122
|
+
|
|
123
|
+
# A name that is not a shell identifier is refused (it would be eval'd): warn, use the default.
|
|
124
|
+
printf '{"model":{"urlEnv":"X; touch %s/pwned"}}\n' "$tmp" > "$tmp/bad.config.json"
|
|
125
|
+
out="$(CCKIT_MODEL_URL='http://default.test/v1' _judge_probe "$tmp/bad.config.json" "$@")"
|
|
126
|
+
t "$label: invalid env name falls back to the default" "$(grep -c '^http://default.test/v1/chat/completions$' "$CURL_LOG")" "1"
|
|
127
|
+
case "$out" in *"model.urlEnv"*) t "$label: invalid env name warns" "warned" "warned" ;;
|
|
128
|
+
*) t "$label: invalid env name warns" "$out" "warned" ;; esac
|
|
129
|
+
t "$label: invalid env name is never executed" "$([ -e "$tmp/pwned" ] && echo ran || echo safe)" "safe"
|
|
130
|
+
}
|
|
131
|
+
_judge_case bash bash
|
|
132
|
+
if command -v zsh >/dev/null 2>&1; then _judge_case zsh zsh --no-rcs
|
|
133
|
+
else echo "skip: zsh absent — zsh judge env-name case not run"; fi
|
|
134
|
+
|
|
135
|
+
# ── #453: capture records build time and tokens from sources that exist, and says why not ───────
|
|
136
|
+
# One probe script, run under bash and zsh. Each case builds its own repo (no usage log unless the
|
|
137
|
+
# case writes one) and prints `<case>: <fields>` lines read back below.
|
|
138
|
+
cat > "$tmp/cap.sh" <<'CAP'
|
|
139
|
+
LIB="$1"; work="$2"
|
|
140
|
+
. "$LIB/effort-metrics.sh"
|
|
141
|
+
mkrepo() { # mkrepo <dir> <effort-branch> — main + one commit on the branch, authored 1000s ago
|
|
142
|
+
git init -q -b main "$1" && cd "$1" || exit 1
|
|
143
|
+
git config user.email t@t; git config user.name t; git config commit.gpgsign false
|
|
144
|
+
git commit -q --allow-empty -m init
|
|
145
|
+
git checkout -q -b "$2"
|
|
146
|
+
echo x > f.txt; git add f.txt
|
|
147
|
+
GIT_AUTHOR_DATE="@$(( $(date -u +%s) - 1000 )) +0000" git commit -q -m work
|
|
148
|
+
}
|
|
149
|
+
last() { tail -1 "$(git rev-parse --git-common-dir)/effort-metrics/records.jsonl"; }
|
|
150
|
+
near() { awk -v v="$1" -v w="$2" 'BEGIN{ if (v ~ /^[0-9]+$/ && v >= w && v < w + 120) print "near"; else print "off:" v }'; }
|
|
151
|
+
export KIT_STATE_DIR="$work/state-none"
|
|
152
|
+
|
|
153
|
+
# (a) no stamp → oldest commit on the branch; no usage source → null with the reason.
|
|
154
|
+
mkrepo "$work/a" effort/5-x
|
|
155
|
+
old='{"effort":1,"branch":"effort/1-old","captured_at":"2026-07-03T03:21:43Z","build_seconds":null,"signals":{"files":2,"added":5,"removed":1,"commits":1},"tokens_real":null,"cost_real_usd":null,"cost_source":null,"tokens_est":null,"cost_est_usd":null,"difficulty_auto":1,"score_auto":null,"difficulty_judge":null,"score_judge":null,"synced_to_graph":false}'
|
|
156
|
+
mkdir -p .git/effort-metrics; printf '%s\n' "$old" > .git/effort-metrics/records.jsonl
|
|
157
|
+
capture_effort_metrics 5 main 2>/dev/null
|
|
158
|
+
echo "a: $(last | jq -r '"\(.build_source) \(.tokens_real) \(.tokens_source) \(.tokens_null_reason) \(.cost_real_usd) \(.cost_source)"') $(near "$(last | jq -r .build_seconds)" 1000)"
|
|
159
|
+
[ "$(head -1 .git/effort-metrics/records.jsonl)" = "$old" ] && echo "a-old: kept" || echo "a-old: rewritten"
|
|
160
|
+
echo "a-rows: $(wc -l < .git/effort-metrics/records.jsonl | tr -d ' ')"
|
|
161
|
+
echo "a-recal: $(jq -r '"\(.model.n_efforts) \(.model.median_build_seconds != null)"' .git/effort-metrics/estimator.json)"
|
|
162
|
+
|
|
163
|
+
# (b) the stamp wins over the commit, and a second record_effort_start keeps it.
|
|
164
|
+
mkrepo "$work/b" effort/6-x
|
|
165
|
+
record_effort_start 6
|
|
166
|
+
[ -s .git/effort-metrics/6.start ] && echo "b-stamp: written" || echo "b-stamp: missing"
|
|
167
|
+
echo $(( $(date -u +%s) - 500 )) > .git/effort-metrics/6.start
|
|
168
|
+
record_effort_start 6
|
|
169
|
+
capture_effort_metrics 6 main 2>/dev/null
|
|
170
|
+
echo "b: $(last | jq -r .build_source) $(near "$(last | jq -r .build_seconds)" 500)"
|
|
171
|
+
[ -e .git/effort-metrics/6.start ] && echo "b-clean: left" || echo "b-clean: removed"
|
|
172
|
+
|
|
173
|
+
# (c) a branch with no commit of its own and no stamp → build_seconds stays null.
|
|
174
|
+
git init -q -b main "$work/c" && cd "$work/c" && git config user.email t@t && git config user.name t
|
|
175
|
+
git commit -q --allow-empty -m init; git checkout -q -b effort/8-x
|
|
176
|
+
capture_effort_metrics 8 main 2>/dev/null
|
|
177
|
+
echo "c: $(last | jq -r '"\(.build_seconds) \(.build_source)"')"
|
|
178
|
+
|
|
179
|
+
# (d) autopilot run state: the effort branch + its sub branch are summed; sub/70a-… is another effort.
|
|
180
|
+
mkrepo "$work/d" effort/7-y
|
|
181
|
+
export KIT_STATE_DIR="$work/state-d"; mkdir -p "$KIT_STATE_DIR/autopilot"
|
|
182
|
+
printf '{"branch":"effort/7-y","rounds":2,"usage":{"tokens":300,"cost_usd":0.02}}\n' > "$KIT_STATE_DIR/autopilot/effort_7-y.json"
|
|
183
|
+
printf '{"branch":"sub/7a-z","rounds":1,"usage":{"tokens":150,"cost_usd":0.01}}\n' > "$KIT_STATE_DIR/autopilot/sub_7a-z.json"
|
|
184
|
+
printf '{"branch":"sub/70a-q","rounds":1,"usage":{"tokens":999,"cost_usd":9}}\n' > "$KIT_STATE_DIR/autopilot/sub_70a-q.json"
|
|
185
|
+
printf '{"branch":"sub/7b-w","rounds":0,"usage":{"tokens":"unknown","cost_usd":"unknown"}}\n' > "$KIT_STATE_DIR/autopilot/sub_7b-w.json"
|
|
186
|
+
capture_effort_metrics 7 main 2>/dev/null
|
|
187
|
+
echo "d: $(last | jq -r '"\(.tokens_real) \(.tokens_source) \(.tokens_null_reason) \(.cost_real_usd) \(.cost_source)"')"
|
|
188
|
+
# a runtime that prints no cost (Codex): tokens stay, cost is null
|
|
189
|
+
printf '{"branch":"sub/7a-z","rounds":1,"usage":{"tokens":150,"cost_usd":"unknown"}}\n' > "$KIT_STATE_DIR/autopilot/sub_7a-z.json"
|
|
190
|
+
capture_effort_metrics 7 main 2>/dev/null
|
|
191
|
+
echo "d-nocost: $(last | jq -r '"\(.tokens_real) \(.tokens_source) \(.cost_real_usd) \(.cost_source)"')"
|
|
192
|
+
# a run whose rounds printed no usage: no partial sum
|
|
193
|
+
printf '{"branch":"sub/7a-z","rounds":1,"usage":{"tokens":"unknown","cost_usd":"unknown"}}\n' > "$KIT_STATE_DIR/autopilot/sub_7a-z.json"
|
|
194
|
+
capture_effort_metrics 7 main 2>/dev/null
|
|
195
|
+
echo "d-unknown: $(last | jq -r '"\(.tokens_real) \(.tokens_source) \(.tokens_null_reason) \(.cost_real_usd)"')"
|
|
196
|
+
|
|
197
|
+
# (e) a usage log that lists no session for this effort.
|
|
198
|
+
export KIT_STATE_DIR="$work/state-none"
|
|
199
|
+
mkrepo "$work/e" effort/9-x
|
|
200
|
+
printf '{"session":"ZZZ","branch":"other/1-y","ts":"2001-01-01T00:00:00Z"}\n' > .git/kit-usage.jsonl
|
|
201
|
+
capture_effort_metrics 9 main 2>/dev/null
|
|
202
|
+
echo "e: $(last | jq -r '"\(.tokens_real) \(.tokens_null_reason)"')"
|
|
203
|
+
|
|
204
|
+
# (f) a usage log that does list one: the transcript sum, labelled.
|
|
205
|
+
mkrepo "$work/f" effort/10-x
|
|
206
|
+
printf '{"session":"FFF","branch":"effort/10-x","ts":"2001-01-01T00:00:00Z"}\n' > .git/kit-usage.jsonl
|
|
207
|
+
printf '{"message":{"usage":{"input_tokens":100,"output_tokens":10}}}\n' > "$HOME/.claude/projects/FFF.jsonl"
|
|
208
|
+
capture_effort_metrics 10 main 2>/dev/null
|
|
209
|
+
echo "f: $(last | jq -r '"\(.tokens_real) \(.tokens_source) \(.tokens_null_reason) \(.cost_source)"')"
|
|
210
|
+
CAP
|
|
211
|
+
_cap_case() { # _cap_case <label> <shell> [flag]
|
|
212
|
+
local label="$1" out work; shift
|
|
213
|
+
work="$(mktemp -d "$tmp/cap.XXXXXX")"
|
|
214
|
+
out="$( cd "$tmp" && "$@" "$tmp/cap.sh" "$LIB" "$work" 2>&1 )"
|
|
215
|
+
g() { printf '%s\n' "$out" | sed -n "s/^$1: //p"; }
|
|
216
|
+
t "$label: no stamp → build time from the oldest branch commit" "$(g a)" "first-commit null null no-usage-source null null near"
|
|
217
|
+
t "$label: an existing record line is left byte-identical" "$(g a-old)" "kept"
|
|
218
|
+
t "$label: capture appends exactly one row" "$(g a-rows)" "2"
|
|
219
|
+
t "$label: recalibration reads old + new rows, build median set" "$(g a-recal)" "2 true"
|
|
220
|
+
t "$label: record_effort_start writes the stamp" "$(g b-stamp)" "written"
|
|
221
|
+
t "$label: the stamp wins and a second start keeps it" "$(g b)" "effort-start near"
|
|
222
|
+
t "$label: capture removes the stamp" "$(g b-clean)" "removed"
|
|
223
|
+
t "$label: no stamp and no commit → build_seconds null" "$(g c)" "null null"
|
|
224
|
+
t "$label: autopilot runs of the effort + its subs are summed" "$(g d)" "450 autopilot-run null 0.03 runtime"
|
|
225
|
+
t "$label: a run with no printed cost keeps cost null" "$(g d-nocost)" "450 autopilot-run null null"
|
|
226
|
+
t "$label: a run with unknown usage gives null, not a partial sum" "$(g d-unknown)" "null null autopilot-usage-unknown null"
|
|
227
|
+
t "$label: a usage log with no matching session says so" "$(g e)" "null no-session-matched"
|
|
228
|
+
t "$label: a matching session is summed from its transcript" "$(g f)" "110 transcripts null list-price"
|
|
229
|
+
}
|
|
230
|
+
_cap_case bash bash
|
|
231
|
+
if command -v zsh >/dev/null 2>&1; then _cap_case zsh zsh --no-rcs
|
|
232
|
+
else echo "skip: zsh absent — zsh capture case not run"; fi
|
|
233
|
+
|
|
57
234
|
[ "$fail" -eq 0 ] && echo "ALL OK (effort-metrics)" || echo "effort-metrics: FAILURES"
|
|
58
235
|
exit "$fail"
|