Skip to content

fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM - #505

Merged
runkids merged 3 commits into
mainfrom
runkids/skill-md-bom
Oct 9, 2026
Merged

runkids merged 3 commits into
mainfrom
runkids/skill-md-bom

Conversation

@runkids

@runkids runkids commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)

Linked Issue

Follow-up found while testing #497 (prefixed naming); no issue filed.

A SKILL.md that starts with a UTF-8 BOM (Notepad and other Windows editors write one) is silently skipped under target_naming: standard and prefixed. utils.ParseSkillName and the other lenient readers do not see the leading ---, so the skill has no readable name. The prefixed copy rewrite (SetFrontmatterValue) also prepended a second frontmatter block to such a file.

What changed

Area Change Covering test
internal/utils readers (ParseSkillName, ParseFrontmatterField/Fields/List, ReadSkillBody) The shared locator and the line scanner skip a leading BOM TestFrontmatterEntryPoints_DelimiterRules/BOM
SetFrontmatterValue (prefixed copy) Keeps the BOM, rewrites only the name value; BOM + no frontmatter gets the new block after the BOM TestSetFrontmatterValue (two BOM rows)
ToggleFrontmatterFlag, RewriteFrontmatterList Same BOM handling, since they share the splitter. RewriteFrontmatterList previously duplicated the frontmatter on a BOM file. TestToggleFrontmatterFlag BOM row; entrypoints BOM and BOM without frontmatter
Readers outside utils that split lines themselves: hub (description, tags), search (remote SKILL.md), audit (metadata analyzer), sync/context utils.TrimBOM TestBuildIndex_BOMFrontmatter, TestParseFrontmatterField_BOM, TestParseFrontmatterNameDesc BOM row, TestCalcSkillContext_BOM
audit (ScanContent, skill scan, ScanMarkdownContentWithRules) A BOM at the very start of a file is no longer reported as HIGH hidden-unicode; one past the start still is. Docs + 4 translations updated TestScanContent_LeadingBOMIsNotHidden
Dashboard parseSkillMarkdown (ui/src/lib/frontmatter.ts) Skips a leading BOM, so the viewer and skill editor see the frontmatter frontmatter.test.ts "skips a leading BOM"
Sync end to end A BOM skill resolves under standard and prefixed TestResolveTargetSkillsForTarget_BOMFrontmatter

Not changed: internal/version/skill.go (reads skillshare's own built-in skill) and internal/memory/store.go (memory notes, not SKILL.md). internal/skillserve already handled BOM.

No website or wiki page describes BOM handling, so no docs changed.

Not touched here: #503 (status/doctor/target list warnings, collision output) and #504 (--mode/--target-naming pairing, skipped-skill listing, diff rows).

Checklist

  • I've read CONTRIBUTING.md
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

Checks run

  • make check in the devcontainer: passed (gofmt, vet, unit and integration tests).
  • Failing-first: each new test row was run red before its fix. The BOM without frontmatter and fallback-scanner tests were re-verified red by temporarily reverting their fixes.
  • /simplify on the change: added utils.TrimBOM/SplitBOM and replaced five inline "" trims and two hand-rolled BOM splits with them; dropped the skipBOM policy field (every policy set it); skipped the string(utf8BOM) micro-allocation as negligible.
  • code-review (Standards and Spec axes, fixed point origin/main): Standards had no violations. Spec found two real issues, both fixed with tests: RewriteFrontmatterList wrote a second BOM mid-file when a BOM file had no frontmatter, and the search fallback line scanner still missed the BOM.
  • Consumer sweep: grepped every reader of SKILL.md content in internal/, cmd/ and ui/src (frontmatter, --- scanners, yaml.Unmarshal on skill text). Ran in the container, global and -p, copy and merge, standard and prefixed, sync --dry-run, sync --json, status, diff, list, audit, analyze, install <local dir>: BOM skills are discovered, the prefixed copy keeps BOM and CRLF and rewrites only name, a second sync and diff show no churn, and audit is clean.
  • /simplify again on the second commit: nothing to change. Its altitude pass found ScanMarkdownContentWithRules still missed the BOM; fixed with a test.
  • Not run: the Windows UTM runbook; a real Notepad-written file was not tried.

Notes for reviewers

  • Follow-up, deliberately not done: the hub, search, audit and sync/context readers still split lines on their own instead of using frontmatterPolicy (the frontmatter: readers in internal/utils locate the delimiters under five different rules #449 inconsistency). Each now calls TrimBOM; a new reader has to remember to as well.
  • The dashboard skill editor writes the file back without the BOM (a BOM-less file is valid); the Go writers keep it.
  • Not fixed: ScanMarkdownDataflow and DetectCommandTiersInMarkdown have no production callers and were left alone. A BOM that is not the first bytes of the file (for example after leading blank lines) is not treated as a BOM. No editor produces that.

Windows editors such as Notepad write a BOM before the opening ---. The
lenient readers (ParseSkillName, ParseFrontmatterField/Fields/List, ReadSkillBody)
did not skip it, so under target_naming standard/prefixed the skill had no
readable name and was silently skipped. Strip the BOM in the shared frontmatter
locator and the line scanner, and in the hub, search, audit and sync/context
readers that split lines themselves (utils.TrimBOM).

The writers kept working on the unstripped text, so SetFrontmatterValue
prepended a second block and ToggleFrontmatterFlag/RewriteFrontmatterList
could leave a BOM in the middle of the file. They now split the BOM off and
put it back in front, rewriting only the name value (or flag/list) as before.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T15:52:39.801412Z 72e188c Manual request
ℹ️ 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.

…ing BOM

A consumer sweep after the first BOM commit found two more places that
mishandled a SKILL.md written by Notepad:

- audit reported the leading BOM as a HIGH hidden-unicode finding (U+FEFF is
  in the zero-width rule), so every such skill showed a risk score. A BOM at
  the very start of a file is its encoding mark and hides nothing; one past
  the start is still reported.
- the dashboard's parseSkillMarkdown saw no frontmatter, so the skill editor
  would treat the whole file as body and write a second block on save.

The audit-engine page and its four translations note the exemption.
@runkids

runkids commented Oct 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a7b47adf5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ui/src/lib/frontmatter.ts Outdated

export function parseSkillMarkdown(content: string): ParsedSkillMarkdown {
// Windows editors write a BOM before the opening fence; the Go readers skip it too.
content = content.replace(/^\uFEFF/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the BOM when recomposing dashboard edits

When a BOM-prefixed SKILL.md is edited in the dashboard, this permanently discards the marker: SkillEditor passes the parsed body and rawFrontmatter to composeSkillMarkdown, but neither retains the removed BOM, so the subsequent PUT overwrites the file without it. This creates an unrelated encoding change on every dashboard edit and contradicts the preservation behavior added to the Go rewrite paths; retain the marker in the parsed result and prepend it during composition.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 72e188c. The finding holds: SkillEditor saved the composed text without the marker. parseSkillMarkdown now returns bom and composeSkillMarkdown takes it as a fifth argument, which SkillEditor passes from the initial parse. Covered by puts the BOM back when composing in ui/src/lib/frontmatter.test.ts (red before the fix, 645 UI tests green; make check green).

parseSkillMarkdown dropped the BOM so the editor could see the frontmatter,
but SkillEditor writes the composed text back through PUT .../content, so every
dashboard edit silently removed the marker from a Notepad-written file. The
parse result now carries the BOM and composeSkillMarkdown puts it back in front,
matching the Go rewrite paths.
@runkids

runkids commented Oct 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 72e188cfd2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@runkids
runkids merged commit 9c994fa into main Oct 9, 2026
8 checks passed
@runkids
runkids deleted the runkids/skill-md-bom branch October 9, 2026 15:59
runkids added a commit that referenced this pull request Oct 9, 2026
Main gained the kept-legacy diff rows (#504), the manifestSymlink constant and prefixed-naming warnings (#503), and the BOM-tolerant frontmatter reader (#505). The diff stream checks the kept legacy entry before the copy-mode copy, since sync leaves a folder on a name held for a kept legacy entry alone; the docs keep both new rows.
runkids added a commit that referenced this pull request Oct 9, 2026
The generated entry listed every commit, including about thirty fixes to
target_naming: prefixed made before it was ever released, a test commit
and an internal helper. Group what users will notice: the prefixed naming
feature, the shared-folder conflict notices, and the fixes to released
behavior (#498, #505, #506, #508, combined --mode/--target-naming).
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