Skip to content

Commit 1cfca08

Browse files
docs(web): 整理文档结构并优化工作台左侧面板布局
- 将散落的设计/实现文档迁入 .docs-internal,完善 docs/zh 与安全说明 - 支持左侧面板拖拽调整宽度,更新 AGENTS 与链接校验脚本 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9245500 commit 1cfca08

49 files changed

Lines changed: 1488 additions & 2790 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.docs-internal/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Internal Documentation
2+
3+
工程契约、设计说明与 ADR。供贡献者与 AI Agent 阅读,不是公开文档入口。
4+
5+
公开文档见 [docs/README.md](../docs/README.md)
6+
7+
## 维护规则
8+
9+
- 不包含凭据、个人路径、个人信息或来源敏感描述。
10+
- 公开文档(`docs/``README*.md`)不得链接本目录。
11+
- 修改文档后运行 `npm run smoke:docs`
12+
13+
## 工程契约
14+
15+
| 文档 | 说明 |
16+
| --- | --- |
17+
| [copilotkit-ag-ui-frontend-protocol.md](engineering/copilotkit-ag-ui-frontend-protocol.md) | AG-UI 前端协议与事件契约 |
18+
| [config-management-api.md](engineering/config-management-api.md) | 配置 REST API 与 `run_config` 合并模型 |
19+
| [backend-rest-api-reference.md](engineering/backend-rest-api-reference.md) | 后端 REST API 完整参考 |
20+
| [supported-databases.md](engineering/supported-databases.md) | 数据源 adapter 与注册说明 |
21+
| [data-tasks-workbench-design.md](engineering/data-tasks-workbench-design.md) | Web `/data-tasks` 工作台 UI 设计 |
22+
| [tui-protocol-client.md](engineering/tui-protocol-client.md) | TUI CopilotKit 协议客户端 |
23+
| [tui-state-management.md](engineering/tui-state-management.md) | TUI 状态管理与 Store API |
24+
25+
## 架构与设计
26+
27+
| 文档 | 说明 |
28+
| --- | --- |
29+
| [agent-context-management-design.md](engineering/agent-context-management-design.md) | Agent 上下文治理设计 |
30+
| [conversation-memory-design.md](engineering/conversation-memory-design.md) | 会话记忆设计 |
31+
| [skill-system-design.md](engineering/skill-system-design.md) | Skill 系统设计 |
32+
| [file-asset-workspace-artifact-knowledge-design.md](engineering/file-asset-workspace-artifact-knowledge-design.md) | 文件资产、工作区与知识库设计 |
33+
| [context-turn-grouping-unification-design.md](engineering/context-turn-grouping-unification-design.md) | Context turn 分组统一设计 |
34+
| [tokenizer-caching.md](engineering/tokenizer-caching.md) | Tokenizer 缓存实现说明 |
35+
36+
## ADR
37+
38+
| 文档 | 说明 |
39+
| --- | --- |
40+
| [adr-0001-context-governance-fail-closed.md](engineering/adr-0001-context-governance-fail-closed.md) | 上下文治理 fail-closed |
41+
| [adr-0002-context-compile-every-mastra-step.md](engineering/adr-0002-context-compile-every-mastra-step.md) | 每 Mastra step 编译上下文 |
42+
| [adr-0002-memory-authority-and-mastra-memory-boundary.md](engineering/adr-0002-memory-authority-and-mastra-memory-boundary.md) | 记忆权威与 Mastra memory 边界 |
43+
| [adr-0003-context-layering-and-naming.md](engineering/adr-0003-context-layering-and-naming.md) | 上下文分层与命名 |

.docs-internal/engineering/adr-0002-memory-authority-and-mastra-memory-boundary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ Neutral:
171171

172172
## Related Documents
173173

174-
- `docs/engineering/2026-06-23-memory-context-prompt-walkthrough.html`
174+
- [mastra-memory-controlled-integration.html](./mastra-memory-controlled-integration.html)
175175
- `docs/plans/2026-06-23-memory-context-source-unification.md`
176176
- `docs/plans/2026-06-23-mastra-memory-controlled-integration.md`

.docs-internal/engineering/adr-0003-context-layering-and-naming.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ Negative:
571571

572572
## Related Documents
573573

574-
- `docs/engineering/context-governance-pipeline.svg`
575-
- `docs/engineering/context-governance-pipeline.mmd`
576-
- `docs/engineering/adr-0002-memory-authority-and-mastra-memory-boundary.md`
577-
- `docs/plans/2026-06-23-memory-context-source-unification.md`
578-
- `docs/engineering/2026-06-23-memory-context-prompt-walkthrough.html`
574+
- [context-governance-pipeline.svg](./context-governance-pipeline.svg)
575+
- [context-governance-pipeline.mmd](./context-governance-pipeline.mmd)
576+
- [adr-0002-memory-authority-and-mastra-memory-boundary.md](./adr-0002-memory-authority-and-mastra-memory-boundary.md)
577+
- [mastra-memory-controlled-integration.html](./mastra-memory-controlled-integration.html)
578+
- [agent-context-architecture.html](./agent-context-architecture.html)

.docs-internal/engineering/agent-context-management-design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Context Sources
4949
- 摘要模型的具体 provider 选择。
5050
- Knowledge retrieval 的召回和 rerank 算法。
5151

52-
这些事项保留在仓库根目录的 `todo_list.md`
52+
这些事项作为后续迭代工作跟踪,不在本文档展开
5353

5454
## 3. 当前实现
5555

.docs-internal/engineering/config-management-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
关联:
77

88
- [copilotkit-ag-ui-frontend-protocol.md](./copilotkit-ag-ui-frontend-protocol.md)(AG-UI run 协议,配置 run 时如何透传)
9-
- [apps/web/src/app/data-tasks/DESIGN.md](../../apps/web/src/app/data-tasks/DESIGN.md)(前端三层配置模型)
9+
- [data-tasks-workbench-design.md](./data-tasks-workbench-design.md)(前端三层配置模型)
1010

1111
## 1. 背景与定位
1212

apps/web/src/app/data-tasks/DESIGN.md renamed to .docs-internal/engineering/data-tasks-workbench-design.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Data Agent Session Page — Design
1+
# Data Tasks Workbench — Design
22

3+
> **Code:** `apps/web/src/app/data-tasks/`
34
> **Last verified against code:** 2026-06-24
45
> **Maintenance:** When changing `TaskConsole`, layout/responsive behavior, config
56
> REST integration, or design tokens, update this document in the same change.
@@ -10,13 +11,13 @@ This page (`/data-tasks`) is a **data-agent workbench** built on CopilotKit v2
1011
the backend actually streams. There is no mock scenario or scripted demo.
1112

1213
The backend protocol surface is the source of truth for what is renderable; see
13-
[copilotkit-ag-ui-frontend-protocol.md](../../../../../.docs-internal/engineering/copilotkit-ag-ui-frontend-protocol.md).
14+
[docs/zh/reference/agent-runtime.md](../../docs/zh/reference/agent-runtime.md).
1415
This document describes how the page maps that protocol to UI.
1516

1617
## Layout
1718

1819
Three-column responsive grid, driven by
19-
[workspace-layout.ts](./workspace-layout.ts) rather than static Tailwind
20+
[workspace-layout.ts](../../apps/web/src/app/data-tasks/workspace-layout.ts) rather than static Tailwind
2021
breakpoints:
2122

2223
```
@@ -58,8 +59,8 @@ Layout behavior:
5859
right console first, then collapse the left panel. User preferences are
5960
restored when space returns.
6061
- When the viewport cannot fit a docked right panel (`canDockRightPanel` in
61-
[workspace-layout.ts](./workspace-layout.ts)), `TaskConsole` opens in
62-
[TaskConsoleDrawer.tsx](./components/task-console/TaskConsoleDrawer.tsx)
62+
[workspace-layout.ts](../../apps/web/src/app/data-tasks/workspace-layout.ts)), `TaskConsole` opens in
63+
[TaskConsoleDrawer.tsx](../../apps/web/src/app/data-tasks/components/task-console/TaskConsoleDrawer.tsx)
6364
(full-screen overlay, Esc / backdrop dismiss) instead of the grid column. The
6465
chat header「打开控制台」button opens the drawer on narrow viewports.
6566
- Opening `WorkspaceConfigPanel` makes the workspace two-column: left config
@@ -68,12 +69,12 @@ Layout behavior:
6869

6970
## Workspace configuration model (DB / KB / MCP / LLM / Skill)
7071

71-
State + schema live in [data-task-state.ts](./data-task-state.ts); UI lives in
72-
[page.tsx](./page.tsx). Backend config I/O is handled by
73-
[use-workspace-config-api.ts](./hooks/use-workspace-config-api.ts), which wraps
72+
State + schema live in [data-task-state.ts](../../apps/web/src/app/data-tasks/data-task-state.ts); UI lives in
73+
[page.tsx](../../apps/web/src/app/data-tasks/page.tsx). Backend config I/O is handled by
74+
[use-workspace-config-api.ts](../../apps/web/src/app/data-tasks/hooks/use-workspace-config-api.ts), which wraps
7475
`lib/config-api`. The backend-side contract and runtime capability surface:
7576

76-
- [config-management-api.md](../../../../../.docs-internal/engineering/config-management-api.md)
77+
- [docs/zh/reference/configuration-api.md](../../docs/zh/reference/configuration-api.md)
7778
— REST contract for config management and the **`run_config` merge model**
7879
section (server-side merge of workspace defaults, session overrides, and per-run
7980
selections).
@@ -230,7 +231,7 @@ Two `useAgentContext` items (+ `forwardedProps.datasourceId`):
230231
- `datasource_id` — the one field the backend currently honors (protocol §2).
231232
- `run_config` — single forward-compatible payload built by `buildRunConfig`
232233
matching the **`run_config` merge model** in
233-
[config-management-api.md](../../../../../.docs-internal/engineering/config-management-api.md);
234+
[docs/zh/reference/configuration-api.md](../../docs/zh/reference/configuration-api.md);
234235
**ids / selections only, no secrets**:
235236

236237
```jsonc
@@ -332,9 +333,9 @@ flowchart LR
332333

333334
- The `CopilotKit` provider points at `NEXT_PUBLIC_AGENT_RUNTIME_URL`
334335
(default `http://127.0.0.1:8787/api/copilotkit`) with `agentId="dataAgent"`.
335-
- [use-data-agent-run.ts](./use-data-agent-run.ts) subscribes to the agent and
336+
- [use-data-agent-run.tsx](../../apps/web/src/app/data-tasks/use-data-agent-run.tsx) subscribes to the agent and
336337
reduces the AG-UI stream into a `LiveRun` via
337-
[live-run-state.ts](./live-run-state.ts).
338+
[live-run-state.ts](../../apps/web/src/app/data-tasks/live-run-state.ts).
338339
- Events consumed: `RUN_STARTED/FINISHED/ERROR`, `STATE_SNAPSHOT/DELTA`,
339340
`ACTIVITY_SNAPSHOT/DELTA` (plan + step), `TOOL_CALL_*`, and
340341
`CUSTOM` (`sql_audit`, `artifact`, `token_usage`, `workspace.metadata`,
@@ -474,8 +475,8 @@ The middle→right linkage mirrors the Step / Tool hierarchy:
474475

475476
## Design tokens and visual semantics
476477

477-
The workbench uses Tailwind v4 CSS variables from [globals.css](../globals.css)
478-
and shared class bundles from [ui-tokens.ts](./ui-tokens.ts). New UI should prefer
478+
The workbench uses Tailwind v4 CSS variables from [globals.css](../../apps/web/src/app/globals.css)
479+
and shared class bundles from [ui-tokens.ts](../../apps/web/src/app/data-tasks/ui-tokens.ts). New UI should prefer
479480
semantic tokens over hardcoded `slate-*` / `blue-*` colors so the dense dashboard
480481
can evolve consistently.
481482

TOKENIZER_CACHING.md renamed to .docs-internal/engineering/tokenizer-caching.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Tokenizer Cache Implementation Note
1+
# Tokenizer Cache
22

3-
更新时间:2026-06-22
4-
状态:基础缓存已实现;request path 预加载尚未实施
3+
> **Code:** `packages/agent-runtime/src/context/token-counter.ts`
4+
> **Updated:** 2026-06-22
5+
> **Status:** 基础缓存已实现;request path 预加载尚未实施
56
67
## Current Behavior
78

apps/tui/src/protocol/README.md renamed to .docs-internal/engineering/tui-protocol-client.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# CopilotKit Protocol Client
1+
# TUI Protocol Client
22

3-
Node client for the DataAgent CopilotKit single-route runtime.
3+
> **Code:** `apps/tui/src/protocol/`
4+
> **Maintenance:** Update when changing CopilotKit client request shape or SSE parsing.
45
56
## Request Shape
67

apps/tui/src/state/store-usage-examples.md renamed to .docs-internal/engineering/tui-state-management.md

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,109 @@
1-
# TUI Store 使用指南
1+
# TUI State Management
2+
3+
> **Code:** `apps/tui/src/state/`
4+
> **Maintenance:** Update this document when changing TUI store shape, selectors, or session stats.
5+
6+
This directory contains the state management implementation for the TUI application.
7+
8+
## Structure
9+
10+
### Symbolic Links (Reused from Web App)
11+
- `live-run-state.ts``../../../web/src/app/data-tasks/live-run-state.ts`
12+
- Core LiveRun state types and reducer logic
13+
- Handles run status, plan tasks, events, artifacts, audits, tool calls
14+
- Event processing for AG-UI protocol (RUN_STARTED, RUN_FINISHED, TOOL_CALL_*, etc.)
15+
16+
- `data-task-state.ts``../../../web/src/app/data-tasks/data-task-state.ts`
17+
- Data task types (TimelineEvent, DataArtifact, SchemaTable, etc.)
18+
- Utility functions for data step kinds and labels
19+
20+
- `workspace-layout.ts``../../../web/src/app/data-tasks/workspace-layout.ts`
21+
- Layout constants and utilities (required by data-task-state.ts)
22+
23+
### TUI-Specific Files
24+
25+
#### `tui-state.ts`
26+
Extends `LiveRun` with TUI-specific fields:
27+
- `messages: DisplayMessage[]` - Chat message history for display
28+
- `inputBuffer: string` - Current user input buffer
29+
- `connectionStatus: 'connected' | 'disconnected' | 'error'` - WebSocket connection status
30+
- `threadId?: string` - Current session thread ID
31+
- `lastError?: string` - Last error message
32+
33+
Functions:
34+
- `createInitialTuiState()` - Create initial state
35+
- `updateConnectionStatus()` - Update connection status
36+
- `updateInputBuffer()` / `clearInputBuffer()` - Manage input buffer
37+
- `setThreadId()` - Set thread ID
38+
39+
#### `message-history.ts`
40+
Message accumulation and display formatting:
41+
- `addUserMessage()` - Add user message to history
42+
- `addAssistantMessage()` - Add assistant message to history
43+
- `addSystemMessage()` - Add system message to history
44+
- `updateLastAssistantMessage()` - Update last assistant message (for streaming)
45+
- `appendToLastAssistantMessage()` - Append delta to last assistant message
46+
- `finalizeLastAssistantMessage()` - Mark streaming as complete
47+
- `formatMessageForDisplay()` - Format message for terminal display
48+
- `formatMessagesForDisplay()` - Format all messages
49+
- `getRecentMessages()` - Get last N messages
50+
51+
#### `store.ts`
52+
Central state store with observer pattern:
53+
- Singleton `StateStore` class
54+
- Subscribe to state changes
55+
- Wrapper methods for all state operations
56+
- Integrates `reduceLiveRunEvent` for AG-UI protocol events
57+
58+
#### `index.ts`
59+
Re-exports all state types and functions for easy consumption.
60+
61+
## Usage
62+
63+
```typescript
64+
import { store } from './state/store';
65+
import { formatMessagesForDisplay } from './state';
66+
67+
// Subscribe to state changes
68+
const unsubscribe = store.subscribe((state) => {
69+
console.log('State updated:', state);
70+
});
71+
72+
// Add user message
73+
store.addUserMessage('Query sales data');
74+
75+
// Handle protocol event
76+
store.handleLiveRunEvent({ type: 'RUN_STARTED' });
77+
78+
// Update connection status
79+
store.setConnectionStatus('connected');
80+
81+
// Stream assistant response
82+
store.addAssistantMessage('', true); // Start streaming
83+
store.appendToAssistantMessage('Analyzing ');
84+
store.appendToAssistantMessage('data...');
85+
store.finalizeAssistantMessage(); // Complete streaming
86+
87+
// Format messages for display
88+
const state = store.getState();
89+
const formatted = formatMessagesForDisplay(state.messages);
90+
```
91+
92+
## Integration with Protocol
93+
94+
The state management integrates with the CopilotKit protocol through `reduceLiveRunEvent`:
95+
96+
1. **Run Lifecycle**: `RUN_STARTED`, `RUN_FINISHED`, `RUN_ERROR`
97+
2. **Tool Calls**: `TOOL_CALL_START`, `TOOL_CALL_ARGS`, `TOOL_CALL_END`, `TOOL_CALL_RESULT`
98+
3. **Activity Events**: `ACTIVITY_SNAPSHOT`, `ACTIVITY_DELTA` (for plan updates)
99+
4. **State Updates**: `STATE_SNAPSHOT`, `STATE_DELTA`
100+
5. **Custom Events**: `sql_audit`, `artifact`, `token_usage`
101+
102+
All these events are processed by `reduceLiveRunEvent` and update the LiveRun portion of the state, while TUI-specific fields (messages, input, connection) are managed separately.
103+
104+
---
105+
106+
# Store API Reference
2107

3108
## 概述
4109

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
A TypeScript data-agent runtime and workbench for safe, auditable analysis over databases, files, knowledge, and generated artifacts.
55
</p>
66

7+
<p align="center">
8+
English · <a href="README_zh.md">简体中文</a>
9+
</p>
10+
711
<p align="center">
812
<a href="docs/zh/quick-start.md"><strong>Quick Start</strong></a>
913
·

0 commit comments

Comments
 (0)