@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
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# autopilot-run.sh - ONE bounded, unattended objective on the current branch (E257.7, #264).
|
|
3
|
+
#
|
|
4
|
+
# `cckit autopilot` launches interactive panes. This is the other half: it starts the agent with no
|
|
5
|
+
# terminal (`claude -p` or `codex exec`, through scripts/lib/agent-launch.sh), one round at a time,
|
|
6
|
+
# and decides in CODE after every round whether the run goes on. Nothing the agent says ends or
|
|
7
|
+
# extends a run; a limit in the prompt is not a limit.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# cckit autopilot run [<issue>] --objective "<text>" [options]
|
|
11
|
+
# cckit autopilot run --resume [limit options]
|
|
12
|
+
#
|
|
13
|
+
# --objective "<text>" | --prompt-file <f> what to do (one is required on a new run)
|
|
14
|
+
# --agent <claude|codex> the CLI (default: CCKIT_AGENT, else claude)
|
|
15
|
+
# --profile <name> a declared agent profile: its kind + args; it must allow `build`
|
|
16
|
+
# and declare write:true
|
|
17
|
+
# --agent-arg <arg> one extra argv entry for the agent CLI (repeatable). cckit adds no
|
|
18
|
+
# permission flag: a run that must edit files names its own here
|
|
19
|
+
# --until "<cmd>" completion check, run before round 1 and after every round; rc 0
|
|
20
|
+
# ends the run. One that already passes ends it with no round run
|
|
21
|
+
# (exit 0, said on stderr): use --check for a gate on the work
|
|
22
|
+
# --check "<cmd>" publication gate, run once the work is complete; a failure stops
|
|
23
|
+
# the run and nothing is published
|
|
24
|
+
# --max-iters <n> rounds allowed in total (default 5)
|
|
25
|
+
# --max-seconds <s> wall-clock allowed in total (default 3600)
|
|
26
|
+
# --round-seconds <s> wall-clock allowed per round (default 900)
|
|
27
|
+
# --max-tokens <n> token ceiling, checked BETWEEN rounds from the runtime's own usage
|
|
28
|
+
# output; a round that reports no usage stops the run
|
|
29
|
+
# --record-skills record which skills each round LOADED, read from the agent CLI's own
|
|
30
|
+
# event output (never from what the agent says): state `.skills`.
|
|
31
|
+
# Claude is started with `--output-format stream-json --verbose`
|
|
32
|
+
# for it; Codex prints events already
|
|
33
|
+
# --publish --summary "<s>" on success open the PR with `cckit pr <issue> "<s>"`, unless the
|
|
34
|
+
# branch already has an open one
|
|
35
|
+
# --resume continue the stopped run on this branch; counters carry over
|
|
36
|
+
# --fresh discard a stopped run's state and start over
|
|
37
|
+
# --dry-run print the plan; start nothing, write nothing
|
|
38
|
+
#
|
|
39
|
+
# Stop reasons, each decided by code and written to the state file:
|
|
40
|
+
# done the completion check passed (and the gate, when given) exit 0
|
|
41
|
+
# agent-failed the agent exited non-zero exit 3
|
|
42
|
+
# limit-iters | limit-seconds | limit-tokens | usage-unknown exit 4
|
|
43
|
+
# no-progress a round changed neither HEAD nor the working tree exit 5
|
|
44
|
+
# check-failed the publication gate failed exit 6
|
|
45
|
+
# publish-failed the work passed but `cckit pr` did not open the PR exit 7
|
|
46
|
+
# interrupted this process or the agent was killed by a signal exit 130
|
|
47
|
+
# A refusal (bad flag, base branch, unsupported agent, a live run on the branch, an agent an
|
|
48
|
+
# earlier run left alive) is exit 2 and writes nothing.
|
|
49
|
+
#
|
|
50
|
+
# A round that was cut short (a signal, or this process killed outright) is counted from whatever
|
|
51
|
+
# usage its output holds; when it holds none the run's tokens read `unknown`, never a sum that
|
|
52
|
+
# leaves the round out.
|
|
53
|
+
#
|
|
54
|
+
# Not here, on purpose: merging. A run never merges and never closes an issue.
|
|
55
|
+
# errors: strict — every stop is a state-file write plus the exit code above
|
|
56
|
+
set -uo pipefail
|
|
57
|
+
|
|
58
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
59
|
+
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
60
|
+
# shellcheck source=/dev/null
|
|
61
|
+
. "$SCRIPT_DIR/lib/agent-launch.sh"
|
|
62
|
+
# shellcheck source=/dev/null
|
|
63
|
+
. "$SCRIPT_DIR/lib/kit-state.sh"
|
|
64
|
+
# shellcheck source=/dev/null
|
|
65
|
+
. "$SCRIPT_DIR/lib/worktree-issue.sh"
|
|
66
|
+
|
|
67
|
+
die() { echo "autopilot run: $*" >&2; exit 2; }
|
|
68
|
+
is_uint() { case "${1:-}" in ''|*[!0-9]*) return 1 ;; esac; return 0; }
|
|
69
|
+
|
|
70
|
+
ISSUE="" OBJECTIVE="" PROMPT_FILE="" AGENT="" AGENT_SET=0 PROFILE="" UNTIL="" CHECK=""
|
|
71
|
+
MAX_ITERS="" MAX_SECONDS="" ROUND_SECONDS="" MAX_TOKENS="" PUBLISH="" SUMMARY=""
|
|
72
|
+
RESUME=0 FRESH=0 DRYRUN=0 RECORD_SKILLS=0
|
|
73
|
+
AGENT_ARGS=()
|
|
74
|
+
|
|
75
|
+
need() { [ "$#" -ge 2 ] || die "$1 needs a value"; }
|
|
76
|
+
while [ "$#" -gt 0 ]; do
|
|
77
|
+
case "$1" in
|
|
78
|
+
--objective) need "$@"; OBJECTIVE="$2"; shift 2 ;;
|
|
79
|
+
--prompt-file) need "$@"; PROMPT_FILE="$2"; shift 2 ;;
|
|
80
|
+
--agent) need "$@"; AGENT="$2"; AGENT_SET=1; shift 2 ;;
|
|
81
|
+
--profile) need "$@"; PROFILE="$2"; shift 2 ;;
|
|
82
|
+
--agent-arg) need "$@"; AGENT_ARGS+=("$2"); shift 2 ;;
|
|
83
|
+
--until) need "$@"; UNTIL="$2"; shift 2 ;;
|
|
84
|
+
--check) need "$@"; CHECK="$2"; shift 2 ;;
|
|
85
|
+
--max-iters) need "$@"; MAX_ITERS="$2"; shift 2 ;;
|
|
86
|
+
--max-seconds) need "$@"; MAX_SECONDS="$2"; shift 2 ;;
|
|
87
|
+
--round-seconds) need "$@"; ROUND_SECONDS="$2"; shift 2 ;;
|
|
88
|
+
--max-tokens) need "$@"; MAX_TOKENS="$2"; shift 2 ;;
|
|
89
|
+
--summary) need "$@"; SUMMARY="$2"; shift 2 ;;
|
|
90
|
+
--publish) PUBLISH=1; shift ;;
|
|
91
|
+
--record-skills) RECORD_SKILLS=1; shift ;;
|
|
92
|
+
--resume) RESUME=1; shift ;;
|
|
93
|
+
--fresh) FRESH=1; shift ;;
|
|
94
|
+
--dry-run) DRYRUN=1; shift ;;
|
|
95
|
+
--notify|--notify=*|--plan|--plan=*)
|
|
96
|
+
die "'${1%%=*}' is not supported: no code path delivers a notification or runs a plan from here (see docs: agent-compatibility, unattended limits)" ;;
|
|
97
|
+
-h|--help) sed -n '2,55p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
98
|
+
[0-9]*) [ -z "$ISSUE" ] || die "one issue at a time (got '$ISSUE' and '$1')"; ISSUE="$1"; shift ;;
|
|
99
|
+
*) die "unknown arg '$1'" ;;
|
|
100
|
+
esac
|
|
101
|
+
done
|
|
102
|
+
|
|
103
|
+
command -v jq >/dev/null 2>&1 || die "jq is required"
|
|
104
|
+
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" || die "not inside a git repository"
|
|
105
|
+
[ "$BRANCH" != "HEAD" ] || die "detached HEAD - a run needs a branch to own"
|
|
106
|
+
WORKTREE="$(git rev-parse --show-toplevel)"
|
|
107
|
+
|
|
108
|
+
# Never on the base branch: every round commits. The config names it; main/develop are refused
|
|
109
|
+
# with or without a config, since a run that could not read the config must not conclude it is safe.
|
|
110
|
+
BASE=""
|
|
111
|
+
CFG="$(. "$SCRIPT_DIR/lib/config-path.sh" 2>/dev/null && kit_config_path 2>/dev/null || true)"
|
|
112
|
+
[ -n "$CFG" ] && [ -f "$CFG" ] && BASE="$(jq -r '.github.baseBranch // .github.integrationBranch // .github.flow // ""' "$CFG" 2>/dev/null)"
|
|
113
|
+
BASE="${KIT_BASE_BRANCH:-$BASE}"
|
|
114
|
+
case "$BRANCH" in main|master|develop|"$BASE") die "refusing to run on '$BRANCH' - start a worktree first (cckit start <issue>)" ;; esac
|
|
115
|
+
|
|
116
|
+
KEY="$(printf '%s' "$BRANCH" | tr -c 'A-Za-z0-9._-' '_')"
|
|
117
|
+
SDIR="$(kit_state_dir)/autopilot"
|
|
118
|
+
STATE="$SDIR/$KEY.json"
|
|
119
|
+
# Where al_run records the agent it has running. Read below before anything starts: a runner killed
|
|
120
|
+
# with SIGKILL leaves `status: running` behind with a dead pid, and only this file can say whether
|
|
121
|
+
# its agent went with it.
|
|
122
|
+
AL_PIDFILE="$SDIR/$KEY.agent.pid"
|
|
123
|
+
sget() { jq -r "$1" "$STATE" 2>/dev/null; }
|
|
124
|
+
|
|
125
|
+
# --- an existing run on this branch --------------------------------------------------------------
|
|
126
|
+
PREV_ROUNDS=0 PREV_ELAPSED=0 TOK_IN=0 TOK_OUT=0 TOK_KNOWN=1 COST=0 COST_KNOWN=1 PR_URL="" USAGE_SRC="none"
|
|
127
|
+
PREV_OPEN_AGENT=""
|
|
128
|
+
# Skills the rounds loaded (--record-skills): one name per line. SK_KNOWN drops to 0 when a round's
|
|
129
|
+
# output held no event, because a list that leaves a round out is not the run's list.
|
|
130
|
+
SK_LIST="" SK_KNOWN=1
|
|
131
|
+
if [ -f "$STATE" ]; then
|
|
132
|
+
prev_status="$(sget '.status // ""')"; prev_pid="$(sget '.pid // ""')"; prev_reason="$(sget '.reason // ""')"
|
|
133
|
+
if [ "$prev_status" = "running" ] && is_uint "$prev_pid" && kill -0 "$prev_pid" 2>/dev/null \
|
|
134
|
+
&& [ "$(sget '.host // ""')" = "$(hostname 2>/dev/null)" ]; then
|
|
135
|
+
die "a run is already live on '$BRANCH' (pid $prev_pid) - one writer per branch"
|
|
136
|
+
fi
|
|
137
|
+
# The runner is gone; its agent may not be. Checked for every start that would launch an agent
|
|
138
|
+
# (--resume, --fresh, a new run; --dry-run launches none), because each would put a second
|
|
139
|
+
# writer on the branch. Refused, not killed: the pid is all the file knows, and a recycled pid
|
|
140
|
+
# belongs to someone else.
|
|
141
|
+
if [ "$DRYRUN" != "1" ] && [ "$(sget '.host // ""')" = "$(hostname 2>/dev/null)" ] && al_pidfile_alive "$AL_PIDFILE"; then
|
|
142
|
+
read -r _apid _agrp < "$AL_PIDFILE" || true
|
|
143
|
+
[ "$_agrp" = "1" ] && _akill="kill -TERM -- -$_apid" || _akill="kill -TERM $_apid"
|
|
144
|
+
die "the agent an earlier run started on '$BRANCH' is still alive (pid $_apid) though its runner is gone - one writer per branch. Stop it with: $_akill (if pid $_apid is not that agent, remove $AL_PIDFILE)"
|
|
145
|
+
fi
|
|
146
|
+
if [ "$RESUME" = "1" ]; then
|
|
147
|
+
if [ "$prev_reason" = "done" ]; then
|
|
148
|
+
echo "autopilot run: '$BRANCH' already finished (reason=done) - nothing to resume"
|
|
149
|
+
[ -n "$(sget '.pr_url // ""')" ] && echo "autopilot run: PR $(sget '.pr_url')"
|
|
150
|
+
exit 0
|
|
151
|
+
fi
|
|
152
|
+
# Flags given with --resume win (that is how a limit-stopped run is extended); everything
|
|
153
|
+
# else comes back from the state file so the resumed run is the same run.
|
|
154
|
+
[ -n "$ISSUE" ] || ISSUE="$(sget '.issue // ""')"
|
|
155
|
+
[ -n "$OBJECTIVE" ] || [ -n "$PROMPT_FILE" ] || OBJECTIVE="$(sget '.objective // ""')"
|
|
156
|
+
[ "$AGENT_SET" = "1" ] || [ -n "$PROFILE" ] || AGENT="$(sget '.agent // ""')"
|
|
157
|
+
if [ "${#AGENT_ARGS[@]}" -eq 0 ] && [ -z "$PROFILE" ]; then
|
|
158
|
+
while IFS= read -r _a; do [ -n "$_a" ] && AGENT_ARGS+=("$_a"); done <<< "$(sget '.agent_args // [] | .[]')"
|
|
159
|
+
fi
|
|
160
|
+
[ -n "$UNTIL" ] || UNTIL="$(sget '.until // ""')"
|
|
161
|
+
[ -n "$CHECK" ] || CHECK="$(sget '.check // ""')"
|
|
162
|
+
[ -n "$MAX_ITERS" ] || MAX_ITERS="$(sget '.limits.max_iters // ""')"
|
|
163
|
+
[ -n "$MAX_SECONDS" ] || MAX_SECONDS="$(sget '.limits.max_seconds // ""')"
|
|
164
|
+
[ -n "$ROUND_SECONDS" ] || ROUND_SECONDS="$(sget '.limits.round_seconds // ""')"
|
|
165
|
+
[ -n "$MAX_TOKENS" ] || MAX_TOKENS="$(sget '.limits.max_tokens // "" | tostring' | sed 's/^null$//')"
|
|
166
|
+
[ -n "$PUBLISH" ] || { [ "$(sget '.publish // false')" = "true" ] && PUBLISH=1; }
|
|
167
|
+
[ -n "$SUMMARY" ] || SUMMARY="$(sget '.summary // ""')"
|
|
168
|
+
if [ "$(sget '.skills | type')" = "object" ]; then
|
|
169
|
+
RECORD_SKILLS=1
|
|
170
|
+
SK_LIST="$(sget '.skills.loaded // [] | .[]')"
|
|
171
|
+
[ "$(sget '.skills.complete')" = "true" ] || { [ "$(sget '.rounds // 0')" = "0" ] || SK_KNOWN=0; }
|
|
172
|
+
fi
|
|
173
|
+
PREV_ROUNDS="$(sget '.rounds // 0')"; PREV_ELAPSED="$(sget '.elapsed_seconds // 0')"
|
|
174
|
+
PR_URL="$(sget '.pr_url // ""')"; USAGE_SRC="$(sget '.usage.source // "none"')"
|
|
175
|
+
TOK_IN="$(sget '.usage.known_input_tokens // 0')"; TOK_OUT="$(sget '.usage.known_output_tokens // 0')"
|
|
176
|
+
[ "$(sget '.usage.tokens')" = "unknown" ] && [ "$PREV_ROUNDS" != "0" ] && TOK_KNOWN=0
|
|
177
|
+
COST="$(sget '.usage.known_cost_usd // 0')"
|
|
178
|
+
[ "$(sget '.usage.cost_usd')" = "unknown" ] && [ "$PREV_ROUNDS" != "0" ] && COST_KNOWN=0
|
|
179
|
+
# A runner that died with a round in flight never counted that round. Its output file is still
|
|
180
|
+
# there; it is counted once the helpers below exist (see "the round a dead runner left open").
|
|
181
|
+
[ "$(sget '.round_open // false')" = "true" ] && [ "$PREV_ROUNDS" != "0" ] && PREV_OPEN_AGENT="$(sget '.agent // ""')"
|
|
182
|
+
elif [ "$FRESH" != "1" ] && [ "$DRYRUN" != "1" ]; then
|
|
183
|
+
die "'$BRANCH' has a stopped run (reason=${prev_reason:-?}, rounds=$(sget '.rounds // 0')): pass --resume to continue it or --fresh to discard it"
|
|
184
|
+
fi
|
|
185
|
+
elif [ "$RESUME" = "1" ]; then
|
|
186
|
+
die "nothing to resume on '$BRANCH' (no state at $STATE)"
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
# --- validate everything before anything runs ----------------------------------------------------
|
|
190
|
+
[ -n "$PROFILE" ] && [ "$AGENT_SET" = "1" ] && die "--agent and --profile are two ways to pick the CLI - pass one"
|
|
191
|
+
if [ -n "$PROFILE" ]; then
|
|
192
|
+
# shellcheck source=/dev/null
|
|
193
|
+
. "$SCRIPT_DIR/lib/agent-profile.sh"
|
|
194
|
+
[ -n "$CFG" ] && [ -f "$CFG" ] || die "--profile '$PROFILE' given but no kit config was found"
|
|
195
|
+
ap_profile_validate "$CFG" "$PROFILE" build || exit 2
|
|
196
|
+
ap_profile_writes "$CFG" "$PROFILE" || die "profile '$PROFILE' does not declare write:true - an unattended run commits to the branch"
|
|
197
|
+
AGENT="$(ap_profile_field "$CFG" "$PROFILE" kind)"
|
|
198
|
+
AGENT_ARGS=()
|
|
199
|
+
while IFS= read -r _a; do [ -n "$_a" ] && AGENT_ARGS+=("$_a"); done <<< "$(ap_profile_args "$CFG" "$PROFILE")"
|
|
200
|
+
fi
|
|
201
|
+
[ -n "$AGENT" ] || AGENT="${CCKIT_AGENT:-claude}"
|
|
202
|
+
al_supported "$AGENT" || die "agent '$AGENT' has no non-interactive form cckit knows (supported: claude, codex)"
|
|
203
|
+
|
|
204
|
+
if [ -n "$PROMPT_FILE" ]; then
|
|
205
|
+
[ -f "$PROMPT_FILE" ] || die "--prompt-file '$PROMPT_FILE' not found"
|
|
206
|
+
OBJECTIVE="$(cat "$PROMPT_FILE")"
|
|
207
|
+
fi
|
|
208
|
+
[ -n "$OBJECTIVE" ] || die "an objective is required: --objective \"<text>\" or --prompt-file <f>"
|
|
209
|
+
[ -n "$ISSUE" ] || ISSUE="$(wt_issue_number "$BRANCH")"
|
|
210
|
+
|
|
211
|
+
MAX_ITERS="${MAX_ITERS:-5}"; MAX_SECONDS="${MAX_SECONDS:-3600}"; ROUND_SECONDS="${ROUND_SECONDS:-900}"
|
|
212
|
+
for _pair in "--max-iters:$MAX_ITERS" "--max-seconds:$MAX_SECONDS" "--round-seconds:$ROUND_SECONDS"; do
|
|
213
|
+
is_uint "${_pair#*:}" && [ "${_pair#*:}" -gt 0 ] || die "${_pair%%:*} '${_pair#*:}' is not a positive integer"
|
|
214
|
+
done
|
|
215
|
+
if [ -n "$MAX_TOKENS" ]; then
|
|
216
|
+
is_uint "$MAX_TOKENS" && [ "$MAX_TOKENS" -gt 0 ] || die "--max-tokens '$MAX_TOKENS' is not a positive integer"
|
|
217
|
+
fi
|
|
218
|
+
if [ -n "$PUBLISH" ]; then
|
|
219
|
+
[ -n "$ISSUE" ] || die "--publish needs an issue: pass <issue>, or run on a <kind>/<N>-<slug> branch"
|
|
220
|
+
[ -n "$SUMMARY" ] || die "--publish needs --summary \"<text>\" (a PR summary is never invented)"
|
|
221
|
+
fi
|
|
222
|
+
|
|
223
|
+
ARGS_NL=""
|
|
224
|
+
[ "${#AGENT_ARGS[@]}" -gt 0 ] && ARGS_NL="$(printf '%s\n' "${AGENT_ARGS[@]}")"
|
|
225
|
+
AL_MODE=json; [ "$RECORD_SKILLS" = "1" ] && AL_MODE=events
|
|
226
|
+
AGENT_CMD="$(al_headless_cmd "$AGENT" "$AL_MODE" "$ARGS_NL")" || exit 2
|
|
227
|
+
# No reader is in a headless run: `cckit page` in the agent's shell reads this and prints to the
|
|
228
|
+
# terminal instead of opening a review page (#451).
|
|
229
|
+
export CCKIT_HEADLESS=1
|
|
230
|
+
|
|
231
|
+
if [ "$DRYRUN" = "1" ]; then
|
|
232
|
+
echo "autopilot run (dry-run): branch $BRANCH${ISSUE:+ (issue #$ISSUE)} in $WORKTREE"
|
|
233
|
+
echo " agent : $AGENT_CMD < prompt on stdin"
|
|
234
|
+
echo " limits : max-iters $MAX_ITERS · max-seconds $MAX_SECONDS · round-seconds $ROUND_SECONDS · max-tokens ${MAX_TOKENS:-none}"
|
|
235
|
+
echo " until : ${UNTIL:-<the agent exits 0 after a round that changed something>}"
|
|
236
|
+
echo " check : ${CHECK:-<none>}"
|
|
237
|
+
echo " publish : $([ -n "$PUBLISH" ] && echo "cckit pr $ISSUE" || echo no)"
|
|
238
|
+
[ "$RECORD_SKILLS" = "1" ] && echo " skills : recorded from the agent CLI's event output"
|
|
239
|
+
echo " state : $STATE"
|
|
240
|
+
exit 0
|
|
241
|
+
fi
|
|
242
|
+
command -v "$AGENT" >/dev/null 2>&1 || die "agent CLI '$AGENT' is not on PATH"
|
|
243
|
+
|
|
244
|
+
mkdir -p "$SDIR" || die "cannot create $SDIR"
|
|
245
|
+
STARTED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
246
|
+
T0="$(date +%s)"
|
|
247
|
+
ROUNDS="$PREV_ROUNDS"
|
|
248
|
+
DETAIL=""
|
|
249
|
+
# 1 from the moment a round is numbered until its usage is counted. A stop in between (a signal)
|
|
250
|
+
# counts the round first, so the record never holds a total that silently leaves a round out.
|
|
251
|
+
ROUND_OPEN=0
|
|
252
|
+
|
|
253
|
+
elapsed() { echo $(( PREV_ELAPSED + $(date +%s) - T0 )); }
|
|
254
|
+
tokens() { if [ "$TOK_KNOWN" = "1" ] && [ "$ROUNDS" -gt 0 ]; then echo $(( TOK_IN + TOK_OUT )); else echo unknown; fi; }
|
|
255
|
+
|
|
256
|
+
# save <status> <reason> — the durable record. Written through a temp file and renamed, so a kill
|
|
257
|
+
# mid-write leaves the previous record whole instead of a truncated one.
|
|
258
|
+
save() {
|
|
259
|
+
local st="$1" reason="$2" tmpf tok cost
|
|
260
|
+
tok="$(tokens)"
|
|
261
|
+
if [ "$COST_KNOWN" = "1" ] && [ "$ROUNDS" -gt 0 ] && [ "$USAGE_SRC" != "none" ]; then cost="$COST"; else cost=unknown; fi
|
|
262
|
+
tmpf="$STATE.tmp.$$"
|
|
263
|
+
jq -n \
|
|
264
|
+
--arg run "$KEY" --arg issue "$ISSUE" --arg branch "$BRANCH" --arg worktree "$WORKTREE" \
|
|
265
|
+
--arg agent "$AGENT" --arg args "$ARGS_NL" --arg objective "$OBJECTIVE" \
|
|
266
|
+
--arg until "$UNTIL" --arg check "$CHECK" --arg summary "$SUMMARY" --arg publish "${PUBLISH:-0}" \
|
|
267
|
+
--arg status "$st" --arg reason "$reason" --arg detail "$DETAIL" \
|
|
268
|
+
--argjson rounds "$ROUNDS" --argjson elapsed "$(elapsed)" \
|
|
269
|
+
--argjson mi "$MAX_ITERS" --argjson ms "$MAX_SECONDS" --argjson rs "$ROUND_SECONDS" --arg mt "$MAX_TOKENS" \
|
|
270
|
+
--arg tok "$tok" --argjson tin "$TOK_IN" --argjson tout "$TOK_OUT" --arg cost "$cost" --arg kcost "$COST" \
|
|
271
|
+
--arg src "$USAGE_SRC" --arg pr "$PR_URL" --arg pid "$$" --arg host "$(hostname 2>/dev/null)" \
|
|
272
|
+
--arg started "$STARTED_AT" --arg updated "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg open "$ROUND_OPEN" \
|
|
273
|
+
--arg skon "$RECORD_SKILLS" --arg sklist "$SK_LIST" --arg skknown "$SK_KNOWN" '
|
|
274
|
+
def num: if . == "unknown" or . == "" then "unknown" else (tonumber * 1000000 | round / 1000000) end;
|
|
275
|
+
{ run: $run, issue: $issue, branch: $branch, worktree: $worktree,
|
|
276
|
+
agent: $agent, agent_args: ($args | split("\n") | map(select(. != ""))),
|
|
277
|
+
objective: $objective, until: $until, check: $check,
|
|
278
|
+
publish: ($publish == "1"), summary: $summary,
|
|
279
|
+
status: $status, reason: $reason, detail: $detail,
|
|
280
|
+
rounds: $rounds, round_open: ($open == "1"), elapsed_seconds: $elapsed,
|
|
281
|
+
limits: { max_iters: $mi, max_seconds: $ms, round_seconds: $rs,
|
|
282
|
+
max_tokens: (if $mt == "" then null else ($mt | tonumber) end) },
|
|
283
|
+
usage: { tokens: ($tok | num), known_input_tokens: $tin, known_output_tokens: $tout,
|
|
284
|
+
cost_usd: ($cost | num), known_cost_usd: ($kcost | num), source: $src },
|
|
285
|
+
# null without --record-skills. `complete` is false until a round ran, and after any round
|
|
286
|
+
# whose output held no event: `loaded` is then a partial list.
|
|
287
|
+
skills: (if $skon == "1"
|
|
288
|
+
then { loaded: ($sklist | split("\n") | map(select(. != "")) | unique),
|
|
289
|
+
complete: ($skknown == "1" and $rounds > 0), source: $agent }
|
|
290
|
+
else null end),
|
|
291
|
+
pr_url: $pr, pid: ($pid | tonumber), host: $host,
|
|
292
|
+
started_at: $started, updated_at: $updated,
|
|
293
|
+
resume: (if $reason == "done" or $status == "running" then "" else "cckit autopilot run --resume" end) }' \
|
|
294
|
+
> "$tmpf" && mv -f "$tmpf" "$STATE"
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
# account_round <agent> <round> — add what the runtime printed for one round to the totals. A
|
|
298
|
+
# round whose output holds no usage makes the total unknown: the tokens it spent are real and
|
|
299
|
+
# uncounted, so a sum without them is an undercount, not a figure.
|
|
300
|
+
account_round() {
|
|
301
|
+
local u_in u_out u_cost
|
|
302
|
+
read -r u_in u_out u_cost <<< "$(al_usage "$1" "$SDIR/$KEY.round-$2.out")"
|
|
303
|
+
if is_uint "$u_in" && is_uint "$u_out"; then
|
|
304
|
+
TOK_IN=$((TOK_IN + u_in)); TOK_OUT=$((TOK_OUT + u_out)); USAGE_SRC="$1"
|
|
305
|
+
else
|
|
306
|
+
TOK_KNOWN=0
|
|
307
|
+
fi
|
|
308
|
+
if [ "$u_cost" = "unknown" ]; then COST_KNOWN=0
|
|
309
|
+
else COST="$(awk -v a="$COST" -v b="$u_cost" 'BEGIN{printf "%.6f", a + b}')"; fi
|
|
310
|
+
if [ "$RECORD_SKILLS" = "1" ]; then
|
|
311
|
+
local sk
|
|
312
|
+
if sk="$(al_skills "$1" "$SDIR/$KEY.round-$2.out")"; then
|
|
313
|
+
[ -z "$sk" ] || SK_LIST="${SK_LIST:+$SK_LIST
|
|
314
|
+
}$sk"
|
|
315
|
+
else
|
|
316
|
+
SK_KNOWN=0
|
|
317
|
+
fi
|
|
318
|
+
fi
|
|
319
|
+
ROUND_OPEN=0
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
# The round a dead runner left open (SIGKILL, power loss: no trap ran). Counted here, once, from
|
|
323
|
+
# the output file it left; the state written next carries round_open=false, so a second resume
|
|
324
|
+
# does not count it again.
|
|
325
|
+
[ -z "$PREV_OPEN_AGENT" ] || account_round "$PREV_OPEN_AGENT" "$PREV_ROUNDS"
|
|
326
|
+
|
|
327
|
+
# stop <reason> <exit-code> — the one way a run ends.
|
|
328
|
+
stop() {
|
|
329
|
+
save stopped "$1"
|
|
330
|
+
echo "autopilot run: stopped - reason=$1 rounds=$ROUNDS elapsed=$(elapsed)s tokens=$(tokens)${DETAIL:+ ($DETAIL)}"
|
|
331
|
+
echo "autopilot run: state $STATE"
|
|
332
|
+
[ "$1" = "done" ] || echo "autopilot run: resume with: cckit autopilot run --resume"
|
|
333
|
+
exit "$2"
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
on_signal() {
|
|
337
|
+
trap '' INT TERM HUP
|
|
338
|
+
al_stop
|
|
339
|
+
# The round in flight is over now; count it before the record is written. Skipping this left
|
|
340
|
+
# the interrupted round out of the total, and `--max-tokens` kept passing after a resume.
|
|
341
|
+
[ "$ROUND_OPEN" != "1" ] || account_round "$AGENT" "$ROUNDS"
|
|
342
|
+
DETAIL="this process received a signal during round $ROUNDS"
|
|
343
|
+
stop interrupted 130
|
|
344
|
+
}
|
|
345
|
+
trap on_signal INT TERM HUP
|
|
346
|
+
|
|
347
|
+
# fingerprint — HEAD plus the working tree. Two equal fingerprints around a round mean the round
|
|
348
|
+
# produced nothing a reviewer could read, whatever the agent printed.
|
|
349
|
+
fingerprint() {
|
|
350
|
+
{ git rev-parse HEAD 2>/dev/null; git status --porcelain 2>/dev/null; git diff 2>/dev/null; } | cksum
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
# run_cmd <label> <command> — a completion check or gate, bounded like a round, output kept.
|
|
354
|
+
run_cmd() {
|
|
355
|
+
al_run "$ROUND_SECONDS" "$2" </dev/null > "$SDIR/$KEY.$1.out" 2>&1
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
publish() {
|
|
359
|
+
[ -n "$PUBLISH" ] || return 0
|
|
360
|
+
if [ -n "$PR_URL" ]; then echo "autopilot run: PR already recorded - $PR_URL"; return 0; fi
|
|
361
|
+
local existing
|
|
362
|
+
# A read, so a run killed between `gh pr create` and the state write still finds its PR.
|
|
363
|
+
existing="$(gh pr list --head "$BRANCH" --state open --json url --jq '.[0].url // ""' 2>/dev/null)" || existing=""
|
|
364
|
+
if [ -n "$existing" ]; then
|
|
365
|
+
PR_URL="$existing"; echo "autopilot run: the branch already has an open PR - $PR_URL"; return 0
|
|
366
|
+
fi
|
|
367
|
+
local out
|
|
368
|
+
out="$("$ROOT/bin/cckit" pr "$ISSUE" "$SUMMARY" 2>&1)" || { DETAIL="cckit pr failed: $(printf '%s' "$out" | tail -n 3 | tr '\n' ' ')"; return 1; }
|
|
369
|
+
PR_URL="$(printf '%s\n' "$out" | grep -oE 'https?://[^ ]+/pull/[0-9]+' | tail -n 1)"
|
|
370
|
+
echo "autopilot run: opened ${PR_URL:-a PR (url not parsed)}"
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
finish() {
|
|
374
|
+
if [ -n "$CHECK" ]; then
|
|
375
|
+
run_cmd check "$CHECK" || { DETAIL="--check exited $? - output in $SDIR/$KEY.check.out"; stop check-failed 6; }
|
|
376
|
+
fi
|
|
377
|
+
publish || stop publish-failed 7
|
|
378
|
+
stop done 0
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
echo "autopilot run: $BRANCH${ISSUE:+ (issue #$ISSUE)} · agent $AGENT · max-iters $MAX_ITERS · max-seconds $MAX_SECONDS · max-tokens ${MAX_TOKENS:-none}"
|
|
382
|
+
save running ""
|
|
383
|
+
|
|
384
|
+
# The stop condition may already hold (a resumed run whose last round finished the work, or an
|
|
385
|
+
# objective that was done before it started). Asking costs one command, not one agent round.
|
|
386
|
+
if [ -n "$UNTIL" ] && run_cmd until "$UNTIL"; then
|
|
387
|
+
DETAIL="--until already passed before round $((ROUNDS + 1))"
|
|
388
|
+
# A first run that ends here did nothing (#496): say so, because exit 0 with rounds=0 reads as
|
|
389
|
+
# "the work is done". --until is a stop condition; the flag for a gate on the work is --check.
|
|
390
|
+
if [ "$ROUNDS" -eq 0 ]; then
|
|
391
|
+
echo "autopilot run: --until already passes, so no round ran and nothing was changed." >&2
|
|
392
|
+
echo "autopilot run: --until is the stop condition. For a gate the work must pass after a round, use --check \"<cmd>\"." >&2
|
|
393
|
+
fi
|
|
394
|
+
finish
|
|
395
|
+
fi
|
|
396
|
+
|
|
397
|
+
FEEDBACK="" UNTIL_FAILED=0
|
|
398
|
+
while :; do
|
|
399
|
+
[ "$ROUNDS" -lt "$MAX_ITERS" ] || { DETAIL="$ROUNDS of $MAX_ITERS rounds used"; stop limit-iters 4; }
|
|
400
|
+
left=$(( MAX_SECONDS - $(elapsed) ))
|
|
401
|
+
[ "$left" -gt 0 ] || { DETAIL="$(elapsed)s of ${MAX_SECONDS}s used"; stop limit-seconds 4; }
|
|
402
|
+
if [ -n "$MAX_TOKENS" ] && [ "$ROUNDS" -gt 0 ]; then
|
|
403
|
+
[ "$TOK_KNOWN" = "1" ] || { DETAIL="--max-tokens $MAX_TOKENS cannot be checked: a round reported no usage"; stop usage-unknown 4; }
|
|
404
|
+
[ $(( TOK_IN + TOK_OUT )) -lt "$MAX_TOKENS" ] || { DETAIL="$(( TOK_IN + TOK_OUT )) of $MAX_TOKENS tokens used"; stop limit-tokens 4; }
|
|
405
|
+
fi
|
|
406
|
+
|
|
407
|
+
ROUNDS=$((ROUNDS + 1)); ROUND_OPEN=1
|
|
408
|
+
bound="$ROUND_SECONDS"; [ "$left" -lt "$bound" ] && bound="$left"
|
|
409
|
+
{
|
|
410
|
+
printf '%s\n\n' "$OBJECTIVE"
|
|
411
|
+
cat <<EOF
|
|
412
|
+
You are running HEADLESS in $WORKTREE on branch $BRANCH: no human is in this session to answer a
|
|
413
|
+
question, so decide within what the repository shows. This is round $ROUNDS of at most $MAX_ITERS.
|
|
414
|
+
Commit your work on this branch as you go. Do not push, open a pull request, merge, or switch
|
|
415
|
+
branches: cckit publishes the branch after its own checks pass.
|
|
416
|
+
EOF
|
|
417
|
+
[ -n "$UNTIL" ] && printf '\nThe run ends when this command exits 0:\n %s\n' "$UNTIL"
|
|
418
|
+
[ "$UNTIL_FAILED" = "1" ] && printf '\nIt failed after the previous round.%s\n' "${FEEDBACK:+ Its last output:
|
|
419
|
+
$FEEDBACK}"
|
|
420
|
+
} > "$SDIR/$KEY.prompt"
|
|
421
|
+
save running ""
|
|
422
|
+
# Taken after this round's own files are written, so only the agent's work can move it.
|
|
423
|
+
before="$(fingerprint)"
|
|
424
|
+
|
|
425
|
+
echo "autopilot run: round $ROUNDS (bound ${bound}s)"
|
|
426
|
+
al_run "$bound" "$AGENT_CMD" < "$SDIR/$KEY.prompt" > "$SDIR/$KEY.round-$ROUNDS.out" 2> "$SDIR/$KEY.round-$ROUNDS.err"
|
|
427
|
+
arc=$?
|
|
428
|
+
|
|
429
|
+
# Usage first, so a round that failed or was killed still counts what it reported.
|
|
430
|
+
account_round "$AGENT" "$ROUNDS"
|
|
431
|
+
|
|
432
|
+
if [ "$arc" = "124" ]; then
|
|
433
|
+
DETAIL="round $ROUNDS hit its ${bound}s bound and was killed"; stop limit-seconds 4
|
|
434
|
+
elif [ "$arc" -gt 128 ]; then
|
|
435
|
+
DETAIL="the agent died on signal $((arc - 128)) in round $ROUNDS"; stop interrupted 130
|
|
436
|
+
elif [ "$arc" != "0" ]; then
|
|
437
|
+
DETAIL="the agent exited $arc in round $ROUNDS - stderr in $SDIR/$KEY.round-$ROUNDS.err"; stop agent-failed 3
|
|
438
|
+
fi
|
|
439
|
+
|
|
440
|
+
if [ -n "$UNTIL" ]; then
|
|
441
|
+
if run_cmd until "$UNTIL"; then DETAIL="--until passed after round $ROUNDS"; finish; fi
|
|
442
|
+
UNTIL_FAILED=1; FEEDBACK="$(tail -n 40 "$SDIR/$KEY.until.out" 2>/dev/null)"
|
|
443
|
+
fi
|
|
444
|
+
if [ "$(fingerprint)" = "$before" ]; then
|
|
445
|
+
DETAIL="round $ROUNDS changed neither HEAD nor the working tree"; stop no-progress 5
|
|
446
|
+
fi
|
|
447
|
+
if [ -z "$UNTIL" ]; then DETAIL="the agent exited 0 after round $ROUNDS"; finish; fi
|
|
448
|
+
done
|
|
@@ -41,6 +41,14 @@ for agent in claude codex; do
|
|
|
41
41
|
has "$out" 'would launch 2 flow(s): 3 4'
|
|
42
42
|
has "$out" "agent '$agent'"
|
|
43
43
|
done
|
|
44
|
+
# #352: a KIT_BASE_BRANCH from the environment reaches orchestrate, and the banner says so. Without
|
|
45
|
+
# one the banner names the config's base and carries no override line.
|
|
46
|
+
out="$(KIT_BASE_BRANCH=effort/9-x run 3)"
|
|
47
|
+
has "$out" '(base effort/9-x)'
|
|
48
|
+
has "$out" "base 'effort/9-x' comes from KIT_BASE_BRANCH in the environment (the config says 'develop')"
|
|
49
|
+
out="$(env -u KIT_BASE_BRANCH bash "$TMP/install/scripts/autopilot.sh" --dry-run 3)"
|
|
50
|
+
has "$out" '(base develop)'
|
|
51
|
+
case "$out" in *'comes from KIT_BASE_BRANCH'*) echo 'FAIL override line printed with no override'; exit 1 ;; esac
|
|
44
52
|
out="$(run --cap 1)"; has "$out" 'would launch 1 flow(s): 3'; has "$out" 'queued past cap (run a later wave): 4'
|
|
45
53
|
out="$(BLOCKER_STATE=CLOSED run 3)"; has "$out" 'would launch 1 flow(s): 3'
|
|
46
54
|
export BLOCKER_STATE=OPEN
|
package/scripts/autopilot.sh
CHANGED
|
@@ -14,15 +14,24 @@
|
|
|
14
14
|
# cckit autopilot --profile build # drive a declared agent profile (kind + argv)
|
|
15
15
|
# cckit autopilot --runtime herdr # run the selected agents in Herdr
|
|
16
16
|
# cckit autopilot --dry-run # print the plan, launch nothing
|
|
17
|
+
# cckit autopilot run [<issue>] --objective "<text>" [--until "<cmd>"] [--max-iters N] ...
|
|
18
|
+
# # ONE bounded headless objective on the current branch
|
|
19
|
+
# # (claude -p / codex exec); see `cckit autopilot run --help`
|
|
17
20
|
set -euo pipefail
|
|
18
21
|
|
|
22
|
+
# `run` is the headless, bounded objective - a different engine from the pane launcher below.
|
|
23
|
+
if [ "${1:-}" = "run" ]; then
|
|
24
|
+
shift
|
|
25
|
+
exec bash "$(cd "$(dirname "$0")" && pwd)/autopilot-run.sh" "$@"
|
|
26
|
+
fi
|
|
27
|
+
|
|
19
28
|
PASS=() # flags forwarded to orchestrate
|
|
20
29
|
ISSUES=()
|
|
21
30
|
while [ "$#" -gt 0 ]; do
|
|
22
31
|
case "$1" in
|
|
23
32
|
--cap|--agent|--profile|--runtime) PASS+=("$1" "$2"); shift 2 ;;
|
|
24
33
|
--cap=*|--agent=*|--profile=*|--runtime=*|--dry-run|--no-seed|--force|--session=*) PASS+=("$1"); shift ;;
|
|
25
|
-
-h|--help) sed -n '2,
|
|
34
|
+
-h|--help) sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
26
35
|
[0-9]*) ISSUES+=("$1"); shift ;;
|
|
27
36
|
*) echo "autopilot: unknown arg '$1'" >&2; exit 2 ;;
|
|
28
37
|
esac
|
|
@@ -27,6 +27,14 @@ printf '%s\n' '{"id":"q1","claim":"Summarize releasing.","must":["version bumped
|
|
|
27
27
|
|
|
28
28
|
export BENCH_DIR="$FIX/bench"
|
|
29
29
|
|
|
30
|
+
# ---- 0. a live backend that reads stdin must not swallow the remaining records ----
|
|
31
|
+
# The real `claude -p` reads stdin. The runners loop with `while read … done < <(records)`, so a
|
|
32
|
+
# child inheriting that stdin drained it and each set scored only its first record.
|
|
33
|
+
STUB="$FIX/stub"; mkdir -p "$STUB"
|
|
34
|
+
printf '%s\n' '#!/bin/sh' 'cat >/dev/null' 'echo NONE' > "$STUB/claude"; chmod +x "$STUB/claude"
|
|
35
|
+
n="$(PATH="$STUB:$PATH" BENCH_BACKEND=claude bash "$HERE/run.sh" --set "$FIX/bench/retrieval.jsonl" --json 2>/dev/null | jq -r '.total')"
|
|
36
|
+
t "a stdin-reading backend still runs every record" "$n" "2"
|
|
37
|
+
|
|
30
38
|
# ---- 1. --dry on well-formed data passes -----------------------------------
|
|
31
39
|
bash "$HERE/run.sh" --dry >/dev/null 2>&1; t "run --dry well-formed" "$?" "0"
|
|
32
40
|
bash "$HERE/run-quality.sh" --dry >/dev/null 2>&1; t "quality --dry well-formed" "$?" "0"
|
|
@@ -79,5 +87,82 @@ bash "$HERE/report.sh" --dry --out "$FIX/RESULTS.md" >/dev/null 2>&1
|
|
|
79
87
|
t "report wrote RESULTS.md" "$([ -s "$FIX/RESULTS.md" ] && echo yes)" "yes"
|
|
80
88
|
grep -q "Documentation benchmark" "$FIX/RESULTS.md"; t "report has heading" "$?" "0"
|
|
81
89
|
|
|
90
|
+
# ---- 10. live report keeps every number on one line (#252) -------------------
|
|
91
|
+
# run.sh exits 1 on this fixture (1 pass / 2 fail, section 5). report.sh used to append a second
|
|
92
|
+
# JSON document on that exit, so each number it read came back as two lines ("33\n0%").
|
|
93
|
+
rm -f "$FIX/RESULTS.md"
|
|
94
|
+
rep_out="$(BENCH_BACKEND=mock bash "$HERE/report.sh" --out "$FIX/RESULTS.md" 2>/dev/null)"
|
|
95
|
+
grep -q 'Retrieval score: 33%\*\* — of 3 questions' "$FIX/RESULTS.md"; t "live report: score + total on one line" "$?" "0"
|
|
96
|
+
grep -q '\*\*1\*\* times' "$FIX/RESULTS.md"; t "live report: pass count on one line" "$?" "0"
|
|
97
|
+
grep -qE '^0(%|\*\*| questions)' "$FIX/RESULTS.md"; t "live report: no number split over a newline" "$?" "1"
|
|
98
|
+
t "live report: stdout summary is one line" "$(printf '%s\n' "$rep_out" | wc -l | tr -d ' ')" "1"
|
|
99
|
+
case "$rep_out" in *"retrieval 33%"*) rc=0 ;; *) rc=1 ;; esac; t "live report: stdout carries 33%" "$rc" "0"
|
|
100
|
+
|
|
101
|
+
# ---- 11. a tier that prints nothing still reports zeros, not a crash ---------
|
|
102
|
+
# No quality set on disk: run-quality.sh exits non-zero with no JSON; the report falls back to {}.
|
|
103
|
+
mv "$FIX/bench/quality.jsonl" "$FIX/bench/quality.jsonl.off"
|
|
104
|
+
BENCH_BACKEND=mock bash "$HERE/report.sh" --out "$FIX/RESULTS.md" >/dev/null 2>&1; t "report without quality set exits 0" "$?" "0"
|
|
105
|
+
grep -q 'Retrieval score: 33%\*\* — of 3 questions' "$FIX/RESULTS.md"; t "report without quality set keeps headline" "$?" "0"
|
|
106
|
+
grep -q 'Answer quality' "$FIX/RESULTS.md"; t "report without quality set omits quality line" "$?" "1"
|
|
107
|
+
mv "$FIX/bench/quality.jsonl.off" "$FIX/bench/quality.jsonl"
|
|
108
|
+
|
|
109
|
+
# ---- 12. the quality tier grades a full answer, not a path --------------------
|
|
110
|
+
# run-quality.sh used to call bench_ask, which returns ONE path (the last non-empty line of the
|
|
111
|
+
# reply). A path covers no rubric point, so every claim scored 0 whatever the docs said. The stub
|
|
112
|
+
# answers in two lines and its judge returns 1 only when both lines reached it.
|
|
113
|
+
QSTUB="$FIX/qstub"; mkdir -p "$QSTUB"
|
|
114
|
+
cat > "$QSTUB/claude" <<'STUBEOF'
|
|
115
|
+
#!/bin/sh
|
|
116
|
+
cat >/dev/null
|
|
117
|
+
case "$2" in
|
|
118
|
+
*"Grade an answer"*) case "$2" in *"line one"*"line two"*) echo 1 ;; *) echo 0 ;; esac ;;
|
|
119
|
+
*"answering a question"*) printf 'line one\nline two\n' ;;
|
|
120
|
+
*) echo NONE ;;
|
|
121
|
+
esac
|
|
122
|
+
STUBEOF
|
|
123
|
+
chmod +x "$QSTUB/claude"
|
|
124
|
+
q_mean="$(PATH="$QSTUB:$PATH" BENCH_BACKEND=claude bash "$HERE/run-quality.sh" --json --answers "$FIX/answers" 2>/dev/null | jq -r '.mean == 1')"
|
|
125
|
+
t "quality: the judge sees the whole answer" "$q_mean" "true"
|
|
126
|
+
t "quality: --answers keeps the graded answer" "$(wc -l < "$FIX/answers/q1.txt" 2>/dev/null | tr -d ' ')" "2"
|
|
127
|
+
t "quality: --answers keeps the judge's reply" "$(cat "$FIX/answers/q1.judge.txt" 2>/dev/null)" "1"
|
|
128
|
+
|
|
129
|
+
# An empty answer (backend failed or timed out) scores 0 and never reaches the judge.
|
|
130
|
+
cat > "$QSTUB/claude" <<'STUBEOF'
|
|
131
|
+
#!/bin/sh
|
|
132
|
+
cat >/dev/null
|
|
133
|
+
case "$2" in *"Grade an answer"*) echo 1 ;; esac
|
|
134
|
+
STUBEOF
|
|
135
|
+
q_mean="$(PATH="$QSTUB:$PATH" BENCH_BACKEND=claude bash "$HERE/run-quality.sh" --json 2>/dev/null | jq -r '.mean == 0 and .count == 1')"
|
|
136
|
+
t "quality: an empty answer scores 0" "$q_mean" "true"
|
|
137
|
+
|
|
138
|
+
# --answers with no directory is refused. It used to loop forever: `shift 2` with one argument left
|
|
139
|
+
# shifts nothing, so the parser saw --answers again. The watchdog turns a regression into a failure.
|
|
140
|
+
perl -e 'alarm 20; exec @ARGV' bash "$HERE/run-quality.sh" --dry --answers >/dev/null 2>&1
|
|
141
|
+
t "quality: --answers without a directory exits 2" "$?" "2"
|
|
142
|
+
bash "$HERE/run-quality.sh" --dry --answers= >/dev/null 2>&1
|
|
143
|
+
t "quality: an empty --answers= exits 2" "$?" "2"
|
|
144
|
+
# The empty-answer run above wrote into no directory; with one, a judge reply left by an earlier run
|
|
145
|
+
# is removed, because this run's answer never reached the judge.
|
|
146
|
+
PATH="$QSTUB:$PATH" BENCH_BACKEND=claude bash "$HERE/run-quality.sh" --json --answers "$FIX/answers" >/dev/null 2>&1
|
|
147
|
+
[ ! -e "$FIX/answers/q1.judge.txt" ]; t "quality: a stale judge reply is removed" "$?" "0"
|
|
148
|
+
|
|
149
|
+
# ---- 13. cckit's own sets point at pages that exist --------------------------
|
|
150
|
+
# benchmarks/ scores cckit's own docs. A renamed or deleted page turns its questions into
|
|
151
|
+
# guaranteed failures that read as a retrieval regression, so the paths are checked offline here.
|
|
152
|
+
REPO="$(cd "$HERE/../.." && pwd)"
|
|
153
|
+
# Only in cckit's own checkout: a consuming project's sets use paths relative to its knowledge dir.
|
|
154
|
+
if [ -f "$REPO/bin/cckit" ] && [ -f "$REPO/benchmarks/benchmark.config.json" ]; then
|
|
155
|
+
missing="$(cd "$REPO" && for f in benchmarks/*.jsonl; do
|
|
156
|
+
grep -vE '^[[:space:]]*(#|$)' "$f" | jq -r '[.expect // empty, .source // empty] | flatten | .[]'
|
|
157
|
+
done | grep -v '^NONE$' | sort -u | while IFS= read -r p; do [ -f "$p" ] || printf '%s\n' "$p"; done)"
|
|
158
|
+
t "own sets: every expect/source path exists" "$missing" ""
|
|
159
|
+
dupes="$(cd "$REPO" && cat benchmarks/*.jsonl | grep -vE '^[[:space:]]*(#|$)' | jq -r '.id' | sort | uniq -d)"
|
|
160
|
+
t "own sets: ids are unique" "$dupes" ""
|
|
161
|
+
(cd "$REPO" && BENCH_DIR="$REPO/benchmarks" bash "$HERE/run.sh" --dry >/dev/null 2>&1); t "own sets: run --dry" "$?" "0"
|
|
162
|
+
(cd "$REPO" && BENCH_DIR="$REPO/benchmarks" bash "$HERE/run-quality.sh" --dry >/dev/null 2>&1); t "own sets: quality --dry" "$?" "0"
|
|
163
|
+
nosrc="$(cd "$REPO" && grep -vE '^[[:space:]]*(#|$)' benchmarks/quality.jsonl 2>/dev/null | jq -r 'select((.source // "") == "") | .id')"
|
|
164
|
+
t "own sets: every quality record cites its source page" "$nosrc" ""
|
|
165
|
+
fi
|
|
166
|
+
|
|
82
167
|
[ "$fail" -eq 0 ] && echo "ALL OK" || echo "SOME FAILED"
|
|
83
168
|
exit "$fail"
|