Draft
Conversation
- gm-api.spec.ts: Phase 2 重启 context 后等待 service worker 注册完成 再交给 fixtures,避免 extensionId fixture 用 10s 全局超时等待失败 - gm-api.spec.ts: 用事件驱动 Promise 替换 500ms 轮询循环, console 结果一出现立即继续 - utils.ts: installScriptByCode 用 DOM 事件等待替代固定延迟: click 后等光标出现,粘贴后等 .view-lines 内容变化 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
新增 AI Agent 聊天模块,包括聊天界面、服务层、数据存储和多语言支持
将 Agent API 请求路由到 runtime/gmApi 通道,通过 @PermissionVerify.API 装饰器实现权限验证,脚本首次调用时弹窗确认,防止未授权消耗 API Token。
- 新增 OPFS 文件浏览器页面,支持目录浏览、文件预览和删除操作 - 默认进入 agents/ 目录,支持面包屑导航到根目录 - 支持在 conversation.create 时注册工具,简化多轮对话的工具传递 - 添加 8 种语言的 i18n 翻译
- 修复 callLLM 提前转发 done 事件导致客户端过早 resolve 的问题 - 修复 WindowMessage.connect 未使用 "*" targetOrigin 导致沙箱消息被丢弃 - 修复 tool calling 循环中 assistant 消息缺少 tool_calls 字段 - 支持 OpenAI 和 Anthropic 格式的 tool_calls 消息构建 - UI 合并 tool 结果到 assistant 的 ToolCallBlock 展示,过滤 tool/system 消息 - 提取 buildInstance 函数解决装饰器 this 绑定问题,使用 uuidv4 生成 ID
- ChatMessage 类型新增 usage/durationMs/firstTokenMs 字段 - Service Worker 测量 LLM 调用总耗时并通过 done 事件返回 - UI 层捕获首 token 延迟和 token 用量,持久化到消息中 - 新增 MessageToolbar 组件:左侧操作按钮(复制/重新回答/删除),右侧元数据信息(token用量/耗时/TTFT/工具调用数) - 流式期间显示实时计时动画,完成后切换为最终数据 - 删除操作支持二次确认 - 新增 deleteMessages 批量删除辅助函数 - 添加 i18n 多语言支持(8个locale)
- 新增 CATTool 元数据解析、存储、注册和执行完整链路 - 新增 CAT.agent.tools GM API(install/remove/list/call) - 修复 CATTool 沙箱执行时 args 未定义的问题:使用 compileScriptCodeByResource 包裹代码以启用 with 上下文绑定 - 优化 Agent Chat UI 组件样式
将 App.tsx (~1130行) 按职责拆分为: - utils.ts: 纯工具函数和常量 - hooks.tsx: useInstallData() 自定义 hook - components/CATToolInstallView.tsx: CATTool 安装视图 - components/ScriptInstallView.tsx: UserScript/Subscribe 安装视图 - App.tsx: 精简为路由分发 (~57行)
新增 example/agents/tools/ 目录: - hello_world.js: 最简 CATTool 示例 - text_processor.js: 多参数和 enum 类型 - json_formatter.js: JSON 处理和错误处理 - weather_query.js: GM_xmlhttpRequest 网络请求 - use_cattool.js: 通过脚本 API 安装和调用 CATTool - README.md: 格式说明和测试方法
- 修复历史消息未携带 toolCalls 字段导致多轮 tool calling 上下文丢失 - 添加 OpenAI 流式 API 错误响应处理 - 添加 /new 命令和 clearMessages 接口用于清空对话上下文 - UI 发送消息时正确传递 toolCallId 和 toolCalls
- 删除独立的 handleChat,UI 和 Sandbox 统一走 conversationChat 通道 - 持久化责任从 UI 移交到 SW,简化前端逻辑 - 字段命名统一:createdAt/updatedAt → createtime/updatetime - 支持 UI 动态切换 modelId - 大幅补充 Agent 相关测试(流式解析、tool calling 循环、CATTool 边界等)
- 对话实例支持 / 命令拦截机制,内置 /new 命令清空对话 - 脚本可通过 commands 选项注册自定义命令并覆盖内置命令 - 修复会话列表删除确认弹框因鼠标移开导致隐藏的问题 - 会话 ID 同步到 URL 参数,刷新页面保持当前会话选中 - 新增命令机制 8 个单元测试
- CATTool 安装改为打开安装页面确认,支持脚本来源追踪和更新提示 - CATToolRepo 索引/数据分离(tools.json 索引 + data/<id>.json 完整记录) - CATTool UUID 由 SW 统一生成,通过全局映射支持 GM API 权限验证 - AgentModelConfig 从 SystemConfig 迁移到独立的 AgentModelRepo - AgentModelRepo.getDefaultModelId 使用 chrome.storage.local 直接存取 - cancelCATToolInstall 统一为 try/finally 模式 - openCATToolInstallPage 增加 tab.id 空值检查
实现 Agent 框架的 DOM 操作 API,支持两种模式: - 默认模式:通过 chrome.scripting.executeScript 操作 - trusted 模式:通过 chrome.debugger CDP 实现真实用户输入 新增 8 个 Agent 工具:dom_list_tabs, dom_navigate, dom_read_page, dom_screenshot, dom_click, dom_fill, dom_scroll, dom_wait_for readPage 支持 summary/detail 分层读取,控制上下文大小; 操作后自动返回 ActionResult(跳转/新 tab/dialog 检测); debugger 权限放在 optional_permissions 动态申请。
- 新增 Skill 类型定义(SkillSummary, SkillRecord, SkillApiRequest 等) - SKILL.md 解析器(YAML frontmatter + markdown body) - SkillRepo OPFS 存储(registry + scripts + references) - AgentService 集成:loadSkills, installSkill, resolveSkills - 2 个 meta-tool:execute_skill_tool, read_reference - GM API: CAT.agent.skills(list/get/install/remove) - UI: ChatInput 增加 Skills 选择器
- agent-fixtures.ts: Mock LLM 基础设施(context.route 拦截 + OpenAI SSE 响应) - agent-conversation.spec.ts: 基础对话、Tool Calling、多轮上下文保持 - agent-cattool.spec.ts: CATTool 安装/调用/删除、CATTool + 对话联动
resolveSkills 不再将完整 SKILL.md 正文和 CATTool schema 一次性注入 system message, 改为三层渐进加载:1) 摘要列表 2) load_skill 按需获取 prompt 3) execute_skill_tool/read_reference 按需执行。 execute_skill_tool 新增 skill_name 参数确定工具作用域,CATTool 脚本改为执行时按需加载。 新增 14 个 Skill 系统单元测试。
ephemeral 模式下会话不持久化到 OPFS、不加载内置工具和 Skills, 工具完全由脚本提供,消息历史由脚本端内存管理。 SW 端无状态处理,仅解析 model 配置调用 LLM。
…rompts 实现完整的 MCP (Model Context Protocol) 客户端: - MCPClient: JSON-RPC 2.0 over HTTP POST,Session ID 管理,认证头 - MCPService: 连接池管理,懒连接,MCP 工具自动注册到 ToolRegistry - MCPServerRepo: chrome.storage 持久化服务器配置 - GM API: CAT.agent.mcp(SW + Content 双侧),权限验证 - UI: AgentMcp 页面 — 服务器 CRUD、启用/禁用、测试连接 - 单元测试覆盖 MCPClient、MCPToolExecutor、MCPService
agent_model:__default__ 存储的是默认模型 ID(字符串),被 find() 当作 AgentModelConfig 返回,导致 UI 访问 model.apiKey.length 时报 TypeError。
- 解析 SSE delta 中的 reasoning_content 字段,发出 thinking_delta 事件(兼容 deepseek/o-series) - 将 usage 检查移到 choices 处理之后,修复最后一个 chunk 同时包含 tool_call 增量和 usage 时丢失数据的问题 - Service Worker callLLM() 收集 thinking 内容并持久化到 assistant 消息 - 修复 vitest.config.ts 中重复 exclude 导致 e2e 测试被误执行的问题
- 注册 installSkill/removeSkill 消息处理到 AgentService.init() - AgentClient 新增 installSkill/removeSkill 方法 - 新建 AgentSkills.tsx:Skill 列表卡片、详情编辑弹窗、URL/粘贴安装弹窗 - 替换 /agent/skills 路由为实际管理页面 - 8 个语言文件新增 19 个 agent_skills_* 翻译 key - 新增 9 个单元测试覆盖安装/卸载/消息注册核心流程
新增 parseSkillZip 解析 ZIP 包(SKILL.md + tools/*.js + references/*), UI 增加 ZIP 上传 Tab,支持嵌套目录结构,含完整单元测试和端到端集成测试。
chrome.permissions.request() 在 MV3 Service Worker 中无法调用(需要用户手势), 改为打开 confirm.html 确认页面,用户点击授权按钮后通过 runtime.sendMessage 通知 SW。
将三层 meta-tool 设计(load_skill → execute_skill_tool → CATTool)简化为两层:
- load_skill 调用时动态注册该 skill 的 CATTool 为独立工具({skill}__{tool} 格式)
- callLLMWithToolLoop 每轮重新获取工具定义以发现新注册的工具
- 对话结束后清理动态注册的工具和 meta-tools
- 新增 prefixToolDefinition 辅助函数
- 新增 ServerDetailDrawer:展示 Tools/Resources/Prompts 三大能力 - 卡片操作栏增加"详情"按钮,通过 MCPClient 直接查询服务器能力 - 测试连接按钮增加 loading 状态 - 编辑 Modal 底部增加测试连接按钮,填完表单可直接测试 - 补充 8 个 locale 文件的 i18n key
- 解决 package.json/manifest.json/pnpm-lock.yaml 版本号冲突(保留 1.5.0-alpha) - 补充 MainLayout 测试缺失的 agentClient mock,修复测试超时问题 - 合并 release/v1.4 的变更:navigation_handle、crontab once 示例、pre-commit 改进等
- navigation_handle.test.ts: 改用 resetAttachedForTest() 重置单例, 不再用 vi.resetModules() 清空全局模块缓存(导致 react-dom/chrome mock 重新加载出错) - MainLayout.test.tsx: 移除多余的 waitFor 避免 500ms 超时
Agent 子菜单项增多后,"设置"可能在小窗口中被挤出可视区域
/setting|设置/ 正则会先匹配到 Agent 子菜单中的 agent_settings(折叠不可见), 改用 .menu-setting class 选择器精确定位
- agent_dom_cdp.test.ts: 保存/恢复 chrome 全局(之前覆盖了完整的 chrome mock, 导致后续测试访问 chrome.tabs.onRemoved 时为 undefined) - opfs_tools.test.ts: stub navigator 时保留 ...globalThis.navigator (之前只有 storage,丢失了 userAgent,导致 react-dom 初始化时 navigator.userAgent.indexOf() 崩溃)
- CI: build/test 流水线支持 feature/* 分支触发 - vitest: 修正 exclude 模式,确保子目录 node_modules/.claude 被排除 - message/server: SenderRuntime.getExtMessageSender 添加 null 检查, 防止 postMessage 通道(Offscreen→SW)因无 RuntimeMessageSender 崩溃 - message/window_message: connect() 使用 WindowPostMessage 包装, 确保 sandbox(origin:null)→offscreen 的消息不被丢弃
- confirm/App.tsx: 定时器从 setTimeout 递归改为 useEffect+setInterval, 修复内存泄漏和渲染循环;提取 PermissionConfirmRequest 组件 - utils.ts: sourceMapTo 添加 chrome.runtime?.getURL 防御, sandbox 环境中 chrome.runtime 不可用时降级为脚本名 - 5 处 eslint-disable react-hooks/exhaustive-deps 注释 - prettier 格式化:CSS/HTML/JSON 文件统一缩进和引号 - .prettierignore: 忽略 *.md 和 example/ - manifest.json: 纯格式化(prettier) - playwright.config.ts: 本地也启用 retry
- 移除 6 处 react-hooks/exhaustive-deps 的 eslint-disable(仅 warn 无需抑制) - 还原 playwright retries 为 CI ? 1 : 0
CSS/HTML/JSON/manifest 等文件还原为 release/v1.4 原始格式
根据 PR #1328 Copilot 评审意见,补充两个单测: - SenderRuntime.getExtMessageSender() 在 sender 为 null/undefined/空对象时不崩溃并返回默认值 - WindowMessage.connect() 返回的连接 sendMessage 带 "*" targetOrigin
- 拆分 useEffect:beforeunload 注册与 getPermissionInfo 请求独立 - 提取命名 handler,在 cleanup 中 removeEventListener - beforeunload effect 只依赖 [uuid],避免语言切换时重复注册 - .gitignore 忽略 .omc 本地开发目录 根据 PR #1328 @cyfung1031 评审意见处理
还原与 agent 功能无关的格式化改动,保持 release/v1.4 原有风格: - CSS/HTML/JSON/YAML:还原 prettier 缩进、引号、数组单行化 - src/index.css: 仅保留 --un-default-border-color(UnoCSS 暗色边框修复) - src/manifest.json: 仅保留 "debugger" 权限(Agent CDP 需要) - workflows: 仅保留 feature/* 分支触发 移除未实际需要的代码抑制: - 5 处 react-hooks/exhaustive-deps 的 eslint-disable-next-line(仅 warn 无需抑制) - playwright 本地 retries 还原为 0
暗色模式下 UnoCSS 的 --un-default-border-color 默认使用浅色值, 导致 border-* 类的边框在暗色主题下与背景对比不足。 将其绑定到 Arco CSS 变量 --color-border-2,让边框色随主题自适应。
vi.resetModules() 会清空全局模块缓存,导致后续测试重新加载 LoggerCore、 chrome mock 等模块时出错,在 CI 上表现为偶发失败。 改为导出 resetAttachedForTest() 重置模块级 attached 单例, 测试无需动态 import 即可验证多次调用的幂等性。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
先放著