Skip to content

The meta-skill that builds and improves all your skills, including itself. Watches your work sessions (autonomous or human-led), captures patterns, corrections and judgement calls, and turns them into skill improvements and new skill candidates for your review. Practical application of the Augmented Expertise methodology. Open source: CC BY 4.0.

Pre-flight the literal command; make the delivery gate assert

Eoghan Henn311c73851d46
diff --git a/references/skill-authoring.md b/references/skill-authoring.md
index 2960cbb..ea478ae 100644
--- a/references/skill-authoring.md
+++ b/references/skill-authoring.md
@@ -48,6 +48,24 @@ with its output inspected for plausibility, before the skill file is
saved. An unverified snippet is among the highest-risk lines in a skill:
it ships bugs that no re-read can catch.
+**Run the literal string, from a clean shell.** Verifying a command by
+running something *equivalent* verifies your paraphrase, not the
+artefact. Copy the command out of the skill file and execute that exact
+text — from a separately spawned shell, not the session you did the work
+in: a working session accumulates environment variables, interpreter
+flags, security-policy overrides, PATH entries and a working directory
+that the eventual reader will not have, and a command that passes there
+can fail on first real use from a normal terminal. Where two shells are
+available, pre-flight in the one NOT used for setup. **When the command
+under test is a guard, assert on the mechanism, not the outcome.** A
+negative test passes only when the failure occurs for the intended reason;
+with several guards over one operation, "it was rejected" is satisfied by
+any of them. Match the error text or exit code to the guard under test,
+choose inputs clearly past the threshold, and test the boundary value
+separately. **Confirm a dry-run path exists before pre-flighting anything
+with side effects**; where none exists, add one first — a test of a guard
+rail must not become the incident the guard rail exists to prevent.
+
**A verification command that AGREES with you is the one to distrust.**
Executing a snippet once, as above, does not catch this class: the command
runs cleanly and returns a plausible number. A check that contradicts a
@@ -315,15 +333,27 @@ capture is the point.)
phrasing, not dropping triggers. Measure every skill in the delivery
set, not just the one that failed — the pressure toward trigger-rich
descriptions puts others near the boundary too, and only measuring the
- set reveals it. Generally: any hard limit the consuming platform imposes
- belongs in this gate as a measurement, not as a rule the author is
- expected to remember; otherwise the user discovers it at install time.
- (Reading this rule while drafting does not enforce
- it at delivery; run the gate as the last step before presenting.)
+ set reveals it; (4) `name` is kebab-case and matches the containing
+ directory; the frontmatter parses as YAML with both required keys;
+ (5) the packed archive's member paths contain no backslash — read as
+ RAW central-directory bytes, because CPython's `zipfile` normalises
+ `0x5C` to `/` on read and reports a malformed archive as clean; Windows
+ `Compress-Archive` produces exactly this defect for any skill with a
+ subdirectory. `scripts/validate-skill-bundle.py` implements all five as
+ assertions and packs a well-formed bundle on any platform; run it where
+ Python is available. Generally: any hard limit the consuming platform
+ imposes belongs in this gate as a measurement compared to a bound in
+ the same step, not as a rule the author is expected to remember — an
+ unasserted metric does not merely miss defects, it manufactures
+ confidence that none exist. State limits as numbers and label them as
+ the consumer's. (Reading this rule while drafting does not enforce it
+ at delivery; run the gate as the last step before presenting.)
Packaging hygiene: before zipping, sweep the staged tree for build
artefacts (`__pycache__/`, `*.pyc`, `.DS_Store`, `.~lock.*`) left by
in-session checks, and read the archive listing back after zipping —
- the listing is the cheap verification that catches leaked artefacts.
+ the listing catches two defect classes, leaked artefacts AND wrong
+ path separators, and it gets read only for the one you name, so check
+ for both explicitly.
6. When seeding a staged copy by copying from the read-only mount, reset
write permissions immediately — the mount's read-only mode travels with
the copy, for directories as well as files, and the follow-up edit
diff --git a/references/weekly-review.md b/references/weekly-review.md
index c2e270d..07be22d 100644
--- a/references/weekly-review.md
+++ b/references/weekly-review.md
@@ -281,9 +281,14 @@ delivery if the artefact being presented is bare file links rather than
the `.skill` bundle; (3) measure each staged skill's frontmatter
description (the folded value, not the raw YAML block) and fail the
delivery above 1024 characters, with a soft warning above ~900 —
-measure every skill in the set, not just the one that failed. Sweep build artefacts (`__pycache__/`, `*.pyc`,
-`.DS_Store`, `.~lock.*`) before zipping and read the archive listing back
-after. When seeding staged
+measure every skill in the set, not just the one that failed; (4) `name`
+is kebab-case, matches the directory, and the frontmatter parses; (5) the
+bundle's member paths use `/`, checked on raw bytes (Windows packers write
+`\`, and normalising readers hide it). `scripts/validate-skill-bundle.py`
+asserts all five and packs a well-formed bundle — run it where Python is
+available. Sweep build artefacts (`__pycache__/`, `*.pyc`, `.DS_Store`,
+`.~lock.*`) before zipping and read the archive listing back after, for
+leaked artefacts and for path separators. When seeding staged
copies from the read-only mount, `chmod -R u+w` the staged path first —
the mount's read-only mode travels with the copy, for directories as
well as files. Do not edit skill files in place — nothing goes live
diff --git a/scripts/validate-skill-bundle.py b/scripts/validate-skill-bundle.py
new file mode 100644
index 0000000..98fd93f
--- /dev/null
+++ b/scripts/validate-skill-bundle.py
@@ -0,0 +1,147 @@
+#!/usr/bin/env python3
+"""
+validate-skill-bundle.py — the pre-delivery gate, as assertions.
+
+Checks a staged skill directory (and optionally its packed .skill bundle)
+against the criteria the INSTALLER enforces, not against what seems
+sensible. Every check compares a measurement to a bound in the same step:
+an unasserted metric manufactures confidence that no defect exists.
+
+Usage
+-----
+ python3 validate-skill-bundle.py <staged-skill-dir> [--bundle file.skill] [--pack out.skill]
+
+ --pack writes a well-formed bundle (POSIX separators on any platform)
+ after the directory checks pass, then validates it.
+
+Exit status 0 = every check passed; 1 = at least one failed (all failures
+are listed, not just the first).
+
+Limits are stated as numbers and labelled with where they come from, so
+the check is implementable without guessing and can be updated when the
+consumer changes them.
+"""
+
+import pathlib
+import re
+import struct
+import sys
+import zipfile
+
+MAX_DESCRIPTION_CHARS = 1024 # installer's documented cap on the folded description
+NAME_RE = re.compile(r"^[a-z0-9]+(-[a-z0-9]+)*$") # kebab-case
+PATH_RE = re.compile(r"`((?:references|scripts|assets)/[^`\s*?]+\.[A-Za-z0-9]+)`")
+BUILD_JUNK = {"__pycache__", ".DS_Store"}
+
+
+def frontmatter(text):
+ m = re.match(r"^---\n(.*?)\n---\n", text, re.S)
+ return m.group(1) if m else None
+
+
+def folded_description(fm):
+ m = re.search(r"(?ms)^description:\s*>-?\s*\n(.*?)(?=^\S|\Z)", fm)
+ if m:
+ return " ".join(m.group(1).split())
+ m = re.search(r"(?m)^description:\s*(.+)$", fm)
+ return m.group(1).strip().strip('"\'') if m else ""
+
+
+def check_dir(skill_dir, fails):
+ skill_dir = pathlib.Path(skill_dir)
+ skill_md = skill_dir / "SKILL.md"
+ if not skill_md.is_file():
+ fails.append("SKILL.md missing"); return
+ text = skill_md.read_text(encoding="utf-8")
+ fm = frontmatter(text)
+ if fm is None:
+ fails.append("frontmatter: no leading --- block"); return
+ try:
+ import yaml # optional; fall back to regex checks if absent
+ data = yaml.safe_load(fm)
+ if not isinstance(data, dict):
+ fails.append("frontmatter: does not parse to a mapping")
+ data = {}
+ except ImportError:
+ data = {"name": (re.search(r"(?m)^name:\s*(.+)$", fm) or [None, ""])[1].strip(),
+ "description": folded_description(fm)}
+ except Exception as e: # yaml error
+ fails.append(f"frontmatter: YAML parse error: {e}"); data = {}
+ name = str(data.get("name") or "").strip()
+ if not name:
+ fails.append("frontmatter: `name` missing")
+ elif not NAME_RE.match(name):
+ fails.append(f"frontmatter: `name` not kebab-case: {name!r}")
+ elif name != skill_dir.name:
+ fails.append(f"frontmatter: `name` {name!r} != directory {skill_dir.name!r}")
+ desc = folded_description(fm)
+ if not desc:
+ fails.append("frontmatter: `description` missing")
+ elif len(desc) > MAX_DESCRIPTION_CHARS:
+ fails.append(f"description {len(desc)} chars > cap {MAX_DESCRIPTION_CHARS}")
+ elif len(desc) > 900:
+ print(f"warn: description {len(desc)} chars (cap {MAX_DESCRIPTION_CHARS}) — near the boundary")
+ # every cited bundled path exists (backticked, real extension — globs in prose are skipped)
+ for rel in sorted(set(PATH_RE.findall(text))):
+ if not (skill_dir / rel).is_file():
+ fails.append(f"cited path missing from staged set: {rel}")
+ for p in skill_dir.rglob("*"):
+ if p.name in BUILD_JUNK or p.suffix == ".pyc" or p.name.startswith(".~lock"):
+ fails.append(f"build artefact in staged tree: {p.relative_to(skill_dir)}")
+
+
+def pack(src, out):
+ """Always writes POSIX separators, on any platform."""
+ src = pathlib.Path(src)
+ with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z:
+ for f in sorted(p for p in src.rglob("*") if p.is_file()):
+ arc = f"{src.name}/{f.relative_to(src).as_posix()}"
+ assert "\\" not in arc, arc
+ z.write(f, arcname=arc)
+
+
+def check_bundle(path, fails):
+ """Central directory as raw bytes: a convenience reader (zipfile.namelist)
+ rewrites 0x5C to '/' and would report a malformed archive as clean."""
+ data, i, n_members = pathlib.Path(path).read_bytes(), 0, 0
+ while True:
+ i = data.find(b"PK\x01\x02", i)
+ if i < 0:
+ break
+ n, m, k = (struct.unpack_from("<H", data, i + o)[0] for o in (28, 30, 32))
+ name = data[i + 46:i + 46 + n]
+ n_members += 1
+ if b"\x5c" in name:
+ fails.append(f"bundle: backslash in member path {name!r} (installer rejects it)")
+ i += 46 + n + m + k
+ if n_members == 0:
+ fails.append("bundle: no members found")
+
+
+def main(argv):
+ if len(argv) < 2:
+ print(__doc__); return 2
+ skill_dir = argv[1]
+ bundle = pack_to = None
+ if "--bundle" in argv:
+ bundle = argv[argv.index("--bundle") + 1]
+ if "--pack" in argv:
+ pack_to = argv[argv.index("--pack") + 1]
+ fails = []
+ check_dir(skill_dir, fails)
+ if pack_to and not fails:
+ pack(skill_dir, pack_to); bundle = pack_to
+ print(f"packed {pack_to}")
+ if bundle:
+ check_bundle(bundle, fails)
+ if fails:
+ print("FAIL:")
+ for f in fails:
+ print(" -", f)
+ return 1
+ print("OK: all gate checks passed")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))