Skip to content

fix(frontmatter): do not add a header over one the writer cannot locate - #988

Merged
runkids merged 1 commit into
mainfrom
runkids/target-writer-foreign-header
Nov 23, 2026
Merged

runkids merged 1 commit into
mainfrom
runkids/target-writer-foreign-header

Conversation

@runkids

@runkids runkids commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

Linked Issue

No issue. Found while reviewing #973.

What was wrong

Readers accept frontmatter that the writers cannot locate:

  • a block whose closing --- is missing;
  • a block whose --- lines are indented;
  • a block below other text, such as a title line.

Three writers treated such a file as having no frontmatter and put a new header on top. Every reader then used the new header and ignored the old one, so the skill lost its description and every other field without any warning.

Setting a target in the dashboard on this SKILL.md:

---
name: demo
description: keeps its fields

# Body

returned 200 and wrote:

---
metadata:
  targets:
    - claude
---
---
name: demo
description: keeps its fields

# Body

After that the dashboard listed the skill with no description.

Fix

  • Dashboard target edits (RewriteFrontmatterList): the file is left unchanged and the request returns 422 target_frontmatter. The message names the layout to fix.
  • Manual-only toggle in the list TUI (ToggleFrontmatterFlag, the m key): the file is left unchanged and the TUI shows the reason.
  • Dashboard editor: saving a body-only edit of a file with no header the editor can parse wrapped the text in an empty header. It now saves the text as written.

Both Go writers share one check, hidesHeader. It refuses when the writer saw an opening --- that never closes, or when the block the readers locate decodes to a non-empty YAML mapping.

Behavior changes

  • A target edit or m toggle on a file with one of the three layouts above is refused. On main it reported success.
  • A target edit that asks for what the readers already see is a no-op for these files too. On main only clearing targets that no reader saw was.
  • Unchanged: a file with no frontmatter still gets a new header, including one whose body has --- horizontal rules around prose.

Tests

  • internal/utils:
    • TestRewriteTargetsRefusesUnclosedHeader fails on main. Its header is unclosed and is not valid YAML.
    • TestFrontmatterEntryPoints_DelimiterRules: the four rows for indented, misplaced and unclosed delimiters pinned the second header. They now expect the refusal.
    • TestToggleFrontmatterFlag_RefusesHeaderItCannotLocate fails on main.
    • TestRewriteTargetsLeavesNoOpUntouched has two new rows. The one with a header below other text fails on main. The one that clears an unclosed header passes on main and guards that case against the new refusal.
    • TestRewriteTargetsAddsHeaderAboveHorizontalRules passes on main too. It guards a file with horizontal rules against the new refusal.
  • ui/src/lib/frontmatter.test.ts: a body-only save of a file with an unclosed header returns the text as written.

Checks

  • make check passes in the devcontainer image on this commit.

  • Dashboard: format:check, typecheck, lint:typed (0 errors) and the full Vitest run (121 files, 1017 tests) pass. They ran before the rebase onto refactor(skillignore): replace the memoized negation search with a loop #984–fix(agents): list agents in .agentignore'd folders as disabled #987, which do not touch ui/.

  • python3 scripts/ai-context.py check passes.

  • End to end with skillshare ui -g and PATCH /api/resources/<name>/targets, comparing a binary built from main at 115b50a with this branch:

    SKILL.md main This branch
    unclosed header 200, second header, description lost 422, file unchanged
    indented --- lines 200, second header, description lost 422, file unchanged
    header below a title 200, second header, description lost 422, file unchanged
    no header, horizontal rules in the body 200, new header 200, new header
    ordinary header 200, targets added 200, targets added

Not run:

  • The website build. The docs change is one sentence in two existing paragraphs and their four translations.
  • The TUI m key and the editor save were not driven by hand. The unit tests above cover the functions they call.

Not covered

  • SetFrontmatterValue still adds a header. Its one caller rewrites the name in a fresh copy inside a target during sync, and an error there fails the whole sync. It never edits the source file. A comment in the code says so.
  • Editing the form in the dashboard editor on a file with no header it can parse still writes a new header above the text. The user is writing that header, and the save confirmation shows the diff.
  • A file that starts with --- as a horizontal rule and has no second --- is refused. Readers already treat all of it as frontmatter.
  • A key: value block between two --- rules below other text is refused. Readers treat it as frontmatter.
  • A header below other text, or with indented --- lines, whose block is also not valid YAML still gets a second header. It needs two malformed traits at once, and a wider check would refuse ordinary agent files that use horizontal rules.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it — written with an AI coding tool in the maintainer's session
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

Readers accept frontmatter the writers cannot locate: an unclosed block,
indented --- lines, or a block below other text. The dashboard target
writer and the list TUI's manual-only toggle treated such a file as having
no frontmatter and put a new header on top. Every reader then saw only the
new header, so the skill lost its name, description and every other field
without any warning.

Both writers now refuse and leave the file unchanged, and say which layout
to fix. A file with no frontmatter at all, including one that only has
horizontal rules in its body, still gets a new header. A target edit that
asks for what the readers already see stays a no-op.

The dashboard editor did the same on a body-only save: it wrapped the text
in an empty header. It now saves the text as written until the form is
edited.

SetFrontmatterValue keeps adding a header. Its one caller renames a fresh
copy inside a target during sync, and an error there fails the whole sync.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:14:48.639328Z b61c3cb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@runkids
runkids merged commit 4d151e3 into main Nov 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant