Custom Output Templates
Every knowledge package is rendered from a package template in your knowledge workspace, by default src/package-templates/kb/. The template supplies the package entry page, the query Skill and any instructions for Agents; the build renders it and adds the selected approved pages. The generated default is a usable generic starting point. Customize it when your package needs project terminology, curated navigation, routing rules or task-specific Skills, for example:
Rename the query Skill to
android-queryand group the entry page by module.
flowchart LR
tpl["src/package-templates/kb/"] --> render["Render with Handlebars"]
vars["Built-in and custom variables"] --> render
render --> out["dist/name/"]
approved["Selected approved pages"] --> out
out --> check["Path, link and<br/>honesty checks"]Accept or edit before the first build
A newly generated template must be accepted as is or edited before the first build. The Agent asks you to confirm: accept the generic default, or edit files under src/package-templates/ (yourself or by asking the Agent). Context records which template files you accepted; it does not judge the template's prose.
What the template contains
src/package-templates/
├── kb/
│ ├── AGENTS.md
│ ├── wikis/
│ │ └── index.md
│ ├── others/
│ │ └── context/
│ │ └── search-guide.md
│ └── skills/
│ └── context-knowledge-query/
│ ├── SKILL.md
│ └── scripts/
│ └── search.mjs
└── llms/
└── llms.txtA knowledge package template must contain at least one SKILL.md and wikis/index.md; a template with only AGENTS.md is rejected. Each rendered Skill lives at skills/<skill-name>/SKILL.md with a matching name in its front matter; Context never derives Skill names from the package name. Add another Skill only when you want behavior beyond knowledge lookup.
The entry page and navigation
wikis/index.md is the package's entry page. Tell readers what the package covers, who it is for and how to query it. Every selected root — wikis/, guides/, rules/, feats/ — always gets an index. By default, small directories fold into their nearest generated ancestor index, and a directory gets its own index.md only when it would expose more than 50 entries to its parent; you can ask for one index per directory or a different threshold.
For curated navigation, loop over the built-in variables in wikis/index.md:
| Variable | Gives you |
|---|---|
{{displayName}}, {{packageName}} | Package display name and name |
{{knowledgeCount}}, {{knowledgeTimestamp}} | Number of selected pages and the latest timestamp |
{{knowledgeItems}} | Selected page metadata for loops |
{{knowledgeGroups}} | Pages grouped by root and first directory |
{{knowledgeTreeNodes}}, {{knowledgeTree}} | Nested tree, or its Markdown preview |
{{wikisRoot}} … {{featsRoot}} | Package-relative root paths, for links inside Skills |
The complete list, with loops, conditionals and helpers, is in Template Variables. Your own values can be passed to the template as custom variables.
The query Skill
The default context-knowledge-query Skill carries the structure-first query discipline and a search fallback, and it is the same in every Context package so one installed copy can serve them all. Context manages it: context build replaces a template copy that is older or edited, so changes made inside it do not survive.
Tune search for your package in others/context/search-guide.md instead: project terminology and synonyms, common questions and the preferred entry page for each kind of task. The Skill reads this guide before it searches. A package that needs its own query Skill adds it under a different directory and name, so it installs beside the shared one.
Workspaces created with the earlier skills/knowledge-query/ template are migrated on the next build: Context replaces it with context-knowledge-query in the same language, adds the search guide when it is missing and reports the replacement. Move any package-specific wording the old Skill carried into the search guide.
Rules the build enforces
- No second knowledge source. Template prose that describes coverage, scope, known gaps or limits must be backed by approved knowledge, the package inventory or rendered structure data; otherwise the build reports it. Facts belong in approved pages.
- No collisions. Template files are rendered first; a rendered path may not land on a selected page or a generated index. Rename the template file or exclude that page from the package.
- Valid links. Links in every root index and generated child index must resolve inside the package; broken ones are reported.
- Fix at the source. Repair the template, the approved page or the package declaration and rebuild; never patch
dist/.
These checks cover structure, not whether the selected knowledge is meaningful for your readers — look through the output yourself. The template API is in Package Templates.
定制输出模板
每个知识包都由你的知识工作区中的一个知识包模板渲染而成,默认位于 src/package-templates/kb/。模板提供知识包的入口页、查询 Skill 以及给 Agent 的各种说明;构建会渲染模板并加入选中的已批准页面。生成的默认模板是一个可用的通用起点。当你的知识包需要项目术语、精选导航、路由规则或面向特定任务的 Skill 时,再对它进行定制,例如:
把查询 Skill 重命名为
android-query,并让入口页按模块分组。
flowchart LR
tpl["src/package-templates/kb/"] --> render["用 Handlebars 渲染"]
vars["内置变量和自定义变量"] --> render
render --> out["dist/name/"]
approved["选中的已批准页面"] --> out
out --> check["路径、链接和<br/>如实性检查"]首次构建前接受或修改
新生成的模板必须先原样接受或进行修改,才能进行首次构建。Agent 会请你确认:接受通用默认模板,或修改 src/package-templates/ 下的文件(你自己修改,或请 Agent 修改)。Context 会记录你接受了哪些模板文件;它不会评判模板的文字内容。
模板包含什么
src/package-templates/
├── kb/
│ ├── AGENTS.md
│ ├── wikis/
│ │ └── index.md
│ ├── others/
│ │ └── context/
│ │ └── search-guide.md
│ └── skills/
│ └── context-knowledge-query/
│ ├── SKILL.md
│ └── scripts/
│ └── search.mjs
└── llms/
└── llms.txt知识包模板至少必须包含一个 SKILL.md 和 wikis/index.md;只有 AGENTS.md 的模板会被拒绝。每个渲染出的 Skill 都位于 skills/<skill-name>/SKILL.md,且 frontmatter 中的 name 与之匹配;Context 绝不会根据知识包名称推导 Skill 名称。只有当你需要知识查找之外的行为时,才添加其他 Skill。
入口页与导航
wikis/index.md 是知识包的入口页。请告诉读者这个知识包覆盖什么、面向谁,以及如何查询它。每个选中的根目录(wikis/、guides/、rules/、feats/)始终都会有一个索引。默认情况下,小目录会折叠到最近的已生成上级索引中,只有当某个目录会向其父级暴露超过 50 个条目时,才会获得自己的 index.md;你可以要求为每个目录生成一个索引,或使用不同的阈值。
如需精选导航,可在 wikis/index.md 中遍历内置变量:
| 变量 | 提供的内容 |
|---|---|
{{displayName}}、{{packageName}} | 知识包显示名称和名称 |
{{knowledgeCount}}、{{knowledgeTimestamp}} | 选中页面的数量和最新时间戳 |
{{knowledgeItems}} | 供循环使用的选中页面元数据 |
{{knowledgeGroups}} | 按根目录和一级目录分组的页面 |
{{knowledgeTreeNodes}}、{{knowledgeTree}} | 嵌套树,或其 Markdown 预览 |
{{wikisRoot}} … {{featsRoot}} | 相对于知识包的根路径,用于 Skill 内的链接 |
包括循环、条件和辅助函数在内的完整列表见 模板变量。你自己的值可以作为自定义变量传给模板。
查询 Skill
默认的 context-knowledge-query Skill 内置了结构优先的查询规范和搜索兜底,并且在每个 Context 知识包中都相同,因此安装一份即可服务所有知识包。它由 Context 管理:如果模板中的副本较旧或被修改过,context build 会替换它,所以在其中做的修改不会保留。
请改为在 others/context/search-guide.md 中为你的知识包调整检索:项目术语和同义词、常见问题,以及每类任务的首选入口页面。Skill 在检索前会先读取这份指南。如果某个知识包需要自己的查询 Skill,请把它放在不同的目录下并使用不同的 name,这样它会与共享 Skill 并列安装。
使用早期 skills/knowledge-query/ 模板创建的工作区会在下一次构建时迁移:Context 会用同一语言的 context-knowledge-query 替换它,在缺少检索指南时添加一份,并报告这次替换。请把旧 Skill 中针对该知识包的措辞移到检索指南中。
构建强制执行的规则
- 不能有第二个知识来源。 描述覆盖范围、范围边界、已知缺口或限制的模板文字,必须有已批准的知识、知识包清单或渲染后的结构数据作为依据;否则构建会报告。事实应放在已批准的页面中。
- 不能冲突。 模板文件会先渲染;渲染后的路径不能落在选中的页面或生成的索引上。请重命名模板文件,或把该页面排除出知识包。
- 链接必须有效。 每个根索引和生成的子索引中的链接都必须能在知识包内解析;失效的链接会被报告。
- 在源头修复。 修复模板、已批准的页面或知识包声明,然后重新构建;永远不要修补
dist/。
这些检查覆盖的是结构,而不是选中的知识对你的读者是否有意义,请自己检查产出。模板 API 见 包模板。