Skip to content

feat(daemon): HTTP 唤醒页面美化、跨平台终端拉起、安装后自启动及错误指引增强#602

Merged
phantom5099 merged 3 commits into1024XEngineer:mainfrom
pionxe:feat/daemon-http-ux
May 10, 2026
Merged

feat(daemon): HTTP 唤醒页面美化、跨平台终端拉起、安装后自启动及错误指引增强#602
phantom5099 merged 3 commits into1024XEngineer:mainfrom
pionxe:feat/daemon-http-ux

Conversation

@pionxe
Copy link
Copy Markdown
Collaborator

@pionxe pionxe commented May 9, 2026

概述

本 PR 围绕 neocode daemon 的 HTTP 页面交互体验和安装部署链路进行了系统性改进,覆盖 13 个文件(+656 / -42 行),分为三个功能维度。

Closes #580

改动详述

1. 跨平台终端自动拉起(5 文件)

之前 Linux 的 launchTerminal() 直接返回 ErrTerminalUnsupported,Windows 仅支持 cmd /c start 且使用 strings.Fields 分割命令字符串,存在安全隐患。

  • Linux:新增 gnome-terminal 探测(优先级最高),失败后回退到 x-terminal-emulator,均不可用时返回明确安装指引
  • Windows:优先探测 wt.exe(Windows Terminal)并通过 new-tab 拉起,失败后回退到 cmd /c start
  • 新增 terminal_linux_test.goterminal_windows_test.go,覆盖三种路径:首选终端、回退终端、无可用的终端

2. HTTP 响应页面美化(2 文件)

之前 daemon 返回的 HTML 页面是裸标签无样式:

<html><body><h3>OK</h3><p>action=run</p>...</body></html>

改进为:

  • 视觉:渐变背景、居中卡片、圆角阴影、响应式布局(适配移动端)
  • 结构:完整的 <!doctype html> 骨架、<meta viewport><title>、SVG favicon
  • 成功页:显示 actionsession_id、可点击的 reusable_url 链接
  • 复制按钮:新增 复制链接 按钮,优先使用 Clipboard API,在非安全上下文(http://neocode)中自动回退到 execCommand('copy')解决了 navigator.clipboardhttp://neocode 下不可用导致"复制失败"的问题
  • 错误页:将原始错误码映射为中文提示(如 Gateway unavailable → "无法连接到 gateway"),并展示可执行的补救命令(neocode daemon statusneocode gateway --listen ...

3. 安装体验增强(6 文件)

  • 安装后自动启动 daemondaemon install 成功后立即以后台进程方式执行 daemon serve,轮询 /healthz 最多 3 秒确认就绪,无需用户手动执行或重启
  • Gateway 拉起超时defaultGatewayLaunchTimeout 从 3 秒延长到 10 秒,适应冷启动较慢的机器;超时等错误信息从 "single fallback" 改为更可读的 "automatic startup"
  • Hosts 写入失败指引:hosts 文件写入需要管理员权限,失败时给出平台对应的手动修复命令(Windows: echo ... >> C:\Windows\...\hosts,Linux/macOS: sudo echo ... >> /etc/hosts
  • CLI 输出改进daemon install 在 stderr 输出结构化日志(成功摘要、hosts 警告、daemon 就绪状态),失败时打印完整补救命令
  • 安装脚本install.sh / install.ps1 在 daemon 安装失败时输出多行补救指引,顶层异常也被捕获并输出重试命令

测试

  • 新增 TestLaunchTerminalLinuxUsesGnomeFirst / FallsBackToXTerminalEmulator / UnsupportedWhenNoTerminal
  • 新增 TestLaunchTerminalWindowsPrefersWT / FallsBackToCmdStart / FallsBackWhenWTFails
  • 新增 TestHTTPDaemonHandlerDispatchErrorIsFriendly(验证错误页中文映射和补救命令)
  • 新增 TestBuildHostsAliasWarningIncludesManualCommands(验证平台化 hosts 指引)
  • 新增 TestDaemonInstallDefaultRunnerUsesCurrentExecutable(验证安装 JSON 输出和 stderr 日志)
  • 新增 TestDaemonInstallDefaultRunnerFailureWritesRemedy(验证失败时的补救输出)
  • 新增 TestGatewayLaunchTimeoutIsTenSeconds / TestWaitGatewayReadyTimeoutMessage
  • 已有 13 个相关测试全部通过

验证方式

# 启动 daemon
neocode daemon serve

# 生成可点击链接并在浏览器打开
neocode daemon encode run --prompt "hello" --workdir "."
# 观察:页面美化效果、复制按钮功能、错误页展示

# 安装验证
neocode daemon install
# 观察:stderr 中的结构化日志、daemon 是否自动启动

# 终端拉起验证(Linux)
# 观察:点击 URL 后是否自动弹出终端并执行 neocode --session

pionxe added 3 commits May 10, 2026 01:49
Linux: probe gnome-terminal first, then x-terminal-emulator fallback.
Windows: prefer Windows Terminal (wt.exe), fallback to cmd /c start.
Previously Linux always returned ErrTerminalUnsupported, and Windows
only used cmd /c start with strings.Fields which was fragile.
…atch error guidance

Replace bare HTML error/success pages with styled cards including:
- CSS gradient background, rounded card with shadow, responsive layout
- viewport meta, favicon, page title for browser tabs
- reusable URL copy button with Clipboard API + execCommand fallback
  (fixes copy failure on http://neocode which is not a secure context)
- friendly dispatch error pages that map error codes to Chinese guidance
  and show exact remedy commands (daemon status, gateway start)
- hosts alias failure now includes platform-specific manual fix commands
- daemon install auto-starts daemon process in background and waits for
  healthz readiness; surfaces DaemonStarted/DaemonStartWarning in result
…ipt output

- Bump gateway auto-start deadline from 3s to 10s for slow machines
- Reword timeout/dial error messages from "single fallback" to "automatic
  startup" for user clarity
- daemon install CLI now writes structured logs to stderr (success/failure
  summary, hosts warning, daemon readiness) and prints explicit remedy
  commands on failure
- Install scripts (install.sh / install.ps1) now emit multi-line remedy
  guidance on daemon install failure instead of a single vague warning,
  and catch top-level errors with retry instructions
@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.

I found 4 noteworthy issues after reviewing the diff across code quality, performance, security, and documentation passes.

if runtime.GOOS == "windows" {
return base + "; please run as Administrator: echo 127.0.0.1 neocode >> C:\\Windows\\System32\\drivers\\etc\\hosts"
}
return base + "; please run with sudo: sudo echo '127.0.0.1 neocode' >> /etc/hosts"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Unix remediation command here is broken: sudo echo ... >> /etc/hosts still performs the redirection as the unprivileged shell, so users will keep getting permission denied. Please switch the guidance to something that elevates the write itself, for example echo '127.0.0.1 neocode' | sudo tee -a /etc/hosts.

Comment thread scripts/install.sh
cat >&2 <<'REMEDY'
Remedy commands:
/usr/local/bin/neocode daemon install
sudo echo '127.0.0.1 neocode' >> /etc/hosts
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This installer prints the same broken Unix hosts fix as above. sudo echo ... >> /etc/hosts does not work for non-root users because >> happens before sudo. The remedy text should use sudo tee -a /etc/hosts (or an equivalent command) or the recovery path will fail when users copy/paste it.

if runtime.GOOS != "linux" {
return fmt.Errorf("%w: run `%s` manually in your terminal", ErrTerminalUnsupported, command)
}
if err := launchWithLinuxTerminal("gnome-terminal", []string{"--", "bash", "-lc", command}); err == nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If gnome-terminal is present but cannot start (for example, no DISPLAY/DBus in a headless session), we silently discard that error, try the fallback, and finally report ErrTerminalUnsupported. That turns a real runtime failure into a misleading “install gnome-terminal/x-terminal-emulator” message. Please preserve and surface the last launch error when binaries are found but launching them fails.

execCommandForTerminalLinux = exec.Command
)

// launchTerminal 在 Linux 上优先尝试 gnome-terminal,再回退到 x-terminal-emulator。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change makes Linux part of the supported auto-launch path, but the docs still say the opposite (README.md:264, docs/guides/http-daemon-wake-user-guide.md:162, www/guide/http-daemon-wake-user-guide.md:151). Please update those docs in the same PR so users do not keep seeing guidance that says Linux wake returns not_supported.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

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

bug(URL Scheme) : 自动启动以及权限问题

2 participants