Repository navigation
fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM - #505
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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.
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
|
||
| 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/, ''); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
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).
Type
proposals/only — see CONTRIBUTING.md)Linked Issue
Follow-up found while testing #497 (prefixed naming); no issue filed.
A
SKILL.mdthat starts with a UTF-8 BOM (Notepad and other Windows editors write one) is silently skipped undertarget_naming: standardandprefixed.utils.ParseSkillNameand 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
internal/utilsreaders (ParseSkillName,ParseFrontmatterField/Fields/List,ReadSkillBody)TestFrontmatterEntryPoints_DelimiterRules/BOMSetFrontmatterValue(prefixed copy)namevalue; BOM + no frontmatter gets the new block after the BOMTestSetFrontmatterValue(two BOM rows)ToggleFrontmatterFlag,RewriteFrontmatterListRewriteFrontmatterListpreviously duplicated the frontmatter on a BOM file.TestToggleFrontmatterFlagBOM row; entrypointsBOMandBOM without frontmatterutilsthat split lines themselves:hub(description, tags),search(remote SKILL.md),audit(metadata analyzer),sync/contextutils.TrimBOMTestBuildIndex_BOMFrontmatter,TestParseFrontmatterField_BOM,TestParseFrontmatterNameDescBOM row,TestCalcSkillContext_BOMaudit(ScanContent, skill scan,ScanMarkdownContentWithRules)hidden-unicode; one past the start still is. Docs + 4 translations updatedTestScanContent_LeadingBOMIsNotHiddenparseSkillMarkdown(ui/src/lib/frontmatter.ts)frontmatter.test.ts"skips a leading BOM"standardandprefixedTestResolveTargetSkillsForTarget_BOMFrontmatterNot changed:
internal/version/skill.go(reads skillshare's own built-in skill) andinternal/memory/store.go(memory notes, not SKILL.md).internal/skillservealready 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-namingpairing, skipped-skill listing, diff rows).Checklist
make check) — for code changesChecks run
make checkin the devcontainer: passed (gofmt, vet, unit and integration tests).BOM without frontmatterand fallback-scanner tests were re-verified red by temporarily reverting their fixes./simplifyon the change: addedutils.TrimBOM/SplitBOMand replaced five inline""trims and two hand-rolled BOM splits with them; dropped theskipBOMpolicy field (every policy set it); skipped thestring(utf8BOM)micro-allocation as negligible.code-review(Standards and Spec axes, fixed pointorigin/main): Standards had no violations. Spec found two real issues, both fixed with tests:RewriteFrontmatterListwrote a second BOM mid-file when a BOM file had no frontmatter, and thesearchfallback line scanner still missed the BOM.internal/,cmd/andui/src(frontmatter,---scanners,yaml.Unmarshalon 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 onlyname, a second sync anddiffshow no churn, andauditis clean./simplifyagain on the second commit: nothing to change. Its altitude pass foundScanMarkdownContentWithRulesstill missed the BOM; fixed with a test.Notes for reviewers
frontmatterPolicy(the frontmatter: readers in internal/utils locate the delimiters under five different rules #449 inconsistency). Each now callsTrimBOM; a new reader has to remember to as well.ScanMarkdownDataflowandDetectCommandTiersInMarkdownhave 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.