我会结合启动脚本、项目说明、Cargo workspace 与前后端入口梳理真实架构,区分已实现的设计与仍属计划/未提交的部分,再给你一份从启动到数据流的整体蓝图。 Read Completed with input: { "path": "D:\\开发项目\\zhuo\\start.bat" } Read , lines 1 to 220 Completed with input: { "path": "D:\\开发项目\\zhuo\\README.md", "view_range": [ 1, 220 ] } Ran terminal command: Get-ChildItem -Force | Select-Object Mode,Name; Get-ChildItem crates -Directory | Select-Object -ExpandProperty Name; Get-ChildItem src -Force | Select-Object Mode,Name Read Completed with input: { "path": "D:\\开发项目\\zhuo\\Cargo.toml" } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\package.json" } Ran terminal command: Get-ChildItem crates -Recurse -File | Where-Object { $_.FullName -match '\\src\\' } | ForEach-Object { Resolve-Path -Relative $_.FullName } Ran terminal command: Get-ChildItem src -Recurse -File | ForEach-Object { Resolve-Path -Relative $_.FullName }; Get-ChildItem scripts -File | Select-Object -ExpandProperty Name Read , lines 1 to 210 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\main.rs", "view_range": [ 1, 210 ] } Read , lines 1 to 140 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\state.rs", "view_range": [ 1, 140 ] } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\services\\memory_service.rs" } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\scripts\\run-backend.mjs" } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\scripts\\ensure-ollama.mjs" } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\src\\api\\client.ts" } Read , lines 1 to 220 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\services\\summarize.rs", "view_range": [ 1, 220 ] } Read , lines 1 to 190 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-llm\\src\\lib.rs", "view_range": [ 1, 190 ] } Read , lines 1 to 115 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-card\\src\\lib.rs", "view_range": [ 1, 115 ] } Search for `^(pub )?(async )?fn |^pub (async )?fn |\.route\(` Search for `^(pub )?fn |^pub struct |^pub const |CREATE TABLE|CREATE VIRTUAL TABLE|CREATE...` Search for `^pub (async )?fn |^pub const |struct StreamConfig|enum StreamOutcome|fn strea...` Read , lines 1 to 160 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-session\\src\\lib.rs", "view_range": [ 1, 160 ] } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\src\\main.tsx" } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\Cargo.toml" } Read , lines 20 to 110 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-memory\\src\\lib.rs", "view_range": [ 20, 110 ] } Read , lines 1 to 220 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\prompt.rs", "view_range": [ 1, 220 ] } Read , lines 697 to 960 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\routes.rs", "view_range": [ 697, 960 ] } Search for `zhuo_session|Session::|sessions_dir` Read , lines 176 to 225 Completed with input: { "path": "D:\\开发项目\\zhuo\\README.md", "view_range": [ 176, 225 ] } Read , lines 1 to 150 Completed with input: { "path": "D:\\开发项目\\zhuo\\src\\App.tsx", "view_range": [ 1, 150 ] } Read , lines 941 to 1145 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-server\\src\\routes.rs", "view_range": [ 941, 1145 ] } Read , lines 225 to 340 Completed with input: { "path": "D:\\开发项目\\zhuo\\crates\\zhuo-memory\\src\\lib.rs", "view_range": [ 225, 340 ] } Read Completed with input: { "path": "D:\\开发项目\\zhuo\\.github\\workflows\\ci.yml" } **已完成任务:** ## Zhuo 项目设计蓝图 ### 1. 产品与运行形态 Zhuo 是本地优先的角色叙事 Web 工作台:浏览器负责界面与交互,Rust/Axum 后端负责业务/API、提示词编排和本地持久化,Ollama 或用户配置的 OpenAI 兼容模型负责推理。启动入口见 `start.bat`:设置默认模型后调用 `npm start`;npm 用 concurrently 管理 Ollama 检查、Rust 后端和 Vite 前端。Vite 默认 `localhost:3000`,后端 `127.0.0.1:1127`,模型服务默认 `127.0.0.1:11434`。后端限制来源为本机 Vite origin。若用户在设置中选择远程兼容服务,提示词和对话会发送到该服务,因此“本地优先”不等于远程模式下数据绝不外传。 ```text start.bat / npm start ├─ ensure-ollama.mjs ── 本机 Ollama :11434 ├─ run-backend.mjs ──── Rust/Axum :1127 ── SQLite zhuo.db └─ Vite/React :3000 ─── /api 代理到 Axum ``` ### 2. 分层与模块边界 - **React 前端**:`src/main.tsx` 装配应用;`src/App.tsx` 目前仍承载主要 UI、状态和交互。真实 HTTP JSON 请求集中在 `src/api/client.ts`,聊天 SSE 单独流式读取。Persona 与客户端 World Info 目前保存在浏览器 `localStorage`。目前尚未形成完整的 `features/chat|session|memory|settings` 目录。 - **HTTP/API 层**:`crates/zhuo-server/src/main.rs` 初始化状态、注册路由、CORS 并绑定回环地址;`routes.rs` 仍包含大部分卡片、聊天、会话、连接设置和状态 handlers;记忆 handlers 已在 `routes/memory.rs`。 - **领域逻辑层**:`services/mod.rs` 声明按真实工作流抽取的 services;`memory_service.rs` 协调记忆查询/写入和提取任务;`summarize.rs` 负责批量摘要与模型输出容错。方向是 handler 管 HTTP 解析/响应,service 管领域流程。 - **基础能力 crate**: `zhuo-card` 解析/规范化 V1/V2 JSON 与 PNG 角色卡;`zhuo-llm` 封装兼容端点、SSE 事件解析、token 转发和首 token 超时;`zhuo-memory` 管 SQLite、迁移、FTS 与记忆存储。`zhuo-session` crate 目前是 JSON 文件会话辅助代码,但 server 的运行时会话实际由 SQLite `chats/messages` 实现;server Cargo 依赖中也未引用该 crate,容易让人误以为它是当前主存储路径。 ### 3. 核心请求数据流 用户选择角色和会话后,前端读取会话历史;发送消息时向 `/api/chat` 提交角色、chat id、用户文本、Persona 与客户端 Lore。后端解析角色卡,以内容指纹 ID 隔离同名卡,短暂持有 DB Mutex:读取会话历史和角色状态、将角色卡/世界书等 Lore 同步至索引、检索相关设定与长期记忆,然后组装紧凑 Prompt。Prompt 预算为基础系统提示最多 200 字、检索内容最多 500 字、最多 6 条历史消息、总量不超过 1500 字,优先丢弃旧历史并压缩可选上下文。随后以 SSE 返回检索/长度元信息和模型 token;模型成功后保存消息、应用显示用 Regex,并尝试触发后台摘要。首 token 最长等待 30 秒,之后的生成不受该首 token deadline 限制。 ### 4. 数据与一致性 SQLite 默认位于根目录 `zhuo.db`,启用 WAL 和 5 秒 busy timeout;单个 `Connection` 由 `Arc<Mutex<MemoryStore>>` 保护。主要表包括 `chats/messages`(会话和对话)、`memories/memories_fts`(长期记忆及 FTS5)、`lore_entries/lore_entries_fts`(设定检索)、`character_state` 和 `app_settings`。FTS 查询使用 jieba 分词和 BM25;按角色检索并限制每类命中数。后台任务按未处理消息阈值抓取快照,锁不跨模型 await;提取模型强制 CPU。提交记忆、FTS 行及消息 processed 游标位于一个事务中,按角色与源消息 ID 幂等;失败整体回滚,重试不重复写入。连接和模型设置保存在 SQLite 设置项中,密钥在读取 API 时掩码。 ### 5. 运维、质量门禁与现状 CI 工作流 `ci.yml` 对 Rust 执行 fmt、严格 Clippy、workspace tests;对前端执行 npm ci、typecheck、build。README 的架构与启动说明见 `README.md`。当前总体蓝图已经有清晰运行边界及本地数据路径,但前端仍集中在 App、后端主 routes 文件仍偏大,领域拆分是渐进过程;工作区里的部分相关改动尚未提交,远端 CI 只验证已提交版本,不能据此认定当前工作区改动已由 GitHub Actions 验证。
Sign in to leave a comment
The SRD will be automatically generated as you discuss your project with the Tech Lead Agent.
No completed page designs yet.
Completed design pages will appear here when they are ready to preview.
No user flows yet.
The User Flow Agent will generate per-persona navigation diagrams after SRD updates.
No completed page designs yet.
Completed design pages will appear here when they are ready to preview.
No user flows yet.
The User Flow Agent will generate per-persona navigation diagrams after SRD updates.
No comments yet. Be the first!