@softure-ai/skills 0.21.0 → 0.23.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 +19 -10
- package/WORKFLOW.md +45 -23
- package/package.json +1 -1
- package/rules/AGENTS.md +1 -1
- package/scripts/install.mjs +37 -8
- package/scripts/portfolio.py +61 -8
- package/skills/softure-doctor/SKILL.md +35 -17
- package/skills/softure-doctor/references/state.schema.json +2 -1
- package/skills/softure-doctor/scripts/context_state.py +39 -3
- package/skills/softure-doctor/scripts/doctor.py +140 -35
- package/skills/softure-doctor/scripts/doctor_fix.py +64 -20
- package/skills/softure-doctor/scripts/doctor_sweep.py +180 -36
- package/skills/softure-init/SKILL.md +5 -0
- package/skills/softure-init/references/example.md +3 -1
|
@@ -7,29 +7,34 @@
|
|
|
7
7
|
doctor.py --baseline last resort: accept today's failures in context/doctor-baseline.json
|
|
8
8
|
npx softure-skills doctor [...] (the same, from the installed package)
|
|
9
9
|
|
|
10
|
-
Adopting projects run it in
|
|
10
|
+
Adopting projects run it in a CI job named `context-doctor`, documentation-only changes included (that is where the
|
|
11
11
|
drift happens). `softure-archive` and `softure-roadmap --close` run it before their commit and fix
|
|
12
12
|
what they own. Each problem is one line `FAIL <code> <path>: <what>`; the codes:
|
|
13
13
|
|
|
14
14
|
roadmap-archived-not-removed roadmap.md is still there although the same roadmap is in foundation/archive/
|
|
15
15
|
roadmap-status-mismatch roadmap.md `status` contradicts its rows (done with open rows; waiting)
|
|
16
16
|
archived-change-status an archived change.md whose status is not `archived`
|
|
17
|
-
archived-change-progress an archived plan.md with unticked Automated items in `## Progress`
|
|
17
|
+
archived-change-progress an archived plan.md with unticked Automated items in `## Progress` (an item
|
|
18
|
+
struck through or noted dropped/cancelled/not applicable is dropped, not open)
|
|
18
19
|
archived-roadmap-open-items an archived roadmap with rows that are not done, done_code, dropped or carried
|
|
19
|
-
archived-roadmap-summary an archived roadmap whose `## Summary`
|
|
20
|
+
archived-roadmap-summary an archived roadmap whose `## Summary` item table holds a placeholder in its merge
|
|
21
|
+
column (a SHA, a release tag, carried, dropped or a dash with a reason pass)
|
|
20
22
|
archived-roadmap-open-checks an archived roadmap with unticked owner decisions or checks (or pre-release
|
|
21
23
|
steps, once its release is recorded or a later roadmap was closed)
|
|
22
24
|
queued-roadmap-done a queued roadmap in foundation/roadmaps/ whose rows are all done
|
|
23
25
|
backlog-without-roadmap a backlog/roadmap-<slug>/ folder without its queued (or promoted) roadmap
|
|
24
26
|
index-missing-file an index row (README.md / INDEX.md table under context/) links a missing file
|
|
27
|
+
(a markdown link, or a cell that is only a path in a file column; a mention
|
|
28
|
+
in a description cell is not a link)
|
|
25
29
|
state-missing context/state.json is missing although the project has written it before
|
|
26
30
|
state-stale context/state.json does not match the markdown
|
|
27
31
|
baseline-stale context/doctor-baseline.json lists a failure that is fixed (remove it), or is unreadable
|
|
28
32
|
|
|
29
33
|
`--fix` repairs what is mechanical (an archived change's status; an archived index row whose target
|
|
30
|
-
moved, found through git history) and prints every edit; see doctor_fix.py. It is a dry run unless
|
|
34
|
+
moved or was deleted on purpose, found through git history; a dropped Progress item, normalised) and prints every edit; see doctor_fix.py. It is a dry run unless
|
|
31
35
|
`--write` is given, and it writes only under `context/`. `--sweep` lists every remaining failure with
|
|
32
|
-
the evidence an agent needs to settle it from the repository alone
|
|
36
|
+
the evidence an agent needs to settle it from the repository alone, classed `evidence`, `superseded` (later
|
|
37
|
+
work made it obsolete; the agent closes it) or `owner`; see doctor_sweep.py.
|
|
33
38
|
|
|
34
39
|
`--baseline` is a last resort for a project that cannot finish the sweep at once: it writes the failures
|
|
35
40
|
that remain to `context/doctor-baseline.json`, and the check then fails only on new failures and on
|
|
@@ -41,6 +46,8 @@ gets a note, not a failure: the first run of `wt-roadmap.py`, `softure-archive`
|
|
|
41
46
|
creates it. Fix a stale or missing file with `npx softure-skills state` (or
|
|
42
47
|
`python3 .claude/skills/softure-doctor/scripts/context_state.py write`) and commit it.
|
|
43
48
|
|
|
49
|
+
Piped into a reader that stops early (`doctor --sweep | head`), it ends quietly with exit 141, no traceback.
|
|
50
|
+
|
|
44
51
|
Importable: `from doctor import run_checks` (takes any reader of context_state).
|
|
45
52
|
"""
|
|
46
53
|
from __future__ import annotations
|
|
@@ -55,7 +62,8 @@ sys.dont_write_bytecode = True # no __pycache__ inside the consumer's .claude/s
|
|
|
55
62
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
56
63
|
from context_state import ( # noqa: E402
|
|
57
64
|
ARCHIVE_ROADMAPS_DIR, CHANGES_DIR, OWNER_SECTION, QUEUED_DIR, RELEASE_SECTION, ROADMAP_PATH, STATE_PATH,
|
|
58
|
-
FsReader, frontmatter, open_checkboxes, pending_release_roadmap, roadmap_rows, sections,
|
|
65
|
+
FsReader, frontmatter, open_checkboxes, pending_release_roadmap, quiet_broken_pipe, roadmap_rows, sections,
|
|
66
|
+
staleness,
|
|
59
67
|
)
|
|
60
68
|
|
|
61
69
|
ARCHIVE_DIR = "context/archive"
|
|
@@ -65,9 +73,13 @@ BACKLOG_DIR = "context/backlog"
|
|
|
65
73
|
CLOSED_STATUSES = ("done", "done_code", "dropped", "carried")
|
|
66
74
|
SHA_RE = re.compile(r"\b[0-9a-f]{7,40}\b")
|
|
67
75
|
EMPTY_MERGE = {"—", "-", "–", "n/a", "none", "no merge", "not merged"}
|
|
76
|
+
RELEASE_TAG_RE = re.compile(r"(?<![\w.])v?\d+\.\d+\.\d+(?:-[\w.]+)?(?![\w.])")
|
|
77
|
+
MERGE_COLUMN_RE = re.compile(r"\bmerge")
|
|
68
78
|
LINK_RE = re.compile(r"\[[^\]]*\]\(([^)\s]+)(?:\s+\"[^\"]*\")?\)")
|
|
69
79
|
INDEX_NAMES = ("README.md", "INDEX.md")
|
|
70
|
-
|
|
80
|
+
_PATH = r"(?:\.{1,2}/)?(?:[\w.-]+/)*[\w.-]+\.md|(?:\.{1,2}/)?(?:[\w.-]+/)+"
|
|
81
|
+
WHOLE_PATH_RE = re.compile(r"(?P<tick>`?)(?P<path>" + _PATH + r")(?P=tick)") # a cell that is only a path
|
|
82
|
+
FILE_COLUMN_RE = re.compile(r"\b(?:files?|paths?|documents?|docs?|links?|artifacts?)\b")
|
|
71
83
|
|
|
72
84
|
|
|
73
85
|
class Finding:
|
|
@@ -144,10 +156,45 @@ def check_archived_changes(reader) -> list[Finding]:
|
|
|
144
156
|
return findings
|
|
145
157
|
|
|
146
158
|
|
|
159
|
+
DROP_WORDS = r"(?:dropped|cancell?ed|not applicable|n/a|obsolete|won't do|wontfix|skipped|replaced by)"
|
|
160
|
+
DROP_NOTE_RE = re.compile(r"\s+(?:—|–|--?)\s+(?P<note>" + DROP_WORDS + r"\b.*)$", re.IGNORECASE)
|
|
161
|
+
DROP_PAREN_RE = re.compile(r"\s*\((?P<note>" + DROP_WORDS + r"\b[^)]*)\)\s*$", re.IGNORECASE)
|
|
162
|
+
STRUCK_RE = re.compile(r"^~~(?P<body>.+?)~~(?P<rest>.*)$")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def dropped_item(text: str) -> tuple[str, str] | None:
|
|
166
|
+
"""(item, note) when a checkbox text says the item was dropped; None otherwise.
|
|
167
|
+
|
|
168
|
+
Dropped by its own text: struck through (`~~1.1 ...~~`, with or without a note after it), or carrying an
|
|
169
|
+
explicit note after a dash or in parentheses (`— cancelled, replaced by 1.12`, `(not applicable)`).
|
|
170
|
+
"""
|
|
171
|
+
text = text.strip()
|
|
172
|
+
struck = STRUCK_RE.match(text)
|
|
173
|
+
if struck:
|
|
174
|
+
rest = re.sub(r"^\s*(?:—|–|--?|:)?\s*", "", struck.group("rest")).strip()
|
|
175
|
+
return struck.group("body").strip(), rest or "struck through, no reason recorded"
|
|
176
|
+
for pattern in (DROP_NOTE_RE, DROP_PAREN_RE):
|
|
177
|
+
found = pattern.search(text)
|
|
178
|
+
if found and found.start() > 0:
|
|
179
|
+
return text[:found.start()].strip(), found.group("note").strip()
|
|
180
|
+
return None
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def dropped_line(text: str) -> str | None:
|
|
184
|
+
"""The normalised `~~<item>~~ — dropped: <note>` for a dropped checkbox text; None when it is not dropped."""
|
|
185
|
+
found = dropped_item(text)
|
|
186
|
+
if not found:
|
|
187
|
+
return None
|
|
188
|
+
item, note = found
|
|
189
|
+
note = re.sub(r"^dropped\s*:?\s*", "", note, flags=re.IGNORECASE) or "no reason recorded"
|
|
190
|
+
return f"~~{item}~~ — dropped: {note}"
|
|
191
|
+
|
|
192
|
+
|
|
147
193
|
def unticked_automated(plan: str) -> list[str]:
|
|
148
|
-
"""Open `- [ ]` items of `## Progress` that are not under a `#### Manual` heading.
|
|
194
|
+
"""Open `- [ ]` items of `## Progress` that are not under a `#### Manual` heading and not dropped.
|
|
149
195
|
|
|
150
|
-
Open Manual items are legitimate in an archived plan (manual mode carries them to the owner).
|
|
196
|
+
Open Manual items are legitimate in an archived plan (manual mode carries them to the owner). An item
|
|
197
|
+
struck through or carrying a dropped/cancelled/not-applicable note is dropped by its own text.
|
|
151
198
|
"""
|
|
152
199
|
progress = sections(plan).get("Progress", [])
|
|
153
200
|
open_items = []
|
|
@@ -160,7 +207,7 @@ def unticked_automated(plan: str) -> list[str]:
|
|
|
160
207
|
manual = False
|
|
161
208
|
continue
|
|
162
209
|
match = re.match(r"^\s*- \[ \] (.+)$", line)
|
|
163
|
-
if match and not manual:
|
|
210
|
+
if match and not manual and not dropped_item(match.group(1)):
|
|
164
211
|
open_items.append(match.group(1).strip())
|
|
165
212
|
return open_items
|
|
166
213
|
|
|
@@ -193,31 +240,56 @@ def check_archived_roadmaps(reader) -> list[Finding]:
|
|
|
193
240
|
bad = summary_placeholders(text)
|
|
194
241
|
if bad:
|
|
195
242
|
findings.append(Finding("archived-roadmap-summary", path,
|
|
196
|
-
"## Summary merge column holds placeholders instead of merge SHAs: "
|
|
243
|
+
"## Summary merge column holds placeholders instead of merge SHAs or outcomes: "
|
|
197
244
|
+ "; ".join(bad[:4])))
|
|
198
245
|
return findings
|
|
199
246
|
|
|
200
247
|
|
|
201
|
-
def
|
|
202
|
-
"""Rows of the
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
248
|
+
def summary_rows(text: str) -> list[dict]:
|
|
249
|
+
"""Rows of the item table under `## Summary`: the table whose header has a merge column.
|
|
250
|
+
|
|
251
|
+
Other tables under `## Summary` (finding numbers, test counts) are not the item table and are skipped.
|
|
252
|
+
Each row: `line` (1-based in `text`), `text`, `item` (first cell), `cell` (the merge cell) and `ok`.
|
|
253
|
+
"""
|
|
254
|
+
rows: list[dict] = []
|
|
255
|
+
in_summary = False
|
|
256
|
+
header: list[str] | None = None
|
|
257
|
+
merge = None
|
|
258
|
+
for number, line in enumerate((text or "").split("\n"), start=1):
|
|
259
|
+
if line.startswith("## "):
|
|
260
|
+
in_summary = line[3:].strip() == "Summary"
|
|
261
|
+
header = None
|
|
262
|
+
continue
|
|
263
|
+
if not in_summary:
|
|
264
|
+
continue
|
|
207
265
|
if not line.strip().startswith("|"):
|
|
266
|
+
header = None
|
|
208
267
|
continue
|
|
209
|
-
|
|
268
|
+
cells = _table_cells(line)
|
|
210
269
|
if header is None:
|
|
211
|
-
header = [cell.lower() for cell in
|
|
212
|
-
|
|
213
|
-
if all(re.fullmatch(r":?-{3,}:?", cell) for cell in parts if cell):
|
|
270
|
+
header = [cell.strip("*` ").lower() for cell in cells]
|
|
271
|
+
merge = next((index for index, name in enumerate(header) if MERGE_COLUMN_RE.search(name)), None)
|
|
214
272
|
continue
|
|
215
|
-
|
|
216
|
-
cell = parts[index] if index < len(parts) else ""
|
|
217
|
-
if SHA_RE.search(cell) or cell.strip("`* ").lower() in EMPTY_MERGE:
|
|
273
|
+
if merge is None or _is_separator(cells):
|
|
218
274
|
continue
|
|
219
|
-
|
|
220
|
-
|
|
275
|
+
cell = cells[merge] if merge < len(cells) else ""
|
|
276
|
+
rows.append({"line": number, "text": line, "item": cells[0], "cell": cell, "ok": merge_cell_ok(cell)})
|
|
277
|
+
return rows
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def merge_cell_ok(cell: str) -> bool:
|
|
281
|
+
"""A merge cell records an outcome: a SHA, a release tag, carried/dropped, or a dash (with or without a reason)."""
|
|
282
|
+
value = cell.strip("`* ").lower()
|
|
283
|
+
if SHA_RE.search(cell) or RELEASE_TAG_RE.search(cell):
|
|
284
|
+
return True
|
|
285
|
+
if value in EMPTY_MERGE or value[:1] in ("—", "–", "-"):
|
|
286
|
+
return True
|
|
287
|
+
return bool(re.match(r"(?:carried|dropped|obsolete|superseded|cancell?ed|not merged|no merge)\b", value))
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def summary_placeholders(text: str) -> list[str]:
|
|
291
|
+
"""Item-table rows of `## Summary` whose merge cell is a placeholder, not an outcome."""
|
|
292
|
+
return [f"{row['item']}: \"{row['cell']}\"" for row in summary_rows(text) if not row["ok"]]
|
|
221
293
|
|
|
222
294
|
|
|
223
295
|
def check_queued_and_backlog(reader) -> list[Finding]:
|
|
@@ -245,8 +317,20 @@ def check_queued_and_backlog(reader) -> list[Finding]:
|
|
|
245
317
|
return findings
|
|
246
318
|
|
|
247
319
|
|
|
320
|
+
def _table_cells(line: str) -> list[str]:
|
|
321
|
+
return [cell.strip() for cell in line.strip().strip("|").split("|")]
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _is_separator(cells: list[str]) -> bool:
|
|
325
|
+
return all(re.fullmatch(r":?-{3,}:?", cell) for cell in cells if cell) and any(cells)
|
|
326
|
+
|
|
327
|
+
|
|
248
328
|
def missing_index_targets(reader) -> list[dict]:
|
|
249
|
-
"""Every link
|
|
329
|
+
"""Every real link in an index row (README.md / INDEX.md table under context/) whose target does not exist.
|
|
330
|
+
|
|
331
|
+
A real link is a markdown link anywhere in the row, or a cell whose whole content is a path (in backticks
|
|
332
|
+
or bare) in a column that indexes files (`File`, `Path`, `Document`, `Link`, ...). A path merely mentioned
|
|
333
|
+
in a description cell (see `change.md`) is not a link and never fails.
|
|
250
334
|
|
|
251
335
|
Each entry: `path` (the index), `line` (1-based), `text` (the line), `kind` (`link` or `code`), `target`
|
|
252
336
|
(as written), `base` (the index folder) and `candidates` (the repository paths the target may mean).
|
|
@@ -256,8 +340,16 @@ def missing_index_targets(reader) -> list[dict]:
|
|
|
256
340
|
if os.path.basename(path) not in INDEX_NAMES:
|
|
257
341
|
continue
|
|
258
342
|
base = os.path.dirname(path)
|
|
343
|
+
header: list[str] | None = None
|
|
259
344
|
for number, line in enumerate((reader.read(path) or "").splitlines(), start=1):
|
|
260
345
|
if not line.strip().startswith("|"):
|
|
346
|
+
header = None
|
|
347
|
+
continue
|
|
348
|
+
cells = _table_cells(line)
|
|
349
|
+
if header is None:
|
|
350
|
+
header = [cell.strip("*` ").lower() for cell in cells]
|
|
351
|
+
continue
|
|
352
|
+
if _is_separator(cells):
|
|
261
353
|
continue
|
|
262
354
|
for target in LINK_RE.findall(line):
|
|
263
355
|
if re.match(r"^[a-z][a-z0-9+.-]*:", target, re.IGNORECASE) or target.startswith("#"):
|
|
@@ -271,8 +363,14 @@ def missing_index_targets(reader) -> list[dict]:
|
|
|
271
363
|
if not reader.exists(resolved.rstrip("/")):
|
|
272
364
|
out.append({"path": path, "line": number, "text": line, "kind": "link", "target": target,
|
|
273
365
|
"base": base, "candidates": [resolved.rstrip("/")]})
|
|
274
|
-
for
|
|
275
|
-
|
|
366
|
+
for column, cell in enumerate(cells):
|
|
367
|
+
if column >= len(header) or not FILE_COLUMN_RE.search(header[column]):
|
|
368
|
+
continue
|
|
369
|
+
whole = WHOLE_PATH_RE.fullmatch(cell)
|
|
370
|
+
if not whole:
|
|
371
|
+
continue
|
|
372
|
+
target = whole.group("path")
|
|
373
|
+
# A path cell: relative to the index, to context/ or to the repository root.
|
|
276
374
|
candidates = [os.path.normpath(os.path.join(prefix, target)).replace(os.sep, "/").rstrip("/")
|
|
277
375
|
for prefix in (base, "context", ".")]
|
|
278
376
|
inside = [c for c in candidates if c.startswith("context/")]
|
|
@@ -490,11 +588,14 @@ def run_sweep(reader, root: str, git_root: str | None, as_json: bool) -> int:
|
|
|
490
588
|
import doctor_sweep
|
|
491
589
|
|
|
492
590
|
entries = doctor_sweep.sweep(reader, git_root)
|
|
493
|
-
owner = [entry for entry in entries if entry["owner"]
|
|
591
|
+
owner = [entry for entry in entries if entry["class"] == "owner"]
|
|
592
|
+
superseded = [entry for entry in entries if entry["class"] == "superseded"]
|
|
593
|
+
with_evidence = len(entries) - len(owner) - len(superseded)
|
|
494
594
|
if as_json:
|
|
495
595
|
print(json.dumps({"root": root, "entries": entries,
|
|
496
|
-
"summary": {"total": len(entries), "with_evidence":
|
|
497
|
-
"owner": len(owner)}},
|
|
596
|
+
"summary": {"total": len(entries), "with_evidence": with_evidence,
|
|
597
|
+
"superseded": len(superseded), "owner": len(owner)}},
|
|
598
|
+
indent=2, ensure_ascii=False))
|
|
498
599
|
return 1 if entries else 0
|
|
499
600
|
if not entries:
|
|
500
601
|
print("softure-doctor --sweep: nothing to settle, the context/ contract is OK")
|
|
@@ -504,11 +605,15 @@ def run_sweep(reader, root: str, git_root: str | None, as_json: bool) -> int:
|
|
|
504
605
|
print(f"{entry['code']} {where}: {entry['subject']}")
|
|
505
606
|
for evidence in entry["evidence"]:
|
|
506
607
|
print(f" evidence {evidence['kind']} {evidence['ref']}: {evidence['note']}")
|
|
608
|
+
if entry["class"] == "superseded":
|
|
609
|
+
print(" superseded: later work made it obsolete; close it yourself, never forward it")
|
|
507
610
|
if entry["owner"]:
|
|
508
|
-
print(" owner:
|
|
611
|
+
print(f" owner ({entry['owner_reason']}): only the owner can settle it")
|
|
612
|
+
for tried in entry["tried"]:
|
|
613
|
+
print(f" tried: {tried}")
|
|
509
614
|
print(f" settle: {entry['settle']}")
|
|
510
615
|
print(f"softure-doctor --sweep: {len(entries)} entr{'y' if len(entries) == 1 else 'ies'} to settle, "
|
|
511
|
-
f"{
|
|
616
|
+
f"{with_evidence} with evidence, {len(superseded)} superseded, {len(owner)} for the owner")
|
|
512
617
|
return 1
|
|
513
618
|
|
|
514
619
|
|
|
@@ -570,4 +675,4 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
570
675
|
|
|
571
676
|
|
|
572
677
|
if __name__ == "__main__":
|
|
573
|
-
sys.exit(main
|
|
678
|
+
sys.exit(quiet_broken_pipe(main))
|
|
@@ -4,18 +4,23 @@
|
|
|
4
4
|
doctor.py --fix [--write] [--json] [--root <dir>]
|
|
5
5
|
npx softure-skills doctor --fix [--write]
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Three shapes are mechanical, and only files under `context/` are edited:
|
|
8
8
|
|
|
9
9
|
archived-change-status an archived change.md gets `status: archived`; the old value is kept as
|
|
10
10
|
`legacy_status` in its front matter (a missing status gets none)
|
|
11
11
|
index-missing-file a row of an index inside an archive folder (`context/archive/`,
|
|
12
12
|
`context/foundation/archive/`) that links a missing file is rewritten to the
|
|
13
13
|
file's current path when git history shows where it moved (rename detection,
|
|
14
|
-
followed across several moves); a file that was deleted
|
|
15
|
-
|
|
14
|
+
followed across several moves); a file that was deleted on purpose (git shows
|
|
15
|
+
the deletion, no rename) is marked `(removed in <sha>)` with the deleting commit
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
dropped Progress item an unticked item of an archived plan's `## Progress` that is struck through or
|
|
18
|
+
carries a dropped/cancelled/not-applicable note is normalised to
|
|
19
|
+
`- [x] ~~<item>~~ — dropped: <note>` (the doctor already reads it as dropped)
|
|
20
|
+
|
|
21
|
+
Everything else (an index row whose target is not in the history this checkout holds, a live index)
|
|
22
|
+
is a judgement case: `doctor.py --sweep` lists it with evidence. A shallow clone works: what it cannot
|
|
23
|
+
see is skipped and named, never guessed.
|
|
19
24
|
Every edit is printed; a second run after `--write` changes nothing.
|
|
20
25
|
|
|
21
26
|
Importable: `from doctor_fix import plan_fixes, apply_fixes`.
|
|
@@ -32,7 +37,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
32
37
|
from context_state import frontmatter # noqa: E402
|
|
33
38
|
|
|
34
39
|
ARCHIVE_PREFIXES = ("context/archive/", "context/foundation/archive/")
|
|
35
|
-
|
|
40
|
+
REMOVED_MARK = "removed in"
|
|
36
41
|
MAX_HOPS = 10
|
|
37
42
|
|
|
38
43
|
|
|
@@ -40,14 +45,17 @@ MAX_HOPS = 10
|
|
|
40
45
|
|
|
41
46
|
|
|
42
47
|
class History:
|
|
43
|
-
"""Where files under a git checkout went. `usable` is False without git
|
|
48
|
+
"""Where files under a git checkout went. `usable` is False without git; `shallow` marks a shallow
|
|
49
|
+
clone, whose answers cover only the commits it holds."""
|
|
44
50
|
|
|
45
51
|
def __init__(self, root: str | None) -> None:
|
|
46
52
|
self.root = root
|
|
47
53
|
self.usable = False
|
|
54
|
+
self.shallow = False
|
|
48
55
|
if root:
|
|
49
56
|
probe = self._git("rev-parse", "--is-shallow-repository")
|
|
50
|
-
self.usable = probe.returncode == 0
|
|
57
|
+
self.usable = probe.returncode == 0
|
|
58
|
+
self.shallow = probe.stdout.strip() == "true"
|
|
51
59
|
|
|
52
60
|
def _git(self, *args: str) -> subprocess.CompletedProcess:
|
|
53
61
|
return subprocess.run(["git", "-C", self.root or ".", *args], capture_output=True, text=True)
|
|
@@ -60,12 +68,12 @@ class History:
|
|
|
60
68
|
return os.path.exists(os.path.join(self.root or ".", rel))
|
|
61
69
|
|
|
62
70
|
def trace(self, rel: str) -> tuple[str, str] | None:
|
|
63
|
-
"""("moved", <current path>) or ("
|
|
64
|
-
the
|
|
71
|
+
"""("moved", <current path>) or ("removed", <short sha of the commit that deleted it>); None when
|
|
72
|
+
the history this checkout holds shows neither (never there, or past a shallow clone's edge)."""
|
|
65
73
|
if not self.usable:
|
|
66
74
|
return None
|
|
67
75
|
current = rel.rstrip("/")
|
|
68
|
-
|
|
76
|
+
last = None
|
|
69
77
|
for _ in range(MAX_HOPS):
|
|
70
78
|
if current != rel.rstrip("/") and self.exists_now(current):
|
|
71
79
|
return "moved", current
|
|
@@ -73,17 +81,27 @@ class History:
|
|
|
73
81
|
sha = log.stdout.strip()
|
|
74
82
|
if log.returncode != 0 or not sha:
|
|
75
83
|
break
|
|
76
|
-
|
|
77
|
-
last_having = parent.stdout.strip() if parent.returncode == 0 else sha
|
|
84
|
+
last = (sha, current)
|
|
78
85
|
moved_to = self._renamed_in(sha, current)
|
|
79
86
|
if not moved_to or moved_to == current:
|
|
80
87
|
break
|
|
81
88
|
current = moved_to
|
|
82
|
-
if
|
|
89
|
+
if last is None:
|
|
83
90
|
return None
|
|
84
91
|
if current != rel.rstrip("/") and self.exists_now(current):
|
|
85
92
|
return "moved", current
|
|
86
|
-
|
|
93
|
+
sha, path = last
|
|
94
|
+
if self.exists_now(path) or not self._deleted_in(sha, path):
|
|
95
|
+
return None
|
|
96
|
+
return "removed", self.short(sha)
|
|
97
|
+
|
|
98
|
+
def _deleted_in(self, sha: str, path: str) -> bool:
|
|
99
|
+
"""Whether commit `sha` deletes `path` (a file, or every file under a folder)."""
|
|
100
|
+
shown = self._git("show", "-M", "--name-status", "--format=", sha)
|
|
101
|
+
statuses = [line.split("\t") for line in shown.stdout.splitlines()]
|
|
102
|
+
hits = [parts[0] for parts in statuses if len(parts) >= 2
|
|
103
|
+
and (parts[1] == path or parts[1].startswith(path + "/"))]
|
|
104
|
+
return bool(hits) and all(status == "D" for status in hits)
|
|
87
105
|
|
|
88
106
|
def _renamed_in(self, sha: str, path: str) -> str | None:
|
|
89
107
|
shown = self._git("show", "-M", "--name-status", "--format=", sha)
|
|
@@ -155,9 +173,10 @@ def _replace_target(line: str, missing: dict, replacement: str | None, gone_note
|
|
|
155
173
|
if replacement is not None:
|
|
156
174
|
return pattern.sub(lambda m: f"[{m.group(1)}]({replacement}{m.group(2)})", line, count=1)
|
|
157
175
|
return pattern.sub(lambda m: f"{m.group(1)} ({gone_note}: {target})", line, count=1)
|
|
176
|
+
cell = re.compile(r"(\|\s*)`?" + re.escape(target) + r"`?(\s*\|)")
|
|
158
177
|
if replacement is not None:
|
|
159
|
-
return
|
|
160
|
-
return
|
|
178
|
+
return cell.sub(lambda m: f"{m.group(1)}`{replacement}`{m.group(2)}", line, count=1)
|
|
179
|
+
return cell.sub(lambda m: f"{m.group(1)}{target} ({gone_note}){m.group(2)}", line, count=1)
|
|
161
180
|
|
|
162
181
|
|
|
163
182
|
def plan_fixes(reader, root: str | None) -> dict:
|
|
@@ -180,6 +199,28 @@ def plan_fixes(reader, root: str | None) -> dict:
|
|
|
180
199
|
files[rel] = fixed[0]
|
|
181
200
|
edits.append({"code": "archived-change-status", "path": rel, "what": fixed[1]})
|
|
182
201
|
|
|
202
|
+
for name, is_dir in reader.listdir(doctor.ARCHIVE_DIR):
|
|
203
|
+
if not is_dir:
|
|
204
|
+
continue
|
|
205
|
+
rel = f"{doctor.ARCHIVE_DIR}/{name}/plan.md"
|
|
206
|
+
text = reader.read(rel)
|
|
207
|
+
if text is None:
|
|
208
|
+
continue
|
|
209
|
+
lines = text.split("\n")
|
|
210
|
+
in_progress = False
|
|
211
|
+
for index, line in enumerate(lines):
|
|
212
|
+
if line.startswith("## "):
|
|
213
|
+
in_progress = line[3:].strip() == "Progress"
|
|
214
|
+
continue
|
|
215
|
+
box = re.match(r"^(\s*)- \[ \] (.+)$", line) if in_progress else None
|
|
216
|
+
normalised = doctor.dropped_line(box.group(2)) if box else None
|
|
217
|
+
if normalised:
|
|
218
|
+
lines[index] = f"{box.group(1)}- [x] {normalised}"
|
|
219
|
+
edits.append({"code": "archived-change-progress", "path": rel, "line": index + 1,
|
|
220
|
+
"what": f"dropped item normalised: {normalised}"})
|
|
221
|
+
if lines != text.split("\n"):
|
|
222
|
+
files[rel] = "\n".join(lines)
|
|
223
|
+
|
|
183
224
|
history = History(root)
|
|
184
225
|
for missing in doctor.missing_index_targets(reader):
|
|
185
226
|
if not missing["path"].startswith(ARCHIVE_PREFIXES):
|
|
@@ -188,7 +229,7 @@ def plan_fixes(reader, root: str | None) -> dict:
|
|
|
188
229
|
continue
|
|
189
230
|
if not history.usable:
|
|
190
231
|
skipped.append({"code": "index-missing-file", "path": missing["path"], "target": missing["target"],
|
|
191
|
-
"why": "
|
|
232
|
+
"why": "not a git checkout"})
|
|
192
233
|
continue
|
|
193
234
|
found = None
|
|
194
235
|
for candidate in missing["candidates"]:
|
|
@@ -197,8 +238,11 @@ def plan_fixes(reader, root: str | None) -> dict:
|
|
|
197
238
|
found = (candidate, traced)
|
|
198
239
|
break
|
|
199
240
|
if not found:
|
|
241
|
+
why = ("not moved or deleted in the history this shallow clone holds (fetch more with "
|
|
242
|
+
"`git fetch --deepen`), or never in git: fix or drop the row (--sweep)" if history.shallow
|
|
243
|
+
else "git shows no move or deletion (never in git?): fix or drop the row (--sweep)")
|
|
200
244
|
skipped.append({"code": "index-missing-file", "path": missing["path"], "target": missing["target"],
|
|
201
|
-
"why":
|
|
245
|
+
"why": why})
|
|
202
246
|
continue
|
|
203
247
|
candidate, (kind, value) = found
|
|
204
248
|
text = files.get(missing["path"], reader.read(missing["path"]) or "")
|
|
@@ -211,7 +255,7 @@ def plan_fixes(reader, root: str | None) -> dict:
|
|
|
211
255
|
lines[index] = _replace_target(lines[index], missing, new_target, None)
|
|
212
256
|
what = f"`{missing['target']}` -> `{new_target}` (moved to {value})"
|
|
213
257
|
else:
|
|
214
|
-
note = f"{
|
|
258
|
+
note = f"{REMOVED_MARK} {value}"
|
|
215
259
|
lines[index] = _replace_target(lines[index], missing, None, note)
|
|
216
260
|
what = f"`{missing['target']}` marked ({note})"
|
|
217
261
|
files[missing["path"]] = "\n".join(lines)
|