wiki-context-pack

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Wiki Context Pack — Bounded Token Retrieval

Wiki上下文包——受限Token检索

You are producing a focused, token-bounded context pack from the wiki. Unlike
wiki-query
(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生成一个聚焦的、受token限制的上下文包。与
wiki-query
(用于回答问题)不同,该skill会将最相关的wiki知识打包成单个Markdown块,供下游Agent、skill或用户直接使用。

Before You Start

开始之前

  1. Resolve config — follow the Config Resolution Protocol in
    llm-wiki/SKILL.md
    (walk up CWD for
    .env
    ~/.obsidian-wiki/config
    → prompt setup). This gives
    OBSIDIAN_VAULT_PATH
    and any QMD variables.
  2. Read
    $OBSIDIAN_VAULT_PATH/hot.md
    if it exists — gives instant context on recent activity.
  3. Read
    $OBSIDIAN_VAULT_PATH/index.md
    — the full page inventory.
  1. 解析配置 — 遵循
    llm-wiki/SKILL.md
    中的配置解析协议(从当前工作目录向上查找
    .env
    ~/.obsidian-wiki/config
    → 提示设置)。这会获取
    OBSIDIAN_VAULT_PATH
    及所有QMD变量。
  2. 若存在
    $OBSIDIAN_VAULT_PATH/hot.md
    ,请读取该文件——它提供了近期活动的即时上下文。
  3. 读取
    $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 tokens
Parse the user's invocation to extract:
  • topic — the query string (required unless
    --recent
    )
  • --budget N
    — token budget in tokens (default:
    8000
    ; max:
    100000
    )
  • --recent
    — pack the most recently updated/ingested pages instead of a topic query
/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
    ,否则为必填项)
  • --budget N
    — token预算(默认:
    8000
    ;最大值:
    100000
  • --recent
    — 打包最近更新/导入的页面,而非基于主题查询

Algorithm

算法流程

Step 1: Relevance Pass (cheap)

步骤1:相关性筛选(低成本)

Without opening page bodies:
  1. Scan
    index.md
    and frontmatter for topic match. Score each page:
    • +5 exact title or alias match
    • +3 tag match
    • +2
      summary:
      field contains the query term
    • +1
      index.md
      entry description contains the query term
  2. For
    --recent
    mode: sort pages by
    updated:
    frontmatter descending. Take top 20 as candidates.
  3. For topic mode: collect the top 20 candidates by score. If QMD is configured (
    QMD_WIKI_COLLECTION
    set), run a semantic pass and merge with the frontmatter score (QMD rank adds +4 to the page's score).
无需打开页面内容:
  1. 扫描
    index.md
    和frontmatter,匹配主题。为每个页面打分:
    • +5分:标题或别名完全匹配
    • +3分:标签匹配
    • +2分
      summary:
      字段包含查询关键词
    • +1分
      index.md
      中的条目描述包含查询关键词
  2. 若为
    --recent
    模式:按frontmatter中的
    updated:
    字段降序排序页面,取前20个作为候选。
  3. 若为主题模式:按分数收集前20个候选页面。若已配置QMD(
    QMD_WIKI_COLLECTION
    已设置),执行语义检索并将结果与frontmatter分数合并(QMD排名为页面额外加**+4分**)。

Step 2: Tier-Aware Selection

步骤2:分层筛选

Within the candidate set, sort by relevance score, then apply tier ordering within each score bucket (see
llm-wiki/SKILL.md
, Importance Tiering section):
  1. All
    core
    -tier matches first
  2. Then
    supporting
  3. Then
    peripheral
    (only if budget allows)
Maintain this ordering when filling the budget in Step 3.
在候选集中,先按相关性分数排序,再在每个分数区间内按层级排序(参考
llm-wiki/SKILL.md
中的重要性分层章节):
  1. 优先选择所有
    core
    层级的匹配页面
  2. 其次是
    supporting
    层级
  3. 最后是
    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:
  1. Required: title,
    tier:
    ,
    tags:
    ,
    summary:
    (from frontmatter — cheap, no body read needed)
  2. If budget allows: add the page body, but stripped of:
    • Frontmatter block (already captured above)
    • The
      ## Sources
      section (keep source names in a one-liner instead)
    • Duplicate wikilinks that are already mentioned in included pages
    • Boilerplate headers with no content following them
  3. 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
.
对每个选中的页面(按层级/相关性顺序)生成压缩表示——并非完整读取,而是结构化提炼:
  1. 必填内容:标题、
    tier:
    tags:
    summary:
    (来自frontmatter——低成本,无需读取页面内容)
  2. 若预算允许:添加页面内容,但需移除以下部分:
    • Frontmatter块(已在上方捕获)
    • ## Sources
      章节(改为用单行保留来源名称)
    • 已在其他包含页面中提及的重复wikilinks
    • 无后续内容的模板化标题
  3. 去重重叠内容:若两个选中页面包含相同段落(或近乎相同的表述),仅保留相关性更高页面中的内容,并标记移除:
    _(内容也见于[[other-page]])_
len(text_chars) / 4
估算每个页面表示的token数量。

Step 4: Budget Enforcement

步骤4:预算管控

Fill the pack greedily in tier/relevance order until the budget is exhausted:
  1. Always include the frontmatter summary block for every selected page, even if the body doesn't fit.
  2. 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).
  3. Drop
    peripheral
    -tier pages first when trimming.
  4. Keep a running token count. Stop adding pages when the next page would exceed the budget.
  5. Track how many pages were dropped and note it in the header.
按层级/相关性顺序贪婪填充包内容,直至预算耗尽:
  1. 始终包含每个选中页面的frontmatter摘要块,即使页面内容无法完全容纳。
  2. 若页面内容无法完整容纳,添加压缩摘录:第一个非标题段落加上“Key Ideas”章节(若存在)。
  3. 裁剪时优先移除
    peripheral
    层级的页面。
  4. 持续跟踪token计数,当添加下一个页面会超出预算时停止。
  5. 统计被移除的页面数量,并在标题中注明。

Step 5: Render Output

步骤5:输出渲染

Emit a single markdown block:
markdown
undefined
生成单个Markdown块:
markdown
undefined

Context 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添加该主题的相关来源。
undefined

Step 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
    /wiki-research
    — pass the pack as context to avoid re-discovering known facts
  • Pass to
    /wiki-synthesize
    — scoped input for a specific synthesis task
  • 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
    4 chars/token
    heuristic matches
    wiki-status
    's token footprint estimate — consistent across skills
  • 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"的估算方法与
    wiki-status
    的token占用量估算一致——确保各skill间的一致性
  • 包为快照形式,不会写入vault。需重新运行以刷新内容
  • 对于超大预算(>50K tokens),需向用户发出警告:"此包体积较大。建议缩小主题范围,或使用wiki-query获取针对性答案。"