Skip to content

feat(ptyproxy,gateway): Ask/IDM 交互诊断链路与 Windows ConPTY 全平台兼容#576

Merged
phantom5099 merged 10 commits into1024XEngineer:mainfrom
pionxe:main
May 8, 2026
Merged

feat(ptyproxy,gateway): Ask/IDM 交互诊断链路与 Windows ConPTY 全平台兼容#576
phantom5099 merged 10 commits into1024XEngineer:mainfrom
pionxe:main

Conversation

@pionxe
Copy link
Copy Markdown
Collaborator

@pionxe pionxe commented May 8, 2026

Summary

本次 PR 聚焦三大主线:(1) 接入 Ask 会话链路,支持 neocode ask@ai 交互诊断模式;(2) 补齐
Windows ConPTY 原生跨平台兼容,使 shell/IDM 在 Windows 与 Linux 行为一致;(3)
抽取共享组件收敛重复逻辑并修复若干边界缺陷。

Closes #533

Changes

1. Ask 会话链路 (neocode ask / IDM @ai 模式)

  • Runtime:新增 internal/runtime/ask.goask_session.goask_store.go,实现 Ask
    会话生命周期管理、上下文存储与流式响应编排;新增 thinking.go 提供 reasoning 级别控制。
  • Gateway:扩展 stream_relay.go 支持 ask_chunk / ask_done / ask_error
    事件转发;contracts.go 新增 Ask/DeleteAskSession 契约。
  • CLIgateway_runtime_bridge.go 增加 Ask 事件转换与 SSE 输出编排;shell_diag_commands.go
    实现 neocode diag -i 进入 IDM 随诊模式。
  • Contextask_prompt.go 构建 Ask 专有系统提示。

2. IDM 交互诊断模式

  • 控制器重构idm_controller.go 全面重构,支持 @ai <question> 异步推理、原生命令透传、Ctrl+C
    中断、Markdown 终端渲染;新增 idm_ask_test.goidm_controller_windows_test.go 补充覆盖。
  • 信号兼容:新增 idm_signal_compat.goidm_process_unix.go /
    idm_process_windows.go,统一跨平台信号处理与进程存活检测。
  • 行尾修复:修复 Linux raw 终端下 IDM AI 输出排版错乱(\n 未转
    \r\n),统一所有平台的换行规范化。

3. Windows ConPTY 原生支持

  • Subsystem 适配:新建 proxy_windows_conpty.go(~500 行),实现 ConPTY shell
    进程创建、管线管理、尺寸监控与资源释放;proxy_windows.go 大幅扩展(~1500 行),补齐 shell
    会话、网关通知订阅、诊断调度、IDM 输入拦截等完整链路。
  • 终端兼容:优化 enableWindowsConsoleModes 控制台模式设置;normalizeWindowsConPTYInputByte
    修复 ConPTY 退格键兼容;resolveWindowsConPTYSize 增强终端尺寸探测回退链。
  • 诊断安全注入:修复诊断结果写入 ConPTY
    屏幕缓冲区时的光标偏移与内容覆盖问题,确保输入不与已有文本重叠。
  • Shell 集成windowsCmdShellIntegrationCommand / windowsPowerShellIntegrationCommand 注入
    OSC133 钩子,使 cmd.exe / PowerShell 均支持命令生命周期感知。

4. 跨平台共享逻辑抽取

  • proxy_bind_shared.go(96 行):抽取 bind_stream 调用、状态回退、ACK 校验共享逻辑,消除
    Windows/Unix 间重复代码。
  • proxy_diag_shared.go(374 行):抽取诊断信号消费、去重协调、结果渲染共享链路,收敛
    runSingleDiagnosisWithCoordinator 等核心函数。
  • proxy_notify_shared.go(84 行):抽取网关通知分流(event/control)与载荷解码共享实现。
  • proxy_common_types.go(170 行):提取
    ManualShellOptionsautoRuntimeStatediagnoseTrigger 等公共类型。

5. Bug 修复

  • Providerrequest.go 中 thinking disabled 时不再强制输出
    reasoning_effort=none,减少协议噪声并与 OpenAI 兼容行为对齐。
  • Gateway:Runtime ask 调用失败时通过 relay 发布 ask_error 事件,避免前端丢失失败反馈;保留
    ask chunk 原始首尾空白,防止流式格式损失。
  • Shell:修复 Windows 退格键(0x08)在部分 ConPTY 版本被解释为按词删除的问题,统一转为 0x7F。

6. 测试覆盖

新增测试文件:

  • proxy_windows_conpty_test.go(316 行)
  • proxy_windows_idm_test.go(373 行)
  • idm_ask_test.go(197 行)
  • proxy_diag_shared 相关诊断链路测试
  • ask_prompt_test.go(89 行)
  • gateway_runtime_bridge_test.go 增强(+281 行)
  • gateway/bootstrap_test.go 增强(+421 行)

Test plan

  • go test ./internal/ptyproxy/... — 全部 PTY/IDM 测试通过
  • go test ./internal/runtime/... — Ask 会话与 thinking 测试通过
  • go test ./internal/gateway/... — 事件转发与 RPC 测试通过
  • go test ./internal/cli/... — 桥接与诊断命令测试通过
  • Windows 实机:neocode shell → 命令错误诊断 → 输入不回覆盖诊断文本
  • Windows 实机:neocode diag -i@ai 交互推理 → exit 退出
  • Linux 实机:IDM @ai 输出的 Markdown 排版正常(无换行丢失)
  • cmd.exe / PowerShell 均可正常启动 neocode shell 并响应 OSC133 事件

pionxe added 6 commits May 8, 2026 08:34
- 在 runtime ask 调用失败时通过 relay 发布 ask_error 事件,避免前端丢失失败反馈
- 调整 bridge 的 ask 事件转换逻辑,保证错误事件在 run 清理后仍可透传
- 保留 ask chunk/full_response 的原始首尾空白,避免流式输出格式损失
- 补充对应单元测试覆盖异常与空白保留场景
- BuildRequest 在 thinking disabled 场景下不再强制写入 reasoning_effort=none
- 与 OpenAI 兼容请求的默认行为保持一致,减少不必要协议噪声
- 更新测试断言,确保禁用场景输出字段被省略
- 提取 bind/diagnosis/notification 共享实现,收敛 Unix 与 Windows 的重复逻辑
- 为 bind_stream 增加 shell 角色与 ACK 校验兼容,补齐相关用例
- 新增诊断游标保护与调度机制,避免 Windows ConPTY 输出插入破坏输入态
- 修复 Windows 输入/回显/换行与屏幕注入细节,提升 IDM 与 ConPTY 稳定性
- 补充多项单元测试覆盖诊断渲染、ConPTY 尺寸与控制台模式等边界场景
@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.

Found 3 noteworthy issues after code quality, performance, security, and documentation-accuracy passes.

Comment thread internal/runtime/ask.go
Comment thread internal/runtime/ask.go
Comment thread internal/runtime/ask.go
session = AskSession{
ID: sessionID,
Workdir: strings.TrimSpace(input.Workdir),
Skills: normalizeAskSkillIDs(input.Skills),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[medium] The public contract says AskInput.Skills are the skills for this ask request, but on a reused ask session they are only read during first-session creation and every later request ignores its input.Skills. That means callers cannot change the active skill set after turn 1, which makes the new API behavior surprising and mismatched with its own documentation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个后面修?

@phantom5099 phantom5099 merged commit 9e1c733 into 1024XEngineer:main May 8, 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.

Phase 5: Windows 适配

2 participants