{"data":{"slug":"discovered-60de090048e2cdd4d86cf74996260621c23a312bbe8f18e3","title":"Stamp Docs","summary":"Automatically updates version numbers and last-updated dates in Markdown and PowerPoint documents during commit, ensuring they reflect the current content accurately. The skill runs by itself at commit time via a pre-commit hook, and can also be used to check, backfill, or force version bumps on documents.","url":"https:\/\/skillshunter.net\/skills\/discovered-60de090048e2cdd4d86cf74996260621c23a312bbe8f18e3","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-60de090048e2cdd4d86cf74996260621c23a312bbe8f18e3","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-60de090048e2cdd4d86cf74996260621c23a312bbe8f18e3.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-60de090048e2cdd4d86cf74996260621c23a312bbe8f18e3\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"To use this skill, ensure the document is staged before committing, as the pre-commit hook applies the stamp based on the staged content. For a major version bump, use the `--major` flag with the document path.","instructions":"---\nname: stamp-docs\ndescription: Keep the bus-system documents (Markdown and PowerPoint) correctly stamped and correctly formatted \u2014 a visible version number and last-updated date that refresh themselves, and Markdown paragraphs kept as whole unwrapped lines. Stamping runs by itself at commit time, from each repository's pre-commit hook; invoke this skill to check the current state, backfill newly added documents, force a major-version bump after a rewrite, change which documents are in scope, or unwrap hard-wrapped Markdown. Use when asked to check\/fix document versions or dates, \"what version is this doc\", \"did the stamp update\", \"add the new folder to stamping\", \"bump that doc to v2\", or to fix\/unwrap\/reflow hard-wrapped paragraphs in .md files.\n---\n\n# stamp-docs\n\nEvery in-scope document carries a version and a last-updated date that is visible when it is viewed or printed, and that refreshes itself whenever the document changes.\n\n## How it already works without you\n\n**The pre-commit hook stamps the documents in the commit in front of it** (`scripts\/docstamp.py --staged`, since 18 September 2026 \u2014 buses-data OA-397, R4 of the process review), so the committed stamp describes the committed content by construction. **You do not need to invoke this skill, re-stamp anything or remember an order of operations**: edit, stage, commit, and the stamp in the commit is current. A document edited and not yet committed carries its previous stamp until it is committed, which is what a stamp should mean.\n\nUntil that day a Stop hook stamped the working tree after every turn, so a commit made mid-turn carried the new content and the old stamp; the story is in [README.md](README.md#what-keeps-it-up-to-date). The hook and its `--auto` mode are both gone \u2014 `--auto` was deleted from the script on 21 September 2026.\n\n## The stamp\n\nVersion is `major.minor` starting at **v1.0**. An ordinary edit bumps the **minor**; a rewrite deserves `--major`. Dates read `27 July 2026`.\n\n**Markdown** \u2014 two lines just after the H1. The HTML comment is invisible in every renderer and is the machine anchor; the bold line is what a reader sees.\n\n```markdown\n# Runbook R1 \u2014 Create a new area or place map\n\n<!-- docstamp v1.4 | 2026-07-27 | sha=3f9a1c2b -->\n**v1.4** \u00b7 updated 27 July 2026\n```\n\n**PowerPoint** \u2014 a 9pt text box on every slide, shape-named `docstamp` so a re-run updates it instead of stacking a second one. Position is whichever candidate band is clear on *every* slide (`top-right` preferred); colour flips light or dark from the slide's background luminance. The record lives in the file's core properties.\n\n## Why a re-run changes nothing\n\nThe stamp carries a short hash of the document's **own content with the stamp removed** \u2014 for a deck, all slide text plus every embedded media blob, so a swapped image counts as a change. If the hash is unchanged the file is **not rewritten at all**, so mtimes never churn and a document re-committed unchanged keeps its version.\n\n## Commands\n\nEvery command on this page runs from `stamp-docs` \u2014 this skill's own folder in the `claude-skills` repository, where `scripts\/` and `stamp-policy.json` sit beside each other. There are no placeholders except the quoted paths, which are the documents or folders to act on.\n\n```bash\npython scripts\/docstamp.py --check              # audit; exits 1 if anything is missing or stale\npython scripts\/docstamp.py --list               # what is in scope\npython scripts\/docstamp.py --backfill           # stamp new documents at v1.0, dated from git\npython scripts\/docstamp.py --all                # hash scan; stamps whatever changed\npython scripts\/docstamp.py --major \"path\/to\/doc.md\"   # rewrite: v1.4 -> v2.0\npython scripts\/docstamp.py --minor \"path\/to\/doc.md\"   # force a bump\npython scripts\/docstamp.py --staged             # what the pre-commit hook runs: stamp the staged documents into the index; always exits 0\npython scripts\/docstamp.py --all --all-roots    # every root, not just the one you are in\n```\n\nAdd `--dry-run` to any of them. A walk covers only the root containing the working directory and prints which, with the absolute path it will write \u2014 standing in a linked worktree of a root, that path is the worktree and not the main checkout (buses-data OA-495, 28 September 2026: until then `--all` from `.claude\/worktrees\/<name>` stamped the main checkout and said only `cwd is inside the buses checkout`); from `stamp-docs`, which is in no root, that means every root, and it says so; `--root buses|portal|ops` names one instead, and `--checkout [DIR]` points one root at a checkout you name (a worktree, placed through git) and walks only that. None of these is an everyday step any more \u2014 the hook stamps every commit, in a worktree or not. `--staged` takes none of them: its subject is the repository enclosing the working directory, and a repository the policy does not name is a no-op that says so.\n\n## Markdown paragraphs\n\nThe house rule (`~\/.claude\/CLAUDE.md`) is that a newline in Markdown means a semantic break \u2014 end of paragraph, next heading, next list item, next table row \u2014 and never \"the line got long\". Hard wrapping is invisible to a reader but corrupts the diff: reflow one sentence and every following line in the paragraph is rewritten, so a one-word change reads as a rewritten section.\n\n`scripts\/reflow_md.py` unwraps prose that broke the rule. It is a **manual** tool \u2014 no hook runs it, and it has no default scope, so it only looks at the paths you name. Run it from `stamp-docs`, and `<path>` is the document or folder to unwrap.\n\n```bash\npython scripts\/reflow_md.py \"<path>\"              # dry run, the default\npython scripts\/reflow_md.py --apply \"<path>\"      # rewrite in place\npython scripts\/reflow_md.py --check \"<path>\"      # exit 1 if anything would change\n```\n\nRun from any folder; a `<path>` may be a file or a directory, and directories are walked for `*.md`. It skips `node_modules`, `.git`, `.venv`, `__pycache__`, `dist` and `build`, and honours the exclusions in `stamp-policy.json` so generated stage output is left alone \u2014 walking the Buses root drops from 141 candidate files to 97 because of that. A file named explicitly is always processed, exclusions or not.\n\nThree guards make it safe over documents you have not read, and all three exist because the tool got it wrong first:\n\n- **YAML frontmatter is passed through untouched.** An earlier version folded a memory file's `description:` line into `metadata:`, silently corrupting the frontmatter. It was caught by the second guard, on a real file, which is the only reason we know that guard works.\n- **A file is written only if the word sequence is identical before and after**, bare `>` blockquote markers excepted since folding a quote drops them. If a join would lose or reorder a word the file is left alone and the failure reported, and `--check` exits 1.\n- **Table rows are never joined** \u2014 `NEW_BLOCK` matches a leading `|`, and a line whose predecessor *ends* in `|` is not joinable either. This guard is load-bearing and its absence is invisible: an early pass collapsed the whole \"Where everything lives\" table in two `Buses\\Documentation\\` READMEs onto one line each, and because the word sequence was preserved the second guard saw nothing wrong. Neither had rendered as a table for weeks, and nobody noticed, because nothing in the workflow opens these files in a renderer. **The word-sequence guard checks that no text was lost; only this one checks that no structure was.** Repaired 2026-08-21.\n\nTwo things it does not do: it will not re-wrap (there is no way back), and it does not know a deliberate short line from a wrapped one below 60 characters \u2014 signatures, one-line answers and `Hello,` all survive because of that floor, but a genuinely short wrapped line would too.\n\n**Archived documents are out of scope**, as of 17 August 2026 \u2014 `_archive` is in the `excludeDirNames` of both the Buses and the portal root (the portal gained a `docs\/_archive` on 18 August 2026, and without the exclusion its three superseded docs would be re-stamped forever, a PR each). Neither tool touches superseded plans. Name such a file explicitly if you ever do want it reflowed.\n\n## Scope\n\n`stamp-policy.json` holds it \u2014 edit that, not the code. Three roots today: the Buses working folder (`.md` + `.pptx`), the `community-bus-maps` repo (`.md`), and the local-only ops notes (`.md`).\n\n**Exclusions come in two layers, and the top one is shared** (buses-data OA-235, 4 September 2026). `baselineExcludeDirNames` names the directories that are never a document in ANY repository \u2014 `.git`, `node_modules`, `worktrees`, `scratch`, `dist`, `coverage`, `build` \u2014 and every root inherits it; a root\u2019s own `excludeDirNames` now holds only what is local to it (`_latest` and `open-actions` in Buses, `data`, `staged`, `_archive` and `CHANGELOG.d` in the portal). Before that the three lists were maintained separately and had drifted to sharing only `.git`: `worktrees` was in ONE of them, so **60 of the 90 markdown files the portal root walked were inside `.claude\/worktrees\/`** \u2014 a second and third checkout of the same repository. The measured effect of adding the baseline was 185 in-scope documents down to 155, and all 30 that left were worktree copies, checked one by one rather than assumed.\n\n**The cost was never the wasted work \u2014 it is that a stamp is an EDIT.** Two sessions could not both run `--all`: on 3 September 2026 each bumped stamps on documents inside the other\u2019s worktree, neither having touched the other\u2019s files, and the standing rule then was *re-stamp a document you edited BEFORE you commit it*, so a stamp arriving from elsewhere was exactly what got swept into a commit describing something else.\n\n**Two kinds of reason live in that baseline** and it matters which when adding to it: `.git`, `node_modules`, `dist`, `coverage` and `build` are excluded because they are **not documents**; `worktrees` and `scratch` because they are **not ours to write to** \u2014 a worktree is full of real documents and the objection is ownership. A directory excluded for a reason peculiar to one repository stays on that root.\n\n**A worktree is placed through git, never by its name.** A linked worktree's `--git-common-dir` is the main checkout's `.git`, whose parent is what a root names, so `docstamp.py --staged` in the pre-commit hook stamps a worktree's commit with its root's exclusions whatever the directory is called \u2014 and since 21 September 2026 the audit places it the same way, through the same function (`root_cfg_for_repo()`). `--checkout` uses that resolution too, and **refuses** a directory it cannot place, because it writes; the audit, which only reads, audits an unplaced repository with no exclusions and says so on stderr. Both directions are proved in `prove_policy.py` and `prove_staged.py`, against a real `git worktree add` rather than a hand-written `.git` file, which `git rev-parse` rejects.\n\n**All three tools read the baseline through `scripts\/policy.py`, and that is deliberate.** A baseline each of them unioned for itself would be the same write-it-once-per-place fault one level down, with a worse failure mode \u2014 two agreeing and the third stamping what the others skip. `scripts\/prove_policy.py` asserts the four resolution rules and then asks all three readers for their resolved exclusions and insists they match, with a control that the comparison can notice a disagreement at all. Run it from `stamp-docs`; there are no placeholders:\n\n```bash\npython scripts\/prove_policy.py\n```\n\n**Never stamp generated output.** The stage pipeline already versions its own files by folder name (`S4-generate\/v1.3_2026-07-19_0517`) and stamps its reports in the body; the portal's rendered sheets sit under a byte-identical gate that stamping would break. The policy excludes `S[1-6]-*`, `_latest`, `node_modules`, `data\/`, and the dated `_gtfs` reports. Adding a root means adding exclusions for whatever it generates.\n\n**A generated report can also exclude ITSELF, and since 2026-08-28 that is the preferred way** (open action OA-096, now closed). Any markdown file whose first 40 lines contain `<!-- generated by ` is skipped, wherever it lives \u2014 `generatedMarker` in `stamp-policy.json`. This exists because the path-based rules only ever caught the generated files somebody remembered to name: `stand-coverage_2026-08-22.md` and `frame-coverage_2026-08-23.md` churned in every diff for weeks, the hook inserting a stamp and the next run of their generator deleting it, over a version number that described nothing. Naming those two would have fixed those two \u2014 nothing about writing a *third* generator reminds anybody that a policy file in another repository has to learn a new filename. **So when you write a script that emits a markdown report, have it print that marker as its second line.** The report is then excluded on the day it is written, by the person already thinking about it. It is read from the head only, and **only a line that *begins* with the marker counts** (since 2026-09-23, buses-data OA-446). Before that any line in the first 40 that merely CONTAINED it counted, so buses-data's `Development Docs\/README.md`, which quotes the marker in backticks while naming the two reports that carry it, was skipped by `--staged` as generated while the pre-commit audit, which skips nothing, refused the commit as stale. `prove_staged.py` case 5b holds it.\n\n## Committing a stamped document\n\n**Since 18 September 2026 there is nothing to run when you edit a stamped document**: the pre-commit hook stamps it as part of the commit (buses-data OA-397). A hand-run walk (`--all`, `--check`, `--list`) covers only the root you are standing in and prints which (buses-data OA-333); `--all-roots` asks for the estate-wide pass by name.\n\n## The stamp can be correct on disk and wrong in git \u2014 and the audit that catches it stays\n\n`--check` audits the **working tree**. A stamp written after a commit could therefore be right on disk and wrong in `HEAD`, and anyone reading the file out of the repository \u2014 a cold start, a clone, a PR review \u2014 would see a stamp that does not describe what they are reading, looking exactly as authoritative as a correct one. Found 2026-08-17: three of the 44 stamped `.md` in the Buses repo were stale in `HEAD`, one of them claiming *v1.12 \u00b7 9 August* over a body that had moved on.\n\nStamping at commit time closes that by construction, and the audit that used to catch it is **kept as the control that must never fire**: `check_committed_stamps.py --staged` still runs in the pre-commit hook after the stamper, and the CI step still hashes `HEAD`'s blobs. A green from either now says the mechanism worked; a red says something bypassed it. `scripts\/prove_staged.py` drives the whole thing through real hooks and real commits, and its mutation arm runs the same mid-turn edit through a hook that does not stamp and requires the audit to refuse it.\n\nTo audit what is actually committed, hash `HEAD`'s blobs rather than the files on disk:\n\n```bash\npython scripts\/check_committed_stamps.py            # every stamped .md in HEAD, per repo\n```\n\nRead it back rather than assuming: on 2026-08-25 the portal briefly went **3 STALE of 29** in `main` this exact way, and reads 32\/32 once the follow-up landed. The checker exits 1 on findings, and **it runs in CI**: the `status` job of `buses-data`'s `.github\/workflows\/gates.yml` runs it from its checkout of this repository \u2014 pinned to the engine commit in `engine.lock.json`, so a change to this script reaches that job when the pin next moves \u2014 over `buses-data` and `community-bus-maps`, naming those two roots explicitly. The third policy root, `community-bus-maps-ops`, is deliberately NOT passed \u2014 it is never pushed, a runner has no copy of it, and it holds the estate's one genuinely stale stamp, so judging it from CI would make the step red on day one for a reason nobody could fix. Proven both ways on 2026-08-27: exit 0 on the real corpus (Buses 82\/82, portal 32\/32 by explicit root), exit 1 on a scratch repository holding one deliberately wrong sha.\n\n### The 16 stale portal docs that were never stale\n\nThis file previously recorded, as known-outstanding, that *\"`community-bus-maps` has 16 of its 31 stamped `.md` stale in `HEAD`\"*, and guessed at squash-merges compounding over many PRs. **That was a bug in the audit tool, not in the stamps.** `check_committed_stamps.py` decoded `HEAD`'s blobs as `utf-8`, keeping the BOM; `docstamp.py`'s `read_text()` strips it before hashing. `str.strip()` does **not** treat `\ufeff` as whitespace, so the BOM stayed in the hashed body and every BOM-carrying file reported stale. The 16 \"stale\" files were exactly the repo's 16 BOM'd files; the 15 \"correct\" were exactly the 15 without.\n\nFixed 2026-08-18 by decoding `utf-8-sig`. Proof, on `docs\/DEPLOY.md` at `HEAD` \u2014 which the tool called stale minutes after its stamp was committed in PR #42:\n\n```\nBOM stripped (docstamp)  -> 80ce1414   stamp says 80ce1414   correct\nBOM kept (old audit)     -> c873552a   stamp says 80ce1414   \"stale\"\n```\n\nThe lesson is the expensive part: the tool reported a real-looking failure with per-file hashes attached, and the recommended fix was 16 version bumps pushed to a public repo. **A red audit is a claim about the tool as much as about the data** \u2014 reproduce one failing case by hand before acting on a batch.\n\nThe audit honours the policy's exclusions, so `_archive` and other out-of-scope trees are counted (`N out of policy scope`) rather than judged \u2014 **provided it can place the repository at a root**, which inside a linked worktree it could not until 21 September 2026 (see the last paragraph of this section).\n\n**`--staged` did not honour them until 2026-08-31, and the docstring said it did.** The exclusions were applied on the HEAD path and not on the index path, and nothing revealed it for two days because **the only way to reach the bug is to EDIT an archived document** \u2014 archiving has always been a pure `git mv`, which changes no content, so a stale stamp never arose there. Then a documentation round in `buses-data` repointed the links inside nine files it was archiving, and the pre-commit hook refused the commit over nine documents this stamper deliberately refuses to stamp. **An unsatisfiable refusal is worse than no check**: it names a fix that cannot be carried out, and the only way past it is `--no-verify`, which is a habit that does not come back. Both halves were proved after the fix \u2014 an in-scope document with a stale stamp is still refused, and an out-of-policy one is skipped.\n\n**And the same bug was one level out, in CI, where the fix above does not reach.** `gates.yml` audits by NAMED path \u2014 `check_committed_stamps.py \"$GITHUB_WORKSPACE\/buses-data\" \u2026` \u2014 and a named repo was documented as *audited without exclusions*, because the policy config travels with the policy ROOTS and a CI checkout is at a path no root has. So the local hook went quiet and CI went red about the same nine files, on the same push. Policy roots now carry **`checkoutDirNames`**: the names the same repository goes by when it is checked out elsewhere (`buses-data`, `community-bus-maps`). **A repo matching nothing is still audited with no exclusions and SAYS so**, on stderr, from both the HEAD path and `--staged`, because a silent filter is the worse of the two failures. Falsified in a throwaway repo with one stale `_archive\/` file and one stale `Documentation\/` file: named `buses-data` it reports 1 STALE and 1 out of policy scope, and renamed to anything else it reports 2 STALE and prints the warning.\n\n**And the placement itself was a second copy of the stamper's, which is how a worktree fell through it (21 September 2026).** The audit matched a repository by path and then by `checkoutDirNames`; a linked worktree has neither, so every commit made in one had its staged documents audited with no exclusions and no warning, while the stamper \u2014 placing through `--git-common-dir` \u2014 correctly left `_archive` alone. A merge in a `community-bus-maps` worktree was refused over `docs\/_archive\/GO-LIVE.md`. The audit now asks `docstamp.root_cfg_for_repo()`, so the two cannot place a tree differently. `prove_staged.py` case 9 commits a stale-stamped `_archive\/x.md` inside a linked worktree named nothing any list holds, with a stale in-scope control beside it; case 10 requires the no-match warning. Both went red against the old placement before the fix.\n\n## Gotchas\n\n- **Decks are git-ignored** (`*.pptx` in the Buses `.gitignore`), so git is no safety net and a git-status trigger would not see them at all. Copy them somewhere before a first stamp of a new deck, and verify afterwards that slide count, text blocks and media parts are unchanged.\n- **A stamped deck's exported PDF goes stale**, and there is no LibreOffice or pandoc on this machine to regenerate it. Re-exporting is manual in PowerPoint.\n- **`--backfill` dates from git**, not today, so a first stamp tells the truth about when the document last actually changed. **It only does this for documents with no stamp yet** \u2014 that restriction was missing until 2026-08-21, and a backfill run for one new README re-dated four documents edited the same morning to the day before, because an already-stamped file only reaches the stamping code when its content just changed and its git date is therefore the *previous* commit. If you are backfilling in a session where you have also edited stamped documents, `--check` afterwards will not catch it (the sha is still correct \u2014 only the date is wrong); read the visible dates.\n- **The stamp says a document changed; it cannot say the documents pointing AT it are still true.** Found 2026-08-22: `Development Docs\/open-actions.md` was deliberately cut from 400 lines to 81 on 2026-08-20, and five places still sent a reader there for narrative and section headings it no longer carried \u2014 three other Development Docs, `community-bus-maps\/CLAUDE.md`, and the project memory index. **Every one of those links still resolved**, so a link checker would have passed all five; only the content behind them had gone. When you cut content out of a document, grep the doc sets and both memory stores for its filename *and* for the headings you are removing, and repoint each hit. Where the content went to git history, name the commit SHA rather than \"the version before the tidy-up\" \u2014 open-actions.md now cites `546cd62` with the exact `git show` command and the folder to run it from. **A link checker over these doc sets now exists** \u2014 built 2026-08-27, and not here: it is `Documentation\/check-doc-links.mjs` in `buses-data`, run from that repository's root and wired into the `docs` job of its `gates.yml`. It covers three of the four classes: a dead path, a dead `#anchor`, and a `\u00a7n` the named target does not have \u2014 plus a link that climbs OUT of the repository, which resolves on the machine that wrote it and 404s for every other reader. It deliberately does NOT judge a citation by phrase, because there is no syntax to anchor that on; that residue is `open-actions` **OA-139**, and the mitigation stays the paragraph above this one. Its first run found **79** dead links, 77 of them from a document split made the same morning.\n- Existing metadata lines such as `**Last reviewed:** \u2026 **Against:** 0.8.1` mean something different (reviewed against a code version). Leave them; the stamp sits above and both coexist.\n\n","use_cases":["Check the current state of document versions and dates","Backfill newly added documents with initial version and date","Force a major version bump after a rewrite","Update document versions and dates automatically during commit","Unwrap hard-wrapped Markdown paragraphs"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/PeterC66\/claude-skills\/blob\/58dff47f900dba553ef0c05217b9276f77cb3b66\/stamp-docs\/SKILL.md","source_commit":"58dff47f900dba553ef0c05217b9276f77cb3b66","license":null,"version":null,"listing_approved_at":"2026-11-30","created_at":"2026-11-29T11:15:29.000000Z","updated_at":"2026-11-30T06:52:46.000000Z","seo_title":"Automate Document Versioning and Stamping","seo_description":"Automatically keep Markdown and PowerPoint documents up to date with version numbers and last-updated dates during commit. Use the skill to audit, backfill, or force a re","seo_keywords":["document versioning","auto-stamp documents","markdown versioning","powerpoint versioning","pre-commit hook","document formatting","version bump","document audit"]}}