@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,309 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# task-source-file.sh — the `file` task source (#450): one tracked file per light task.
|
|
4
|
+
#
|
|
5
|
+
# <tasks.dir>/<id>.md (tasks.dir defaults to `tasks`, at the checkout root)
|
|
6
|
+
#
|
|
7
|
+
# id: t3f9a
|
|
8
|
+
# title: Write the spring newsletter
|
|
9
|
+
# status: todo
|
|
10
|
+
# priority: p2
|
|
11
|
+
# kind: task
|
|
12
|
+
# created: 2026-11-12
|
|
13
|
+
#
|
|
14
|
+
# Free-form notes after the first blank line.
|
|
15
|
+
#
|
|
16
|
+
# The header is one `key: value` per line up to the first blank line. `status` is `todo`, `done`
|
|
17
|
+
# or `dropped` (set `dropped` by hand to abandon a task); anything else reads as `todo`.
|
|
18
|
+
#
|
|
19
|
+
# ONE FILE PER TASK, because two branches that each add a task must merge without a conflict. Two
|
|
20
|
+
# appends to one shared file land on the same lines and conflict in git; two new files never touch.
|
|
21
|
+
# Finishing a task rewrites one line (`status:`) of one file.
|
|
22
|
+
#
|
|
23
|
+
# STATE IS DERIVED from where the file is and what it says — there is no second record to keep in
|
|
24
|
+
# step. For a task id, in this order:
|
|
25
|
+
# done / dropped the base branch's copy says so (the pull request that finished it merged)
|
|
26
|
+
# review a `light/<id>-<slug>` branch exists and its copy says `done`
|
|
27
|
+
# doing a `light/<id>-<slug>` branch exists
|
|
28
|
+
# todo the base branch has the file
|
|
29
|
+
# shared a `light/share-<stamp>` branch has the file and the base branch does not yet:
|
|
30
|
+
# `cckit task share` committed it and its pull request has not merged
|
|
31
|
+
# draft only this checkout has the file (not committed anywhere a teammate can see)
|
|
32
|
+
# The base branch is read as `origin/<base>` when that ref exists, else the local `<base>`.
|
|
33
|
+
# Branches are local heads first, then the cached `origin/light/*` refs. No op here uses the
|
|
34
|
+
# network; the verbs fetch before they list.
|
|
35
|
+
#
|
|
36
|
+
# Implements the interface in task-source.sh; called only through task_source_call.
|
|
37
|
+
# Requires: git. bash 3.2 + zsh (no glob held in a variable, no `status`/`path` variable names).
|
|
38
|
+
# errors: mixed — reads are forgiving (a missing file is an absent task); writes return 1
|
|
39
|
+
|
|
40
|
+
_tsf_top() { git rev-parse --show-toplevel 2>/dev/null; }
|
|
41
|
+
|
|
42
|
+
_tsf_base_ref() {
|
|
43
|
+
local base="${KIT_BASE_BRANCH:-main}"
|
|
44
|
+
if git show-ref --verify --quiet "refs/remotes/origin/$base" 2>/dev/null; then printf 'origin/%s' "$base"
|
|
45
|
+
elif git show-ref --verify --quiet "refs/heads/$base" 2>/dev/null; then printf '%s' "$base"
|
|
46
|
+
fi
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# _tsf_field <key> — stdin: a task file. Print the header value of <key>, or nothing.
|
|
50
|
+
_tsf_field() {
|
|
51
|
+
awk -v k="$1" '
|
|
52
|
+
NF == 0 { exit }
|
|
53
|
+
{ i = index($0, ":")
|
|
54
|
+
if (i && substr($0, 1, i - 1) == k) {
|
|
55
|
+
v = substr($0, i + 1); sub(/^[ \t]+/, "", v); sub(/[ \t\r]+$/, "", v); print v; exit
|
|
56
|
+
} }'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# _tsf_branch <id> — the task's branch as a ref git can read: a local `light/<id>-…` head, else a
|
|
60
|
+
# cached `origin/light/<id>-…`. Nothing when the task has no branch.
|
|
61
|
+
_tsf_branch() {
|
|
62
|
+
local b
|
|
63
|
+
b="$(git for-each-ref --format='%(refname:short)' "refs/heads/light/$1-*" 2>/dev/null | sed -n 1p)"
|
|
64
|
+
[ -n "$b" ] || b="$(git for-each-ref --format='%(refname:short)' "refs/remotes/origin/light/$1-*" 2>/dev/null | sed -n 1p)"
|
|
65
|
+
printf '%s' "$b"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_tsf_closed() { case "$1" in done|dropped) return 0 ;; esac; return 1; }
|
|
69
|
+
|
|
70
|
+
# _tsf_share_refs — every `light/share-<stamp>` ref: local heads first, then the cached origin ones.
|
|
71
|
+
_tsf_share_refs() {
|
|
72
|
+
git for-each-ref --format='%(refname:short)' 'refs/heads/light/share-*' \
|
|
73
|
+
'refs/remotes/origin/light/share-*' 2>/dev/null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# _tsf_share_ref <id> — the first share ref whose tree carries the task's file, or nothing.
|
|
77
|
+
_tsf_share_ref() {
|
|
78
|
+
local top dir r
|
|
79
|
+
top="$(_tsf_top)" || return 0
|
|
80
|
+
[ -n "$top" ] || return 0
|
|
81
|
+
dir="$(task_source_dir)"
|
|
82
|
+
_tsf_share_refs | while IFS= read -r r; do
|
|
83
|
+
if git -C "$top" cat-file -e "$r:$dir/$1.md" 2>/dev/null; then printf '%s' "$r"; break; fi
|
|
84
|
+
done
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# _tsf_ids — every task id visible from this checkout: its tasks dir, the base branch, the
|
|
88
|
+
# `light/*` branches, and the files a `light/share-*` branch carries.
|
|
89
|
+
_tsf_ids() {
|
|
90
|
+
local top dir base r
|
|
91
|
+
top="$(_tsf_top)" || return 0
|
|
92
|
+
[ -n "$top" ] || return 0
|
|
93
|
+
dir="$(task_source_dir)"; base="$(_tsf_base_ref)"
|
|
94
|
+
{
|
|
95
|
+
if [ -d "$top/$dir" ]; then ls "$top/$dir" 2>/dev/null | grep '\.md$' | sed 's/\.md$//'; fi
|
|
96
|
+
if [ -n "$base" ]; then
|
|
97
|
+
git -C "$top" ls-tree --name-only "$base" "$dir/" 2>/dev/null | grep '\.md$' | sed 's|.*/||; s/\.md$//'
|
|
98
|
+
fi
|
|
99
|
+
_tsf_share_refs | while IFS= read -r r; do
|
|
100
|
+
git -C "$top" ls-tree --name-only "$r" "$dir/" 2>/dev/null || true
|
|
101
|
+
done | grep '\.md$' | sed 's|.*/||; s/\.md$//'
|
|
102
|
+
git for-each-ref --format='%(refname)' refs/heads/light/ refs/remotes/origin/light/ 2>/dev/null \
|
|
103
|
+
| sed -E 's#^refs/(heads|remotes/origin)/light/##; s/-.*$//'
|
|
104
|
+
} | while IFS= read -r id; do
|
|
105
|
+
if task_id_valid "$id"; then printf '%s\n' "$id"; fi
|
|
106
|
+
done | sort -u
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# _tsf_row <id> — the task's TSV row; rc 1 when no copy of the file can be read.
|
|
110
|
+
_tsf_row() {
|
|
111
|
+
local id="$1" top dir base rel br="" c_base="" c_br="" c_wt="" content state s sr=""
|
|
112
|
+
top="$(_tsf_top)" || return 1
|
|
113
|
+
[ -n "$top" ] || return 1
|
|
114
|
+
dir="$(task_source_dir)"; base="$(_tsf_base_ref)"; rel="$dir/$id.md"
|
|
115
|
+
if [ -n "$base" ]; then c_base="$(git -C "$top" show "$base:$rel" 2>/dev/null || true)"; fi
|
|
116
|
+
br="$(_tsf_branch "$id")"
|
|
117
|
+
if [ -n "$br" ]; then c_br="$(git -C "$top" show "$br:$rel" 2>/dev/null || true)"; fi
|
|
118
|
+
if [ -f "$top/$rel" ]; then c_wt="$(cat "$top/$rel" 2>/dev/null || true)"; fi
|
|
119
|
+
|
|
120
|
+
s="$(printf '%s\n' "$c_base" | _tsf_field status)"
|
|
121
|
+
if [ -n "$c_base" ] && _tsf_closed "$s"; then
|
|
122
|
+
state="$s"; content="$c_base"
|
|
123
|
+
elif [ -n "$br" ] && [ -n "${c_br:-$c_base$c_wt}" ]; then
|
|
124
|
+
content="${c_br:-${c_base:-$c_wt}}"
|
|
125
|
+
if [ "$(printf '%s\n' "$c_br" | _tsf_field status)" = "done" ]; then state="review"; else state="doing"; fi
|
|
126
|
+
elif [ -n "$c_base" ]; then
|
|
127
|
+
state="todo"; content="$c_base"
|
|
128
|
+
elif sr="$(_tsf_share_ref "$id")" && [ -n "$sr" ]; then
|
|
129
|
+
state="shared"; br="$sr"; content="$(git -C "$top" show "$sr:$rel" 2>/dev/null || true)"
|
|
130
|
+
elif [ -n "$c_wt" ]; then
|
|
131
|
+
content="$c_wt"; s="$(printf '%s\n' "$c_wt" | _tsf_field status)"
|
|
132
|
+
if _tsf_closed "$s"; then state="$s"; else state="draft"; fi
|
|
133
|
+
else
|
|
134
|
+
return 1
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
local title prio kind created
|
|
138
|
+
title="$(printf '%s\n' "$content" | _tsf_field title)"
|
|
139
|
+
prio="$(printf '%s\n' "$content" | _tsf_field priority)"
|
|
140
|
+
kind="$(printf '%s\n' "$content" | _tsf_field kind)"
|
|
141
|
+
created="$(printf '%s\n' "$content" | _tsf_field created)"
|
|
142
|
+
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$id" "$state" "${prio:-p2}" "${kind:-task}" "${created:--}" \
|
|
143
|
+
"${br:--}" "$(printf '%s' "${title:-(untitled)}" | tr '\t' ' ')"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# task_file_list — every task, ordered: doing, review, todo, draft, shared, done, dropped; inside a state
|
|
147
|
+
# by priority, then creation date, then id.
|
|
148
|
+
task_file_list() {
|
|
149
|
+
local id
|
|
150
|
+
_tsf_ids | while IFS= read -r id; do
|
|
151
|
+
[ -n "$id" ] || continue
|
|
152
|
+
_tsf_row "$id" || true
|
|
153
|
+
done | awk -F'\t' '
|
|
154
|
+
BEGIN { r["doing"] = 1; r["review"] = 2; r["todo"] = 3; r["draft"] = 4; r["shared"] = 5; r["done"] = 8; r["dropped"] = 9 }
|
|
155
|
+
{ print (($2 in r) ? r[$2] : 7) "\t" $3 "\t" $5 "\t" $1 "\t" $0 }' \
|
|
156
|
+
| sort -t "$(printf '\t')" -k1,1n -k2,2 -k3,3 -k4,4 | cut -f5-
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# task_file_get <id|prefix> — the one row whose id is <id>, else the one whose id starts with it.
|
|
160
|
+
task_file_get() {
|
|
161
|
+
local want="${1:-}" rows n
|
|
162
|
+
[ -n "$want" ] || { echo "✗ a task id is required" >&2; return 1; }
|
|
163
|
+
if task_id_valid "$want" && rows="$(_tsf_row "$want")" && [ -n "$rows" ]; then
|
|
164
|
+
printf '%s\n' "$rows"; return 0
|
|
165
|
+
fi
|
|
166
|
+
rows="$(task_file_list | awk -F'\t' -v w="$want" 'index($1, w) == 1')"
|
|
167
|
+
n="$(printf '%s\n' "$rows" | grep -c . || true)"
|
|
168
|
+
if [ "$n" -eq 0 ]; then
|
|
169
|
+
echo "✗ no task '$want' — see 'cckit task list --all'" >&2; return 1
|
|
170
|
+
elif [ "$n" -gt 1 ]; then
|
|
171
|
+
echo "✗ '$want' matches $n tasks: $(printf '%s\n' "$rows" | cut -f1 | tr '\n' ' ')" >&2; return 3
|
|
172
|
+
fi
|
|
173
|
+
printf '%s\n' "$rows"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_tsf_exists() {
|
|
177
|
+
local id="$1" top dir base
|
|
178
|
+
top="$(_tsf_top)"; dir="$(task_source_dir)"; base="$(_tsf_base_ref)"
|
|
179
|
+
[ -f "$top/$dir/$id.md" ] && return 0
|
|
180
|
+
[ -n "$base" ] && git -C "$top" cat-file -e "$base:$dir/$id.md" 2>/dev/null && return 0
|
|
181
|
+
[ -n "$(_tsf_branch "$id")" ] && return 0
|
|
182
|
+
[ -n "$(_tsf_share_ref "$id")" ] && return 0
|
|
183
|
+
return 1
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# _tsf_new_id <seed> — `t` + 4 hex digits not used by any task this checkout can see. Not a
|
|
187
|
+
# counter: two branches that each took "the next number" would both create task 7.
|
|
188
|
+
_tsf_new_id() {
|
|
189
|
+
local seed="$1" i=0 h id
|
|
190
|
+
while [ "$i" -lt 64 ]; do
|
|
191
|
+
h="$(printf '%s|%s|%s|%s|%s' "$seed" "$$" "$(date +%s 2>/dev/null)" "${RANDOM:-0}" "$i" \
|
|
192
|
+
| git hash-object --stdin 2>/dev/null | cut -c1-4)"
|
|
193
|
+
id="t$h"
|
|
194
|
+
if [ -n "$h" ] && ! _tsf_exists "$id"; then printf '%s' "$id"; return 0; fi
|
|
195
|
+
i=$((i + 1))
|
|
196
|
+
done
|
|
197
|
+
return 1
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# task_file_create <title> <priority> <kind> <body> — write the task file into THIS checkout and
|
|
201
|
+
# print the id. Nothing is committed: the file travels with the branch that starts or shares it.
|
|
202
|
+
task_file_create() {
|
|
203
|
+
local title="$1" prio="${2:-p2}" kind="${3:-task}" body="${4:-}" top dir id f
|
|
204
|
+
top="$(_tsf_top)"
|
|
205
|
+
[ -n "$top" ] || { echo "✗ not inside a git repository" >&2; return 1; }
|
|
206
|
+
dir="$(task_source_dir)"
|
|
207
|
+
title="$(printf '%s' "$title" | tr '\n\t' ' ' | sed -E 's/^ +| +$//g')"
|
|
208
|
+
[ -n "$title" ] || { echo "✗ a title is required" >&2; return 1; }
|
|
209
|
+
id="$(_tsf_new_id "$title")" || { echo "✗ could not allocate a task id" >&2; return 1; }
|
|
210
|
+
mkdir -p "$top/$dir" || return 1
|
|
211
|
+
f="$top/$dir/$id.md"
|
|
212
|
+
{
|
|
213
|
+
printf 'id: %s\ntitle: %s\nstatus: todo\npriority: %s\nkind: %s\ncreated: %s\n' \
|
|
214
|
+
"$id" "$title" "$prio" "$kind" "$(date +%Y-%m-%d)"
|
|
215
|
+
if [ -n "$body" ]; then printf '\n%s\n' "$body"; fi
|
|
216
|
+
} > "$f" || return 1
|
|
217
|
+
printf '%s\n' "$id"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# _tsf_untracked <checkout> <rel> — rc 0 when <rel> exists there and git does not track it.
|
|
221
|
+
_tsf_untracked() {
|
|
222
|
+
[ -f "$1/$2" ] && ! git -C "$1" ls-files --error-unmatch -- "$2" >/dev/null 2>&1
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
# task_file_on_start <id> <worktree> <from-checkout> — make sure the task file is committed on the
|
|
226
|
+
# task's branch. When the base branch does not have it yet (a draft), it is copied from the checkout
|
|
227
|
+
# the start was run in and committed; an untracked original is then removed, because a file left
|
|
228
|
+
# untracked there blocks the pull that later brings the merged copy.
|
|
229
|
+
task_file_on_start() {
|
|
230
|
+
local id="$1" wt="$2" from="$3" dir rel
|
|
231
|
+
dir="$(task_source_dir)"; rel="$dir/$id.md"
|
|
232
|
+
if git -C "$wt" cat-file -e "HEAD:$rel" 2>/dev/null; then return 0; fi
|
|
233
|
+
if [ ! -f "$wt/$rel" ]; then
|
|
234
|
+
[ -f "$from/$rel" ] || { echo "✗ task $id has no file at $rel" >&2; return 1; }
|
|
235
|
+
mkdir -p "$wt/$dir" && cp "$from/$rel" "$wt/$rel" || return 1
|
|
236
|
+
fi
|
|
237
|
+
git -C "$wt" add -- "$rel" >/dev/null 2>&1 \
|
|
238
|
+
&& git -C "$wt" commit -q -m "chore(tasks): add $id" -- "$rel" >/dev/null 2>&1 \
|
|
239
|
+
|| { echo "✗ could not commit $rel on the task branch" >&2; return 1; }
|
|
240
|
+
if [ "$from" != "$wt" ] && _tsf_untracked "$from" "$rel"; then
|
|
241
|
+
rm -f "$from/$rel"; rmdir "$from/$dir" 2>/dev/null || true
|
|
242
|
+
echo "[$id] moved $rel onto the task branch" >&2
|
|
243
|
+
fi
|
|
244
|
+
return 0
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
# task_file_on_finish <id> <worktree> — set `status: done` in the worktree's copy and stage the
|
|
248
|
+
# tasks dir (so a task created in this worktree ships with it). The mark reaches the base branch
|
|
249
|
+
# when the pull request merges, which is what makes the task done.
|
|
250
|
+
task_file_on_finish() {
|
|
251
|
+
local id="$1" wt="$2" dir rel tmp
|
|
252
|
+
dir="$(task_source_dir)"; rel="$dir/$id.md"
|
|
253
|
+
[ -f "$wt/$rel" ] || { echo "✗ task $id has no file at $rel in $wt" >&2; return 1; }
|
|
254
|
+
tmp="$(mktemp)" || return 1
|
|
255
|
+
if [ -n "$(_tsf_field status < "$wt/$rel")" ]; then
|
|
256
|
+
awk 'BEGIN { h = 1 } h && NF == 0 { h = 0 }
|
|
257
|
+
h && !d && /^status:/ { print "status: done"; d = 1; next } { print }' "$wt/$rel" > "$tmp"
|
|
258
|
+
else
|
|
259
|
+
{ printf 'status: done\n'; cat "$wt/$rel"; } > "$tmp"
|
|
260
|
+
fi
|
|
261
|
+
cat "$tmp" > "$wt/$rel" && rm -f "$tmp" || { rm -f "$tmp"; return 1; }
|
|
262
|
+
git -C "$wt" add -- "$dir" >/dev/null 2>&1 || return 1
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
# task_file_body <id> <worktree> — the free-form notes of the task: everything after the header's
|
|
266
|
+
# first blank line in <worktree>'s copy. Nothing when the task has no notes.
|
|
267
|
+
task_file_body() {
|
|
268
|
+
local f; f="$2/$(task_source_dir)/$1.md"
|
|
269
|
+
[ -f "$f" ] || return 0
|
|
270
|
+
awk 'b { print; next } NF == 0 { b = 1 }' "$f"
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
# task_file_state <id> [<branch>] — what gc asks before it offers a `light/<id>-…` branch for
|
|
274
|
+
# deletion. `closed` only when the base branch's copy says done or dropped. `open` when the base
|
|
275
|
+
# copy says otherwise, or when only the branch (or this checkout) has the file: the work exists
|
|
276
|
+
# nowhere else. Empty when no copy exists. `unknown` when there is no base ref to read.
|
|
277
|
+
task_file_state() {
|
|
278
|
+
local id="$1" br="${2:-}" top dir base rel c
|
|
279
|
+
top="$(_tsf_top)"
|
|
280
|
+
[ -n "$top" ] || { printf 'unknown\n'; return 0; }
|
|
281
|
+
base="$(_tsf_base_ref)"
|
|
282
|
+
[ -n "$base" ] || { printf 'unknown\n'; return 0; }
|
|
283
|
+
dir="$(task_source_dir)"; rel="$dir/$id.md"
|
|
284
|
+
c="$(git -C "$top" show "$base:$rel" 2>/dev/null || true)"
|
|
285
|
+
if [ -n "$c" ]; then
|
|
286
|
+
if _tsf_closed "$(printf '%s\n' "$c" | _tsf_field status)"; then printf 'closed\n'; else printf 'open\n'; fi
|
|
287
|
+
return 0
|
|
288
|
+
fi
|
|
289
|
+
if [ -n "$br" ] && git -C "$top" cat-file -e "$br:$rel" 2>/dev/null; then printf 'open\n'; return 0; fi
|
|
290
|
+
if [ -f "$top/$rel" ]; then printf 'open\n'; fi
|
|
291
|
+
return 0
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
# task_file_share <worktree> <from-checkout> — move every draft (a task file the from-checkout has
|
|
295
|
+
# untracked and no branch or base copy carries) into <worktree> and stage it. Prints the ids moved.
|
|
296
|
+
task_file_share() {
|
|
297
|
+
local wt="$1" from="$2" dir id state rest
|
|
298
|
+
dir="$(task_source_dir)"
|
|
299
|
+
task_file_list | while IFS="$(printf '\t')" read -r id state rest; do
|
|
300
|
+
[ "$state" = draft ] || continue
|
|
301
|
+
_tsf_untracked "$from" "$dir/$id.md" || continue
|
|
302
|
+
mkdir -p "$wt/$dir" && cp "$from/$dir/$id.md" "$wt/$dir/$id.md" || continue
|
|
303
|
+
git -C "$wt" add -- "$dir/$id.md" >/dev/null 2>&1 || continue
|
|
304
|
+
rm -f "$from/$dir/$id.md"
|
|
305
|
+
printf '%s\n' "$id"
|
|
306
|
+
done
|
|
307
|
+
rmdir "$from/$dir" 2>/dev/null || true
|
|
308
|
+
return 0
|
|
309
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# task-source.sh — the task-source interface for light tasks (#450).
|
|
4
|
+
#
|
|
5
|
+
# A light task is a unit of work that is NOT a GitHub issue. Where its record lives is a SOURCE, and
|
|
6
|
+
# every reader and writer (the `cckit task` verbs in light-task.sh, the gc protection in
|
|
7
|
+
# worktree-issue.sh) reaches it through task_source_call — never through a source's own functions.
|
|
8
|
+
# One source ships: `file` (task-source-file.sh), one tracked file per task.
|
|
9
|
+
#
|
|
10
|
+
# Selecting a source: `tasks.source` in the project config (default `file`); KIT_TASKS_SOURCE in the
|
|
11
|
+
# environment wins per invocation.
|
|
12
|
+
#
|
|
13
|
+
# `tasks.default` is a different question — whether the project's DEFAULT list is this one (`light`)
|
|
14
|
+
# or GitHub issues (`issues`, the default). task_default_name answers it.
|
|
15
|
+
#
|
|
16
|
+
# Adding a source `<name>` (lowercase letters, digits, `_`): add scripts/lib/task-source-<name>.sh
|
|
17
|
+
# defining the functions below, then set `tasks.source` to `<name>`. Nothing else changes: the verbs,
|
|
18
|
+
# the branch form and the gc protection are source-independent.
|
|
19
|
+
#
|
|
20
|
+
# task_<name>_list every task, one TSV row each (format below)
|
|
21
|
+
# task_<name>_get <id|prefix> the one matching row; rc 1 none, rc 3 ambiguous
|
|
22
|
+
# task_<name>_create <title> <priority> <kind> <body> record a new task; print its id
|
|
23
|
+
# task_<name>_on_start <id> <worktree> <from-checkout> work begins in <worktree>
|
|
24
|
+
# task_<name>_on_finish <id> <worktree> work is ready for review
|
|
25
|
+
# task_<name>_state <id> [<branch>] open | closed | unknown | (empty: no such task). rc 0
|
|
26
|
+
# always. gc keeps a branch on `open` and on `unknown`.
|
|
27
|
+
# task_<name>_body <id> <worktree> OPTIONAL: the task's notes, as text. `cckit task run`
|
|
28
|
+
# builds its objective from the title alone without it.
|
|
29
|
+
# task_<name>_share <worktree> <from-checkout> OPTIONAL: move every not-yet-shared task into
|
|
30
|
+
# <worktree>; print one id per line. `cckit task share`
|
|
31
|
+
# refuses when the source does not define it.
|
|
32
|
+
#
|
|
33
|
+
# TSV row: <id>\t<state>\t<priority>\t<kind>\t<created>\t<branch>\t<title>
|
|
34
|
+
# state draft (only in this checkout) · todo · doing · review · done · dropped ·
|
|
35
|
+
# shared (committed by `cckit task share`, its pull request not merged yet)
|
|
36
|
+
# branch the task's `light/<id>-<slug>` ref; for `shared`, the `light/share-<stamp>` ref that
|
|
37
|
+
# carries it; else `-`
|
|
38
|
+
# No field is ever empty (`-` is the absent marker): tab is IFS whitespace, so an empty field would
|
|
39
|
+
# shift the rest. The title is last and may hold spaces.
|
|
40
|
+
#
|
|
41
|
+
# An id is a lowercase letter followed by 1-11 lowercase letters or digits. The leading letter is
|
|
42
|
+
# what keeps a light branch from parsing as an issue number (worktree-issue.sh, wt_issue_number).
|
|
43
|
+
#
|
|
44
|
+
# Requires: git; jq for the config read (without it the defaults apply). bash 3.2 + zsh.
|
|
45
|
+
# errors: mixed — the dispatcher returns 2 for an unknown source or op; each op states its own
|
|
46
|
+
|
|
47
|
+
_TASK_SOURCE_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
|
|
48
|
+
|
|
49
|
+
# _task_source_cfg <jq-filter> <default> — one key of the project config, or the default.
|
|
50
|
+
_task_source_cfg() {
|
|
51
|
+
local cfg="${KIT_CONFIG:-}" top v=""
|
|
52
|
+
if [ -z "$cfg" ] || [ ! -f "$cfg" ]; then
|
|
53
|
+
top="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
54
|
+
if [ -n "$top" ] && [ -f "$top/cckit.config.json" ]; then cfg="$top/cckit.config.json"
|
|
55
|
+
elif [ -n "$top" ] && [ -f "$top/.claude/kit.config.json" ]; then cfg="$top/.claude/kit.config.json"
|
|
56
|
+
else cfg=""; fi
|
|
57
|
+
fi
|
|
58
|
+
if [ -n "$cfg" ] && command -v jq >/dev/null 2>&1; then
|
|
59
|
+
v="$(jq -r "$1 // empty" "$cfg" 2>/dev/null || true)"
|
|
60
|
+
fi
|
|
61
|
+
printf '%s' "${v:-$2}"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# task_source_name — the selected source.
|
|
65
|
+
task_source_name() {
|
|
66
|
+
if [ -n "${KIT_TASKS_SOURCE:-}" ]; then printf '%s' "$KIT_TASKS_SOURCE"; return 0; fi
|
|
67
|
+
_task_source_cfg '.tasks.source' file
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# task_default_name — which task list is this project's default: `light` (the `cckit task` list) or
|
|
71
|
+
# `issues` (GitHub issues). `tasks.default` in the project config; anything else, or no key, is
|
|
72
|
+
# `issues`, with a warning for a value that is neither. `cckit next` and the campaign skill read it
|
|
73
|
+
# to pick their lane; both lists stay usable whatever it says.
|
|
74
|
+
task_default_name() {
|
|
75
|
+
local v; v="$(_task_source_cfg '.tasks.default' issues)"
|
|
76
|
+
case "$v" in
|
|
77
|
+
light|issues) printf '%s' "$v" ;;
|
|
78
|
+
*) echo "⚠ tasks.default '$v' is neither 'light' nor 'issues' — using 'issues'" >&2; printf 'issues' ;;
|
|
79
|
+
esac
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# task_source_dir — the tracked directory the file source keeps tasks in, relative to the checkout
|
|
83
|
+
# root (`tasks.dir`, default `tasks`; KIT_TASKS_DIR wins). A value that is absolute or climbs out
|
|
84
|
+
# of the checkout is ignored with a warning.
|
|
85
|
+
task_source_dir() {
|
|
86
|
+
local d="${KIT_TASKS_DIR:-}"
|
|
87
|
+
[ -n "$d" ] || d="$(_task_source_cfg '.tasks.dir' tasks)"
|
|
88
|
+
d="${d%/}"
|
|
89
|
+
case "$d" in
|
|
90
|
+
''|/*|..|../*|*/..|*/../*)
|
|
91
|
+
echo "⚠ tasks.dir '$d' is not a path inside the project — using 'tasks'" >&2; d="tasks" ;;
|
|
92
|
+
esac
|
|
93
|
+
printf '%s' "$d"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# task_id_valid <id> — rc 0 for a usable task id. `share` is reserved: `light/share-<stamp>` is the
|
|
97
|
+
# branch `cckit task share` opens its pull request from.
|
|
98
|
+
task_id_valid() {
|
|
99
|
+
case "${1:-}" in ''|[!a-z]*|*[!a-z0-9]*|share) return 1 ;; esac
|
|
100
|
+
[ "${#1}" -ge 2 ] && [ "${#1}" -le 12 ]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# task_source_has <op> — rc 0 when the selected source defines <op>.
|
|
104
|
+
task_source_has() {
|
|
105
|
+
local src fn
|
|
106
|
+
src="$(task_source_name)"
|
|
107
|
+
case "$src" in ''|*[!a-z0-9_]*) return 1 ;; esac
|
|
108
|
+
fn="task_${src}_$1"
|
|
109
|
+
if ! command -v "$fn" >/dev/null 2>&1 && [ -f "$_TASK_SOURCE_LIB_DIR/task-source-$src.sh" ]; then
|
|
110
|
+
# shellcheck source=/dev/null
|
|
111
|
+
. "$_TASK_SOURCE_LIB_DIR/task-source-$src.sh"
|
|
112
|
+
fi
|
|
113
|
+
command -v "$fn" >/dev/null 2>&1
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# task_source_call <op> [args…] — run <op> on the selected source. rc 2 when the source name is not
|
|
117
|
+
# a name, or the source does not define the op.
|
|
118
|
+
task_source_call() {
|
|
119
|
+
local op="${1:-}" src
|
|
120
|
+
[ "$#" -gt 0 ] && shift
|
|
121
|
+
src="$(task_source_name)"
|
|
122
|
+
case "$src" in
|
|
123
|
+
''|*[!a-z0-9_]*) echo "✗ tasks.source '$src' is not a source name (lowercase letters, digits, _)" >&2; return 2 ;;
|
|
124
|
+
esac
|
|
125
|
+
if ! task_source_has "$op"; then
|
|
126
|
+
echo "✗ task source '$src' has no '$op' (expected task_${src}_$op in scripts/lib/task-source-$src.sh)" >&2
|
|
127
|
+
return 2
|
|
128
|
+
fi
|
|
129
|
+
"task_${src}_$op" "$@"
|
|
130
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# upgrade-report-test.sh — unit tests for scripts/lib/upgrade-report.sh (#448). Runs under bash AND zsh.
|
|
4
|
+
#
|
|
5
|
+
# upgrade_snapshot / upgrade_changes the before/after measurement `cckit init --upgrade` prints
|
|
6
|
+
# json_write_minimal a JSON write that changes as few lines as the change needs
|
|
7
|
+
#
|
|
8
|
+
# The end-to-end use of both is scripts/update-path-test.sh. Everything lives under one mktemp dir.
|
|
9
|
+
# Run: bash scripts/lib/upgrade-report-test.sh
|
|
10
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
11
|
+
ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/../.." && pwd)
|
|
12
|
+
|
|
13
|
+
if [ -n "${UPGRADE_REPORT_TEST_INNER:-}" ]; then
|
|
14
|
+
set -u
|
|
15
|
+
sh_name="$UPGRADE_REPORT_TEST_INNER"
|
|
16
|
+
fail=0
|
|
17
|
+
t() { if [ "$2" = "$3" ]; then echo "ok($sh_name): $1"; else echo "FAIL($sh_name): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
18
|
+
# shellcheck source=/dev/null
|
|
19
|
+
. "$ROOT/scripts/lib/upgrade-report.sh"
|
|
20
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
21
|
+
p="$tmp/proj"; mkdir -p "$p/.claude/rules" "$p/.claude/worktrees/other/.claude" "$p/scripts/node_modules/x" "$p/src"
|
|
22
|
+
|
|
23
|
+
# ── snapshot + changes ───────────────────────────────────────────────────────────────────────
|
|
24
|
+
printf 'one\n' > "$p/.claude/rules/a.md"
|
|
25
|
+
printf 'keep\n' > "$p/.claude/rules/with space.md"
|
|
26
|
+
printf 'x\n' > "$p/CLAUDE.md"
|
|
27
|
+
printf 'x\n' > "$p/scripts/run.sh"
|
|
28
|
+
printf 'x\n' > "$p/.claude/worktrees/other/.claude/in-another-checkout.md"
|
|
29
|
+
printf 'x\n' > "$p/scripts/node_modules/x/index.js"
|
|
30
|
+
printf 'x\n' > "$p/src/app.js"
|
|
31
|
+
upgrade_snapshot "$p" > "$tmp/before"
|
|
32
|
+
t "snapshot lists the kit-managed files, by path" "$(cut -f1 "$tmp/before" | tr '\n' '|')" \
|
|
33
|
+
".claude/rules/a.md|.claude/rules/with space.md|CLAUDE.md|scripts/run.sh|"
|
|
34
|
+
t "snapshot of a directory with none of the paths is empty, rc 0" "$(upgrade_snapshot "$tmp"; echo "rc=$?")" "rc=0"
|
|
35
|
+
|
|
36
|
+
printf 'two\n' > "$p/.claude/rules/a.md" # modified
|
|
37
|
+
printf 'new\n' > "$p/.claude/rules/b.md" # added
|
|
38
|
+
mkdir -p "$p/knowledge"; printf 'n\n' > "$p/knowledge/INDEX.md" # added, a root that was absent
|
|
39
|
+
rm -f "$p/scripts/run.sh" # deleted
|
|
40
|
+
printf 'y\n' > "$p/src/app.js" # outside the managed paths
|
|
41
|
+
printf 'y\n' > "$p/.claude/worktrees/other/.claude/in-another-checkout.md"
|
|
42
|
+
upgrade_snapshot "$p" > "$tmp/after"
|
|
43
|
+
upgrade_changes "$tmp/before" "$tmp/after" > "$tmp/changes"
|
|
44
|
+
t "changes: A / M / D by path, nothing else" "$(tr '\t\n' ' |' < "$tmp/changes")" \
|
|
45
|
+
"M .claude/rules/a.md|A .claude/rules/b.md|A knowledge/INDEX.md|D scripts/run.sh|"
|
|
46
|
+
t "print: heading carries the counts" "$(upgrade_changes_print "$tmp/changes" "Changed on disk" | sed -n 1p)" \
|
|
47
|
+
" Changed on disk (2 added, 1 modified, 1 deleted):"
|
|
48
|
+
t "print: one row per change" "$(upgrade_changes_print "$tmp/changes" "Changed on disk" | sed -n 2p)" " M .claude/rules/a.md"
|
|
49
|
+
: > "$tmp/none"
|
|
50
|
+
t "print: no change says so" "$(upgrade_changes_print "$tmp/none" "Would change" | tr '\n' '|')" \
|
|
51
|
+
" Would change (0 added, 0 modified):| (nothing)|"
|
|
52
|
+
|
|
53
|
+
# ── json_write_minimal ───────────────────────────────────────────────────────────────────────
|
|
54
|
+
# The project's own formatting: inline arrays, its own key order.
|
|
55
|
+
orig() {
|
|
56
|
+
cat > "$tmp/cfg.json" <<'JSON'
|
|
57
|
+
{
|
|
58
|
+
"kitVersion": "0.7.1",
|
|
59
|
+
"roles": ["PM", "Generalist"],
|
|
60
|
+
"review": { "bots": ["one", "two"] },
|
|
61
|
+
"note": "a \"quoted\" kitVersion: 0.7.1",
|
|
62
|
+
"milestones": ["Backlog", "Doing", "Done"]
|
|
63
|
+
}
|
|
64
|
+
JSON
|
|
65
|
+
}
|
|
66
|
+
changed_lines() { diff "$tmp/cfg.orig" "$tmp/cfg.json" | grep -c '^[<>]'; }
|
|
67
|
+
|
|
68
|
+
orig; cp "$tmp/cfg.json" "$tmp/cfg.orig"
|
|
69
|
+
jq '.kitVersion = "0.9.0"' "$tmp/cfg.json" > "$tmp/m.json"
|
|
70
|
+
t "one string key differs -> in-place" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "in-place"
|
|
71
|
+
t "…one line removed, one added" "$(changed_lines)" "2"
|
|
72
|
+
t "…the value is the merged one" "$(jq -c . "$tmp/cfg.json")" "$(jq -c '.kitVersion = "0.9.0"' "$tmp/cfg.orig")"
|
|
73
|
+
t "…the merged temp file is consumed" "$([ -e "$tmp/m.json" ] && echo left || echo gone)" "gone"
|
|
74
|
+
|
|
75
|
+
orig
|
|
76
|
+
jq . "$tmp/cfg.json" > "$tmp/m.json"
|
|
77
|
+
t "same value, different formatting -> unchanged" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "unchanged"
|
|
78
|
+
t "…the file is byte-identical" "$(cmp -s "$tmp/cfg.orig" "$tmp/cfg.json" && echo same || echo differs)" "same"
|
|
79
|
+
|
|
80
|
+
orig
|
|
81
|
+
jq '.kitVersion = "0.9.0" | .knowledge = {dir: "knowledge"}' "$tmp/cfg.json" > "$tmp/m.json"
|
|
82
|
+
t "a key is added -> rewritten" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
|
|
83
|
+
t "…and holds the merged value" "$(jq -r '.knowledge.dir + " " + .kitVersion' "$tmp/cfg.json")" "knowledge 0.9.0"
|
|
84
|
+
|
|
85
|
+
orig
|
|
86
|
+
jq '.review.bots = ["one"]' "$tmp/cfg.json" > "$tmp/m.json"
|
|
87
|
+
t "a nested value differs -> rewritten" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
|
|
88
|
+
t "…and holds the merged value" "$(jq -c '.review.bots' "$tmp/cfg.json")" '["one"]'
|
|
89
|
+
|
|
90
|
+
# A value with characters a careless substitution would mangle.
|
|
91
|
+
orig
|
|
92
|
+
jq '.note = "back\\slash $1 & \"q\" /"' "$tmp/cfg.json" > "$tmp/m.json"
|
|
93
|
+
t "a string with quotes, backslash, \$1 and & -> in-place" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "in-place"
|
|
94
|
+
t "…and it round-trips" "$(jq -r .note "$tmp/cfg.json")" 'back\slash $1 & "q" /'
|
|
95
|
+
t "…one line removed, one added" "$(changed_lines)" "2"
|
|
96
|
+
|
|
97
|
+
# The first textual match is not the top-level key: the in-place result fails its own check and
|
|
98
|
+
# the write falls back to the whole document. The file never ends up holding a wrong value.
|
|
99
|
+
printf '{\n "inner": { "kitVersion": "nested" },\n "kitVersion": "0.7.1"\n}\n' > "$tmp/cfg.json"
|
|
100
|
+
jq '.kitVersion = "0.9.0"' "$tmp/cfg.json" > "$tmp/m.json"
|
|
101
|
+
t "a nested key of the same name comes first -> rewritten, not mis-edited" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
|
|
102
|
+
t "…both values are right" "$(jq -r '.inner.kitVersion + " " + .kitVersion' "$tmp/cfg.json")" "nested 0.9.0"
|
|
103
|
+
|
|
104
|
+
rm -f "$tmp/cfg.json"
|
|
105
|
+
printf '{"a":1}\n' > "$tmp/m.json"
|
|
106
|
+
t "no file yet -> rewritten (created)" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
|
|
107
|
+
t "…created with the merged value" "$(jq -c . "$tmp/cfg.json")" '{"a":1}'
|
|
108
|
+
|
|
109
|
+
[ "$fail" = "0" ] && echo "ALL OK($sh_name)" || { echo "upgrade-report($sh_name): FAILURES"; exit 1; }
|
|
110
|
+
exit 0
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
command -v jq >/dev/null 2>&1 || { echo "upgrade-report-test: jq absent — skipping"; exit 0; }
|
|
114
|
+
rc=0
|
|
115
|
+
for sh in bash zsh; do
|
|
116
|
+
command -v "$sh" >/dev/null 2>&1 || { echo "--- $sh --- (not installed, skipped)"; continue; }
|
|
117
|
+
echo "--- $sh ---"
|
|
118
|
+
UPGRADE_REPORT_TEST_INNER="$sh" "$sh" "$0" || rc=1
|
|
119
|
+
done
|
|
120
|
+
exit "$rc"
|