feat: research lens — recursive term explanations with concept chain - #661
Open
laohuan12138 wants to merge 1 commit into
Open
feat: research lens — recursive term explanations with concept chain#661laohuan12138 wants to merge 1 commit into
laohuan12138 wants to merge 1 commit into
Conversation
Select any term in rendered markdown to get a streaming AI explanation in an animated, draggable card; terms inside explanations recurse as child nodes, forming an explicit research path. - Concept chain panel: per-session tree with summaries and counts, subtree pruning, click-to-reopen with locate flash, per-session localStorage persistence - In-card follow-up questions: streamed markdown Q/A scoped to the term's explanation, count badge on chain nodes - Hover preview for already-explained terms (caret-based full-string match, CJK-safe); explained terms highlighted in the original text via the CSS Custom Highlight API (rule injected through CSSOM because Lightning CSS rejects ::highlight at build time) - Optional web grounding: keyless DuckDuckGo HTML search injects <web-search-results> context with source-citation instructions; failures degrade silently to model knowledge - Exports: Markdown note, self-contained interactive HTML mind map (embeds a .mm download for XMind/FreeMind), Anki-importable CSV - Settings → General 'Research mode' toggle (localStorage, synced across hook instances and tabs) - i18n: en / zh-CN / zh-TW; 16 unit tests for the pure helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a research lens (研究模式) to Pi Web: select any term while reading an AI answer and get a streaming AI explanation in place — then keep drilling down. Nested lookups form an explicit concept chain so the reader always knows how they got here, and the whole chain can be reviewed, exported and revisited.
Features
Recursive explanations
MarkdownBody, so any term inside them is selectable again — nesting is unbounded, and every nested card carries a breadcrumb (nginx › reverse proxy)thinking_delta) is shown inside the loading card, so the wait is visible instead of a silent spinnerConcept chain panel
localStorageIn-card follow-up questions
Review affordances
Web grounding (联网核实)
HTTPS_PROXYvia the existing global dispatcherExports (chain panel)
.mmXML embedded behind a download link for XMind/FreeMind users.csvwith directive headers + UTF-8 BOM, HTML answer side, follow-up Q/A appended, tags derived from the chain rootSettings
localStorage, synced live across hook instances and tabs)Implementation notes
POST /api/research/definestreams SSE. Model resolution: fastModelRuntime.create()first, fullcreateAgentSessionServices({ cwd })(cached per cwd) only when the provider is unknown — npm-package providers register only through extension loading. Streaming usesmodelRuntime.streamSimple(...)so custom API providers work{ scope, nodes, openIds }live in one atomically-swapped state so a session switch can never write one session's chain under another's key; deleting a session prunes its chain (forgetResearchChain)::highlight()rule is injected through CSSOM at runtime because Lightning CSS (Turbopack) rejects::highlight()at build time — a brokenglobals.cssblanks the appFiles
lib/term-research.ts(+16 unit tests),lib/web-search.ts,hooks/useTermResearch.ts,hooks/useResearchEnabled.ts,app/api/research/define/route.ts,components/research/{TermResearchOverlay,TermCard,ConceptChain}.tsxChatWindow(mount + gate),SessionSidebar(chain cleanup on session delete),SettingsPanel(toggle),globals.css(overlay styles), i18nen/zh-CN/zh-TW,AGENTS.mddocsTesting
tsc --noEmitclean, ESLint clean,npm test— 16 new unit tests for the pure helpers (context trimming, prompt building, chain markdown/FreeMind/Anki generation, escaping), all passing