@jeiemgi/cckit 0.8.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 +505 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +189 -20
- 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/guard-raw-git-ops-test.sh +8 -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 +188 -35
- package/scripts/lib/effort-ops-test.sh +217 -7
- package/scripts/lib/effort-ops.sh +281 -49
- 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-slug.sh +16 -2
- package/scripts/lib/effort.sh +67 -12
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +37 -16
- package/scripts/lib/gh-rest-test.sh +330 -0
- package/scripts/lib/gh-rest.sh +304 -0
- 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 +244 -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 +362 -89
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
- 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/test-env-test.sh +3 -3
- package/scripts/lib/test-env.sh +7 -4
- 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 +93 -9
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +169 -32
- 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 +27 -14
- 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,369 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# review-page.sh — plans, decisions and grilling rounds open as a review page (#451).
|
|
4
|
+
#
|
|
5
|
+
# The page tool is an integration (integrations/lavish.json, `reviewPages.enabled`, ON by default).
|
|
6
|
+
# This file is the `cckit page` verb: it decides whether THIS session can show a page, opens one
|
|
7
|
+
# through the tool when it can, prints to the terminal when it cannot, and writes the reader's
|
|
8
|
+
# answer where the project keeps its record.
|
|
9
|
+
#
|
|
10
|
+
# A page needs a reader with a browser. rp_mode answers `page` or `terminal<TAB><reason>`, and the
|
|
11
|
+
# first rule below that holds decides:
|
|
12
|
+
# 1. CCKIT_PAGES=terminal|off|0|false|no terminal. CCKIT_PAGES=page|on|1|true|yes skips 4-9.
|
|
13
|
+
# 2. the integration is off `reviewPages.enabled` is false in the project config
|
|
14
|
+
# 3. (forced by rule 1: go to 10)
|
|
15
|
+
# 4. CI is set (not `false`/`0`) a CI job has no reader
|
|
16
|
+
# 5. CCKIT_HEADLESS is set (not `0`) an unattended run: `cckit autopilot run` and the tmux
|
|
17
|
+
# wave worker export it
|
|
18
|
+
# 6. a headless Claude Code session CLAUDECODE is set and CLAUDE_CODE_SESSION_ATTENDED is
|
|
19
|
+
# `0` or CLAUDE_CODE_ENTRYPOINT starts with `sdk`
|
|
20
|
+
# (`claude -p` reports `sdk-cli` and `0`)
|
|
21
|
+
# 7. SSH_CONNECTION or SSH_TTY is set the browser would open on the remote host
|
|
22
|
+
# 8. not macOS, and neither DISPLAY nor WAYLAND_DISPLAY is set
|
|
23
|
+
# 9. no agent session and no terminal CLAUDECODE unset and none of fd 0/1/2 is a TTY. An
|
|
24
|
+
# agent's shell tool has no TTY, so inside an attended
|
|
25
|
+
# Claude Code session the TTY is not required
|
|
26
|
+
# 10. no runner neither `lavish-axi` nor `npx` is on PATH
|
|
27
|
+
# Terminal mode is never an error: every verb here exits 0 in it.
|
|
28
|
+
#
|
|
29
|
+
# Source it: source scripts/lib/review-page.sh
|
|
30
|
+
# rp_descriptor the page tool's descriptor path; rc 1 when there is none
|
|
31
|
+
# rp_enabled rc 0 unless the project config turns review pages off
|
|
32
|
+
# rp_runner `lavish-axi`, or `npx -y lavish-axi`; rc 1 when neither exists
|
|
33
|
+
# rp_mode `page`, or `terminal<TAB><reason>`; always rc 0
|
|
34
|
+
# rp_open <html> [<fallback-md>] [tool args…]
|
|
35
|
+
# open the page; in terminal mode, or when the tool exits
|
|
36
|
+
# non-zero, print the fallback file (or a one-line notice). rc 0
|
|
37
|
+
# rp_pass <poll|reply|end> <html> [args…] hand the subcommand to the tool; no-op in terminal mode
|
|
38
|
+
# rp_answer_dest <issue> `issue` or `file`: where an answer is written
|
|
39
|
+
# rp_answer --kind <plan|decision|grill> --title <t> [--issue <n>] [--body-file <f|->]
|
|
40
|
+
# write the answer: a comment on the issue when the project uses
|
|
41
|
+
# GitHub and an issue is named, else a file under
|
|
42
|
+
# `reviewPages.answersDir` (default docs/answers) in the work tree
|
|
43
|
+
# rp_cli <mode|open|poll|reply|end|answer> … the `cckit page` verb
|
|
44
|
+
# Requires: jq. bash 3.2 + zsh compatible.
|
|
45
|
+
# errors: mixed — rp_mode / rp_open / rp_pass in terminal mode always return 0 (falling back is the
|
|
46
|
+
# contract); rp_pass in page mode returns the tool's own status; rp_answer is strict: rc 2 on a
|
|
47
|
+
# usage error, rc 1 when the comment or the file could not be written.
|
|
48
|
+
|
|
49
|
+
_rp_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
50
|
+
# shellcheck source=/dev/null
|
|
51
|
+
. "$_rp_dir/kit-cli.sh" # kit_is_main, kit_say, kit_warn
|
|
52
|
+
# shellcheck source=/dev/null
|
|
53
|
+
. "$_rp_dir/integrations.sh" # integration_file, integration_enabled; sources config-path.sh
|
|
54
|
+
|
|
55
|
+
_rp_tool_id="lavish"
|
|
56
|
+
|
|
57
|
+
_rp_truthy() { case "${1:-}" in ''|0|false|False|FALSE|no|off) return 1 ;; *) return 0 ;; esac; }
|
|
58
|
+
|
|
59
|
+
rp_descriptor() { integration_file "$_rp_tool_id"; }
|
|
60
|
+
|
|
61
|
+
_rp_cfg() { kit_config_path 2>/dev/null || true; }
|
|
62
|
+
|
|
63
|
+
# rp_enabled — on unless the config says otherwise. No project config at all is ON: the default
|
|
64
|
+
# holds in every project, and a directory with no config has not turned anything off.
|
|
65
|
+
rp_enabled() {
|
|
66
|
+
local f cfg
|
|
67
|
+
f="$(rp_descriptor)" || return 1
|
|
68
|
+
cfg="$(_rp_cfg)"
|
|
69
|
+
[ -n "$cfg" ] && [ -f "$cfg" ] || return 0
|
|
70
|
+
integration_enabled "$f" "$cfg"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
rp_runner() {
|
|
74
|
+
if command -v lavish-axi >/dev/null 2>&1; then printf 'lavish-axi\n'; return 0; fi
|
|
75
|
+
if command -v npx >/dev/null 2>&1; then printf 'npx -y lavish-axi\n'; return 0; fi
|
|
76
|
+
return 1
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# _rp_run <args…> — run the page tool with these arguments: the binary when it is on PATH, else
|
|
80
|
+
# through npx. Spelled as two branches because a command held in a variable does not word-split
|
|
81
|
+
# under zsh.
|
|
82
|
+
_rp_run() {
|
|
83
|
+
if command -v lavish-axi >/dev/null 2>&1; then lavish-axi "$@"; else npx -y lavish-axi "$@"; fi
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
rp_mode() {
|
|
87
|
+
local forced=0 cfg
|
|
88
|
+
case "${CCKIT_PAGES:-}" in
|
|
89
|
+
'') ;;
|
|
90
|
+
terminal|off|0|false|no) printf 'terminal\tCCKIT_PAGES=%s\n' "$CCKIT_PAGES"; return 0 ;;
|
|
91
|
+
page|on|1|true|yes) forced=1 ;;
|
|
92
|
+
*) kit_warn "page: CCKIT_PAGES='$CCKIT_PAGES' is neither 'page' nor 'terminal' — ignored" ;;
|
|
93
|
+
esac
|
|
94
|
+
if ! rp_enabled; then
|
|
95
|
+
cfg="$(_rp_cfg)"
|
|
96
|
+
printf 'terminal\treview pages are off (reviewPages.enabled is false in %s)\n' "${cfg:-the project config}"
|
|
97
|
+
return 0
|
|
98
|
+
fi
|
|
99
|
+
if [ "$forced" -eq 0 ]; then
|
|
100
|
+
if _rp_truthy "${CI:-}"; then printf 'terminal\tCI is set: a CI job has no reader\n'; return 0; fi
|
|
101
|
+
if _rp_truthy "${CCKIT_HEADLESS:-}"; then printf 'terminal\tCCKIT_HEADLESS is set: an unattended run\n'; return 0; fi
|
|
102
|
+
if [ -n "${CLAUDECODE:-}" ]; then
|
|
103
|
+
if [ "${CLAUDE_CODE_SESSION_ATTENDED:-}" = "0" ]; then
|
|
104
|
+
printf 'terminal\ta headless Claude Code session (CLAUDE_CODE_SESSION_ATTENDED=0)\n'; return 0
|
|
105
|
+
fi
|
|
106
|
+
case "${CLAUDE_CODE_ENTRYPOINT:-}" in
|
|
107
|
+
sdk*) printf 'terminal\ta headless Claude Code session (CLAUDE_CODE_ENTRYPOINT=%s)\n' "$CLAUDE_CODE_ENTRYPOINT"; return 0 ;;
|
|
108
|
+
esac
|
|
109
|
+
fi
|
|
110
|
+
if [ -n "${SSH_CONNECTION:-}" ] || [ -n "${SSH_TTY:-}" ]; then
|
|
111
|
+
printf 'terminal\tan SSH session: the browser would open on the remote host\n'; return 0
|
|
112
|
+
fi
|
|
113
|
+
if [ "$(uname -s 2>/dev/null)" != "Darwin" ] && [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
|
|
114
|
+
printf 'terminal\tno display: neither DISPLAY nor WAYLAND_DISPLAY is set\n'; return 0
|
|
115
|
+
fi
|
|
116
|
+
if [ -z "${CLAUDECODE:-}" ] && ! [ -t 0 ] && ! [ -t 1 ] && ! [ -t 2 ]; then
|
|
117
|
+
printf 'terminal\tno terminal and no attended agent session (set CCKIT_PAGES=page to open one anyway)\n'; return 0
|
|
118
|
+
fi
|
|
119
|
+
fi
|
|
120
|
+
if ! rp_runner >/dev/null; then
|
|
121
|
+
printf 'terminal\tneither lavish-axi nor npx is on PATH\n'; return 0
|
|
122
|
+
fi
|
|
123
|
+
printf 'page\n'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_rp_json() { [ "${CCKIT_OUTPUT:-human}" = "json" ]; }
|
|
127
|
+
|
|
128
|
+
# _rp_ignore_dir <html> — keep the page directory out of `git status`. When the page sits in a
|
|
129
|
+
# `.lavish/` directory of a git work tree and git does not already ignore it, one `.lavish/` line
|
|
130
|
+
# goes into the repository's local exclude file (info/exclude: never tracked, never pushed).
|
|
131
|
+
_rp_ignore_dir() {
|
|
132
|
+
local d ex
|
|
133
|
+
d="$(CDPATH='' cd -- "$(dirname -- "$1")" 2>/dev/null && pwd)" || return 0
|
|
134
|
+
[ "$(basename "$d")" = ".lavish" ] || return 0
|
|
135
|
+
git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0
|
|
136
|
+
if git -C "$d" check-ignore -q "$d" 2>/dev/null; then return 0; fi
|
|
137
|
+
ex="$(git -C "$d" rev-parse --path-format=absolute --git-path info/exclude 2>/dev/null)" || return 0
|
|
138
|
+
[ -n "$ex" ] || return 0
|
|
139
|
+
mkdir -p "$(dirname "$ex")" 2>/dev/null || return 0
|
|
140
|
+
printf '.lavish/\n' >> "$ex" 2>/dev/null || true
|
|
141
|
+
return 0
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# _rp_terminal <reason> <html> [<fallback-md>] — the terminal side of rp_open.
|
|
145
|
+
_rp_terminal() {
|
|
146
|
+
local reason="$1" html="$2" fb="${3:-}"
|
|
147
|
+
kit_say "page: terminal output — $reason"
|
|
148
|
+
if _rp_json; then
|
|
149
|
+
jq -cn --arg r "$reason" --arg f "$html" --arg fb "$fb" \
|
|
150
|
+
'{mode: "terminal", reason: $r, file: $f} + (if $fb == "" then {} else {fallback: $fb} end)'
|
|
151
|
+
return 0
|
|
152
|
+
fi
|
|
153
|
+
if [ -n "$fb" ] && [ -f "$fb" ]; then cat "$fb"; return 0; fi
|
|
154
|
+
printf 'terminal: no page was opened (%s). Print the plan, the options or the questions in the terminal.\n' "$reason"
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
rp_open() {
|
|
158
|
+
local html="${1:-}" fb="${2:-}" mode reason runner rc
|
|
159
|
+
[ $# -ge 2 ] && shift 2 || shift $#
|
|
160
|
+
[ -n "$html" ] || { kit_warn "page open: name the HTML file — cckit page open <html-file> [--fallback <md-file>]"; return 2; }
|
|
161
|
+
[ -f "$html" ] || { kit_warn "page open: no file at '$html'"; return 2; }
|
|
162
|
+
if [ -n "$fb" ] && [ ! -f "$fb" ]; then kit_warn "page open: no fallback file at '$fb'"; return 2; fi
|
|
163
|
+
mode="$(rp_mode)"
|
|
164
|
+
if [ "$mode" != "page" ]; then
|
|
165
|
+
reason="${mode#* }"
|
|
166
|
+
_rp_terminal "$reason" "$html" "$fb"
|
|
167
|
+
return 0
|
|
168
|
+
fi
|
|
169
|
+
runner="$(rp_runner)"
|
|
170
|
+
_rp_ignore_dir "$html"
|
|
171
|
+
# Under --llm stdout is the one JSON object, so the tool's own output goes to stderr.
|
|
172
|
+
if _rp_json; then _rp_run "$html" "$@" >&2; rc=$?
|
|
173
|
+
else _rp_run "$html" "$@"; rc=$?; fi
|
|
174
|
+
if [ "$rc" -ne 0 ]; then
|
|
175
|
+
_rp_terminal "$runner exited $rc" "$html" "$fb"
|
|
176
|
+
return 0
|
|
177
|
+
fi
|
|
178
|
+
if _rp_json; then jq -cn --arg f "$html" '{mode: "page", file: $f}'; fi
|
|
179
|
+
return 0
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
rp_pass() {
|
|
183
|
+
local sub="${1:-}" html="${2:-}" mode
|
|
184
|
+
[ -n "$html" ] || { kit_warn "page $sub: name the HTML file — cckit page $sub <html-file>"; return 2; }
|
|
185
|
+
shift 2
|
|
186
|
+
mode="$(rp_mode)"
|
|
187
|
+
if [ "$mode" != "page" ]; then
|
|
188
|
+
kit_say "page $sub: nothing to do in terminal mode — ${mode#* }"
|
|
189
|
+
return 0
|
|
190
|
+
fi
|
|
191
|
+
_rp_run "$sub" "$html" "$@"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# ── the answer ─────────────────────────────────────────────────────────────────────────────────
|
|
195
|
+
_rp_cfg_get() { # <jq-path> -> the config value, or empty
|
|
196
|
+
local cfg; cfg="$(_rp_cfg)"
|
|
197
|
+
[ -n "$cfg" ] && [ -f "$cfg" ] || return 0
|
|
198
|
+
jq -r "$1 // \"\"" "$cfg" 2>/dev/null || true
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# rp_answer_dest <issue> -> `issue` or `file`. `reviewPages.answers` decides when it is set
|
|
202
|
+
# (`issue` | `file`); otherwise an answer goes to the issue when the project names a GitHub repo
|
|
203
|
+
# (`github.repo`) and an issue number was given, and to a file in every other case.
|
|
204
|
+
rp_answer_dest() {
|
|
205
|
+
local issue="${1:-}" want repo
|
|
206
|
+
want="$(_rp_cfg_get '.reviewPages.answers')"
|
|
207
|
+
case "$want" in
|
|
208
|
+
issue|file) printf '%s\n' "$want"; return 0 ;;
|
|
209
|
+
'') ;;
|
|
210
|
+
*) kit_warn "page answer: reviewPages.answers='$want' is neither 'issue' nor 'file' — ignored" ;;
|
|
211
|
+
esac
|
|
212
|
+
repo="$(_rp_cfg_get '.github.repo')"
|
|
213
|
+
if [ -n "$repo" ] && [ -n "$issue" ]; then printf 'issue\n'; else printf 'file\n'; fi
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_rp_slug() {
|
|
217
|
+
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9]\{1,\}/-/g' -e 's/^-//' -e 's/-$//' | cut -c1-50 | sed 's/-$//'
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_rp_kind_label() { case "$1" in plan) printf 'Plan' ;; decision) printf 'Decision' ;; grill) printf 'Grill' ;; esac; }
|
|
221
|
+
|
|
222
|
+
rp_answer() {
|
|
223
|
+
local kind="" title="" issue="" bfile="" dest tmp body id marker label repo out dir root rel slug f n today
|
|
224
|
+
while [ $# -gt 0 ]; do
|
|
225
|
+
case "$1" in
|
|
226
|
+
--kind) kind="${2:-}"; [ $# -gt 1 ] && shift ;;
|
|
227
|
+
--title) title="${2:-}"; [ $# -gt 1 ] && shift ;;
|
|
228
|
+
--issue) issue="${2:-}"; [ $# -gt 1 ] && shift ;;
|
|
229
|
+
--body-file) bfile="${2:-}"; [ $# -gt 1 ] && shift ;;
|
|
230
|
+
*) kit_warn "page answer: unknown argument '$1'"; return 2 ;;
|
|
231
|
+
esac
|
|
232
|
+
shift
|
|
233
|
+
done
|
|
234
|
+
case "$kind" in plan|decision|grill) ;; *) kit_warn "page answer: --kind is one of plan, decision, grill"; return 2 ;; esac
|
|
235
|
+
[ -n "$title" ] || { kit_warn "page answer: --title is required"; return 2; }
|
|
236
|
+
issue="${issue#\#}"
|
|
237
|
+
if [ -n "$issue" ]; then
|
|
238
|
+
case "$issue" in *[!0-9]*) kit_warn "page answer: --issue takes an issue number, got '$issue'"; return 2 ;; esac
|
|
239
|
+
fi
|
|
240
|
+
tmp="$(mktemp)" || return 1
|
|
241
|
+
if [ -z "$bfile" ] || [ "$bfile" = "-" ]; then cat > "$tmp"
|
|
242
|
+
elif [ -f "$bfile" ]; then cat "$bfile" > "$tmp"
|
|
243
|
+
else rm -f "$tmp"; kit_warn "page answer: no body file at '$bfile'"; return 2; fi
|
|
244
|
+
if ! grep -q '[^[:space:]]' "$tmp"; then rm -f "$tmp"; kit_warn "page answer: the answer is empty — pass --body-file <file>, or the text on stdin"; return 2; fi
|
|
245
|
+
|
|
246
|
+
dest="$(rp_answer_dest "$issue")"
|
|
247
|
+
if [ "$dest" = "issue" ] && [ -z "$issue" ]; then
|
|
248
|
+
rm -f "$tmp"; kit_warn "page answer: reviewPages.answers is 'issue' — name one with --issue <n>"; return 2
|
|
249
|
+
fi
|
|
250
|
+
# The id is a checksum of what is being recorded, so recording the same answer twice is a no-op.
|
|
251
|
+
id="$( { printf '%s\n%s\n' "$kind" "$title"; cat "$tmp"; } | cksum | awk '{print $1}')"
|
|
252
|
+
marker="<!-- cckit:page-answer kind=$kind id=$id -->"
|
|
253
|
+
label="$(_rp_kind_label "$kind")"
|
|
254
|
+
today="$(date +%Y-%m-%d)"
|
|
255
|
+
body="$(mktemp)" || { rm -f "$tmp"; return 1; }
|
|
256
|
+
|
|
257
|
+
if [ "$dest" = "issue" ]; then
|
|
258
|
+
{ printf '%s\n### %s answer: %s\n\n' "$marker" "$label" "$title"; cat "$tmp"
|
|
259
|
+
printf '\n\n_Recorded from a review page with `cckit page answer`, %s._\n' "$today"; } > "$body"
|
|
260
|
+
repo="$(_rp_cfg_get '.github.repo')"
|
|
261
|
+
if [ -n "$repo" ]; then out="$(gh issue view "$issue" --repo "$repo" --json comments -q '.comments[].body' 2>/dev/null || true)"
|
|
262
|
+
else out="$(gh issue view "$issue" --json comments -q '.comments[].body' 2>/dev/null || true)"; fi
|
|
263
|
+
case "$out" in *"$marker"*)
|
|
264
|
+
rm -f "$tmp" "$body"
|
|
265
|
+
kit_say "page answer: already recorded on #$issue — nothing written"
|
|
266
|
+
if _rp_json; then jq -cn --arg i "$issue" '{ok: true, where: "issue", issue: ($i | tonumber), written: false}'
|
|
267
|
+
else printf 'issue #%s (already recorded)\n' "$issue"; fi
|
|
268
|
+
return 0 ;;
|
|
269
|
+
esac
|
|
270
|
+
if [ -n "$repo" ]; then out="$(gh issue comment "$issue" --repo "$repo" --body-file "$body" 2>&1)"; n=$?
|
|
271
|
+
else out="$(gh issue comment "$issue" --body-file "$body" 2>&1)"; n=$?; fi
|
|
272
|
+
rm -f "$tmp" "$body"
|
|
273
|
+
if [ "$n" -ne 0 ]; then
|
|
274
|
+
kit_warn "page answer: could not comment on #$issue — $out"
|
|
275
|
+
return 1
|
|
276
|
+
fi
|
|
277
|
+
if _rp_json; then jq -cn --arg i "$issue" --arg u "$out" '{ok: true, where: "issue", issue: ($i | tonumber), url: $u, written: true}'
|
|
278
|
+
else printf 'issue #%s %s\n' "$issue" "$out"; fi
|
|
279
|
+
return 0
|
|
280
|
+
fi
|
|
281
|
+
|
|
282
|
+
dir="$(_rp_cfg_get '.reviewPages.answersDir')"; [ -n "$dir" ] || dir="docs/answers"
|
|
283
|
+
case "/$dir/" in
|
|
284
|
+
//*|*/../*) rm -f "$tmp" "$body"; kit_warn "page answer: reviewPages.answersDir must be a path inside the repo, got '$dir'"; return 2 ;;
|
|
285
|
+
esac
|
|
286
|
+
root="$(git rev-parse --show-toplevel 2>/dev/null)" || root="$PWD"
|
|
287
|
+
slug="$(_rp_slug "$title")"; [ -n "$slug" ] || slug="answer"
|
|
288
|
+
rel="$dir/$today-$kind-$slug"
|
|
289
|
+
# The marker is looked up in every file of the directory, not only today's: the file name starts
|
|
290
|
+
# with the date, so the same answer recorded on a later day would otherwise be written twice.
|
|
291
|
+
f=""
|
|
292
|
+
[ -d "$root/$dir" ] && f="$(grep -lF -- "$marker" "$root/$dir"/*.md 2>/dev/null | sed -n 1p)"
|
|
293
|
+
if [ -n "$f" ]; then
|
|
294
|
+
rm -f "$tmp" "$body"
|
|
295
|
+
kit_say "page answer: already recorded in $f — nothing written"
|
|
296
|
+
if _rp_json; then jq -cn --arg f "$f" '{ok: true, where: "file", file: $f, written: false}'
|
|
297
|
+
else printf 'file %s (already recorded)\n' "$f"; fi
|
|
298
|
+
return 0
|
|
299
|
+
fi
|
|
300
|
+
f="$root/$rel.md"; n=1
|
|
301
|
+
while [ -e "$f" ]; do n=$((n + 1)); f="$root/$rel-$n.md"; done
|
|
302
|
+
{ printf '# %s answer: %s\n\n%s\n\n' "$label" "$title" "$marker"
|
|
303
|
+
printf -- '- Recorded: %s\n- Kind: %s\n' "$today" "$kind"
|
|
304
|
+
[ -n "$issue" ] && printf -- '- Issue: #%s\n' "$issue"
|
|
305
|
+
printf '\n'; cat "$tmp"; printf '\n'; } > "$body"
|
|
306
|
+
if ! mkdir -p "$(dirname "$f")" 2>/dev/null || ! cp "$body" "$f" 2>/dev/null; then
|
|
307
|
+
rm -f "$tmp" "$body"; kit_warn "page answer: cannot write $f"; return 1
|
|
308
|
+
fi
|
|
309
|
+
rm -f "$tmp" "$body"
|
|
310
|
+
kit_say "page answer: written to $f — commit it with the change it belongs to"
|
|
311
|
+
if _rp_json; then jq -cn --arg f "$f" '{ok: true, where: "file", file: $f, written: true}'
|
|
312
|
+
else printf 'file %s\n' "$f"; fi
|
|
313
|
+
return 0
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_rp_usage() {
|
|
317
|
+
cat >&2 <<'EOF'
|
|
318
|
+
cckit page mode print `page`, or `terminal` and why this session has no page
|
|
319
|
+
cckit page open <html-file> [--fallback <md-file>] [-- <tool flags…>]
|
|
320
|
+
open the page in the browser; where there is none, print the
|
|
321
|
+
fallback file (or a one-line notice) and exit 0. Flags after
|
|
322
|
+
`--` go to the page tool (`--reopen`, `--no-open`)
|
|
323
|
+
cckit page poll <html-file> [args…] wait for the reader's feedback (the page tool's `poll`)
|
|
324
|
+
cckit page reply <html-file> [args…] show a reply on the page (the page tool's `reply`)
|
|
325
|
+
cckit page end <html-file> end the page session
|
|
326
|
+
cckit page answer --kind <plan|decision|grill> --title "<title>" [--issue <n>] [--body-file <file>]
|
|
327
|
+
record the answer (body from the file, or stdin): a comment
|
|
328
|
+
on the issue when the project uses GitHub and --issue is
|
|
329
|
+
given, else a file under reviewPages.answersDir (docs/answers)
|
|
330
|
+
|
|
331
|
+
On by default. Off: `cckit add lavish --set enable=no` (reviewPages.enabled: false), or
|
|
332
|
+
CCKIT_PAGES=terminal for one command. A session with no browser (CI, an unattended run, SSH, no
|
|
333
|
+
display) prints to the terminal and exits 0.
|
|
334
|
+
EOF
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
rp_cli() {
|
|
338
|
+
local sub="${1:-}" html="" fb="" mode
|
|
339
|
+
[ $# -gt 0 ] && shift
|
|
340
|
+
case "$sub" in
|
|
341
|
+
mode)
|
|
342
|
+
mode="$(rp_mode)"
|
|
343
|
+
if _rp_json; then
|
|
344
|
+
case "$mode" in
|
|
345
|
+
page) jq -cn '{mode: "page"}' ;;
|
|
346
|
+
*) jq -cn --arg r "${mode#* }" '{mode: "terminal", reason: $r}' ;;
|
|
347
|
+
esac
|
|
348
|
+
else
|
|
349
|
+
case "$mode" in page) printf 'page\n' ;; *) printf 'terminal: %s\n' "${mode#* }" ;; esac
|
|
350
|
+
fi ;;
|
|
351
|
+
open)
|
|
352
|
+
while [ $# -gt 0 ]; do
|
|
353
|
+
case "$1" in
|
|
354
|
+
--fallback) fb="${2:-}"; [ $# -gt 1 ] && shift ;;
|
|
355
|
+
--) shift; break ;;
|
|
356
|
+
-*) kit_warn "page open: unknown flag '$1'"; return 2 ;;
|
|
357
|
+
*) if [ -z "$html" ]; then html="$1"; else kit_warn "page open: one HTML file at a time"; return 2; fi ;;
|
|
358
|
+
esac
|
|
359
|
+
shift
|
|
360
|
+
done
|
|
361
|
+
rp_open "$html" "$fb" "$@" ;;
|
|
362
|
+
poll|reply|end) rp_pass "$sub" "$@" ;;
|
|
363
|
+
answer) rp_answer "$@" ;;
|
|
364
|
+
''|-h|--help|help) _rp_usage; [ -n "$sub" ] || return 2 ;;
|
|
365
|
+
*) kit_warn "page: unknown subcommand '$sub'"; _rp_usage; return 2 ;;
|
|
366
|
+
esac
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if kit_is_main; then rp_cli "$@"; fi
|
|
@@ -61,6 +61,11 @@ rs_needs_dispatch REVIEW_MISSING verify 0; rc "a PR blocked ON the missing revie
|
|
|
61
61
|
# Unless it already has a verdict — then REVIEW_MISSING means the verdict is stale, and a receipt
|
|
62
62
|
# the head check rejected sets have=0, so this case only arises from a caller that lost track.
|
|
63
63
|
rs_needs_dispatch REVIEW_MISSING verify 1; rc "but never twice for the same verdict" "$?" "1"
|
|
64
|
+
# QA_MISSING stands where CLEAN would have: a would-be merge held for a human QA pass (#300). With
|
|
65
|
+
# requireReview:false it is the only state such a PR ever shows, so it must still earn a reviewer.
|
|
66
|
+
rs_needs_dispatch QA_MISSING verify 0; rc "a PR held for QA still gets its reviewer" "$?" "0"
|
|
67
|
+
rs_needs_dispatch QA_MISSING verify 1; rc "and only once per head" "$?" "1"
|
|
68
|
+
rs_needs_dispatch QA_FAILING fix 0; rc "a PR QA failed is not sent to review" "$?" "1"
|
|
64
69
|
# A recorded FAIL is not re-reviewed on its own: the author acts on it and pushes, which changes the
|
|
65
70
|
# head, which makes the verdict stale, which is what earns the next review.
|
|
66
71
|
rs_needs_dispatch REVIEW_FAILING fix 1; rc "a failing review is not re-run" "$?" "1"
|
|
@@ -187,17 +192,8 @@ cat > "$tmp/tozero.json" <<'JSON'
|
|
|
187
192
|
JSON
|
|
188
193
|
t "a zero bound falls back" "$(rs_timeout "$tmp/tozero.json" 2>/dev/null)" "900"
|
|
189
194
|
|
|
190
|
-
#
|
|
191
|
-
|
|
192
|
-
printf 'ignored
|
|
193
|
-
' | _rs_run 2 'sleep 60' >/dev/null 2>&1
|
|
194
|
-
rc "a command past its bound is rc 124" "$?" "124"
|
|
195
|
-
elapsed=$(( $(date +%s) - start ))
|
|
196
|
-
[ "$elapsed" -lt 30 ] && echo "ok: it was killed in ${elapsed}s, not left running" \
|
|
197
|
-
|| { echo "FAIL: still ran ${elapsed}s after a 2s bound"; fail=1; }
|
|
198
|
-
t "a command inside its bound returns its output" "$(printf '' | _rs_run 10 'echo alive' 2>/dev/null)" "alive"
|
|
199
|
-
printf '' | _rs_run 10 'exit 7' >/dev/null 2>&1
|
|
200
|
-
rc "a command's own exit code survives" "$?" "7"
|
|
195
|
+
# The bound itself (TERM then KILL, rc 124, the command's own rc) is al_run's and is covered in
|
|
196
|
+
# agent-launch-test.sh; what stays here is what rs_dispatch does with it.
|
|
201
197
|
|
|
202
198
|
# A dispatch whose reviewer hangs writes NO receipt — a killed reviewer is not a verdict.
|
|
203
199
|
cat > "$tmp/hang.json" <<'JSON'
|
|
@@ -237,5 +233,60 @@ rs_have_receipt 80; rc "with no head given, the issue alone counts" "$?
|
|
|
237
233
|
rs_have_receipt 42 'abc123'; rc "a head-less receipt does not cover a head" "$?" "1"
|
|
238
234
|
rs_have_receipt 42; rc "but still counts when no head is asked" "$?" "0"
|
|
239
235
|
|
|
236
|
+
# ── review.headless: cckit builds the reviewer's command from the profile ────────────────────────
|
|
237
|
+
# Stubs named `claude` and `codex` stand in for the agents: they record their argv and the brief
|
|
238
|
+
# they were piped, and print a report. No real agent runs.
|
|
239
|
+
mkdir -p "$tmp/bin"
|
|
240
|
+
for k in claude codex; do
|
|
241
|
+
cat > "$tmp/bin/$k" <<STUB
|
|
242
|
+
#!/usr/bin/env bash
|
|
243
|
+
printf '%s\n' "\$*" > "$tmp/$k.argv"
|
|
244
|
+
cat > "$tmp/$k.stdin"
|
|
245
|
+
printf 'outcome: pr-open\nurl: u\ngate: pass — read by $k\nblocker: none\nnext stage: none\n'
|
|
246
|
+
STUB
|
|
247
|
+
chmod +x "$tmp/bin/$k"
|
|
248
|
+
done
|
|
249
|
+
cat > "$tmp/headless.json" <<'JSON'
|
|
250
|
+
{ "review": { "headless": true },
|
|
251
|
+
"agents": { "default": "critic",
|
|
252
|
+
"profiles": {
|
|
253
|
+
"critic": { "kind": "codex", "stages": ["review"], "args": ["-s", "read-only"] },
|
|
254
|
+
"reader": { "kind": "claude", "stages": ["review"] },
|
|
255
|
+
"other": { "kind": "aider", "stages": ["review"] } } } }
|
|
256
|
+
JSON
|
|
257
|
+
rs_headless "$tmp/headless.json"; rc "review.headless true is read" "$?" "0"
|
|
258
|
+
rs_headless "$CFG"; rc "it is off when unset" "$?" "1"
|
|
259
|
+
rs_enabled "$tmp/headless.json"; rc "review.headless alone turns the stage on" "$?" "0"
|
|
260
|
+
rs_enabled "$tmp/none.json"; rc "neither key leaves the stage off" "$?" "1"
|
|
261
|
+
|
|
262
|
+
FX_CTX="90\t\t"
|
|
263
|
+
hp="$(PATH="$tmp/bin:$PATH" rs_dispatch "$tmp/headless.json" 'o/r' 9 90)"
|
|
264
|
+
t "codex ran non-interactively with the profile's args" "$(cat "$tmp/codex.argv")" "exec -s read-only -"
|
|
265
|
+
has "the brief reached codex on stdin" "$(cat "$tmp/codex.stdin")" "You are reviewing pull request #9"
|
|
266
|
+
t "the codex reply is the receipt" "$(jq -r .gate "$hp")" "pass — read by codex"
|
|
267
|
+
|
|
268
|
+
FX_CTX="91\tagent:reader\t"
|
|
269
|
+
hp="$(PATH="$tmp/bin:$PATH" rs_dispatch "$tmp/headless.json" 'o/r' 9 91)"
|
|
270
|
+
t "claude ran in print mode" "$(cat "$tmp/claude.argv")" "-p"
|
|
271
|
+
t "the claude reply is the receipt" "$(jq -r .gate "$hp")" "pass — read by claude"
|
|
272
|
+
|
|
273
|
+
FX_CTX="92\tagent:other\t"
|
|
274
|
+
before3="$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')"
|
|
275
|
+
PATH="$tmp/bin:$PATH" rs_dispatch "$tmp/headless.json" 'o/r' 9 92 >/dev/null 2>&1
|
|
276
|
+
rc "a kind with no headless form is refused" "$?" "2"
|
|
277
|
+
t "and writes no receipt" "$(ls "$KIT_STATE_DIR/receipts" 2>/dev/null | wc -l | tr -d ' ')" "$before3"
|
|
278
|
+
|
|
279
|
+
# review.command still wins over review.headless.
|
|
280
|
+
cat > "$tmp/both.json" <<'JSON'
|
|
281
|
+
{ "review": { "headless": true, "command": "cat > /dev/null; printf 'outcome: pr-open\nurl: u\ngate: pass — the override\nblocker: none\nnext stage: none\n'" },
|
|
282
|
+
"agents": { "default": "critic",
|
|
283
|
+
"profiles": { "critic": { "kind": "codex", "stages": ["review"] } } } }
|
|
284
|
+
JSON
|
|
285
|
+
rm -f "$tmp/codex.argv"
|
|
286
|
+
FX_CTX="93\t\t"
|
|
287
|
+
hp="$(PATH="$tmp/bin:$PATH" rs_dispatch "$tmp/both.json" 'o/r' 9 93)"
|
|
288
|
+
t "review.command overrides the built command" "$(jq -r .gate "$hp")" "pass — the override"
|
|
289
|
+
t "the agent CLI was not started" "$([ -f "$tmp/codex.argv" ] && echo ran || echo no)" "no"
|
|
290
|
+
|
|
240
291
|
[ "$fail" -eq 0 ] && echo "review-stage-test: PASS" || echo "review-stage-test: FAILED"
|
|
241
292
|
exit "$fail"
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
# dispatch half; the merge gate that reads the verdict is separate on purpose (#348), so the gate
|
|
8
8
|
# stays testable against a receipt that this file never produced.
|
|
9
9
|
#
|
|
10
|
-
# WHO STARTS THE AGENT.
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
10
|
+
# WHO STARTS THE AGENT. The shared headless launcher (agent-launch.sh, E257.7): cckit pipes a brief
|
|
11
|
+
# to the command's stdin, bounds it, and reads the report off its stdout — the same shape sr_record
|
|
12
|
+
# already takes. Two ways to name the command, and neither is on by default:
|
|
13
|
+
# review.command the project's own command line. It wins when set, so a project that
|
|
14
|
+
# wraps its reviewer keeps doing so.
|
|
15
|
+
# review.headless true cckit builds the line from the resolved profile's kind and args:
|
|
16
|
+
# `claude -p` or `codex exec -`. A kind with no headless form is refused.
|
|
17
|
+
# With neither set the stage is off.
|
|
17
18
|
#
|
|
18
19
|
# THE REVIEWER DOES NOT OWN THE BRANCH. A review profile must not write to the branch it reviews:
|
|
19
20
|
# ap_profile_writes defaults to false and branch-owner.sh already refuses a second writer. Nothing
|
|
@@ -33,6 +34,8 @@ _rs_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>
|
|
|
33
34
|
command -v ap_resolve_pr >/dev/null 2>&1 || . "$_rs_dir/agent-resolve.sh"
|
|
34
35
|
# shellcheck source=/dev/null
|
|
35
36
|
command -v sr_record >/dev/null 2>&1 || . "$_rs_dir/stage-receipt.sh"
|
|
37
|
+
# shellcheck source=/dev/null
|
|
38
|
+
command -v al_run >/dev/null 2>&1 || . "$_rs_dir/agent-launch.sh"
|
|
36
39
|
|
|
37
40
|
# rs_command <cfg> — the command the project configured to run a reviewer. Empty when unset, which
|
|
38
41
|
# is what keeps the stage off in every project that has not opted in.
|
|
@@ -42,8 +45,16 @@ rs_command() {
|
|
|
42
45
|
jq -r '.review.command // ""' "$cfg" 2>/dev/null || true
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
#
|
|
46
|
-
|
|
48
|
+
# rs_headless <cfg> — rc 0 when `review.headless` is true: cckit builds the reviewer's command from
|
|
49
|
+
# the resolved profile instead of reading one from `review.command`.
|
|
50
|
+
rs_headless() {
|
|
51
|
+
local cfg="${1:-}"
|
|
52
|
+
[ -n "$cfg" ] && [ -f "$cfg" ] || return 1
|
|
53
|
+
[ "$(jq -r '.review.headless // false' "$cfg" 2>/dev/null)" = "true" ]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# rs_enabled <cfg> — rc 0 when the stage is on: a review command is configured, or review.headless.
|
|
57
|
+
rs_enabled() { [ -n "$(rs_command "${1:-}")" ] || rs_headless "${1:-}"; }
|
|
47
58
|
|
|
48
59
|
# rs_needs_dispatch <state> <action> <have-receipt> — rc 0 when this PR should get a reviewer now.
|
|
49
60
|
# Pure.
|
|
@@ -63,6 +74,9 @@ rs_needs_dispatch() {
|
|
|
63
74
|
local state="${1:-}" action="${2:-}" have="${3:-}"
|
|
64
75
|
[ "$have" = "1" ] && return 1
|
|
65
76
|
[ "$state" = "REVIEW_MISSING" ] && return 0
|
|
77
|
+
# QA_MISSING (#300) is returned only where CLEAN would have been, so it is the same would-be
|
|
78
|
+
# merge held for a human QA pass. It still earns its reviewer: the agent reads before the human.
|
|
79
|
+
[ "$state" = "QA_MISSING" ] && return 0
|
|
66
80
|
[ "$action" = "merge" ] || return 1
|
|
67
81
|
return 0
|
|
68
82
|
}
|
|
@@ -141,59 +155,18 @@ rs_timeout() {
|
|
|
141
155
|
esac
|
|
142
156
|
}
|
|
143
157
|
|
|
144
|
-
# _rs_run <seconds> <command> — run the command on stdin under a wall-clock bound, rc 124 on expiry.
|
|
145
|
-
#
|
|
146
|
-
# `timeout(1)` when it is there, a poll loop when it is not. The fallback is not a nicety: macOS
|
|
147
|
-
# ships no timeout, so on the platform this is most often run from, "use timeout or go unbounded"
|
|
148
|
-
# means unbounded — and an unbounded reviewer hangs the whole captain pass, every other PR in it
|
|
149
|
-
# included, with nobody watching.
|
|
150
|
-
#
|
|
151
|
-
# The loop is safe because a background child that has exited is reaped before `kill -0` is asked
|
|
152
|
-
# about it, in both bash and zsh, so the poll terminates rather than spinning on a zombie. SIGTERM
|
|
153
|
-
# first, then SIGKILL, because an agent that traps TERM to clean up should get the chance and one
|
|
154
|
-
# that ignores it should not get to stay.
|
|
155
|
-
_rs_run() {
|
|
156
|
-
local secs="${1:-900}" cmd="${2:-}" t="" out rc=0 pid waited=0
|
|
157
|
-
if command -v timeout >/dev/null 2>&1; then t=timeout
|
|
158
|
-
elif command -v gtimeout >/dev/null 2>&1; then t=gtimeout
|
|
159
|
-
fi
|
|
160
|
-
if [ -n "$t" ]; then
|
|
161
|
-
"$t" --kill-after=10s "${secs}s" sh -c "$cmd" 2>/dev/null
|
|
162
|
-
return $?
|
|
163
|
-
fi
|
|
164
|
-
|
|
165
|
-
out="$(mktemp 2>/dev/null)" || { sh -c "$cmd" 2>/dev/null; return $?; }
|
|
166
|
-
sh -c "$cmd" > "$out" 2>/dev/null &
|
|
167
|
-
pid=$!
|
|
168
|
-
while kill -0 "$pid" 2>/dev/null; do
|
|
169
|
-
if [ "$waited" -ge "$secs" ]; then
|
|
170
|
-
kill -TERM "$pid" 2>/dev/null
|
|
171
|
-
# A short grace period, then SIGKILL. Not `sleep 10`: the captain is already waiting on this.
|
|
172
|
-
local grace=0
|
|
173
|
-
while [ "$grace" -lt 10 ] && kill -0 "$pid" 2>/dev/null; do sleep 1; grace=$((grace + 1)); done
|
|
174
|
-
kill -KILL "$pid" 2>/dev/null
|
|
175
|
-
wait "$pid" 2>/dev/null
|
|
176
|
-
rm -f "$out"
|
|
177
|
-
return 124
|
|
178
|
-
fi
|
|
179
|
-
sleep 1; waited=$((waited + 1))
|
|
180
|
-
done
|
|
181
|
-
wait "$pid" 2>/dev/null; rc=$?
|
|
182
|
-
cat "$out"; rm -f "$out"
|
|
183
|
-
return "$rc"
|
|
184
|
-
}
|
|
185
|
-
|
|
186
158
|
# rs_dispatch <cfg> <repo> <pr> <issue> [<head-sha>] — resolve a reviewer, run it, record its
|
|
187
159
|
# verdict. <head-sha> is the PR head the review applies to; it is stored on the receipt so a
|
|
188
160
|
# later commit cannot inherit this verdict (#351 review).
|
|
189
|
-
# Echoes the receipt path. The
|
|
190
|
-
#
|
|
161
|
+
# Echoes the receipt path. The command receives the brief on stdin; its stdout is the report
|
|
162
|
+
# sr_record parses. The command is `review.command`, or the profile's headless form under
|
|
163
|
+
# `review.headless`; al_run (agent-launch.sh) bounds either.
|
|
191
164
|
rs_dispatch() {
|
|
192
165
|
local cfg="${1:-}" repo="${2:-}" pr="${3:-}" num="${4:-}" head="${5:-}"
|
|
193
166
|
local cmd prof tier src kind args ctx il pl report attempt path secs rc_=0
|
|
194
167
|
[ -n "$num" ] || { echo "review: PR #${pr:-?} has no linked issue — nothing to record a receipt against" >&2; return 2; }
|
|
195
168
|
cmd="$(rs_command "$cfg")"
|
|
196
|
-
[ -n "$cmd" ] || return 4
|
|
169
|
+
[ -n "$cmd" ] || rs_headless "$cfg" || return 4
|
|
197
170
|
|
|
198
171
|
# ONE context fetch, not two. ap_resolve_pr fetches it internally and a second call for
|
|
199
172
|
# ap_resolve_source would fetch again — two round trips whose answers can disagree, since every
|
|
@@ -223,20 +196,29 @@ rs_dispatch() {
|
|
|
223
196
|
kind="$(ap_profile_field "$cfg" "$prof" kind)"
|
|
224
197
|
args="$(ap_profile_args "$cfg" "$prof")"
|
|
225
198
|
|
|
199
|
+
# No review.command: build the reviewer's line from the profile. Text mode, because the reply IS
|
|
200
|
+
# the report sr_record parses. A kind with no headless form is refused here — a receipt recorded
|
|
201
|
+
# from a command cckit guessed at would be a verdict nobody asked that agent for.
|
|
202
|
+
if [ -z "$cmd" ]; then
|
|
203
|
+
cmd="$(al_headless_cmd "$kind" text "$args")" || {
|
|
204
|
+
echo "review: review.headless is on but profile '$prof' is kind '${kind:-?}' — set review.command for it" >&2
|
|
205
|
+
return 2
|
|
206
|
+
}
|
|
207
|
+
fi
|
|
208
|
+
|
|
226
209
|
# Bound the run. The captain is unattended and single-threaded: a reviewer that never returns
|
|
227
|
-
# blocks the whole pass, every other PR in it included, with no human to notice.
|
|
228
|
-
#
|
|
229
|
-
# degrading to today's unbounded behaviour beats refusing to review at all.
|
|
210
|
+
# blocks the whole pass, every other PR in it included, with no human to notice. al_run needs no
|
|
211
|
+
# timeout(1), so the bound holds on macOS too.
|
|
230
212
|
secs="$(rs_timeout "$cfg")"
|
|
231
213
|
report="$(rs_brief "$repo" "$pr" "$num" \
|
|
232
214
|
| CCKIT_REVIEW_PROFILE="$prof" CCKIT_REVIEW_KIND="$kind" CCKIT_REVIEW_ARGS="$args" \
|
|
233
215
|
CCKIT_REVIEW_PR="$pr" CCKIT_REVIEW_ISSUE="$num" CCKIT_REVIEW_REPO="$repo" \
|
|
234
|
-
|
|
216
|
+
al_run "$secs" "$cmd" 2>/dev/null)" || {
|
|
235
217
|
rc_=$?
|
|
236
218
|
if [ "$rc_" = "124" ]; then
|
|
237
|
-
echo "review:
|
|
219
|
+
echo "review: the reviewer exceeded ${secs}s for PR #$pr — killed, no receipt written" >&2
|
|
238
220
|
else
|
|
239
|
-
echo "review: the
|
|
221
|
+
echo "review: the reviewer command failed for PR #$pr — no receipt written" >&2
|
|
240
222
|
fi
|
|
241
223
|
return 3
|
|
242
224
|
}
|