@event4u/agent-config 2.20.0 → 2.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.
@@ -0,0 +1,327 @@
1
+ #!/usr/bin/env python3
2
+ """verify_roadmap_closure — scan archived roadmaps for phantom-shipping.
3
+
4
+ For each `agents/roadmaps/archive/*.md` file:
5
+
6
+ 1. Locate the closure-decision block (heuristic: `## Closure decision`,
7
+ `## Sunset`, `maintainer override`).
8
+ 2. Extract file-path-shaped tokens from the block (backtick paths +
9
+ markdown link targets). Sibling-roadmap references are filtered out.
10
+ 3. Verify each token: exists on disk? If not, was it ever in git history?
11
+ 4. Classify the roadmap (verified / partial / phantom / no-claims /
12
+ not-closure-marked) and emit a per-roadmap + aggregate report.
13
+
14
+ Run: `python3 scripts/verify_roadmap_closure.py [--json out.json]`
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import argparse
20
+ import json
21
+ import re
22
+ import subprocess
23
+ import sys
24
+ from dataclasses import dataclass, field
25
+ from pathlib import Path
26
+ from typing import Iterable
27
+
28
+ REPO = Path(__file__).resolve().parent.parent
29
+ ARCHIVE = REPO / "agents" / "roadmaps" / "archive"
30
+
31
+ CLOSURE_HEADERS = re.compile(
32
+ r"^##\s+(closure decision|sunset|cancellation|maintainer override)",
33
+ re.IGNORECASE | re.MULTILINE,
34
+ )
35
+ NEXT_H2 = re.compile(r"^##\s+", re.MULTILINE)
36
+
37
+ BACKTICK_TOKEN = re.compile(r"`([^`\n]+?)`")
38
+ MD_LINK = re.compile(r"\]\(([^)\s]+?)\)")
39
+ TASK_TARGET = re.compile(r"^task\s+([a-z][\w:-]*)$")
40
+ SLASH_CMD = re.compile(r"^/([a-z][\w-]*(?::[a-z][\w-]*)?)$")
41
+ HEADING_PAT = re.compile(r"^##+\s+(.+)$")
42
+
43
+ PATH_HINT = re.compile(
44
+ r"^(scripts/|docs/|agents/|templates/|"
45
+ r"\.agent-src\.uncompressed/|\.agent-src/|\.augment/|\.claude/|\.cursor/|"
46
+ r"taskfiles/|Taskfile)"
47
+ )
48
+ PATH_SHAPED = re.compile(r"^[\w.-]+/.+|\.[a-z]{1,5}$")
49
+ CONCEPT_NAME = re.compile(r"^[a-z][\w-]{2,}$")
50
+ PUNCT_ONLY = re.compile(r"^[^A-Za-z0-9]+$")
51
+ SKIP_PREFIX = ("http://", "https://", "mailto:", "#")
52
+ SKIP_SUFFIX_FRAGMENT = re.compile(r"#.*$")
53
+
54
+
55
+ SHIPPED_MARKERS = re.compile(
56
+ r"\b(shipped|landed|live|live in|delivered|completed|complete|exists?|in tree|"
57
+ r"in place|wired|active|adopted|published|are live|partially shipped)\b",
58
+ re.IGNORECASE,
59
+ )
60
+ DROPPED_MARKERS = re.compile(
61
+ r"\b(sunset|sunsetted|dropped|drop\b|cancell?ed|deferred|retracted|phantom|"
62
+ r"never materiali[sz]ed|not shipped|does not exist|doesn't exist|missing|"
63
+ r"out of scope|deprioriti[sz]ed|out\-of\-scope|won't ship|will not ship)\b",
64
+ re.IGNORECASE,
65
+ )
66
+ BULLET_SPLIT = re.compile(r"^[ \t]*[-*]\s+", re.MULTILINE)
67
+
68
+
69
+ def bullet_sentiment(bullet_text: str) -> str:
70
+ has_dropped = bool(DROPPED_MARKERS.search(bullet_text))
71
+ has_shipped = bool(SHIPPED_MARKERS.search(bullet_text))
72
+ if has_dropped and not has_shipped:
73
+ return "dropped"
74
+ if has_shipped and not has_dropped:
75
+ return "shipped"
76
+ if has_shipped and has_dropped:
77
+ return "mixed"
78
+ return "neutral"
79
+
80
+
81
+ @dataclass
82
+ class Claim:
83
+ token: str
84
+ kind: str # path | task | md-link | slash-cmd | heading | concept
85
+ sentiment: str = "neutral" # shipped | dropped | mixed | neutral
86
+ exists: bool = False
87
+ ever_in_git: bool = False
88
+
89
+
90
+ @dataclass
91
+ class Verdict:
92
+ roadmap: str
93
+ has_closure: bool
94
+ block: str = ""
95
+ claims: list[Claim] = field(default_factory=list)
96
+ classification: str = "no-claims"
97
+ phantom_rate: float = 0.0
98
+
99
+
100
+ def find_block(text: str) -> str:
101
+ m = CLOSURE_HEADERS.search(text)
102
+ if not m:
103
+ return ""
104
+ start = m.start()
105
+ end_match = NEXT_H2.search(text, m.end())
106
+ end = end_match.start() if end_match else len(text)
107
+ return text[start:end]
108
+
109
+
110
+ def is_self_roadmap_ref(token: str, roadmap_name: str) -> bool:
111
+ base = token.rsplit("/", 1)[-1]
112
+ return base.endswith(".md") and (
113
+ base.startswith("step-") or base.startswith("road-to-") or base == roadmap_name
114
+ )
115
+
116
+
117
+ def classify_token(tok: str) -> tuple[str, str] | None:
118
+ tok = SKIP_SUFFIX_FRAGMENT.sub("", tok).strip()
119
+ if not tok or PUNCT_ONLY.match(tok) or any(tok.startswith(p) for p in SKIP_PREFIX):
120
+ return None
121
+ m = TASK_TARGET.match(tok)
122
+ if m:
123
+ return ("task", m.group(1))
124
+ m = SLASH_CMD.match(tok)
125
+ if m:
126
+ return ("slash-cmd", m.group(1))
127
+ m = HEADING_PAT.match(tok)
128
+ if m:
129
+ return ("heading", m.group(1).strip())
130
+ if PATH_HINT.match(tok) or "/" in tok or tok.endswith((".md", ".py", ".sh", ".yml", ".json")):
131
+ return ("path", tok)
132
+ if CONCEPT_NAME.match(tok):
133
+ return ("concept", tok)
134
+ return None
135
+
136
+
137
+ def split_bullets(block: str) -> list[str]:
138
+ parts = BULLET_SPLIT.split(block)
139
+ return [p.strip() for p in parts[1:] if p.strip()]
140
+
141
+
142
+ def _ingest(seen: dict, kind: str, value: str, sentiment: str) -> None:
143
+ key = (kind, value)
144
+ if key in seen:
145
+ existing = seen[key]
146
+ if existing.sentiment == "neutral" and sentiment != "neutral":
147
+ existing.sentiment = sentiment
148
+ elif existing.sentiment != sentiment and sentiment != "neutral":
149
+ existing.sentiment = "mixed"
150
+ return
151
+ seen[key] = Claim(value, kind, sentiment)
152
+
153
+
154
+ def extract_claims(block: str, roadmap_name: str) -> list[Claim]:
155
+ seen: dict[tuple[str, str], Claim] = {}
156
+ bullets = split_bullets(block) or [block]
157
+ for bullet in bullets:
158
+ sent = bullet_sentiment(bullet)
159
+ for m in BACKTICK_TOKEN.finditer(bullet):
160
+ cls = classify_token(m.group(1))
161
+ if not cls:
162
+ continue
163
+ kind, value = cls
164
+ if kind == "path" and is_self_roadmap_ref(value, roadmap_name):
165
+ continue
166
+ _ingest(seen, kind, value, sent)
167
+ for m in MD_LINK.finditer(bullet):
168
+ cls = classify_token(m.group(1))
169
+ if not cls:
170
+ continue
171
+ kind, value = cls
172
+ if kind == "path" and is_self_roadmap_ref(value, roadmap_name):
173
+ continue
174
+ _ingest(seen, "md-link", value, sent)
175
+ return list(seen.values())
176
+
177
+
178
+ def verify_path(token: str) -> bool:
179
+ return (REPO / token).exists()
180
+
181
+
182
+ def verify_task(target: str) -> bool:
183
+ for tf in [REPO / "Taskfile.yml", *((REPO / "taskfiles").glob("*.yml") if (REPO / "taskfiles").exists() else [])]:
184
+ if not tf.exists():
185
+ continue
186
+ if re.search(rf"^\s+{re.escape(target)}:\s*$", tf.read_text(), re.MULTILINE):
187
+ return True
188
+ return False
189
+
190
+
191
+ def verify_slash_cmd(name: str) -> bool:
192
+ base = name.split(":")[0]
193
+ candidates = [
194
+ REPO / ".agent-src.uncompressed" / "commands" / f"{base}.md",
195
+ REPO / ".agent-src.uncompressed" / "commands" / base,
196
+ REPO / ".agent-src.uncompressed" / "skills" / base,
197
+ REPO / ".claude" / "skills" / base,
198
+ ]
199
+ return any(c.exists() for c in candidates)
200
+
201
+
202
+ def verify_heading(heading: str) -> bool:
203
+ # Look for the heading text in skills/rules/contexts as evidence of pattern adoption
204
+ pattern = re.compile(rf"^##+\s+{re.escape(heading)}\b", re.MULTILINE)
205
+ for root in (REPO / ".agent-src.uncompressed", REPO / "agents", REPO / "docs"):
206
+ if not root.exists():
207
+ continue
208
+ for f in root.rglob("*.md"):
209
+ try:
210
+ if pattern.search(f.read_text(errors="ignore")):
211
+ return True
212
+ except Exception:
213
+ continue
214
+ return False
215
+
216
+
217
+ def verify_concept(name: str) -> bool:
218
+ # grep across source-of-truth tree for any literal mention as evidence
219
+ try:
220
+ r = subprocess.run(
221
+ ["git", "grep", "-l", "-w", name, "--",
222
+ ".agent-src.uncompressed/", "docs/", "scripts/", "agents/contexts/"],
223
+ cwd=REPO, capture_output=True, text=True, timeout=15,
224
+ )
225
+ return bool(r.stdout.strip())
226
+ except Exception:
227
+ return False
228
+
229
+
230
+ def git_history(token: str) -> bool:
231
+ try:
232
+ r = subprocess.run(
233
+ ["git", "log", "--all", "--oneline", "-n", "1", "--", token],
234
+ cwd=REPO, capture_output=True, text=True, timeout=10,
235
+ )
236
+ return bool(r.stdout.strip())
237
+ except Exception:
238
+ return False
239
+
240
+
241
+ def classify(claims: list[Claim]) -> tuple[str, float]:
242
+ # Phantom rate is computed only over claims the closure block *asserts as
243
+ # shipped*. Claims explicitly marked as dropped/sunset are excluded —
244
+ # missing them is consistent with the rationale, not a phantom.
245
+ shipped = [c for c in claims if c.sentiment in ("shipped", "mixed")]
246
+ if not shipped:
247
+ if not claims:
248
+ return "no-claims", 0.0
249
+ return "no-shipped-claims", 0.0
250
+ missing = [c for c in shipped if not c.exists]
251
+ rate = len(missing) / len(shipped)
252
+ if rate == 0:
253
+ return "verified", 0.0
254
+ if rate >= 0.5:
255
+ return "phantom", rate
256
+ return "partial-phantom", rate
257
+
258
+
259
+ def audit(roadmap: Path) -> Verdict:
260
+ text = roadmap.read_text()
261
+ block = find_block(text)
262
+ if not block:
263
+ return Verdict(roadmap.name, has_closure=False)
264
+ claims = extract_claims(block, roadmap.name)
265
+ for c in claims:
266
+ if c.kind == "task":
267
+ c.exists = verify_task(c.token)
268
+ elif c.kind == "slash-cmd":
269
+ c.exists = verify_slash_cmd(c.token)
270
+ elif c.kind == "heading":
271
+ c.exists = verify_heading(c.token)
272
+ elif c.kind == "concept":
273
+ c.exists = verify_concept(c.token)
274
+ else:
275
+ c.exists = verify_path(c.token)
276
+ if not c.exists and c.kind in ("path", "md-link"):
277
+ c.ever_in_git = git_history(c.token)
278
+ cls, rate = classify(claims)
279
+ return Verdict(roadmap.name, True, block.strip()[:200], claims, cls, rate)
280
+
281
+
282
+ def main(argv: Iterable[str]) -> int:
283
+ ap = argparse.ArgumentParser()
284
+ ap.add_argument("--json", type=Path)
285
+ ap.add_argument("--only", help="filter by roadmap name substring")
286
+ args = ap.parse_args(list(argv))
287
+
288
+ verdicts = []
289
+ for md in sorted(ARCHIVE.glob("*.md")):
290
+ if args.only and args.only not in md.name:
291
+ continue
292
+ verdicts.append(audit(md))
293
+
294
+ closure_set = [v for v in verdicts if v.has_closure]
295
+ by_cls: dict[str, list[Verdict]] = {}
296
+ for v in closure_set:
297
+ by_cls.setdefault(v.classification, []).append(v)
298
+
299
+ print(f"# Archive Closure-Verification Report\n")
300
+ print(f"- archive total: {len(verdicts)}")
301
+ print(f"- with closure block: {len(closure_set)}")
302
+ for cls in ("phantom", "partial-phantom", "verified", "no-shipped-claims", "no-claims"):
303
+ print(f"- {cls}: {len(by_cls.get(cls, []))}")
304
+ print()
305
+
306
+ for cls in ("phantom", "partial-phantom"):
307
+ rows = by_cls.get(cls, [])
308
+ if not rows:
309
+ continue
310
+ print(f"## {cls.upper()} ({len(rows)})\n")
311
+ for v in sorted(rows, key=lambda x: -x.phantom_rate):
312
+ print(f"### {v.roadmap} · phantom-rate {v.phantom_rate:.0%} (shipped-claim basis)")
313
+ for c in v.claims:
314
+ mark = "✅" if c.exists else "❌"
315
+ git = " (git: ever-existed)" if (not c.exists and c.ever_in_git) else ""
316
+ sentinel = {"shipped": "[SHIP]", "dropped": "[DROP]", "mixed": "[MIX]", "neutral": "[--]"}.get(c.sentiment, "[?]")
317
+ print(f" {mark} {sentinel} [{c.kind}] `{c.token}`{git}")
318
+ print()
319
+
320
+ if args.json:
321
+ args.json.write_text(json.dumps([v.__dict__ for v in verdicts], default=lambda o: o.__dict__, indent=2))
322
+ print(f"\n→ JSON written to {args.json}", file=sys.stderr)
323
+ return 0
324
+
325
+
326
+ if __name__ == "__main__":
327
+ sys.exit(main(sys.argv[1:]))