/spark-to-paper:ts-kg-buildfrom spark-to-paper
Builds a reusable research-pattern knowledge graph from a paper corpus, extracting problem→solution→story patterns for recall by ts-idea2story. Claude handles reasoning; scripts handle embeddings and clustering.
Ships in spark-to-paper. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
The product mined a corpus into a graph of research patterns (clusters of papers reframed as a
reusable problem → solution → story) that recall then surfaces for a new idea. Distilled: Claude
is the extractor and the cluster namer/summarizer; four small scripts do only the irreducible math.
A built KG matches the product's kg_ts/ schema, so ts-idea2story reads it unchanged.
Honesty (the user accepted this): a full, quality KG needs embeddings + a crawled corpus + (for review-weighted edges) a reviews corpus. It is not guaranteed great. Build the extraction + lite shelf unconditionally; the embedded/clustered path activates only when a
TS_EMBED_*endpoint is configured. TS already ships a built KG (kg_ts/) — reuse it; this skill is for a NEW domain/corpus.
corpus.jsonl — one paper per line: {paper_id, title, abstract, venue, year, doi, url, pages?, num_references?, keywords?, authors?, reviews?/review_score?}.domain label (e.g. ts, cv, nlp).TS_EMBED_MODEL / TS_EMBED_API_KEY / TS_EMBED_BASE_URL (OpenAI-compatible /embeddings; same pattern as the figure/image config).For each paper, read the title+abstract (+reviews if present) and write the reusable pattern. Append
these fields to each record in papers.jsonl:
base_problem — the underlying problem class (not this paper's specific instance).solution_pattern — the transferable mechanism/idea (not the implementation details).story — the most important field: the narrative reframe — "this work reframes X from Y
to Z" — the angle that makes the contribution compelling. Anti-summary rule: do NOT summarize
the abstract; reframe it into a reusable story. A summary ("this paper proposes a CNN for …") is
a failure; a story ("recasts dense prediction as a retrieval problem so labels become free") is the goal.application — where the pattern pays off.idea — a one-line transferable research idea seed.domain, sub_domains (free-text list).
Each field self-QC: reject <100-char filler or generic phrasing; never fabricate content not
supported by the abstract.Build the text to embed from the story-first fields (story + base_problem + solution_pattern), NOT the raw abstract — clustering on the reframe is what groups transferable angles:
# write items.jsonl: {"id": paper_id, "text": "<story> <base_problem> <solution_pattern>"}
python3 scripts/embed.py --in items.jsonl --out kg/pattern # needs TS_EMBED_* ; else SKIP -> lite shelf (step 4b)
python3 scripts/cluster.py --emb kg/pattern_emb.npy --meta kg/pattern_meta.jsonl --out kg/clusters.json
cluster.py returns members, per-member membership (cosine to centroid), coherence, and exemplars.
For each cluster, read its exemplars (the highest-membership papers' story fields) and write
cluster_meta.json = {cluster_id: {name, summary, llm_enhanced_summary, tier}}:
name — a distinctive 3–6 word research-STORY angle (e.g. "labels-for-free via retrieval").
BANNED generic words in the name: method, framework, model, approach, network, system, technique,
learning, based, novel, general. Name the angle, not the architecture.summary — one inductive sentence capturing what the cluster's papers share.llm_enhanced_summary — a richer one-sentence-per-facet distillation (problem / solution / when-it-wins).tier — A/B/C by size AND coherence (a big but incoherent cluster is NOT tier A; respect
cluster.py's coherence).python3 scripts/kg_build.py --papers papers.jsonl --clusters kg/clusters.json \
--cluster-meta cluster_meta.json --domain <domain> --out kg/
python3 scripts/kg_lint.py kg/ # must be ok:true
Produces kg/nodes_{paper,idea,pattern,domain}.json, kg/edges.json,
kg/knowledge_graph_stats.json — the schema ts-idea2story recalls over. Copy the
kg/pattern_emb.npy/_meta.jsonl/_manifest.json into kg/ too (recall uses them for the semantic
fine-rank; the manifest's model id stops recall from mixing embedding spaces).
If embed.py reports "not configured", skip clustering: write the per-paper patterns to
kg/patterns_shelf.jsonl and let ts-idea2story recall by reading the shelf in context (works
for small corpora like the 79-paper TS set). Label the KG lite — recall by reading. No fabrication
of clusters/edges you didn't compute.
uses_pattern(paper→pattern, quality), in_domain(paper→domain), belongs_to(pattern→domain),
works_well_in(pattern→domain, effectiveness = avg pattern quality − domain baseline, confidence).
quality comes from the raw review_score field (expected pre-normalized to ~0-1) when present, else a neutral 0.7 default.
Write logs/kg_build.io.md — INPUT (corpus size, domain, embeddings on/off), DECISIONS (extraction
self-QC rejects; cluster names + tiers + why), OUTPUT (counts from knowledge_graph_stats.json,
kg_lint result, lite-vs-full).
What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (spark-to-paper-skills/spark-to-paper-skills) — no native marketplace selected
npx claudepluginhub p/spark-to-paper-skills-spark-to-paper14 skills in this plugin
/ts-figure-optimizeThe suite's SOLE figure vectorizer: turn ONE raster scientific figure (a PNG/JPG, e.g. a gpt-image-2 schematic) into an editable, publication-ready figure via DrawAI's **key-free HYBRID** — local perception (SAM3 region detection + PaddleOCR + Box-IR layout, no account) then a deterministic hybrid build that keeps the approved render **pixel-exact** (a whole-canvas raster) and lays an **editable <text> overlay** on top (~0.91 SSIM), exported as a self-contained SVG + vector PDF + an editable PPTX. The render's full richness is preserved EXACTLY (it IS the approved image) while every label becomes editable. The original raster is always kept. Hybrid is the ONLY mode used: there is no Codex full-vector redraw (legacy/off — it needs an account, and a redraw of a dense figure loses fidelity) and no Claude-redraw fallback. If this runtime cannot be provisioned, the caller keeps the approved PNG as-is — never a lossy redraw. Independent of the paper pipeline — give it any figure image.
/ts-figure-svgPaperBanana+ — turn a paper's figure brief into a native, editable, publication-grade SVG. Stage 1 runs the OFFICIAL PaperBanana (dwzhu-pku/PaperBanana, pulled by `setup_paperbanana.py`, its own Retriever→Planner→Stylist→Visualizer→Critic pipeline) to produce candidate PNGs. Stage 2 is the "+": Claude LOOKS at the chosen PNG, extracts its DESIGN LANGUAGE (palette, type scale, spacing, idiom) into a style sheet, then redraws the figure FROM THE PAPER'S FACTS as real <rect>/<path>/<text> objects — never tracing pixels, never embedding the PNG. Stage 3 is a measured repair loop: `audit_svg.py` (stdlib, no renderer needed) catches overflow, text-on-text, icons cutting labels, stroke-scaled and canvas-clipped arrowheads, dangling connectors, sub-legible type, font-fallback glyphs, CSS-cascade colour traps and traced path-soup; ≥4 rounds, no upper bound while defects remain. Ends on a vector PDF verified on the real compiled page. Use when a figure must be editable and correct, not merely pretty.
Other plugins' skills for the same job