Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

fix(skill): keep SKILL.md LF and measure its byte cap on LF bytes (#256)

Cathryn Laveryc874f326174e
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..3610938
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+# SKILL.md is held to a byte cap (ADR 0004). Keep it LF in the repository
+# and in every checkout, whatever core.autocrlf says, so the measured size
+# is the committed size.
+skills/diagram-design/SKILL.md text eol=lf
diff --git a/docs/adr/0004-skill-md-byte-cap-and-trigger-rich-description.md b/docs/adr/0004-skill-md-byte-cap-and-trigger-rich-description.md
index 9d8758e..82bb618 100644
--- a/docs/adr/0004-skill-md-byte-cap-and-trigger-rich-description.md
+++ b/docs/adr/0004-skill-md-byte-cap-and-trigger-rich-description.md
@@ -16,4 +16,4 @@ Two rules, in priority order:
## Consequences
- Adding a visual type requires touching the description; CI fails otherwise, by design.
-- The cap is measured on raw bytes with `core.autocrlf=false` pinned in CI checkout; Windows contributors should keep LF endings for `SKILL.md`.
+- `.gitattributes` pins SKILL.md to LF in the repository and in every checkout, and the cap counts LF-normalized bytes, so a checkout with `core.autocrlf=true` measures the committed size ([#246](https://github.com/cathrynlavery/diagram-design/issues/246)). Normalization never loosens the cap: 40,001 LF bytes still fail, and the gate fails if the pin is removed.
diff --git a/scripts/test-verify-semantic-motion.py b/scripts/test-verify-semantic-motion.py
index a32137c..3ebf20d 100644
--- a/scripts/test-verify-semantic-motion.py
+++ b/scripts/test-verify-semantic-motion.py
@@ -10,6 +10,9 @@ test-verify-motion.py for the other verifiers in this repo.
from __future__ import annotations
import importlib.util
+import os
+import shutil
+import subprocess
import sys
import tempfile
from pathlib import Path
@@ -98,27 +101,130 @@ def main() -> int:
raise AssertionError(f"missing lifecycle route was accepted: {errors}")
print("OK: missing lifecycle phase-map route is rejected")
- # The byte cap is inclusive. Pad the real SKILL.md after its final
- # newline so every other check still reads the shipped content.
- skill_bytes = original_skill.read_bytes()
+ # The byte cap is inclusive and measures LF-normalized bytes, so a
+ # checkout with core.autocrlf=true measures the same as the
+ # committed file (#246). Pad the real SKILL.md after its final
+ # newline so every other check still reads the shipped content,
+ # and run each boundary with LF and CRLF line endings.
+ skill_bytes = original_skill.read_bytes().replace(b"\r\n", b"\n")
if len(skill_bytes) > 40_000:
raise AssertionError(
f"shipped SKILL.md is already {len(skill_bytes)} bytes; "
"the boundary cases need it at or under 40000"
)
+ if skill_bytes.count(b"\n") < 100:
+ raise AssertionError("shipped SKILL.md has too few lines to test CRLF")
for size, expected in (
+ (None, []),
(40_000, []),
(40_001, ["SKILL.md exceeds 40000 bytes: 40001 bytes"]),
):
- padded = scratch / f"skill-{size}.md"
- padded.write_bytes(skill_bytes + b" " * (size - len(skill_bytes)))
- module.SKILL = padded
- errors = module.verify_markdown()
- if errors != expected:
- raise AssertionError(
- f"SKILL.md byte cap at {size} bytes: expected {expected}, got {errors}"
- )
- print("OK: SKILL.md passes at 40000 bytes and is rejected at 40001")
+ lf = skill_bytes if size is None else skill_bytes + b" " * (size - len(skill_bytes))
+ for label, content in (("LF", lf), ("CRLF", lf.replace(b"\n", b"\r\n"))):
+ padded = scratch / f"skill-{size}-{label}.md"
+ padded.write_bytes(content)
+ module.SKILL = padded
+ errors = module.verify_markdown()
+ if errors != expected:
+ raise AssertionError(
+ f"SKILL.md byte cap, {label}, "
+ f"{size or 'shipped'} normalized bytes: expected {expected}, got {errors}"
+ )
+ # Mixed endings normalize the same way and still fail past the cap.
+ over = skill_bytes + b" " * (40_001 - len(skill_bytes))
+ head, tail = over[: len(over) // 2], over[len(over) // 2 :]
+ mixed = scratch / "skill-mixed.md"
+ mixed.write_bytes(head.replace(b"\n", b"\r\n") + tail)
+ module.SKILL = mixed
+ if module.verify_markdown() != ["SKILL.md exceeds 40000 bytes: 40001 bytes"]:
+ raise AssertionError(f"mixed line endings loosened the cap: {module.verify_markdown()}")
+ print(
+ "OK: SKILL.md passes at 40000 LF-normalized bytes and is rejected at "
+ "40001, with LF, CRLF, and mixed line endings alike"
+ )
+
+ # The repository pins SKILL.md to LF, so the committed file is what
+ # the cap measures. The gate asks git, so every rule form counts the
+ # way git counts it; each case runs in a scratch repository.
+ module.SKILL = original_skill
+ if shutil.which("git") is None:
+ print("SKIP: git not found; the SKILL.md LF pin cases were not run")
+ else:
+ pin = "skills/diagram-design/SKILL.md text eol=lf\n"
+ original_root = module.GIT_ROOT
+ for label, attributes, pinned in (
+ ("no pin", "*.png binary\n", False),
+ ("exact pin", pin, True),
+ ("glob pin", "*.md text eol=lf\n", True),
+ ("unrelated later rule", pin + "docs/*.md eol=crlf\n", True),
+ ("later eol=crlf", pin + "*.md eol=crlf\n", False),
+ ("later -text", pin + "skills/**/SKILL.md -text\n", False),
+ ("later binary", pin + "SKILL.md binary\n", False),
+ ("later unset eol", pin + "SKILL.md !eol\n", False),
+ ("later character class", pin + "SKILL.[m]d eol=crlf\n", False),
+ ("later negated class that misses", pin + "SKILL.[!m]d eol=crlf\n", True),
+ ("later class with an escaped bracket", pin + "SKILL.[m\\]]d eol=crlf\n", False),
+ ):
+ repo = scratch / f"repo-{label.replace(' ', '-')}"
+ repo.mkdir()
+ subprocess.run(["git", "init", "-q", str(repo)], check=True)
+ (repo / ".gitattributes").write_text(attributes, encoding="utf-8")
+ module.GIT_ROOT = repo
+ try:
+ errors = module.verify_markdown()
+ finally:
+ module.GIT_ROOT = original_root
+ flagged = any(".gitattributes must pin" in error for error in errors)
+ if flagged == pinned:
+ raise AssertionError(f".gitattributes {label}: pinned={pinned}, got {errors}")
+ # A contributor's own git configuration must not stand in for
+ # the repository pin: a global `*.md text eol=lf` rule, and a
+ # repo-local info/attributes rule, are both ignored.
+ masked = scratch / "repo-masked-by-global-attributes"
+ masked.mkdir()
+ subprocess.run(["git", "init", "-q", str(masked)], check=True)
+ (masked / ".gitattributes").write_text("*.png binary\n", encoding="utf-8")
+ (masked / ".git" / "info").mkdir(parents=True, exist_ok=True)
+ (masked / ".git" / "info" / "attributes").write_text("*.md text eol=lf\n", encoding="utf-8")
+ global_attributes = scratch / "global-attributes"
+ global_attributes.write_text("*.md text eol=lf\n", encoding="utf-8")
+ global_config = scratch / "global-gitconfig"
+ global_config.write_text(
+ f"[core]\n\tattributesFile = {global_attributes.as_posix()}\n", encoding="utf-8"
+ )
+ saved = os.environ.get("GIT_CONFIG_GLOBAL")
+ os.environ["GIT_CONFIG_GLOBAL"] = str(global_config)
+ module.GIT_ROOT = masked
+ try:
+ errors = module.verify_markdown()
+ finally:
+ module.GIT_ROOT = original_root
+ if saved is None:
+ os.environ.pop("GIT_CONFIG_GLOBAL", None)
+ else:
+ os.environ["GIT_CONFIG_GLOBAL"] = saved
+ if not any(".gitattributes must pin" in error for error in errors):
+ raise AssertionError(f"global or local attributes masked a missing pin: {errors}")
+ # Git hooks export GIT_DIR. An inherited repository location must
+ # neither redirect the scratch repository nor let that
+ # repository's local attributes mask the missing pin.
+ masked_config = (masked / ".git" / "config").read_bytes()
+ saved_dir = os.environ.get("GIT_DIR")
+ os.environ["GIT_DIR"] = str(masked / ".git")
+ module.GIT_ROOT = masked
+ try:
+ errors = module.verify_markdown()
+ finally:
+ module.GIT_ROOT = original_root
+ if saved_dir is None:
+ os.environ.pop("GIT_DIR", None)
+ else:
+ os.environ["GIT_DIR"] = saved_dir
+ if not any(".gitattributes must pin" in error for error in errors):
+ raise AssertionError(f"an inherited GIT_DIR masked a missing pin: {errors}")
+ if (masked / ".git" / "config").read_bytes() != masked_config:
+ raise AssertionError("the pin check modified the repository named by GIT_DIR")
+ print("OK: .gitattributes must pin SKILL.md to LF, as git resolves it")
finally:
module.SKILL = original_skill
diff --git a/scripts/verify-semantic-motion.py b/scripts/verify-semantic-motion.py
index b09e31c..82fe3b9 100644
--- a/scripts/verify-semantic-motion.py
+++ b/scripts/verify-semantic-motion.py
@@ -7,8 +7,12 @@ Uses only the Python standard library and never executes example JavaScript.
from __future__ import annotations
import argparse
+import os
import re
+import shutil
+import subprocess
import sys
+import tempfile
from collections import Counter
from html.parser import HTMLParser
from pathlib import Path
@@ -17,6 +21,7 @@ from urllib.parse import parse_qs, urlparse
ROOT = Path(__file__).resolve().parent.parent
SKILL = ROOT / "skills/diagram-design/SKILL.md"
+GIT_ROOT = ROOT
PATTERNS = ROOT / "skills/diagram-design/references/semantic-patterns.md"
ANIMATION = ROOT / "skills/diagram-design/references/animation.md"
EXAMPLE = ROOT / "skills/diagram-design/assets/example-policy-trace-animated.html"
@@ -180,9 +185,69 @@ def section(markdown: str, heading: str, next_heading: str | None) -> str:
return markdown[start:] if end < 0 else markdown[start:end]
+SKILL_PATH_IN_REPO = "skills/diagram-design/SKILL.md"
+
+
+def skill_lf_pin_problem(root: Path) -> str | None:
+ """Why the committed .gitattributes would not keep SKILL.md LF, or None.
+
+ Git itself resolves the attributes (`git check-attr`), so every rule,
+ glob, bracket expression, and later override counts exactly as git
+ counts it. It runs in a scratch repository holding only the committed
+ .gitattributes files on SKILL.md's path, with global and system config
+ switched off and inherited GIT_* variables dropped, so neither a
+ contributor's own attributes nor a hook's repository can stand in for the
+ repository pin.
+ """
+ git = shutil.which("git")
+ if git is None:
+ return None
+ parts = Path(SKILL_PATH_IN_REPO).parent.parts
+ committed = [Path(*parts[:depth], ".gitattributes") for depth in range(len(parts) + 1)]
+ with tempfile.TemporaryDirectory(prefix="skill-lf-pin-") as scratch:
+ scratch_root = Path(scratch)
+ # Drop inherited GIT_* variables: a hook's GIT_DIR or GIT_WORK_TREE would
+ # otherwise point both commands at the caller's repository.
+ env = {
+ **{name: value for name, value in os.environ.items() if not name.startswith("GIT_")},
+ # Paths that do not exist read as empty on every platform.
+ "GIT_CONFIG_GLOBAL": str(scratch_root / "no-global-config"),
+ "GIT_CONFIG_NOSYSTEM": "1",
+ "HOME": scratch,
+ "XDG_CONFIG_HOME": scratch,
+ }
+ subprocess.run([git, "init", "-q", scratch], capture_output=True, env=env, check=True)
+ for relative in committed:
+ source = root / relative
+ if source.is_file():
+ target = scratch_root / relative
+ target.parent.mkdir(parents=True, exist_ok=True)
+ target.write_bytes(source.read_bytes())
+ result = subprocess.run(
+ [git, "-C", scratch, "-c", f"core.attributesFile={(scratch_root / 'no-attributes').as_posix()}",
+ "check-attr", "text", "eol", "--", SKILL_PATH_IN_REPO],
+ capture_output=True,
+ text=True,
+ env=env,
+ )
+ if result.returncode != 0:
+ return f"git check-attr failed: {result.stderr.strip()}"
+ values = dict(
+ line.rsplit(": ", 2)[1:] for line in result.stdout.splitlines() if line.count(": ") >= 2
+ )
+ if values.get("text") not in ("set", "auto") or values.get("eol") != "lf":
+ return (
+ ".gitattributes must pin skills/diagram-design/SKILL.md to `text eol=lf` "
+ f"so the byte cap measures the committed file (git resolves text={values.get('text')}, "
+ f"eol={values.get('eol')})"
+ )
+ return None
+
def verify_markdown() -> list[str]:
errors: list[str] = []
- skill_bytes = SKILL.read_bytes()
+ # Measure the committed LF content. A checkout with core.autocrlf=true adds
+ # one CR per line, which would otherwise fail the cap on Windows (#246).
+ skill_bytes = SKILL.read_bytes().replace(b"\r\n", b"\n")
skill = skill_bytes.decode("utf-8")
patterns = PATTERNS.read_text(encoding="utf-8")
animation = ANIMATION.read_text(encoding="utf-8")
@@ -191,6 +256,9 @@ def verify_markdown() -> list[str]:
errors.append(
f"SKILL.md exceeds {MAX_SKILL_BYTES} bytes: {len(skill_bytes)} bytes"
)
+ pin_problem = skill_lf_pin_problem(GIT_ROOT)
+ if pin_problem:
+ errors.append(pin_problem)
if "Selection: semantic pattern, then visual type" not in skill:
errors.append("SKILL.md must choose semantic pattern before visual type")
router_position = skill.find("semantic-patterns.md")