@softure-ai/skills 0.19.0 → 0.21.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 +44 -0
- package/WORKFLOW.md +210 -6
- package/package.json +2 -1
- package/rules/AGENTS.md +26 -1
- package/scripts/install.mjs +70 -1
- package/scripts/portfolio.py +328 -0
- package/skills/softure-archive/SKILL.md +15 -6
- package/skills/softure-doctor/SKILL.md +146 -0
- package/skills/softure-doctor/references/state.schema.json +125 -0
- package/skills/softure-doctor/scripts/context_state.py +622 -0
- package/skills/softure-doctor/scripts/doctor.py +573 -0
- package/skills/softure-doctor/scripts/doctor_fix.py +227 -0
- package/skills/softure-doctor/scripts/doctor_sweep.py +386 -0
- package/skills/softure-roadmap/SKILL.md +21 -3
- 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,328 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""softure-skills portfolio: where every adopting project stands, from its context/state.json. Read-only.
|
|
3
|
+
|
|
4
|
+
softure-skills portfolio [<repo> ...] [--config <file>] [--owner] [--json] [--source git|api]
|
|
5
|
+
|
|
6
|
+
Repositories come from the arguments or from a config file outside any project (default
|
|
7
|
+
`~/.config/softure/portfolio.json`, or `$SOFTURE_PORTFOLIO`):
|
|
8
|
+
|
|
9
|
+
{ "projects": [ { "name": "shop", "repo": "acme/shop", "branch": "main" },
|
|
10
|
+
{ "repo": "https://git.example.com/acme/api.git" },
|
|
11
|
+
{ "name": "local", "repo": "~/code/app" } ] }
|
|
12
|
+
|
|
13
|
+
A repo is `owner/name` (GitHub), a git URL, or a local checkout. Without `branch` the remote's default
|
|
14
|
+
branch is read; a local checkout is read at `origin/<mainBranch>` when that ref exists, else at
|
|
15
|
+
`<mainBranch>` (no fetch: nothing is written to it).
|
|
16
|
+
|
|
17
|
+
`--source git` (default) reads `context/` of the main branch through git (a shallow, sparse, blob-less
|
|
18
|
+
clone into a temporary folder for a remote), takes `context/state.json`, and runs softure-doctor on the
|
|
19
|
+
same tree. A project without `state.json` gets one built in memory and is marked `*`.
|
|
20
|
+
`--source api` reads only `context/state.json` through the GitHub API (`gh api`); the doctor column
|
|
21
|
+
then shows `n/a`.
|
|
22
|
+
|
|
23
|
+
Default output, one row per project:
|
|
24
|
+
|
|
25
|
+
project | active roadmap X/N | queued | open changes | owner queue | last release | doctor
|
|
26
|
+
|
|
27
|
+
Last release comes from the forge when it can: the latest GitHub release through `gh api` (for a GitHub
|
|
28
|
+
repository, in both modes; a local checkout counts when its `origin` is on GitHub), else the highest
|
|
29
|
+
`v*` tag (git mode), else the value a closed roadmap recorded in `state.json`, labelled `(roadmap)`.
|
|
30
|
+
`SOFTURE_GH` names another `gh` binary.
|
|
31
|
+
|
|
32
|
+
`--owner` prints only the owner queue across all projects, oldest first. `--json` prints the same data
|
|
33
|
+
for another tool (`last_release` is the version; `last_release_source` is `release`, `tag` or `roadmap`). Exit 1 when a project could not be read (its row says why); nothing is ever written
|
|
34
|
+
outside a temporary folder.
|
|
35
|
+
"""
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import datetime as dt
|
|
39
|
+
import json
|
|
40
|
+
import os
|
|
41
|
+
import re
|
|
42
|
+
import shutil
|
|
43
|
+
import subprocess
|
|
44
|
+
import sys
|
|
45
|
+
import tempfile
|
|
46
|
+
|
|
47
|
+
sys.dont_write_bytecode = True
|
|
48
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
49
|
+
sys.path.insert(0, os.path.join(HERE, "..", "skills", "softure-doctor", "scripts"))
|
|
50
|
+
import context_state # noqa: E402
|
|
51
|
+
import doctor # noqa: E402
|
|
52
|
+
|
|
53
|
+
DEFAULT_CONFIG = os.path.join("~", ".config", "softure", "portfolio.json")
|
|
54
|
+
GITHUB_RE = re.compile(r"github\.com[:/]([\w.-]+/[\w.-]+?)(?:\.git)?/?$")
|
|
55
|
+
SEMVER_RE = re.compile(r"^v?(\d+)\.(\d+)\.(\d+)$")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def git(*args: str, cwd: str | None = None, check: bool = True) -> subprocess.CompletedProcess:
|
|
59
|
+
env = {**os.environ, "GIT_TERMINAL_PROMPT": "0"}
|
|
60
|
+
return subprocess.run(["git", *args], cwd=cwd, capture_output=True, text=True, check=check, env=env)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def load_projects(args: list[str], config: str | None) -> list[dict]:
|
|
64
|
+
if args:
|
|
65
|
+
return [{"repo": repo} for repo in args]
|
|
66
|
+
path = os.path.expanduser(config or os.environ.get("SOFTURE_PORTFOLIO") or DEFAULT_CONFIG)
|
|
67
|
+
if not os.path.exists(path):
|
|
68
|
+
sys.exit(f"no repositories: pass them as arguments or list them in {path} (see --help)")
|
|
69
|
+
with open(path, encoding="utf-8") as fh:
|
|
70
|
+
data = json.load(fh)
|
|
71
|
+
entries = data.get("projects", data) if isinstance(data, dict) else data
|
|
72
|
+
projects = []
|
|
73
|
+
for entry in entries:
|
|
74
|
+
projects.append({"repo": entry} if isinstance(entry, str) else dict(entry))
|
|
75
|
+
return projects
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def project_name(project: dict) -> str:
|
|
79
|
+
if project.get("name"):
|
|
80
|
+
return project["name"]
|
|
81
|
+
repo = project["repo"].rstrip("/")
|
|
82
|
+
return re.sub(r"\.git$", "", repo.rsplit("/", 1)[-1].rsplit(":", 1)[-1])
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def is_local(repo: str) -> bool:
|
|
86
|
+
return os.path.isdir(os.path.expanduser(repo))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def remote_url(repo: str) -> str:
|
|
90
|
+
if re.fullmatch(r"[\w.-]+/[\w.-]+", repo):
|
|
91
|
+
return f"https://github.com/{repo}.git"
|
|
92
|
+
return repo
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def gh() -> str:
|
|
96
|
+
return os.environ.get("SOFTURE_GH") or "gh"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def github_slug(repo: str, local_path: str | None = None) -> str | None:
|
|
100
|
+
"""`owner/name` of a GitHub repository: from the argument, or the `origin` of a local checkout."""
|
|
101
|
+
if local_path:
|
|
102
|
+
url = git("remote", "get-url", "origin", cwd=local_path, check=False).stdout.strip()
|
|
103
|
+
match = GITHUB_RE.search(url)
|
|
104
|
+
return match.group(1) if match else None
|
|
105
|
+
if re.fullmatch(r"[\w.-]+/[\w.-]+", repo):
|
|
106
|
+
return repo
|
|
107
|
+
match = GITHUB_RE.search(repo)
|
|
108
|
+
return match.group(1) if match else None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def forge_release(slug: str | None) -> dict | None:
|
|
112
|
+
"""The latest GitHub release of `slug` through `gh api`; None without gh, access or a release."""
|
|
113
|
+
if not slug:
|
|
114
|
+
return None
|
|
115
|
+
try:
|
|
116
|
+
shown = subprocess.run([gh(), "api", f"repos/{slug}/releases/latest"], capture_output=True, text=True,
|
|
117
|
+
timeout=30)
|
|
118
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
119
|
+
return None
|
|
120
|
+
if shown.returncode != 0:
|
|
121
|
+
return None
|
|
122
|
+
try:
|
|
123
|
+
data = json.loads(shown.stdout)
|
|
124
|
+
except json.JSONDecodeError:
|
|
125
|
+
return None
|
|
126
|
+
if not data.get("tag_name"):
|
|
127
|
+
return None
|
|
128
|
+
return {"version": data["tag_name"], "date": (data.get("published_at") or "")[:10] or None, "source": "release"}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def pick_release(forge: dict | None, tag: dict | None, state: dict | None) -> dict:
|
|
132
|
+
"""The forge's release, else the highest tag, else the roadmap-recorded value (labelled as such)."""
|
|
133
|
+
for found in (forge, tag):
|
|
134
|
+
if found and found.get("version"):
|
|
135
|
+
return found
|
|
136
|
+
recorded = (state or {}).get("last_release") or {}
|
|
137
|
+
if recorded.get("version"):
|
|
138
|
+
return {"version": recorded["version"], "date": recorded.get("date"), "source": "roadmap"}
|
|
139
|
+
return {"version": None, "date": None, "source": None}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def highest_tag(tags: list[str]) -> str | None:
|
|
143
|
+
versions = [(tuple(int(n) for n in SEMVER_RE.match(tag).groups()), tag) for tag in tags if SEMVER_RE.match(tag)]
|
|
144
|
+
return max(versions)[1] if versions else None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def local_ref(path: str, branch: str | None) -> str:
|
|
148
|
+
if not branch:
|
|
149
|
+
raw = git("show", "HEAD:context/workflow.json", cwd=path, check=False).stdout
|
|
150
|
+
try:
|
|
151
|
+
branch = json.loads(raw).get("mainBranch") if raw else None
|
|
152
|
+
except json.JSONDecodeError:
|
|
153
|
+
branch = None
|
|
154
|
+
for ref in ([f"origin/{branch}", branch] if branch else []) + ["HEAD"]:
|
|
155
|
+
if git("rev-parse", "--verify", "-q", f"{ref}^{{commit}}", cwd=path, check=False).returncode == 0:
|
|
156
|
+
return ref
|
|
157
|
+
return "HEAD"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def read_git(project: dict) -> dict:
|
|
161
|
+
"""State, doctor findings and last release of one project, read through git."""
|
|
162
|
+
repo = project["repo"]
|
|
163
|
+
tmp = None
|
|
164
|
+
try:
|
|
165
|
+
if is_local(repo):
|
|
166
|
+
path = os.path.expanduser(repo)
|
|
167
|
+
ref = local_ref(path, project.get("branch"))
|
|
168
|
+
reader = context_state.GitReader(path, ref)
|
|
169
|
+
tags = git("tag", "-l", "v*", cwd=path, check=False).stdout.split()
|
|
170
|
+
branch = ref
|
|
171
|
+
slug = github_slug(repo, path)
|
|
172
|
+
else:
|
|
173
|
+
tmp = tempfile.mkdtemp(prefix="softure-portfolio-")
|
|
174
|
+
url = remote_url(repo)
|
|
175
|
+
clone = ["clone", "-q", "--depth", "1", "--filter=blob:none", "--sparse"]
|
|
176
|
+
if project.get("branch"):
|
|
177
|
+
clone += ["--branch", project["branch"]]
|
|
178
|
+
result = git(*clone, url, tmp, check=False)
|
|
179
|
+
if result.returncode != 0:
|
|
180
|
+
raise RuntimeError(f"git clone failed: {result.stderr.strip()[:200]}")
|
|
181
|
+
git("sparse-checkout", "set", "--no-cone", "/context/", cwd=tmp, check=False)
|
|
182
|
+
reader = context_state.FsReader(tmp)
|
|
183
|
+
branch = git("rev-parse", "--abbrev-ref", "HEAD", cwd=tmp, check=False).stdout.strip()
|
|
184
|
+
listed = git("ls-remote", "--tags", "--refs", url, "v*", check=False).stdout
|
|
185
|
+
tags = [line.split("refs/tags/", 1)[1] for line in listed.splitlines() if "refs/tags/" in line]
|
|
186
|
+
slug = github_slug(repo)
|
|
187
|
+
if not reader.exists("context"):
|
|
188
|
+
raise RuntimeError(f"no context/ on {branch}")
|
|
189
|
+
state, source = context_state.load_prior(reader), "stored"
|
|
190
|
+
if state is None:
|
|
191
|
+
state, source = context_state.build_state(reader), "built"
|
|
192
|
+
findings = doctor.run_checks(reader, None)
|
|
193
|
+
failures = [f.as_dict() for f in findings if f.severity == "fail"]
|
|
194
|
+
top = highest_tag(tags)
|
|
195
|
+
release = pick_release(forge_release(slug), {"version": top, "date": None, "source": "tag"} if top else None,
|
|
196
|
+
state)
|
|
197
|
+
return {"branch": branch, "state": state, "state_source": source, "doctor": failures,
|
|
198
|
+
**release_fields(release)}
|
|
199
|
+
finally:
|
|
200
|
+
if tmp:
|
|
201
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def read_api(project: dict) -> dict:
|
|
205
|
+
"""State and last release of one GitHub project, through `gh api`; no doctor."""
|
|
206
|
+
repo = project["repo"]
|
|
207
|
+
slug = github_slug(repo)
|
|
208
|
+
if not slug:
|
|
209
|
+
raise RuntimeError("--source api needs a GitHub repository (owner/name)")
|
|
210
|
+
ref = f"?ref={project['branch']}" if project.get("branch") else ""
|
|
211
|
+
shown = subprocess.run([gh(), "api", "-H", "Accept: application/vnd.github.raw",
|
|
212
|
+
f"repos/{slug}/contents/context/state.json{ref}"], capture_output=True, text=True)
|
|
213
|
+
state, source = None, "missing"
|
|
214
|
+
if shown.returncode == 0:
|
|
215
|
+
state, source = json.loads(shown.stdout), "stored"
|
|
216
|
+
elif "404" not in shown.stderr and "Not Found" not in shown.stderr:
|
|
217
|
+
raise RuntimeError(f"gh api failed: {shown.stderr.strip()[:200]}")
|
|
218
|
+
release = pick_release(forge_release(slug), None, state)
|
|
219
|
+
return {"branch": project.get("branch") or "default", "state": state, "state_source": source,
|
|
220
|
+
"doctor": None, **release_fields(release)}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def release_fields(release: dict) -> dict:
|
|
224
|
+
return {"last_release": release["version"], "last_release_date": release["date"],
|
|
225
|
+
"last_release_source": release["source"]}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def release_cell(row: dict) -> str:
|
|
229
|
+
version = row.get("last_release")
|
|
230
|
+
if not version:
|
|
231
|
+
return "—"
|
|
232
|
+
notes = [note for note in ("roadmap" if row.get("last_release_source") == "roadmap" else None,
|
|
233
|
+
row.get("last_release_date")) if note]
|
|
234
|
+
return version + (f" ({', '.join(notes)})" if notes else "")
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def collect(projects: list[dict], source: str) -> list[dict]:
|
|
238
|
+
rows = []
|
|
239
|
+
for project in projects:
|
|
240
|
+
row = {"name": project_name(project), "repo": project["repo"], "error": None}
|
|
241
|
+
try:
|
|
242
|
+
row.update(read_api(project) if source == "api" else read_git(project))
|
|
243
|
+
except (RuntimeError, OSError, subprocess.CalledProcessError, json.JSONDecodeError) as exc:
|
|
244
|
+
row.update({"branch": project.get("branch"), "state": None, "state_source": "missing",
|
|
245
|
+
"doctor": None, "last_release": None, "last_release_date": None,
|
|
246
|
+
"last_release_source": None, "error": str(exc)})
|
|
247
|
+
rows.append(row)
|
|
248
|
+
return rows
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def summary_cells(row: dict) -> list[str]:
|
|
252
|
+
name = row["name"] + ("*" if row.get("state_source") == "built" else "")
|
|
253
|
+
if row["error"]:
|
|
254
|
+
return [name, f"error: {row['error']}", "", "", "", "", ""]
|
|
255
|
+
state = row["state"]
|
|
256
|
+
if state is None:
|
|
257
|
+
return [name, "no state.json", "—", "—", "—", release_cell(row), "n/a"]
|
|
258
|
+
active = state.get("active_roadmap")
|
|
259
|
+
roadmap = f"{active.get('slug') or '?'} {active['done']}/{active['total']}" if active else "—"
|
|
260
|
+
doctor_cell = "n/a" if row["doctor"] is None else ("ok" if not row["doctor"] else
|
|
261
|
+
f"{len(row['doctor'])} failing")
|
|
262
|
+
return [name, roadmap, str(len(state.get("queued", []))), str(len(state.get("open_changes", []))),
|
|
263
|
+
str(len(state.get("owner_queue", []))), release_cell(row), doctor_cell]
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def owner_entries(rows: list[dict]) -> list[dict]:
|
|
267
|
+
entries = []
|
|
268
|
+
for row in rows:
|
|
269
|
+
for entry in (row["state"] or {}).get("owner_queue", []):
|
|
270
|
+
entries.append({"project": row["name"], **entry})
|
|
271
|
+
entries.sort(key=lambda entry: (entry.get("since") or "", entry["project"], entry.get("text", "")))
|
|
272
|
+
return entries
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def table(header: list[str], body: list[list[str]]) -> str:
|
|
276
|
+
def clean(cell: str) -> str:
|
|
277
|
+
return str(cell).replace("|", "\\|").replace("\n", " ")
|
|
278
|
+
lines = ["| " + " | ".join(header) + " |", "| " + " | ".join("---" for _ in header) + " |"]
|
|
279
|
+
lines += ["| " + " | ".join(clean(cell) for cell in cells) + " |" for cells in body]
|
|
280
|
+
return "\n".join(lines)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def main(argv: list[str] | None = None) -> int:
|
|
284
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
285
|
+
if "-h" in args or "--help" in args:
|
|
286
|
+
print(__doc__)
|
|
287
|
+
return 0
|
|
288
|
+
flags = {flag: flag in args for flag in ("--owner", "--json")}
|
|
289
|
+
args = [arg for arg in args if arg not in flags]
|
|
290
|
+
options = {"--config": None, "--source": "git"}
|
|
291
|
+
for key in options:
|
|
292
|
+
if key in args:
|
|
293
|
+
k = args.index(key)
|
|
294
|
+
options[key] = args[k + 1]
|
|
295
|
+
del args[k:k + 2]
|
|
296
|
+
if options["--source"] not in ("git", "api"):
|
|
297
|
+
print("--source is git or api", file=sys.stderr)
|
|
298
|
+
return 2
|
|
299
|
+
unknown = [arg for arg in args if arg.startswith("--")]
|
|
300
|
+
if unknown:
|
|
301
|
+
print(f"unknown option {unknown[0]} (see --help)", file=sys.stderr)
|
|
302
|
+
return 2
|
|
303
|
+
rows = collect(load_projects(args, options["--config"]), options["--source"])
|
|
304
|
+
generated = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
305
|
+
if flags["--json"]:
|
|
306
|
+
if flags["--owner"]:
|
|
307
|
+
print(json.dumps({"generated_at": generated, "owner_queue": owner_entries(rows)}, indent=2,
|
|
308
|
+
ensure_ascii=False))
|
|
309
|
+
else:
|
|
310
|
+
print(json.dumps({"generated_at": generated, "projects": rows}, indent=2, ensure_ascii=False))
|
|
311
|
+
elif flags["--owner"]:
|
|
312
|
+
entries = owner_entries(rows)
|
|
313
|
+
print(table(["since", "project", "kind", "what", "source"],
|
|
314
|
+
[[e.get("since") or "—", e["project"], e["kind"], e["text"],
|
|
315
|
+
e["source"].replace("context/", "")] for e in entries]) if entries else "Nothing waits for the owner.")
|
|
316
|
+
else:
|
|
317
|
+
print(table(["project", "active roadmap X/N", "queued", "open changes", "owner queue", "last release", "doctor"],
|
|
318
|
+
[summary_cells(row) for row in rows]))
|
|
319
|
+
if any(row.get("state_source") == "built" for row in rows):
|
|
320
|
+
print("\n* no context/state.json on the main branch yet; built from the markdown for this report")
|
|
321
|
+
errors = [row for row in rows if row["error"]]
|
|
322
|
+
for row in errors:
|
|
323
|
+
print(f"{row['name']}: {row['error']}", file=sys.stderr)
|
|
324
|
+
return 1 if errors else 0
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
if __name__ == "__main__":
|
|
328
|
+
sys.exit(main())
|
|
@@ -36,7 +36,7 @@ re-running is always safe. Report what you found and what you completed.
|
|
|
36
36
|
| Found | Do |
|
|
37
37
|
|---|---|
|
|
38
38
|
| `context/changes/<id>/change.md` | continue |
|
|
39
|
-
| no folder in `changes/`, but `context/archive/*-<id>/` | already archived: report the path. If its roadmap row is not `done` / `done_code`, offer to finish only steps 3 to
|
|
39
|
+
| no folder in `changes/`, but `context/archive/*-<id>/` | already archived: report the path. If its roadmap row is not `done` / `done_code`, offer to finish only steps 3 to 9 on the archived folder |
|
|
40
40
|
| `status: archived`, folder still in `changes/` | an earlier run stopped after the stamp. An uncommitted diff of change.md limited to the stamp is that run's own and does not count as uncommitted work; resume at step 2 once the other checks pass |
|
|
41
41
|
| `created` missing or not `YYYY-MM-DD` | stop: the archive folder name cannot be derived |
|
|
42
42
|
| nothing | stop: name the folders that do exist |
|
|
@@ -119,13 +119,20 @@ hard stops. Sample reports: [references/example-archive.md](references/example-a
|
|
|
119
119
|
hit to `archive/<created>-<id>`. Links inside the archived folder are relative and stay valid.
|
|
120
120
|
6. **Verify** that the old folder is gone, the new one exists, the roadmap row has exactly one
|
|
121
121
|
match, and no dangling `changes/<id>` links remain.
|
|
122
|
-
7. **
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
7. **State and doctor** (WORKFLOW §12; skip both with `--handoff`: the branch never writes
|
|
123
|
+
`context/state.json`, `wt-roadmap.py done` does after the merge). Once the paths below are
|
|
124
|
+
staged, run `python3 .claude/skills/softure-doctor/scripts/context_state.py write --staged`
|
|
125
|
+
(it reads the index and stages `context/state.json`), then
|
|
126
|
+
`python3 .claude/skills/softure-doctor/scripts/doctor.py`. Fix what this archive owns (this
|
|
127
|
+
change's `change.md` stamp, its Progress, its index rows, the state) and re-run; name any other
|
|
128
|
+
failure in the report without touching it. A project without the scripts installed skips this.
|
|
129
|
+
8. **Commit** with `chore(archive): close <change-id>`, staging only the touched paths: the
|
|
130
|
+
archive folder, the roadmap (unless step 3 left it unstaged), `context/state.json` (step 7), and
|
|
131
|
+
the files whose links you fixed. Before committing, `git diff --cached --name-only` must list nothing else. Never
|
|
125
132
|
`--no-verify`; if a hook fails, fix the cause and commit again (a new commit, never an amend).
|
|
126
133
|
In `--auto`, the commit body lists the soft warnings.
|
|
127
|
-
|
|
128
|
-
checks added, links fixed, edits skipped or left unstaged, and the commit SHA. The commit is
|
|
134
|
+
9. **Report:** old and new path, the stamp, the roadmap transition (or "no matching row"), owner
|
|
135
|
+
checks added, links fixed, edits skipped or left unstaged, the doctor result, and the commit SHA. The commit is
|
|
129
136
|
local: never push from this skill.
|
|
130
137
|
|
|
131
138
|
## Without a plan
|
|
@@ -193,6 +200,8 @@ row by row during the merge. Do not touch rows of other items.
|
|
|
193
200
|
with `--handoff`, `roadmap.md` untouched and `## Roadmap handoff` written instead.
|
|
194
201
|
- [ ] Open Manual items listed for the owner (manual mode), or none left but `(owner only: …)` ones,
|
|
195
202
|
written as owner steps (`--auto`); deploy prerequisites under `## Before the next release`.
|
|
203
|
+
- [ ] `context/state.json` regenerated from the index and staged, the doctor green on what this
|
|
204
|
+
archive owns (not with `--handoff`).
|
|
196
205
|
- [ ] No dangling links; one commit, conventional message, not pushed.
|
|
197
206
|
|
|
198
207
|
## Anti-patterns
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: softure-doctor
|
|
3
|
+
description: >
|
|
4
|
+
Check a project's context/ contract and keep its machine-readable state current: regenerate
|
|
5
|
+
context/state.json (active roadmap, queued roadmaps, open changes, and one owner_queue of
|
|
6
|
+
everything live that waits for the owner) and fail on drift: a roadmap left after its archive, archived
|
|
7
|
+
changes that are not stamped or have unticked Automated items, Summary placeholders instead of
|
|
8
|
+
merge SHAs, archived roadmaps with open rows, queued roadmaps that are fully done, backlog folders
|
|
9
|
+
without their roadmap, index rows pointing at missing files, and a missing or stale state.json.
|
|
10
|
+
Repairs history: --fix for the mechanical shapes, --sweep for a worklist with evidence that an
|
|
11
|
+
agent settles to zero. Use in CI, before an archive or roadmap commit, or when the user says
|
|
12
|
+
"check the context", "run the doctor", "what waits for me", "refresh the state", "clean up the
|
|
13
|
+
history", "sweep the doctor to zero".
|
|
14
|
+
argument-hint: "[doctor [--fix [--write] | --sweep | --baseline] | state write|print|check] [--root <dir>] [--json] [--staged]"
|
|
15
|
+
allowed-tools:
|
|
16
|
+
- Read
|
|
17
|
+
- Bash
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# softure-doctor: the context/ contract as a check
|
|
21
|
+
|
|
22
|
+
Contract: `WORKFLOW.md` §12 (state.json and the doctor), §5 (roadmap), §5.1 (queued roadmaps and the
|
|
23
|
+
backlog), §5.2 (closing a roadmap), §6 (Progress). Two scripts next to this file (`<S>` below):
|
|
24
|
+
|
|
25
|
+
| Command | Does |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `python3 <S>/doctor.py [--json]` | every check; exit 1 on a failure. Same as `npx softure-skills doctor` |
|
|
28
|
+
| `python3 <S>/doctor.py --fix [--write]` | the mechanical repairs of history, printed edit by edit; a dry run unless `--write` |
|
|
29
|
+
| `python3 <S>/doctor.py --sweep [--json]` | every remaining failure as a worklist entry with evidence pointers; read-only |
|
|
30
|
+
| `python3 <S>/doctor.py --baseline` | last resort only: accept today's failures in `context/doctor-baseline.json`; it only shrinks |
|
|
31
|
+
| `python3 <S>/context_state.py write` | regenerate `context/state.json` from the working tree |
|
|
32
|
+
| `python3 <S>/context_state.py write --staged` | regenerate it from what is staged, and stage it (use right before a commit) |
|
|
33
|
+
| `python3 <S>/context_state.py print` / `check` | show it / exit 1 when it is missing or stale |
|
|
34
|
+
|
|
35
|
+
`<S>` is `.claude/skills/softure-doctor/scripts` in an installed project.
|
|
36
|
+
|
|
37
|
+
## When it runs
|
|
38
|
+
|
|
39
|
+
- **CI of every adopting project**, documentation-only changes included: `npx softure-skills doctor`
|
|
40
|
+
(the installer prints this line). A project with history adds it after the rollout (WORKFLOW §12.4):
|
|
41
|
+
`--fix --write`, the sweep to zero, the owner's short list, then the CI line. Drift happens in the documents, so a CI that skips doc-only
|
|
42
|
+
changes misses it.
|
|
43
|
+
- **`softure-archive`** (on the main branch) and **`softure-roadmap`** (record, `--queue`, `--promote`,
|
|
44
|
+
`--close`): `context_state.py write --staged` right before the commit, then `doctor.py`; each fixes
|
|
45
|
+
what it owns and names the rest in its report.
|
|
46
|
+
- **`wt-roadmap.py`** writes `context/state.json` itself in every mode, in the same commit as `roadmap.md`.
|
|
47
|
+
|
|
48
|
+
## Reading the result
|
|
49
|
+
|
|
50
|
+
Each problem is one line `FAIL <code> <path>: <what>`. Fix the file it names, never the check:
|
|
51
|
+
|
|
52
|
+
| Code | Fix |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `roadmap-archived-not-removed` | the close moved a copy and left `roadmap.md`: remove it (promote the next one only on the owner's word) |
|
|
55
|
+
| `roadmap-status-mismatch` | set `status` to match the rows (`done` only when every row is closed; `waiting` belongs to queued roadmaps) |
|
|
56
|
+
| `archived-change-status` | stamp the archived `change.md` `status: archived` (and `archived_at`) |
|
|
57
|
+
| `archived-change-progress` | the change was archived with open Automated items: tick them with their SHA when the work is on the main branch, or mark them `~~dropped~~ — dropped: <reason>` |
|
|
58
|
+
| `archived-roadmap-open-items` | rows of an archived roadmap end `done`, `done_code`, dropped or carried (with where they went) |
|
|
59
|
+
| `archived-roadmap-open-checks` | an archived roadmap still holds unticked owner entries: tick each with its evidence (`— done: <sha / release / path>`), as obsolete (`— obsolete: <reason>`), or carry it to a live roadmap or an `owner-word` issue and tick it with where it went |
|
|
60
|
+
| `archived-roadmap-summary` | put the merge SHA (`git log --merges --grep "<change-id>"`) into each `## Summary` row |
|
|
61
|
+
| `queued-roadmap-done` | archive the finished queued roadmap to `foundation/archive/` |
|
|
62
|
+
| `backlog-without-roadmap` | move live entries to a queued roadmap, then remove the folder |
|
|
63
|
+
| `index-missing-file` | fix or drop the index row |
|
|
64
|
+
| `state-missing` / `state-stale` | `context_state.py write`, commit `context/state.json` |
|
|
65
|
+
| `baseline-stale` | a baselined failure is fixed: `doctor.py --baseline` rewrites the file without it (commit it) |
|
|
66
|
+
|
|
67
|
+
## Mechanical repairs: `--fix`
|
|
68
|
+
|
|
69
|
+
`doctor.py --fix` prints every edit it would make and the failures left after them; `--fix --write`
|
|
70
|
+
applies them. It writes only under `context/`, and a second run changes nothing. Two shapes are
|
|
71
|
+
mechanical:
|
|
72
|
+
|
|
73
|
+
- `archived-change-status`: the archived `change.md` gets `status: archived`, and the old value is kept
|
|
74
|
+
as `legacy_status` in its front matter (`implemented`, `done`, `impl_reviewed`, … stay readable);
|
|
75
|
+
- `index-missing-file` in an index inside an archive folder: the link is rewritten to the file's current
|
|
76
|
+
path when git history shows where it moved (renames followed across several moves); a file that was
|
|
77
|
+
deleted, not moved, is marked `(moved, not found; last seen in <sha>: <path>)`.
|
|
78
|
+
|
|
79
|
+
It skips, and names, every row it cannot settle from history (a live index, a target that was never
|
|
80
|
+
in git, a shallow checkout). Those and every other failure are judgement cases.
|
|
81
|
+
|
|
82
|
+
## Sweep history to zero
|
|
83
|
+
|
|
84
|
+
`doctor.py --sweep --json` lists every failure left after `--fix` as one entry per thing to settle:
|
|
85
|
+
`code`, `path`, `line` and the exact `text` of the line, `evidence` (pointers of kind `commit`,
|
|
86
|
+
`release` or `file`, each with a note), `settle` (what to do), and `owner: true` when the repository
|
|
87
|
+
holds no evidence at all. The evidence it looks for:
|
|
88
|
+
|
|
89
|
+
| Code | Evidence |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `archived-change-progress` | the SHA ticked items of the same phase cite; commits that touched the phase's files after the plan's date; the change's merge commit |
|
|
92
|
+
| `archived-roadmap-summary` | the merge (or squash) commit of the item's change on the main line; the last SHA of its archived plan |
|
|
93
|
+
| `archived-roadmap-open-items` | the item's archived change folder, its merge commit, the release that contains it, later roadmaps that mention it |
|
|
94
|
+
| `archived-roadmap-open-checks` | the same for the item the check names, plus the first release after the close (for pre-release steps) |
|
|
95
|
+
| anything else | the file to fix (`index-missing-file`: where git history says the file went, or that it never existed) |
|
|
96
|
+
|
|
97
|
+
Work the list in one change per repository (`docs(context): settle history to zero`):
|
|
98
|
+
|
|
99
|
+
1. `doctor.py --fix --write` first, and commit it, so the sweep holds only judgement cases.
|
|
100
|
+
2. For every entry, open its evidence (`git show <sha>`, the file, the release notes) and decide what
|
|
101
|
+
it proves. **Settle with evidence, never without:** write the proof into the line itself.
|
|
102
|
+
- Progress item: `- [x] <text> — <sha>` when that commit did it; `- [x] ~~<text>~~ — dropped: <reason>`
|
|
103
|
+
when the evidence shows it was never done and is no longer wanted.
|
|
104
|
+
- Summary placeholder: the merge SHA in the `Merge` cell.
|
|
105
|
+
- Open row: `done` (it shipped), `carried (to <path>)` (a later roadmap took it), `dropped (<reason>)`.
|
|
106
|
+
- Open check: `- [x] <text> — done: <sha | release | path>`, `- [x] <text> — obsolete: <reason, with
|
|
107
|
+
the evidence that made it obsolete>`, or carried (below).
|
|
108
|
+
3. **Only true owner items stay open, in one place.** An entry is the owner's when the evidence does
|
|
109
|
+
not settle it and only the owner can: a real decision that is still open, or a step outside the
|
|
110
|
+
repository (a production setting, a secret, an account) that nothing shows as done. Carry it to the
|
|
111
|
+
live roadmap's `## Owner decisions and checks` (or an `owner-word` issue, WORKFLOW §8.6) and tick
|
|
112
|
+
the archived line `— carried to <path | #N>`. Never carry a check whose work the evidence shows done,
|
|
113
|
+
and never tick a decision on the owner's behalf.
|
|
114
|
+
4. Regenerate the state (`context_state.py write`) and re-run `doctor.py` until it exits 0. Commit.
|
|
115
|
+
5. Report: failures per code before and after, and **one short list for the owner**: `ID | what the
|
|
116
|
+
owner decides or does | where it lives now`. Nothing else is left open.
|
|
117
|
+
|
|
118
|
+
An entry the agent cannot settle and that is not the owner's (the evidence is ambiguous) is named in
|
|
119
|
+
the report with its evidence, not ticked.
|
|
120
|
+
|
|
121
|
+
## Baseline: the last resort
|
|
122
|
+
|
|
123
|
+
`doctor.py --baseline` writes the failures that remain to `context/doctor-baseline.json`. The check
|
|
124
|
+
then reports them as `baselined` and fails only on a new failure and on a baseline entry that was
|
|
125
|
+
fixed but not removed (`baseline-stale`). It only shrinks: run again, it drops the fixed entries,
|
|
126
|
+
refuses to add new ones (exit 1, it names them) and removes the file once it is empty. State findings
|
|
127
|
+
are never baselined, and `--fix` and `--sweep` ignore the baseline.
|
|
128
|
+
|
|
129
|
+
Use it only when the owner decides a project cannot finish the sweep in one change; never to get a red
|
|
130
|
+
CI green, and never on your own initiative. Record why in the commit. The sweep to zero is the path.
|
|
131
|
+
|
|
132
|
+
A project that has never written `context/state.json` gets a `note`, not a failure, until the first
|
|
133
|
+
script run creates it.
|
|
134
|
+
|
|
135
|
+
## Rules
|
|
136
|
+
|
|
137
|
+
- `context/state.json` is written by scripts only. Never edit it by hand; regenerate it.
|
|
138
|
+
- Never tick, fill or close anything in the sweep without the evidence written into the line.
|
|
139
|
+
- The doctor never edits anything, except `--fix --write`, which is run on purpose and edits only the
|
|
140
|
+
two mechanical shapes above. A skill that runs it fixes only the files it owns in that run.
|
|
141
|
+
- `open_changes`, `updated_at` and owner-queue entries from open changes are refreshed on every write
|
|
142
|
+
and never make the file stale, so a change branch that edits its own `change.md` keeps a green doctor.
|
|
143
|
+
- `owner_queue` reads only what is live (WORKFLOW §12.1): an unticked entry left in an archived roadmap
|
|
144
|
+
is a failure to settle, not something that waits for the owner.
|
|
145
|
+
- Owner-word issues (label `owner-word`, WORKFLOW §8.6) live on the forge, not in `state.json`;
|
|
146
|
+
an aggregator reads both.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/SOFTURE/SKILLS/skills/softure-doctor/references/state.schema.json",
|
|
4
|
+
"title": "context/state.json",
|
|
5
|
+
"description": "Machine-readable state of a project that follows the SOFTURE workflow (WORKFLOW.md §12). Written only by scripts.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schema_version", "project", "mode", "main_branch", "updated_at", "active_roadmap", "queued",
|
|
8
|
+
"open_changes", "owner_queue", "last_release"],
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"schema_version": { "type": "integer", "enum": [1] },
|
|
12
|
+
"project": { "type": ["string", "null"], "description": "workflow.json `project`, else the roadmap's `project`" },
|
|
13
|
+
"mode": { "type": "string", "enum": ["manual", "autonomous"] },
|
|
14
|
+
"main_branch": { "type": ["string", "null"] },
|
|
15
|
+
"updated_at": { "type": "string", "description": "UTC ISO 8601; changes only when the content does" },
|
|
16
|
+
"active_roadmap": {
|
|
17
|
+
"type": ["object", "null"],
|
|
18
|
+
"required": ["slug", "title", "status", "version", "path", "done", "total", "items"],
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"properties": {
|
|
21
|
+
"slug": { "type": ["string", "null"] },
|
|
22
|
+
"title": { "type": ["string", "null"] },
|
|
23
|
+
"status": { "type": ["string", "null"] },
|
|
24
|
+
"version": { "type": ["string", "null"] },
|
|
25
|
+
"path": { "type": "string" },
|
|
26
|
+
"done": { "type": "integer", "description": "rows done or done_code" },
|
|
27
|
+
"total": { "type": "integer" },
|
|
28
|
+
"items": {
|
|
29
|
+
"type": "array",
|
|
30
|
+
"description": "rows not done yet",
|
|
31
|
+
"items": {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"required": ["id", "change_id", "outcome", "status", "stage", "since", "detail", "prerequisites", "mode"],
|
|
34
|
+
"additionalProperties": false,
|
|
35
|
+
"properties": {
|
|
36
|
+
"id": { "type": "string" },
|
|
37
|
+
"change_id": { "type": ["string", "null"] },
|
|
38
|
+
"outcome": { "type": ["string", "null"] },
|
|
39
|
+
"status": { "type": "string" },
|
|
40
|
+
"stage": { "type": ["string", "null"] },
|
|
41
|
+
"since": { "type": ["string", "null"] },
|
|
42
|
+
"detail": { "type": ["string", "null"] },
|
|
43
|
+
"prerequisites": { "type": "array", "items": { "type": "string" } },
|
|
44
|
+
"mode": { "type": ["string", "null"] }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"queued": {
|
|
51
|
+
"type": "array",
|
|
52
|
+
"items": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"required": ["slug", "title", "status", "path", "start_condition", "done", "total", "items"],
|
|
55
|
+
"additionalProperties": false,
|
|
56
|
+
"properties": {
|
|
57
|
+
"slug": { "type": "string" },
|
|
58
|
+
"title": { "type": ["string", "null"] },
|
|
59
|
+
"status": { "type": ["string", "null"] },
|
|
60
|
+
"path": { "type": "string" },
|
|
61
|
+
"start_condition": { "type": ["string", "null"] },
|
|
62
|
+
"done": { "type": "integer" },
|
|
63
|
+
"total": { "type": "integer" },
|
|
64
|
+
"items": {
|
|
65
|
+
"type": "array",
|
|
66
|
+
"items": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"required": ["id", "change_id", "outcome", "status"],
|
|
69
|
+
"additionalProperties": false,
|
|
70
|
+
"properties": {
|
|
71
|
+
"id": { "type": "string" },
|
|
72
|
+
"change_id": { "type": ["string", "null"] },
|
|
73
|
+
"outcome": { "type": ["string", "null"] },
|
|
74
|
+
"status": { "type": "string" }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"open_changes": {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"description": "folders in context/changes/ on the branch the file was written on; refreshed on every script run",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"required": ["change_id", "title", "status", "roadmap_item", "updated", "stage"],
|
|
87
|
+
"additionalProperties": false,
|
|
88
|
+
"properties": {
|
|
89
|
+
"change_id": { "type": "string" },
|
|
90
|
+
"title": { "type": ["string", "null"] },
|
|
91
|
+
"status": { "type": ["string", "null"] },
|
|
92
|
+
"roadmap_item": { "type": ["string", "null"] },
|
|
93
|
+
"updated": { "type": ["string", "null"] },
|
|
94
|
+
"stage": { "type": ["string", "null"] }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"owner_queue": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"description": "everything that waits for the owner, oldest first",
|
|
101
|
+
"items": {
|
|
102
|
+
"type": "object",
|
|
103
|
+
"required": ["kind", "source", "item", "since", "text"],
|
|
104
|
+
"additionalProperties": false,
|
|
105
|
+
"properties": {
|
|
106
|
+
"kind": { "type": "string", "enum": ["word", "decision", "step", "secret"] },
|
|
107
|
+
"source": { "type": "string", "description": "file, then `#` and the heading" },
|
|
108
|
+
"item": { "type": ["string", "null"], "description": "roadmap item ID, when the entry names one" },
|
|
109
|
+
"since": { "type": ["string", "null"], "description": "YYYY-MM-DD" },
|
|
110
|
+
"text": { "type": "string" }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"last_release": {
|
|
115
|
+
"type": ["object", "null"],
|
|
116
|
+
"required": ["version", "date", "source"],
|
|
117
|
+
"additionalProperties": false,
|
|
118
|
+
"properties": {
|
|
119
|
+
"version": { "type": "string" },
|
|
120
|
+
"date": { "type": ["string", "null"] },
|
|
121
|
+
"source": { "type": "string" }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|