Skip to content

feat(web): 新增 Web 前端与 Electron 桌面应用,增强 Gateway 模块#520

Merged
phantom5099 merged 36 commits into1024XEngineer:mainfrom
Yumiue:html_gui_build
May 4, 2026
Merged

feat(web): 新增 Web 前端与 Electron 桌面应用,增强 Gateway 模块#520
phantom5099 merged 36 commits into1024XEngineer:mainfrom
Yumiue:html_gui_build

Conversation

@Yumiue
Copy link
Copy Markdown
Collaborator

@Yumiue Yumiue commented Apr 30, 2026

概述

本 PR 为 NeoCode 新增了 Web 前端界面和 Electron 桌面应用支持,同时增强了 Gateway 模块的 RPC 协议和契约定义,为多端 UI 提供了完整的基础设施。

主要改动

1. Web 前端应用(React + TypeScript + Vite)

  • 聊天界面:实现完整的对话交互界面,包括消息列表、输入框、模型选择器、工具调用卡片等
  • 文件管理:提供文件树面板和文件变更面板,支持查看项目结构和文件修改
  • 权限审批:实现权限审批对话框,支持用户对工具调用进行授权
  • 状态管理:使用 Zustand 实现聊天、会话、Gateway 连接等状态管理
  • 通信层:实现 WebSocket 客户端,与 Gateway 建立实时双向通信
  • UI 组件:提供错误边界、Toast 提示等基础 UI 组件
  • 测试覆盖:使用 Vitest 添加单元测试和集成测试

2. Electron 桌面应用

  • 主进程:实现 Electron 主进程逻辑,处理窗口管理和原生 API 调用
  • 预加载脚本:提供安全的 IPC 通信桥接
  • 构建配置:配置 electron-builder 支持桌面应用打包
  • 事件桥接:实现 Web 端与 Electron 原生能力的事件桥接工具

3. Gateway 模块增强

  • 契约定义:新增 contracts.go,明确定义 Gateway 与 Runtime 之间的交互契约
  • RPC 协议:重构 protocol/jsonrpc.go,优化 JSON-RPC 协议处理逻辑
  • 启动逻辑:增强 bootstrap.go,改进 Gateway 启动流程和依赖注入
  • 参数校验:增强 validate.go,添加更严格的参数校验
  • 安全机制:在 security.go 中新增安全相关逻辑
  • 测试覆盖:新增 rpc_dispatch_test.go 等测试文件,提高测试覆盖率

4. CLI 层改进

  • 桥接重构:重构 gateway_runtime_bridge.go,优化 Gateway 与 Runtime 的桥接逻辑
  • 测试增强:新增 gateway_runtime_bridge_test.go 测试覆盖

5. 文档更新

  • RPC API 文档:更新 docs/gateway-rpc-api.md,补充完整的 RPC API 说明
  • 兼容性文档:更新 docs/gateway-compatibility.md,说明版本兼容性

6. 其他改进

  • Repo Hooks:新增 repo hooks 支持(repo_hooks.go 及平台特定实现)
  • 编译修复:修复 Gateway 自动连接因编译超时失败的问题
  • 代码规范:修复 TypeScript 类型错误和代码规范问题

技术栈

  • 前端框架:React 18 + TypeScript 5
  • 构建工具:Vite 6
  • 状态管理:Zustand 5
  • 路由:React Router DOM 6
  • 桌面框架:Electron 33
  • 测试框架:Vitest 4 + Testing Library
  • UI 图标:Lucide React

测试

  • Web 端组件和工具函数已添加 Vitest 单元测试
  • Gateway 模块新增测试覆盖
  • CLI 桥接逻辑已添加测试

向后兼容性

  • Gateway RPC 协议保持向后兼容
  • 不影响现有 TUI 端功能
  • 新增 Web 端为独立模块,不影响现有架构

检查清单

  • 代码遵循项目编码规范
  • 添加必要的测试
  • 更新相关文档
  • 无明文密钥或敏感信息
  • UTF-8 编码(无 BOM)

link #529

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完成四轮审查(代码质量/性能/安全/文档一致性)并去重后,以下问题建议优先处理。

Comment thread web/src/api/wsClient.ts
let url = `${wsBase}${normalizedEndpoint}`
if (token) {
const separator = url.includes('?') ? '&' : '?'
url = `${url}${separator}token=${encodeURIComponent(token)}`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildWSURL() 将鉴权 token 放在 URL query(?token=)里。该模式会把密钥暴露给代理日志、错误上报、历史记录和调试工具,属于敏感信息泄露风险。建议改为:连接建立后立即通过 gateway.authenticate 在消息体传 token,或使用受控 header/cookie 通道,不在 URL 携带凭据。

Comment thread web/electron/preload.ts
/** 暴露安全 API 到渲染进程 */
contextBridge.exposeInMainWorld('electronAPI', {
/** 获取认证 Token */
getToken: () => ipcRenderer.invoke('gateway:getToken'),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

预加载层直接向渲染进程暴露 getToken()。一旦渲染层发生 XSS/供应链注入,攻击者可直接读取长期凭据。建议不要把 token 暴露给 renderer;改为由主进程代发鉴权请求(renderer 仅拿到会话态/短期授权结果)。

Comment thread web/.vite/deps/_metadata.json Outdated
@@ -0,0 +1,8 @@
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 引入了本地构建缓存产物(.vite/deps),同时还提交了 web/dist/index.html。这类生成文件易陈旧且会制造噪声,和源码/文档状态不一致。建议移除生成产物并通过 .gitignore 统一忽略,仅保留源码与可复现构建配置。

@Yumiue
Copy link
Copy Markdown
Collaborator Author

Yumiue commented Apr 30, 2026

@xgopilot 对于这个PR的review提到的有关安全性的问题,整理成一个合规中文待办issue提交到仓库

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 30, 2026

codeagent is processing your request, please wait a moment...

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 30, 2026

处理结果

已根据 PR #520 的 review 安全反馈,整理并提交合规中文待办 Issue:

Issue 内容摘要

  • 聚焦两项安全问题:
    • web/src/api/wsClient.ts 使用 ?token= URL Query 传递凭据导致泄露风险
    • web/electron/preload.ts 向 renderer 暴露 getToken() 导致凭据可被前端上下文读取
  • 已在 Issue 中给出:整改目标、可执行待办清单、验收标准、关联 PR 信息。

未执行项

  • 本次仅完成“整理并提交待办 Issue”,未直接修改 PR 代码实现。

View job run

Yumiue and others added 20 commits May 4, 2026 17:19
- eventBridge.ts: EventType 是 const 对象不能作为类型使用,改用 Set<string>
- Sidebar.tsx: handleToggleSkill 补充 gatewayAPI null 守卫

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
增加前端自动检测重试次数(15→60),fetch 失败时重试而非直接放弃,
适配 Windows 上 Go 编译耗时较长的场景。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
.gitignore 已有对应规则但文件仍被跟踪,从 Git 索引中移除
web/.vite/ 和 web/dist/ 构建缓存。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Yumiue Yumiue force-pushed the html_gui_build branch from 69d8658 to 7054598 Compare May 4, 2026 10:11
Yumiue and others added 4 commits May 4, 2026 18:36
- 移除 rebase 后 recordingPort 中重复的 ListSessionTodos/GetRuntimeSnapshot 方法声明
- 新增 toSlash/isAbsolutePath 辅助函数,确保路径比较在 Windows 上使用统一的正斜杠格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 移除 rebase 后 recordingPort 中重复的 ListSessionTodos/GetRuntimeSnapshot 方法声
  明
- 新增 toSlash/isAbsolutePath 辅助函数,确保路径比较在 Windows 上使用统一的正斜杠格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@phantom5099 phantom5099 merged commit bdcb7fb into 1024XEngineer:main May 4, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants