@softure-ai/skills 0.20.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/README.md +21 -2
- package/WORKFLOW.md +77 -8
- package/package.json +1 -1
- package/scripts/install.mjs +4 -1
- package/scripts/portfolio.py +84 -15
- package/skills/softure-doctor/SKILL.md +85 -8
- package/skills/softure-doctor/scripts/context_state.py +58 -14
- package/skills/softure-doctor/scripts/doctor.py +248 -15
- 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 +9 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""softure-doctor --fix: the mechanical repairs of history, as a dry run unless `--write` is given.
|
|
3
|
+
|
|
4
|
+
doctor.py --fix [--write] [--json] [--root <dir>]
|
|
5
|
+
npx softure-skills doctor --fix [--write]
|
|
6
|
+
|
|
7
|
+
Only two kinds of failure are mechanical, and only files under `context/` are edited:
|
|
8
|
+
|
|
9
|
+
archived-change-status an archived change.md gets `status: archived`; the old value is kept as
|
|
10
|
+
`legacy_status` in its front matter (a missing status gets none)
|
|
11
|
+
index-missing-file a row of an index inside an archive folder (`context/archive/`,
|
|
12
|
+
`context/foundation/archive/`) that links a missing file is rewritten to the
|
|
13
|
+
file's current path when git history shows where it moved (rename detection,
|
|
14
|
+
followed across several moves); a file that was deleted, not moved, is marked
|
|
15
|
+
`(moved, not found; last seen in <sha>: <path>)` with the last commit that had it
|
|
16
|
+
|
|
17
|
+
Everything else (and an index row whose target was never in git history, or any row when the
|
|
18
|
+
checkout has no full history) is a judgement case: `doctor.py --sweep` lists it with evidence.
|
|
19
|
+
Every edit is printed; a second run after `--write` changes nothing.
|
|
20
|
+
|
|
21
|
+
Importable: `from doctor_fix import plan_fixes, apply_fixes`.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import os
|
|
26
|
+
import re
|
|
27
|
+
import subprocess
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
sys.dont_write_bytecode = True
|
|
31
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
32
|
+
from context_state import frontmatter # noqa: E402
|
|
33
|
+
|
|
34
|
+
ARCHIVE_PREFIXES = ("context/archive/", "context/foundation/archive/")
|
|
35
|
+
GONE_MARK = "moved, not found"
|
|
36
|
+
MAX_HOPS = 10
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# ---------------------------------------------------------------- git history
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class History:
|
|
43
|
+
"""Where files under a git checkout went. `usable` is False without git or with a shallow clone."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, root: str | None) -> None:
|
|
46
|
+
self.root = root
|
|
47
|
+
self.usable = False
|
|
48
|
+
if root:
|
|
49
|
+
probe = self._git("rev-parse", "--is-shallow-repository")
|
|
50
|
+
self.usable = probe.returncode == 0 and probe.stdout.strip() == "false"
|
|
51
|
+
|
|
52
|
+
def _git(self, *args: str) -> subprocess.CompletedProcess:
|
|
53
|
+
return subprocess.run(["git", "-C", self.root or ".", *args], capture_output=True, text=True)
|
|
54
|
+
|
|
55
|
+
def short(self, sha: str) -> str:
|
|
56
|
+
out = self._git("rev-parse", "--short", sha)
|
|
57
|
+
return out.stdout.strip() if out.returncode == 0 else sha[:7]
|
|
58
|
+
|
|
59
|
+
def exists_now(self, rel: str) -> bool:
|
|
60
|
+
return os.path.exists(os.path.join(self.root or ".", rel))
|
|
61
|
+
|
|
62
|
+
def trace(self, rel: str) -> tuple[str, str] | None:
|
|
63
|
+
"""("moved", <current path>) or ("gone", <short sha of the last commit that had it>); None when
|
|
64
|
+
the path was never in history (or history is not usable)."""
|
|
65
|
+
if not self.usable:
|
|
66
|
+
return None
|
|
67
|
+
current = rel.rstrip("/")
|
|
68
|
+
last_having = None
|
|
69
|
+
for _ in range(MAX_HOPS):
|
|
70
|
+
if current != rel.rstrip("/") and self.exists_now(current):
|
|
71
|
+
return "moved", current
|
|
72
|
+
log = self._git("log", "-1", "--no-merges", "--format=%H", "--", current)
|
|
73
|
+
sha = log.stdout.strip()
|
|
74
|
+
if log.returncode != 0 or not sha:
|
|
75
|
+
break
|
|
76
|
+
parent = self._git("rev-parse", "-q", "--verify", f"{sha}^")
|
|
77
|
+
last_having = parent.stdout.strip() if parent.returncode == 0 else sha
|
|
78
|
+
moved_to = self._renamed_in(sha, current)
|
|
79
|
+
if not moved_to or moved_to == current:
|
|
80
|
+
break
|
|
81
|
+
current = moved_to
|
|
82
|
+
if last_having is None:
|
|
83
|
+
return None
|
|
84
|
+
if current != rel.rstrip("/") and self.exists_now(current):
|
|
85
|
+
return "moved", current
|
|
86
|
+
return "gone", self.short(last_having)
|
|
87
|
+
|
|
88
|
+
def _renamed_in(self, sha: str, path: str) -> str | None:
|
|
89
|
+
shown = self._git("show", "-M", "--name-status", "--format=", sha)
|
|
90
|
+
moves: dict[str, int] = {}
|
|
91
|
+
for line in shown.stdout.splitlines():
|
|
92
|
+
parts = line.split("\t")
|
|
93
|
+
if len(parts) != 3 or not parts[0].startswith("R"):
|
|
94
|
+
continue
|
|
95
|
+
old, new = parts[1], parts[2]
|
|
96
|
+
if old == path:
|
|
97
|
+
return new
|
|
98
|
+
if old.startswith(path + "/"): # a folder: where most of its files went
|
|
99
|
+
rest = old[len(path):]
|
|
100
|
+
if new.endswith(rest):
|
|
101
|
+
target = new[: len(new) - len(rest)]
|
|
102
|
+
moves[target] = moves.get(target, 0) + 1
|
|
103
|
+
return max(moves, key=moves.get) if moves else None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ---------------------------------------------------------------- the edits
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def fix_change_status(text: str) -> tuple[str, str] | None:
|
|
110
|
+
"""The change.md text with `status: archived` (and `legacy_status`), and what changed; None when fine."""
|
|
111
|
+
match = re.match(r"^---\n(.*?)\n---", text, re.DOTALL)
|
|
112
|
+
if not match:
|
|
113
|
+
return "---\nstatus: archived\n---\n\n" + text, "status missing -> archived (front matter added)"
|
|
114
|
+
lines = match.group(1).split("\n")
|
|
115
|
+
meta = frontmatter(text)
|
|
116
|
+
old = meta.get("status")
|
|
117
|
+
if old == "archived":
|
|
118
|
+
return None
|
|
119
|
+
index = next((i for i, line in enumerate(lines) if re.match(r"^status:", line)), None)
|
|
120
|
+
if index is None:
|
|
121
|
+
lines.append("status: archived")
|
|
122
|
+
what = "status missing -> archived"
|
|
123
|
+
else:
|
|
124
|
+
raw = re.sub(r"^status:\s*", "", lines[index]).split(" #", 1)[0].strip()
|
|
125
|
+
lines[index] = "status: archived"
|
|
126
|
+
if "legacy_status" not in meta and raw:
|
|
127
|
+
lines.insert(index + 1, f"legacy_status: {raw}")
|
|
128
|
+
what = f"status {old or 'empty'} -> archived" + (f" (legacy_status: {raw})" if raw else "")
|
|
129
|
+
body = "---\n" + "\n".join(lines) + "\n---" + text[match.end():]
|
|
130
|
+
return body, what
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _relative(new_path: str, missing: dict, original_candidate: str) -> str:
|
|
134
|
+
"""`new_path` written the way the row wrote the old one (relative to the index, context/ or the root)."""
|
|
135
|
+
target = missing["target"]
|
|
136
|
+
anchor = ""
|
|
137
|
+
if missing["kind"] == "link" and "#" in target:
|
|
138
|
+
anchor = "#" + target.split("#", 1)[1]
|
|
139
|
+
trailing = "/" if target.split("#", 1)[0].endswith("/") else ""
|
|
140
|
+
if missing["kind"] == "link":
|
|
141
|
+
start = missing["base"]
|
|
142
|
+
else:
|
|
143
|
+
base = missing["base"]
|
|
144
|
+
joined = os.path.normpath(os.path.join(base, target)).replace(os.sep, "/").rstrip("/")
|
|
145
|
+
context_joined = os.path.normpath(os.path.join("context", target)).replace(os.sep, "/").rstrip("/")
|
|
146
|
+
start = base if joined == original_candidate else ("context" if context_joined == original_candidate else ".")
|
|
147
|
+
rel = os.path.relpath(new_path, start).replace(os.sep, "/") if start != "." else new_path
|
|
148
|
+
return rel + trailing + anchor
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _replace_target(line: str, missing: dict, replacement: str | None, gone_note: str | None) -> str:
|
|
152
|
+
target = missing["target"]
|
|
153
|
+
if missing["kind"] == "link":
|
|
154
|
+
pattern = re.compile(r"\[([^\]]*)\]\(" + re.escape(target) + r"((?:\s+\"[^\"]*\")?)\)")
|
|
155
|
+
if replacement is not None:
|
|
156
|
+
return pattern.sub(lambda m: f"[{m.group(1)}]({replacement}{m.group(2)})", line, count=1)
|
|
157
|
+
return pattern.sub(lambda m: f"{m.group(1)} ({gone_note}: {target})", line, count=1)
|
|
158
|
+
if replacement is not None:
|
|
159
|
+
return line.replace(f"`{target}`", f"`{replacement}`", 1)
|
|
160
|
+
return line.replace(f"`{target}`", f"{target} ({gone_note})", 1)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def plan_fixes(reader, root: str | None) -> dict:
|
|
164
|
+
"""The edits `--fix` would make: {"edits": [...], "skipped": [...], "files": {path: new text}}."""
|
|
165
|
+
import doctor # noqa: E402 (doctor imports this module lazily too)
|
|
166
|
+
|
|
167
|
+
edits: list[dict] = []
|
|
168
|
+
skipped: list[dict] = []
|
|
169
|
+
files: dict[str, str] = {}
|
|
170
|
+
|
|
171
|
+
for name, is_dir in reader.listdir(doctor.ARCHIVE_DIR):
|
|
172
|
+
if not is_dir:
|
|
173
|
+
continue
|
|
174
|
+
rel = f"{doctor.ARCHIVE_DIR}/{name}/change.md"
|
|
175
|
+
text = reader.read(rel)
|
|
176
|
+
if text is None:
|
|
177
|
+
continue
|
|
178
|
+
fixed = fix_change_status(text)
|
|
179
|
+
if fixed:
|
|
180
|
+
files[rel] = fixed[0]
|
|
181
|
+
edits.append({"code": "archived-change-status", "path": rel, "what": fixed[1]})
|
|
182
|
+
|
|
183
|
+
history = History(root)
|
|
184
|
+
for missing in doctor.missing_index_targets(reader):
|
|
185
|
+
if not missing["path"].startswith(ARCHIVE_PREFIXES):
|
|
186
|
+
skipped.append({"code": "index-missing-file", "path": missing["path"], "target": missing["target"],
|
|
187
|
+
"why": "a live index: fix or drop the row by hand (--sweep)"})
|
|
188
|
+
continue
|
|
189
|
+
if not history.usable:
|
|
190
|
+
skipped.append({"code": "index-missing-file", "path": missing["path"], "target": missing["target"],
|
|
191
|
+
"why": "no full git history in this checkout"})
|
|
192
|
+
continue
|
|
193
|
+
found = None
|
|
194
|
+
for candidate in missing["candidates"]:
|
|
195
|
+
traced = history.trace(candidate)
|
|
196
|
+
if traced:
|
|
197
|
+
found = (candidate, traced)
|
|
198
|
+
break
|
|
199
|
+
if not found:
|
|
200
|
+
skipped.append({"code": "index-missing-file", "path": missing["path"], "target": missing["target"],
|
|
201
|
+
"why": "never in git history: fix or drop the row (--sweep)"})
|
|
202
|
+
continue
|
|
203
|
+
candidate, (kind, value) = found
|
|
204
|
+
text = files.get(missing["path"], reader.read(missing["path"]) or "")
|
|
205
|
+
lines = text.split("\n")
|
|
206
|
+
index = missing["line"] - 1
|
|
207
|
+
if index >= len(lines):
|
|
208
|
+
continue
|
|
209
|
+
if kind == "moved":
|
|
210
|
+
new_target = _relative(value, missing, candidate)
|
|
211
|
+
lines[index] = _replace_target(lines[index], missing, new_target, None)
|
|
212
|
+
what = f"`{missing['target']}` -> `{new_target}` (moved to {value})"
|
|
213
|
+
else:
|
|
214
|
+
note = f"{GONE_MARK}; last seen in {value}"
|
|
215
|
+
lines[index] = _replace_target(lines[index], missing, None, note)
|
|
216
|
+
what = f"`{missing['target']}` marked ({note})"
|
|
217
|
+
files[missing["path"]] = "\n".join(lines)
|
|
218
|
+
edits.append({"code": "index-missing-file", "path": missing["path"], "line": missing["line"], "what": what})
|
|
219
|
+
return {"edits": edits, "skipped": skipped, "files": files}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def apply_fixes(root: str, files: dict[str, str]) -> None:
|
|
223
|
+
for rel, text in files.items():
|
|
224
|
+
if not rel.startswith("context/"):
|
|
225
|
+
raise ValueError(f"--fix writes only under context/, not {rel}")
|
|
226
|
+
with open(os.path.join(root, rel), "w", encoding="utf-8") as fh:
|
|
227
|
+
fh.write(text)
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""softure-doctor --sweep: every remaining failure as a worklist entry with the evidence to settle it.
|
|
3
|
+
|
|
4
|
+
doctor.py --sweep [--json] [--root <dir>]
|
|
5
|
+
npx softure-skills doctor --sweep [--json]
|
|
6
|
+
|
|
7
|
+
Read-only. One entry per thing to settle (an unticked Progress item, a Summary placeholder, an open
|
|
8
|
+
row, an open owner check, ...), each with `path`, `line` and the exact `text` of the line, the
|
|
9
|
+
evidence found in the repository, and how to settle it:
|
|
10
|
+
|
|
11
|
+
archived-change-progress commits that touched the phase's files after the plan's date, the SHA
|
|
12
|
+
ticked items of the same phase cite, and the change's merge commit
|
|
13
|
+
archived-roadmap-summary the merge (or squash) commit of the item's change on the main branch
|
|
14
|
+
archived-roadmap-open-items the item's archived change folder, merge commit, the release that
|
|
15
|
+
contains it, and later roadmaps that mention the item
|
|
16
|
+
archived-roadmap-open-checks the same for the item the check names, plus the first release after
|
|
17
|
+
the roadmap was closed
|
|
18
|
+
anything else the file to fix (and `--fix` for the mechanical shapes)
|
|
19
|
+
|
|
20
|
+
An entry with no evidence at all carries `"owner": true`: only the owner can settle it, and it goes to
|
|
21
|
+
the owner's list (WORKFLOW §12.4). The skill section "Sweep history to zero" tells an agent how to work
|
|
22
|
+
the list: settle every entry with its evidence, never without.
|
|
23
|
+
|
|
24
|
+
Importable: `from doctor_sweep import sweep`.
|
|
25
|
+
"""
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
|
|
33
|
+
sys.dont_write_bytecode = True
|
|
34
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
35
|
+
from context_state import ( # noqa: E402
|
|
36
|
+
ARCHIVE_ROADMAPS_DIR, OWNER_SECTION, QUEUED_DIR, RELEASE_SECTION, ROADMAP_PATH, CHECKBOX_RE,
|
|
37
|
+
ITEM_REF_RE, archived_roadmap_files, frontmatter, pending_release_roadmap, roadmap_rows, sections,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
SHA_TAIL_RE = re.compile(r"\b([0-9a-f]{7,40})\b")
|
|
41
|
+
PATH_RE = re.compile(r"`((?:[\w.-]+/)+[\w.-]+\.\w+|[\w.-]+\.(?:ts|tsx|js|jsx|mjs|py|cs|go|rs|java|kt|rb|php|sql|css|scss|html|json|yml|yaml|sh))`")
|
|
42
|
+
SEMVER_TAG_RE = re.compile(r"^v?\d+\.\d+\.\d+")
|
|
43
|
+
LIMIT = 3
|
|
44
|
+
|
|
45
|
+
SETTLE = {
|
|
46
|
+
"archived-change-progress": "tick it with the SHA that did it (`- [x] <text> — <sha>`), or, when the work was "
|
|
47
|
+
"never done, `- [x] ~~<text>~~ — dropped: <reason>`",
|
|
48
|
+
"archived-roadmap-summary": "put the merge SHA into the row's Merge cell (`—` only for a carried or dropped row)",
|
|
49
|
+
"archived-roadmap-open-items": "set the row's status to `done` when the evidence shows it shipped, "
|
|
50
|
+
"`carried (to <path>)` when a later roadmap took it, or `dropped (<reason>)`",
|
|
51
|
+
"archived-roadmap-open-checks": "tick it with its evidence (`— done: <sha | release | path>`), as obsolete "
|
|
52
|
+
"(`— obsolete: <reason>`), or carry it to a live roadmap or an owner-word issue "
|
|
53
|
+
"and tick it with where it went (`— carried to <path | #N>`)",
|
|
54
|
+
"archived-change-status": "mechanical: `doctor --fix --write`",
|
|
55
|
+
"index-missing-file": "point the row at the file's current path, or drop the row",
|
|
56
|
+
"roadmap-archived-not-removed": "remove roadmap.md (the close moved it)",
|
|
57
|
+
"roadmap-status-mismatch": "set `status` to match the rows",
|
|
58
|
+
"queued-roadmap-done": "archive the finished queued roadmap to foundation/archive/",
|
|
59
|
+
"backlog-without-roadmap": "move live entries to a queued roadmap, then remove the folder",
|
|
60
|
+
"state-missing": "`npx softure-skills state`, commit context/state.json",
|
|
61
|
+
"state-stale": "`npx softure-skills state`, commit context/state.json",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Git:
|
|
66
|
+
"""Read-only questions to the repository's history; every answer is [] without full history."""
|
|
67
|
+
|
|
68
|
+
def __init__(self, root: str | None) -> None:
|
|
69
|
+
self.root = root
|
|
70
|
+
self.usable = False
|
|
71
|
+
if root:
|
|
72
|
+
probe = self._run("rev-parse", "--is-shallow-repository")
|
|
73
|
+
self.usable = probe.returncode == 0 and probe.stdout.strip() == "false"
|
|
74
|
+
|
|
75
|
+
def _run(self, *args: str) -> subprocess.CompletedProcess:
|
|
76
|
+
return subprocess.run(["git", "-C", self.root or ".", *args], capture_output=True, text=True)
|
|
77
|
+
|
|
78
|
+
def _commits(self, *args: str) -> list[dict]:
|
|
79
|
+
if not self.usable:
|
|
80
|
+
return []
|
|
81
|
+
out = self._run("log", "--format=%h%x09%ad%x09%s", "--date=short", *args)
|
|
82
|
+
commits = []
|
|
83
|
+
for line in out.stdout.splitlines():
|
|
84
|
+
parts = line.split("\t", 2)
|
|
85
|
+
if len(parts) == 3:
|
|
86
|
+
commits.append({"sha": parts[0], "date": parts[1], "subject": parts[2]})
|
|
87
|
+
return commits
|
|
88
|
+
|
|
89
|
+
def touching(self, files: list[str], since: str | None) -> list[dict]:
|
|
90
|
+
if not files:
|
|
91
|
+
return []
|
|
92
|
+
args = ["--no-merges", f"-n{LIMIT}"] + ([f"--since={since}"] if since else []) + ["--", *files]
|
|
93
|
+
return self._commits(*args)
|
|
94
|
+
|
|
95
|
+
def merges_for(self, change_id: str | None) -> list[dict]:
|
|
96
|
+
"""First-parent commits of the main line that name the change (merge commits and squash merges)."""
|
|
97
|
+
if not change_id:
|
|
98
|
+
return []
|
|
99
|
+
return self._commits("--first-parent", "-i", "--fixed-strings", f"--grep={change_id}", f"-n{LIMIT}")
|
|
100
|
+
|
|
101
|
+
def release_containing(self, sha: str) -> str | None:
|
|
102
|
+
if not self.usable:
|
|
103
|
+
return None
|
|
104
|
+
out = self._run("tag", "--contains", sha, "--sort=v:refname")
|
|
105
|
+
tags = [tag for tag in out.stdout.split() if SEMVER_TAG_RE.match(tag)]
|
|
106
|
+
return tags[0] if tags else None
|
|
107
|
+
|
|
108
|
+
def release_after(self, day: str | None) -> dict | None:
|
|
109
|
+
"""The first release tag created on or after `day`."""
|
|
110
|
+
if not self.usable or not day:
|
|
111
|
+
return None
|
|
112
|
+
out = self._run("for-each-ref", "--sort=creatordate", "--format=%(refname:short)\t%(creatordate:short)",
|
|
113
|
+
"refs/tags")
|
|
114
|
+
for line in out.stdout.splitlines():
|
|
115
|
+
tag, _, date = line.partition("\t")
|
|
116
|
+
if SEMVER_TAG_RE.match(tag) and date >= day:
|
|
117
|
+
return {"tag": tag, "date": date}
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _evidence(kind: str, ref: str, note: str) -> dict:
|
|
122
|
+
return {"kind": kind, "ref": ref, "note": note}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _commit_evidence(commits: list[dict], note: str) -> list[dict]:
|
|
126
|
+
return [_evidence("commit", c["sha"], f"{note}: {c['date']} {c['subject']}") for c in commits]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _lines(text: str) -> list[str]:
|
|
130
|
+
return (text or "").split("\n")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _archived_change_folder(reader, change_id: str | None) -> str | None:
|
|
134
|
+
if not change_id:
|
|
135
|
+
return None
|
|
136
|
+
for name, is_dir in reader.listdir("context/archive"):
|
|
137
|
+
if is_dir and re.sub(r"^\d{4}-\d{2}-\d{2}-", "", name) == change_id:
|
|
138
|
+
return f"context/archive/{name}"
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _date_of(path: str, meta: dict) -> str | None:
|
|
143
|
+
match = re.search(r"(\d{4}-\d{2}-\d{2})", os.path.basename(path.rstrip("/")))
|
|
144
|
+
return meta.get("created") or meta.get("updated") or (match.group(1) if match else None)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _later_mentions(reader, path: str, needles: list[str]) -> list[dict]:
|
|
148
|
+
"""Roadmaps other than `path` (later archived ones, queued, the live one) that mention a needle."""
|
|
149
|
+
candidates = [p for p in archived_roadmap_files(reader) if p > path]
|
|
150
|
+
candidates += [f"{QUEUED_DIR}/{name}" for name, is_dir in reader.listdir(QUEUED_DIR)
|
|
151
|
+
if not is_dir and name.endswith(".md")]
|
|
152
|
+
candidates.append(ROADMAP_PATH)
|
|
153
|
+
found = []
|
|
154
|
+
for candidate in candidates:
|
|
155
|
+
text = reader.read(candidate)
|
|
156
|
+
if text is None:
|
|
157
|
+
continue
|
|
158
|
+
for number, line in enumerate(_lines(text), start=1):
|
|
159
|
+
if any(needle and re.search(r"(?<![\w-])" + re.escape(needle) + r"(?![\w-])", line)
|
|
160
|
+
for needle in needles):
|
|
161
|
+
found.append(_evidence("file", f"{candidate}:{number}", line.strip()[:160]))
|
|
162
|
+
break
|
|
163
|
+
return found
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _item_evidence(reader, git: Git, path: str, item: str | None, change_id: str | None) -> list[dict]:
|
|
167
|
+
evidence: list[dict] = []
|
|
168
|
+
folder = _archived_change_folder(reader, change_id)
|
|
169
|
+
if folder:
|
|
170
|
+
evidence.append(_evidence("file", folder + "/", "the item's change was archived"))
|
|
171
|
+
merges = git.merges_for(change_id)
|
|
172
|
+
evidence += _commit_evidence(merges, "merge of the item's change")
|
|
173
|
+
for commit in merges[:1]:
|
|
174
|
+
release = git.release_containing(commit["sha"])
|
|
175
|
+
if release:
|
|
176
|
+
evidence.append(_evidence("release", release, f"the first release that contains {commit['sha']}"))
|
|
177
|
+
evidence += _later_mentions(reader, path, [item, change_id] if item else [change_id])
|
|
178
|
+
return evidence
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _entry(code: str, path: str, line: int | None, text: str, subject: str, evidence: list[dict],
|
|
182
|
+
**extra) -> dict:
|
|
183
|
+
return {"code": code, "path": path, "line": line, "text": text, "subject": subject, "evidence": evidence,
|
|
184
|
+
"owner": not evidence, "settle": SETTLE.get(code, "fix the file it names"), **extra}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
# ---------------------------------------------------------------- per failure code
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _progress_entries(reader, git: Git, path: str) -> list[dict]:
|
|
191
|
+
import doctor
|
|
192
|
+
|
|
193
|
+
text = reader.read(path) or ""
|
|
194
|
+
folder = os.path.dirname(path)
|
|
195
|
+
change = frontmatter(reader.read(f"{folder}/change.md") or "")
|
|
196
|
+
change_id = change.get("change_id") or re.sub(r"^\d{4}-\d{2}-\d{2}-", "", os.path.basename(folder))
|
|
197
|
+
since = _date_of(folder, change)
|
|
198
|
+
phase_files: dict[str, list[str]] = {}
|
|
199
|
+
current = None
|
|
200
|
+
for line in _lines(text):
|
|
201
|
+
heading = re.match(r"^## Phase (\d+)", line)
|
|
202
|
+
if heading:
|
|
203
|
+
current = heading.group(1)
|
|
204
|
+
continue
|
|
205
|
+
if line.startswith("## "):
|
|
206
|
+
current = None
|
|
207
|
+
if current:
|
|
208
|
+
phase_files.setdefault(current, []).extend(PATH_RE.findall(line))
|
|
209
|
+
open_items = set(doctor.unticked_automated(text))
|
|
210
|
+
entries = []
|
|
211
|
+
in_progress = False
|
|
212
|
+
phase = None
|
|
213
|
+
phase_shas: dict[str, list[str]] = {}
|
|
214
|
+
pending: list[tuple[int, str, str, str]] = []
|
|
215
|
+
for number, line in enumerate(_lines(text), start=1):
|
|
216
|
+
if line.startswith("## "):
|
|
217
|
+
in_progress = line[3:].strip() == "Progress"
|
|
218
|
+
continue
|
|
219
|
+
if not in_progress:
|
|
220
|
+
continue
|
|
221
|
+
heading = re.match(r"^### Phase (\d+)", line)
|
|
222
|
+
if heading:
|
|
223
|
+
phase = heading.group(1)
|
|
224
|
+
continue
|
|
225
|
+
box = CHECKBOX_RE.match(line)
|
|
226
|
+
if not box:
|
|
227
|
+
continue
|
|
228
|
+
if box.group("mark") != " ":
|
|
229
|
+
tail = line.rsplit(" — ", 1)[-1] if " — " in line else ""
|
|
230
|
+
phase_shas.setdefault(phase or "", []).extend(SHA_TAIL_RE.findall(tail))
|
|
231
|
+
elif box.group("text").strip() in open_items:
|
|
232
|
+
pending.append((number, line, box.group("text").strip(), phase or ""))
|
|
233
|
+
merges = git.merges_for(change_id)
|
|
234
|
+
for number, line, subject, phase in pending:
|
|
235
|
+
evidence = [_evidence("commit", sha, f"cited by a ticked item of phase {phase}")
|
|
236
|
+
for sha in dict.fromkeys(phase_shas.get(phase, []))]
|
|
237
|
+
files = sorted(set(phase_files.get(phase, [])))
|
|
238
|
+
evidence += _commit_evidence(git.touching(files, since), f"touched {', '.join(files)} after {since}")
|
|
239
|
+
evidence += _commit_evidence(merges, "merge of the change")
|
|
240
|
+
entries.append(_entry("archived-change-progress", path, number, line, subject, evidence))
|
|
241
|
+
return entries
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _roadmap_rows_by_id(text: str) -> dict[str, dict]:
|
|
245
|
+
return {row["id"]: row for row in roadmap_rows(text)}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _summary_entries(reader, git: Git, path: str) -> list[dict]:
|
|
249
|
+
import doctor
|
|
250
|
+
|
|
251
|
+
text = reader.read(path) or ""
|
|
252
|
+
rows = _roadmap_rows_by_id(text)
|
|
253
|
+
bad = {entry.split(":", 1)[0] for entry in doctor.summary_placeholders(text)}
|
|
254
|
+
entries = []
|
|
255
|
+
in_summary = False
|
|
256
|
+
header = None
|
|
257
|
+
for number, line in enumerate(_lines(text), start=1):
|
|
258
|
+
if line.startswith("## "):
|
|
259
|
+
in_summary = line[3:].strip() == "Summary"
|
|
260
|
+
header = None
|
|
261
|
+
continue
|
|
262
|
+
if not in_summary or not line.strip().startswith("|"):
|
|
263
|
+
continue
|
|
264
|
+
cells = [cell.strip() for cell in line.strip().strip("|").split("|")]
|
|
265
|
+
if header is None:
|
|
266
|
+
header = [cell.lower() for cell in cells]
|
|
267
|
+
continue
|
|
268
|
+
if cells[0] not in bad:
|
|
269
|
+
continue
|
|
270
|
+
index = header.index("merge") if "merge" in header else len(cells) - 1
|
|
271
|
+
cell = cells[index] if index < len(cells) else ""
|
|
272
|
+
item = cells[0]
|
|
273
|
+
change_id = (rows.get(item) or {}).get("change_id")
|
|
274
|
+
evidence = _commit_evidence(git.merges_for(change_id), "merge of the item's change")
|
|
275
|
+
folder = _archived_change_folder(reader, change_id)
|
|
276
|
+
if folder:
|
|
277
|
+
shas = SHA_TAIL_RE.findall(reader.read(f"{folder}/plan.md") or "")
|
|
278
|
+
if shas:
|
|
279
|
+
evidence.append(_evidence("commit", shas[-1], f"last SHA in {folder}/plan.md (not a merge; prefer the merge)"))
|
|
280
|
+
entries.append(_entry("archived-roadmap-summary", path, number, line, f"{item}: {cell}", evidence,
|
|
281
|
+
cell=cell, item=item, change_id=change_id))
|
|
282
|
+
return entries
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _open_item_entries(reader, git: Git, path: str) -> list[dict]:
|
|
286
|
+
import doctor
|
|
287
|
+
|
|
288
|
+
text = reader.read(path) or ""
|
|
289
|
+
entries = []
|
|
290
|
+
rows = {row["id"]: row for row in roadmap_rows(text) if row["status"] not in doctor.CLOSED_STATUSES}
|
|
291
|
+
for number, line in enumerate(_lines(text), start=1):
|
|
292
|
+
match = re.match(r"^\|\s*\*\*([A-Z]+-\d+)\*\*\s*\|", line)
|
|
293
|
+
if not match or match.group(1) not in rows:
|
|
294
|
+
continue
|
|
295
|
+
row = rows.pop(match.group(1))
|
|
296
|
+
status = [cell.strip() for cell in line.strip().strip("|").split("|")][-1]
|
|
297
|
+
evidence = _item_evidence(reader, git, path, row["id"], row["change_id"])
|
|
298
|
+
entries.append(_entry("archived-roadmap-open-items", path, number, line, f"{row['id']} ({row['status']})",
|
|
299
|
+
evidence, item=row["id"], change_id=row["change_id"], status=status))
|
|
300
|
+
return entries
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _open_check_entries(reader, git: Git, path: str) -> list[dict]:
|
|
304
|
+
text = reader.read(path) or ""
|
|
305
|
+
rows = _roadmap_rows_by_id(text)
|
|
306
|
+
include_release = path != pending_release_roadmap(reader)
|
|
307
|
+
wanted = {OWNER_SECTION} | ({RELEASE_SECTION} if include_release else set())
|
|
308
|
+
closed_on = _date_of(path, frontmatter(text))
|
|
309
|
+
release = git.release_after(closed_on)
|
|
310
|
+
entries = []
|
|
311
|
+
section = None
|
|
312
|
+
for number, line in enumerate(_lines(text), start=1):
|
|
313
|
+
if line.startswith("## "):
|
|
314
|
+
section = line[3:].strip()
|
|
315
|
+
continue
|
|
316
|
+
box = CHECKBOX_RE.match(line)
|
|
317
|
+
if section not in wanted or not box or box.group("mark") != " ":
|
|
318
|
+
continue
|
|
319
|
+
ref = ITEM_REF_RE.search(line)
|
|
320
|
+
item = ref.group("id") if ref else None
|
|
321
|
+
change_id = (rows.get(item) or {}).get("change_id") if item else None
|
|
322
|
+
evidence = _item_evidence(reader, git, path, item, change_id) if item else []
|
|
323
|
+
if release and section == RELEASE_SECTION:
|
|
324
|
+
evidence.append(_evidence("release", release["tag"], f"released {release['date']}, after the close"))
|
|
325
|
+
entries.append(_entry("archived-roadmap-open-checks", path, number, line, box.group("text").strip(),
|
|
326
|
+
evidence, item=item, change_id=change_id, section=section))
|
|
327
|
+
return entries
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _index_entries(reader, root: str | None) -> list[dict]:
|
|
331
|
+
import doctor
|
|
332
|
+
import doctor_fix
|
|
333
|
+
|
|
334
|
+
history = doctor_fix.History(root)
|
|
335
|
+
entries = []
|
|
336
|
+
for missing in doctor.missing_index_targets(reader):
|
|
337
|
+
evidence = []
|
|
338
|
+
for candidate in missing["candidates"]:
|
|
339
|
+
traced = history.trace(candidate)
|
|
340
|
+
if traced and traced[0] == "moved":
|
|
341
|
+
evidence.append(_evidence("file", traced[1], f"`{missing['target']}` moved here (git rename history)"))
|
|
342
|
+
break
|
|
343
|
+
if traced:
|
|
344
|
+
evidence.append(_evidence("commit", traced[1], f"the last commit that had `{candidate}`; "
|
|
345
|
+
"it was deleted, not moved"))
|
|
346
|
+
break
|
|
347
|
+
if not evidence:
|
|
348
|
+
evidence.append(_evidence("file", f"{missing['path']}:{missing['line']}",
|
|
349
|
+
"the target was never in git history: fix the link or drop the row"))
|
|
350
|
+
entries.append(_entry("index-missing-file", missing["path"], missing["line"], missing["text"],
|
|
351
|
+
f"`{missing['target']}`", evidence, target=missing["target"]))
|
|
352
|
+
return entries
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _file_entry(failure, reader) -> dict:
|
|
356
|
+
target = failure.path.rstrip("/")
|
|
357
|
+
evidence = [_evidence("file", failure.path, failure.message)] if reader.exists(target) or failure.code in (
|
|
358
|
+
"state-missing",) else []
|
|
359
|
+
return _entry(failure.code, failure.path, None, "", failure.message, evidence)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def sweep(reader, root: str | None) -> list[dict]:
|
|
363
|
+
"""Every failure the doctor reports on `reader`, as worklist entries with evidence."""
|
|
364
|
+
import doctor
|
|
365
|
+
|
|
366
|
+
git = Git(root)
|
|
367
|
+
entries: list[dict] = []
|
|
368
|
+
indexes_done = False
|
|
369
|
+
for failure in doctor.run_checks(reader, root, baseline=False):
|
|
370
|
+
if failure.severity != "fail":
|
|
371
|
+
continue
|
|
372
|
+
if failure.code == "index-missing-file":
|
|
373
|
+
if not indexes_done:
|
|
374
|
+
entries += _index_entries(reader, root)
|
|
375
|
+
indexes_done = True
|
|
376
|
+
elif failure.code == "archived-change-progress":
|
|
377
|
+
entries += _progress_entries(reader, git, failure.path)
|
|
378
|
+
elif failure.code == "archived-roadmap-summary":
|
|
379
|
+
entries += _summary_entries(reader, git, failure.path)
|
|
380
|
+
elif failure.code == "archived-roadmap-open-items":
|
|
381
|
+
entries += _open_item_entries(reader, git, failure.path)
|
|
382
|
+
elif failure.code == "archived-roadmap-open-checks":
|
|
383
|
+
entries += _open_check_entries(reader, git, failure.path)
|
|
384
|
+
else:
|
|
385
|
+
entries.append(_file_entry(failure, reader))
|
|
386
|
+
return entries
|
|
@@ -71,10 +71,17 @@ Read the PRD in full, not in excerpts.
|
|
|
71
71
|
roadmap, `git mv` the queued file to `roadmap.md`, set `status: ready`, and take its ready entries
|
|
72
72
|
(`git mv …/change.md context/changes/<id>/backlog-input.md`, then the `softure-new` format).
|
|
73
73
|
Never promote on your own initiative, not even in `--auto`.
|
|
74
|
-
- **`--close`**: the main roadmap is realised; archive it per WORKFLOW §5.2. Check the
|
|
74
|
+
- **`--close`**: the main roadmap is realised; archive it per WORKFLOW §5.2. Check the four gates
|
|
75
75
|
first and report every failing one at once: rows not `done` / `done_code` and not carried over,
|
|
76
76
|
leftover folders in `context/changes/` (archive each through `softure-archive`, a change without a
|
|
77
|
-
plan included, before continuing),
|
|
77
|
+
plan included, before continuing), the full integration result on `<main>` when configured, and
|
|
78
|
+
open checks: the close **refuses** to archive while a `- [ ]` is left under `## Owner decisions and
|
|
79
|
+
checks`. Settle each one first: tick it with its evidence (`— done: <sha | release | path>`), tick it
|
|
80
|
+
as obsolete with the reason (`— obsolete: <reason>`), or carry it to the next or a queued roadmap's
|
|
81
|
+
owner section (or an `owner-word` issue) and tick it with where it went (`— carried to <path | #N>`).
|
|
82
|
+
An archived roadmap with an open check is the doctor's `archived-roadmap-open-checks` and never an
|
|
83
|
+
owner-queue entry, so nothing that waits for the owner may stay behind in it. Open
|
|
84
|
+
`## Before the next release` steps stay: they wait for the release the close comes before.
|
|
78
85
|
Then write `## Summary` (`| ID | Item | What changed | Merge |`, the merge SHA from
|
|
79
86
|
`git log --merges --grep "<change-id>"` on `<main>`, plus the integration line), move the file to
|
|
80
87
|
`foundation/archive/<YYYY-MM-DD>-roadmap.md`, clean up the promoted roadmap's backlog folder and
|