feat: improve index-append.py frontmatter self-healing

This commit is contained in:
Matteo Cherubini 2026-06-05 10:37:09 +02:00
parent 9a81bb2d6f
commit ddf34944e0
2 changed files with 29 additions and 1 deletions

View file

@ -41,18 +41,26 @@ def main() -> int:
# 1. Bump last_updated inside the first frontmatter block
fm_open = False
fm_close_idx = None
bumped = False
for i, ln in enumerate(lines):
if ln.strip() == "---":
if not fm_open:
fm_open = True
continue
break # end of frontmatter
fm_close_idx = i # the closing ---
break
if fm_open and ln.startswith("last_updated:"):
lines[i] = f"last_updated: {today}"
bumped = True
if not fm_open:
print("index-append: warning: no frontmatter found, last_updated not bumped",
file=sys.stderr)
elif not bumped and fm_close_idx is not None:
# self-heal: frontmatter present but missing the key — insert it before the close
lines.insert(fm_close_idx, f"last_updated: {today}")
print("index-append: last_updated key was missing — inserted", file=sys.stderr)
# 2. Locate the target section [start, end)
start = None

View file

@ -66,3 +66,23 @@ load helpers
[ "$status" -ne 0 ]
[ -z "$output" ] || [[ "$output" != *"feat/ai-ingest-"* ]]
}
@test "index-append: self-heals a frontmatter missing last_updated" {
G="$(make_fixture_genome)"; cd "$G"
cat > wiki/index.md <<'EOF'
---
title: "Index"
type: index
domain: genome-test
maturity: stable
private: false
---
# Index
## Sources (`wiki/sources/`)
*x*
EOF
python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/foo]] — s. `maturity: draft`'
grep -q "^last_updated: $(date +%F)$" wiki/index.md
}