Skip to content

Commit 6b1edb9

Browse files
TMHSDigitalclaude
andauthored
feat: add Phase 1 stamper scripts (add_frontmatter.py, add_comment_marker.py) (#67)
* feat: add add_frontmatter.py and add_comment_marker.py Phase 1 stamper scripts These scripts are called by cli.py --fix to apply standards-version updates in-place. add_frontmatter.py targets YAML-frontmatter files (SKILL.md, .mdc), add_comment_marker.py targets HTML-comment marker files (CLAUDE.md, AGENTS.md). Interface: python <script> <file_path> <new_version> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: fOuttaMyPaint <154358121+TMHSDigital@users.noreply.github.com> * chore: bump VERSION to 1.13.0 for feat: add Phase 1 stamper scripts Signed-off-by: fOuttaMyPaint <154358121+TMHSDigital@users.noreply.github.com> --------- Signed-off-by: fOuttaMyPaint <154358121+TMHSDigital@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 56e9d80 commit 6b1edb9

3 files changed

Lines changed: 117 additions & 1 deletion

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.0
1+
1.13.0

scripts/add_comment_marker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Update the standards-version HTML comment marker in an agent file.
2+
3+
Usage: python add_comment_marker.py <file_path> <new_version>
4+
5+
Finds a line matching ``<!-- standards-version: X.Y.Z -->`` (anywhere in the
6+
file, though convention is the first line) and replaces the version. Exits 0
7+
on success, 1 if the marker is absent.
8+
"""
9+
from __future__ import annotations
10+
11+
import re
12+
import sys
13+
from pathlib import Path
14+
15+
16+
_MARKER_RE = re.compile(r"<!--\s*standards-version\s*:\s*[^\s>]+\s*-->")
17+
18+
19+
def _update(text: str, new_version: str) -> str | None:
20+
"""Return updated text, or None if no marker is found."""
21+
new_marker = f"<!-- standards-version: {new_version} -->"
22+
updated, count = _MARKER_RE.subn(new_marker, text, count=1)
23+
return updated if count else None
24+
25+
26+
def main(argv: list[str]) -> int:
27+
if len(argv) != 3:
28+
print(f"usage: {argv[0]} <file_path> <new_version>", file=sys.stderr)
29+
return 1
30+
31+
path = Path(argv[1])
32+
new_version = argv[2]
33+
34+
try:
35+
text = path.read_text(encoding="utf-8")
36+
except OSError as exc:
37+
print(f"error: cannot read {path}: {exc}", file=sys.stderr)
38+
return 1
39+
40+
updated = _update(text, new_version)
41+
if updated is None:
42+
print(f"error: standards-version marker not found in {path}", file=sys.stderr)
43+
return 1
44+
45+
path.write_text(updated, encoding="utf-8")
46+
print(f"updated {path}")
47+
return 0
48+
49+
50+
if __name__ == "__main__":
51+
sys.exit(main(sys.argv))

scripts/add_frontmatter.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Update the standards-version field in a YAML-frontmatter file.
2+
3+
Usage: python add_frontmatter.py <file_path> <new_version>
4+
5+
Finds the ``standards-version:`` key inside the leading ``---`` block and
6+
replaces its value. Exits 0 on success, 1 if the marker is absent or the
7+
file cannot be parsed.
8+
"""
9+
from __future__ import annotations
10+
11+
import re
12+
import sys
13+
from pathlib import Path
14+
15+
16+
_FRONTMATTER_RE = re.compile(r"\Astandardsversion:", re.I) # loose sentinel
17+
18+
19+
def _update(text: str, new_version: str) -> str | None:
20+
"""Return updated text, or None if the standards-version key is absent."""
21+
lines = text.splitlines(keepends=True)
22+
in_block = False
23+
for i, line in enumerate(lines):
24+
stripped = line.lstrip()
25+
if i == 0 and stripped.rstrip() == "---":
26+
in_block = True
27+
continue
28+
if in_block and stripped.rstrip() in ("---", "..."):
29+
break
30+
if in_block and re.match(r"^standards-version\s*:", stripped):
31+
lines[i] = re.sub(
32+
r"(standards-version\s*:\s*).*",
33+
rf"\g<1>{new_version}",
34+
line,
35+
)
36+
return "".join(lines)
37+
return None
38+
39+
40+
def main(argv: list[str]) -> int:
41+
if len(argv) != 3:
42+
print(f"usage: {argv[0]} <file_path> <new_version>", file=sys.stderr)
43+
return 1
44+
45+
path = Path(argv[1])
46+
new_version = argv[2]
47+
48+
try:
49+
text = path.read_text(encoding="utf-8")
50+
except OSError as exc:
51+
print(f"error: cannot read {path}: {exc}", file=sys.stderr)
52+
return 1
53+
54+
updated = _update(text, new_version)
55+
if updated is None:
56+
print(f"error: standards-version not found in frontmatter of {path}", file=sys.stderr)
57+
return 1
58+
59+
path.write_text(updated, encoding="utf-8")
60+
print(f"updated {path}")
61+
return 0
62+
63+
64+
if __name__ == "__main__":
65+
sys.exit(main(sys.argv))

0 commit comments

Comments
 (0)