Skip to content

feat(diag): 实现终端诊断系统 Phase 1 (Manual 模式最小闭环)#541

Merged
phantom5099 merged 8 commits into1024XEngineer:mainfrom
pionxe:feature/diag-phase1
May 1, 2026
Merged

feat(diag): 实现终端诊断系统 Phase 1 (Manual 模式最小闭环)#541
phantom5099 merged 8 commits into1024XEngineer:mainfrom
pionxe:feature/diag-phase1

Conversation

@pionxe
Copy link
Copy Markdown
Collaborator

@pionxe pionxe commented May 1, 2026

🎯 背景与目标

为了打造沉浸式的 NeoCode 终端协作体验,本 PR 落地了 Terminal Diagnostic System (终端诊断系统) 的 Phase 1。该阶段重点打通了:底层 PTY 劫持 -> Ring Buffer 缓存 -> 跨进程 Socket 触发 -> 网关工具链路由 -> 原位结果渲染 的全链路闭环,为后续真正接入 LLM 根因分析奠定了坚实的基础设施。

🚀 核心更新内容

1. 架构解耦与重构

  • Client 下沉:将 gateway_rpc_client 从 TUI 展现层彻底抽离并下沉至 internal/gateway/client,清理了业务职责,实现各组件间统一且干净的网关调用复用。

2. 底层 PTY 代理中枢 (internal/ptyproxy)

  • 透明透传:基于 creack/pty 实现了对 Bash/Zsh 的子进程拉起与标准流的 io.Copy 透明代理。
  • 日志缓存:自研了基于 UTF-8 边界安全的内存 RingBuffer (64KB),防止终端报错日志溢出,并保障日志截取不产生乱码。
  • 跨平台防呆:当前阶段优雅降级非 Unix 系统,Windows 环境下执行命令会温和提示不支持。

3. IPC 通信与命令行扩展 (internal/cli)

  • 新命令:新增 neocode shell(启动主代理与 Unix Socket 监听)与 neocode diag(轻量化纯发信令客户端)。
  • 隐式路由:子 Shell 启动时自动注入环境变量 NEOCODE_DIAG_SOCKET,实现了父子进程无感知的 IPC 路由互通。

4. 系统工具集成 (internal/tools)

  • 工具白名单:开发了受保护的内置系统工具 diagnose,并在 names.gobootstrap.go 中完成系统级注册验证。
  • Mock 联调:当前 Phase 1 返回结构化的 Mock 数据字典(置信度、根因、修复命令),验证端到端链路的可行性。

🛠️ 关键体验优化 (UX Improvements)

本 PR 深入处理了多个典型的底层终端痛点,保障商业级手感:

  • 无缝拖拽 (SIGWINCH):通过 pty.InheritSize 与监听 SIGWINCH 信号,使得代理能够动态继承宿主终端尺寸,彻底解决了由于尺寸未同步导致的**“长命令输入覆盖重写”** Bug。
  • 纯净的 Raw Mode:严格管理 term.MakeRawRestore 状态,消灭了双重回显(结巴)、CPR(光标位置报告)乱码,并优雅吞噬了 Ctrl+V 带来的 ^[[200~ 括号粘贴符。
  • 同步防干扰排版:强制规范了 Raw 模式下的 \r\n 渲染;并将异步的 neocode diag 改造为阻塞等待结果完成,避免原生 Bash Prompt 越界“插队”。
  • 平滑登出:移除了标准输入阻塞(Stdin Deadlock)导致卡死的问题,并在进出 Shell 时增加 [ NeoCode Proxy initialized/exited ] 提示。

🧪 测试路径

  1. 编译构建go build -o neocode ./cmd/neocode
  2. 启动代理壳:输入 ./neocode shell 进入接管模式,确认常规操作(如 ls)与缩放终端无异常。
  3. 制造错误:执行 cat /a/non-existent/file
  4. 发起诊断:执行 ./neocode diag
  5. 预期结果:终端光标处将立刻排版优美地打印出:[NeoCode Diagnosis] 相关 Mock 数据及建议指令。输入 exit 顺畅退出代理。

📋 提交前检查清单 (Checklist)

  • 所有新增加的文件与功能符合架构解耦底线规则 (AGENTS.md)。
  • 工具集与 Gateway 客户端通信无遗漏未加密密钥。
  • CLI 帮助文档和使用说明已同步。
  • (如有)关键的边界测试与网络中断测试通过。

Closes #524

@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.

Completed 4 review passes on changed code (code quality, performance, security, documentation accuracy).

No noteworthy issues found in this PR diff.

Comment thread README.md

```bash
# 进入代理 shell(Phase1 仅支持 Unix)
neocode shell
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the changed areas; no actionable issues found.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

@phantom5099 phantom5099 merged commit 884c8d1 into 1024XEngineer:main May 1, 2026
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.

终端诊断 Phase 1: 最小单次闭环 (Manual 模式) 落地

2 participants