feat(gui): Implement RAG context visualization in Discussion history

This commit is contained in:
2026-05-04 11:26:36 -04:00
parent 3b876e9556
commit d4dc23720f
2 changed files with 21 additions and 1 deletions
@@ -31,7 +31,7 @@
- [x] Task: Implement the RAG Settings panel in `src/gui_2.py`. f57e2fe - [x] Task: Implement the RAG Settings panel in `src/gui_2.py`. f57e2fe
- [x] Add UI controls for choosing the RAG source, embedding model, and retrieval parameters. f57e2fe - [x] Add UI controls for choosing the RAG source, embedding model, and retrieval parameters. f57e2fe
- [x] Add a "Rebuild Index" button and status progress bar. f57e2fe - [x] Add a "Rebuild Index" button and status progress bar. f57e2fe
- [ ] Task: Implement retrieval visualization in the Discussion history. - [~] Task: Implement retrieval visualization in the Discussion history.
- [ ] Display "Retrieved Context" blocks with expandable summaries. - [ ] Display "Retrieved Context" blocks with expandable summaries.
- [ ] Add "Source" buttons to each block that open the file at the specific chunk's location. - [ ] Add "Source" buttons to each block that open the file at the specific chunk's location.
- [ ] Task: Implement auto-start/indexing status indicators in the GUI. - [ ] Task: Implement auto-start/indexing status indicators in the GUI.
+20
View File
@@ -2710,6 +2710,26 @@ def hello():
if read_mode: if read_mode:
content = entry["content"] content = entry["content"]
if content.strip(): if content.strip():
if '## Retrieved Context' in content:
rag_match = re.search(r'## Retrieved Context\n\n([\s\S]*?)(?=\n\n#|\Z)', content)
if rag_match:
rag_section = rag_match.group(1)
if imgui.collapsing_header('Retrieved Context'):
chunks = re.finditer(r'### Chunk (\d+) \(Source: (.*?)\)\n([\s\S]*?)(?=\n### Chunk|\Z)', rag_section)
for chunk_match in chunks:
idx = chunk_match.group(1)
path = chunk_match.group(2)
chunk_content = chunk_match.group(3)
if imgui.collapsing_header(f'Chunk {idx}: {path}'):
if imgui.button(f'[Source]##rag_{i}_{idx}'):
res = mcp_client.read_file(path)
if res:
self.text_viewer_title = path
self.text_viewer_content = res
self.text_viewer_type = Path(path).suffix.lstrip('.') if Path(path).suffix else 'text'
self.show_text_viewer = True
imgui.text_unformatted(chunk_content)
content = content[:rag_match.start()] + content[rag_match.end():]
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?") pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
matches = list(pattern.finditer(content)) matches = list(pattern.finditer(content))
is_nerv = theme.is_nerv_active() is_nerv = theme.is_nerv_active()