diff --git a/AGENTS.md b/AGENTS.md index cf1bb16..0cd5415 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,3 +7,19 @@ - Prefer established, well-maintained libraries when they reduce overall complexity or improve reliability. Do not reimplement common functionality without a clear reason. - Lean on the dependencies already in the project before writing your own implementation or adding packages. Do not assume a library lacks a capability without checking its documentation and types. - Make architectural decisions for the long term. Do not accept a stopgap that only works for now and is meant to be replaced later. + +## Communication + +- Lead with the conclusion. Keep responses direct and omit filler, repeated context, generic explanations, and narration of obvious steps. +- Match the level requested by the user: discuss architecture as architecture, behavior as behavior, and code details only when they materially support the answer. +- For architecture, refactoring, and module-boundary discussions, communicate primarily with annotated directory trees and ASCII architecture/data-flow diagrams instead of long prose. +- In directory trees, annotate every relevant directory and file with its single responsibility. When discussing code size, include line counts in the comments: + - use measured line counts for existing code; + - use clearly marked approximate targets such as `≈300 lines` for proposed code; + - state whether tests, generated code, and blank lines are excluded. +- Show the complete main execution path, including inputs, ownership boundaries, runtime loops, persistence, outputs, and extension points. Make the direction of data and control flow explicit. +- Clearly separate the current structure from the proposed structure. Explicitly list modules that move, merge, split, or are deleted. +- Use the user's vocabulary consistently. Do not introduce new domain terms when existing plain-language terms are sufficient; when an implementation name must be mentioned, distinguish it from the architecture concept. +- For stateful or concurrent behavior, show timing, ownership, state boundaries, and before/during/after behavior explicitly. Distinguish continuation within the same lifecycle from creation of a new lifecycle. +- Prefer compact trees, flow diagrams, state matrices, and mappings when they communicate the structure more clearly than paragraphs. +- Tie recommendations to the actual repository structure and code. Do not present a speculative target architecture as if it already exists. diff --git a/cursor.md b/cursor.md index 4dd819f..2bbd7f6 100644 --- a/cursor.md +++ b/cursor.md @@ -1,468 +1,722 @@ -# Cursor BYOK 架构重构交接 - -## 使用方式 - -这是新对话的完整交接上下文。开始工作前: - -1. 阅读根目录 `AGENTS.md`。 -2. 阅读 `.agents/skills/cursor-prefix-stability/SKILL.md`。 -3. 查看 `git status` 和当前 feature 分支最新提交。 -4. 不要直接开始大规模移动 `server/src/cursor`;先完成本文“第一阶段测试护栏”。 - -## 本轮目标 - -本次不是功能缩减,而是代码模块消除和状态机收敛: - -- 保留当前 Cursor Proto、工具、Checkpoint、恢复、打断、后台完成、子 Task、本地 BYOK 和官方上游转发能力。 -- 以 `conversation_id` 为 Cursor 协议的核心状态身份。 -- `request_id` 只作为可能重复的传输关联 ID,不能作为 Conversation、Run、Session 或 Trace 的唯一身份。 -- 将 Cursor 生命周期收敛为一个状态写入者。 -- 目录即架构,减少顶层模块数量,明确核心和扩展边界。 -- 面向多人协作,禁止跨目录访问内部实现。 - -## 当前阶段已经完成的代码 - -本 feature 分支当前提交的是第一轮目录与模块整理,不包含后续 Conversation 状态机重写: - -- Cursor Proto 唯一来源收敛到 `protocols/cursor/`。 -- 根目录开发辅助工具统一移动到 `support/`: - - `support/cursor-protocol-extractor/` - - `support/cursor-capture/` - - `support/benchmarks/` -- Desktop 前端按架构整理为: - - `apps/desktop/src/features/` - - `apps/desktop/src/shell/` - - `apps/desktop/src/shared/` -- Server 的通用客户端端口并入 `server/src/run/`。 -- `server/src/web/` 重命名为 `server/src/search/`。 -- 模型观测数据结构聚合为 `server/src/model/observability.rs`。 -- Release 辅助脚本移动到 `.github/scripts/`。 -- 老配置导入能力保留,不应在后续重构中误删。 - -已完成过的验证: - -- Workspace `cargo check` 通过。 -- Desktop build 通过。 -- `support/benchmarks/semble` crate check 通过。 -- Cursor 生命周期相关测试曾通过:interrupt 12、error lifecycle 4、background completion 5、connect wire 6。 - -重新工作时仍需基于当前提交再次运行针对性验证,不能只依赖上述历史结果。 - -## 需要保留但未提交的独立工作区修改 - -`apps/docs/scripts/build-product-demo.mjs` 有一个独立的 Windows `spawnSync(..., shell: true)` 修正。它不属于本次架构提交,已从提交中排除;不要覆盖或删除。 - -## 当前实现规模 - -`server/src/cursor` 当前约 64 个 Rust 文件、约 1.9 万行。 - -主要分布: - -| 模块 | 文件数 | 行数约 | -|---|---:|---:| -| `tools/` | 26 | 6382 | -| `request/` | 7 | 2785 | -| `checkpoint/` | 7 | 1159 | -| `interaction/` | 3 | 1105 | -| `session.rs` | 1 | 868 | -| `projection/` | 4 | 796 | - -问题不是协议服务太复杂,而是同一条生命周期被多个模块分段持有。 - -## 当前协议链路 +以下是重构后完整目标版本 +实现时,先创建所有目录和文件固化,每个文件头部都写好注释再实现 +旧服务已被备份为server_backup,/Users/leokun/Documents/cursor-byok/server 目录已创建 +行数均为目标估算,使用 `≈` 标记;不包含测试、生成代码和空行。 +实现时可做略微调整,测试要求相对于目标文件旁边的独立文件,禁止码内测试 +本文档目录 /Users/leokun/Documents/cursor-byok/cursor.md +## 完整目录 ```text -Cursor BidiAppend -→ handlers.rs 选择 local/upstream -→ bidi_append.rs 解码 AgentClientMessage -→ CursorSessionRegistry.get_or_create(request_id) -→ CursorActor:append 排序、协议消息分发、Run 启动 -→ CursorSession:Run/Tool/Checkpoint/Interrupt 协调 -→ RunActor / RunEngine:通用模型循环和历史提交 -→ OutputHub -→ RunSSE +server/ +├── src/ # ≈36,000 行;服务端全部业务代码 +│ ├── app.rs # ≈180 行;依赖组装和服务启动 +│ ├── config.rs # ≈180 行;进程配置 +│ ├── error.rs # ≈150 行;统一错误 +│ ├── network.rs # ≈100 行;网络公共配置 +│ │ +│ ├── bin/ # ≈100 行;可执行程序入口 +│ │ └── cursor-server.rs # ≈100 行;启动服务 +│ │ +│ ├── api/ # ≈1,500 行;HTTP/Connect API +│ │ ├── mod.rs # ≈20 行;模块导出 +│ │ ├── router.rs # ≈100 行;总路由 +│ │ └── cursor/ # ≈1,350 行;Cursor API +│ │ ├── mod.rs # ≈20 行;Cursor 路由 +│ │ ├── bidi.rs # ≈250 行;上行请求 +│ │ ├── run_sse.rs # ≈300 行;下行订阅 +│ │ ├── handlers.rs # ≈450 行;其他 Cursor API +│ │ └── proxy.rs # ≈330 行;本地/官方服务选择 +│ │ +│ ├── cursor/ # ≈18,000 行;Cursor Agent 适配层 +│ │ ├── mod.rs # ≈40 行;公共导出 +│ │ │ +│ │ ├── transport/ # ≈800 行;request_id 双向通道 +│ │ │ ├── mod.rs # ≈20 行;模块导出 +│ │ │ ├── registry.rs # ≈220 行;request_id → TransportHandle +│ │ │ ├── handle.rs # ≈200 行;输入、订阅和终态 +│ │ │ ├── inbox.rs # ≈70 行;append_seqno 排序 +│ │ │ └── output.rs # ≈290 行;缓存、广播、重放、关闭 +│ │ │ +│ │ ├── conversation/ # ≈1,600 行;Conversation 运行协调 +│ │ │ ├── mod.rs # ≈30 行;公共类型 +│ │ │ ├── registry.rs # ≈220 行;conversation_id → Runtime +│ │ │ ├── runtime.rs # ≈500 行;current_run 唯一所有者 +│ │ │ ├── command.rs # ≈120 行;Start/Action/Cancel/Disconnect +│ │ │ ├── delivery.rs # ≈280 行;Ignore/Insert/Break +│ │ │ ├── pending.rs # ≈150 行;Run 边界上的待处理消息 +│ │ │ └── output.rs # ≈300 行;RunEvent 下行及 Step 记录 +│ │ │ +│ │ ├── compile/ # ≈2,700 行;Cursor 输入编译 +│ │ │ ├── mod.rs # ≈30 行;统一入口 +│ │ │ ├── run.rs # ≈650 行;RunRequest → PreparedRun +│ │ │ ├── context.rs # ≈650 行;rules/skills/MCP/environment +│ │ │ ├── action.rs # ≈250 行;Action 分类和路由 +│ │ │ ├── insert_messages.rs # ≈400 行;非打断消息 +│ │ │ ├── break_messages.rs # ≈400 行;打断当前 cycle 的消息 +│ │ │ ├── images.rs # ≈100 行;图片和 Blob +│ │ │ └── model.rs # ≈220 行;Cursor model → Provider model +│ │ │ +│ │ ├── checkpoint/ # ≈2,200 行;Conversation 持久化和恢复 +│ │ │ ├── mod.rs # ≈30 行;公共接口 +│ │ │ ├── builder.rs # ≈280 行;构建 Checkpoint +│ │ │ ├── steps.rs # ≈120 行;尚未持久化的步骤缓存 +│ │ │ ├── turns.rs # ≈150 行;Conversation turns +│ │ │ ├── roots.rs # ≈150 行;稳定根消息 +│ │ │ ├── recovery.rs # ≈100 行;恢复 Conversation +│ │ │ ├── summary.rs # ≈120 行;压缩摘要 +│ │ │ ├── derived.rs # ≈220 行;Todo/Plan 等派生状态 +│ │ │ ├── worker.rs # ≈250 行;异步持久化和 barrier +│ │ │ └── messages/ # ≈800 行;Message 编解码 +│ │ │ ├── mod.rs # ≈20 行;统一入口 +│ │ │ ├── decode.rs # ≈250 行;Checkpoint → Message +│ │ │ ├── encode.rs # ≈280 行;Message → Checkpoint +│ │ │ └── tests.rs # ≈250 行;稳定性测试 +│ │ │ +│ │ ├── tools/ # ≈6,500 行;可扩展 Tool 系统 +│ │ │ ├── mod.rs # ≈180 行;公共类型和注册 +│ │ │ ├── registry.rs # ≈180 行;Tool 定义 +│ │ │ ├── runtime.rs # ≈420 行;运行状态和取消 +│ │ │ ├── stream.rs # ≈350 行;流式参数 +│ │ │ ├── edit.rs # ≈340 行;编辑状态 +│ │ │ ├── schedule.rs # ≈100 行;后台任务调度 +│ │ │ ├── compat.rs # ≈150 行;兼容工具转换 +│ │ │ │ +│ │ │ ├── codec/ # ≈1,750 行;Tool Wire Protocol +│ │ │ │ ├── mod.rs # ≈20 行;模块导出 +│ │ │ │ ├── request.rs # ≈520 行;执行请求编码 +│ │ │ │ ├── response.rs # ≈360 行;执行响应编码 +│ │ │ │ ├── query.rs # ≈250 行;InteractionQuery +│ │ │ │ └── render.rs # ≈600 行;Cursor Tool 卡片 +│ │ │ │ +│ │ │ ├── tool_call_dispatch/ # ≈700 行;ToolCall 分发 +│ │ │ │ ├── mod.rs # ≈260 行;主 Dispatcher +│ │ │ │ ├── exec.rs # ≈80 行;命令执行 +│ │ │ │ ├── edit.rs # ≈40 行;编辑调用 +│ │ │ │ ├── interaction.rs # ≈260 行;用户交互 +│ │ │ │ ├── local.rs # ≈30 行;本地工具 +│ │ │ │ └── search.rs # ≈40 行;搜索工具 +│ │ │ │ +│ │ │ └── tool_call_result/ # ≈3,000 行;ToolResult 消费 +│ │ │ ├── mod.rs # ≈180 行;统一结果 +│ │ │ ├── gate.rs # ≈850 行;完成关联和门控 +│ │ │ ├── interaction.rs # ≈450 行;用户交互结果 +│ │ │ ├── local.rs # ≈220 行;本地工具结果 +│ │ │ ├── mcp.rs # ≈80 行;MCP 结果 +│ │ │ ├── mcp_state.rs # ≈150 行;MCP 状态 +│ │ │ ├── search.rs # ≈150 行;搜索结果 +│ │ │ └── exec/ # ≈920 行;命令执行结果 +│ │ │ ├── mod.rs # ≈180 行;执行结果入口 +│ │ │ ├── output.rs # ≈500 行;输出处理 +│ │ │ └── render.rs # ≈240 行;结果渲染 +│ │ │ +│ │ ├── protocol/ # ≈600 行;非 Tool Wire Protocol +│ │ │ ├── mod.rs # ≈20 行;模块导出 +│ │ │ ├── proto.rs # ≈80 行;protobuf 类型 +│ │ │ ├── connect.rs # ≈150 行;Connect framing +│ │ │ ├── json_stream.rs # ≈280 行;JSON 流 +│ │ │ └── events.rs # ≈300 行;实时下行消息 +│ │ │ +│ │ ├── prompting/ # ≈650 行;Prompt 编译 +│ │ │ ├── mod.rs # ≈20 行;模块导出 +│ │ │ ├── compiler.rs # ≈120 行;PromptSpec 编译 +│ │ │ ├── catalog.rs # ≈100 行;Prompt 目录 +│ │ │ ├── assets.rs # ≈220 行;资源加载 +│ │ │ └── derived_state.rs # ≈190 行;稳定派生上下文 +│ │ │ +│ │ └── services/ # ≈2,800 行;非 Agent Loop 服务 +│ │ ├── mod.rs # ≈30 行;模块导出 +│ │ ├── account.rs # ≈470 行;账号信息 +│ │ ├── analytics.rs # ≈240 行;Analytics +│ │ ├── blob_sync.rs # ≈320 行;Blob 同步 +│ │ ├── context_sync.rs # ≈200 行;上下文同步 +│ │ ├── model_catalog.rs # ≈730 行;模型目录 +│ │ ├── observability.rs # ≈230 行;Cursor Trace +│ │ ├── tab.rs # ≈80 行;Tab 信息 +│ │ └── usage.rs # ≈350 行;用量统计 +│ │ +│ ├── run/ # ≈2,400 行;通用 Agent Loop +│ │ ├── mod.rs # ≈30 行;公共接口 +│ │ ├── engine.rs # ≈550 行;Loop 主流程 +│ │ ├── handle.rs # ≈180 行;RunHandle/RunPhase +│ │ ├── command.rs # ≈180 行;RunCommand/CommandResult +│ │ ├── event.rs # ≈180 行;RunEvent/RunOutcome +│ │ ├── model_cycle.rs # ≈380 行;单次 LLM 调用 +│ │ ├── tool_round.rs # ≈320 行;单轮 Tool 调用 +│ │ ├── messages.rs # ≈220 行;幂等追加消息 +│ │ ├── compaction.rs # ≈260 行;显式上下文压缩 +│ │ └── port.rs # ≈100 行;外部端口 +│ │ +│ ├── model/ # ≈1,900 行;公共数据类型 +│ │ ├── mod.rs # ≈30 行;模块导出 +│ │ ├── conversation.rs # ≈100 行;Conversation 类型 +│ │ ├── checkpoint.rs # ≈80 行;Checkpoint 类型 +│ │ ├── message.rs # ≈180 行;Message 类型 +│ │ ├── run.rs # ≈100 行;Run 类型 +│ │ ├── tool.rs # ≈100 行;ToolCall/ToolResult +│ │ ├── inference.rs # ≈150 行;模型请求和响应 +│ │ ├── projection.rs # ≈180 行;Provider 输入消息 +│ │ ├── configuration.rs # ≈550 行;模型配置 +│ │ ├── observability.rs # ≈300 行;调用观测 +│ │ ├── token_count.rs # ≈50 行;Token 统计 +│ │ └── tool_result_replay.rs # ≈230 行;ToolResult 恢复 +│ │ +│ ├── provider/ # ≈3,000 行;Provider 适配 +│ │ ├── mod.rs # ≈80 行;Provider trait +│ │ ├── router.rs # ≈230 行;Provider 路由 +│ │ ├── event.rs # ≈100 行;统一流事件 +│ │ ├── normalize.rs # ≈50 行;响应归一化 +│ │ ├── retry.rs # ≈270 行;重试 +│ │ ├── recorder.rs # ≈600 行;调用记录 +│ │ ├── anthropic.rs # ≈500 行;Anthropic +│ │ ├── openai_chat.rs # ≈580 行;Chat Completions +│ │ └── openai_responses.rs # ≈650 行;Responses +│ │ +│ ├── store/ # ≈4,100 行;本地持久化 +│ │ ├── mod.rs # ≈40 行;Store 接口 +│ │ ├── sqlite.rs # ≈60 行;SQLite 初始化 +│ │ ├── writer.rs # ≈30 行;串行写事务 +│ │ ├── cas.rs # ≈120 行;并发写检查 +│ │ ├── conversations.rs # ≈180 行;Conversation +│ │ ├── checkpoints.rs # ≈400 行;Checkpoint +│ │ ├── messages.rs # ≈150 行;Message 和幂等 +│ │ ├── runs.rs # ≈300 行;Run +│ │ ├── tool_rounds.rs # ≈330 行;Tool Round +│ │ ├── input_anchors.rs # ≈60 行;输入去重 +│ │ ├── llm_calls.rs # ≈650 行;LLM 调用记录 +│ │ ├── models.rs # ≈430 行;模型配置 +│ │ ├── settings.rs # ≈430 行;应用设置 +│ │ ├── storage.rs # ≈230 行;Blob 存储 +│ │ ├── cursor_traces.rs # ≈400 行;Cursor Trace +│ │ └── overview.rs # ≈350 行;控制台查询 +│ │ +│ ├── control/ # ≈2,100 行;管理端 API +│ │ ├── mod.rs # ≈30 行;模块导出 +│ │ ├── service.rs # ≈500 行;管理端服务 +│ │ ├── settings.rs # ≈350 行;设置接口 +│ │ ├── models.rs # ≈350 行;模型接口 +│ │ ├── overview.rs # ≈300 行;概览 +│ │ ├── calls.rs # ≈250 行;调用记录 +│ │ ├── ads.rs # ≈150 行;广告配置 +│ │ └── harness.rs # ≈170 行;Harness 控制 +│ │ +│ ├── search/ # ≈1,400 行;搜索能力 +│ │ ├── mod.rs # ≈30 行;模块导出 +│ │ ├── engine.rs # ≈350 行;搜索入口 +│ │ ├── catalog.rs # ≈250 行;搜索服务目录 +│ │ ├── federation.rs # ≈280 行;聚合搜索 +│ │ ├── fetch.rs # ≈250 行;网页获取 +│ │ └── search_provider.rs # ≈240 行;搜索 Provider +│ │ +│ └── local_app/ # ≈1,000 行;本地运行环境 +│ ├── mod.rs # ≈100 行;local_app 入口(原Harness) +│ ├── account.rs # ≈150 行;账号 +│ ├── proxy.rs # ≈250 行;代理 +│ ├── settings.rs # ≈200 行;设置 +│ └── ca/ # ≈300 行;证书 +│ ├── mod.rs # ≈250 行;CA 实现 +│ └── windows.rs # ≈50 行;Windows 支持 +│ +└── tests/ # ≈3,500 行;跨模块行为测试 + ├── conversation_delivery.rs # ≈400 行;消息投递时序 + ├── interrupt.rs # ≈400 行;Break 和取消 + ├── error_lifecycle.rs # ≈300 行;终态唯一性 + ├── checkpoint_recovery.rs # ≈350 行;恢复 + ├── prefix_stability.rs # ≈450 行;前缀稳定 + ├── compaction.rs # ≈300 行;压缩 + ├── tool_round.rs # ≈450 行;Tool Round + └── connect_wire.rs # ≈300 行;Wire Protocol ``` -主要客户端消息类型: - -- `RunRequest` -- `ExecClientMessage` -- `ExecClientControlMessage` -- `KvClientMessage` -- `ConversationAction` -- `InteractionResponse` -- `ClientHeartbeat` - -运行时 Action: - -- `UserMessageAction`:软打断并继续当前 Conversation。 -- `InjectContextAction`:软打断、追加运行时事件并继续。 -- `CancelAction`:硬取消活动 Run。 -- `CancelSubagentAction`:终止对应的普通子 Task 工具调用,不改变父 Conversation 生命周期。 - -主要服务端消息类型: - -- `InteractionUpdate` -- `InteractionQuery` -- `ExecServerMessage` -- `ExecServerControlMessage` -- `ConversationCheckpointUpdate` -- Connect terminal frame - -## 已确认的身份语义 - -| 身份 | 语义与约束 | -|---|---| -| `conversation_id` | 持久化 Conversation 的唯一核心身份 | -| `ParentConversationRef` | 子 Conversation 的不可变创建来源 | -| internal `run_id` | 服务端一次循环引擎执行,全局唯一 | -| Cursor `run_id` | `AgentRunRequest.run_id`,用于 `expected_run_id` 等 wire 关联 | -| `agent_session_id` | Cursor Agent 会话实例 | -| `request_id` | BidiAppend 与 RunSSE 的可重复传输关联 ID | -| `append_seqno` | 一个传输代次内的顺序,不是身份 | -| `message_id` / `injection_id` | 事件幂等身份 | -| `trace_id` | 一次链路观测的服务端唯一身份 | - -身份约束: - -- `request_id → conversation_id` 必须强关联。 -- 同一个 `request_id` 可以在同一个 Conversation 内因重试或队列再次出现。 -- 同一个 `request_id` 如果绑定到不同 Conversation,必须报协议冲突。 -- 并发重复且 wire 无法区分时应拒绝冲突,不能猜测路由。 -- 缺少 `conversation_id` 时,只能使用已经存在的 request binding;禁止回退到 `request_id`。 -- `InjectContextAction.expected_run_id` 应比较 Cursor wire `run_id`,不能比较 `request_id`。 - -## ParentConversationRef 决策 - -任何根或子 Task 都是独立 Conversation。Conversation 不维护 children,不订阅子状态,不管理子生命周期。 - -父 Conversation 只看到一次普通 ToolCall。子 Conversation 只保存不可变的创建溯源: - -```rust -struct ParentConversationRef { - parent_conversation_id: ConversationId, - parent_run_id: RunId, - parent_tool_call_id: ToolCallId, -} -``` - -三个字段都必须保留: - -- `parent_conversation_id`:属于哪条 Conversation 链。 -- `parent_run_id`:父 Conversation 的哪次服务端 Run 创建。 -- `parent_tool_call_id`:哪次普通 ToolCall 创建。 - -它不表示父子状态管理,也不应形成内存 children 树。 - -## 当前高风险点 - -### P0:request_id 被错误提升为核心身份 - -- `CursorSessionRegistry.runs` 使用 `HashMap`。 -- RunSSE 使用 request ID 查找和等待路由。 -- Trace 表使用 `request_id TEXT PRIMARY KEY`。 -- 父 Run 通过 `active_run_for_cursor_request(request_id)` 查找最近活动 Run。 -- `request::prepare` 在缺失 Conversation ID 时回退到 request ID。 - -### P0:Wire Run 身份没有进入生命周期 - -- `AgentRunRequest.run_id`、`agent_session_id` 基本未使用。 -- 内部 RunId 当前由 `request_id + UUID` 生成。 -- `InjectContextAction.expected_run_id` 当前错误地与 `context.request_id` 比较。 - -### P0:生命周期有多个写入者 - -以下模块都能直接 cancel token、关闭 output 或发送 terminal: - -- `bidi_append.rs` -- `actor.rs` -- `session.rs` -- `run_sse.rs` -- `sessions.rs` -- `lifecycle.rs` -- 通用 `RunEngine` 还会独立产生 `RunOutcome` - -可能导致终态竞争、terminal 重复、错误原因不稳定。 - -### P0:Actor 与 Session 是重叠事件循环 - -- Actor 管 wire 输入、排序、工具回传和 runtime action。 -- Session 管 Run 事件、工具状态、Checkpoint、interrupt 和 terminal。 -- RunEngine 内还有第三层模型循环。 - -### P1:Transport 与 Run 生命周期绑定 - -- 当前 RunSSE Drop 会直接取消共享 Run token。 -- 正确语义应为 `SSE disconnect = DetachTransport`,而不是必然 Cancel Run。 - -### P1:旁路状态 - -- `cancelled_conversations: HashSet` 与 Store、RunOutcome、CancellationToken 平行存在。 -- OutputHub 可以重放,但 Handle 关闭后 Registry 很快删除;晚到 RunSSE 可能永久等待。 -- `CancelAction` 在 BidiAppend 和 Actor 两处处理。 -- `CursorCommand::Abort` 没有生产发送者,主要只在测试中使用。 -- `ClientCommand::Cancel` 没有 Cursor 生产发送者。 - -## 受保护的历史不变量 - -后续移动 `request / projection / checkpoint / run` 时,必须保持: - -- 未发生 compaction 时,第 N 轮 provider history 是第 N+1 轮的严格结构前缀。 -- 旧消息不能编辑、合并、重排或重新生成。 -- request context 是 append-only 事件;内容相同不重复追加,变化时在本轮 runtime message 前追加。 -- `A → B → A` 必须保留三个不同事件;同一事件重试必须幂等。 -- Checkpoint encode/decode 必须保留 request-context wire identity。 -- 自动 compaction 是显式前缀重置,只保留最新 request context。 -- 后台完成和注入不能制造重复 request context。 - -## 目标状态模型 - -Conversation 本身没有 Completed/Cancelled 终态,结束的是 Run: +## 顶层架构 ```text -Idle -→ Preparing -→ Modeling -↔ WaitingTools -→ Interrupting → Modeling -→ Checkpointing -→ Finalizing -→ Idle + Cursor Client + ┌──────────────┴──────────────┐ + │ │ + Bidi 上行 RunSSE 下行 + │ ▲ + ▼ │ + ┌──────────────────────┐ │ + │ Transport │ │ + │ │ │ + │ request_id │ │ + │ OrderedInbox │ │ + │ OutputHub ────────────────────────────┘ + └──────────┬───────────┘ + │ + │ conversation_id + ▼ + ┌──────────────────────────────┐ + │ ConversationRegistry │ + │ │ + │ conversation_id │ + │ → ConversationRuntime │ + └──────────────┬───────────────┘ + ▼ +┌─────────────────────────────────────────────────────────────┐ +│ Conversation │ +│ │ +│ Messages │ +│ current_run: Option │ +│ pending_messages │ +│ Checkpoint │ +│ Transport bindings │ +│ │ +│ 唯一负责: │ +│ 创建 Run / 投递 Message / Cancel / RunOutcome / 输出终态 │ +└──────────────┬────────────────┬─────────────────────────────┘ + │ │ + RunCommand Checkpoint + │ │ + ▼ ▼ + ┌─────────────────┐ ┌──────────────────────┐ + │ RunEngine │ │ CheckpointBuilder │ + │ │ │ │ + │ Model Cycle │ │ Messages │ + │ Tool Round │ │ Turns │ + │ Message Append │ │ Steps │ + │ Compaction │ │ Derived State │ + └────────┬────────┘ └──────────┬───────────┘ + │ │ + ┌──────┴───────┐ ▼ + │ │ ┌──────────────────┐ + ▼ ▼ │ Store │ + Provider Tool Runtime │ │ + │ │ │ Conversations │ + └──────┬───────┘ │ Messages │ + │ │ Checkpoints │ + └───────────────→│ Runs │ + │ Tool Rounds │ + └──────────────────┘ ``` -唯一生命周期写入位置: +## 上行主链路 ```text -server/src/cursor/conversation/runtime.rs +BidiAppendRequest + │ + ▼ +api/cursor/bidi.rs +├── decode request_id +├── decode append_seqno +└── decode AgentClientMessage + │ + ▼ +TransportRegistry + │ + ▼ +OrderedInbox + │ + ▼ +compile/action.rs + │ + ├── Ignore + ├── InsertMessages + └── BreakMessages + │ + ▼ +ConversationRuntime + │ + ▼ +current_run ``` -建议模型: - -```rust -struct ConversationRuntime { - identity: ConversationIdentity, - active_run: Option, - request_bindings: RequestBindings, -} - -struct ConversationIdentity { - conversation_id: ConversationId, - parent: Option, -} - -enum ConversationState { - Idle, - Active(ActiveRunState), -} - -enum ActiveRunPhase { - Preparing, - Modeling, - WaitingTools, - Interrupting, - Checkpointing, - Finalizing, -} -``` - -所有其他模块只能向它发送命令或事件,不能直接关闭输出或修改生命周期。 - -## 目标目录 +## 下行主链路 ```text -protocols/ -└── cursor/ # Proto 唯一来源 - -server/src/cursor/ -├── mod.rs # 只组合模块 -├── protocol/ # wire 类型与编解码 -│ ├── mod.rs -│ ├── proto.rs -│ ├── wire.rs -│ └── identity.rs -├── gateway/ # HTTP/Bidi/SSE 入口 -│ ├── mod.rs -│ ├── bidi.rs -│ ├── stream.rs -│ └── routing.rs -├── conversation/ # 唯一核心状态域 -│ ├── mod.rs -│ ├── identity.rs -│ ├── registry.rs -│ ├── state.rs -│ ├── runtime.rs # 唯一生命周期写入者 -│ ├── output.rs -│ ├── sync.rs -│ └── history/ -│ ├── request/ -│ ├── projection/ -│ └── checkpoint/ -├── tools/ # 可扩展普通工具能力 -│ ├── mod.rs # ToolPort -│ ├── codec.rs -│ ├── runtime.rs -│ ├── dispatch.rs -│ ├── completion.rs -│ ├── presentation.rs -│ ├── edit.rs -│ └── subtask.rs -├── prompting/ # 无状态确定性编译 -│ ├── mod.rs -│ ├── compiler.rs -│ └── assets.rs -├── apis/ # 可替换产品能力 -│ ├── mod.rs -│ ├── upstream.rs -│ ├── account.rs -│ ├── models.rs -│ ├── analytics.rs -│ └── tab.rs -└── observability.rs # 只观察,不写生命周期 +RunEvent + │ + ▼ +conversation/output.rs + │ + ├── protocol/events.rs + │ │ + │ ▼ + │ AgentServerMessage + │ │ + │ ▼ + │ Transport OutputHub + │ │ + │ ▼ + │ RunSSE + │ + └── checkpoint/steps.rs + │ + ▼ + StepBuffer + │ + ▼ + CheckpointWorker ``` -顶层架构概念最终收敛为: +## Message 编译 ```text -protocol -gateway -conversation -tools -prompting -apis -observability +Cursor Action + │ + ▼ +compile/action.rs + │ + ▼ +CompiledMessages +├── event_id +├── target_run_id +├── messages +└── delivery + │ + ├── Ignore + ├── InsertMessages + └── BreakMessages ``` -## 核心与扩展边界 - -核心: - -- Conversation identity 与 ParentConversationRef。 -- RequestBinding 一致性。 -- 单一生命周期状态机。 -- canonical history、projection、checkpoint 与恢复。 -- RunEngine 端口。 -- terminal exactly-once。 - -允许扩展: - -- 具体 Tool 实现,包括子 Task Tool。 -- Cursor 官方上游代理。 -- Account、Models、Analytics、Tab 等产品 API。 -- Provider。 -- Presentation 和 Observability sink。 - -Conversation 核心只认识 `ToolCall / ToolResult / ToolInterrupted`,不能认识或保存子 Conversation 状态。 - -## 模块消除映射 - -| 当前 | 目标 | -|---|---| -| `actor.rs + session.rs + command.rs + lifecycle.rs + inbox.rs` | `conversation/runtime.rs + state.rs` | -| `sessions.rs` | `conversation/registry.rs + output.rs` | -| `handlers.rs + bidi_append.rs + run_sse.rs` | `gateway/` | -| `connect.rs + proto.rs` | `protocol/` | -| `blob_sync.rs + context_sync.rs` | `conversation/sync.rs` | -| `request + projection + checkpoint` | `conversation/history/`,保留语义 | -| `interaction + json_stream + presentation + tools/stream` | `tools/presentation.rs + codec.rs` | -| `tools/dispatch/* + tools/result/*` | `dispatch.rs + completion.rs` | -| `proxy/account/model_catalog/analytics/tab` | `apis/` | - -最终应删除: - -- `cancelled_conversations` 旁路状态。 -- `CursorCommand::Finished`。 -- 无生产用途的 `CursorCommand::Abort`。 -- 多处 `lifecycle::finish/cancel/fail`。 -- 旧路径和兼容 re-export。 - -## 安全实施顺序 - -### 第一阶段:测试护栏,不移动目录 - -先增加行为测试: - -- 同 request、同 Conversation、同事件:幂等。 -- 同 request、同 Conversation、新 Cursor run:正确建立新代次。 -- 同 request、不同 Conversation:协议冲突。 -- `expected_run_id` 使用 wire run ID。 -- ParentConversationRef 三字段准确并可持久恢复。 -- RunSSE 先到、重连、晚到。 -- cancel 发生在 prepare/model/tools/checkpoint 各阶段。 -- soft interrupt 继续同一 Conversation。 -- late ToolResult 不污染新一轮。 -- final checkpoint 必须先于 terminal。 -- terminal frame 恰好一次。 -- SSE detach 与 CancelAction 独立。 - -### 第二阶段:身份收敛 - -- 引入强类型 ID。 -- 消费 `AgentRunRequest.run_id` 和 `agent_session_id`。 -- 建立 RequestBinding,不再假设 request ID 唯一。 -- 删除 Conversation ID fallback。 -- ParentConversationRef 改为三元组并持久化。 -- Trace 使用独立 `trace_id`,不再以 request ID 为主键。 -- 不修改工具、Checkpoint 或输出 wire 行为。 - -### 第三阶段:ConversationRegistry - -- Registry 以 Conversation ID 为主键。 -- request ID 仅作为反向路由索引。 -- RunSSE 根据 binding 定位 Conversation。 -- 不再通过 request ID 查询“最近父 Run”。 - -### 第四阶段:生命周期单写入者 - -- 所有 cancel 转为 ConversationCommand。 -- SSE Drop 转为 DetachTransport。 -- terminal 只能从 Conversation runtime 发出。 -- 删除 `cancelled_conversations` 和重复 lifecycle 调用。 - -### 第五阶段:合并 Actor 与 Session - -- 使用一个 `tokio::select!` 处理 wire、Run、Tool、Checkpoint。 -- prepare 作为异步任务返回事件。 -- 删除 `run_resources.take()` 和 `CursorCommand::Finished`。 -- Run 结束后 Conversation 回到 Idle,可继续下一 Run。 - -### 第六阶段:目录和 Tools 收敛 - -- 生命周期稳定后再机械移动目录。 -- 同一提交删除旧路径,不保留兼容层。 -- 对 Tools 先锁定 wire 行为,再合并 codec、dispatch、completion、presentation。 - -## 多人协作规则 - -- `conversation/runtime.rs` 同一时间只由一个负责人修改。 -- `mod.rs` 只组合和导出,不放业务。 -- 跨目录只能使用公开 façade,禁止引用内部子模块。 -- `tools` 不引用 `ConversationRuntime`。 -- `apis` 不访问 Conversation 内部状态。 -- `observability` 只能订阅事件。 -- Provider 不认识 Cursor Proto。 -- 一个 PR 不同时重写 identity、lifecycle 和 tool wire。 -- 目录迁移设置短合并窗口,避免多人同时修改路径。 -- 每阶段必须保持可编译、可测试、可回滚。 - -最终依赖方向: +## Message 投递 ```text -Gateway - ↓ -Conversation Runtime - ├── History - ├── ToolPort - └── Generic Run - ↓ - Provider + Ignore InsertMessages BreakMessages -APIs → Gateway 公开接口 -Observability ← 领域事件 +Run 开始前 丢弃 initial_messages initial_messages + +Run 运行中 丢弃 等当前 cycle 完成 取消当前 cycle + 后追加 后追加 + +Run Finalizing 丢弃 pending_messages pending_messages + +Run 结束后 丢弃 启动下一个 Run 启动下一个 Run ``` -## 新对话建议的第一条任务 +带 `target_run_id` 时: ```text -阅读 cursor.md、AGENTS.md 和 cursor-prefix-stability skill。不要立即移动目录。 -先为 Cursor 身份建立 characterization tests,覆盖 request_id 重复、conversation_id 冲突、wire run_id 的 expected_run_id 校验,以及 ParentConversationRef 三元组。测试完成后给出最小身份收敛改动,不要同时重写生命周期和 Tools。 +target_run_id == current_run_id +└── 按 delivery 消费 + +target_run_id != current_run_id +└── StaleTarget,忽略 ``` + +## RunEngine + +```text +RunEngine +│ +├── Running +│ ├── 接受 InsertMessages +│ ├── 接受 BreakMessages +│ ├── 接受 ToolResult +│ └── 接受 Cancel +│ +├── Finalizing +│ ├── 拒绝新消息 +│ ├── 提交最终 Message +│ ├── 等待 Checkpoint barrier +│ └── 返回 RunClosing +│ +└── Ended + └── 返回 RunEnded +``` + +```text +RunCommand +├── InsertMessages(MessageBatch) +├── BreakMessages(MessageBatch) +├── ToolResult(ToolResult) +└── Cancel + +CommandResult +├── Applied +├── Duplicate +├── RunClosing +├── RunEnded +└── StaleTarget +``` + +## InsertMessages + +```text +同一个 Run +│ +├── LLM Call #1 正在执行 +│ │ +│ └── 收到 InsertMessages +│ └── pending_insertions +│ +├── LLM Call #1 完成 +├── 提交 Assistant Message +├── 追加 InsertMessages +├── 持久化 Checkpoint +└── LLM Call #2 +``` + +不会创建新 Run。 + +## BreakMessages + +```text +同一个 Run +│ +├── LLM Call / Tool Round 正在执行 +│ │ +│ └── 收到 BreakMessages +│ +├── 取消当前 cycle +├── 中止未完成 Tool +├── 写入 interrupted ToolResult +├── 追加 BreakMessages +├── 持久化 Checkpoint +└── 重新进入 Model Cycle +``` + +取消的是当前 cycle,不是整个 Run。 + +## Tool 链路 + +```text +RunEngine + │ ToolCall + ▼ +ConversationRuntime + │ + ▼ +ToolDispatcher + │ + ├── Local Tool + ├── Exec Tool + ├── Edit Tool + ├── Interaction Tool + ├── Search Tool + ├── MCP Tool + └── Subagent Tool + │ + ▼ +ToolRuntime + │ + ├── stream + ├── cancel + ├── result gate + └── completion + │ + ▼ +ToolResult + │ + ▼ +RunEngine +``` + +Tool 的 Cursor Wire Protocol: + +```text +ToolCall +├── tools/codec/query.rs +│ └── InteractionQuery +├── tools/codec/render.rs +│ └── Cursor Tool 卡片 +├── tools/codec/request.rs +│ └── Exec 请求 +└── tools/codec/response.rs + └── Exec 响应 +``` + +## Checkpoint 链路 + +持久化: + +```text +Conversation Messages + │ + ▼ +checkpoint/messages/encode.rs + │ + ▼ +Stable root messages + │ + ├── Turns + ├── Steps + ├── Tool state + ├── Todo/Plan + └── Read paths + │ + ▼ +Checkpoint + │ + ▼ +Cursor ConversationState +``` + +恢复: + +```text +Cursor ConversationState + │ + ▼ +checkpoint/recovery.rs + │ + ▼ +checkpoint/messages/decode.rs + │ + ▼ +Conversation Messages + │ + ▼ +PreparedRun +``` + +稳定性: + +```text +没有压缩 +└── 之前的 Message 不修改、不删除、不重排 + └── 新 Message 只追加 + +发生压缩 +└── 显式替换 Checkpoint roots + └── 保留最新稳定上下文 +``` + +## Cancel 链路 + +```text +Bidi Cancel / RunSSE Disconnect / Shutdown + │ + ▼ + ConversationRuntime + │ + ┌─────────┴─────────┐ + │ │ + ▼ ▼ + RunHandle.cancel ToolRuntime.abort + │ │ + └─────────┬─────────┘ + ▼ + RunOutcome + │ + ▼ + Final Checkpoint + │ + ▼ + TransportHandle.terminal + │ + ▼ + OutputHub.close +``` + +只有 `ConversationRuntime` 可以: + +```text +Cancel current_run +结束 Tool +发送 terminal +关闭 OutputHub +删除 request_id 路由 +``` + +## 模块依赖 + +```text +api +└── cursor + +cursor/transport +└── cursor/conversation + +cursor/conversation +├── cursor/compile +├── cursor/checkpoint +├── cursor/tools +├── cursor/protocol +└── run + +run +├── model +├── provider +└── store + +cursor/checkpoint +├── model +├── store +└── cursor/protocol + +cursor/tools +├── model +├── store +└── cursor/protocol + +provider +└── model + +store +└── model +``` + +禁止反向依赖: + +```text +run ─X→ cursor +provider ─X→ cursor +store ─X→ cursor +model ─X→ cursor +``` + +## 当前代码迁移 + +```text +当前 目标 + +cursor/bidi_append.rs → api/cursor/bidi.rs +cursor/run_sse.rs → api/cursor/run_sse.rs +cursor/handlers.rs → api/cursor/handlers.rs +cursor/proxy.rs → api/cursor/proxy.rs + +cursor/sessions.rs → cursor/transport/registry.rs + + cursor/transport/handle.rs + + cursor/transport/output.rs + +cursor/inbox.rs → cursor/transport/inbox.rs + +cursor/actor.rs → cursor/transport/ + + cursor/conversation/runtime.rs + + cursor/conversation/delivery.rs + +cursor/session.rs → cursor/conversation/runtime.rs + + cursor/conversation/output.rs + + cursor/checkpoint/ + + cursor/tools/ + +cursor/request/prepare.rs → cursor/compile/run.rs +cursor/request/context.rs → cursor/compile/context.rs +cursor/request/background.rs → cursor/compile/insert_messages.rs +cursor/request/runtime.rs → cursor/compile/break_messages.rs +cursor/request/images.rs → cursor/compile/images.rs +cursor/request/model.rs → cursor/compile/model.rs + +cursor/interaction/mod.rs → cursor/protocol/events.rs +cursor/interaction/query.rs → cursor/tools/codec/query.rs +cursor/interaction/render.rs → cursor/tools/codec/render.rs + +cursor/projection/decode.rs → cursor/checkpoint/messages/decode.rs +cursor/projection/encode.rs → cursor/checkpoint/messages/encode.rs +cursor/projection/tests.rs → cursor/checkpoint/messages/tests.rs + +cursor/presentation.rs → cursor/checkpoint/steps.rs + +run/runtime.rs RunRegistry → cursor/conversation/registry.rs +run/runtime.rs RunActor → run/engine.rs + run/handle.rs +run/port.rs → run/command.rs + run/event.rs + run/port.rs + +store/revisions.rs → store/checkpoints.rs +``` + + +## 最终核心 + +```text +Bidi + → Transport(request_id) + → Compile + → Conversation(conversation_id) + → RunEngine + → Provider / Tools + → Conversation + → Checkpoint + → Transport + → RunSSE +``` \ No newline at end of file diff --git a/server/.gitkeep b/server/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/server/Cargo.toml b/server_backup/Cargo.toml similarity index 100% rename from server/Cargo.toml rename to server_backup/Cargo.toml diff --git a/server/build.rs b/server_backup/build.rs similarity index 100% rename from server/build.rs rename to server_backup/build.rs diff --git a/server/migrations/0001_initial.sql b/server_backup/migrations/0001_initial.sql similarity index 100% rename from server/migrations/0001_initial.sql rename to server_backup/migrations/0001_initial.sql diff --git a/server/migrations/0002_llm_call_model_options.sql b/server_backup/migrations/0002_llm_call_model_options.sql similarity index 100% rename from server/migrations/0002_llm_call_model_options.sql rename to server_backup/migrations/0002_llm_call_model_options.sql diff --git a/server/migrations/0003_run_cursor_request_id.sql b/server_backup/migrations/0003_run_cursor_request_id.sql similarity index 100% rename from server/migrations/0003_run_cursor_request_id.sql rename to server_backup/migrations/0003_run_cursor_request_id.sql diff --git a/server/migrations/0004_flatten_model_configuration.sql b/server_backup/migrations/0004_flatten_model_configuration.sql similarity index 100% rename from server/migrations/0004_flatten_model_configuration.sql rename to server_backup/migrations/0004_flatten_model_configuration.sql diff --git a/server/migrations/0005_add_first_valid_response_timing.sql b/server_backup/migrations/0005_add_first_valid_response_timing.sql similarity index 100% rename from server/migrations/0005_add_first_valid_response_timing.sql rename to server_backup/migrations/0005_add_first_valid_response_timing.sql diff --git a/server/prompt/cursor/agent/prompt.md b/server_backup/prompt/cursor/agent/prompt.md similarity index 100% rename from server/prompt/cursor/agent/prompt.md rename to server_backup/prompt/cursor/agent/prompt.md diff --git a/server/prompt/cursor/agent/runtime.md b/server_backup/prompt/cursor/agent/runtime.md similarity index 100% rename from server/prompt/cursor/agent/runtime.md rename to server_backup/prompt/cursor/agent/runtime.md diff --git a/server/prompt/cursor/ask/prompt.md b/server_backup/prompt/cursor/ask/prompt.md similarity index 100% rename from server/prompt/cursor/ask/prompt.md rename to server_backup/prompt/cursor/ask/prompt.md diff --git a/server/prompt/cursor/ask/runtime.md b/server_backup/prompt/cursor/ask/runtime.md similarity index 100% rename from server/prompt/cursor/ask/runtime.md rename to server_backup/prompt/cursor/ask/runtime.md diff --git a/server/prompt/cursor/compaction/prompt.md b/server_backup/prompt/cursor/compaction/prompt.md similarity index 100% rename from server/prompt/cursor/compaction/prompt.md rename to server_backup/prompt/cursor/compaction/prompt.md diff --git a/server/prompt/cursor/compaction/runtime.md b/server_backup/prompt/cursor/compaction/runtime.md similarity index 100% rename from server/prompt/cursor/compaction/runtime.md rename to server_backup/prompt/cursor/compaction/runtime.md diff --git a/server/prompt/cursor/debug/prompt.md b/server_backup/prompt/cursor/debug/prompt.md similarity index 100% rename from server/prompt/cursor/debug/prompt.md rename to server_backup/prompt/cursor/debug/prompt.md diff --git a/server/prompt/cursor/debug/runtime.md b/server_backup/prompt/cursor/debug/runtime.md similarity index 100% rename from server/prompt/cursor/debug/runtime.md rename to server_backup/prompt/cursor/debug/runtime.md diff --git a/server/prompt/cursor/modes/agent.json b/server_backup/prompt/cursor/modes/agent.json similarity index 100% rename from server/prompt/cursor/modes/agent.json rename to server_backup/prompt/cursor/modes/agent.json diff --git a/server/prompt/cursor/modes/ask.json b/server_backup/prompt/cursor/modes/ask.json similarity index 100% rename from server/prompt/cursor/modes/ask.json rename to server_backup/prompt/cursor/modes/ask.json diff --git a/server/prompt/cursor/modes/compaction.json b/server_backup/prompt/cursor/modes/compaction.json similarity index 100% rename from server/prompt/cursor/modes/compaction.json rename to server_backup/prompt/cursor/modes/compaction.json diff --git a/server/prompt/cursor/modes/debug.json b/server_backup/prompt/cursor/modes/debug.json similarity index 100% rename from server/prompt/cursor/modes/debug.json rename to server_backup/prompt/cursor/modes/debug.json diff --git a/server/prompt/cursor/modes/multitask.json b/server_backup/prompt/cursor/modes/multitask.json similarity index 100% rename from server/prompt/cursor/modes/multitask.json rename to server_backup/prompt/cursor/modes/multitask.json diff --git a/server/prompt/cursor/modes/plan.json b/server_backup/prompt/cursor/modes/plan.json similarity index 100% rename from server/prompt/cursor/modes/plan.json rename to server_backup/prompt/cursor/modes/plan.json diff --git a/server/prompt/cursor/modes/subagent.json b/server_backup/prompt/cursor/modes/subagent.json similarity index 100% rename from server/prompt/cursor/modes/subagent.json rename to server_backup/prompt/cursor/modes/subagent.json diff --git a/server/prompt/cursor/multitask/prompt.md b/server_backup/prompt/cursor/multitask/prompt.md similarity index 100% rename from server/prompt/cursor/multitask/prompt.md rename to server_backup/prompt/cursor/multitask/prompt.md diff --git a/server/prompt/cursor/multitask/runtime.md b/server_backup/prompt/cursor/multitask/runtime.md similarity index 100% rename from server/prompt/cursor/multitask/runtime.md rename to server_backup/prompt/cursor/multitask/runtime.md diff --git a/server/prompt/cursor/plan/prompt.md b/server_backup/prompt/cursor/plan/prompt.md similarity index 100% rename from server/prompt/cursor/plan/prompt.md rename to server_backup/prompt/cursor/plan/prompt.md diff --git a/server/prompt/cursor/plan/runtime.md b/server_backup/prompt/cursor/plan/runtime.md similarity index 100% rename from server/prompt/cursor/plan/runtime.md rename to server_backup/prompt/cursor/plan/runtime.md diff --git a/server/prompt/cursor/subagent/prompt.md b/server_backup/prompt/cursor/subagent/prompt.md similarity index 100% rename from server/prompt/cursor/subagent/prompt.md rename to server_backup/prompt/cursor/subagent/prompt.md diff --git a/server/prompt/cursor/subagent/runtime.md b/server_backup/prompt/cursor/subagent/runtime.md similarity index 100% rename from server/prompt/cursor/subagent/runtime.md rename to server_backup/prompt/cursor/subagent/runtime.md diff --git a/server/prompt/cursor/tools.json b/server_backup/prompt/cursor/tools.json similarity index 100% rename from server/prompt/cursor/tools.json rename to server_backup/prompt/cursor/tools.json diff --git a/server/src/app.rs b/server_backup/src/app.rs similarity index 100% rename from server/src/app.rs rename to server_backup/src/app.rs diff --git a/server/src/bin/cursor-server.rs b/server_backup/src/bin/cursor-server.rs similarity index 100% rename from server/src/bin/cursor-server.rs rename to server_backup/src/bin/cursor-server.rs diff --git a/server/src/config.rs b/server_backup/src/config.rs similarity index 100% rename from server/src/config.rs rename to server_backup/src/config.rs diff --git a/server/src/control/ads.rs b/server_backup/src/control/ads.rs similarity index 100% rename from server/src/control/ads.rs rename to server_backup/src/control/ads.rs diff --git a/server/src/control/calls.rs b/server_backup/src/control/calls.rs similarity index 100% rename from server/src/control/calls.rs rename to server_backup/src/control/calls.rs diff --git a/server/src/control/harness.rs b/server_backup/src/control/harness.rs similarity index 100% rename from server/src/control/harness.rs rename to server_backup/src/control/harness.rs diff --git a/server/src/control/mod.rs b/server_backup/src/control/mod.rs similarity index 100% rename from server/src/control/mod.rs rename to server_backup/src/control/mod.rs diff --git a/server/src/control/models.rs b/server_backup/src/control/models.rs similarity index 100% rename from server/src/control/models.rs rename to server_backup/src/control/models.rs diff --git a/server/src/control/overview.rs b/server_backup/src/control/overview.rs similarity index 100% rename from server/src/control/overview.rs rename to server_backup/src/control/overview.rs diff --git a/server/src/control/service.rs b/server_backup/src/control/service.rs similarity index 100% rename from server/src/control/service.rs rename to server_backup/src/control/service.rs diff --git a/server/src/control/settings.rs b/server_backup/src/control/settings.rs similarity index 100% rename from server/src/control/settings.rs rename to server_backup/src/control/settings.rs diff --git a/server/src/cursor/account.rs b/server_backup/src/cursor/account.rs similarity index 100% rename from server/src/cursor/account.rs rename to server_backup/src/cursor/account.rs diff --git a/server/src/cursor/actor.rs b/server_backup/src/cursor/actor.rs similarity index 100% rename from server/src/cursor/actor.rs rename to server_backup/src/cursor/actor.rs diff --git a/server/src/cursor/analytics.rs b/server_backup/src/cursor/analytics.rs similarity index 100% rename from server/src/cursor/analytics.rs rename to server_backup/src/cursor/analytics.rs diff --git a/server/src/cursor/bidi_append.rs b/server_backup/src/cursor/bidi_append.rs similarity index 100% rename from server/src/cursor/bidi_append.rs rename to server_backup/src/cursor/bidi_append.rs diff --git a/server/src/cursor/blob_sync.rs b/server_backup/src/cursor/blob_sync.rs similarity index 100% rename from server/src/cursor/blob_sync.rs rename to server_backup/src/cursor/blob_sync.rs diff --git a/server/src/cursor/checkpoint/derived.rs b/server_backup/src/cursor/checkpoint/derived.rs similarity index 100% rename from server/src/cursor/checkpoint/derived.rs rename to server_backup/src/cursor/checkpoint/derived.rs diff --git a/server/src/cursor/checkpoint/mod.rs b/server_backup/src/cursor/checkpoint/mod.rs similarity index 100% rename from server/src/cursor/checkpoint/mod.rs rename to server_backup/src/cursor/checkpoint/mod.rs diff --git a/server/src/cursor/checkpoint/recovery.rs b/server_backup/src/cursor/checkpoint/recovery.rs similarity index 100% rename from server/src/cursor/checkpoint/recovery.rs rename to server_backup/src/cursor/checkpoint/recovery.rs diff --git a/server/src/cursor/checkpoint/roots.rs b/server_backup/src/cursor/checkpoint/roots.rs similarity index 100% rename from server/src/cursor/checkpoint/roots.rs rename to server_backup/src/cursor/checkpoint/roots.rs diff --git a/server/src/cursor/checkpoint/summary.rs b/server_backup/src/cursor/checkpoint/summary.rs similarity index 100% rename from server/src/cursor/checkpoint/summary.rs rename to server_backup/src/cursor/checkpoint/summary.rs diff --git a/server/src/cursor/checkpoint/turns.rs b/server_backup/src/cursor/checkpoint/turns.rs similarity index 100% rename from server/src/cursor/checkpoint/turns.rs rename to server_backup/src/cursor/checkpoint/turns.rs diff --git a/server/src/cursor/checkpoint/worker.rs b/server_backup/src/cursor/checkpoint/worker.rs similarity index 100% rename from server/src/cursor/checkpoint/worker.rs rename to server_backup/src/cursor/checkpoint/worker.rs diff --git a/server/src/cursor/command.rs b/server_backup/src/cursor/command.rs similarity index 100% rename from server/src/cursor/command.rs rename to server_backup/src/cursor/command.rs diff --git a/server/src/cursor/connect.rs b/server_backup/src/cursor/connect.rs similarity index 100% rename from server/src/cursor/connect.rs rename to server_backup/src/cursor/connect.rs diff --git a/server/src/cursor/context_sync.rs b/server_backup/src/cursor/context_sync.rs similarity index 100% rename from server/src/cursor/context_sync.rs rename to server_backup/src/cursor/context_sync.rs diff --git a/server/src/cursor/handlers.rs b/server_backup/src/cursor/handlers.rs similarity index 100% rename from server/src/cursor/handlers.rs rename to server_backup/src/cursor/handlers.rs diff --git a/server/src/cursor/inbox.rs b/server_backup/src/cursor/inbox.rs similarity index 100% rename from server/src/cursor/inbox.rs rename to server_backup/src/cursor/inbox.rs diff --git a/server/src/cursor/interaction/mod.rs b/server_backup/src/cursor/interaction/mod.rs similarity index 100% rename from server/src/cursor/interaction/mod.rs rename to server_backup/src/cursor/interaction/mod.rs diff --git a/server/src/cursor/interaction/query.rs b/server_backup/src/cursor/interaction/query.rs similarity index 100% rename from server/src/cursor/interaction/query.rs rename to server_backup/src/cursor/interaction/query.rs diff --git a/server/src/cursor/interaction/render.rs b/server_backup/src/cursor/interaction/render.rs similarity index 100% rename from server/src/cursor/interaction/render.rs rename to server_backup/src/cursor/interaction/render.rs diff --git a/server/src/cursor/json_stream.rs b/server_backup/src/cursor/json_stream.rs similarity index 100% rename from server/src/cursor/json_stream.rs rename to server_backup/src/cursor/json_stream.rs diff --git a/server/src/cursor/lifecycle.rs b/server_backup/src/cursor/lifecycle.rs similarity index 100% rename from server/src/cursor/lifecycle.rs rename to server_backup/src/cursor/lifecycle.rs diff --git a/server/src/cursor/mod.rs b/server_backup/src/cursor/mod.rs similarity index 100% rename from server/src/cursor/mod.rs rename to server_backup/src/cursor/mod.rs diff --git a/server/src/cursor/model_catalog.rs b/server_backup/src/cursor/model_catalog.rs similarity index 100% rename from server/src/cursor/model_catalog.rs rename to server_backup/src/cursor/model_catalog.rs diff --git a/server/src/cursor/observability.rs b/server_backup/src/cursor/observability.rs similarity index 100% rename from server/src/cursor/observability.rs rename to server_backup/src/cursor/observability.rs diff --git a/server/src/cursor/presentation.rs b/server_backup/src/cursor/presentation.rs similarity index 100% rename from server/src/cursor/presentation.rs rename to server_backup/src/cursor/presentation.rs diff --git a/server/src/cursor/projection/decode.rs b/server_backup/src/cursor/projection/decode.rs similarity index 100% rename from server/src/cursor/projection/decode.rs rename to server_backup/src/cursor/projection/decode.rs diff --git a/server/src/cursor/projection/encode.rs b/server_backup/src/cursor/projection/encode.rs similarity index 100% rename from server/src/cursor/projection/encode.rs rename to server_backup/src/cursor/projection/encode.rs diff --git a/server/src/cursor/projection/mod.rs b/server_backup/src/cursor/projection/mod.rs similarity index 100% rename from server/src/cursor/projection/mod.rs rename to server_backup/src/cursor/projection/mod.rs diff --git a/server/src/cursor/projection/tests.rs b/server_backup/src/cursor/projection/tests.rs similarity index 100% rename from server/src/cursor/projection/tests.rs rename to server_backup/src/cursor/projection/tests.rs diff --git a/server/src/cursor/prompting/assets.rs b/server_backup/src/cursor/prompting/assets.rs similarity index 100% rename from server/src/cursor/prompting/assets.rs rename to server_backup/src/cursor/prompting/assets.rs diff --git a/server/src/cursor/prompting/catalog.rs b/server_backup/src/cursor/prompting/catalog.rs similarity index 100% rename from server/src/cursor/prompting/catalog.rs rename to server_backup/src/cursor/prompting/catalog.rs diff --git a/server/src/cursor/prompting/compiler.rs b/server_backup/src/cursor/prompting/compiler.rs similarity index 100% rename from server/src/cursor/prompting/compiler.rs rename to server_backup/src/cursor/prompting/compiler.rs diff --git a/server/src/cursor/prompting/derived_state.rs b/server_backup/src/cursor/prompting/derived_state.rs similarity index 100% rename from server/src/cursor/prompting/derived_state.rs rename to server_backup/src/cursor/prompting/derived_state.rs diff --git a/server/src/cursor/prompting/mod.rs b/server_backup/src/cursor/prompting/mod.rs similarity index 100% rename from server/src/cursor/prompting/mod.rs rename to server_backup/src/cursor/prompting/mod.rs diff --git a/server/src/cursor/proto.rs b/server_backup/src/cursor/proto.rs similarity index 100% rename from server/src/cursor/proto.rs rename to server_backup/src/cursor/proto.rs diff --git a/server/src/cursor/proxy.rs b/server_backup/src/cursor/proxy.rs similarity index 100% rename from server/src/cursor/proxy.rs rename to server_backup/src/cursor/proxy.rs diff --git a/server/src/cursor/request/background.rs b/server_backup/src/cursor/request/background.rs similarity index 100% rename from server/src/cursor/request/background.rs rename to server_backup/src/cursor/request/background.rs diff --git a/server/src/cursor/request/context.rs b/server_backup/src/cursor/request/context.rs similarity index 100% rename from server/src/cursor/request/context.rs rename to server_backup/src/cursor/request/context.rs diff --git a/server/src/cursor/request/images.rs b/server_backup/src/cursor/request/images.rs similarity index 100% rename from server/src/cursor/request/images.rs rename to server_backup/src/cursor/request/images.rs diff --git a/server/src/cursor/request/mod.rs b/server_backup/src/cursor/request/mod.rs similarity index 100% rename from server/src/cursor/request/mod.rs rename to server_backup/src/cursor/request/mod.rs diff --git a/server/src/cursor/request/model.rs b/server_backup/src/cursor/request/model.rs similarity index 100% rename from server/src/cursor/request/model.rs rename to server_backup/src/cursor/request/model.rs diff --git a/server/src/cursor/request/prepare.rs b/server_backup/src/cursor/request/prepare.rs similarity index 100% rename from server/src/cursor/request/prepare.rs rename to server_backup/src/cursor/request/prepare.rs diff --git a/server/src/cursor/request/runtime.rs b/server_backup/src/cursor/request/runtime.rs similarity index 100% rename from server/src/cursor/request/runtime.rs rename to server_backup/src/cursor/request/runtime.rs diff --git a/server/src/cursor/run_sse.rs b/server_backup/src/cursor/run_sse.rs similarity index 100% rename from server/src/cursor/run_sse.rs rename to server_backup/src/cursor/run_sse.rs diff --git a/server/src/cursor/session.rs b/server_backup/src/cursor/session.rs similarity index 100% rename from server/src/cursor/session.rs rename to server_backup/src/cursor/session.rs diff --git a/server/src/cursor/sessions.rs b/server_backup/src/cursor/sessions.rs similarity index 100% rename from server/src/cursor/sessions.rs rename to server_backup/src/cursor/sessions.rs diff --git a/server/src/cursor/tab.rs b/server_backup/src/cursor/tab.rs similarity index 100% rename from server/src/cursor/tab.rs rename to server_backup/src/cursor/tab.rs diff --git a/server/src/cursor/tools/codec/mod.rs b/server_backup/src/cursor/tools/codec/mod.rs similarity index 100% rename from server/src/cursor/tools/codec/mod.rs rename to server_backup/src/cursor/tools/codec/mod.rs diff --git a/server/src/cursor/tools/codec/request.rs b/server_backup/src/cursor/tools/codec/request.rs similarity index 100% rename from server/src/cursor/tools/codec/request.rs rename to server_backup/src/cursor/tools/codec/request.rs diff --git a/server/src/cursor/tools/codec/response.rs b/server_backup/src/cursor/tools/codec/response.rs similarity index 100% rename from server/src/cursor/tools/codec/response.rs rename to server_backup/src/cursor/tools/codec/response.rs diff --git a/server/src/cursor/tools/compat.rs b/server_backup/src/cursor/tools/compat.rs similarity index 100% rename from server/src/cursor/tools/compat.rs rename to server_backup/src/cursor/tools/compat.rs diff --git a/server/src/cursor/tools/dispatch/edit.rs b/server_backup/src/cursor/tools/dispatch/edit.rs similarity index 100% rename from server/src/cursor/tools/dispatch/edit.rs rename to server_backup/src/cursor/tools/dispatch/edit.rs diff --git a/server/src/cursor/tools/dispatch/exec.rs b/server_backup/src/cursor/tools/dispatch/exec.rs similarity index 100% rename from server/src/cursor/tools/dispatch/exec.rs rename to server_backup/src/cursor/tools/dispatch/exec.rs diff --git a/server/src/cursor/tools/dispatch/interaction.rs b/server_backup/src/cursor/tools/dispatch/interaction.rs similarity index 100% rename from server/src/cursor/tools/dispatch/interaction.rs rename to server_backup/src/cursor/tools/dispatch/interaction.rs diff --git a/server/src/cursor/tools/dispatch/local.rs b/server_backup/src/cursor/tools/dispatch/local.rs similarity index 100% rename from server/src/cursor/tools/dispatch/local.rs rename to server_backup/src/cursor/tools/dispatch/local.rs diff --git a/server/src/cursor/tools/dispatch/mod.rs b/server_backup/src/cursor/tools/dispatch/mod.rs similarity index 100% rename from server/src/cursor/tools/dispatch/mod.rs rename to server_backup/src/cursor/tools/dispatch/mod.rs diff --git a/server/src/cursor/tools/dispatch/semble.rs b/server_backup/src/cursor/tools/dispatch/semble.rs similarity index 100% rename from server/src/cursor/tools/dispatch/semble.rs rename to server_backup/src/cursor/tools/dispatch/semble.rs diff --git a/server/src/cursor/tools/edit.rs b/server_backup/src/cursor/tools/edit.rs similarity index 100% rename from server/src/cursor/tools/edit.rs rename to server_backup/src/cursor/tools/edit.rs diff --git a/server/src/cursor/tools/mod.rs b/server_backup/src/cursor/tools/mod.rs similarity index 100% rename from server/src/cursor/tools/mod.rs rename to server_backup/src/cursor/tools/mod.rs diff --git a/server/src/cursor/tools/result/exec/mod.rs b/server_backup/src/cursor/tools/result/exec/mod.rs similarity index 100% rename from server/src/cursor/tools/result/exec/mod.rs rename to server_backup/src/cursor/tools/result/exec/mod.rs diff --git a/server/src/cursor/tools/result/exec/output.rs b/server_backup/src/cursor/tools/result/exec/output.rs similarity index 100% rename from server/src/cursor/tools/result/exec/output.rs rename to server_backup/src/cursor/tools/result/exec/output.rs diff --git a/server/src/cursor/tools/result/exec/render.rs b/server_backup/src/cursor/tools/result/exec/render.rs similarity index 100% rename from server/src/cursor/tools/result/exec/render.rs rename to server_backup/src/cursor/tools/result/exec/render.rs diff --git a/server/src/cursor/tools/result/gate.rs b/server_backup/src/cursor/tools/result/gate.rs similarity index 100% rename from server/src/cursor/tools/result/gate.rs rename to server_backup/src/cursor/tools/result/gate.rs diff --git a/server/src/cursor/tools/result/interaction.rs b/server_backup/src/cursor/tools/result/interaction.rs similarity index 100% rename from server/src/cursor/tools/result/interaction.rs rename to server_backup/src/cursor/tools/result/interaction.rs diff --git a/server/src/cursor/tools/result/local.rs b/server_backup/src/cursor/tools/result/local.rs similarity index 100% rename from server/src/cursor/tools/result/local.rs rename to server_backup/src/cursor/tools/result/local.rs diff --git a/server/src/cursor/tools/result/mcp.rs b/server_backup/src/cursor/tools/result/mcp.rs similarity index 100% rename from server/src/cursor/tools/result/mcp.rs rename to server_backup/src/cursor/tools/result/mcp.rs diff --git a/server/src/cursor/tools/result/mcp_state.rs b/server_backup/src/cursor/tools/result/mcp_state.rs similarity index 100% rename from server/src/cursor/tools/result/mcp_state.rs rename to server_backup/src/cursor/tools/result/mcp_state.rs diff --git a/server/src/cursor/tools/result/mod.rs b/server_backup/src/cursor/tools/result/mod.rs similarity index 100% rename from server/src/cursor/tools/result/mod.rs rename to server_backup/src/cursor/tools/result/mod.rs diff --git a/server/src/cursor/tools/result/semble.rs b/server_backup/src/cursor/tools/result/semble.rs similarity index 100% rename from server/src/cursor/tools/result/semble.rs rename to server_backup/src/cursor/tools/result/semble.rs diff --git a/server/src/cursor/tools/runtime.rs b/server_backup/src/cursor/tools/runtime.rs similarity index 100% rename from server/src/cursor/tools/runtime.rs rename to server_backup/src/cursor/tools/runtime.rs diff --git a/server/src/cursor/tools/schedule.rs b/server_backup/src/cursor/tools/schedule.rs similarity index 100% rename from server/src/cursor/tools/schedule.rs rename to server_backup/src/cursor/tools/schedule.rs diff --git a/server/src/cursor/tools/stream.rs b/server_backup/src/cursor/tools/stream.rs similarity index 100% rename from server/src/cursor/tools/stream.rs rename to server_backup/src/cursor/tools/stream.rs diff --git a/server/src/cursor/tools/tests.rs b/server_backup/src/cursor/tools/tests.rs similarity index 100% rename from server/src/cursor/tools/tests.rs rename to server_backup/src/cursor/tools/tests.rs diff --git a/server/src/cursor/usage.rs b/server_backup/src/cursor/usage.rs similarity index 100% rename from server/src/cursor/usage.rs rename to server_backup/src/cursor/usage.rs diff --git a/server/src/error.rs b/server_backup/src/error.rs similarity index 100% rename from server/src/error.rs rename to server_backup/src/error.rs diff --git a/server/src/harness/account.rs b/server_backup/src/harness/account.rs similarity index 100% rename from server/src/harness/account.rs rename to server_backup/src/harness/account.rs diff --git a/server/src/harness/ca.rs b/server_backup/src/harness/ca.rs similarity index 100% rename from server/src/harness/ca.rs rename to server_backup/src/harness/ca.rs diff --git a/server/src/harness/ca/windows.rs b/server_backup/src/harness/ca/windows.rs similarity index 100% rename from server/src/harness/ca/windows.rs rename to server_backup/src/harness/ca/windows.rs diff --git a/server/src/harness/mod.rs b/server_backup/src/harness/mod.rs similarity index 100% rename from server/src/harness/mod.rs rename to server_backup/src/harness/mod.rs diff --git a/server/src/harness/proxy.rs b/server_backup/src/harness/proxy.rs similarity index 100% rename from server/src/harness/proxy.rs rename to server_backup/src/harness/proxy.rs diff --git a/server/src/harness/settings.rs b/server_backup/src/harness/settings.rs similarity index 100% rename from server/src/harness/settings.rs rename to server_backup/src/harness/settings.rs diff --git a/server/src/lib.rs b/server_backup/src/lib.rs similarity index 100% rename from server/src/lib.rs rename to server_backup/src/lib.rs diff --git a/server/src/model/configuration.rs b/server_backup/src/model/configuration.rs similarity index 100% rename from server/src/model/configuration.rs rename to server_backup/src/model/configuration.rs diff --git a/server/src/model/conversation.rs b/server_backup/src/model/conversation.rs similarity index 100% rename from server/src/model/conversation.rs rename to server_backup/src/model/conversation.rs diff --git a/server/src/model/inference.rs b/server_backup/src/model/inference.rs similarity index 100% rename from server/src/model/inference.rs rename to server_backup/src/model/inference.rs diff --git a/server/src/model/message.rs b/server_backup/src/model/message.rs similarity index 100% rename from server/src/model/message.rs rename to server_backup/src/model/message.rs diff --git a/server/src/model/mod.rs b/server_backup/src/model/mod.rs similarity index 100% rename from server/src/model/mod.rs rename to server_backup/src/model/mod.rs diff --git a/server/src/model/model_spec.rs b/server_backup/src/model/model_spec.rs similarity index 100% rename from server/src/model/model_spec.rs rename to server_backup/src/model/model_spec.rs diff --git a/server/src/model/observability.rs b/server_backup/src/model/observability.rs similarity index 100% rename from server/src/model/observability.rs rename to server_backup/src/model/observability.rs diff --git a/server/src/model/projection.rs b/server_backup/src/model/projection.rs similarity index 100% rename from server/src/model/projection.rs rename to server_backup/src/model/projection.rs diff --git a/server/src/model/run.rs b/server_backup/src/model/run.rs similarity index 100% rename from server/src/model/run.rs rename to server_backup/src/model/run.rs diff --git a/server/src/model/runtime_tag.rs b/server_backup/src/model/runtime_tag.rs similarity index 100% rename from server/src/model/runtime_tag.rs rename to server_backup/src/model/runtime_tag.rs diff --git a/server/src/model/token_count.rs b/server_backup/src/model/token_count.rs similarity index 100% rename from server/src/model/token_count.rs rename to server_backup/src/model/token_count.rs diff --git a/server/src/model/tool.rs b/server_backup/src/model/tool.rs similarity index 100% rename from server/src/model/tool.rs rename to server_backup/src/model/tool.rs diff --git a/server/src/model/tool_result_replay.rs b/server_backup/src/model/tool_result_replay.rs similarity index 100% rename from server/src/model/tool_result_replay.rs rename to server_backup/src/model/tool_result_replay.rs diff --git a/server/src/network.rs b/server_backup/src/network.rs similarity index 100% rename from server/src/network.rs rename to server_backup/src/network.rs diff --git a/server/src/provider/anthropic.rs b/server_backup/src/provider/anthropic.rs similarity index 100% rename from server/src/provider/anthropic.rs rename to server_backup/src/provider/anthropic.rs diff --git a/server/src/provider/event.rs b/server_backup/src/provider/event.rs similarity index 100% rename from server/src/provider/event.rs rename to server_backup/src/provider/event.rs diff --git a/server/src/provider/mod.rs b/server_backup/src/provider/mod.rs similarity index 100% rename from server/src/provider/mod.rs rename to server_backup/src/provider/mod.rs diff --git a/server/src/provider/normalize.rs b/server_backup/src/provider/normalize.rs similarity index 100% rename from server/src/provider/normalize.rs rename to server_backup/src/provider/normalize.rs diff --git a/server/src/provider/openai_chat.rs b/server_backup/src/provider/openai_chat.rs similarity index 100% rename from server/src/provider/openai_chat.rs rename to server_backup/src/provider/openai_chat.rs diff --git a/server/src/provider/openai_responses.rs b/server_backup/src/provider/openai_responses.rs similarity index 100% rename from server/src/provider/openai_responses.rs rename to server_backup/src/provider/openai_responses.rs diff --git a/server/src/provider/recorder.rs b/server_backup/src/provider/recorder.rs similarity index 100% rename from server/src/provider/recorder.rs rename to server_backup/src/provider/recorder.rs diff --git a/server/src/provider/retry.rs b/server_backup/src/provider/retry.rs similarity index 100% rename from server/src/provider/retry.rs rename to server_backup/src/provider/retry.rs diff --git a/server/src/provider/router.rs b/server_backup/src/provider/router.rs similarity index 100% rename from server/src/provider/router.rs rename to server_backup/src/provider/router.rs diff --git a/server/src/run/engine.rs b/server_backup/src/run/engine.rs similarity index 100% rename from server/src/run/engine.rs rename to server_backup/src/run/engine.rs diff --git a/server/src/run/mod.rs b/server_backup/src/run/mod.rs similarity index 100% rename from server/src/run/mod.rs rename to server_backup/src/run/mod.rs diff --git a/server/src/run/model_cycle.rs b/server_backup/src/run/model_cycle.rs similarity index 100% rename from server/src/run/model_cycle.rs rename to server_backup/src/run/model_cycle.rs diff --git a/server/src/run/port.rs b/server_backup/src/run/port.rs similarity index 100% rename from server/src/run/port.rs rename to server_backup/src/run/port.rs diff --git a/server/src/run/runtime.rs b/server_backup/src/run/runtime.rs similarity index 100% rename from server/src/run/runtime.rs rename to server_backup/src/run/runtime.rs diff --git a/server/src/run/tool_round.rs b/server_backup/src/run/tool_round.rs similarity index 100% rename from server/src/run/tool_round.rs rename to server_backup/src/run/tool_round.rs diff --git a/server/src/search/catalog.rs b/server_backup/src/search/catalog.rs similarity index 100% rename from server/src/search/catalog.rs rename to server_backup/src/search/catalog.rs diff --git a/server/src/search/engine.rs b/server_backup/src/search/engine.rs similarity index 100% rename from server/src/search/engine.rs rename to server_backup/src/search/engine.rs diff --git a/server/src/search/federation.rs b/server_backup/src/search/federation.rs similarity index 100% rename from server/src/search/federation.rs rename to server_backup/src/search/federation.rs diff --git a/server/src/search/fetch.rs b/server_backup/src/search/fetch.rs similarity index 100% rename from server/src/search/fetch.rs rename to server_backup/src/search/fetch.rs diff --git a/server/src/search/mod.rs b/server_backup/src/search/mod.rs similarity index 100% rename from server/src/search/mod.rs rename to server_backup/src/search/mod.rs diff --git a/server/src/search/semble.rs b/server_backup/src/search/semble.rs similarity index 100% rename from server/src/search/semble.rs rename to server_backup/src/search/semble.rs diff --git a/server/src/store/cas.rs b/server_backup/src/store/cas.rs similarity index 100% rename from server/src/store/cas.rs rename to server_backup/src/store/cas.rs diff --git a/server/src/store/conversations.rs b/server_backup/src/store/conversations.rs similarity index 100% rename from server/src/store/conversations.rs rename to server_backup/src/store/conversations.rs diff --git a/server/src/store/cursor_traces.rs b/server_backup/src/store/cursor_traces.rs similarity index 100% rename from server/src/store/cursor_traces.rs rename to server_backup/src/store/cursor_traces.rs diff --git a/server/src/store/input_anchors.rs b/server_backup/src/store/input_anchors.rs similarity index 100% rename from server/src/store/input_anchors.rs rename to server_backup/src/store/input_anchors.rs diff --git a/server/src/store/legacy_config.rs b/server_backup/src/store/legacy_config.rs similarity index 100% rename from server/src/store/legacy_config.rs rename to server_backup/src/store/legacy_config.rs diff --git a/server/src/store/llm_calls.rs b/server_backup/src/store/llm_calls.rs similarity index 100% rename from server/src/store/llm_calls.rs rename to server_backup/src/store/llm_calls.rs diff --git a/server/src/store/messages.rs b/server_backup/src/store/messages.rs similarity index 100% rename from server/src/store/messages.rs rename to server_backup/src/store/messages.rs diff --git a/server/src/store/mod.rs b/server_backup/src/store/mod.rs similarity index 100% rename from server/src/store/mod.rs rename to server_backup/src/store/mod.rs diff --git a/server/src/store/models.rs b/server_backup/src/store/models.rs similarity index 100% rename from server/src/store/models.rs rename to server_backup/src/store/models.rs diff --git a/server/src/store/overview.rs b/server_backup/src/store/overview.rs similarity index 100% rename from server/src/store/overview.rs rename to server_backup/src/store/overview.rs diff --git a/server/src/store/revisions.rs b/server_backup/src/store/revisions.rs similarity index 100% rename from server/src/store/revisions.rs rename to server_backup/src/store/revisions.rs diff --git a/server/src/store/runs.rs b/server_backup/src/store/runs.rs similarity index 100% rename from server/src/store/runs.rs rename to server_backup/src/store/runs.rs diff --git a/server/src/store/settings.rs b/server_backup/src/store/settings.rs similarity index 100% rename from server/src/store/settings.rs rename to server_backup/src/store/settings.rs diff --git a/server/src/store/sqlite.rs b/server_backup/src/store/sqlite.rs similarity index 100% rename from server/src/store/sqlite.rs rename to server_backup/src/store/sqlite.rs diff --git a/server/src/store/storage.rs b/server_backup/src/store/storage.rs similarity index 100% rename from server/src/store/storage.rs rename to server_backup/src/store/storage.rs diff --git a/server/src/store/tool_rounds.rs b/server_backup/src/store/tool_rounds.rs similarity index 100% rename from server/src/store/tool_rounds.rs rename to server_backup/src/store/tool_rounds.rs diff --git a/server/src/store/writer.rs b/server_backup/src/store/writer.rs similarity index 100% rename from server/src/store/writer.rs rename to server_backup/src/store/writer.rs diff --git a/server/tests/background_completion.rs b/server_backup/tests/background_completion.rs similarity index 100% rename from server/tests/background_completion.rs rename to server_backup/tests/background_completion.rs diff --git a/server/tests/checkpoint_recovery.rs b/server_backup/tests/checkpoint_recovery.rs similarity index 100% rename from server/tests/checkpoint_recovery.rs rename to server_backup/tests/checkpoint_recovery.rs diff --git a/server/tests/client_contract.rs b/server_backup/tests/client_contract.rs similarity index 100% rename from server/tests/client_contract.rs rename to server_backup/tests/client_contract.rs diff --git a/server/tests/compaction.rs b/server_backup/tests/compaction.rs similarity index 100% rename from server/tests/compaction.rs rename to server_backup/tests/compaction.rs diff --git a/server/tests/connect_wire.rs b/server_backup/tests/connect_wire.rs similarity index 100% rename from server/tests/connect_wire.rs rename to server_backup/tests/connect_wire.rs diff --git a/server/tests/error_lifecycle.rs b/server_backup/tests/error_lifecycle.rs similarity index 100% rename from server/tests/error_lifecycle.rs rename to server_backup/tests/error_lifecycle.rs diff --git a/server/tests/interrupt.rs b/server_backup/tests/interrupt.rs similarity index 100% rename from server/tests/interrupt.rs rename to server_backup/tests/interrupt.rs diff --git a/server/tests/model_configuration.rs b/server_backup/tests/model_configuration.rs similarity index 100% rename from server/tests/model_configuration.rs rename to server_backup/tests/model_configuration.rs diff --git a/server/tests/observability.rs b/server_backup/tests/observability.rs similarity index 100% rename from server/tests/observability.rs rename to server_backup/tests/observability.rs diff --git a/server/tests/prefix_stability.rs b/server_backup/tests/prefix_stability.rs similarity index 100% rename from server/tests/prefix_stability.rs rename to server_backup/tests/prefix_stability.rs diff --git a/server/tests/provider_stream.rs b/server_backup/tests/provider_stream.rs similarity index 100% rename from server/tests/provider_stream.rs rename to server_backup/tests/provider_stream.rs diff --git a/server/tests/removed_tool_compat.rs b/server_backup/tests/removed_tool_compat.rs similarity index 100% rename from server/tests/removed_tool_compat.rs rename to server_backup/tests/removed_tool_compat.rs diff --git a/server/tests/revision_branch.rs b/server_backup/tests/revision_branch.rs similarity index 100% rename from server/tests/revision_branch.rs rename to server_backup/tests/revision_branch.rs diff --git a/server/tests/runtime_modes.rs b/server_backup/tests/runtime_modes.rs similarity index 100% rename from server/tests/runtime_modes.rs rename to server_backup/tests/runtime_modes.rs diff --git a/server/tests/runtime_tag_once.rs b/server_backup/tests/runtime_tag_once.rs similarity index 100% rename from server/tests/runtime_tag_once.rs rename to server_backup/tests/runtime_tag_once.rs diff --git a/server/tests/schema_upgrade.rs b/server_backup/tests/schema_upgrade.rs similarity index 100% rename from server/tests/schema_upgrade.rs rename to server_backup/tests/schema_upgrade.rs diff --git a/server/tests/selected_images.rs b/server_backup/tests/selected_images.rs similarity index 100% rename from server/tests/selected_images.rs rename to server_backup/tests/selected_images.rs diff --git a/server/tests/subagent_e2e.rs b/server_backup/tests/subagent_e2e.rs similarity index 100% rename from server/tests/subagent_e2e.rs rename to server_backup/tests/subagent_e2e.rs diff --git a/server/tests/subagent_protocol.rs b/server_backup/tests/subagent_protocol.rs similarity index 100% rename from server/tests/subagent_protocol.rs rename to server_backup/tests/subagent_protocol.rs diff --git a/server/tests/support/fake_cursor.rs b/server_backup/tests/support/fake_cursor.rs similarity index 100% rename from server/tests/support/fake_cursor.rs rename to server_backup/tests/support/fake_cursor.rs diff --git a/server/tests/support/fake_provider.rs b/server_backup/tests/support/fake_provider.rs similarity index 100% rename from server/tests/support/fake_provider.rs rename to server_backup/tests/support/fake_provider.rs diff --git a/server/tests/support/fixtures.rs b/server_backup/tests/support/fixtures.rs similarity index 100% rename from server/tests/support/fixtures.rs rename to server_backup/tests/support/fixtures.rs diff --git a/server/tests/text_turn.rs b/server_backup/tests/text_turn.rs similarity index 100% rename from server/tests/text_turn.rs rename to server_backup/tests/text_turn.rs diff --git a/server/tests/tool_loop.rs b/server_backup/tests/tool_loop.rs similarity index 100% rename from server/tests/tool_loop.rs rename to server_backup/tests/tool_loop.rs diff --git a/server/tests/tool_order.rs b/server_backup/tests/tool_order.rs similarity index 100% rename from server/tests/tool_order.rs rename to server_backup/tests/tool_order.rs diff --git a/server/tests/web_search.rs b/server_backup/tests/web_search.rs similarity index 100% rename from server/tests/web_search.rs rename to server_backup/tests/web_search.rs