> For AI agents: the complete documentation index is available at /Prism/llms.txt, the full documentation bundle is available at /Prism/llms-full.txt.

# Paper ↔ Code Repository Companion (`/code-bridge`)

Most ML, robotics, bioinformatics, physics, and systems papers ship an official **GitHub, GitLab, Hugging Face, Codeberg, or Bitbucket** repository—yet papers frequently omit subtle implementation choices (gradient clipping, normalization placement, EMA decay, default epsilon values) or diverge from their released `config.yaml`, and the repository URL is often hidden inside a PDF hyperlink (`\href{...}{Code}`), a footnote, or a project page rather than in Zotero's `URL`/`Extra`/`Abstract` fields.

Prism's **Paper ↔ Code Repository Companion (`/code-bridge`)** bridges your Zotero PDF and the official codebase directly inside the sidebar chat card—with zero API keys required for public repositories.

Prism — Paper ↔ Code Repository Companion (/code-bridge)

![Interactive Code Bridge card inside Zotero showing the auto-detected Context Bar 'Code Repo' pill, repository badge with stars, license & 24h cache status, clickable 3-column Hyperparameter Audit KPIs (Discrepancies · Undocumented · Matches), 4 interactive tabs (Mappings · Hyperparam Audit · Code Explorer · Repro), verified [p. N] PDF jump, and clickable remote #L line links.](/Prism/images/code-bridge.png)

Interactive Code Bridge card inside Zotero showing the auto-detected Context Bar 'Code Repo' pill, repository badge with stars, license & 24h cache status, clickable 3-column Hyperparameter Audit KPIs (Discrepancies · Undocumented · Matches), 4 interactive tabs (Mappings · Hyperparam Audit · Code Explorer · Repro), verified [p. N] PDF jump, and clickable remote #L line links.

:::tip Fail-Closed Privacy Guardrail (`Local Only`)
Whenever a paper matches your **Local-Only Privacy Guardrail** (e.g., `unpublished`, `confidential`, or a protected collection), Prism blocks **both** cloud LLM calls **and** outbound repository / project-page / registry discovery queries before anything leaves your machine. Inside the Privacy Blocked card, you can paste local Python/YAML code and audit 100% offline using your configured local LLM (e.g., Ollama or LM Studio).
:::

## 1. Ways to Launch

| Entry Point                                   | How It Works                                                                                                                                                                                                                                                                                                                                                              |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Automatic `Code Repo` Pill in Context Bar** | Even when Zotero's `URL`, `Extra`, and `Abstract` fields contain no link, Prism checks child notes & linked URL attachments, PDF clickable link annotations (`\href{...}{Code}`), PDF fulltext, and (for non-protected papers) project pages & Hugging Face Papers / arXiv in the background—surfacing a clickable **`Code Repo`** pill right in the sidebar Context Bar. |
| **Chat Slash Command**                        | Type **`/code-bridge`** in the sidebar composer. Pass an optional repository URL or focus hint, e.g. `/code-bridge https://github.com/owner/repo Eq. (5) loss` or `/code-bridge Algorithm 1`.                                                                                                                                                                             |
| **Library Right-Click**                       | Right-click any paper in Zotero Library → **`Prism Actions ▸ Explore Official Code Repo`**.                                                                                                                                                                                                                                                                               |
| **Command Palette**                           | Press **`⌘K`** / **`Ctrl+K`** → **Paper ↔ Code Companion**.                                                                                                                                                                                                                                                                                                               |
| **1-Click Card Handoffs**                     | Click **`Find in Code`** on any **X-Ray Lens Card** or **`Explore Code Repo`** on any **Math & Table Audit Card** to jump straight into the corresponding implementation.                                                                                                                                                                                                 |

## 2. Phase 1 — Official Repository Discovery & Caching

1. **Deep Multi-Layer Official-Repo Discovery:** Prism searches in a strict local-first cascade:
   - **Local (100% offline, always runs):** user-supplied URL, Zotero `URL` / `Extra` / `Abstract`, Zotero child notes & linked URL attachments, **PDF clickable hyperlink annotations** (via PDF.js `getAnnotations()`, Reader `.annotationLayer`, and raw PDF `/URI (...)` & hex byte scanning—recovering links hidden behind `[Code]` or `here`), and full PDF text (rejoining multi-column line-wrapped and kerning-spaced URLs across **GitHub, GitLab (including subgroups), Hugging Face / `hf.co`, Codeberg, and Bitbucket**).
   - **Zero-key online fallback (only when local scan finds nothing and the paper is NOT privacy-protected):** scrapes official **project pages** (e.g., `*.github.io/...` or `Project page:` links), queries **Hugging Face Papers API** & **arXiv API** (`<arxiv:comment>`), checks **OpenAlex**, and runs a strictly verified **GitHub Repository Search** by arXiv ID or distinctive title. Generic third-party library links (`pytorch/pytorch`, `numpy/numpy`, `huggingface/transformers`, etc.) are automatically filtered out unless the paper itself introduces that framework.
2. **Prioritized Multi-Platform Tree Indexing:** Fetches the repository tree across **GitHub, GitLab, Hugging Face, Codeberg, or Bitbucket** with zero required API keys, prioritizing `README.md`, dependency manifests (`pyproject.toml`, `requirements.txt`), hyperparameter configs (`*.yaml`, `*.yml`, `*.json`), and core algorithmic source files (`model*`, `loss*`, `train*`, `attention*`, etc.) under a strict token budget while skipping binary weights and lockfiles.
3. **24-Hour Local Disk Cache:** Fetched snapshots are cached locally in `<ZoteroProfile>/prism-cache/code-bridge/` for 24 hours (device-local, never synced). Click **`Refresh Live`** on any cached card to bypass the cache and pull fresh files.

## 3. Phase 2 — Interactive Code Bridge Card

Every `/code-bridge` run produces a persistent **Code Bridge Card** (synced conflict-free across devices via `PaperChatStore`) with a clickable **3-column Hyperparameter KPI strip** (`Discrepancies` · `Undocumented` · `Matches`) and 4 interactive tabs:

- **Mappings (`Equation & Algorithm ↔ Source`):** Maps `Eq. (3)`, `Eq. (5)`, `Algorithm 1`, or architectural modules to verified line-numbered snippets highlighted offline via bundled `highlight.js`. Every mapping pairs a clickable **`[p. N]`** PDF jump badge (verified against the real PDF text layer) with a clickable external GitHub / Hugging Face line link (`path/to/file.py#L42-L88`), implementation notes, **`Ask Follow-Up`**, **`Inspect File`**, and **`Toy Repro`** handoffs.
- **Hyperparam Audit (`Paper vs. Code`):** Combines Prism's **deterministic YAML/JSON/Python config parser** (handling scientific notation like `1 × 10^{-4}` vs. `1e-4` vs. `0.0001` with exact line numbers) and LLM synthesis to flag **`Discrepancy`** (e.g., paper states `lr = 1e-4` on `[p. 6]`, while `configs/default.yaml#L14` sets `3e-4`), **`Undocumented`** code settings (e.g., `grad_clip`, `ema_decay`, `label_smoothing`), and **`Matches`**.
- **Code Explorer:** Filter and browse every indexed repository file offline with line numbers, syntax highlighting, `Copy`, `Open`, and **`Ask About File`**.
- **Repro (`Reproducibility Readiness`):** Summarizes reproducibility status (`Ready` / `Partially Reproducible` / `Incomplete`), estimated GPU/VRAM requirements, key dependencies, copyable entry commands, missing external artifacts (checkpoints/datasets), and top open GitHub Issues relevant to reproduction.

## 4. Optional GitHub Personal Access Token (PAT)

Public GitHub, GitLab, Hugging Face, Codeberg, and Bitbucket repositories work out of the box with **zero API keys** (GitHub allows 60 unauthenticated API requests per hour). If you audit many GitHub repositories or want to inspect private GitHub repos:

1. Open **Prism Settings → MCP & Web → Paper ↔ Code Companion (`/code-bridge`)**.
2. Paste a read-only GitHub Personal Access Token (`ghp_…` or `github_pat_…`) and click **Save**.
3. The token is encrypted locally in Zotero's OS Login Manager (`Services.logins`)—it is never written to prefs, never synced, never included in settings backups, and never logged—raising your GitHub API rate limit to **5,000 requests/hour**.
