frontmatter-guard
它能做什么
这项技能检查每个知识库页面顶部隐藏的头部区域是否有错误。在你批准预览之后,它可以自动修复常见错误。
适用场景
- ✓当知识库页面无法同步,或搜索结果显示为乱码时。
- ✓当你想在大型导入之前检查所有页面的头部错误时。
- ✓当页面缺少结束行、存在嵌套引号,或标题与文件名不一致时。
技能链接
https://github.com/garrytan/gbrain/blob/master/plugin/skills/frontmatter-guard/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我所有知识库页面的头部信息是否损坏,并在应用任何修复之前先给我看预览。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会按一套标准检查逐页扫描。它会解释每个问题,然后先做备份,只有在你批准预览后才会应用修复。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Frontmatter Guard Skill
Convention: see
skills/conventions/quality.mdfor citation rules; this skill is structural validation, not citation auditing.
Contract
This skill guarantees:
- Every brain page is scanned against the eight canonical frontmatter validation classes
- Mechanical errors (nested quotes, missing closing
---, null bytes, slug mismatch) are auto-repairable on demand with.bakbackups - Validation logic is shared with
gbrain doctor'sfrontmatter_integritysubcheck — single source of truth - Reports per source (gbrain is multi-source since v0.18.0); never silently audits the wrong root
- Files sync holds are explained from their hold record (code, reason, key, line, fix) and fixed only through a previewed, hash-bound repair the user approved
Why This Exists
Brain pages pile up over months. Agents write them with malformed frontmatter:
- Missing closing
---(entity detector bugs) - Unstructured YAML in meeting pages (ingestion bugs)
- Slug mismatches (path renames not propagated)
- Null bytes (binary corruption from copy-paste accidents)
- Nested double quotes in titles (
title: "Alice "Ace" Example")
Without a guard, these accumulate silently until gbrain sync chokes or search returns garbage. The guard makes the failure visible at audit time and trivially fixable.
Write brain files safely (do this first)
Write pages through
put_page/capture(MCP orgbrain put). gbrain serializes frontmatter itself, so the file on disk is always valid YAML.A script or agent that writes Markdown files directly must build frontmatter with a YAML serializer (
yaml.dump, js-yamldump), never by string interpolation.title: ${title}breaks as soon as a title contains:,#, quotes or a newline.Check generated content before writing it, without touching disk:
printf '%s' "$content" | gbrain frontmatter validate --stdin --path notes/2026-10-04-digest.mdExit 1 means fix it first. The default is the strict producer rule: YAML gbrain could still import by quoting a value fails too, because other tools reject it.
--importableanswers the narrower question "would sync hold it?".Never write a key gbrain reads for access or identity (
visibility,derived_from,slug,type,id,source_id) from untrusted text.
Held files: read them, then fix them
A file sync cannot import without guessing is held: the rest of the source still syncs, a new file has no page yet, and an existing page keeps its last good revision and refuses put_page until the file is repaired (do not retry the write). Where holds show up: sync output (Held <path>: <code> … Next: <command>), gbrain sources status <id> (--json: git_holds.items[]), doctor git_held_files, get_page file_held, and search hits marked stale.
Each hold record carries code, reason, key, line, message (location only, never the value), fix (exact argv) and docs. Act on reason:
| Hold | What to do |
|---|---|
invalid_frontmatter / yaml_parse |
Preview gbrain repair frontmatter --source <id>; usually needs_review with the exact line to fix by hand. |
invalid_frontmatter / needs_interpretation |
Preview with --include-ambiguous, show the user each per-file diff, apply only what they approve. |
invalid_frontmatter / ambiguous_identity_key or ambiguous_protected_key; visibility_noncanonical |
Never guess. Show the user the line; they decide the one value (visibility decides who can read the page; page privacy reads only visibility: private, lowercase on its own line). |
frontmatter_slug_conflict |
Remove the slug: line or move the file; the repair proposes removing it under --include-ambiguous. |
file_too_large |
The file is over the fixed page limit (24 MiB for Markdown, 5 MB for code); every page under it is searchable, so never split one that fits. Ask the user to add it to sync.exclude, or to split it into files under the limit. A smaller page an MCP transport refused goes by file instead (docs/guides/memory-boundaries.md#large-page-limits). |
content_rejected |
The user chose content_sanity.junk_disposition=reject; ask before changing it. |
The fix flow (walkthrough with real output: docs/guides/repair.md#held-files):
gbrain sources status <id> # what is held and why
gbrain repair frontmatter --source <id> # pass 1: safe quotin
常见问题
它会不经询问就修改我的页面吗?
不会。修复会先以预览形式展示,并且会保留备份。
它能发现哪些类型的错误?
包括缺少结束行、嵌套引号、名称不匹配、空的头部,以及损坏的字符。
为什么同步会跳过某些文件?
技能会根据记录解释每个被暂停的原因,并且只通过经过批准的修复来处理。
详情
作者的原始描述
Validate and auto-repair YAML frontmatter on brain pages. Catches malformed pages before they enter the brain (missing closing ---, nested quotes, slug mismatches, null bytes, empty frontmatter, YAML parse failures), explains files sync holds instead of importing, and drives the previewed `gbrain repair frontmatter` fix. Wraps the `gbrain frontmatter` CLI for agent-driven workflows.
repo: garrytan/gbrain
热度
- GitHub 星标
- 31k
- 排名
- #9302
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …