The editor's strip regex anchored on \\A — a Python-ism JS treats as a literal — so it never matched: the editor showed the raw frontmatter and every save re-wrapped the file in one more frontmatter layer. Extract the strip into lib/skillFrontmatter.ts with a ^ anchor, import it from the page, and guard it with scripts/check-skill-frontmatter.mjs (wired into npm test): strips the render_skill_md block shape, exact split boundary, idempotent, save-reload round-trip adds no layer, and the inline \\A pattern is banned statically. Also per review notes: skill toggles are now the spec-v2 §5 34x19 capsule (amber track + dark knob when on), and version-history timestamps render localized instead of the raw SQLite UTC string. Co-authored-by: multica-agent <github@multica.ai>
16 lines
588 B
TypeScript
16 lines
588 B
TypeScript
/**
|
|
* Strip a SKILL.md YAML frontmatter block, leaving only the body the
|
|
* skill editor edits.
|
|
*
|
|
* The block is `---` … `---` at the START of the file. The anchor is `^`
|
|
* (string start) — `\A` is a Python-ism that JS silently treats as a
|
|
* literal, which made the strip a no-op and let every save re-wrap the
|
|
* whole file in a new frontmatter layer (HEL-613 rework).
|
|
*/
|
|
const FRONTMATTER_RE = /^---\s*\n[\s\S]*?\n---\s*\n?/;
|
|
|
|
export function stripSkillFrontmatter(text: string): string {
|
|
const m = text.match(FRONTMATTER_RE);
|
|
return m ? text.slice(m[0].length) : text;
|
|
}
|