wiki-context-pack
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWiki Context Pack — Bounded Token Retrieval
Wiki上下文包——受限Token检索
You are producing a focused, token-bounded context pack from the wiki. Unlike (which answers a question), this skill packages the most relevant wiki knowledge into a single markdown block that a downstream agent, skill, or user can consume directly.
wiki-query你需要从wiki生成一个聚焦的、受token限制的上下文包。与(用于回答问题)不同,该skill会将最相关的wiki知识打包成单个Markdown块,供下游Agent、skill或用户直接使用。
wiki-queryBefore You Start
开始之前
- Resolve config — follow the Config Resolution Protocol in (walk up CWD for
llm-wiki/SKILL.md→.env→ prompt setup). This gives~/.obsidian-wiki/configand any QMD variables.OBSIDIAN_VAULT_PATH - Read if it exists — gives instant context on recent activity.
$OBSIDIAN_VAULT_PATH/hot.md - Read — the full page inventory.
$OBSIDIAN_VAULT_PATH/index.md
- 解析配置 — 遵循中的配置解析协议(从当前工作目录向上查找
llm-wiki/SKILL.md→.env→ 提示设置)。这会获取~/.obsidian-wiki/config及所有QMD变量。OBSIDIAN_VAULT_PATH - 若存在,请读取该文件——它提供了近期活动的即时上下文。
$OBSIDIAN_VAULT_PATH/hot.md - 读取——完整的页面清单。
$OBSIDIAN_VAULT_PATH/index.md
Invocation Forms
调用格式
/wiki-context-pack "transformer attention mechanism" --budget 16000
/wiki-context-pack "my-project architecture decisions" --budget 8000
/wiki-context-pack --recent --budget 4000 # recent activity pack from hot.md
/wiki-context-pack "authentication patterns" # default budget: 8000 tokensParse the user's invocation to extract:
- topic — the query string (required unless )
--recent - — token budget in tokens (default:
--budget N; max:8000)100000 - — pack the most recently updated/ingested pages instead of a topic query
--recent
/wiki-context-pack "transformer attention mechanism" --budget 16000
/wiki-context-pack "my-project architecture decisions" --budget 8000
/wiki-context-pack --recent --budget 4000 # 从hot.md生成近期活动包
/wiki-context-pack "authentication patterns" # 默认预算:8000 tokens解析用户的调用内容,提取以下信息:
- 主题 — 查询字符串(除非使用,否则为必填项)
--recent - — token预算(默认:
--budget N;最大值:8000)100000 - — 打包最近更新/导入的页面,而非基于主题查询
--recent
Algorithm
算法流程
Step 1: Relevance Pass (cheap)
步骤1:相关性筛选(低成本)
Without opening page bodies:
-
Scanand frontmatter for topic match. Score each page:
index.md- +5 exact title or alias match
- +3 tag match
- +2 field contains the query term
summary: - +1 entry description contains the query term
index.md
-
Formode: sort pages by
--recentfrontmatter descending. Take top 20 as candidates.updated: -
For topic mode: collect the top 20 candidates by score. If QMD is configured (set), run a semantic pass and merge with the frontmatter score (QMD rank adds +4 to the page's score).
QMD_WIKI_COLLECTION
无需打开页面内容:
-
扫描和frontmatter,匹配主题。为每个页面打分:
index.md- +5分:标题或别名完全匹配
- +3分:标签匹配
- +2分:字段包含查询关键词
summary: - +1分:中的条目描述包含查询关键词
index.md
-
若为模式:按frontmatter中的
--recent字段降序排序页面,取前20个作为候选。updated: -
若为主题模式:按分数收集前20个候选页面。若已配置QMD(已设置),执行语义检索并将结果与frontmatter分数合并(QMD排名为页面额外加**+4分**)。
QMD_WIKI_COLLECTION
Step 2: Tier-Aware Selection
步骤2:分层筛选
Within the candidate set, sort by relevance score, then apply tier ordering within each score bucket (see , Importance Tiering section):
llm-wiki/SKILL.md- All -tier matches first
core - Then
supporting - Then (only if budget allows)
peripheral
Maintain this ordering when filling the budget in Step 3.
在候选集中,先按相关性分数排序,再在每个分数区间内按层级排序(参考中的重要性分层章节):
llm-wiki/SKILL.md- 优先选择所有层级的匹配页面
core - 其次是层级
supporting - 最后是层级(仅当预算允许时)
peripheral
在步骤3填充预算时,需保持此排序顺序。
Step 3: Compression
步骤3:压缩处理
For each selected page (in tier/relevance order), compute its compressed representation — not a full read, but a structured distillation:
- Required: title, ,
tier:,tags:(from frontmatter — cheap, no body read needed)summary: - If budget allows: add the page body, but stripped of:
- Frontmatter block (already captured above)
- The section (keep source names in a one-liner instead)
## Sources - Duplicate wikilinks that are already mentioned in included pages
- Boilerplate headers with no content following them
- Dedup overlapping content — if two selected pages share a paragraph (or near-identical claim), keep it only in the more relevant page. Mark the removal: .
_(content also in [[other-page]])_
Estimate tokens for each page representation as .
len(text_chars) / 4对每个选中的页面(按层级/相关性顺序)生成压缩表示——并非完整读取,而是结构化提炼:
- 必填内容:标题、、
tier:、tags:(来自frontmatter——低成本,无需读取页面内容)summary: - 若预算允许:添加页面内容,但需移除以下部分:
- Frontmatter块(已在上方捕获)
- 章节(改为用单行保留来源名称)
## Sources - 已在其他包含页面中提及的重复wikilinks
- 无后续内容的模板化标题
- 去重重叠内容:若两个选中页面包含相同段落(或近乎相同的表述),仅保留相关性更高页面中的内容,并标记移除:。
_(内容也见于[[other-page]])_
按估算每个页面表示的token数量。
len(text_chars) / 4Step 4: Budget Enforcement
步骤4:预算管控
Fill the pack greedily in tier/relevance order until the budget is exhausted:
- Always include the frontmatter summary block for every selected page, even if the body doesn't fit.
- If a page body doesn't fit in full, include a compressed excerpt: the first non-header paragraph plus the "Key Ideas" section (if present).
- Drop -tier pages first when trimming.
peripheral - Keep a running token count. Stop adding pages when the next page would exceed the budget.
- Track how many pages were dropped and note it in the header.
按层级/相关性顺序贪婪填充包内容,直至预算耗尽:
- 始终包含每个选中页面的frontmatter摘要块,即使页面内容无法完全容纳。
- 若页面内容无法完整容纳,添加压缩摘录:第一个非标题段落加上“Key Ideas”章节(若存在)。
- 裁剪时优先移除层级的页面。
peripheral - 持续跟踪token计数,当添加下一个页面会超出预算时停止。
- 统计被移除的页面数量,并在标题中注明。
Step 5: Render Output
步骤5:输出渲染
Emit a single markdown block:
markdown
undefined生成单个Markdown块:
markdown
undefinedContext Pack: <topic>
上下文包: <主题>
Generated: <ISO timestamp>
生成时间: <ISO时间戳>
Budget: <budget> tokens | Actual: <actual> tokens | Pages: <N included> / <M candidates>
预算: <预算> tokens | 实际使用: <实际> tokens | 页面: <已包含数量> / <候选数量>
Methodology: 4 chars/token estimate
估算方法: 4字符/Token
[[<category/page-name>]] (<tier>, ~<tokens> tokens)
[[<分类/页面名称>]] (<层级>, ~<token数> tokens)
tags: #tag1 #tag2
summary: <summary field text>
<compressed body or excerpt>
tags: #tag1 #tag2
summary: <摘要字段文本>
<压缩内容或摘录>
[[<next-page>]] (<tier>, ~<tokens> tokens)
[[<下一页>]] (<层级>, ~<token数> tokens)
...
If `--recent` mode, the header reads:...
若为`--recent`模式,标题为:Context Pack: Recent Activity (last N pages)
上下文包: 近期活动(最近N页)
**Empty result:** If no pages scored above 0 and `--recent` produced no results, output:
**空结果处理**:若没有页面得分高于0,且`--recent`模式无结果,输出:Context Pack: <topic>
上下文包: <主题>
No relevant pages found. Consider running /wiki-ingest to add sources about this topic.
undefined未找到相关页面。建议运行/wiki-ingest添加该主题的相关来源。
undefinedStep 6: Log
步骤6:日志记录
Append to :
$OBSIDIAN_VAULT_PATH/log.md- [TIMESTAMP] CONTEXT_PACK topic="<topic>" budget=<N> actual_tokens=<M> pages_included=<K> pages_dropped=<D>在中追加内容:
$OBSIDIAN_VAULT_PATH/log.md- [时间戳] CONTEXT_PACK topic="<主题>" budget=<N> actual_tokens=<M> pages_included=<K> pages_dropped=<D>Use Cases
使用场景
- Feed into — pass the pack as context to avoid re-discovering known facts
/wiki-research - Pass to — scoped input for a specific synthesis task
/wiki-synthesize - Provide to external agents via MCP or clipboard — bounded, structured, citation-ready
- Checkpoint context before a long multi-step task — know what the wiki already knows before starting
- 传入/wiki-research — 将包作为上下文,避免重复发现已知信息
- 传入/wiki-synthesize — 为特定合成任务提供限定范围的输入
- 通过MCP或剪贴板提供给外部Agent — 受限、结构化、可直接引用的内容
- 长多步骤任务前的上下文检查点 — 在开始任务前了解wiki已有的相关知识
Notes
注意事项
- The heuristic matches
4 chars/token's token footprint estimate — consistent across skillswiki-status - The pack is a snapshot; it is not written to the vault. Re-run to refresh.
- For very large budgets (> 50K tokens), warn the user: "This pack is large. Consider narrowing your topic or using wiki-query for a targeted answer instead."
- "4字符/Token"的估算方法与的token占用量估算一致——确保各skill间的一致性
wiki-status - 包为快照形式,不会写入vault。需重新运行以刷新内容
- 对于超大预算(>50K tokens),需向用户发出警告:"此包体积较大。建议缩小主题范围,或使用wiki-query获取针对性答案。"