Skip to content

Commit a3529e3

Browse files
committed
feat(agent-workspace): render source-backed focus evidence
1 parent 454c1c0 commit a3529e3

17 files changed

Lines changed: 1673 additions & 733 deletions

docs/diataxis/en/explanation/development-progress-dashboard.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,48 @@ Verification for this slice:
2929
- `node --check src/frontend/workspace_panes.js`
3030
- `npm.cmd run build`
3131

32+
## 2026-06-07 Graph-Focus Source Rendering and AhaDiff Comparison
33+
34+
This slice corrects a remaining mismatch between the intended Knowledge Workspace interaction and the actual right-side graph-focus pane behavior.
35+
The earlier implementation opened the right pane with `matchedSpans`, but only rendered a compact evidence list.
36+
That meant the user could not inspect the original knowledge point in its normal rendered form and therefore could not see matched passages highlighted in-place.
37+
38+
Code-vs-plan reconciliation for this slice:
39+
40+
| Requirement | Current implementation evidence | Progress call |
41+
|---|---|---|
42+
| Render the original knowledge point in the right pane | `src/frontend/workspace_panes.js` now resolves `sourcePath`, reads the original markdown through `NoteConnectionStorage.readContent()`, and renders it through the shared `NoteConnectionMarkdownRuntime.renderMarkdownInto()` path instead of falling back to a snippet-only card. | Implemented |
43+
| Highlight matched passages inside the normal rendered document | The graph-focus pane now scores rendered paragraphs/blocks against `matchedSpans[].snippet` terms and applies a restrained highlight style in `src/frontend/styles.css` via `.agent-focus-match` / `data-agent-focus-highlight`. | Implemented |
44+
| Preserve backward compatibility when source rendering is unavailable | The previous summary + evidence-list view remains the fallback path when source markdown, storage access, or markdown runtime rendering is unavailable. | Preserved |
45+
| Keep the pane inside the same Reader-aligned rendering substrate | The focus pane reuses the same markdown runtime owner already used by the Tauri reply surface rather than creating a second markdown/mermaid/math render stack. | Implemented |
46+
47+
Verification for this slice:
48+
49+
- `npm.cmd exec -- jest src/agent_workspace.frontend.test.ts -t "graph focus|knowledge hits as file entries" --runInBand --no-cache`
50+
- `npm.cmd exec -- tsc --noEmit`
51+
52+
### AhaDiff comparison and implications
53+
54+
The latest `ref/ahadiff` codebase makes three moves that are directly relevant to this project's next phase.
55+
56+
1. It treats claims, evidence, runtime validation, and review state as first-class product surfaces, not hidden backend details.
57+
Evidence in `ref/ahadiff/src/ahadiff/claims/verify.py` is verified against concrete file/hunk anchors instead of being treated as a loose text summary problem.
58+
Viewer-side API boundaries are runtime-validated in `ref/ahadiff/viewer/src/api/schemas.ts`, which prevents UI drift from silently accepting malformed payloads.
59+
2. It productizes memory/review/challenge loops as durable state, not just one-shot outputs.
60+
`review.sqlite` is guarded as a real persistence boundary in `ref/ahadiff/src/ahadiff/review/database.py`, and the challenge loop in `ref/ahadiff/src/ahadiff/challenge/engine.py` converts missed understanding back into new learning signals.
61+
3. Its UI is organized around explicit task surfaces with typed stores, typed API clients, and route-level product pages.
62+
The viewer separates shell, API schemas, Zustand state, and focused pages/components rather than letting one large host file own too much of the interaction model.
63+
64+
For this project, that comparison sharpens the next gaps:
65+
66+
| Area | Current NoteConnection position | Gap vs AhaDiff-style maturity | Next move |
67+
|---|---|---|---|
68+
| Evidence model | Scoped citations and `matchedSpans` exist, but evidence is still mostly conversation-output metadata. | Missing a first-class evidence ledger that can survive beyond one answer turn and be reused by later agent flows. | Introduce a durable evidence/claim projection for agent answers and learning artifacts. |
69+
| Runtime contract validation | TypeScript contracts exist, but runtime response validation is still uneven across the frontend boundary. | UI can still trust structurally malformed payloads too often. | Expand runtime schema validation at the agent-workspace API boundary, especially for richer assistant payloads and future learning-state endpoints. |
70+
| Durable learning loop | Conversation memory exists, but challenge/review/adaptation loops are still shallow. | Missing a mechanism that turns failed understanding or weak answers back into future tasks/review signals. | Build an explicit agent learning loop: answer -> inspect evidence -> mark confusion/gap -> schedule guided follow-up. |
71+
| UI information architecture | Tauri workspace is improving, but large host files still own too much orchestration and the workspace still mixes retrieval, action, and diagnostics surfaces densely. | Interaction surfaces are less modular and less stateful than AhaDiff's page/store split. | Continue extracting workspace surfaces behind clear owners and move high-density diagnostics/learning views toward typed state modules. |
72+
| Cross-run quality governance | Foundation and runbook gates exist, but answer quality and learning effectiveness are not yet tracked with the same durability. | Missing a stable quality ratchet for agent-grounded learning outcomes. | Add persistent answer-quality / evidence-coverage / follow-up-effectiveness history that can drive policy rather than just reporting snapshots. |
73+
3274
## 2026-06-06 Active-Scope Miss Recovery and Document-Augmented RAG Patch
3375

3476
This patch resolves the live "what is water glass?" failure that reproduced while the WebView was already running on `npm run tauri:dev:mini:gpu`.
@@ -91,7 +133,7 @@ Code-vs-plan reconciliation:
91133
| Durable resource/index/workspace/session/memory/export substrate | Program A-F code exists under `src/resources/`, `src/indexing/`, `src/workspace/`, `src/session/`, `src/workflows/`, `src/memory/`, and `src/export/`. | Implemented |
92134
| Platform shell separation | `PlatformCapabilities`, `RenderMaterializer`, render routes, and workspace export bundles keep desktop/Godot/mobile materialization decisions explicit. Godot remains PNG-first because direct SVG import is unsafe. | Implemented |
93135
| Runtime graphdb/ANN production closure | graphdb/sqlite, external graphdb HTTP, local-vector rollout controls, external HTTP vector acceleration, runtime capability checks, and rollout profile payloads exist. | Operational, not production-closed |
94-
| Single route/runtime ownership | modular route registration exists, but conversation, runbook, turn-cache, rollout, and fallback orchestration still carry heavy ownership inside `src/server.ts`. | Partially complete |
136+
| Single route/runtime ownership | modular route registration exists, and runtime runbook modular-route operations now have a dedicated owner in `src/routes/runtimeRunbookRouteOps.ts`, but conversation, turn-cache, rollout, and other stateful fallback/orchestration logic still carry heavy ownership inside `src/server.ts`. | Partially complete |
95137
| Architecture reduction | Current line-count scan shows `src/server.ts` about 15,920 lines and `src/learning/KnowledgeLearningPlatform.ts` about 10,351 lines; major frontend hosts remain large. | Behind target |
96138

97139
Architecture progress map:
@@ -193,6 +235,13 @@ The next real improvement beyond that baseline is now also in code:
193235
- the reply policy is now also intent-aware, so comparison-style and how-to-style prompts can shape the explanation and next-action sections differently,
194236
- which means the Tauri agent surface can now look materially different even when the underlying knowledge result set is unchanged.
195237

238+
The next architecture-quality improvement beyond that rendering/semantics baseline is also now started:
239+
240+
- the agent-conversation reply composition path is no longer treated as permanent inline `KnowledgeLearningPlatform.ts` ownership,
241+
- a dedicated `src/learning/conversationComposer.ts` module now owns grouped knowledge-point composition plus scoped reply-section synthesis,
242+
- which lowers KLP pressure without changing the public `AgentConversationResponse` contract or the existing Tauri/browser rendering path.
243+
- this is intentionally a small, ownership-oriented extraction rather than a new abstraction layer: KLP still owns runtime state and persistence, while the new module owns pure data composition only.
244+
196245
The next gap is narrower now:
197246

198247
- broaden block coverage where future endpoints emit richer assistant payloads,

docs/diataxis/zh/explanation/development-progress-dashboard.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@
2828
- `node --check src/frontend/workspace_panes.js`
2929
- `npm.cmd run build`
3030

31+
## 2026-06-07 Graph-focus 原文渲染与 AhaDiff 对比
32+
33+
本切片修正的是知识工作区右侧 graph-focus pane 的剩余交互偏差。
34+
此前虽然右侧 pane 会收到 `matchedSpans`,但实际只渲染了一组紧凑的命中摘录列表。
35+
这意味着用户看不到“原知识点的正常渲染结果”,也就无法在原文语境内查看命中段落是否被正确高亮。
36+
37+
本切片的代码 / 方案对齐结果:
38+
39+
| 要求 | 当前实现证据 | 进度判断 |
40+
|---|---|---|
41+
| 右侧 pane 渲染原知识点正文 | `src/frontend/workspace_panes.js` 现在会解析 `sourcePath`,通过 `NoteConnectionStorage.readContent()` 读取原始 markdown,再经共享的 `NoteConnectionMarkdownRuntime.renderMarkdownInto()` 渲染,而不再只显示摘录卡片。 | 已实现 |
42+
| 在正常渲染的原文中高亮命中段落 | graph-focus pane 现在会用 `matchedSpans[].snippet` 对渲染后的段落/块进行评分匹配,并在 `src/frontend/styles.css` 中通过 `.agent-focus-match` / `data-agent-focus-highlight` 施加适度高亮。 | 已实现 |
43+
| 保留 source 渲染不可用时的降级路径 | 当 source markdown、storage access 或 markdown runtime 不可用时,仍然保留旧的 summary + evidence list fallback,不破坏现有交互。 | 已保留 |
44+
| 保持与现有 Reader-aligned 渲染基底一致 | graph-focus pane 复用了当前 Tauri 回复区域已在使用的 markdown runtime owner,而不是再造一套独立的 markdown / mermaid / math 渲染链。 | 已实现 |
45+
46+
本切片验证:
47+
48+
- `npm.cmd exec -- jest src/agent_workspace.frontend.test.ts -t "graph focus|knowledge hits as file entries" --runInBand --no-cache`
49+
- `npm.cmd exec -- tsc --noEmit`
50+
51+
### AhaDiff 对比与推进含义
52+
53+
最新版 `ref/ahadiff` 对本项目后续推进最有价值的地方,不是某个单点 UI,而是它把 claims、evidence、runtime validation、review state 都做成了一等产品面,而不是隐藏在后端或一次性结果中的细节。
54+
55+
1. 它把 evidence 当成可验证的产品对象,而不是回答字符串的附属说明。
56+
`ref/ahadiff/src/ahadiff/claims/verify.py` 会把 claim 严格绑定到 file/hunk anchor,而不是接受松散文本解释。
57+
`ref/ahadiff/viewer/src/api/schemas.ts` 也把 viewer 的 API 边界做成 runtime validation,而不是只信 TypeScript。
58+
2. 它把 review/challenge/adapt 做成 durable learning loop,而不是一次性输出。
59+
`review.sqlite``ref/ahadiff/src/ahadiff/review/database.py` 中是明确的持久化边界,`ref/ahadiff/src/ahadiff/challenge/engine.py` 会把“没学会的点”重新转成后续学习信号。
60+
3. 它的 UI 结构按任务面和状态面分离,typed API + typed store + page/component owner 更清晰。
61+
Shell、API schema、store、page/component 被拆开,避免一个大型宿主文件同时拥有太多产品状态与交互逻辑。
62+
63+
这对本项目的推进方向意味着以下缺口更清晰:
64+
65+
| 领域 | 当前 NoteConnection 位置 | 相比 AhaDiff 式成熟度的不足 | 下一步 |
66+
|---|---|---|---|
67+
| Evidence 模型 | 已有 scoped citation 与 `matchedSpans`,但 evidence 仍主要停留在单轮回答载荷里。 | 缺少能跨回合、跨学习任务复用的第一类 evidence ledger。 | 为 agent answer / 学习产物引入 durable evidence/claim projection。 |
68+
| Runtime contract validation | 已有 TypeScript 契约,但前端运行时边界的 schema validation 仍不均匀。 | UI 仍可能过度信任结构漂移的 payload。 | 在 agent-workspace API 边界继续扩展 runtime schema validation,尤其是 richer assistant payload 和后续学习状态端点。 |
69+
| Durable learning loop | 已有 conversation memory,但 challenge/review/adapt 的学习回路还很浅。 | 缺少把“未理解 / 弱回答”自动回写成后续学习任务或复习信号的机制。 | 构建显式 agent learning loop:answer -> inspect evidence -> mark confusion/gap -> schedule guided follow-up。 |
70+
| UI 信息架构 | Tauri workspace 正在改善,但大型 host 仍承载过多 orchestration,且 retrieval/action/diagnostics surface 仍较密。 | 交互面拆分与状态所有权还不如 AhaDiff 清晰。 | 继续从大型 workspace host 中抽离清晰 owner,并把高密度 diagnostics/learning surface 推向 typed state 模块。 |
71+
| 跨运行质量治理 | foundation 与 runbook gate 已存在,但 answer quality 与 learning effectiveness 还缺同等级持久治理。 | 缺少能稳定推动 agent 学习质量上升的 quality ratchet。 | 增加持久化的 answer-quality / evidence-coverage / follow-up-effectiveness history,用它驱动策略而不只做快照展示。 |
72+
3173
## 2026-06-06 active scope miss recovery 与 document-augmented RAG 修复
3274

3375
本次补丁修复了 WebView 已在 `npm run tauri:dev:mini:gpu` 中运行时复现的 “what is water glass?” 失败。
@@ -90,7 +132,7 @@
90132
| Resource/index/workspace/session/memory/export 持久化底座 | Program A-F 已在 `src/resources/``src/indexing/``src/workspace/``src/session/``src/workflows/``src/memory/``src/export/` 中落地。 | 已实现 |
91133
| 平台壳层分离 | `PlatformCapabilities``RenderMaterializer`、render routes、workspace export bundle 已显式化桌面/Godot/mobile materialization 决策。Godot 仍保持 PNG-first,因为直接 SVG 导入不可靠。 | 已实现 |
92134
| graphdb/ANN 运行时生产闭环 | graphdb/sqlite、external graphdb HTTP、local-vector rollout controls、external HTTP vector acceleration、runtime capability checks 与 rollout profile payloads 已存在。 | Operational,但未 production-closed |
93-
| 唯一路由 / 运行时所有权 | modular route registration 已存在,但 conversation、runbook、turn-cache、rollout、fallback 编排仍大量留在 `src/server.ts`| 部分完成 |
135+
| 唯一路由 / 运行时所有权 | modular route registration 已存在,runtime runbook 的 modular-route operation 现在也已有独立 owner `src/routes/runtimeRunbookRouteOps.ts`但 conversation、turn-cache、rollout、fallback 编排仍大量留在 `src/server.ts`| 部分完成 |
94136
| 架构缩减 | 当前行数扫描显示 `src/server.ts` 约 15,920 行、`src/learning/KnowledgeLearningPlatform.ts` 约 10,351 行;主要前端宿主文件仍偏大。 | 落后于目标 |
95137

96138
架构推进图:
@@ -192,6 +234,13 @@ Tauri-first reply rendering 基线已交付:
192234
- reply policy 现在也具备 intent awareness,因此 comparison-style 与 how-to-style prompt 可以把 explanation 和 next-action section 引导成不同语气与用途,
193235
- 这意味着即便底层知识命中集合没变,Tauri 中的 agent 输出也已经可以在结构上明显不同。
194236

237+
在这条渲染/语义基线之上,当前架构质量也向前推进了一步:
238+
239+
- agent-conversation reply composition 已不再被视为永久内联在 `KnowledgeLearningPlatform.ts` 中的所有权,
240+
- 新的 `src/learning/conversationComposer.ts` 现在负责 grouped knowledge-point 组装与 scoped reply section synthesis,
241+
- 这在不改变公开 `AgentConversationResponse` 契约、也不改现有 Tauri/browser 渲染路径的前提下,降低了 KLP 的局部压力。
242+
- 这次抽取刻意保持为“小而明确的所有权切分”,而不是再加一层抽象:KLP 继续持有 runtime state 与 persistence,新的模块只持有纯数据组合逻辑。
243+
195244
当前剩余缺口已经收窄为:
196245

197246
- 当更多端点开始返回 richer assistant payload 时,继续扩充 block 覆盖面,

docs/en/implementation_plan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ Land the current code-vs-plan assessment into the active implementation plan whi
2929
3. **P2: `server.ts` ownership reduction**
3030
- Extract turn-cache, alert-trend, runbook bridge, rollout-profile, and connector helper logic behind explicit modules.
3131
- Preserve endpoint names and response compatibility while moving ownership.
32+
- `src/routes/runtimeRunbookRouteOps.ts` now owns runtime runbook modular-route operation assembly; remaining P2 work should keep peeling route-layer composition out of `server.ts` without introducing pass-through facades around stateful logic.
33+
- Apply the same ownership-reduction rule to oversized learning-runtime helpers when they are pure data composers; agent conversation reply composition is now a candidate/module boundary rather than permanent KLP inline logic.
3234
4. **P3: Learning-platform domain extraction**
3335
- Continue extracting ingest/query/conversation/mastery/quality/tutor/memory ownership only when the new owner hides state or enforces invariants.
3436
- Avoid pass-through facades around `KnowledgeLearningPlatform.ts`.
3537
5. **P4: Agent workspace contract hardening**
3638
- Keep stream-first + sync fallback + replay compatibility.
3739
- Expand typed `assistantBlocks` coverage only through optional payloads and parity-tested capabilities.
40+
- Treat evidence rendering and evidence persistence as separate concerns: the current graph-focus pane now renders source markdown with in-place highlights, but future work still needs a durable evidence/claim surface rather than turn-local snippets only.
3841
6. **P5: Platform/export compatibility**
3942
- Keep Godot/mobile PNG-first materialization and export profile semantics explicit.
4043
- Keep core retrieval/synthesis free of shell-specific branches.
@@ -163,6 +166,8 @@ Align the active implementation plan with current code reality:
163166
- structured reply composition now splits the assistant output into overview / explanation / evidence summary / memory notice / action guidance blocks instead of emitting only one wrapped markdown answer.
164167
- those sections are now also semantically richer: the explanation is anchored to the strongest scoped knowledge point, the evidence summary reflects real scoped citations, and next-action guidance incorporates both scoped nodes and memory-action follow-through.
165168
- reply composition is now intent-aware as well: comparison-style and how-to-style prompts no longer reuse the exact same explanation/action phrasing as plain explanatory prompts.
169+
- reply-composition ownership is now explicitly treated as extractable architecture surface rather than permanent `KnowledgeLearningPlatform.ts` inline logic, and the current `conversationComposer` module boundary exists to reduce KLP gravity without changing the public response contract.
170+
- the grouped-knowledge-point and scoped-reply-section assembly path now has an explicit code owner in `src/learning/conversationComposer.ts`, so `KnowledgeLearningPlatform.ts` no longer has to own both session/runtime state and reply-composition detail in the same file.
166171

167172
#### Next execution order
168173

0 commit comments

Comments
 (0)