@softure-ai/skills 0.19.0 → 0.20.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/ONBOARD.md +1 -1
- package/README.md +25 -0
- package/WORKFLOW.md +141 -6
- package/package.json +2 -1
- package/rules/AGENTS.md +26 -1
- package/scripts/install.mjs +67 -1
- package/scripts/portfolio.py +259 -0
- package/skills/softure-archive/SKILL.md +15 -6
- package/skills/softure-doctor/SKILL.md +69 -0
- package/skills/softure-doctor/references/state.schema.json +125 -0
- package/skills/softure-doctor/scripts/context_state.py +578 -0
- package/skills/softure-doctor/scripts/doctor.py +340 -0
- package/skills/softure-roadmap/SKILL.md +12 -1
- package/skills/softure-worktree/scripts/wt-roadmap.py +66 -5
- package/skills/softure-worktree-manager/SKILL.md +7 -1
- package/skills/softure-worktree-manager/references/report-routine.md +3 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""softure-doctor: check the `context/` contract of a project (WORKFLOW.md §12) and exit non-zero on drift.
|
|
3
|
+
|
|
4
|
+
doctor.py [--root <dir>] [--json]
|
|
5
|
+
npx softure-skills doctor (the same, from the installed package)
|
|
6
|
+
|
|
7
|
+
Adopting projects run it in their CI check, documentation-only changes included (that is where the
|
|
8
|
+
drift happens). `softure-archive` and `softure-roadmap --close` run it before their commit and fix
|
|
9
|
+
what they own. Each problem is one line `FAIL <code> <path>: <what>`; the codes:
|
|
10
|
+
|
|
11
|
+
roadmap-archived-not-removed roadmap.md is still there although the same roadmap is in foundation/archive/
|
|
12
|
+
roadmap-status-mismatch roadmap.md `status` contradicts its rows (done with open rows; waiting)
|
|
13
|
+
archived-change-status an archived change.md whose status is not `archived`
|
|
14
|
+
archived-change-progress an archived plan.md with unticked Automated items in `## Progress`
|
|
15
|
+
archived-roadmap-open-items an archived roadmap with rows that are not done, done_code, dropped or carried
|
|
16
|
+
archived-roadmap-summary an archived roadmap whose `## Summary` merge column holds placeholders, not SHAs
|
|
17
|
+
queued-roadmap-done a queued roadmap in foundation/roadmaps/ whose rows are all done
|
|
18
|
+
backlog-without-roadmap a backlog/roadmap-<slug>/ folder without its queued (or promoted) roadmap
|
|
19
|
+
index-missing-file an index row (README.md / INDEX.md table under context/) links a missing file
|
|
20
|
+
state-missing context/state.json is missing although the project has written it before
|
|
21
|
+
state-stale context/state.json does not match the markdown
|
|
22
|
+
|
|
23
|
+
A project that has never written `context/state.json` (it adopted the package before the file existed)
|
|
24
|
+
gets a note, not a failure: the first run of `wt-roadmap.py`, `softure-archive` or `softure-roadmap`
|
|
25
|
+
creates it. Fix a stale or missing file with `npx softure-skills state` (or
|
|
26
|
+
`python3 .claude/skills/softure-doctor/scripts/context_state.py write`) and commit it.
|
|
27
|
+
|
|
28
|
+
Importable: `from doctor import run_checks` (takes any reader of context_state).
|
|
29
|
+
"""
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import json
|
|
33
|
+
import os
|
|
34
|
+
import re
|
|
35
|
+
import subprocess
|
|
36
|
+
import sys
|
|
37
|
+
|
|
38
|
+
sys.dont_write_bytecode = True # no __pycache__ inside the consumer's .claude/skills
|
|
39
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
40
|
+
from context_state import ( # noqa: E402
|
|
41
|
+
ARCHIVE_ROADMAPS_DIR, CHANGES_DIR, QUEUED_DIR, ROADMAP_PATH, STATE_PATH, FsReader, frontmatter,
|
|
42
|
+
roadmap_rows, sections, staleness,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
ARCHIVE_DIR = "context/archive"
|
|
46
|
+
BACKLOG_DIR = "context/backlog"
|
|
47
|
+
CLOSED_STATUSES = ("done", "done_code", "dropped", "carried")
|
|
48
|
+
SHA_RE = re.compile(r"\b[0-9a-f]{7,40}\b")
|
|
49
|
+
EMPTY_MERGE = {"—", "-", "–", "n/a", "none", "no merge", "not merged"}
|
|
50
|
+
LINK_RE = re.compile(r"\[[^\]]*\]\(([^)\s]+)(?:\s+\"[^\"]*\")?\)")
|
|
51
|
+
INDEX_NAMES = ("README.md", "INDEX.md")
|
|
52
|
+
CODE_PATH_RE = re.compile(r"`((?:\.{1,2}/)?(?:[\w.-]+/)*[\w.-]+\.md|(?:\.{1,2}/)?(?:[\w.-]+/)+)`")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Finding:
|
|
56
|
+
def __init__(self, code: str, path: str, message: str, severity: str = "fail") -> None:
|
|
57
|
+
self.code, self.path, self.message, self.severity = code, path, message, severity
|
|
58
|
+
|
|
59
|
+
def as_dict(self) -> dict:
|
|
60
|
+
return {"code": self.code, "path": self.path, "message": self.message, "severity": self.severity}
|
|
61
|
+
|
|
62
|
+
def __str__(self) -> str:
|
|
63
|
+
label = "FAIL" if self.severity == "fail" else "note"
|
|
64
|
+
return f"{label} {self.code} {self.path}: {self.message}"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _files(reader, directory: str, pattern: str) -> list[str]:
|
|
68
|
+
return [f"{directory}/{name}" for name, is_dir in reader.listdir(directory)
|
|
69
|
+
if not is_dir and re.match(pattern, name)]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _archived_roadmaps(reader) -> list[str]:
|
|
73
|
+
"""Archived roadmap files: `<date>-roadmap*.md` in foundation/archive/ that carry a roadmap table."""
|
|
74
|
+
paths = _files(reader, ARCHIVE_ROADMAPS_DIR, r"^\d{4}-\d{2}-\d{2}-roadmap.*\.md$")
|
|
75
|
+
return [path for path in paths if roadmap_rows(reader.read(path) or "")]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def check_main_roadmap(reader) -> list[Finding]:
|
|
79
|
+
findings: list[Finding] = []
|
|
80
|
+
text = reader.read(ROADMAP_PATH)
|
|
81
|
+
if text is None:
|
|
82
|
+
return findings
|
|
83
|
+
meta = frontmatter(text)
|
|
84
|
+
slug, version = meta.get("roadmap"), meta.get("version")
|
|
85
|
+
if slug:
|
|
86
|
+
for path in _archived_roadmaps(reader):
|
|
87
|
+
archived = frontmatter(reader.read(path) or "")
|
|
88
|
+
if archived.get("roadmap") == slug and (not version or not archived.get("version")
|
|
89
|
+
or archived.get("version") == version):
|
|
90
|
+
findings.append(Finding("roadmap-archived-not-removed", ROADMAP_PATH,
|
|
91
|
+
f"roadmap `{slug}` is already archived as {path}; remove roadmap.md "
|
|
92
|
+
"(the close moves it, WORKFLOW §5.2)"))
|
|
93
|
+
break
|
|
94
|
+
rows = roadmap_rows(text)
|
|
95
|
+
status = meta.get("status")
|
|
96
|
+
open_rows = [row["id"] for row in rows if row["status"] not in CLOSED_STATUSES]
|
|
97
|
+
if status == "done" and open_rows:
|
|
98
|
+
findings.append(Finding("roadmap-status-mismatch", ROADMAP_PATH,
|
|
99
|
+
f"status is done but rows are open: {', '.join(open_rows)}"))
|
|
100
|
+
if status == "waiting":
|
|
101
|
+
findings.append(Finding("roadmap-status-mismatch", ROADMAP_PATH,
|
|
102
|
+
"status is waiting, which belongs to a queued roadmap; the main roadmap is "
|
|
103
|
+
"draft, ready or done (a promote sets ready)"))
|
|
104
|
+
return findings
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def check_archived_changes(reader) -> list[Finding]:
|
|
108
|
+
findings: list[Finding] = []
|
|
109
|
+
for name, is_dir in reader.listdir(ARCHIVE_DIR):
|
|
110
|
+
if not is_dir:
|
|
111
|
+
continue
|
|
112
|
+
folder = f"{ARCHIVE_DIR}/{name}"
|
|
113
|
+
change = reader.read(f"{folder}/change.md")
|
|
114
|
+
if change is not None:
|
|
115
|
+
status = frontmatter(change).get("status")
|
|
116
|
+
if status != "archived":
|
|
117
|
+
findings.append(Finding("archived-change-status", f"{folder}/change.md",
|
|
118
|
+
f"status is {status or 'missing'}, expected archived"))
|
|
119
|
+
plan = reader.read(f"{folder}/plan.md")
|
|
120
|
+
if plan is not None:
|
|
121
|
+
open_items = unticked_automated(plan)
|
|
122
|
+
if open_items:
|
|
123
|
+
listed = "; ".join(open_items[:3]) + ("; …" if len(open_items) > 3 else "")
|
|
124
|
+
findings.append(Finding("archived-change-progress", f"{folder}/plan.md",
|
|
125
|
+
f"{len(open_items)} unticked Automated item(s) in ## Progress: {listed}"))
|
|
126
|
+
return findings
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def unticked_automated(plan: str) -> list[str]:
|
|
130
|
+
"""Open `- [ ]` items of `## Progress` that are not under a `#### Manual` heading.
|
|
131
|
+
|
|
132
|
+
Open Manual items are legitimate in an archived plan (manual mode carries them to the owner).
|
|
133
|
+
"""
|
|
134
|
+
progress = sections(plan).get("Progress", [])
|
|
135
|
+
open_items = []
|
|
136
|
+
manual = False
|
|
137
|
+
for line in progress:
|
|
138
|
+
if line.startswith("#### "):
|
|
139
|
+
manual = line[5:].strip().lower().startswith("manual")
|
|
140
|
+
continue
|
|
141
|
+
if line.startswith("### "):
|
|
142
|
+
manual = False
|
|
143
|
+
continue
|
|
144
|
+
match = re.match(r"^\s*- \[ \] (.+)$", line)
|
|
145
|
+
if match and not manual:
|
|
146
|
+
open_items.append(match.group(1).strip())
|
|
147
|
+
return open_items
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def check_archived_roadmaps(reader) -> list[Finding]:
|
|
151
|
+
findings: list[Finding] = []
|
|
152
|
+
for path in _archived_roadmaps(reader):
|
|
153
|
+
text = reader.read(path) or ""
|
|
154
|
+
open_rows = [f"{row['id']} ({row['status']})" for row in roadmap_rows(text)
|
|
155
|
+
if row["status"] not in CLOSED_STATUSES]
|
|
156
|
+
if open_rows:
|
|
157
|
+
findings.append(Finding("archived-roadmap-open-items", path,
|
|
158
|
+
f"rows not done, done_code, dropped or carried: {', '.join(open_rows)}"))
|
|
159
|
+
bad = summary_placeholders(text)
|
|
160
|
+
if bad:
|
|
161
|
+
findings.append(Finding("archived-roadmap-summary", path,
|
|
162
|
+
"## Summary merge column holds placeholders instead of merge SHAs: "
|
|
163
|
+
+ "; ".join(bad[:4])))
|
|
164
|
+
return findings
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def summary_placeholders(text: str) -> list[str]:
|
|
168
|
+
"""Rows of the `## Summary` table whose `Merge` cell holds no SHA (and is not an explicit dash)."""
|
|
169
|
+
lines = sections(text).get("Summary", [])
|
|
170
|
+
header = None
|
|
171
|
+
bad = []
|
|
172
|
+
for line in lines:
|
|
173
|
+
if not line.strip().startswith("|"):
|
|
174
|
+
continue
|
|
175
|
+
parts = [cell.strip() for cell in line.strip().strip("|").split("|")]
|
|
176
|
+
if header is None:
|
|
177
|
+
header = [cell.lower() for cell in parts]
|
|
178
|
+
continue
|
|
179
|
+
if all(re.fullmatch(r":?-{3,}:?", cell) for cell in parts if cell):
|
|
180
|
+
continue
|
|
181
|
+
index = header.index("merge") if "merge" in header else len(parts) - 1
|
|
182
|
+
cell = parts[index] if index < len(parts) else ""
|
|
183
|
+
if SHA_RE.search(cell) or cell.strip("`* ").lower() in EMPTY_MERGE:
|
|
184
|
+
continue
|
|
185
|
+
bad.append(f"{parts[0]}: \"{cell}\"")
|
|
186
|
+
return bad
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def check_queued_and_backlog(reader) -> list[Finding]:
|
|
190
|
+
findings: list[Finding] = []
|
|
191
|
+
queued_slugs = set()
|
|
192
|
+
for path in _files(reader, QUEUED_DIR, r"^roadmap-.+\.md$"):
|
|
193
|
+
text = reader.read(path) or ""
|
|
194
|
+
slug = os.path.basename(path)[len("roadmap-"):-len(".md")]
|
|
195
|
+
queued_slugs.add(slug)
|
|
196
|
+
rows = roadmap_rows(text)
|
|
197
|
+
if rows and all(row["status"] in ("done", "done_code") for row in rows):
|
|
198
|
+
findings.append(Finding("queued-roadmap-done", path,
|
|
199
|
+
f"all {len(rows)} rows are done but the roadmap is still queued; "
|
|
200
|
+
"archive it to foundation/archive/ (WORKFLOW §5.2)"))
|
|
201
|
+
main = frontmatter(reader.read(ROADMAP_PATH) or "")
|
|
202
|
+
for name, is_dir in reader.listdir(BACKLOG_DIR):
|
|
203
|
+
if not is_dir or not name.startswith("roadmap-"):
|
|
204
|
+
continue
|
|
205
|
+
slug = name[len("roadmap-"):]
|
|
206
|
+
promoted = main.get("roadmap") == slug or (main.get("backlog") or "").rstrip("/").endswith(name)
|
|
207
|
+
if slug not in queued_slugs and not promoted:
|
|
208
|
+
findings.append(Finding("backlog-without-roadmap", f"{BACKLOG_DIR}/{name}/",
|
|
209
|
+
f"no {QUEUED_DIR}/roadmap-{slug}.md and the main roadmap is not `{slug}`; "
|
|
210
|
+
"move live entries to a queued roadmap or remove the folder (WORKFLOW §5.1)"))
|
|
211
|
+
return findings
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def check_indexes(reader) -> list[Finding]:
|
|
215
|
+
findings: list[Finding] = []
|
|
216
|
+
for path in _walk(reader, "context"):
|
|
217
|
+
if os.path.basename(path) not in INDEX_NAMES:
|
|
218
|
+
continue
|
|
219
|
+
base = os.path.dirname(path)
|
|
220
|
+
for line in (reader.read(path) or "").splitlines():
|
|
221
|
+
if not line.strip().startswith("|"):
|
|
222
|
+
continue
|
|
223
|
+
for target in LINK_RE.findall(line):
|
|
224
|
+
if re.match(r"^[a-z][a-z0-9+.-]*:", target, re.IGNORECASE) or target.startswith("#"):
|
|
225
|
+
continue
|
|
226
|
+
rel = target.split("#", 1)[0]
|
|
227
|
+
if not rel:
|
|
228
|
+
continue
|
|
229
|
+
resolved = os.path.normpath(os.path.join(base, rel)).replace(os.sep, "/")
|
|
230
|
+
if resolved.startswith("..") or not resolved.startswith("context/"):
|
|
231
|
+
continue # outside context/: not this check's business
|
|
232
|
+
if not reader.exists(resolved.rstrip("/")):
|
|
233
|
+
findings.append(Finding("index-missing-file", path, f"row links `{target}`, which does not exist"))
|
|
234
|
+
for target in CODE_PATH_RE.findall(line):
|
|
235
|
+
# A path in backticks: relative to the index, to context/ or to the repository root.
|
|
236
|
+
candidates = [os.path.normpath(os.path.join(prefix, target)).replace(os.sep, "/").rstrip("/")
|
|
237
|
+
for prefix in (base, "context", ".")]
|
|
238
|
+
inside = [c for c in candidates if c.startswith("context/")]
|
|
239
|
+
if inside and not any(reader.exists(c) for c in inside):
|
|
240
|
+
findings.append(Finding("index-missing-file", path, f"row names `{target}`, which does not exist"))
|
|
241
|
+
return findings
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _walk(reader, directory: str) -> list[str]:
|
|
245
|
+
out = []
|
|
246
|
+
for name, is_dir in reader.listdir(directory):
|
|
247
|
+
path = f"{directory}/{name}"
|
|
248
|
+
if is_dir:
|
|
249
|
+
out += _walk(reader, path)
|
|
250
|
+
else:
|
|
251
|
+
out.append(path)
|
|
252
|
+
return out
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def ever_written(root: str | None) -> bool | None:
|
|
256
|
+
"""Whether git history has ever held context/state.json; None when that cannot be told."""
|
|
257
|
+
if not root:
|
|
258
|
+
return None
|
|
259
|
+
probe = subprocess.run(["git", "-C", root, "rev-parse", "--is-shallow-repository"],
|
|
260
|
+
capture_output=True, text=True)
|
|
261
|
+
if probe.returncode != 0 or probe.stdout.strip() == "true":
|
|
262
|
+
return None
|
|
263
|
+
log = subprocess.run(["git", "-C", root, "log", "--all", "-1", "--format=%H", "--", STATE_PATH],
|
|
264
|
+
capture_output=True, text=True)
|
|
265
|
+
return log.returncode == 0 and bool(log.stdout.strip())
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def check_state(reader, root: str | None) -> list[Finding]:
|
|
269
|
+
if not reader.exists("context"):
|
|
270
|
+
return []
|
|
271
|
+
problem = staleness(reader)
|
|
272
|
+
if problem is None:
|
|
273
|
+
return []
|
|
274
|
+
if problem == "missing":
|
|
275
|
+
if ever_written(root):
|
|
276
|
+
return [Finding("state-missing", STATE_PATH,
|
|
277
|
+
"missing, but git history holds it: regenerate it (`npx softure-skills state`) and commit")]
|
|
278
|
+
return [Finding("state-missing", STATE_PATH,
|
|
279
|
+
"not written yet; the next wt-roadmap.py, softure-archive or softure-roadmap run creates it",
|
|
280
|
+
severity="note")]
|
|
281
|
+
return [Finding("state-stale", STATE_PATH,
|
|
282
|
+
f"{problem}; regenerate it (`npx softure-skills state`) and commit")]
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def run_checks(reader, root: str | None = None) -> list[Finding]:
|
|
286
|
+
"""Every finding for the project `reader` sees. `root` (a git checkout) enables the history check."""
|
|
287
|
+
if not reader.exists("context"):
|
|
288
|
+
return []
|
|
289
|
+
findings: list[Finding] = []
|
|
290
|
+
for check in (check_main_roadmap, check_archived_changes, check_archived_roadmaps,
|
|
291
|
+
check_queued_and_backlog, check_indexes):
|
|
292
|
+
findings += check(reader)
|
|
293
|
+
findings += check_state(reader, root)
|
|
294
|
+
return findings
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def main(argv: list[str] | None = None) -> int:
|
|
298
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
299
|
+
if "-h" in args or "--help" in args:
|
|
300
|
+
print(__doc__)
|
|
301
|
+
return 0
|
|
302
|
+
as_json = "--json" in args
|
|
303
|
+
args = [arg for arg in args if arg != "--json"]
|
|
304
|
+
root = None
|
|
305
|
+
if "--root" in args:
|
|
306
|
+
k = args.index("--root")
|
|
307
|
+
root = os.path.abspath(args[k + 1])
|
|
308
|
+
del args[k:k + 2]
|
|
309
|
+
if args:
|
|
310
|
+
print(__doc__, file=sys.stderr)
|
|
311
|
+
return 2
|
|
312
|
+
top = subprocess.run(["git", "-C", root or os.getcwd(), "rev-parse", "--show-toplevel"],
|
|
313
|
+
capture_output=True, text=True)
|
|
314
|
+
toplevel = os.path.realpath(top.stdout.strip()) if top.returncode == 0 else None
|
|
315
|
+
root = root or toplevel or os.getcwd()
|
|
316
|
+
git_root = root if toplevel and toplevel == os.path.realpath(root) else None
|
|
317
|
+
reader = FsReader(root)
|
|
318
|
+
if not reader.exists("context"):
|
|
319
|
+
if as_json:
|
|
320
|
+
print(json.dumps({"root": root, "failures": [], "notes": ["no context/ directory"]}, indent=2))
|
|
321
|
+
else:
|
|
322
|
+
print(f"softure-doctor: no context/ directory in {root}, nothing to check")
|
|
323
|
+
return 0
|
|
324
|
+
findings = run_checks(reader, git_root)
|
|
325
|
+
failures = [f for f in findings if f.severity == "fail"]
|
|
326
|
+
if as_json:
|
|
327
|
+
print(json.dumps({"root": root, "failures": [f.as_dict() for f in failures],
|
|
328
|
+
"notes": [f.as_dict() for f in findings if f.severity != "fail"]}, indent=2))
|
|
329
|
+
return 1 if failures else 0
|
|
330
|
+
for finding in findings:
|
|
331
|
+
print(finding)
|
|
332
|
+
if failures:
|
|
333
|
+
print(f"softure-doctor: {len(failures)} problem(s) in the context/ contract (WORKFLOW.md §12)")
|
|
334
|
+
return 1
|
|
335
|
+
print("softure-doctor: context/ contract OK")
|
|
336
|
+
return 0
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
if __name__ == "__main__":
|
|
340
|
+
sys.exit(main())
|
|
@@ -78,7 +78,9 @@ Read the PRD in full, not in excerpts.
|
|
|
78
78
|
Then write `## Summary` (`| ID | Item | What changed | Merge |`, the merge SHA from
|
|
79
79
|
`git log --merges --grep "<change-id>"` on `<main>`, plus the integration line), move the file to
|
|
80
80
|
`foundation/archive/<YYYY-MM-DD>-roadmap.md`, clean up the promoted roadmap's backlog folder and
|
|
81
|
-
index row, and
|
|
81
|
+
index row, run step 15 (state and doctor), and commit. A `## Summary` row never holds a placeholder
|
|
82
|
+
("merge SHA after the PR", "this PR"): the close runs on `<main>` after the merges, so every SHA is
|
|
83
|
+
known; a carried or dropped row has `—`. With `integration.coveredByRelease` and "Release: at the end" the close does not
|
|
82
84
|
wait for the release: the integration line reads `covered by the release on <sha> (coveredByRelease)`
|
|
83
85
|
unless a green stored result exists. The archived file is what the release notes read (every release
|
|
84
86
|
of this roadmap, retries and redeploys included); rows waiting for the release keep `done_code`, so
|
|
@@ -241,6 +243,15 @@ Overwriting a roadmap without archiving it is never an option. In `--auto`: revi
|
|
|
241
243
|
(`--no-open-changes`, recorded in the handoff); never skip it on your own, not even in `--auto`.
|
|
242
244
|
`--open-changes` is still accepted and changes nothing.
|
|
243
245
|
|
|
246
|
+
15. **State and doctor, before every commit of this skill** (record, `--revise`, `--queue`,
|
|
247
|
+
`--promote`, `--close`; WORKFLOW §12). Stage the files, run
|
|
248
|
+
`python3 .claude/skills/softure-doctor/scripts/context_state.py write --staged` (it reads the
|
|
249
|
+
index and stages `context/state.json`, so it rides in the same commit), then
|
|
250
|
+
`python3 .claude/skills/softure-doctor/scripts/doctor.py`. Fix what this run owns (the roadmap
|
|
251
|
+
files, their backlog folders and index rows, the `## Summary` SHAs) and re-run; name any other
|
|
252
|
+
failure in the handoff without touching it. In `--close` a failure this run owns blocks the
|
|
253
|
+
commit like a failing gate.
|
|
254
|
+
|
|
244
255
|
A complete, realistic roadmap in this format, with a bad version and why it fails:
|
|
245
256
|
[references/example-roadmap.md](references/example-roadmap.md) (read before the first roadmap in a
|
|
246
257
|
project).
|
|
@@ -43,6 +43,10 @@ from HEAD plus one edit (hash-object -> update-index), so other sessions' uncomm
|
|
|
43
43
|
the working file never ride along; the same edit is applied to the working file too, so it does
|
|
44
44
|
not look like it reverts the commit.
|
|
45
45
|
|
|
46
|
+
Every commit also carries `context/state.json` (WORKFLOW.md §12), regenerated from the same tree
|
|
47
|
+
plus the new roadmap, so the machine-readable state never lags the markdown. A project without the
|
|
48
|
+
file gets it on the first run.
|
|
49
|
+
|
|
46
50
|
Always works on the main worktree (first entry of `git worktree list`), whichever worktree
|
|
47
51
|
calls it. The main branch name comes from context/workflow.json (`mainBranch`).
|
|
48
52
|
|
|
@@ -76,7 +80,14 @@ sys.dont_write_bytecode = True # no __pycache__ inside the consumer's .claude/s
|
|
|
76
80
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
77
81
|
from wt_config import load_config, main_branch, main_root # noqa: E402
|
|
78
82
|
|
|
83
|
+
try: # the state writer ships in the softure-doctor skill, installed next to this one
|
|
84
|
+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "softure-doctor", "scripts"))
|
|
85
|
+
import context_state # noqa: E402
|
|
86
|
+
except ImportError: # pragma: no cover - an install without softure-doctor still marks the roadmap
|
|
87
|
+
context_state = None
|
|
88
|
+
|
|
79
89
|
ROADMAP = "context/foundation/roadmap.md"
|
|
90
|
+
STATE = "context/state.json"
|
|
80
91
|
COAUTHOR = "Co-Authored-By: Claude <noreply@anthropic.com>"
|
|
81
92
|
|
|
82
93
|
ROW_RE = re.compile(r"^(?P<head>\|.*\|\s*)(?P<status>[^|]*?)(?P<tail>\s*\|\s*)$")
|
|
@@ -256,6 +267,21 @@ def done_status(handoff: dict, mode: str, arg: str | None, today: str) -> str:
|
|
|
256
267
|
return "done"
|
|
257
268
|
|
|
258
269
|
|
|
270
|
+
def render_state(reader) -> str | None:
|
|
271
|
+
"""`context/state.json` for the tree `reader` sees, or None when softure-doctor is not installed."""
|
|
272
|
+
if context_state is None:
|
|
273
|
+
print("note: softure-doctor is not installed next to softure-worktree; context/state.json not written",
|
|
274
|
+
file=sys.stderr)
|
|
275
|
+
return None
|
|
276
|
+
return context_state.render_state(reader)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def print_state_diff(old: str | None, new: str | None, label: str) -> None:
|
|
280
|
+
if new is not None and old != new:
|
|
281
|
+
sys.stdout.writelines(difflib.unified_diff((old or "").splitlines(True), new.splitlines(True),
|
|
282
|
+
f"{label}:{STATE}", f"commit:{STATE}"))
|
|
283
|
+
|
|
284
|
+
|
|
259
285
|
def unchanged(old: str, new: str, target: str) -> bool:
|
|
260
286
|
"""A re-run (e.g. `done` after a retry) whose edit is already in place commits nothing."""
|
|
261
287
|
if re.sub(r"(?m)^updated: .*$", "", old) != re.sub(r"(?m)^updated: .*$", "", new):
|
|
@@ -415,8 +441,11 @@ def run_cloud(mode: str, change_id: str, arg: str | None, branch: str | None, dr
|
|
|
415
441
|
handoff, run_mode, run_arg = load_handoff(repo, base, mode, change_id, arg, verified)
|
|
416
442
|
new = edit(old, run_mode, change_id, run_arg, repo_name, cloud_branch=branch if mode == "open" else None,
|
|
417
443
|
handoff=handoff)
|
|
444
|
+
state = render_state(context_state.GitReader(repo, base, {ROADMAP: new})) if context_state else None
|
|
418
445
|
if dry:
|
|
419
446
|
sys.stdout.writelines(difflib.unified_diff(old.splitlines(True), new.splitlines(True), f"origin/{main}", "commit"))
|
|
447
|
+
print_state_diff(context_state.GitReader(repo, base).read(STATE) if context_state else None, state,
|
|
448
|
+
f"origin/{main}")
|
|
420
449
|
return
|
|
421
450
|
if unchanged(old, new, f"origin/{main}"):
|
|
422
451
|
return
|
|
@@ -432,6 +461,12 @@ def run_cloud(mode: str, change_id: str, arg: str | None, branch: str | None, dr
|
|
|
432
461
|
git(repo, "read-tree", base, env=index_env)
|
|
433
462
|
blob = git(repo, "hash-object", "-w", blob_path, env=index_env).strip()
|
|
434
463
|
git(repo, "update-index", "--cacheinfo", f"100644,{blob},{ROADMAP}", env=index_env)
|
|
464
|
+
if state is not None:
|
|
465
|
+
state_path = os.path.join(tmpdir, "state.json")
|
|
466
|
+
with open(state_path, "w", encoding="utf-8") as fh:
|
|
467
|
+
fh.write(state)
|
|
468
|
+
state_blob = git(repo, "hash-object", "-w", state_path, env=index_env).strip()
|
|
469
|
+
git(repo, "update-index", "--add", "--cacheinfo", f"100644,{state_blob},{STATE}", env=index_env)
|
|
435
470
|
tree = git(repo, "write-tree", env=index_env).strip()
|
|
436
471
|
sha = git(repo, "commit-tree", tree, "-p", base, "-m", msg, env=index_env).strip()
|
|
437
472
|
push = push_roadmap_commit(repo, sha, main, env)
|
|
@@ -462,22 +497,39 @@ def run_cloud_branch(mode: str, change_id: str, arg: str | None, branch: str | N
|
|
|
462
497
|
handoff, mode, arg = load_handoff(repo, "HEAD", mode, change_id, arg, verified)
|
|
463
498
|
new = edit(old, mode, change_id, arg, repo_name, cloud_branch=branch if mode == "open" else None,
|
|
464
499
|
handoff=handoff)
|
|
500
|
+
state = render_state(context_state.FsReader(repo, {ROADMAP: new})) if context_state else None
|
|
465
501
|
if dry:
|
|
466
502
|
sys.stdout.writelines(difflib.unified_diff(old.splitlines(True), new.splitlines(True), current, "commit"))
|
|
503
|
+
print_state_diff(context_state.FsReader(repo).read(STATE) if context_state else None, state, current)
|
|
467
504
|
return
|
|
468
505
|
if unchanged(old, new, current):
|
|
469
506
|
return
|
|
470
507
|
with open(work_path, "w", encoding="utf-8") as fh:
|
|
471
508
|
fh.write(new)
|
|
509
|
+
paths = [ROADMAP]
|
|
510
|
+
if state is not None:
|
|
511
|
+
with open(os.path.join(repo, STATE), "w", encoding="utf-8") as fh:
|
|
512
|
+
fh.write(state)
|
|
513
|
+
git(repo, "add", "--", STATE)
|
|
514
|
+
paths.append(STATE)
|
|
472
515
|
msg = commit_message(old, mode, change_id, arg, f"cloud session, branch {branch}", new)
|
|
473
516
|
session = os.environ.get("CLAUDE_CODE_REMOTE_SESSION_ID", "")
|
|
474
517
|
if session.startswith("cse_"):
|
|
475
518
|
msg += f"\nClaude-Session: https://claude.ai/code/session_{session[4:]}"
|
|
476
|
-
git(repo, "commit", "-q", "-m", msg, "--",
|
|
519
|
+
git(repo, "commit", "-q", "-m", msg, "--", *paths)
|
|
477
520
|
sha = git(repo, "rev-parse", "--short", "HEAD").strip()
|
|
478
521
|
print(f"{sha} {msg.splitlines()[0]} -> {current} (not pushed; the branch carries the state)")
|
|
479
522
|
|
|
480
523
|
|
|
524
|
+
def hash_text(repo: str, text: str) -> str:
|
|
525
|
+
with tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8") as tmp:
|
|
526
|
+
tmp.write(text)
|
|
527
|
+
try:
|
|
528
|
+
return git(repo, "hash-object", "-w", tmp.name).strip()
|
|
529
|
+
finally:
|
|
530
|
+
os.unlink(tmp.name)
|
|
531
|
+
|
|
532
|
+
|
|
481
533
|
def run_local(mode: str, change_id: str, arg: str | None, dry: bool, verified: str | None = None) -> None:
|
|
482
534
|
main_wt = main_root()
|
|
483
535
|
repo_name = os.path.basename(main_wt)
|
|
@@ -492,6 +544,9 @@ def run_local(mode: str, change_id: str, arg: str | None, dry: bool, verified: s
|
|
|
492
544
|
handoff, mode, arg = load_handoff(main_wt, "HEAD", mode, change_id, arg, verified)
|
|
493
545
|
new_head = edit(head_text, mode, change_id, arg, repo_name, handoff=handoff)
|
|
494
546
|
sys.stdout.writelines(difflib.unified_diff(head_text.splitlines(True), new_head.splitlines(True), "HEAD", "commit"))
|
|
547
|
+
if context_state:
|
|
548
|
+
print_state_diff(context_state.GitReader(main_wt, "HEAD").read(STATE),
|
|
549
|
+
render_state(context_state.GitReader(main_wt, "HEAD", {ROADMAP: new_head})), "HEAD")
|
|
495
550
|
return
|
|
496
551
|
|
|
497
552
|
# Several sessions commit stages on the main branch at once. Every attempt re-reads HEAD,
|
|
@@ -518,25 +573,31 @@ def run_local(mode: str, change_id: str, arg: str | None, dry: bool, verified: s
|
|
|
518
573
|
new_work = new_head if work_text == head_text else edit(work_text, run_mode, change_id, run_arg, repo_name,
|
|
519
574
|
handoff=handoff)
|
|
520
575
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
os.unlink(tmp.name)
|
|
576
|
+
state = render_state(context_state.GitReader(main_wt, head_sha, {ROADMAP: new_head})) if context_state else None
|
|
577
|
+
blob = hash_text(main_wt, new_head)
|
|
578
|
+
state_blob = hash_text(main_wt, state) if state is not None else None
|
|
525
579
|
|
|
526
580
|
try:
|
|
527
581
|
git(main_wt, "update-index", "--cacheinfo", f"100644,{blob},{ROADMAP}")
|
|
582
|
+
if state_blob:
|
|
583
|
+
git(main_wt, "update-index", "--add", "--cacheinfo", f"100644,{state_blob},{STATE}")
|
|
528
584
|
if git(main_wt, "rev-parse", "HEAD").strip() != head_sha:
|
|
529
585
|
raise subprocess.CalledProcessError(1, "rev-parse", stderr="HEAD moved")
|
|
530
586
|
git(main_wt, "commit", "-q", "-m", msg)
|
|
531
587
|
break
|
|
532
588
|
except subprocess.CalledProcessError as exc:
|
|
533
589
|
subprocess.run(["git", "-C", main_wt, "reset", "-q", "--", ROADMAP])
|
|
590
|
+
if state_blob:
|
|
591
|
+
subprocess.run(["git", "-C", main_wt, "reset", "-q", "--", STATE], capture_output=True)
|
|
534
592
|
if attempt < 7:
|
|
535
593
|
time.sleep(2)
|
|
536
594
|
continue
|
|
537
595
|
sys.exit(f"commit failed (index restored): {exc.stderr}")
|
|
538
596
|
with open(work_path, "w", encoding="utf-8") as fh:
|
|
539
597
|
fh.write(new_work)
|
|
598
|
+
if state is not None:
|
|
599
|
+
with open(os.path.join(main_wt, STATE), "w", encoding="utf-8") as fh:
|
|
600
|
+
fh.write(state)
|
|
540
601
|
sha = git(main_wt, "rev-parse", "--short", "HEAD").strip()
|
|
541
602
|
print(f"{sha} {msg.splitlines()[0]}")
|
|
542
603
|
if work_text != head_text:
|
|
@@ -188,7 +188,13 @@ claude agents --json # background + interactive sessio
|
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
Plus `ListAgents` for peer sessions — its header names **this** session;
|
|
191
|
-
remember it, M0.1 compares against it.
|
|
191
|
+
remember it, M0.1 compares against it. List the open `owner-word` issues of
|
|
192
|
+
this repository (`gh issue list --label owner-word --state open`, WORKFLOW §8.6)
|
|
193
|
+
and act on them before anything else: autonomous mode carries each out like an
|
|
194
|
+
order in the conversation, comments what was done and closes it (one it cannot
|
|
195
|
+
act on gets a comment with the question and stays open); manual mode shows them
|
|
196
|
+
to the owner and waits for the word. Repeat this on every status firing (M4).
|
|
197
|
+
Read `context/foundation/roadmap.md`:
|
|
192
198
|
the header note (run-wide orders from the owner such as parallelism or the
|
|
193
199
|
final push), `## At a glance`, `## Order`, each candidate's `### <ID>` block.
|
|
194
200
|
|
|
@@ -34,7 +34,9 @@ Roadmap report for <roadmap name> (SOFTURE workflow, AGENTS.md → Operating mod
|
|
|
34
34
|
If several firings queued up while busy, do one.
|
|
35
35
|
- Running as the coordinator: post the roadmap report in the main chat in the standard shape
|
|
36
36
|
(title, "X of N on <main>", the four-column table of the items not done yet, Decision, times),
|
|
37
|
-
in chatLanguage, times in timezone. Before posting,
|
|
37
|
+
in chatLanguage, times in timezone. Before posting, act on every open `owner-word` issue of
|
|
38
|
+
<owner/repo> (WORKFLOW §8.6: carry it out, comment, close; ask in a comment when unclear), then run
|
|
39
|
+
the heartbeat: recompute the startable set
|
|
38
40
|
from roadmap.md on origin/<main> (softure-worktree/scripts/wt-startable.py; never only the
|
|
39
41
|
successors of the last merge) and start a thread for every item that is not done, has no thread
|
|
40
42
|
and has all prerequisites on <main> or none; give the go to every READY thread; nudge every
|