Commit Graph
10 Commits
Author SHA1 Message Date
Willie 9c994faa17 fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM (#505)
* fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM

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.

* fix(frontmatter): cover the dashboard parser and stop auditing a leading 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.

* fix(ui): keep the BOM when the skill editor saves a SKILL.md

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.
2026-10-09 23:58:56 +08:00
Willie 4c433281a8 fix(sync): add a missing name before the first frontmatter key
Appending an inherited (merge-key) name at the end of the frontmatter
kept running into what may follow the mapping: a "..." end marker,
comments after it at any indent. Its indent also came from the first
key node's column, which sits after "? " for an explicit key. Insert
the key before the first key instead, with that line's own indent; an
explicit key overrides a merged one wherever it stands.
2026-10-09 12:52:41 +08:00
Willie 666df43edd fix(sync): rewrite only the name value, keeping its key as written
Rewriting the whole name line dropped whatever sat on the key side: an
anchor on the key (&f name:) left its aliases undefined, and quoting,
"name :" spacing or an explicit "? name" key were rewritten. Keep the
text before the value as written, located from the YAML node, and
replace only the value span, keeping the value's own anchor.
2026-10-09 12:44:24 +08:00
Willie 183beeba54 fix(sync): keep the name's YAML anchor when prefixing it
A name that defines an anchor (name: &n prototype) lost it on rewrite
while aliases to it (description: *n) stayed, so the copied frontmatter
had an undefined alias. Keep the anchor on the new value, in both the
line rewrite and the flow-mapping rewrite.
2026-10-09 12:37:04 +08:00
Willie 967e1fad07 fix(sync): find a document end marker followed by a comment
Only a bare "..." was taken for the end marker, so "... # end" (or
comment lines after the marker) still got the inherited prefixed name
appended outside the mapping. Accept a trailing comment on the marker
and skip comment lines while looking for it.
2026-10-09 12:31:18 +08:00
Willie 5cf18e2723 fix(sync): add the prefixed name before a YAML document end marker
When the name is inherited (a merge key) and the frontmatter ends with
"...", the new name: was appended after the marker, outside the
mapping, so the copy kept the old name or held an invalid second
document. Insert the key before the marker.
2026-10-09 12:16:54 +08:00
Willie adf375d3e2 fix(sync): keep the indent of an indented root mapping when renaming
ParseSkillName accepts frontmatter whose root mapping is indented as a
whole, but SetFrontmatterValue wrote name: at column zero beside the
indented keys, so a prefixed copy got malformed YAML. Write the key at
the column the mapping's keys use.
2026-10-09 11:56:12 +08:00
Willie 84cccb0d2f fix(sync): rewrite the name inside flow-style frontmatter
Keys of a flow mapping share one line, so the span-based rewrite added a
second name: beside {name: ...}, or dropped the whole line and the
fields before name when it came last. Write a flow mapping back whole
with the new value instead.
2026-10-09 10:46:00 +08:00
Willie 330b34510e fix(sync): replace the whole name entry when prefixing a copied skill
The prefixed rename matched "name:" line by line, while resolution parses
the frontmatter as YAML. A quoted key, "name :" or a multi-line scalar
was accepted upstream but left a duplicate key or orphaned continuation
lines in the copy. Locate the key through YAML and replace its full span.
2026-10-09 09:56:12 +08:00
Willie a9c3189ce3 feat(utils): add a line-based frontmatter string setter
Prefixed target naming has to rewrite name: in each copied SKILL.md.
ToggleFrontmatterFlag only adds or removes a boolean, so SetFrontmatterValue
sets a plain scalar the same way: one line edited, key order, comments,
CRLF and the body untouched. Both now share the delimiter scan.
2026-10-09 00:44:47 +08:00