feat(daemon): HTTP 唤醒页面美化、跨平台终端拉起、安装后自启动及错误指引增强#602
feat(daemon): HTTP 唤醒页面美化、跨平台终端拉起、安装后自启动及错误指引增强#602phantom5099 merged 3 commits into1024XEngineer:mainfrom
Conversation
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
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
| 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" |
There was a problem hiding this comment.
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.
| cat >&2 <<'REMEDY' | ||
| Remedy commands: | ||
| /usr/local/bin/neocode daemon install | ||
| sudo echo '127.0.0.1 neocode' >> /etc/hosts |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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。 |
There was a problem hiding this comment.
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 Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
概述
本 PR 围绕
neocode daemon的 HTTP 页面交互体验和安装部署链路进行了系统性改进,覆盖 13 个文件(+656 / -42 行),分为三个功能维度。Closes #580
改动详述
1. 跨平台终端自动拉起(5 文件)
之前 Linux 的
launchTerminal()直接返回ErrTerminalUnsupported,Windows 仅支持cmd /c start且使用strings.Fields分割命令字符串,存在安全隐患。gnome-terminal探测(优先级最高),失败后回退到x-terminal-emulator,均不可用时返回明确安装指引wt.exe(Windows Terminal)并通过new-tab拉起,失败后回退到cmd /c startterminal_linux_test.go和terminal_windows_test.go,覆盖三种路径:首选终端、回退终端、无可用的终端2. HTTP 响应页面美化(2 文件)
之前 daemon 返回的 HTML 页面是裸标签无样式:
改进为:
<!doctype html>骨架、<meta viewport>、<title>、SVG faviconaction、session_id、可点击的reusable_url链接复制链接按钮,优先使用 Clipboard API,在非安全上下文(http://neocode)中自动回退到execCommand('copy')。解决了navigator.clipboard在 http://neocode 下不可用导致"复制失败"的问题Gateway unavailable→ "无法连接到 gateway"),并展示可执行的补救命令(neocode daemon status、neocode gateway --listen ...)3. 安装体验增强(6 文件)
daemon install成功后立即以后台进程方式执行daemon serve,轮询/healthz最多 3 秒确认就绪,无需用户手动执行或重启defaultGatewayLaunchTimeout从 3 秒延长到 10 秒,适应冷启动较慢的机器;超时等错误信息从 "single fallback" 改为更可读的 "automatic startup"echo ... >> C:\Windows\...\hosts,Linux/macOS:sudo echo ... >> /etc/hosts)daemon install在 stderr 输出结构化日志(成功摘要、hosts 警告、daemon 就绪状态),失败时打印完整补救命令install.sh/install.ps1在 daemon 安装失败时输出多行补救指引,顶层异常也被捕获并输出重试命令测试
TestLaunchTerminalLinuxUsesGnomeFirst/FallsBackToXTerminalEmulator/UnsupportedWhenNoTerminalTestLaunchTerminalWindowsPrefersWT/FallsBackToCmdStart/FallsBackWhenWTFailsTestHTTPDaemonHandlerDispatchErrorIsFriendly(验证错误页中文映射和补救命令)TestBuildHostsAliasWarningIncludesManualCommands(验证平台化 hosts 指引)TestDaemonInstallDefaultRunnerUsesCurrentExecutable(验证安装 JSON 输出和 stderr 日志)TestDaemonInstallDefaultRunnerFailureWritesRemedy(验证失败时的补救输出)TestGatewayLaunchTimeoutIsTenSeconds/TestWaitGatewayReadyTimeoutMessage验证方式