Skip to content

feat(web): 连接电脑向导生成后台服务安装命令 - #1281

Open
qqqqqf-q wants to merge 3 commits into
felinics:mainfrom
qqqqqf-q:feat/connect-wizard-daemon
Open

qqqqqf-q wants to merge 3 commits into
felinics:mainfrom
qqqqqf-q:feat/connect-wizard-daemon

Conversation

@qqqqqf-q

@qqqqqf-q qqqqqf-q commented Sep 15, 2026

Copy link
Copy Markdown
Member

问题

「Connect computer」向导生成的命令仍是 npx --yes <pkg> --server ... --key ... 裸 flags 前台运行模式:终端一关连接就断,用户只能把进程一直挂着。#1128 给 runtime CLI 加了 enroll/service 的 daemon 能力(launchd / systemd / Task Scheduler),但向导从未跟进——CLI 有持久化能力,产品入口生成的却还是一次性命令。

改动

buildRuntimeConnectCommand 改为生成官方 README 推荐的持久化流程(&& 单行,一次粘贴):

npm install -g @memohai/runtime && memoh-runtime enroll --server <url> --key <key> [--team-id <id>] --replace && memoh-runtime service install && memoh-runtime service start
  • 全局安装而非 npx:service 注册的入口是当前 CLI 路径,README 明确 npx 缓存不是持久安装,缓存被清理后服务会静默失效。
  • bin 名推导:按 @memohai/<name>memoh-<name> 约定从包名推导(@memohai/cloud-runtimememoh-cloud-runtime),hosted 构建经 VITE_RUNTIME_NPX_PACKAGE 传入包名即自动得到正确命令,Cloud 侧无需改配置。
  • enroll 带 --replace:每次向导会话都签发新 key(关闭对话框即 revoke 旧 credential),重开向导重跑命令必然与已存登记不同,不带会被 saved enrollment differs 拦截;换绑正是用户意图。
  • && 单行:一次粘贴、失败即停。唯一例外是 Windows PowerShell 5.1(不支持 &&),该环境下分行执行;cmd 与 PowerShell 7+ 正常。
  • --insecure-localhost(loopback 开发)照旧附加到 enroll 段。
  • 向导文案同步更新(en/zh/ja):一次性运行、安装后台服务、无需保持终端打开。

⚠️ 合并前提:@memohai/runtime ≥ 0.20.0 须先上 npm

npm 上 @memohai/runtime latest 仍是 0.18.0(无 enroll/service,strict 解析遇 positional 直接退出)。本 PR 合并后,任何从 main 构建的 OSS 自托管 web 生成的命令会在 enroll 处失败,直到 @memohai/runtime@0.20.0 发布。v0.20.0 tag 已推,但 release workflow 的 npm publish 因 org 更名(memohai→felinics)导致 trusted publisher 不匹配而 404,需先在 npmjs.com 更新各包的 trusted publisher 后重跑 failed jobs。Cloud 不受影响(@memohai/cloud-runtime@2026.9.15-1 已含 daemon)。

验证

  • command.test.ts 8 个用例全绿(默认包、无 team-id 旧凭据、loopback insecure、单行无换行、必带 --replace、hosted 包名推导、bin 约定、未知包兜底)
  • ESLint 改动文件无告警;三个 locale JSON 校验通过
  • 命令形态逐条对照 packages/runtime/src/cli-main.ts 的 enroll/service 实现核验
  • 已在本机(macOS,homebrew node)按生成的 cloud 命令形态实测:全局安装 → enroll --replace(覆盖既有登记)→ service installservice start,launchd running、日志 connected
  • 未做端到端:向导弹窗的实际渲染与剪贴板复制未走查;Windows/Linux 两平台未实测

⚠️ No human QA — this PR has not been verified by a human yet. Remove this line once a human confirms the happy path.

向导原来生成裸 flags 的前台运行命令(npx 一次性进程,关掉终端即
断连)。runtime CLI 在 felinics#1128 已有 enroll/service 的 daemon 能力,但
向导从未跟进。

改为生成官方文档推荐的持久化流程:全局安装 CLI 后 enroll + service
install + service start,服务由 launchd/systemd/Task Scheduler 接管,
不再依赖 npx 缓存路径(README 明确 npx 缓存不是持久安装)。

CLI bin 名按 @memohai/<name> → memoh-<name> 约定从包名推导,hosted
部署(如 @memohai/cloud-runtime)经 VITE_RUNTIME_NPX_PACKAGE 传入包
名即可获得正确的 memoh-cloud-runtime 命令,无需额外配置。
@qqqqqf-q
qqqqqf-q requested a review from a team as a code owner September 15, 2026 12:10
@github-actions github-actions Bot added change:web Changes web frontend or shared frontend packages needs:format Description needs template corrections; removed automatically once fixed size:S PR size uses the larger of added or deleted lines, excluding generated files labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@qqqqqf-q Please complete the following information using the template:

  • Select exactly one option for "Author": Human / Agent.
  • Select exactly one option for "Type": bug / feat / test.
  • Please complete "Summary".
  • Please complete "Validation".
  • Please complete "Screenshots / Recordings".
  • Please complete "Human QA".
  • Keep exactly one "Human QA passed" checkbox in "Human QA"; leave it unchecked until verified.

Editing the description triggers another check; format feedback does not block or cancel code CI.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T12:14:15.217948Z 5f66c47 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f66c4724f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

key,
]
const bin = runtimeCliBin(npmPackage)
const enrollArgs = [bin, 'enroll', '--server', serverUrl, '--key', key]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace an existing enrollment in the generated command

When the same machine is connected again after revocation, an account/server change, or another freshly issued credential, its previous ~/.memoh/runtime.json remains. enroll deliberately rejects a different saved enrollment without --replace (packages/runtime/src/cli-main.ts, lines 125-133), so this && chain stops before installing or starting the service and the dialog waits indefinitely. Add --replace to this wizard-generated enrollment or explicitly handle existing enrollment.

Useful? React with 👍 / 👎.

enrollArgs.join(' '),
`${bin} service install`,
`${bin} service start`,
].join(' && ')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Support Windows PowerShell in the generated command

When a Windows user pastes this generic command into Windows PowerShell 5.1, parsing fails at the first &&; Microsoft documents these pipeline-chain operators as introduced in PowerShell 7 in about_Pipeline_Chain_Operators. Since the runtime explicitly supports Windows Task Scheduler (packages/runtime/src/daemon/index.ts, lines 20-29), provide shell-specific syntax or a Windows-compatible command instead of making the supported Windows flow depend on PowerShell 7 or cmd.exe.

Useful? React with 👍 / 👎.

- enroll 加 --replace:每次向导会话都签发新 key(关闭即 revoke 旧
  credential),已登记过的机器重跑命令必然与存档不同,不加会被
  'saved enrollment differs' 拦截断链;换绑正是用户意图
- && 链改为逐行命令:Windows 默认 PowerShell 5.1 不支持 &&,多行
  粘贴在 bash/zsh/cmd/PS 各 shell 都逐条执行
单行一次粘贴、失败即停,符合连接向导的一次性操作语义。唯一例外是
Windows PowerShell 5.1(不支持 &&),该环境下用户分行执行;cmd 与
PowerShell 7+ 正常。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:web Changes web frontend or shared frontend packages needs:format Description needs template corrections; removed automatically once fixed size:S PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant