@softure-ai/skills 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/WORKFLOW.md +308 -0
  4. package/package.json +31 -4
  5. package/rules/AGENTS.md +78 -0
  6. package/scripts/install.mjs +151 -0
  7. package/scripts/uninstall.mjs +49 -0
  8. package/skills/softure-archive/SKILL.md +100 -0
  9. package/skills/softure-code-review/SKILL.md +124 -0
  10. package/skills/softure-frame/SKILL.md +113 -0
  11. package/skills/softure-impl-review/SKILL.md +150 -0
  12. package/skills/softure-implement/SKILL.md +141 -0
  13. package/skills/softure-init/SKILL.md +131 -0
  14. package/skills/softure-lesson/SKILL.md +99 -0
  15. package/skills/softure-new/SKILL.md +127 -0
  16. package/skills/softure-plan/SKILL.md +157 -0
  17. package/skills/softure-plan/references/progress-format.md +79 -0
  18. package/skills/softure-plan-review/SKILL.md +152 -0
  19. package/skills/softure-prd/SKILL.md +132 -0
  20. package/skills/softure-research/SKILL.md +165 -0
  21. package/skills/softure-roadmap/SKILL.md +128 -0
  22. package/skills/softure-rule-review/SKILL.md +121 -0
  23. package/skills/softure-shape/SKILL.md +128 -0
  24. package/skills/softure-worktree/SKILL.md +888 -0
  25. package/skills/softure-worktree/scripts/wt-integration.sh +59 -0
  26. package/skills/softure-worktree/scripts/wt-open.sh +57 -0
  27. package/skills/softure-worktree/scripts/wt-roadmap.py +301 -0
  28. package/skills/softure-worktree/scripts/wt-status.sh +70 -0
  29. package/skills/softure-worktree/scripts/wt_config.py +109 -0
  30. package/skills/softure-worktree-manager/SKILL.md +553 -0
  31. package/skills/softure-worktree-manager/scripts/wm-launch.sh +52 -0
  32. package/skills/softure-worktree-manager/scripts/wm-report.sh +45 -0
  33. package/skills/softure-worktree-manager/scripts/wm-resume.sh +132 -0
  34. package/skills/softure-worktree-manager/scripts/wm-watch.sh +49 -0
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # Run the project's full integration suite for the current HEAD, as configured in
3
+ # context/workflow.json (`integration.remote`, else `integration.local`).
4
+ #
5
+ # wt-integration.sh <name> [--wait <minutes>] # default 30
6
+ #
7
+ # Run it from inside the tree to test (cd <WT> && bash …/wt-integration.sh <change-id>).
8
+ #
9
+ # `integration.remote` — a project command that runs the suite elsewhere (CI) for the
10
+ # committed HEAD and waits for the result. It receives INTEGRATION_NAME, INTEGRATION_SHA and
11
+ # INTEGRATION_WAIT_MINUTES in the environment and must follow this contract:
12
+ # exit 0 green · 1 red (or the run could not start) · 75 no result in time
13
+ # stdout lines (optional, used by the READY report):
14
+ # integration: green|red counts: <passed>/<total> run: <url>
15
+ # flaky: <test> red: <test> new-red: <test> (new-red = red and absent from the
16
+ # latest result on the main branch; when the command cannot tell, it prints none and
17
+ # every red counts as new)
18
+ # `integration.local` — runs in this tree; exit 0 green, anything else red (mapped to 1).
19
+ #
20
+ # Exit codes: 0 green · 1 red · 75 no result in time (retry later, never bypass) ·
21
+ # 78 not configured · 2 bad call.
22
+ set -uo pipefail
23
+
24
+ SCRIPTS="$(cd "$(dirname "$0")" && pwd)"
25
+ CFG() { python3 "$SCRIPTS/wt_config.py" "$@"; }
26
+
27
+ NAME="${1:-}"
28
+ [ -n "$NAME" ] || { sed -n '2,24p' "$0"; exit 2; }
29
+ shift
30
+ WAIT=30
31
+ [ "${1:-}" = "--wait" ] && { WAIT="$2"; shift 2; }
32
+ case "$NAME" in *[!a-zA-Z0-9._/-]*) echo "name: letters, digits, . _ - / only" >&2; exit 2 ;; esac
33
+
34
+ ROOT="$(git rev-parse --show-toplevel)"
35
+ SHA="$(git rev-parse HEAD)"
36
+ REMOTE="$(CFG integration.remote)"
37
+ LOCAL="$(CFG integration.local)"
38
+
39
+ [ -z "$(git status --porcelain --untracked-files=no)" ] \
40
+ || echo "⚠ uncommitted changes are NOT part of the run — commit ${SHA:0:8} is what gets tested" >&2
41
+
42
+ if [ -n "$REMOTE" ]; then
43
+ echo "▸ integration (remote) for ${SHA:0:8} as '$NAME': $REMOTE"
44
+ ( cd "$ROOT" && INTEGRATION_NAME="$NAME" INTEGRATION_SHA="$SHA" INTEGRATION_WAIT_MINUTES="$WAIT" bash -c "$REMOTE" )
45
+ RC=$?
46
+ echo "commit: $SHA"
47
+ case "$RC" in 0|1|75) exit "$RC" ;; *) echo "✗ remote integration command exited $RC — treated as red" >&2; exit 1 ;; esac
48
+ fi
49
+
50
+ if [ -n "$LOCAL" ]; then
51
+ echo "▸ integration (local) for ${SHA:0:8}: $LOCAL"
52
+ if ( cd "$ROOT" && bash -c "$LOCAL" ); then
53
+ echo "integration: green"; echo "commit: $SHA"; exit 0
54
+ fi
55
+ echo "integration: red"; echo "commit: $SHA"; exit 1
56
+ fi
57
+
58
+ echo "integration: not configured (context/workflow.json → integration.local / integration.remote)" >&2
59
+ exit 78
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+ # Create a change worktree next to the main repo and prepare it for work.
3
+ #
4
+ # wt-open.sh <change-id> [--base <ref>]
5
+ #
6
+ # Worktree: ../<repo>-<change-id>, branch <change-id>, base = the main branch from
7
+ # context/workflow.json (--base <branch> for a change that depends on another, unmerged one).
8
+ #
9
+ # Then runs every command from `worktree.setup` inside it ({repo} expands to the main repo's
10
+ # folder name, e.g. "cp ../{repo}/.env .env", "npm ci"). Ends with `git status --short`:
11
+ # an empty result is the condition for exit 0 — a fresh worktree holds nobody's work.
12
+ set -euo pipefail
13
+
14
+ SCRIPTS="$(cd "$(dirname "$0")" && pwd)"
15
+ CFG() { python3 "$SCRIPTS/wt_config.py" "$@"; }
16
+
17
+ CHANGE_ID="${1:-}"
18
+ [ -n "$CHANGE_ID" ] || { echo "usage: wt-open.sh <change-id> [--base <ref>]" >&2; exit 2; }
19
+ shift
20
+ MAIN="$(CFG --root)"
21
+ BASE="$(CFG mainBranch)"
22
+ while [ $# -gt 0 ]; do
23
+ case "$1" in
24
+ --base) BASE="$2"; shift 2 ;;
25
+ *) echo "unknown option: $1" >&2; exit 2 ;;
26
+ esac
27
+ done
28
+
29
+ REPO="$(basename "$MAIN")"
30
+ WT="$(dirname "$MAIN")/$REPO-$CHANGE_ID"
31
+
32
+ if git -C "$MAIN" show-ref --verify --quiet "refs/heads/$CHANGE_ID"; then
33
+ echo "branch $CHANGE_ID already exists — this is a resume, not an open (wt-status.sh)" >&2; exit 3
34
+ fi
35
+ if [ -e "$WT" ]; then
36
+ echo "directory $WT already exists — find out whose it is before doing anything" >&2; exit 3
37
+ fi
38
+
39
+ git -C "$MAIN" worktree add -q -b "$CHANGE_ID" "$WT" "$BASE"
40
+ echo "worktree: $WT (branch $CHANGE_ID from $BASE @ $(git -C "$WT" rev-parse --short HEAD))"
41
+
42
+ while IFS= read -r STEP; do
43
+ [ -n "$STEP" ] || continue
44
+ CMD="${STEP//\{repo\}/$REPO}"
45
+ echo "setup: $CMD"
46
+ ( cd "$WT" && bash -c "$CMD" ) 2>&1 | tail -5
47
+ done < <(CFG worktree.setup)
48
+
49
+ DIRTY="$(git -C "$WT" status --short)"
50
+ if [ -n "$DIRTY" ]; then
51
+ echo "worktree is not clean after setup:" >&2
52
+ echo "$DIRTY" >&2
53
+ echo "A fresh worktree holds nobody's work — a setup step (an installer, a generator) wrote tracked files. Restore them (git -C \"$WT\" restore -- <paths>) and fix the setup step." >&2
54
+ exit 4
55
+ fi
56
+ echo "ready — worktree clean"
57
+ echo "WT=$WT"
@@ -0,0 +1,301 @@
1
+ #!/usr/bin/env python3
2
+ """Mark one roadmap item on the main branch and commit ONLY that edit.
3
+
4
+ wt-roadmap.py open <change-id> [--note "…"] [--dry-run]
5
+ wt-roadmap.py stage <change-id> "<stage>" [--dry-run]
6
+ wt-roadmap.py ready <change-id> [--dry-run]
7
+ (cloud sessions additionally: [--cloud] [--branch <branch>] — see below)
8
+
9
+ `open` — status -> **in_progress** (research, since <today>; worktree `../<repo>-<id>`, branch `<id>`[; note])
10
+ `stage` — replaces only the stage inside the parentheses: research -> frame -> plan -> plan-review ->
11
+ implement N/M -> impl-review -> integration -> archive (WORKFLOW.md §5)
12
+ `ready` — **in_progress** (<stage>, since …; <where>) -> **ready_to_merge** (since <today>; <where>)
13
+
14
+ Why a script instead of editing the file: sessions in worktrees used to edit the main tree's
15
+ roadmap without committing. Someone else's uncommitted rows then sat in `roadmap.md`, every
16
+ following session had to work around them, and merges conflicted. Here the commit is built
17
+ from HEAD plus one edit (hash-object -> update-index), so other sessions' uncommitted lines in
18
+ the working file never ride along; the same edit is applied to the working file too, so it does
19
+ not look like it reverts the commit.
20
+
21
+ Always works on the main worktree (first entry of `git worktree list`), whichever worktree
22
+ calls it. The main branch name comes from context/workflow.json (`mainBranch`).
23
+
24
+ **Cloud session** (`CLAUDE_CODE_REMOTE=true` or `--cloud`): there is no main tree on the main
25
+ branch and no other session in this container — the other sessions are other containers that
26
+ see only `origin`. The commit is then built directly on `origin/<main>` (fetch -> one edit ->
27
+ `commit-tree` on a temporary index) and **pushed at once**; the working tree and the current
28
+ branch stay untouched. A rejected push (someone pushed meanwhile) -> fetch and retry from the
29
+ fresh state. `--branch <name>` overrides the branch written into the row (default: current).
30
+ """
31
+ from __future__ import annotations
32
+
33
+ import datetime as dt
34
+ import difflib
35
+ import os
36
+ import re
37
+ import subprocess
38
+ import sys
39
+ import tempfile
40
+ import time
41
+
42
+ sys.dont_write_bytecode = True # no __pycache__ inside the consumer's .claude/skills
43
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
44
+ from wt_config import main_branch, main_root # noqa: E402
45
+
46
+ ROADMAP = "context/foundation/roadmap.md"
47
+ COAUTHOR = "Co-Authored-By: Claude <noreply@anthropic.com>"
48
+
49
+ ROW_RE = re.compile(r"^(?P<head>\|.*\|\s*)(?P<status>[^|]*?)(?P<tail>\s*\|\s*)$")
50
+ ID_RE = re.compile(r"^\| \*\*([A-Z]+-\d+)\*\* \|")
51
+ STAGE_RE = re.compile(r"(in_progress\*{0,2} \()([^,;)]*)(, since )")
52
+ READY_RE = re.compile(r"(\*{0,2})in_progress(\*{0,2}) \([^,;)]*, since [0-9-]+; ")
53
+
54
+
55
+ def git(repo: str, *args: str, env: dict[str, str] | None = None) -> str:
56
+ return subprocess.run(
57
+ ["git", "-C", repo, *args], check=True, capture_output=True, text=True, env=env
58
+ ).stdout
59
+
60
+
61
+ def find_row(lines: list[str], change_id: str) -> int:
62
+ needle = f"| `{change_id}` |"
63
+ hits = [i for i, line in enumerate(lines) if line.startswith("|") and needle in line]
64
+ if len(hits) != 1:
65
+ sys.exit(f"the roadmap table has {len(hits)} rows with `{change_id}` — expected exactly 1")
66
+ return hits[0]
67
+
68
+
69
+ def set_row_status(line: str, new_status: str) -> str:
70
+ match = ROW_RE.match(line.rstrip("\n"))
71
+ if not match:
72
+ sys.exit(f"cannot parse table row: {line[:120]}")
73
+ return f"{match['head']}{new_status}{match['tail']}\n"
74
+
75
+
76
+ def row_status(line: str) -> str:
77
+ match = ROW_RE.match(line.rstrip("\n"))
78
+ return match["status"] if match else ""
79
+
80
+
81
+ def item_id(line: str, change_id: str) -> str:
82
+ match = ID_RE.match(line)
83
+ return match.group(1) if match else change_id
84
+
85
+
86
+ def edit(text: str, mode: str, change_id: str, arg: str | None, repo_name: str,
87
+ cloud_branch: str | None = None) -> str:
88
+ lines = text.splitlines(keepends=True)
89
+ i = find_row(lines, change_id)
90
+ today = dt.date.today().isoformat()
91
+ body_status = None
92
+
93
+ if mode == "open":
94
+ current = row_status(lines[i])
95
+ if any(word in current for word in ("in_progress", "ready_to_merge", "done")):
96
+ sys.exit(f"item `{change_id}` already has status: {current.strip()[:100]}")
97
+ note = f"; {arg}" if arg else ""
98
+ if cloud_branch:
99
+ where = f"cloud session, branch `{cloud_branch}` — do not take in another session"
100
+ else:
101
+ where = f"worktree `../{repo_name}-{change_id}`, branch `{change_id}`"
102
+ lines[i] = set_row_status(lines[i], f"**in_progress** (research, since {today}; {where}{note})")
103
+ body_status = f"- **Status:** in_progress (research, since {today}; {where}{note})\n"
104
+ elif mode == "stage":
105
+ new, count = STAGE_RE.subn(lambda m: f"{m[1]}{arg}{m[3]}", lines[i], count=1)
106
+ if count != 1:
107
+ sys.exit(f"row `{change_id}` has no `in_progress (<stage>, since …)` status — run `open` first")
108
+ lines[i] = new
109
+ else: # ready
110
+ new, count = READY_RE.subn(lambda m: f"{m[1]}ready_to_merge{m[2]} (since {today}; ", lines[i], count=1)
111
+ if count != 1:
112
+ sys.exit(f"row `{change_id}` is not `in_progress (<stage>, since …; …)` — nothing to mark ready")
113
+ lines[i] = new
114
+
115
+ # Item block (if present): the `- **Status:**` line under `- **Change ID:** `<id>``.
116
+ cid = next((k for k, line in enumerate(lines) if line.strip() == f"- **Change ID:** `{change_id}`"), None)
117
+ if cid is not None:
118
+ end = next(
119
+ (k for k in range(cid + 1, len(lines)) if lines[k].startswith(("#", "- **Change ID:**"))),
120
+ len(lines),
121
+ )
122
+ sidx = next((k for k in range(cid + 1, end) if lines[k].startswith("- **Status:**")), None)
123
+ if mode == "open":
124
+ if sidx is None:
125
+ lines.insert(cid + 1, body_status)
126
+ else:
127
+ lines[sidx] = body_status
128
+ elif sidx is not None and mode == "stage":
129
+ lines[sidx] = STAGE_RE.sub(lambda m: f"{m[1]}{arg}{m[3]}", lines[sidx], count=1)
130
+ elif sidx is not None:
131
+ lines[sidx] = READY_RE.sub(lambda m: f"{m[1]}ready_to_merge{m[2]} (since {today}; ", lines[sidx], count=1)
132
+
133
+ out = "".join(lines)
134
+ return re.sub(r"(?m)^updated: .*$", f"updated: {today}", out, count=1)
135
+
136
+
137
+ def commit_message(text: str, mode: str, change_id: str, arg: str | None, where: str) -> str:
138
+ lines = text.splitlines(keepends=True)
139
+ rid = item_id(lines[find_row(lines, change_id)], change_id)
140
+ label = {"open": f"in_progress ({where})", "stage": arg or "", "ready": "ready_to_merge"}[mode]
141
+ return f"docs(roadmap): {rid} {label}\n\n{COAUTHOR}"
142
+
143
+
144
+ def push_roadmap_commit(repo: str, sha: str, main: str, env: dict[str, str]) -> subprocess.CompletedProcess:
145
+ """Push `sha` to `origin/<main>` from a throwaway worktree, never from the session checkout.
146
+
147
+ Pre-push hooks commonly compute the pushed files as `git diff HEAD @{push}` — from HEAD, not
148
+ from the commit being sent. From the session checkout HEAD is a branch full of code, so the
149
+ hook would run the whole test suite for a roadmap-only commit; from a detached HEAD
150
+ `@{push}` does not resolve and hooks treat the push as "all files". Here HEAD = `sha`,
151
+ upstream = `origin/<main>` and `push.default=upstream`, so the diff is the roadmap alone.
152
+ Hooks stay enabled — nothing here uses `--no-verify`.
153
+ """
154
+ tmpdir = tempfile.mkdtemp(prefix="wt-roadmap-")
155
+ branch = f"wt-roadmap-{os.getpid()}"
156
+ try:
157
+ git(repo, "worktree", "add", "-q", "-b", branch, tmpdir, sha)
158
+ git(tmpdir, "branch", "-q", f"--set-upstream-to=origin/{main}")
159
+ return subprocess.run(
160
+ ["git", "-C", tmpdir, "-c", "push.default=upstream", "push", "-q", "origin", f"{branch}:{main}"],
161
+ capture_output=True, text=True, env=env,
162
+ )
163
+ finally:
164
+ subprocess.run(["git", "-C", repo, "worktree", "remove", "--force", tmpdir], capture_output=True)
165
+ subprocess.run(["git", "-C", repo, "branch", "-D", branch], capture_output=True)
166
+
167
+
168
+ def run_cloud(mode: str, change_id: str, arg: str | None, branch: str | None, dry: bool) -> None:
169
+ """Commit one roadmap edit directly on `origin/<main>` and push it — no working tree involved."""
170
+ repo = git(".", "rev-parse", "--show-toplevel").strip()
171
+ repo_name = os.path.basename(repo)
172
+ main = main_branch(repo)
173
+ if branch is None:
174
+ branch = git(repo, "rev-parse", "--abbrev-ref", "HEAD").strip()
175
+ env = dict(os.environ)
176
+ push = None
177
+ for attempt in range(6):
178
+ git(repo, "fetch", "-q", "origin", main)
179
+ base = git(repo, "rev-parse", f"origin/{main}").strip()
180
+ old = git(repo, "show", f"{base}:{ROADMAP}")
181
+ new = edit(old, mode, change_id, arg, repo_name, cloud_branch=branch if mode == "open" else None)
182
+ if dry:
183
+ sys.stdout.writelines(difflib.unified_diff(old.splitlines(True), new.splitlines(True), f"origin/{main}", "commit"))
184
+ return
185
+ msg = commit_message(old, mode, change_id, arg, f"cloud session, branch {branch}")
186
+ session = os.environ.get("CLAUDE_CODE_REMOTE_SESSION_ID", "")
187
+ if session.startswith("cse_"):
188
+ msg += f"\nClaude-Session: https://claude.ai/code/session_{session[4:]}"
189
+ with tempfile.TemporaryDirectory() as tmpdir:
190
+ index_env = {**env, "GIT_INDEX_FILE": os.path.join(tmpdir, "index")}
191
+ blob_path = os.path.join(tmpdir, "roadmap.md")
192
+ with open(blob_path, "w", encoding="utf-8") as fh:
193
+ fh.write(new)
194
+ git(repo, "read-tree", base, env=index_env)
195
+ blob = git(repo, "hash-object", "-w", blob_path, env=index_env).strip()
196
+ git(repo, "update-index", "--cacheinfo", f"100644,{blob},{ROADMAP}", env=index_env)
197
+ tree = git(repo, "write-tree", env=index_env).strip()
198
+ sha = git(repo, "commit-tree", tree, "-p", base, "-m", msg, env=index_env).strip()
199
+ push = push_roadmap_commit(repo, sha, main, env)
200
+ if push.returncode == 0:
201
+ # Move the local main branch forward only when this session is not standing on it.
202
+ if git(repo, "rev-parse", "--abbrev-ref", "HEAD").strip() != main:
203
+ subprocess.run(["git", "-C", repo, "update-ref", f"refs/heads/{main}", sha], capture_output=True)
204
+ subprocess.run(["git", "-C", repo, "fetch", "-q", "origin", main], capture_output=True)
205
+ print(f"{sha[:8]} {msg.splitlines()[0]} -> origin/{main}")
206
+ return
207
+ time.sleep(2 + attempt * 2)
208
+ sys.exit(f"push to origin/{main} failed after 6 attempts: {push.stderr.strip()[:300] if push else ''}")
209
+
210
+
211
+ def run_local(mode: str, change_id: str, arg: str | None, dry: bool) -> None:
212
+ main_wt = main_root()
213
+ repo_name = os.path.basename(main_wt)
214
+ main = main_branch(main_wt)
215
+ current = git(main_wt, "symbolic-ref", "--short", "HEAD").strip()
216
+ if current != main:
217
+ sys.exit(f"the main tree is on `{current}`, not on `{main}` — not committing")
218
+
219
+ work_path = os.path.join(main_wt, ROADMAP)
220
+ if dry:
221
+ head_text = git(main_wt, "show", f"HEAD:{ROADMAP}")
222
+ new_head = edit(head_text, mode, change_id, arg, repo_name)
223
+ sys.stdout.writelines(difflib.unified_diff(head_text.splitlines(True), new_head.splitlines(True), "HEAD", "commit"))
224
+ return
225
+
226
+ # Several sessions commit stages on the main branch at once. Every attempt re-reads HEAD,
227
+ # checks right before committing that it did not move, and every failure removes its own
228
+ # index entry (`reset -- ROADMAP`) before retrying or exiting — otherwise a lost race leaves
229
+ # a blob staged on the main tree and every later call (of every session) refuses.
230
+ for attempt in range(8):
231
+ staged = subprocess.run(["git", "-C", main_wt, "diff", "--cached", "--quiet"])
232
+ if staged.returncode != 0:
233
+ if attempt < 7:
234
+ time.sleep(3)
235
+ continue
236
+ sys.exit(f"the index on `{main}` holds someone else's staged changes — not committing under them; retry shortly")
237
+
238
+ head_sha = git(main_wt, "rev-parse", "HEAD").strip()
239
+ head_text = git(main_wt, "show", f"{head_sha}:{ROADMAP}")
240
+ new_head = edit(head_text, mode, change_id, arg, repo_name)
241
+ msg = commit_message(head_text, mode, change_id, arg, "separate worktree")
242
+ with open(work_path, encoding="utf-8") as fh:
243
+ work_text = fh.read()
244
+ new_work = new_head if work_text == head_text else edit(work_text, mode, change_id, arg, repo_name)
245
+
246
+ with tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8") as tmp:
247
+ tmp.write(new_head)
248
+ blob = git(main_wt, "hash-object", "-w", tmp.name).strip()
249
+ os.unlink(tmp.name)
250
+
251
+ try:
252
+ git(main_wt, "update-index", "--cacheinfo", f"100644,{blob},{ROADMAP}")
253
+ if git(main_wt, "rev-parse", "HEAD").strip() != head_sha:
254
+ raise subprocess.CalledProcessError(1, "rev-parse", stderr="HEAD moved")
255
+ git(main_wt, "commit", "-q", "-m", msg)
256
+ break
257
+ except subprocess.CalledProcessError as exc:
258
+ subprocess.run(["git", "-C", main_wt, "reset", "-q", "--", ROADMAP])
259
+ if attempt < 7:
260
+ time.sleep(2)
261
+ continue
262
+ sys.exit(f"commit failed (index restored): {exc.stderr}")
263
+ with open(work_path, "w", encoding="utf-8") as fh:
264
+ fh.write(new_work)
265
+ sha = git(main_wt, "rev-parse", "--short", "HEAD").strip()
266
+ print(f"{sha} {msg.splitlines()[0]}")
267
+ if work_text != head_text:
268
+ print(f"note: roadmap.md on `{main}` holds someone else's uncommitted edits — left untouched, outside the commit")
269
+
270
+
271
+ def main() -> None:
272
+ argv = sys.argv[1:]
273
+ dry = "--dry-run" in argv
274
+ cloud = "--cloud" in argv or os.environ.get("CLAUDE_CODE_REMOTE") == "true"
275
+ args = [a for a in argv if a not in ("--dry-run", "--cloud")]
276
+ note = branch = None
277
+ if "--note" in args:
278
+ k = args.index("--note")
279
+ note = args[k + 1]
280
+ del args[k:k + 2]
281
+ if "--branch" in args:
282
+ k = args.index("--branch")
283
+ branch = args[k + 1]
284
+ del args[k:k + 2]
285
+ valid = (
286
+ len(args) >= 2 and args[0] in ("open", "stage", "ready")
287
+ and (args[0] != "stage" or len(args) == 3)
288
+ and (args[0] == "stage" or len(args) == 2)
289
+ )
290
+ if not valid:
291
+ sys.exit(__doc__)
292
+ mode, change_id = args[0], args[1]
293
+ arg = note if mode == "open" else (args[2] if mode == "stage" else None)
294
+ if cloud:
295
+ run_cloud(mode, change_id, arg, branch, dry)
296
+ else:
297
+ run_local(mode, change_id, arg, dry)
298
+
299
+
300
+ if __name__ == "__main__":
301
+ main()
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+ # State of every change worktree at once — for picking an item and for numbering.
3
+ #
4
+ # wt-status.sh # table + next free numbers
5
+ # wt-status.sh --files # also the files each branch changed against the main branch
6
+ #
7
+ # Why: parallel sessions collide on three things that only show at merge time — the same
8
+ # files, lesson numbers and migration numbers. This prints all three before anyone starts.
9
+ set -uo pipefail
10
+
11
+ SCRIPTS="$(cd "$(dirname "$0")" && pwd)"
12
+ CFG() { python3 "$SCRIPTS/wt_config.py" "$@"; }
13
+
14
+ SHOW_FILES=0
15
+ [ "${1:-}" = "--files" ] && SHOW_FILES=1
16
+
17
+ MAIN="$(CFG --root)"
18
+ MAIN_BRANCH="$(CFG mainBranch)"
19
+ MIG_DIR="$(CFG migrations.dir)"
20
+ MIG_PATTERN="$(CFG migrations.pattern)"
21
+ [ -n "$MIG_PATTERN" ] || MIG_PATTERN='^[0-9]+_.*'
22
+ LESSONS="context/foundation/lessons.md"
23
+
24
+ max_lesson() { grep -oE '^#+ *L-[0-9]+' "$1" 2>/dev/null | grep -oE '[0-9]+' | sort -n | tail -1; }
25
+ max_migration() {
26
+ [ -n "$MIG_DIR" ] && [ -d "$1/$MIG_DIR" ] || return 0
27
+ ls "$1/$MIG_DIR" 2>/dev/null | grep -E "$MIG_PATTERN" | grep -oE '^[0-9]+' | sort -n | tail -1
28
+ }
29
+
30
+ L_MAX="$(max_lesson "$MAIN/$LESSONS")"; L_MAX=${L_MAX:-0}
31
+ M_MAX="$(max_migration "$MAIN")"; M_MAX=${M_MAX:-0}
32
+ L_WHO="$MAIN_BRANCH"; M_WHO="$MAIN_BRANCH"
33
+
34
+ printf '%-44s %-32s %-9s %-16s %-6s %s\n' WORKTREE BRANCH "+/-main" "change status" lesson migrations
35
+ git worktree list --porcelain | awk '/^worktree /{w=substr($0,10)} /^branch /{sub("refs/heads/","",$2); print w"\t"$2} /^detached/{print w"\t(detached)"}' |
36
+ while IFS=$'\t' read -r WT BR; do
37
+ [ "$WT" = "$MAIN" ] && continue
38
+ if [ "$BR" = "(detached)" ]; then
39
+ printf '%-44s %-32s %s\n' "$(basename "$WT")" "$BR" "baseline/helper — not a change"
40
+ continue
41
+ fi
42
+ AB="$(git -C "$MAIN" rev-list --left-right --count "$MAIN_BRANCH...$BR" 2>/dev/null | awk '{print "+"$2"/-"$1}')"
43
+ STATUS="$(sed -n 's/^status: *//p' "$WT/context/changes/$BR/change.md" 2>/dev/null | head -1)"
44
+ [ -z "$STATUS" ] && [ -d "$WT/context/archive" ] && ls -d "$WT"/context/archive/*-"$BR" >/dev/null 2>&1 && STATUS="archived"
45
+ L="$(max_lesson "$WT/$LESSONS")"
46
+ MIG="—"
47
+ if [ -n "$MIG_DIR" ]; then
48
+ MIG="$(git -C "$MAIN" diff --name-only --diff-filter=A "$MAIN_BRANCH...$BR" -- "$MIG_DIR" 2>/dev/null \
49
+ | xargs -n1 basename 2>/dev/null | grep -E "$MIG_PATTERN" | tr '\n' ' ')"
50
+ MIG="${MIG:-—}"
51
+ fi
52
+ printf '%-44s %-32s %-9s %-16s %-6s %s\n' "$(basename "$WT")" "$BR" "$AB" "${STATUS:-?}" "L-${L:-?}" "$MIG"
53
+ if [ "$SHOW_FILES" = 1 ]; then
54
+ git -C "$MAIN" diff --name-only "$MAIN_BRANCH...$BR" 2>/dev/null | grep -v '^context/' | sed 's/^/ /'
55
+ fi
56
+ done
57
+
58
+ # Next free numbers: maximum over the main branch and every worktree, plus one.
59
+ while IFS= read -r WT; do
60
+ L="$(max_lesson "$WT/$LESSONS")"; [ -n "$L" ] && [ "$((10#$L))" -gt "$((10#$L_MAX))" ] && L_MAX=$L && L_WHO="$(basename "$WT")"
61
+ M="$(max_migration "$WT")"; [ -n "$M" ] && [ "$((10#$M))" -gt "$((10#$M_MAX))" ] && M_MAX=$M && M_WHO="$(basename "$WT")"
62
+ done < <(git worktree list --porcelain | awk '/^worktree /{print substr($0,10)}')
63
+ echo
64
+ printf 'highest lesson: L-%03d (%s) -> next free: L-%03d\n' "$((10#$L_MAX))" "$L_WHO" "$((10#$L_MAX + 1))"
65
+ if [ -n "$MIG_DIR" ]; then
66
+ echo "highest migration: $M_MAX ($M_WHO) -> whoever merges second renumbers theirs"
67
+ else
68
+ echo "migrations: not configured (context/workflow.json → migrations)"
69
+ fi
70
+ echo "integration: wt-integration.sh <name> — the full suite as configured in context/workflow.json"
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env python3
2
+ """Read the project's workflow configuration (context/workflow.json, see WORKFLOW.md §2).
3
+
4
+ wt_config.py <dotted.key> # scalar -> one line; list -> one item per line; missing/null -> nothing
5
+ wt_config.py --root # absolute path of the main worktree
6
+ wt_config.py --json # the whole resolved config as JSON
7
+
8
+ Always reads the config of the MAIN worktree (first entry of `git worktree list`), so every
9
+ worktree and every script sees the same values. `mainBranch` falls back to origin's HEAD, then
10
+ "main"; `worktree.maxParallel` to 4; `language` to "en".
11
+
12
+ Importable: `from wt_config import load_config, main_root, main_branch`.
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ import subprocess
19
+ import sys
20
+
21
+ CONFIG_PATH = os.path.join("context", "workflow.json")
22
+ DEFAULTS = {"language": "en", "worktree": {"maxParallel": 4, "setup": []}, "release": {"owner": True}}
23
+
24
+
25
+ def main_root() -> str:
26
+ out = subprocess.run(
27
+ ["git", "worktree", "list", "--porcelain"], check=True, capture_output=True, text=True
28
+ ).stdout
29
+ first = out.splitlines()[0] if out else ""
30
+ if not first.startswith("worktree "):
31
+ sys.exit("cannot read `git worktree list` output — run inside a git repository")
32
+ return first[len("worktree "):]
33
+
34
+
35
+ def _detect_main_branch(root: str) -> str:
36
+ ref = subprocess.run(
37
+ ["git", "-C", root, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"],
38
+ capture_output=True, text=True,
39
+ )
40
+ if ref.returncode == 0 and ref.stdout.strip().startswith("origin/"):
41
+ return ref.stdout.strip()[len("origin/"):]
42
+ return "main"
43
+
44
+
45
+ def _merge(base: dict, override: dict) -> dict:
46
+ merged = dict(base)
47
+ for key, value in override.items():
48
+ if isinstance(value, dict) and isinstance(merged.get(key), dict):
49
+ merged[key] = _merge(merged[key], value)
50
+ else:
51
+ merged[key] = value
52
+ return merged
53
+
54
+
55
+ def load_config(root: str | None = None) -> dict:
56
+ root = root or main_root()
57
+ path = os.path.join(root, CONFIG_PATH)
58
+ data: dict = {}
59
+ if os.path.exists(path):
60
+ with open(path, encoding="utf-8") as fh:
61
+ data = json.load(fh)
62
+ config = _merge(DEFAULTS, data)
63
+ if not config.get("mainBranch"):
64
+ config["mainBranch"] = _detect_main_branch(root)
65
+ return config
66
+
67
+
68
+ def main_branch(root: str | None = None) -> str:
69
+ return load_config(root)["mainBranch"]
70
+
71
+
72
+ def lookup(config: dict, dotted: str):
73
+ node = config
74
+ for part in dotted.split("."):
75
+ if not isinstance(node, dict) or part not in node:
76
+ return None
77
+ node = node[part]
78
+ return node
79
+
80
+
81
+ def main() -> None:
82
+ if len(sys.argv) != 2:
83
+ sys.exit(__doc__)
84
+ arg = sys.argv[1]
85
+ if arg == "--root":
86
+ print(main_root())
87
+ return
88
+ config = load_config()
89
+ if arg == "--json":
90
+ print(json.dumps(config, indent=2, ensure_ascii=False))
91
+ return
92
+ value = lookup(config, arg)
93
+ if value is None:
94
+ return
95
+ if isinstance(value, list):
96
+ for item in value:
97
+ print(item)
98
+ elif isinstance(value, dict):
99
+ for key, item in value.items():
100
+ if item is not None:
101
+ print(f"{key}\t{item}")
102
+ elif isinstance(value, bool):
103
+ print("true" if value else "false")
104
+ else:
105
+ print(value)
106
+
107
+
108
+ if __name__ == "__main__":
109
+ main()