paper-library-kit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. paper_library_kit-0.1.0/.claude/hooks/paper_hint.py +146 -0
  2. paper_library_kit-0.1.0/.claude/settings.json +15 -0
  3. paper_library_kit-0.1.0/.gitignore +12 -0
  4. paper_library_kit-0.1.0/CONTRIBUTING.md +24 -0
  5. paper_library_kit-0.1.0/LICENSE +21 -0
  6. paper_library_kit-0.1.0/PKG-INFO +164 -0
  7. paper_library_kit-0.1.0/README.md +113 -0
  8. paper_library_kit-0.1.0/README.zh-TW.md +66 -0
  9. paper_library_kit-0.1.0/ROADMAP.md +26 -0
  10. paper_library_kit-0.1.0/config/paper_config.yaml +97 -0
  11. paper_library_kit-0.1.0/docs/research_problems.md +12 -0
  12. paper_library_kit-0.1.0/examples/demo_build.py +405 -0
  13. paper_library_kit-0.1.0/examples/demo_evo_graph.html +419 -0
  14. paper_library_kit-0.1.0/init_library.py +66 -0
  15. paper_library_kit-0.1.0/paper_library_kit/__init__.py +3 -0
  16. paper_library_kit-0.1.0/paper_library_kit/cli.py +151 -0
  17. paper_library_kit-0.1.0/papers/PDF_MANIFEST.csv +1 -0
  18. paper_library_kit-0.1.0/papers/README.md +30 -0
  19. paper_library_kit-0.1.0/papers/tools/backfill_seed.py +117 -0
  20. paper_library_kit-0.1.0/papers/tools/cards_from_yaml.py +183 -0
  21. paper_library_kit-0.1.0/papers/tools/check_ai_readable.py +364 -0
  22. paper_library_kit-0.1.0/papers/tools/check_core_tags.py +170 -0
  23. paper_library_kit-0.1.0/papers/tools/check_relations.py +98 -0
  24. paper_library_kit-0.1.0/papers/tools/cite_audit.py +307 -0
  25. paper_library_kit-0.1.0/papers/tools/cite_chain.py +160 -0
  26. paper_library_kit-0.1.0/papers/tools/evo_graph.py +210 -0
  27. paper_library_kit-0.1.0/papers/tools/evo_graph_template.html +419 -0
  28. paper_library_kit-0.1.0/papers/tools/find_paper.py +327 -0
  29. paper_library_kit-0.1.0/papers/tools/gap_scan.py +130 -0
  30. paper_library_kit-0.1.0/papers/tools/ingest_pdf.py +346 -0
  31. paper_library_kit-0.1.0/papers/tools/lib_config.py +161 -0
  32. paper_library_kit-0.1.0/papers/tools/lit_search.py +264 -0
  33. paper_library_kit-0.1.0/papers/tools/meta_health.py +159 -0
  34. paper_library_kit-0.1.0/papers/tools/ocr_pages.py +66 -0
  35. paper_library_kit-0.1.0/papers/tools/paper_graph.py +101 -0
  36. paper_library_kit-0.1.0/papers/tools/rel_context.py +107 -0
  37. paper_library_kit-0.1.0/papers/tools/retag_candidates.py +50 -0
  38. paper_library_kit-0.1.0/papers/tools/summary_from_resp.py +104 -0
  39. paper_library_kit-0.1.0/papers/tools/triage_apply.py +95 -0
  40. paper_library_kit-0.1.0/papers/triage/REDIRECTS.md +4 -0
  41. paper_library_kit-0.1.0/papers/triage/TRIAGE_SPEC.md +43 -0
  42. paper_library_kit-0.1.0/papers/triage/cards_template.yaml +28 -0
  43. paper_library_kit-0.1.0/papers/triage/cite_verified.tsv +1 -0
  44. paper_library_kit-0.1.0/papers/triage/core_tags.tsv +1 -0
  45. paper_library_kit-0.1.0/papers/triage/ingest_template.tsv +2 -0
  46. paper_library_kit-0.1.0/papers/triage/triage.tsv +1 -0
  47. paper_library_kit-0.1.0/papers/triage/wanted_template.md +9 -0
  48. paper_library_kit-0.1.0/prompts/00_AGENT_LITERATURE_RULES.md +31 -0
  49. paper_library_kit-0.1.0/prompts/01_CLAUDE_SYSTEM_PROMPT.md +23 -0
  50. paper_library_kit-0.1.0/prompts/02_PROMPT_SURVEY_AND_GAP.md +60 -0
  51. paper_library_kit-0.1.0/prompts/03_PROMPT_TRIAGE_AND_CONVERT.md +53 -0
  52. paper_library_kit-0.1.0/prompts/04_PROMPT_CARDS_AND_TAGS.md +39 -0
  53. paper_library_kit-0.1.0/prompts/05_PROMPT_RELATION_NETWORK.md +88 -0
  54. paper_library_kit-0.1.0/prompts/en/00_AGENT_LITERATURE_RULES.md +30 -0
  55. paper_library_kit-0.1.0/prompts/en/01_CLAUDE_SYSTEM_PROMPT.md +23 -0
  56. paper_library_kit-0.1.0/prompts/en/02_PROMPT_SURVEY_AND_GAP.md +50 -0
  57. paper_library_kit-0.1.0/prompts/en/03_PROMPT_TRIAGE_AND_CONVERT.md +44 -0
  58. paper_library_kit-0.1.0/prompts/en/04_PROMPT_CARDS_AND_TAGS.md +36 -0
  59. paper_library_kit-0.1.0/prompts/en/05_PROMPT_RELATION_NETWORK.md +63 -0
  60. paper_library_kit-0.1.0/pyproject.toml +88 -0
  61. paper_library_kit-0.1.0/requirements.txt +3 -0
  62. paper_library_kit-0.1.0/tests/test_kit.py +220 -0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env python3
2
+ """Claude Code PostToolUse hook:在固定時點自動印「最相關的前 3 篇論文」(只提醒、不阻擋)。
3
+
4
+ 觸發時點:
5
+ 1. 編輯研究問題清單(config/paper_config.yaml 的 problems_file,預設 docs/research_problems.md)
6
+ 2. 在研究日誌(docs/log/*.md)寫入含失敗關鍵詞的段落,且同一機制累計出現第 2 次
7
+ 關掉:設環境變數 PAPER_HINT=0。
8
+ """
9
+ import hashlib
10
+ import json
11
+ import os
12
+ import re
13
+ import subprocess
14
+ import sys
15
+ import tempfile
16
+
17
+ ROOT = os.environ.get("CLAUDE_PROJECT_DIR") or os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
18
+ TOOLS = os.path.join(ROOT, "papers", "tools")
19
+ FIND = os.path.join(TOOLS, "find_paper.py")
20
+ FAIL = re.compile(r"排除|不成立|不夠|仍崩|仍失敗|仍然失敗|沒改善|未改善|無效|沒用|又失敗|FAIL")
21
+ LOGDOC = re.compile(r"docs/log/[^\s'\"]*\.md")
22
+
23
+
24
+ def problems_rel():
25
+ sys.path.insert(0, TOOLS)
26
+ try:
27
+ import lib_config as cfg
28
+ return os.path.relpath(cfg.problems_path(), ROOT).replace("\\", "/")
29
+ except Exception:
30
+ return "docs/research_problems.md"
31
+
32
+
33
+ def note_text(name, inp):
34
+ text = ""
35
+ if name in ("Edit", "MultiEdit", "Write") and LOGDOC.search(str(inp.get("file_path", ""))):
36
+ text = (inp.get("new_string") or inp.get("content")
37
+ or " ".join(e.get("new_string", "") for e in inp.get("edits") or []))
38
+ elif name == "Bash":
39
+ cmd = inp.get("command", "")
40
+ if re.search(r">>\s*\S*docs/log/", cmd):
41
+ text = cmd
42
+ return text if text and FAIL.search(text) else None
43
+
44
+
45
+ def query(text, n=3):
46
+ r = subprocess.run([sys.executable, FIND, "search", "--json", "-n", str(n), "--text", text],
47
+ capture_output=True, text=True, timeout=20)
48
+ return json.loads(r.stdout) if r.returncode == 0 and r.stdout.strip() else None
49
+
50
+
51
+ def fail_trigger(sid, text):
52
+ res = query(text, n=1)
53
+ terms = ((res or {}).get("query") or {})
54
+ terms = (terms.get("problems") or []) + (terms.get("symptoms") or [])
55
+ if not terms:
56
+ return None
57
+ st = os.path.join(tempfile.gettempdir(), f"paper_fail_{sid}.json")
58
+ try:
59
+ cnt = json.load(open(st, encoding="utf-8"))
60
+ except (OSError, ValueError):
61
+ cnt = {}
62
+ for t in terms:
63
+ cnt[t] = cnt.get(t, 0) + 1
64
+ with open(st, "w", encoding="utf-8") as f:
65
+ json.dump(cnt, f, ensure_ascii=False)
66
+ hit = [t for t in terms if cnt[t] >= 2]
67
+ return (f"同機制失敗 2 次({', '.join(hit)})", text) if hit else None
68
+
69
+
70
+ def trigger(name, inp, sid="x"):
71
+ note = note_text(name, inp)
72
+ if note:
73
+ return fail_trigger(sid, note)
74
+ prob_file = problems_rel()
75
+ fp = str(inp.get("file_path", "")).replace("\\", "/")
76
+ if name in ("Edit", "MultiEdit", "Write") and fp.endswith(prob_file):
77
+ text = inp.get("new_string") or inp.get("content") or " ".join(e.get("new_string", "") for e in inp.get("edits") or [])
78
+ if re.search(r"^###\s+[A-Z]{2,6}-P?\d+", text, re.M) or len(text) >= 150:
79
+ return f"寫 {prob_file}", text
80
+ return None
81
+
82
+
83
+ def render(when, res):
84
+ q = res["query"]
85
+ terms = ", ".join((q.get("problems") or []) + (q.get("symptoms") or []))
86
+ lines = [f"〔paper_hint〕{when}:論文庫最相關的前 {len(res['results'])} 篇(依 {terms};共 {res['total']} 篇命中)"]
87
+ for p in res["results"]:
88
+ num = re.sub(r"\s*«.*", "", p.get("best_number") or "")[:90]
89
+ lines.append(f"- {p['id']}({p['year']},核心度 {p['core_a']}){p['title'][:60]}——{(p['core_a_reason'] or p['reason'])[:50]}"
90
+ + (f";{num}" if num else ""))
91
+ ev = {}
92
+ for x in (p.get("links") or [])[:4]:
93
+ ev.setdefault(x["label"], []).append(x["id"])
94
+ if ev:
95
+ lines.append(" 演進:" + ";".join(f"{k} {'、'.join(v)}" for k, v in ev.items()))
96
+ lines.append("有用的寫進該條「文獻對照」(細節:`python papers/tools/find_paper.py show <id>`);無關就忽略。")
97
+ return "\n".join(lines)
98
+
99
+
100
+ def log_hint(d, when, res):
101
+ log_path = os.environ.get("PAPER_HINT_LOG") or os.path.join(ROOT, "papers", "triage", "hint_log.tsv")
102
+ try:
103
+ from datetime import datetime, timezone
104
+ new = not os.path.exists(log_path)
105
+ with open(log_path, "a", encoding="utf-8") as f:
106
+ if new:
107
+ f.write("utc\tsession\twhen\tids\n")
108
+ f.write(f"{datetime.now(timezone.utc):%Y-%m-%dT%H:%M}\t{str(d.get('session_id', 'x'))[-6:]}\t"
109
+ f"{when.replace(chr(9), ' ')}\t{';'.join(p['id'] for p in res['results'])}\n")
110
+ except Exception:
111
+ pass
112
+
113
+
114
+ def main():
115
+ if os.environ.get("PAPER_HINT", "1") == "0":
116
+ return 0
117
+ d = json.load(sys.stdin)
118
+ if d.get("agent_id"):
119
+ return 0
120
+ t = trigger(d.get("tool_name", ""), d.get("tool_input") or {}, d.get("session_id", "x"))
121
+ if not t:
122
+ return 0
123
+ res = query(t[1])
124
+ if not res or not res.get("results"):
125
+ return 0
126
+ key = hashlib.md5(",".join(p["id"] for p in res["results"]).encode()).hexdigest()[:10]
127
+ st = os.path.join(tempfile.gettempdir(), f"paper_hint_{d.get('session_id', 'x')}.txt")
128
+ try:
129
+ seen = open(st, encoding="utf-8").read().split()
130
+ except OSError:
131
+ seen = []
132
+ if key in seen:
133
+ return 0
134
+ with open(st, "a", encoding="utf-8") as f:
135
+ f.write(key + "\n")
136
+ log_hint(d, t[0], res)
137
+ print(json.dumps({"hookSpecificOutput": {"hookEventName": "PostToolUse", "additionalContext": render(t[0], res)}},
138
+ ensure_ascii=False))
139
+ return 0
140
+
141
+
142
+ if __name__ == "__main__":
143
+ try:
144
+ sys.exit(main())
145
+ except Exception:
146
+ sys.exit(0)
@@ -0,0 +1,15 @@
1
+ {
2
+ "hooks": {
3
+ "PostToolUse": [
4
+ {
5
+ "matcher": "Edit|MultiEdit|Write|Bash",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/hooks/paper_hint.py\""
10
+ }
11
+ ]
12
+ }
13
+ ]
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ # 原始 PDF 不進 Git(封存於本機電腦資料夾)
2
+ *.pdf
3
+ papers/**/pages/
4
+ __pycache__/
5
+ *.pyc
6
+ *.egg-info/
7
+ build/
8
+ dist/
9
+ .cache/
10
+ .venv/
11
+ venv/
12
+ .DS_Store
@@ -0,0 +1,24 @@
1
+ # Contributing to Paper Library Kit
2
+
3
+ Thank you for helping make AI-assisted literature research verifiable, low-token, and hallucination-free!
4
+
5
+ ## Ways to Contribute
6
+
7
+ 1. **Report bugs or edge cases** (PDF cropping quirks, Unicode normalization in quote verification, OpenAlex/Crossref rate-limit edge cases).
8
+ 2. **Pick up a `good first issue` from [`ROADMAP.md`](ROADMAP.md)** — such as Marker/Docling adapters, Zotero/BibTeX importers, Obsidian exporters, Cursor/Codex hook adapters, or domain `paper_config.yaml` presets.
9
+ 3. **Improve documentation or prompts** in `prompts/` and `prompts/en/`.
10
+
11
+ ## Local Development & Testing
12
+
13
+ ```bash
14
+ git clone https://github.com/<your-fork>/paper-library-kit.git
15
+ cd paper-library-kit
16
+ pip install -e ".[all]"
17
+ python -m unittest discover -s tests -v
18
+ ```
19
+
20
+ Before opening a pull request:
21
+ - Ensure `python -m py_compile init_library.py paper_library_kit/*.py papers/tools/*.py .claude/hooks/*.py` passes.
22
+ - Ensure `python -m unittest discover -s tests -v` passes with zero errors.
23
+ - Ensure `python examples/demo_build.py` still builds `examples/demo_evo_graph.html` cleanly if you touched card/graph tooling.
24
+ - Never include copyrighted PDFs, private API keys, or proprietary project data in PRs.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Debiddo0506
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.5
2
+ Name: paper-library-kit
3
+ Version: 0.1.0
4
+ Summary: Git-native, anti-hallucination literature knowledge graph & AI-readable paper library toolkit for AI coding agents.
5
+ Project-URL: Homepage, https://github.com/Debiddo0506/paper-library-kit
6
+ Project-URL: Repository, https://github.com/Debiddo0506/paper-library-kit
7
+ Project-URL: Issues, https://github.com/Debiddo0506/paper-library-kit/issues
8
+ Project-URL: Demo, https://debiddo0506.github.io/paper-library-kit/
9
+ Author: Debiddo0506
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 Debiddo0506
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: ai-agents,anti-hallucination,claude-code,knowledge-graph,literature-review,pdf-to-markdown,research-tools
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Intended Audience :: Science/Research
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Topic :: Scientific/Engineering
42
+ Requires-Python: >=3.10
43
+ Requires-Dist: pyyaml>=6.0
44
+ Provides-Extra: all
45
+ Requires-Dist: pymupdf4llm>=0.0.17; extra == 'all'
46
+ Requires-Dist: pymupdf>=1.24.0; extra == 'all'
47
+ Provides-Extra: pdf
48
+ Requires-Dist: pymupdf4llm>=0.0.17; extra == 'pdf'
49
+ Requires-Dist: pymupdf>=1.24.0; extra == 'pdf'
50
+ Description-Content-Type: text/markdown
51
+
52
+ # Paper Library Kit (`plk`)
53
+
54
+ [![CI](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml)
55
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
56
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](pyproject.toml)
57
+
58
+ **Stop letting AI coding agents hallucinate DOIs and burn tokens reading raw PDFs.**
59
+
60
+ `paper-library-kit` is a **Git-native, verbatim-verified literature knowledge graph, PDF-to-Markdown pipeline, and proactive debugging hook** designed for **Claude Code, Codex, Cursor, and Perplexity/Gemini research workflows**.
61
+
62
+ > **English** | [繁體中文版說明 (Traditional Chinese)](README.zh-TW.md) | [Live Interactive Evolution Graph Demo (16 Real AI-Agent/RAG Papers)](https://debiddo0506.github.io/paper-library-kit/)
63
+
64
+ ---
65
+
66
+ ## Why This Exists
67
+
68
+ Standard reference managers (Zotero, Mendeley) are built for humans, while naive vector RAG stores often fail in rigorous engineering and academic workflows:
69
+
70
+ | Common AI Failure Mode | How `paper-library-kit` Fixes It |
71
+ |---|---|
72
+ | **Fabricated DOIs** during deep-research surveys | `plk verify` extracts every DOI in a Markdown file and checks title similarity live against **Crossref** |
73
+ | **Token bloat & garbled columns** when agents read raw PDFs | `plk ingest` converts PDFs to clean two-column Markdown with `=== p.N ===` markers + cropped figures; raw PDFs stay archived locally (never in Git) |
74
+ | **Hallucinated numbers & unit swaps** in summaries | `plk cards` & `plk check` enforce **verbatim `«quote»` substring matching** and **number-unit adjacency** before writing any entry |
75
+ | **Isolated paper lists** with no technical lineage | `plk cites` runs 4-source citation cross-auditing and `plk graph build` compiles a zero-backend interactive HTML evolution timeline |
76
+ | **Forgetting relevant papers** while debugging | `.claude/hooks/paper_hint.py` automatically surfaces the top 3 papers & evolution links when you log recurring failures |
77
+
78
+ ---
79
+
80
+ ## 5-Stage Pipeline
81
+
82
+ ```mermaid
83
+ flowchart LR
84
+ S1["1. Survey & Gaps\nplk lit / verify / chain / gap"] --> S2["2. PDF to AI-Readable\nplk ingest / ocr / audit-pdfs"]
85
+ S2 --> S3["3. Verbatim Cards & Tags\nplk cards / check / meta-health"]
86
+ S3 --> S4["4. Relation Graph & Timeline\nplk backfill / cites / graph build"]
87
+ S4 --> S5["5. Retrieval & Proactive Hooks\nplk search / neighbors / paper_hint.py"]
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Real Anti-Hallucination Catch Examples
93
+
94
+ 1. **Catching misquoted metrics before they enter your notes (`plk check`)**:
95
+ ```text
96
+ ✗ [數字查無] M05: 5 datasets @ plug-and-play retrieval correction evaluation
97
+ ✗ [引句無此數值] M05: 5 «Experiments on five datasets demonstrate that CRAG»
98
+ ```
99
+ If the paper text says `"five datasets"` and an LLM rewrites `"5"`, or attaches a model number like `SM15T30A` as `30 A`, `check_core_tags.py` rejects it immediately.
100
+
101
+ 2. **Catching LLM-hallucinated DOIs (`plk verify survey_notes.md`)**:
102
+ ```text
103
+ | Verdict | Sim | DOI | Crossref Actual Title | In Lib |
104
+ |----------------------|------|----------------------------|-------------------------------------------|--------|
105
+ | OK | 1.00 | 10.48550/arxiv.2210.03629 | ReAct: Synergizing Reasoning and Acting | M01 |
106
+ | DOI 錯(指到別篇) | 0.14 | 10.1109/jssc.2020.9999999 | Unrelated Journal Article | — |
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Quick Start (5 Minutes)
112
+
113
+ ### 1. Install the `plk` CLI
114
+ ```bash
115
+ git clone https://github.com/Debiddo0506/paper-library-kit.git
116
+ cd paper-library-kit
117
+ pip install -e ".[all]" # or `pip install -e .` without PDF conversion extras
118
+ ```
119
+ > Optional system packages for scanned PDFs: `poppler-utils` (`pdftoppm`/`pdftotext`) and `tesseract-ocr`.
120
+ > Optional environment variable for high-rate OpenAlex queries: `export OPENALEX_API_KEY=...`
121
+
122
+ ### 2. Initialize a Project
123
+ ```bash
124
+ plk init ./my-research
125
+ cd my-research
126
+ ```
127
+ Edit [`config/paper_config.yaml`](config/paper_config.yaml) for your domain (`topics`, `themes` swimlanes, controlled `vocab`, `aliases`, and local `pdf_archive_dir`).
128
+
129
+ ### 3. Try the 16-Paper Real Demo Immediately
130
+ ```bash
131
+ python examples/demo_build.py
132
+ # Open examples/demo_evo_graph.html in your browser
133
+ ```
134
+
135
+ ---
136
+
137
+ ## CLI & Prompt Reference
138
+
139
+ ### Unified `plk` Commands (also runnable via `python papers/tools/*.py`)
140
+ | Stage | Commands | Purpose |
141
+ |---|---|---|
142
+ | **1. Survey** | `plk lit search`, `plk verify`, `plk chain`, `plk gap` | Crossref/OpenAlex search, DOI anti-hallucination verification, citation chains, problem-gap scan |
143
+ | **2. Convert** | `plk ingest`, `plk ocr`, `plk audit-pdfs` | PDF -> `=== p.N ===` Markdown + cropped `images/` + SHA-256 `meta.yaml`, OCR, 6-point audit |
144
+ | **3. Verify** | `plk cards`, `plk check`, `plk meta-health`, `plk triage-apply` | Build `summary.md` & TSVs from YAML with verbatim quote verification, OpenAlex metadata audit |
145
+ | **4. Graph** | `plk backfill`, `plk rel-context`, `plk check-relations`, `plk cites`, `plk graph` | Batch relation backfill, 4-source citation audit (`H x T x O x Y`), compile `evo_graph.html` |
146
+ | **5. Retrieve** | `plk search`, `plk show`, `plk neighbors`, `plk path`, `plk vocab` | Multi-signal search (problem ID, vocab, alias, `--fulltext`), multi-hop graph traversal |
147
+
148
+ ### Ready-to-Use Prompt Templates
149
+ - **English**: [`prompts/en/`](prompts/en/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)
150
+ - **繁體中文**: [`prompts/`](prompts/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)
151
+
152
+ ---
153
+
154
+ ## Development, Tests & Contributing
155
+
156
+ ```bash
157
+ python -m unittest discover -s tests -v
158
+ ```
159
+
160
+ See [`ROADMAP.md`](ROADMAP.md) for `good first issue` ideas (Marker/Docling backend, BibTeX/Zotero importer, MCP server wrapper, Obsidian exporter, domain presets) and [`CONTRIBUTING.md`](CONTRIBUTING.md) for guidelines.
161
+
162
+ ## License
163
+
164
+ MIT License — see [`LICENSE`](LICENSE). **Never commit copyrighted PDFs or private API keys to a public repository.**
@@ -0,0 +1,113 @@
1
+ # Paper Library Kit (`plk`)
2
+
3
+ [![CI](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](pyproject.toml)
6
+
7
+ **Stop letting AI coding agents hallucinate DOIs and burn tokens reading raw PDFs.**
8
+
9
+ `paper-library-kit` is a **Git-native, verbatim-verified literature knowledge graph, PDF-to-Markdown pipeline, and proactive debugging hook** designed for **Claude Code, Codex, Cursor, and Perplexity/Gemini research workflows**.
10
+
11
+ > **English** | [繁體中文版說明 (Traditional Chinese)](README.zh-TW.md) | [Live Interactive Evolution Graph Demo (16 Real AI-Agent/RAG Papers)](https://debiddo0506.github.io/paper-library-kit/)
12
+
13
+ ---
14
+
15
+ ## Why This Exists
16
+
17
+ Standard reference managers (Zotero, Mendeley) are built for humans, while naive vector RAG stores often fail in rigorous engineering and academic workflows:
18
+
19
+ | Common AI Failure Mode | How `paper-library-kit` Fixes It |
20
+ |---|---|
21
+ | **Fabricated DOIs** during deep-research surveys | `plk verify` extracts every DOI in a Markdown file and checks title similarity live against **Crossref** |
22
+ | **Token bloat & garbled columns** when agents read raw PDFs | `plk ingest` converts PDFs to clean two-column Markdown with `=== p.N ===` markers + cropped figures; raw PDFs stay archived locally (never in Git) |
23
+ | **Hallucinated numbers & unit swaps** in summaries | `plk cards` & `plk check` enforce **verbatim `«quote»` substring matching** and **number-unit adjacency** before writing any entry |
24
+ | **Isolated paper lists** with no technical lineage | `plk cites` runs 4-source citation cross-auditing and `plk graph build` compiles a zero-backend interactive HTML evolution timeline |
25
+ | **Forgetting relevant papers** while debugging | `.claude/hooks/paper_hint.py` automatically surfaces the top 3 papers & evolution links when you log recurring failures |
26
+
27
+ ---
28
+
29
+ ## 5-Stage Pipeline
30
+
31
+ ```mermaid
32
+ flowchart LR
33
+ S1["1. Survey & Gaps\nplk lit / verify / chain / gap"] --> S2["2. PDF to AI-Readable\nplk ingest / ocr / audit-pdfs"]
34
+ S2 --> S3["3. Verbatim Cards & Tags\nplk cards / check / meta-health"]
35
+ S3 --> S4["4. Relation Graph & Timeline\nplk backfill / cites / graph build"]
36
+ S4 --> S5["5. Retrieval & Proactive Hooks\nplk search / neighbors / paper_hint.py"]
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Real Anti-Hallucination Catch Examples
42
+
43
+ 1. **Catching misquoted metrics before they enter your notes (`plk check`)**:
44
+ ```text
45
+ ✗ [數字查無] M05: 5 datasets @ plug-and-play retrieval correction evaluation
46
+ ✗ [引句無此數值] M05: 5 «Experiments on five datasets demonstrate that CRAG»
47
+ ```
48
+ If the paper text says `"five datasets"` and an LLM rewrites `"5"`, or attaches a model number like `SM15T30A` as `30 A`, `check_core_tags.py` rejects it immediately.
49
+
50
+ 2. **Catching LLM-hallucinated DOIs (`plk verify survey_notes.md`)**:
51
+ ```text
52
+ | Verdict | Sim | DOI | Crossref Actual Title | In Lib |
53
+ |----------------------|------|----------------------------|-------------------------------------------|--------|
54
+ | OK | 1.00 | 10.48550/arxiv.2210.03629 | ReAct: Synergizing Reasoning and Acting | M01 |
55
+ | DOI 錯(指到別篇) | 0.14 | 10.1109/jssc.2020.9999999 | Unrelated Journal Article | — |
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Quick Start (5 Minutes)
61
+
62
+ ### 1. Install the `plk` CLI
63
+ ```bash
64
+ git clone https://github.com/Debiddo0506/paper-library-kit.git
65
+ cd paper-library-kit
66
+ pip install -e ".[all]" # or `pip install -e .` without PDF conversion extras
67
+ ```
68
+ > Optional system packages for scanned PDFs: `poppler-utils` (`pdftoppm`/`pdftotext`) and `tesseract-ocr`.
69
+ > Optional environment variable for high-rate OpenAlex queries: `export OPENALEX_API_KEY=...`
70
+
71
+ ### 2. Initialize a Project
72
+ ```bash
73
+ plk init ./my-research
74
+ cd my-research
75
+ ```
76
+ Edit [`config/paper_config.yaml`](config/paper_config.yaml) for your domain (`topics`, `themes` swimlanes, controlled `vocab`, `aliases`, and local `pdf_archive_dir`).
77
+
78
+ ### 3. Try the 16-Paper Real Demo Immediately
79
+ ```bash
80
+ python examples/demo_build.py
81
+ # Open examples/demo_evo_graph.html in your browser
82
+ ```
83
+
84
+ ---
85
+
86
+ ## CLI & Prompt Reference
87
+
88
+ ### Unified `plk` Commands (also runnable via `python papers/tools/*.py`)
89
+ | Stage | Commands | Purpose |
90
+ |---|---|---|
91
+ | **1. Survey** | `plk lit search`, `plk verify`, `plk chain`, `plk gap` | Crossref/OpenAlex search, DOI anti-hallucination verification, citation chains, problem-gap scan |
92
+ | **2. Convert** | `plk ingest`, `plk ocr`, `plk audit-pdfs` | PDF -> `=== p.N ===` Markdown + cropped `images/` + SHA-256 `meta.yaml`, OCR, 6-point audit |
93
+ | **3. Verify** | `plk cards`, `plk check`, `plk meta-health`, `plk triage-apply` | Build `summary.md` & TSVs from YAML with verbatim quote verification, OpenAlex metadata audit |
94
+ | **4. Graph** | `plk backfill`, `plk rel-context`, `plk check-relations`, `plk cites`, `plk graph` | Batch relation backfill, 4-source citation audit (`H x T x O x Y`), compile `evo_graph.html` |
95
+ | **5. Retrieve** | `plk search`, `plk show`, `plk neighbors`, `plk path`, `plk vocab` | Multi-signal search (problem ID, vocab, alias, `--fulltext`), multi-hop graph traversal |
96
+
97
+ ### Ready-to-Use Prompt Templates
98
+ - **English**: [`prompts/en/`](prompts/en/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)
99
+ - **繁體中文**: [`prompts/`](prompts/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)
100
+
101
+ ---
102
+
103
+ ## Development, Tests & Contributing
104
+
105
+ ```bash
106
+ python -m unittest discover -s tests -v
107
+ ```
108
+
109
+ See [`ROADMAP.md`](ROADMAP.md) for `good first issue` ideas (Marker/Docling backend, BibTeX/Zotero importer, MCP server wrapper, Obsidian exporter, domain presets) and [`CONTRIBUTING.md`](CONTRIBUTING.md) for guidelines.
110
+
111
+ ## License
112
+
113
+ MIT License — see [`LICENSE`](LICENSE). **Never commit copyrighted PDFs or private API keys to a public repository.**
@@ -0,0 +1,66 @@
1
+ # Paper Library Kit — 給 AI Coding Agent 的零幻覺文獻知識庫與演進圖工具包
2
+
3
+ > [English README](README.md) | **繁體中文說明(本頁)** | [互動演進圖線上 Demo](https://debiddo0506.github.io/paper-library-kit/)
4
+
5
+ **別再讓 AI 編造假 DOI、或每次開工就讀幾十 MB 的原始 PDF 燒光 Token。**
6
+ 這套工具包將「**Survey 找文獻 → PDF 轉 AI 易讀版 → 分級建卡防幻覺 → 論文關係網/演進圖 → 主動檢索與 Hook 提醒**」整合成 Git 原生、可驗證、低 Token 消耗的開源工作流,支援 **Claude Code、Codex、Cursor、Gemini 與 Perplexity**。
7
+
8
+ ---
9
+
10
+ ## 為什麼需要這套工具?
11
+
12
+ | 常見痛點 | 本工具包的解法 |
13
+ |---|---|
14
+ | AI 做 Survey 時會編造不存在的 DOI | `plk verify` 直接拿輸出接 Crossref API 實查標題相似度 |
15
+ | AI 每次讀 PDF 燒掉數萬 Token、雙欄排版亂序 | `plk ingest` 轉成含 `=== p.N ===` 頁碼的平整 Markdown+自動切圖;原 PDF 封存本機不進 Git |
16
+ | AI 總結數據時偷換單位、把常識混充成論文寫的 | `plk cards` + `plk check` **逐字核對 `«原文引句»` 與數值單位相鄰**,找不到就拒絕寫入 |
17
+ | 論文越囤越多,不知道誰改善了誰、寫 Related Work 沒骨架 | `plk cites` 四源核對+`plk graph build` 編譯單檔互動演進圖 `evo_graph.html` |
18
+ | 除錯卡關時忘記自己其實存過解法論文 | `.claude/hooks/paper_hint.py` 在寫問題紀錄或同機制失敗 2 次時自動推送前 3 篇文獻 |
19
+
20
+ ---
21
+
22
+ ## 5 分鐘快速開始
23
+
24
+ ### 方式 A:直接安裝 `plk` CLI(推薦)
25
+ ```bash
26
+ pip install -e ".[all]" # 或從原始碼目錄執行 pip install .
27
+ plk init ./my-research # 在任意專案一鍵建好骨架與 tools
28
+ cd my-research
29
+ ```
30
+
31
+ ### 方式 B:直接 Clone 範本庫
32
+ ```bash
33
+ git clone https://github.com/Debiddo0506/paper-library-kit.git
34
+ cd paper-library-kit
35
+ pip install -r requirements.txt
36
+ python init_library.py
37
+ ```
38
+
39
+ ### 試玩 16 篇真實 AI Agent / RAG / 防幻覺論文 Demo
40
+ ```bash
41
+ python examples/demo_build.py
42
+ # 接著用瀏覽器打開 examples/demo_evo_graph.html
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 五階段工作流與對應工具/Prompt
48
+
49
+ | 階段 | `plk` 指令(或 `papers/tools/*.py`) | 對應 Prompt(繁中 / EN) |
50
+ |---|---|---|
51
+ | **1. Survey 與找缺口** | `plk lit`、`plk verify`、`plk chain`、`plk gap` | [`prompts/02_PROMPT_SURVEY_AND_GAP.md`](prompts/02_PROMPT_SURVEY_AND_GAP.md) |
52
+ | **2. PDF 轉 AI 易讀版** | `plk ingest`、`plk ocr`、`plk audit-pdfs` | [`prompts/03_PROMPT_TRIAGE_AND_CONVERT.md`](prompts/03_PROMPT_TRIAGE_AND_CONVERT.md) |
53
+ | **3. 分級建卡防幻覺** | `plk cards`、`plk check`、`plk meta-health`、`plk triage-apply` | [`prompts/04_PROMPT_CARDS_AND_TAGS.md`](prompts/04_PROMPT_CARDS_AND_TAGS.md)<br>+[`prompts/00_AGENT_LITERATURE_RULES.md`](prompts/00_AGENT_LITERATURE_RULES.md) |
54
+ | **4. 關係網與演進圖** | `plk backfill`、`plk rel-context`、`plk check-relations`、`plk cites`、`plk graph` | [`prompts/05_PROMPT_RELATION_NETWORK.md`](prompts/05_PROMPT_RELATION_NETWORK.md) |
55
+ | **5. 檢索與主動提醒** | `plk search`、`plk show`、`plk neighbors`、`plk path`、`.claude/hooks/paper_hint.py` | [`prompts/01_CLAUDE_SYSTEM_PROMPT.md`](prompts/01_CLAUDE_SYSTEM_PROMPT.md) |
56
+
57
+ ---
58
+
59
+ ## 測試與貢獻
60
+
61
+ ```bash
62
+ python -m unittest discover -s tests -v
63
+ ```
64
+
65
+ 歡迎看 [`ROADMAP.md`](ROADMAP.md) 與 [`CONTRIBUTING.md`](CONTRIBUTING.md) 認領 `good first issue`。
66
+ **授權**:MIT License(切勿將受版權保護的論文原始 PDF 推送到公開 GitHub)。
@@ -0,0 +1,26 @@
1
+ # Roadmap & Good First Issues
2
+
3
+ Contributions are very welcome! Below are concrete, self-contained tasks suited for first-time contributors and maintainers.
4
+
5
+ ## Parsers & Importers
6
+ - [ ] **Optional Marker / Docling backend for `ingest_pdf.py`** (`--parser pymupdf|marker|docling`) for equation-heavy PDFs.
7
+ - [ ] **BibTeX / RIS / Zotero CSV importer** -> auto-generate `ingest_bN.tsv` and pre-populated `meta.yaml`.
8
+ - [ ] **arXiv URL / ID direct downloader** (`plk ingest --arxiv 2310.06770`) fetching PDF + metadata in one command.
9
+ - [ ] **Improved multi-column / multi-panel figure bounding-box detector** in `ingest_pdf.py`.
10
+
11
+ ## Verification & Search
12
+ - [ ] **BM25 ranking fallback in `find_paper.py --fulltext`** (zero-dependency pure Python BM25 scoring).
13
+ - [ ] **Optional local embedding / hybrid rerank plugin** (`--semantic`, optional dependency) while keeping exact TSV/quote checks.
14
+ - [ ] **Auto-quote locator helper** (`plk quote-find <ID> "partial phrase"`) returning exact line numbers, page marker, and clean `«...»` string.
15
+ - [ ] **English CLI output mode (`--lang en`)** across `check_core_tags.py`, `find_paper.py`, and `gap_scan.py`.
16
+
17
+ ## Exporters & Agent Integrations
18
+ - [ ] **Obsidian Vault exporter** (`summary.md` + `[[wikilinks]]` for `builds_on`/`improves`/`tradeoff`).
19
+ - [ ] **Cursor `.cursorrules` / Windsurf / Codex `AGENTS.md` hook & rule adapters**.
20
+ - [ ] **MCP (Model Context Protocol) server wrapper** exposing `find_paper` (`search`, `show`, `neighbors`, `path`) as MCP tools.
21
+ - [ ] **Static English UI toggle in `evo_graph_template.html`** (EN / 繁中 language switch in the top bar).
22
+
23
+ ## Domain Presets (`config/presets/`)
24
+ - [ ] **ML / LLM Systems preset** (`paper_config.yaml` + `research_problems.md`)
25
+ - [ ] **Analog / Power Electronics IC Design preset**
26
+ - [ ] **Bioinformatics / Computational Biology preset**