12# paper-search-pro
13
14Multi-source literature search with adjustable depth. Four tiers, five data sources orchestrated by you (the main agent). Python helpers handle deterministic work; LLM classification is delegated to parallel Inline SubAgents — no external API key required.
15
16## When to use this skill
17
18- User wants to find academic papers / 找文献 / 论文搜索
19- User is preparing a literature review, systematic review (SR), scoping review, or meta-analysis
20- User wants to scope research on a topic for a thesis / proposal / coursework / news story
21- User asks "what research exists on X" / "find me papers about Y"
22- User uploads a query that suggests literature gathering (PICO, SPIDER, MeSH, RCT, etc.)
23
24## When NOT to use
25
26- User wants to **read** a specific paper (use PDF reader / download tool)
27- User wants to **summarize** a single known paper (use a summarizer)
28- User wants to **download** PDFs given DOIs (use paper-downloader-portable)
29- User already has a literature set and wants to write a review (use literature-set-review / factor-outcome-review)
30- User wants concept explanation, not papers ("what is prospect theory" → just answer)
31
32---
33
34## 🤖 Called by another agent / headless mode
35
36**If you are an agent driving this Skill for your own reasoning (not for a human
37who wants an HTML report)**, do NOT hand-run the 14-STEP recipe below. There is a
38single structured-data channel built for you:
39
40```bash
41PYTHONPATH=$PSP_HOME python3 -m scripts.agent_search "<query>" > result.json
42```
43
44One command runs the whole deterministic core — multi-strategy retrieve → dedup →
45heuristic relevance score (computed for every paper) → saturation signal → quota
46snapshot → per-paper journal metric — and prints **one JSON envelope** (no HTML,
47no PRISMA, no LLM classification SubAgent). The human path below is unaffected.
48That command gives you a deterministic **floor**, not the finished job — agent mode
49is *not* meant to stop at the machine output; references/agent_mode.md is where you
50layer your own semantic judgement on top to reach human-recipe quality (the command
51guarantees the floor; you supply the quality).
52
53📖 **Read references/agent_mode.md** for the full envelope schema, every flag
54(--verify, --min-relevance, --quartile, --min-impact, …), the relevance
55formula, error codes / exit codes, and source selection. This is the SSOT for
56agent callers — everything else in this section is just the pointer to it.
57
58Everything from here down is the **human-facing 14-STEP recipe** (HTML report +
59exports). Use it when the consumer is a person.
60
61---
62
63## 🔥 Execution discipline (read before running anything)
64
65Four invariants govern every step — ignoring them is the dominant failure mode in real sessions:
66
67- **A — NEVER cd into the Skill directory.** cd $PSP_HOME rebinds ./ to the Skill asset folder, so ./paper-search-results/... lands inside the Skill instead of the user's workspace (and a re-install wipes it). Run every helper from the user's PWD: PYTHONPATH=$PSP_HOME python3 -m scripts.<name> … > "$SEARCH_DIR/...". $PSP_HOME (STEP 0) is the install dir; $SEARCH_DIR (STEP 0) is an absolute path under the user's PWD.
68- **B — Dispatch classifier SubAgents in parallel.** STEP 6 puts up to 5 Task blocks in one assistant message; serial dispatch inflates Standard tier from ~10 to ~17 min. The worked example lives in STEP 6 — it is not repeated elsewhere.
69- **C — Announce every skip.** If you skip a STEP (budget / empty data / user choice), say *what* you skipped, *why*, *what's lost*, and *how to recover* (e.g. "re-run at --tier deep"). Skipping is fine; surprising the user is not.
70- **D — Read a step's cited reference when that step is non-trivial for this case.** Each STEP names a references/<file>.md carrying edge cases not duplicated here. You won't read all of them every run, nor should you — but skipping the reference for a step you are *actually about to run* is where boundary knowledge (dict-vs-list shapes, enrich-not-search, DOI casing) gets lost. Read the one in front of you.
71
72---
73
74## Architecture at a glance
75
76```
77You (main agent) drive the workflow per this SKILL.md.
78Python helpers do deterministic work — NO LLM inside, NO external API key.
79
80 L1 OpenAlex (primary) → deep top-100 multi-strategy
81 L2 PubMed (medical) → MeSH enricher (mostly; Audit-tier can search independently)
82 L2 arXiv (CS/preprint) → T-0~T-4 freshness sentinel
83 L3 Semantic Scholar → influentialCitationCount + abstract fallback
84 L3 CrossRef → funder / license / clinical-trial-number
85
86 Classification → Inline SubAgents (parallel, file-IPC, 5 per message)
87 Output → HTML (Shadcn) + MD + BibTeX/RIS/CSV + PRISMA-S log
88```
89
90---
91
92## The 4 tiers — pick first
93
94| Tier | Wall-clock | Papers | When to pick |
95|------|------------|--------|--------------|
96| Quick | ~5-8 min | 20-60 | "查一下" / "几篇" / "before tomorrow" / fast scope |
97| **Standard** (default) | ~10-17 min | 60-180 | Scope a topic / write background / general lit search |
98| Deep | ~30-45 min | 180-400 | "thorough" / writing a review article / 综述写作 |
99| Audit | ~2-3 hr | 400-1000+ | "systematic review" / "PRISMA" / "Cochrane" / "meta-analysis" |
100
101📖 **BEFORE picking, read references/tier_decision.md.** Tell the user your choice and why. For Audit, show limitations warning + get explicit confirmation before starting.
102
103---
104
105## The recipe
106
107For every literature search, follow these steps in order. Each step references a references/ file for details. Skip files only when the step is obviously trivial for the case at hand — and announce the skip per Rule C.
108
109### STEP 0 — Setup ($PSP_HOME + working directory)
110
111📖 BEFORE THIS STEP, read: references/setup.md.
112
113**Resolve the Skill install path into $PSP_HOME** (every later step uses PYTHONPATH=$PSP_HOME). Prefer explicit injection / agent env var; otherwise scan the known cross-agent install locations. If your harness already exposes this SKILL.md's absolute path, just export PSP_HOME="<that dir>" and skip the scan. 📖 Full rationale, why this can't be a script, and the complete path list: references/runtime_bootstrap.md.
114
115```bash
116PSP_HOME="${PSP_HOME:-${CLAUDE_SKILL_DIR:-${CODEBUDDY_SKILL_DIR:-}}}" # explicit / agent-injected
117if [ -z "$PSP_HOME" ]; then # else scan known installs
118 for base in "$HOME/.claude" "$HOME/.codex" "$HOME/.agents" "$HOME/.config/opencode" \
119 "$HOME/.codeium/windsurf" "$HOME/.config/goose" "$HOME/.cline" "$HOME/.roo" \
120 "$HOME/.copilot" ./.claude ./.codex ./.agents ./.cursor ./.opencode ./.windsurf; do
121 [ -f "$base/skills/paper-search-pro/SKILL.md" ] && PSP_HOME="$base/skills/paper-search-pro" && break
122 done
123fi
124[ -z "$PSP_HOME" ] && { echo "ERROR: paper-search-pro install not found. Set PSP_HOME to the dir containing SKILL.md."; exit 1; }
125export PSP_HOME; echo "Using Skill install: $PSP_HOME"
126```
127
128**Verify config keys** (executed from any cwd, never cd into the Skill dir):
129
130```bash
131PYTHONPATH=$PSP_HOME python3 -c \
132 "from scripts.config import load_config; c = load_config(); print('OK' if c.openalex_api_key and c.ncbi_email else 'MISSING — see references/setup.md')"
133```
134
135If "MISSING", point the user to references/setup.md (5 keys, all free, ~15 min total) and halt.
136
137**Set up the working directory variable** — every subsequent step uses $SEARCH_DIR:
138
139```bash
140SEARCH_ID="<topic_slug>_<tier>_$(date +%Y%m%d_%H%M%S)" # e.g. clt_education_quick_20260522_103045
141SEARCH_DIR="$(pwd)/paper-search-results/$SEARCH_ID"
142mkdir -p "$SEARCH_DIR/raw" "$SEARCH_DIR/batches" "$SEARCH_DIR/classifications"
143echo "Outputs will land in: $SEARCH_DIR"
144```
145
146$SEARCH_DIR is now an **absolute path under the user's PWD**. Use "$SEARCH_DIR/..." (quoted, with the variable) in every helper command below — not ./paper-search-results/....
147
148### STEP 1 — Plan the query (MANDATORY for all tiers)
149
150📖 BEFORE THIS STEP, read: references/query_planner.md.
151
152**Detect the report UI language** — UI_LANG (zh for Chinese queries, en for everything else) selects which UI language the final HTML report renders in. Paper titles / abstracts / authors / venues are NEVER translated — only the report's UI chrome. Pass --language $UI_LANG to STEP 12b.
153
154```bash
155UI_LANG=$(PYTHONPATH=$PSP_HOME python3 -m scripts.detect_language "$USER_QUERY")
156```
157
158The detector routes Japanese / Korean / European queries to **English** (the bundle ships only EN + ZH dictionaries; English is the international academic default). 📖 The exact Unicode rule and why kana is checked before Han live in references/runtime_bootstrap.md.
159
160**Determine the search language space** (search_language, axis 2 — *which literature ocean*, distinct from UI_LANG above which is only *report chrome*). 📖 The parsing SSOT is references/source_routing.md §"Language scope"; resolve the space here, before phrasing the query, because it changes how STEP 3's query is built. This is **additive and opt-in — a pure English query resolves to the en space with zero new prompts or behavior (R-19)**; everything below fires only for Chinese queries or explicit signals.
161
162- Read the persisted default config.search_language (auto | en | zh | both) and apply the priority ladder **flags > in-query markers > config > auto**. CJK presence is the mechanical fact from detect_language above; markers (CSSCI, 中文文献, SSCI, 知网, …) and non-signals (中科院一区, topic-about-China) are your semantic judgment per the §"Language scope" tables.
163- **auto + a Chinese (CJK) query + no language marker + no persisted value → ask ONE question before retrieving** (this is the human path's job; the CLI/agent path passes through instead). Two sentences, offer to persist, and don't re-ask later this session:
164
165 > 你用中文提问——文献要英文、中文,还是都要?顺便可以说"以后都这样",我就记成默认、下次不再问。
166
167 - "中文" / "都要" → enter that space (STEP 2 discipline routing takes over; report one line there).
168 - "英文" → v2.2 behavior (Chinese topic planned as an English query), report one line.
169 - "无所谓 / 都行" → **this run uses both** (Recall > Precision), not persisted; if the same user answers "无所谓" a second time, add one light offer to set both as default, then never ask again.
170 - Only an explicit "以后都…" persists to config.search_language (single answers never auto-persist).
171- **If a rank ambiguity (bare "Q1") also fired this run, merge both questions into ONE message** — ask language + platform together, never in two rounds (over-asking is a red line).
172- Once the space is known, phrase the query per references/query_planner.md §"Cross-language query handling": **zh keeps Chinese search terms (no translation)**, en uses the English terms (v2.2 behavior), both builds two sets.
173
174Apply PICO / SPIDER / PEO depending on domain:
175- Medical/clinical → PICO (Population/Intervention/Comparator/Outcome)
176- Qualitative → SPIDER
177- Scoping → PEO (Population/Exposure/Outcome)
178- Open-ended → just extract 2-4 concept blocks + 2-5 synonyms each
179
180**Journal-rank intent recognition (additive — only acts when the query mentions a partition).** Before you extract concept blocks, check whether the user's query carries a journal-rank/partition phrase — "中科院一区", "Q1", "JCR Q1", "SJR Q2", "顶刊 / top journal". If so, that phrase is a **filter condition, not a search term**, and it MUST be **stripped from the topic** before retrieval. This roots out the failure that motivated the whole feature: "中科院一区 情绪调节" used to send "中科院一区" to the search engine as a topic word, so it searched for papers *about* 中科院一区 instead of papers *on* 情绪调节 *filtered to* CAS tier 1. The deterministic parser does both jobs (extract + strip) for you:
181
182```bash
183PYTHONPATH=$PSP_HOME python3 -c "
184from scripts.rank_intent import parse_rank_intent
185i = parse_rank_intent('''<original user query>''')
186import json; print(json.dumps({
187 'platform': i.platform, 'tiers': i.tiers, 'quartiles': i.quartiles,
188 'top': i.top, 'ambiguous': i.ambiguous, 'cleaned_query': i.cleaned_query,
189 'stripped': i.matched}, ensure_ascii=False))
190"
191```
192
193Then act on the parse:
194- **cleaned_query** is the real topic — use it (NOT the raw query) for STEP 3 retrieval and the query plan. When the query had no rank phrasing, cleaned_query == query and nothing changes (R-19 default path is untouched).
195- **platform + tiers/quartiles/top** are the filter you will apply in STEP 10/11 — remember them; do not filter here.
196- **ambiguous == True** (a bare "Q1"/"Q2" with no platform word — the recogniser never guesses a platform): **ask the user one short question inline** before going further — *"按 JCR 还是 SJR 的 Q1 筛?顺便要不要设为以后的默认?"* The CLI/headless path cannot ask, so this inline question is specifically the human path's job.
197- If the query mentions no partition at all, skip this entirely — STEP 1 proceeds exactly as before.
198
199Even Quick tier needs a lightweight version of this step — never skip silently. Output: 1-3 search strategies (concept blocks + year range + work type filter). Write to "$SEARCH_DIR/query_plan.json" so PRISMA-S logger can pick it up later (STEP 13).
200
201### STEP 2 — Route supplemental sources within the STEP-1 language space
202
203📖 BEFORE THIS STEP, read: references/source_routing.md.
204
205**You make these routing calls by judging the query's domain — the reference's keyword tables are calibration examples, not a match list** (mechanical facts — CJK detection, explicit --flags — stay deterministic). Within the language space fixed in STEP 1, route the per-discipline boosters:
206
207- **English space** (en, or the English half of both) — unchanged from v2.2:
208 - Medical signals (RCT, PRISMA, MeSH, clinical, disease names) → enable PubMed
209 - CS/preprint signals (preprint, arXiv, NeurIPS, transformer, "最新", 2024+) → enable arXiv
210 - Cross-domain (e.g. "AI in radiology") → enable both
211 - Pure social science / humanities → OpenAlex only
212 - *(Judgment call: a core AI/CS query may also raise the primary engine to Semantic Scholar — see source_routing.md §"AI / CS queries → consider Semantic Scholar as primary".)*
213- **Chinese space** (zh, or the Chinese half of both) — route the Chinese boosters the same way, by discipline:
214 - Social-science / humanities signal → add **NSSD** (国家哲社文献中心; carries the CSSCI 收录标识 OpenAlex has ≈0 coverage of)
215 - Medical signal → add **yiigle** (中华医学期刊全文数据库); PubMed still covers MEDLINE-indexed 中华 journals, so the two are complementary
216 - Pure sci-tech with neither → Chinese side runs on OpenAlex only (sci-tech Chinese core journals mostly register DOIs, so OpenAlex covers them well)
217
218**Report one line** (axis-3 style — a statement, not a question; 22 §6.3). For an English-only run this is the existing PubMed/arXiv notice, unchanged (*"I detected medical + CS signals — also searching PubMed and arXiv. Override with --no-pubmed."*). For a Chinese space, e.g.:
219
220> 本次按「中英都要」检索;中文侧检测到社科主题,已加 NSSD(国家哲社文献中心)。想去掉说 --no-nssd,只查一边说"只要英文/中文"。
221
222**Coverage honesty rides with the notice:** if the zh space has a social-science topic but the user declined NSSD, add that OpenAlex hits ≈0 on CSSCI flagship journals (经济研究 / 管理世界 …), so that layer is missing. User can override any of this with an explicit instruction (a per-query override wins over everything).
223
224**On the --flag shorthands above (--no-nssd, --no-pubmed, --source …):** on this human path they are **natural-language override *notation*** — a compact way to write what the user can *say* ("去掉 NSSD" / "只查 OpenAlex"), which you (the LLM) interpret. They are **not executable CLI flags** — no script parses them here. The only real, script-parsed flags live on the agent/headless path (agent_search), and there the Chinese-source control is opt-**in**: --with-nssd / --with-yiigle (there is no --no-nssd / --source there). See references/agent_mode.md.
225
226### STEP 3 — Retrieve from OpenAlex (deep)
227
228📖 BEFORE THIS STEP, read: references/openalex_helper_cheatsheet.md.
229
230Always run OpenAlex first. (OpenAlex is the default primary source; only if primary_source is set in config.yaml or the OpenAlex quota is exhausted, see *Primary source selection & quota fallback* in references/source_routing.md for the additive SS-fallback flow — default behavior is unchanged.) For Standard+ tiers, use multi-strategy deep crawl:
231
232```bash
233PYTHONPATH=$PSP_HOME \
234 python3 -m scripts.openalex_helper double-sort "<query>" \
235 --n 50 --year-min 2018 \
236 > "$SEARCH_DIR/raw/openalex.json"
237```
238
239For Quick tier, single-strategy is fine:
240
241```bash
242PYTHONPATH=$PSP_HOME \
243 python3 -m scripts.openalex_helper search "<query>" \
244 --limit 30 --year-min 2018 \
245 > "$SEARCH_DIR/raw/openalex.json"
246```
247
248The full subcommand + flag reference (search / double-sort / seminal / reviews / journal-list / citation-network, all verified against argparse) is in references/openalex_helper_cheatsheet.md — read it before reaching for anything beyond the two commands above. For Deep+Audit, also call topic-specific subcommands (e.g. seminal, reviews, journal-list), append outputs to $SEARCH_DIR/raw/openalex_*.json, and federate them all together in STEP 5.
249
250### STEP 4 — Run L2 boosters (if enabled by STEP 2)
251
252📖 BEFORE THIS STEP, read: references/pubmed_helper_cheatsheet.md and references/arxiv_helper_cheatsheet.md.
253
254**PubMed — default mode is enrich, NOT search**:
255
256- **Standard / Deep tier**: enrich OA-found papers with MeSH terms (mutates the openalex.json file in place):
257 ```bash
258 PYTHONPATH=$PSP_HOME \
259 python3 -m scripts.pubmed_helper enrich \
260 --input-file "$SEARCH_DIR/raw/openalex.json" \
261 --output-file "$SEARCH_DIR/raw/openalex.json"
262 ```
263- **Audit tier with explicit MeSH query**: independent MeSH search (produces a new file to federate later):
264 ```bash
265 PYTHONPATH=$PSP_HOME \
266 python3 -m scripts.pubmed_helper search-mesh "Diabetes Mellitus, Type 2" \
267 --year-min 2020 --limit 30 --pub-type "Randomized Controlled Trial" \
268 > "$SEARCH_DIR/raw/pubmed.json"
269 ```
270- Generic pubmed_helper search is a fallback when no MeSH term is known — prefer enrich or search-mesh whenever possible.
271
272**arXiv — only if query contains freshness signals (preprint, 最新, 2024+):**
273
274```bash
275PYTHONPATH=$PSP_HOME \
276 python3 -m scripts.arxiv_helper freshness "<query>" \
277 --days 4 --limit 30 \
278 > "$SEARCH_DIR/raw/arxiv.json"
279```
280
281Subcommand reference:
282- arxiv_helper freshness <query> --days N --limit M [--all-cats]
283- arxiv_helper search <query> --limit M --sort submitted|relevance|lastUpdated [--all-cats]
284- arxiv_helper get <arxiv_id>
285
286**NSSD / yiigle — Chinese boosters (ONLY when STEP 1-2 put this run in the zh space, and only the one(s) the discipline routing selected):**
287
288Each is an independent primary source for the Chinese space (same role as ss_helper --search) and emits the **same UnifiedPaperEntity shape** as openalex.json, so STEP 5 federates them identically. Keep the query in **Chinese** (do NOT translate — query_planner §Cross-language) and write to raw/nssd.json / raw/yiigle.json:
289
290```bash
291# NSSD — Chinese social-sciences & humanities (adds the CSSCI-tier layer OpenAlex lacks)
292PYTHONPATH=$PSP_HOME \
293 python3 -m scripts.nssd_helper --search "<中文检索式>" \
294 --n 50 --year-min 2018 \
295 > "$SEARCH_DIR/raw/nssd.json"
296
297# yiigle — Chinese medical (中华医学期刊全文数据库; native-Chinese titles + abstracts)
298PYTHONPATH=$PSP_HOME \
299 python3 -m scripts.yiigle_helper --search "<中文检索式>" \
300 --n 50 --year-min 2018 \
301 > "$SEARCH_DIR/raw/yiigle.json"
302```
303
304Both degrade gracefully to [] on any network / HTTP failure (they never raise) — an empty file just federates to nothing. Both take **only** 题录 + 摘要 (compliance: no full-text download, no caching) and print their source attribution to stderr. --year-min filters client-side; drop it to keep all years.
305
306**config search_language: en but a Chinese query arrived (hard boundary 2):** do NOT enable Chinese boosters, but say one line — never a silent translation (22 §6.4):
307
308> 按你的默认(只查英文),我把中文主题规划成英文检索式了。想要中文文献这次说一声即可,想改默认说"以后…"。
309
310**User names 知网 / CNKI / 万方 / 维普 (marker hit + compliance):** these are closed subscription databases PSP does not scrape. Say one line, offer the substitute, don't re-argue (22 §6.5):
311
312> PSP 不接知网/万方(合规原因,不做封闭库抓取)。中文侧用 OpenAlex 中文底座 + NSSD(社科,含 CSSCI 标识)/yiigle(医学)覆盖;如需知网全文,结果里的题录可去知网人工检索。继续吗?
313
314### STEP 5 — Federate (dedup + merge)
315
316📖 BEFORE THIS STEP, read: references/source_routing.md §"Field priority table".
317
318Combine all retrieval results into a single deduped KG. **Default output is a dict keyed by canonical_key** — that's what rcs_parser expects later, so do NOT pass --as-list:
319
320```bash
321PYTHONPATH=$PSP_HOME \
322 python3 -m scripts.federated_kg_resolver \
323 --input-files "$SEARCH_DIR/raw/openalex.json" \
324 "$SEARCH_DIR/raw/pubmed.json" \
325 "$SEARCH_DIR/raw/arxiv.json" \
326 --output "$SEARCH_DIR/kg.json"
327```
328
329Pass only the input files you actually produced — skip ones that were not enabled by STEP 2. **If STEP 4 ran the Chinese boosters, add "$SEARCH_DIR/raw/nssd.json" / "$SEARCH_DIR/raw/yiigle.json" to the same --input-files list** — they carry the identical entity shape and federate exactly like the others (CJK-safe dedup is handled by the Phase 0 canonical-key fix, so distinct Chinese titles don't collapse). For an English-only run those files don't exist, so the call is byte-identical to v2.2 (R-19). This handles DOI normalization (arXiv X→x case), version stripping, E5b guard (same title+year but different DOIs are kept separate), and field-priority merge.
330
331--as-list exists but is only for consumers that want a sorted list (by citation_count); do not use it in this pipeline.
332
333### STEP 6 — Classify in parallel batches (LLM happens here — main agent + SubAgents)
334
335📖 BEFORE THIS STEP, read: references/classifier_subagent_prompt.md and references/rcs_rubric.md.
336
337Split the KG into batches of 10 papers each. Write to "$SEARCH_DIR/batches/batch_NNN.jsonl".
338
339**Before dispatch**, expand $PSP_HOME/references/rcs_rubric.md into the actual absolute path (e.g. /Users/alice/.claude/skills/paper-search-pro/references/rcs_rubric.md) and substitute it for {rubric_path} in the classifier prompt template. Each SubAgent runs in its own shell where $PSP_HOME is **not** exported — passing the literal $PSP_HOME token would leave the SubAgent unable to find the rubric, which silently degrades scoring quality. See references/classifier_subagent_prompt.md for the full placeholder table.
340
341🔥 **PARALLELISM IS MANDATORY** (Rule B):
342
343You MUST dispatch up to **5 classifier SubAgents in a single assistant message** using multiple Task tool_use blocks. Serial dispatch (one Task per message, waiting for each result) is the single biggest performance failure observed — it inflates Standard tier from ~10 min to ~17 min.
344
345✅ **CORRECT — in ONE assistant message:**
346
347```
348Task tool_use #1 → subagent_type="general-purpose", prompt="<classifier prompt for batch_001.jsonl>"
349Task tool_use #2 → subagent_type="general-purpose", prompt="<classifier prompt for batch_002.jsonl>"
350Task tool_use #3 → subagent_type="general-purpose", prompt="<classifier prompt for batch_003.jsonl>"
351Task tool_use #4 → subagent_type="general-purpose", prompt="<classifier prompt for batch_004.jsonl>"
352Task tool_use #5 → subagent_type="general-purpose", prompt="<classifier prompt for batch_005.jsonl>"
353```
354
355All five tool_use blocks live in the same <assistant> message. The harness fires them in parallel; you receive five tool_result blocks back together.
356
357❌ **WRONG — five separate messages (this is what serial dispatch looks like):**
358
359```
360Message N: Task tool_use #1 ─→ wait for result
361Message N+1: Task tool_use #2 ─→ wait for result ← SERIAL, makes Standard run 70% slower
362Message N+2: Task tool_use #3 ─→ wait for result
363...
364```
365
366If you have more than 5 batches, send 5-at-a-time across multiple messages — each message still contains 5 parallel Task blocks.
367
368Each SubAgent reads its batch file, applies the RCS rubric, and writes "$SEARCH_DIR/classifications/batch_NNN_result.json". Then merge classifications into the KG:
369
370```bash
371PYTHONPATH=$PSP_HOME \
372 python3 -m scripts.rcs_parser \
373 --input-dir "$SEARCH_DIR/classifications/" \
374 --kg "$SEARCH_DIR/kg.json" \
375 --output "$SEARCH_DIR/kg_classified.json"
376```
377
378### STEP 7 — Compute saturation curve (MANDATORY for all tiers)
379
380📖 BEFORE THIS STEP, read: references/stop_decision.md.
381
382This step is NOT optional, even for Quick. The curve.json drives both STEP 8 stop decision and STEP 12 HTML chart rendering. If you skip it, the report shows an empty curve and PRISMA-S transparency suffers.
383
384```bash
385PYTHONPATH=$PSP_HOME \
386 python3 -m scripts.discovery_curve \
387 --kg "$SEARCH_DIR/kg_classified.json" \
388 --output "$SEARCH_DIR/curve.json"
389```
390
391The curve has saturation_estimate (0-1) + ci_low + ci_high. Optional --prior-snapshots lets you chain curves across iterations; --papers-evaluated overrides the auto-count.
392
393### STEP 8 — Decide next action (MANDATORY)
394
395📖 BEFORE THIS STEP, read: references/stop_decision.md.
396
397This step is NOT optional. Make the decision **explicitly** — based on curve.json + tier budget + intent — and state the reasoning to the user. Do not skip based on intuition.
398
399Decision tree:
400- saturation < 0.6 AND budget remaining AND tier in {standard, deep, audit} → expand citations (STEP 9)
401- saturation > 0.85 OR budget exhausted → stop, write report (STEP 10+)
402- ambiguous → tell user the numbers and ask
403
404### STEP 9 — Expand citations (if applicable)
405
406📖 BEFORE THIS STEP, read: references/citation_chasing.md.
407
408For top-rcs papers (rcs >= 7), get the citation network:
409
410```bash
411PYTHONPATH=$PSP_HOME \
412 python3 -m scripts.openalex_helper citation-network <openalex_id> \
413 --refs-limit 25 --cited-by-limit 25 \
414 >> "$SEARCH_DIR/raw/citations.json"
415```
416
417Then loop back to STEP 5 (federate the new papers into the KG, then re-classify only the new entries in STEP 6).
418
419### STEP 10 — Enrich top-N papers (L3, optional but recommended)
420
421📖 BEFORE THIS STEP, read: references/ss_helper_cheatsheet.md and references/crossref_helper_cheatsheet.md.
422
423For papers with rcs >= 6, enrich with SS (influentialCitationCount + abstract fallback + tldr) and CrossRef (funder/license/clinical-trial-number). Both helpers consume a JSON **list** — the KG is currently dict-shaped. Convert first, enrich, then federate back; or supply a paper_list.json produced by data_materialization in STEP 12.
424
425For Quick tier, skipping STEP 10 is acceptable — but **announce the skip** per Rule C ("Skipped L3 enrichment → no influentialCitationCount or funder fields; re-run at --tier standard to include this").
426
427```bash
428# Semantic Scholar — adds influentialCitationCount + abstract fallback + tldr
429PYTHONPATH=$PSP_HOME \
430 python3 -m scripts.ss_helper \
431 --input-file "$SEARCH_DIR/paper_list.json" \
432 --mode enrich \
433 --output-file "$SEARCH_DIR/paper_list.json"
434
435# CrossRef — adds funder + license + refs + clinical_trial_number in one fetch
436PYTHONPATH=$PSP_HOME \
437 python3 -m scripts.crossref_helper \
438 --input-file "$SEARCH_DIR/paper_list.json" \
439 --mode all \
440 --output-file "$SEARCH_DIR/paper_list.json"
441```
442
443This adds ~135-170s for 100 papers — only do it on top-N, not the full set.
444
445**Optional (additive) — journal partitions (中科院 / JCR / SJR).**
446The multi-platform partition layer labels every paper with
447**all three** platforms and, when a tier was requested, filters on **one**. Like
448everything else in this step it is **opt-in and off by default — skip it and the
449report is byte-for-byte unchanged** (R-19). 📖 Read references/journal_metrics.md
450first (it is the SSOT for sources, the ISSN join, attribution, and R-04 naming).
451
452- **First use needs a one-time fetch** (init-once; data is pulled at runtime into
453 ~/.paper-search-pro/ranks/ and **never bundled in the repo**). If you have not
454 fetched before, run it once (and tell the user it is a one-time step):
455 ```bash
456 PYTHONPATH=$PSP_HOME python3 -m scripts.journal_rank fetch # all three
457 # or a single platform: ... journal_rank fetch --platform cas
458 PYTHONPATH=$PSP_HOME python3 -m scripts.journal_rank info # what's cached
459 ```
460- **Annotate (label all three platforms — do this once per result set):**
461 ```bash
462 PYTHONPATH=$PSP_HOME python3 -c "
463 from scripts import journal_rank, rank_filter
464 # ... load your papers as UnifiedPaperEntity list, then:
465 lk = journal_rank.load() # RankLookup | None (None → graceful degrade)
466 n = rank_filter.annotate_papers(papers, lk) # fills paper.journal_rank (三家全标)
467 "
468 ```
469 journal_rank.load() returns **None** when nothing is cached — then this layer
470 silently degrades (no partitions; the OpenAlex open-impact figure from the block
471 above is still the influence placeholder) and you tell the user they can
472 journal_rank fetch to enable partitions.
473- **Filter (only when a tier was requested — see STEP 11 for the full flow):** call
474 rank_filter.filter_by_rank(papers, platform, tiers=…, quartiles=…, top=…). It
475 returns (kept, filtered_out, no_platform_data) — the third bucket (journals not
476 on the chosen platform) is **reported, never silently dropped**.
477- **R-04 naming** is enforced for you in the serialised dict: only JCR exposes an
478 impact_factor (the real IF); 中科院"区" and SJR quartile are **分区/quartile**.
479
480### STEP 11 — Write the executive summary
481
482📖 BEFORE THIS STEP, read: references/summary_writer.md.
483
484Write a ~300-word executive summary in your own words based on the classified papers:
485- The field's main consensus
486- Key methods / theoretical frameworks
487- Notable disagreements or open questions
488- Top 3-5 most influential papers (by influential_citation_count when available)
489- *(Optional)* journal tier of the leading papers, **if** you attached SJR metrics in STEP 10 — phrase as "SJR分区 / 期刊影响力", never "影响因子 / JCR" (R-04). Skip this bullet entirely when no metrics were attached.
490
491Save to "$SEARCH_DIR/summary.md".
492
493**Partition default / ask / filter / report / switch flow (additive — only when partitions are in play).** When you annotated the multi-platform journal_rank in STEP 10, follow this flow; it is entirely opt-in and changes nothing on the default no-partition path (R-19):
494
495- **Factory default standard = JCR.** The persistent default lives in config rank.default_platform (out of the box: jcr; the user can set it to cas/sjr). The default platform only **labels** every paper — it does **not** filter unless the user actually asked for a tier.
496- **No partition mentioned → do not filter.** Just show all three platforms' labels per paper (STEP 10 annotate already did this) and let the user read / refine. Never invent a tier filter the user didn't ask for.
497- **A tier was requested (from STEP 1 intent or the user this round) → filter this once.** Use the STEP 1 parse: platform + tiers/quartiles/top. A per-request tier filter is **transient — never auto-persist it** to config. The persistent default is only ever changed when the user explicitly says "以后都用 X".
498- **Ambiguous bare "Q1" with no platform and no persistent default → ask one short question** (you should already have asked in STEP 1; if not, ask now): *"按 JCR 还是 SJR?顺带设默认吗?"* Small confirmations are welcome, but do not over-ask.
499- **Always report what this run did.** After filtering, tell the user in one line: *"本次按 {platform} 筛(留 N / 滤 M",* plus a light offer: *"可换中科院/JCR/SJR 或换档位、可设为以后的默认。"* Include the per-platform attribution (journal_rank.ATTRIBUTION[platform]).
500- **Switching standard or tier = RE-FILTER the already-annotated pool, NOT a re-search.** When the user then says "换成中科院二区" or "看看 SJR Q1", do **not** re-run the search. annotate_papers already stamped all three platforms onto the same candidate pool, so a switch is a pure in-memory re-filter — call rank_filter.filter_by_rank(papers, new_platform, tiers=new_tiers, …) again and it returns instantly. **Only when the re-filter leaves too few survivors** do you go back to STEP 3 and deepen the search (retrieve more, re-annotate, re-filter). This "切换=重筛不重搜" rule is what makes partition exploration cheap.
501- **Persisting the default** (only on an explicit "以后都用 X"): set rank.default_platform in ~/.paper-search-pro/config.yaml. Tier档位 is never persisted — only the platform default is.
502- **R-04 naming in the summary bullet too:** 中科院"区" and SJR quartile are **分区 / quartile**; only JCR IF(2024) is an **影响因子 / Impact Factor**. The OpenAlex 2yr-mean-citedness figure is "期刊影响力" (open), never a JIF.
503
504### STEP 12 — Render the report
505
506📖 BEFORE THIS STEP, read: references/output_files.md.
507
508```bash
509# 12a. Materialize data for the renderer (also writes sibling chart_data / paper_list / metadata / prisma_log)
510PYTHONPATH=$PSP_HOME \
511 python3 -m scripts.data_materialization \
512 --kg "$SEARCH_DIR/kg_classified.json" \
513 --summary "$SEARCH_DIR/summary.md" \
514 --query "<original query>" \
515 --tier "<quick|standard|deep|audit>" \
516 --search-id "$SEARCH_ID" \
517 --snapshots "$SEARCH_DIR/curve.json" \
518 --output "$SEARCH_DIR/report_data.json"
519
520# 12b. Render HTML (Shadcn webartifacts — only renderer; no size cap)
521# --language $UI_LANG selects EN vs ZH UI; the bundle ships with both
522# dictionaries inlined, $UI_LANG just picks which one mounts. Resolution
523# order inside the renderer is: explicit --language > metadata.language > en.
524PYTHONPATH=$PSP_HOME \
525 python3 -m scripts.html_renderer_webartifacts \
526 --data "$SEARCH_DIR/report_data.json" \
527 --output "$SEARCH_DIR/report.html" \
528 --query "<original query>" \
529 --language "$UI_LANG"
530
531# 12c. MD report (uses materialized-dir for speed)
532PYTHONPATH=$PSP_HOME \
533 python3 -m scripts.md_report \
534 --materialized-dir "$SEARCH_DIR" \
535 --query "<original query>" \
536 --tier "<quick|standard|deep|audit>" \
537 --output "$SEARCH_DIR/report.md"
538
539# 12d. Exports (BibTeX / RIS / CSV / papers.json — only rcs >= 5 by default)
540PYTHONPATH=$PSP_HOME \
541 python3 -m scripts.generate_exports \
542 --kg "$SEARCH_DIR/kg_classified.json" \
543 --output-dir "$SEARCH_DIR/" \
544 --min-rcs 5
545```
546
547data_materialization accepts --wall-clock-seconds if you tracked elapsed time yourself; otherwise the helper computes it from session timestamps when available.
548
549### STEP 13 — Write PRISMA-S log
550
551📖 BEFORE THIS STEP, read: references/prisma_s_checklist.md.
552
553```bash
554PYTHONPATH=$PSP_HOME \
555 python3 -m scripts.prisma_s_logger \
556 --search-id "$SEARCH_ID" \
557 --kg "$SEARCH_DIR/kg_classified.json" \
558 --user-query "<original query>" \
559 --tier "<quick|standard|deep|audit>" \
560 --query-plan "$SEARCH_DIR/query_plan.json" \
561 --snapshots "$SEARCH_DIR/curve.json" \
562 --output "$SEARCH_DIR/execution_log.json"
563```
564
565This captures the 16 PRISMA-S items for transparency / audit.
566
567### STEP 14 — Open the report + report to user
568
569**First**, auto-open the HTML report in the user's default browser (do NOT wait for the user to ask). Platform-aware Bash:
570
571```bash
572# macOS — most common dev setup
573open "$SEARCH_DIR/report.html"
574# Linux fallback — xdg-open "$SEARCH_DIR/report.html"
575# Windows fallback — start "" "$SEARCH_DIR/report.html"
576```
577
578Use open on macOS by default. If it fails (rare — only bare Linux containers), fall through to xdg-open then start. **Do NOT skip this step** — the user just waited 5-30 minutes for the report; they should see it the moment it's ready.
579
580**Then** tell the user:
581- "Opened report in your default browser." (1 line confirmation)
582- Where the report is on disk (absolute path: $SEARCH_DIR/report.html) — so the user can find it later
583- Top findings (3-5 sentences from your executive summary)
584- Any caveats — including any steps you skipped per Rule C (e.g. "PubMed wasn't queried because no medical signals were detected", "Skipped STEP 10 L3 enrichment because Quick tier; re-run at standard to include funder/license fields")
585
586---
587
588## Output convention
589
590📖 See references/output_files.md for the full directory layout. All paths below are **relative to the user's working directory (PWD)** — never the Skill asset directory.
591
592```
593$(pwd)/paper-search-results/<search_id>/
594├── report.html # Main deliverable (Shadcn style)
595├── report.md # Markdown copy
596├── papers.csv # Spreadsheet export
597├── papers.bib # Citation manager import (BibTeX)
598├── papers.ris # Alternative citation format
599├── papers.json # Full structured data
600├── kg_classified.json # Internal KG with RCS scores
601├── summary.md # Your executive summary
602├── execution_log.json # PRISMA-S 16-item log
603├── report_data.json # Renderer bundle
604├── chart_data.json # Sibling: chart series
605├── paper_list.json # Sibling: per-paper list
606├── metadata.json # Sibling: run metadata
607├── prisma_log.json # Sibling: PRISMA log JSON view
608├── curve.json # Saturation snapshot
609├── query_plan.json # STEP 1 output
610├── raw/ # Raw per-source dumps (openalex.json, pubmed.json, arxiv.json, citations.json)
611├── batches/ # batch_NNN.jsonl files
612└── classifications/ # batch_NNN_result.json files
613```
614
615---
616
617## Error handling
618
619📖 See references/error_handling.md. Common cases:
620
621| Error | What to do |
622|-------|-----------|
623| Config missing keys | Direct user to references/setup.md, halt |
624| Rate limit (SS 429 / NCBI 429) | Helper auto-retries; if persistent, drop that enricher |
625| OpenAlex 404 on DOI | Use title search fallback (helper handles) |
626| L2 booster returns 0 papers | Skip silently, note in PRISMA-S log via STEP 13 |
627| SubAgent classifier returns invalid JSON | rcs_parser.py has 5-layer fallback (regex parse) |
628| HTML output size | No size cap or fallback — html_renderer_webartifacts always produces the full Shadcn bundle. Typical 250-paper report is ~1.7 MB; pathological 1000+ paper Audit may reach 5-10 MB. All modern browsers handle 10+ MB HTML cleanly. |
629
630---
631
632## References (progressive disclosure — read the one for the step you're on)
633
634You won't read all of these every run, and shouldn't. Read a step's reference when you reach that step and it's non-trivial for the case (Rule D). **core** = read for its step; **cond** = only when its trigger fires.
635
636| File | Load | Read when |
637|------|------|---------|
638| tier_decision.md | core | choosing the tier (before STEP 0) |
639| setup.md | core | STEP 0 — config + 5-key acquisition |
640| runtime_bootstrap.md | cond | STEP 0/1 — only if $PSP_HOME env injection failed, or you need the full install-path list / language-routing rationale |
641| query_planner.md | core | STEP 1 — PICO / SPIDER / PEO frameworks |
642| source_routing.md | core | STEP 1 language scope (§"Language scope" SSOT) + STEP 2 routing + STEP 5 field-priority merge |
643| openalex_helper_cheatsheet.md | core | STEP 3 + STEP 9 — subcommands, params, gotchas |
644| pubmed_helper_cheatsheet.md | cond | STEP 4 — only if PubMed enabled |
645| arxiv_helper_cheatsheet.md | cond | STEP 4 — only if arXiv enabled |
646| classifier_subagent_prompt.md, rcs_rubric.md | core | STEP 6 — SubAgent prompt + RCS 0-10 rubric |
647| stop_decision.md | core | STEP 7 + STEP 8 |
648| citation_chasing.md | cond | STEP 9 — only if expanding citations |
649| ss_helper_cheatsheet.md, crossref_helper_cheatsheet.md | cond | STEP 10 — only if enriching top-N |
650| summary_writer.md | core | STEP 11 |
651| journal_metrics.md (SSOT) | cond | STEP 1 / STEP 10-11 — only if the user wants journal partitions (中科院 / JCR / SJR) or SJR metrics; ISSN join, attribution, R-04 naming |
652| output_files.md | core | STEP 12 — output dir layout (PWD-relative) |
653| prisma_s_checklist.md | core | STEP 13 |
654| agent_mode.md (SSOT) | cond | only when another agent / headless calls this Skill — agent_search envelope + flags |
655| error_handling.md | cond | any unexpected error |
656
657---
658
659## Examples
660
661### Example 1: Quick scan (5-8 min)
662
663User: "find 5-6 high-impact papers on prospect theory in decision making, classics + a couple recent ones"
664
665You: Pick Quick tier (signals: "5-6", "high-impact", short query). Run STEP 0-2 lightweight. In STEP 3 use openalex_helper seminal for classics + openalex_helper search for recent (year >= 2020). No L2 boosters in STEP 4 (pure social science). In STEP 6 classify 20-30 papers via 2 parallel SubAgents in one message. STEP 7 + 8 still run (curve renders in the report). Announce skip of STEP 9 + STEP 10 per Rule C. Render report.
666
667### Example 2: Standard ZH (10-17 min)
668
669User: "用 paper-search-pro 帮我找一些关于工作记忆训练干预的文献 老板让我看 我对这块完全不懂 要给老年人群体的最好 谢谢🙏"
670
671You: Pick Standard tier (default; signals: "找一些", "老板让我看"). Detect medical signal ("干预" + "老年") in STEP 2 → enable PubMed enricher. Query plan: PICO (P=elderly, I=working memory training, O=cognitive outcomes). OpenAlex double-sort top-100 in STEP 3. PubMed enrich of openalex.json in STEP 4. Federate in STEP 5 (dict output). Classify 60-180 papers via 4 batches × 5 SubAgents — **all 5 Tasks in one message** (Rule B). STEP 7 curve, STEP 8 expand if saturation < 0.6. Render report.
672
673### Example 3: Deep × Lit review writing (30-45 min)
674
675User: "I'm writing a proper literature review article on attachment and human-robot interaction in elderly care contexts. Need real depth..."
676
677You: Pick Deep tier ("proper literature review article" + "real depth"). Cross-domain (psychology + CS) in STEP 2 → enable arXiv freshness sentinel. SPIDER plan in STEP 1. OpenAlex double-sort top-200 + reviews subcommand in STEP 3. Classify 200+ papers via 8 batches in STEP 6 — dispatch 5 parallel Tasks per message, two waves. STEP 9 expand citations 2 hops. STEP 10 enrich top-50 with SS + CrossRef. Render report with PRISMA-S log.
678
679### Example 4: Audit × SR-prep (2-3 hr)
680
681User: "Need help — preparing a systematic review on dietary interventions for IBS in adults. Inclusion criteria: RCTs, adult populations (≥18), low-FODMAP or fiber-based interventions, English-language, published 2010-present."
682
683You: Pick Audit tier ("systematic review" + PICO + IC). **Show limitations warning first** ("This is not a PRISMA replacement — it's SR-prep assist. Cochrane Library + Embase still needed for full SR rigor."). Get user confirmation. STEP 4 use pubmed_helper search-mesh "Irritable Bowel Syndrome" --pub-type "Randomized Controlled Trial" for independent MeSH search. STEP 3 also call openalex_helper journal-list --preset Cochrane. STEP 10 add CrossRef enrichment for funder + clinical-trial-number. Render with PRISMA flow chart in STEP 12.
684