From 1e4245956089da4495e311dd10beb325f2fde92b Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:56:07 +0800 Subject: [PATCH] docs: design.md v3-final (startup env + dynamic model picker, no settings) Co-Authored-By: Claude Fable 5 --- design.md | 77 ++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/design.md b/design.md index bbd7300..32f9a0f 100644 --- a/design.md +++ b/design.md @@ -45,7 +45,12 @@ 1. **原生 Cell Toolbar 单按钮(2026-07-23 v2 修正)**:不再自绘悬浮 toolbar,也合并了 v1 的三个 mode(优化/排错/编辑)为单个 `🪄 AI 智能编辑` 图标按钮。通过 `IToolbarWidgetRegistry.addFactory('Cell', 'opencode-cell-actions', ...)` 注入 JupyterLab 原生 cell toolbar,显示在 **active cell 右上角**(move up/down 按钮旁,`rank: 100` 排在 delete 右侧);仅 `CodeCell` 显示,随 active cell 切换移动。**前端不做任何语义处理** —— 不再发 `mode` 字段,后端用统一的系统提示词 + 用户的自然语言指令 + 上下文(含 traceback)由 LLM 自己判断是优化/排错/编辑。 -2. **Inline Prompt 输入框(v2 实现)**:点击 `🪄 AI 智能编辑` 按钮后,`OpenCodeInlinePrompt` widget 追加到当前 `CodeCell` 的 DOM 末尾,呈现内嵌输入面板:多行 `textarea`(placeholder "向 AI 描述你想要的修改…",无默认值)+ `🚀 发送` + `✕ 取消` 两个按钮。提交时前端仅收集 cell `source` / `outputs` / `error` 与用户在 textarea 里写的指令,POST `/opencode-bridge/edit`,body 为 `{prompt, context, providerId?, modelId?}`(**无 `mode`**)。**成功** → 前端调用 `cell.model.sharedModel.setSource(resp.finalSource)` 就地替换 cell 源码 + `Notification.info`;**失败** → `Notification.error`,输入框保留(可改文案重发)。Session 由服务端 `SessionManager` 保证 1 notebook 1 sid(前端不感知)。 +2. **Inline Prompt 输入框(v3-final)**:点击 `🪄 AI 智能编辑` 按钮后,`OpenCodeInlinePrompt` widget 追加到当前 `CodeCell` 的 DOM 末尾,呈现内嵌输入面板: + * 顶部一行 `模型: ` 的选项来自 `index.ts` 启动时 `callOpenCodeProviders` 拉取并写入 `setOpenCodeProviders(p)` 的模块级缓存: ``` -Settings (JupyterLab) - │ - ├── opencodeProvider = "anthropic" - └── opencodeModel = "claude-sonnet-4-20250514" - │ - ▼ setOpenCodeRuntime() - Frontend (opencode_cell_footer.ts) - │ - ▼ build request body - POST /opencode-bridge/edit - { mode, prompt, context, providerId, modelId } - │ - ▼ send_message_sync - OpenCode Serve 接受 model = { providerID, modelID } +index.ts (启动) + └─ GET /opencode-bridge/providers + └─ setOpenCodeProviders(data) // 模块级 _providers + └─ OpenCodeInlinePrompt 构造时读 + └─