Ingest

From Chanw-research/claude-code-paper-writing · View interactive version

Ingest is an AI agent skill from the GitHub repository Chanw-research/claude-code-paper-writing. 把一篇论文 ingest 进 wiki —— 建立 papers + concepts + people + claims 页面,并完成所有双向交叉引用与 graph edge。当用户说 "ingest"、"加入这篇论文"、丢 `.pdf` / `.tex` / arXiv URL 或要求把论文折叠进知识库时触发。

How to use this skill

Skill file

/ingest

把一篇论文转化成一组正确链接的 wiki 页面。/ingest 的职责是写出 well-shaped 的实体与正确的双向链接;语义层面的审计(反向链接对称性、dangling node、字段取值合规)留给 /check。

按需打开下列本地参考文件:

在撰写任何 wiki 页面 frontmatter 或正文章节前,先打开 docs/runtime-page-templates.zh.md;需要 index.md、log.md 或 graph/ 格式时,打开 docs/runtime-support-files.zh.md。

Inputs

Outputs

Wiki Interaction

Reads

Writes

会新增的 Graph edges

tools/research_wiki.py add-edge 会拒绝缺少 confidence/evidence 的

paper-paper 与 paper-concept semantic edge,也会拒绝新写入 legacy

paper-to-concept 或 paper-to-paper 类型。

Workflow

前置条件:工作目录下同时存在 wiki/、raw/、tools/。先解析一次 Python interpreter 并复用:

# 通过 git 找到项目根,让 worktree 中的 subagent 也能定位 .venv。
# .venv 被 gitignore,subagent 的 cwd 在 ../.worktrees/<branch>/ 时本地没有
# .venv——若不解析项目根,PYTHON_BIN 会回退到系统 python3,既丢失 .env 里的
# API key,也丢失安装的依赖(deepxiv-sdk 等)。
# git rev-parse --git-common-dir 无论 cwd 位于哪个 worktree 都返回主仓库的
# .git 目录;其父目录即项目根。
GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null || true)
PROJECT_ROOT=""
if [ -n "$GIT_COMMON_DIR" ]; then
  PROJECT_ROOT=$(cd "$(dirname "$GIT_COMMON_DIR")" 2>/dev/null && pwd)
fi

if   [ -x "$PROJECT_ROOT/.venv/bin/python" ];         then PYTHON_BIN="$PROJECT_ROOT/.venv/bin/python"
elif [ -x "$PROJECT_ROOT/.venv/Scripts/python.exe" ]; then PYTHON_BIN="$PROJECT_ROOT/.venv/Scripts/python.exe"
elif [ -x .venv/bin/python ];                         then PYTHON_BIN=.venv/bin/python
elif [ -x .venv/Scripts/python.exe ];                 then PYTHON_BIN=.venv/Scripts/python.exe
else                                                       PYTHON_BIN=python3
fi
export PYTHON_BIN

Step 1: 解析来源

  1. 如果 /init 交接了 canonical_ingest_path,进入 INIT MODE 并原样消费该路径,不要重新扫描 raw/。详见 references/init-mode.md。
  2. 如果来源是 arXiv URL,先提取 arXiv ID;可用时通过 "$PYTHON_BIN" tools/fetch_s2.py paper <arxiv-id> 恢复标题,然后运行 "$PYTHON_BIN" tools/init_discovery.py download --raw-root raw --arxiv-id <arxiv-id> --title "<title-or-arxiv-id>"。后续从返回的 canonical_ingest_path 继续。该 helper 会先尝试 arXiv source,再 fallback 到 PDF;不要用 fetch_arxiv.py 处理单篇论文,因为它只用于 RSS。
  3. 如果来源是本地 .tex,直接使用。
  4. 如果来源是本地 .pdf,先走 references/pdf-preprocessing.md 的预处理流程,在 raw/tmp/ 下生成 prepared .tex,再继续。

raw 持久化规则:已经在 raw/discovered/、raw/tmp/、raw/papers/ 中的文件,不得被复制或重写到别的 raw 子目录。

Step 2: 论文身份与 enrichment

  1. 生成 paper slug:

```bash

"$PYTHON_BIN" tools/research_wiki.py slug "<paper-title>"

```

  1. 冲突检查:若 wiki/papers/{slug}.md 已存在且 arXiv ID 或标题一致,报告并退出;若不一致,按 references/error-handling.md 处理冲突。
  2. 有 arXiv ID 时查询 Semantic Scholar:

```bash

"$PYTHON_BIN" tools/fetch_s2.py paper <arxiv-id>

```

用于填写 venue、year、s2_id、citation count,以及 importance(1-5)的评估依据。

  1. 可选 DeepXiv enrichment,失败则静默跳过:

```bash

"$PYTHON_BIN" tools/fetch_deepxiv.py brief <arxiv-id>

"$PYTHON_BIN" tools/fetch_deepxiv.py head <arxiv-id>

"$PYTHON_BIN" tools/fetch_deepxiv.py social <arxiv-id>

```

brief 用于 seed Key idea;head 用于对照 tex 解析的章节结构;social 作为 importance 的辅助信号。

Step 3: 写 paper 页面

打开 docs/runtime-page-templates.zh.md 中的 paper 模板。填写全部必需 frontmatter 字段;cited_by 本步骤留空,Step 5 再回填。

写入前对即将输出的 frontmatter 做一次形状检查 —— 仅限以下范围:

形状检查刻意保持狭窄:反向链接对称性、dangling node、跨实体一致性是 /check 的工作,不是本 skill 的。

正文章节:Problem、Key idea、Method、Results、Limitations、Open questions、My take、Related。

Step 4: concept / claim / people

按 references/dedup-policy.md 执行。简要步骤:

  1. 每个 concept / claim 候选都先调用对应的 find-similar-* 工具。
  2. 默认合并到 top 结果。只有在工具返回无可用候选、且论文 importance 确实证明新建合理时,才新建页面。
  3. 每写一条正向链接,同一 turn 内写入其反向链接。义务矩阵见 references/cross-references.md。
  4. 仅当 importance ≥ 4 才允许新建 wiki/people/{slug}.md;否则只允许向已有作者页面追加。

Step 5: paper-to-paper edge 与 `cited_by`

INIT MODE 下整步跳过 —— 由上层 /init 在 fan-in 时统一处理。

"$PYTHON_BIN" tools/fetch_s2.py references <arxiv-id>
"$PYTHON_BIN" tools/fetch_s2.py citations <arxiv-id>

Step 6: topic 与 index

  1. 将论文的 domain 与 tags 对 wiki/topics/*.md 做匹配。对每个命中 topic:
  1. /ingest 不得新建 topic 页面 —— topic 创建属于 /init 与 /edit。
  2. 在 wiki/index.md 对应分类下追加新增或编辑过的条目。格式见 docs/runtime-support-files.zh.md。

Step 7: 日志与 rebuild

"$PYTHON_BIN" tools/research_wiki.py log wiki/ "ingest | added papers/<slug> | updated: <list>"

非 INIT MODE 下再执行:

"$PYTHON_BIN" tools/research_wiki.py rebuild-context-brief wiki/
"$PYTHON_BIN" tools/research_wiki.py rebuild-open-questions wiki/

Step 8: 汇报

输出一个紧凑 summary:新建的页面、编辑的页面、新增的 graph edge、发现的 contradiction(如有)、尚未 ingest 的高引用 references(后续 /ingest 建议)。末尾一行:

Wiki: +1 paper, +{N} claims, +{M} concepts, +{K} edges

Step 9: 可选的 discovery(仅当 `--discover` 显式开启)

如果用户没有显式传 --discover,跳过本步骤。INIT MODE 下也一律跳过 —— 是否在 fan-in 之后跑 discovery,是 /init 父流程的决定,不是单个子代理的决定。

开启时,用刚 ingest 论文作为单 anchor 调用 /discover:

"$PYTHON_BIN" tools/discover.py from-anchors \
  --id <arxiv-id-of-this-paper> \
  --wiki-root wiki \
  --limit 10 \
  --output-checkpoint .checkpoints/ \
  --markdown

把 markdown 输出附在 report 下一个 "接下来可能想 ingest 的相关论文" 小节里。不要自动 ingest 列表里的任何东西 —— 由用户挑选。若 discovery 失败(S2 故障、所有通道返回空),在 report 里一行说明并继续 —— discovery 失败不应让一次成功的 /ingest 也算失败。

Constraints

Error Handling

详见 references/error-handling.md。要点:来源解析按 tex → PDF → vision API → 报告用户的顺序 fallback;S2 不可用时 importance 默认取 3 并跳过 citation 回填;DeepXiv 不可用时静默跳过 enrichment;slug 冲突追加数字后缀。

Dependencies

Tools(via Bash)

Shared References

Skills

External APIs

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.