glasspane-install 1.26.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.js +230 -42
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -27,6 +27,44 @@ import path from 'node:path'
27
27
  import process from 'node:process'
28
28
  import net from 'node:net'
29
29
 
30
+ /**
31
+ * One value, quoted as one shell word — the installer-side copy of the product rule.
32
+ *
33
+ * The rule already has three executable bodies in this product (`mcp-shell/src/errors.ts`'s
34
+ * `quoteShellArg`, `engine/Sources/GlassPaneEngine/StateRoot.swift`'s `RemedyCommand.quote`,
35
+ * `updater/lib/shell-quote.js`), and a fourth is legitimate here for the same reason the third
36
+ * one is: this package ships standalone — `installer/package.json`'s `files` is `cli.js` +
37
+ * `glasspane.js`, and `npx glasspane-install` installs nothing beside it, so importing
38
+ * `mcp-shell/dist` from here is impossible. What the packages share is therefore the *gate*:
39
+ * `mcp-shell/test/remedy-shell-quoting.test.mjs` scans `installer/*.js` with the same
40
+ * argument-position judgement it applies to `src/` and `updater/`, so a bare interpolation at a
41
+ * command operand reddens all three sides in one run, and `installer/test/shell-quoting.test.mjs`
42
+ * pins this table against the shipped behaviour.
43
+ *
44
+ * Why it was needed at all: every one of these commands interpolates a path this process did
45
+ * not author — `tree.cli` / `update.updaterCli` come from `--repo`, `GLASSPANE_REPO` and
46
+ * `GLASSPANE_INSTALL_DIR` — and they were wrapped in DOUBLE quotes. Double quotes are not inert:
47
+ * `$(` and a backtick still expand inside them, so "run this restore command" became "run what
48
+ * the directory name says", with the agent's own privileges.
49
+ */
50
+
51
+ /** Characters a shell cannot act on inside an unquoted word. */
52
+ const SHELL_INERT_WORD = /^[A-Za-z0-9@%+=:,./_-]+$/
53
+
54
+ /**
55
+ * `value` as one shell word: left bare when it is made only of characters a shell cannot act on,
56
+ * single-quoted with `'\''` splices for anything else — a space, a quote, a dollar sign, a glob,
57
+ * the empty string (an argument that vanished is a different command line), or a leading hyphen
58
+ * (read as an option otherwise). Same table as `updater/lib/shell-quote.js` and
59
+ * `mcp-shell/src/errors.ts`.
60
+ */
61
+ export function quoteShellArg(value) {
62
+ const text = String(value)
63
+ return SHELL_INERT_WORD.test(text) && !text.startsWith('-')
64
+ ? text
65
+ : `'${text.split("'").join("'\\''")}'`
66
+ }
67
+
30
68
  // 显式常量,避免散落魔法字符串。
31
69
  export const MIN_NODE_MAJOR = 18
32
70
  export const SOCKET_DIR_NAME = '.glasspane'
@@ -70,7 +108,7 @@ export const INSTALL_SH_URL =
70
108
  /** 发布线锚点(版本真源 = 根 package.json,由 scripts/set-version.mjs 统一改写,
71
109
  * 勿手改):npx 形态下本地没有仓库时,引导 clone 的就是这个 tag,与 install.sh
72
110
  * 的 `GLASSPANE_RELEASE` 同值——两条一键入口必须拿到同一份源码。 */
73
- export const RELEASE_VERSION = '1.26.0'
111
+ export const RELEASE_VERSION = '1.27.0'
74
112
  /** 发布 ref(tag 名)。GLASSPANE_REF 环境变量可覆盖(追主干用 `main`)。 */
75
113
  export const REPO_REF = `v${RELEASE_VERSION}`
76
114
 
@@ -160,7 +198,14 @@ export function paint(text, color, enabled = process.stdout.isTTY) {
160
198
  // 纯逻辑层(可单测)
161
199
  // ---------------------------------------------------------------------------
162
200
 
163
- /** 解析 CLI 参数;未知/带值参数缺参时返回 { error }。 */
201
+ /** 解析 CLI 参数;未知/带值参数缺参时返回 `{ error, errorKind }`。
202
+ *
203
+ * 返回的 `options` 是**已经读到的那一部分**(不是 defaults)——入口要在"--help 与用法错同时
204
+ * 出现时谁赢"这条规则上看得见 help 有没有被真的给出来(2026-10-31 P1)。
205
+ * `errorKind` 也只有两个取值:`'repo-value'`=这一层自己就说不通的用法错(`--repo` 没接到取值、
206
+ * 或取值是旗标形状),`'unknown'`=只有本文件认得的旗标清单才能判定的错。两个 kind 与
207
+ * `--help` 的先后关系不同,规则写在入口的 `if (isMain)` 那一块上面。
208
+ */
164
209
  export function parseArgs(argv) {
165
210
  const defaults = {
166
211
  repoDir: null,
@@ -186,13 +231,21 @@ export function parseArgs(argv) {
186
231
  case '-h':
187
232
  opts.help = true
188
233
  break
189
- case '--repo':
190
- index += 1
191
- if (index >= rest.length || rest[index].startsWith('--')) {
192
- return { options: defaults, error: '--repo 需要一个目录参数' }
234
+ case '--repo': {
235
+ // 取值的两条判据与 install.sh 的 2c' 同一句,且**不以 `--` 为界**:单横线的 `-x` 同样是
236
+ // 一面旗标的形状。从前这里只否 `--` 前缀,于是 `--repo -x` 被当成一个目录收下继续跑,
237
+ // 而同一个文件的 unsafeArgvValue 对 clone 目标却否 `-` 前缀——一处两套口径(2026-10-31 P1)。
238
+ const value = rest[index + 1]
239
+ if (value === undefined) {
240
+ return { options: opts, error: '--repo 需要一个目录参数(后面没有取值)', errorKind: 'repo-value' }
193
241
  }
194
- opts.repoDir = rest[index]
242
+ if (value.startsWith('-')) {
243
+ return { options: opts, error: `--repo 需要一个目录参数(收到的是旗标:${value})`, errorKind: 'repo-value' }
244
+ }
245
+ index += 1
246
+ opts.repoDir = value
195
247
  break
248
+ }
196
249
  case '--no-prompt':
197
250
  opts.prompt = false
198
251
  break
@@ -232,10 +285,10 @@ export function parseArgs(argv) {
232
285
  opts.acceptUnverifiedSignature = true
233
286
  break
234
287
  default:
235
- return { options: defaults, error: `未知参数:${arg}(--help 查看用法)` }
288
+ return { options: opts, error: `未知参数:${arg}(--help 查看用法)`, errorKind: 'unknown' }
236
289
  }
237
290
  }
238
- return { options: opts, error: null }
291
+ return { options: opts, error: null, errorKind: null }
239
292
  }
240
293
 
241
294
  /** "这一棵是不是 GlassPane 仓库"的**唯一一份**判据(两个 marker 的相对路径)。
@@ -253,6 +306,39 @@ export function looksLikeRepoHere(dir) {
253
306
  return REPO_MARKERS.every((rel) => fs.existsSync(path.join(dir, rel)))
254
307
  }
255
308
 
309
+ /** 显式定位位(`--repo` / `GLASSPANE_REPO`)交进来的那一条路径的**第一字节之前的闸**(纯函数)。
310
+ *
311
+ * 存在的理由(2026-10-31 P0,实测):`install()` 从前对这两个值只测 `fs.existsSync`,于是
312
+ * `npx glasspane-install --repo <一个存在的非仓库目录>` 真的把那个目录当项目根——`npm install`
313
+ * 以它为 cwd 跑起来(往里写 `node_modules`),一路撞到 `swift build` 才回 1。同一串输入
314
+ * `install.sh` 在 2e 那一支回 1 且"没有 clone、没有写入任何东西"。两条一键入口对同一串 argv
315
+ * 必须同判,而"先写再拒"本身就违背本仓的规矩:能拒绝的守卫要在第一字节之前拒
316
+ * (同一族的先例:`GP_E_SOCKET_TRUST` 写在写位之前、`install.sh` 的 `looks_like_repo`)。
317
+ *
318
+ * 判据两条,拒时都要点名(缺了哪一条也要点名,否则读者不知道该补什么):
319
+ * 1. 目录存在;
320
+ * 2. 目录里同时有 {@link REPO_MARKERS} 那两个文件(与 `install.sh` 的 `looks_like_repo` 同一份)。
321
+ * 文案与 `install.sh` 的 2e/2f 两支逐句对齐,由 `installer/test/daily-20261030-entry-parity.test.mjs`
322
+ * 按同一串输入逐值对照——那句"两条入口同答"从前只写在注释里。
323
+ *
324
+ * @returns {string|null} 拒绝正文(调用方抛错即可,一条字节都不必已经写出);放行时是 null。
325
+ */
326
+ export function locatedRootRefusal({ label, dir, ref = '' }) {
327
+ if (typeof dir !== 'string' || dir === '') return null
328
+ const exists = fs.existsSync(dir)
329
+ if (exists && looksLikeRepoHere(dir)) return null
330
+ const missing = REPO_MARKERS.filter((rel) => !fs.existsSync(path.join(dir, rel)))
331
+ return [
332
+ `${label} 给了这个目录,而它不合判据:${dir}`,
333
+ ` 判据(两条都要在,与 looks_like_repo 同一份):目录要存在;目录里要同时有 ${REPO_MARKERS.join(' 与 ')}。`,
334
+ ` 现在缺的是:${exists ? `${missing.join('、')} 不在` : '目录不存在'}`,
335
+ // 这一句是这条闸的**承诺**,不是装饰:它排在 ensureLogDir 与 npm 之前,所以拒绝之后
336
+ // 家目录里不会多出 .glasspane,指定目录里不会多出 node_modules。
337
+ '本轮没有 clone、没有写入任何东西。',
338
+ `下一步:${label} 指一棵真的仓库(上面两条判据都在),或去掉 ${label} 让它 clone 一份${ref ? `(ref: ${ref})` : ''}。`,
339
+ ].join('\n')
340
+ }
341
+
256
342
  /** 从起始目录向上逐级寻找含 engine/Package.swift 与 mcp-shell/package.json 的根目录。 */
257
343
  export function resolveProjectRoot(startDir = process.cwd()) {
258
344
  let dir = path.resolve(startDir)
@@ -427,6 +513,40 @@ export function platformRefusal(platform = process.platform) {
427
513
  + '要在别的系统上用 GlassPane,等它把引擎搬到那一侧再说——现在这一步没有可绕的旗标。'
428
514
  }
429
515
 
516
+ /**
517
+ * 入口那一条 if/else 链的**纯函数形状**(2026-10-31):次序里有一档只在非 darwin 主机上才走到,
518
+ * 而 CI 的两条 lane 正好各跑一种(ubuntu 的 root workspace gate、macOS 的 darwin-only 套件)。
519
+ * 把判据留在 `if (isMain)` 里,本机就永远证不到那一档——上一轮正是这样把"同一串 argv 两入口
520
+ * 两个码"发到了 main 上(Linux runner 现形:install.sh 回 1,cli.js 回 2)。抽出来之后,
521
+ * 次序矩阵在任一台机器上都能整表跑,包括那台跑不到的。
522
+ *
523
+ * 次序(同一份规则写在 install.sh 的 2c'/2e 与 `if (isMain)` 上面):
524
+ * 1. `--repo` 的两类用法错(缺取值 / 取值是旗标形状)——这串 argv 自己就不通,先于 --help;
525
+ * 2. 显式定位位(`--repo` / `GLASSPANE_REPO`)交的目录不合仓库判据——**与主机无关**,
526
+ * 所以它排在平台判据之前,两条入口在 Linux 与 macOS 上给同一句、同一个码;
527
+ * 3. `--help` / `-h`:0(CI 的 install-gate 与两份 README 钉的就是这个 0);
528
+ * 4. 平台判据:跑不了这个产品的机器上第一句说的是"这里跑不了"(1)。未知参数只有本文件判得
529
+ * 出来(install.sh 没有旗标清单,也不许抄一份),所以那一档在平台判据**之后**:否则
530
+ * 同一串 argv 在 Linux 上就成了 install.sh=1 / cli.js=2;
531
+ * 5. 未知参数:2 + usage 页;
532
+ * 6. `--restore-launchd` / 正常安装。
533
+ */
534
+ export function entryDecision({ options, error = null, errorKind = null,
535
+ platform = process.platform, env = process.env }) {
536
+ const repoValueError = errorKind === 'repo-value'
537
+ const located = (repoValueError || options.help || options.restoreLaunchd)
538
+ ? null : explicitLocatedRootRefusal(options, env)
539
+ const platformRefuse = (repoValueError || options.help || located !== null || options.restoreLaunchd)
540
+ ? null : platformRefusal(platform)
541
+ if (repoValueError) return { kind: 'usage-error', message: error, exitCode: 2 }
542
+ if (located !== null) return { kind: 'located-root', message: located, exitCode: 1 }
543
+ if (options.help) return { kind: 'help', exitCode: 0 }
544
+ if (platformRefuse) return { kind: 'platform', message: platformRefuse, exitCode: 1 }
545
+ if (error) return { kind: 'usage-error', message: error, exitCode: 2 }
546
+ if (options.restoreLaunchd) return { kind: 'restore-launchd', exitCode: 0 }
547
+ return { kind: 'install', exitCode: 0 }
548
+ }
549
+
430
550
  /** 汇总预检结果:缺项按严重程度排序返回可读描述(空数组 = 全部通过)。 */
431
551
  export function preflightIssues(env) {
432
552
  const issues = []
@@ -751,37 +871,56 @@ export function bundlesToReplace({ plan, exists = fs.existsSync } = {}) {
751
871
  .map(([, target]) => target)
752
872
  }
753
873
 
874
+ export function explicitLocatedRootRefusal(options, env = process.env) {
875
+ const explicitRoot = options.repoDir ? path.resolve(options.repoDir) : null
876
+ const envRoot = env.GLASSPANE_REPO ? path.resolve(env.GLASSPANE_REPO) : null
877
+ const ref = resolvePinRef(env)
878
+ for (const located of [
879
+ { label: '--repo', dir: explicitRoot },
880
+ { label: 'GLASSPANE_REPO', dir: envRoot },
881
+ ]) {
882
+ const refusal = locatedRootRefusal({ ...located, ref })
883
+ if (refusal) return refusal
884
+ }
885
+ return null
886
+ }
887
+
754
888
  /** 安置一份 bundle 时那条"没落地"的拒绝:说清动到哪一步、旧的一份还在不在、下一步跑什么。
755
889
  * finding C9(2026-10-24):从前这里只把 `cpSync` 的 errno 原样抛出去——读的人既不知道
756
890
  * 旧 bundle 是否还在(旧实现是先 `rm -rf` 再拷,中途失败就是"旧的没了、新的是半棵"),
757
891
  * 也没有一句下一步。现在每一种失败各自点名"原件在不在",并给一条真能跑的命令。 */
758
- function bundlePlacementFailureText({ source, target, staged, retired, error, step, stagedRemoved = true }) {
892
+ export function bundlePlacementFailureText({ source, target, staged, retired, error, step, stagedRemoved = true }) {
759
893
  const raw = String(error?.message ?? error)
760
894
  const errno = error?.code && !raw.startsWith(String(error.code)) ? `${error.code}: ${raw}` : raw
761
895
  const head = `安置 ${target} 失败(来源 ${source}):${errno}`
762
- const dir = JSON.stringify(path.dirname(target))
763
- const q = (p) => JSON.stringify(p)
896
+ // 命令位上的每一份路径都**就地**走本包自己的 `quoteShellArg`(2026-10-31:这里原来是一个
897
+ // `const dir = JSON.stringify(...)` 与一个 `q = (p) => JSON.stringify(p)`——那是双引号,
898
+ // `$(` 与反引号在双引号里照常展开,"照着这条命令修磁盘"就变成"照着目录名执行"。判据在
899
+ // `installer/test/shell-quoting.test.mjs` 的行为半边与
900
+ // `mcp-shell/test/remedy-shell-quoting.test.mjs` 的参数位扫描里;扫描按**名字**放行,所以
901
+ // 这里不保留 `dir`/`q` 这类别名:一个别名就是一次让闸看不见这处调用的改写。)
764
902
  if (step === 'copy' || step === 'retire') {
765
903
  return `${head}\n`
766
904
  + `新的一份只走到暂存位置就断了,原件还在原位——${target} 仍是上一轮那份**完整**的 bundle,`
767
- + `本轮没有任何一步动过它的内容。下一步:空间不够看 \`df -h ${dir}\`,权限/旗标看 `
768
- + `\`ls -ld ${dir}\` 与 \`ls -lO ${q(target)}\`(macOS 的 immutable 旗标 uchg 会让改名与覆盖都失败),`
905
+ + `本轮没有任何一步动过它的内容。下一步:空间不够看 \`df -h ${quoteShellArg(path.dirname(target))}\`,权限/旗标看 `
906
+ + `\`ls -ld ${quoteShellArg(path.dirname(target))}\` 与 \`ls -lO ${quoteShellArg(target)}\`(macOS 的 immutable 旗标 uchg 会让改名与覆盖都失败),`
769
907
  + `腾出来或修好之后重跑 install.sh。`
770
908
  + (stagedRemoved
771
909
  ? `本轮的暂存副本 ${staged} 已删,不需要手工清理。`
772
- : `本轮的暂存副本 ${staged} 没能删掉(同一个错误也挡住了它),重跑前手工 \`rm -rf ${q(staged)}\` 即可。`)
910
+ : `本轮的暂存副本 ${staged} 没能删掉(同一个错误也挡住了它),重跑前手工 \`rm -rf ${quoteShellArg(staged)}\` 即可。`)
773
911
  }
774
912
  if (step === 'restore') {
775
913
  return `${head}\n`
776
914
  + `这一步之后本机已经没有 ${target} 了:新的一份在 ${staged},上一轮那份完整的备份在 ${retired},`
777
915
  + `而把它们放回原位的改名也被同一个错误挡住。这一步归人(安装器不发放提权命令):`
778
- + `先 \`mv ${q(retired)} ${q(target)}\` 把旧的一份放回原位,或 \`mv ${q(staged)} ${q(target)}\` 用本轮新的一份;`
779
- + `两个都跑不通就是 ${path.dirname(target)} 的权限问题,看 \`ls -ld ${dir}\`,修好后重跑 install.sh。`
916
+ + `先 \`mv ${quoteShellArg(retired)} ${quoteShellArg(target)}\` 把旧的一份放回原位,`
917
+ + `或 \`mv ${quoteShellArg(staged)} ${quoteShellArg(target)}\` 用本轮新的一份;`
918
+ + `两个都跑不通就是 ${path.dirname(target)} 的权限问题,看 \`ls -ld ${quoteShellArg(path.dirname(target))}\`,修好后重跑 install.sh。`
780
919
  }
781
920
  // step === 'place':新的一份没能落位,旧的一份已经被挪回原位——机器上此刻仍是完整的一版。
782
921
  return `${head}\n`
783
922
  + `${target} 已经放回上一轮那一份(先把备份 ${retired} 挪回原位再报错),本轮新的一份留在 ${staged}——`
784
- + `本机现在不是"半棵",是旧的那版在位。下一步:\`ls -ld ${dir}\` 看这个目录当前账号能不能写`
923
+ + `本机现在不是"半棵",是旧的那版在位。下一步:\`ls -ld ${quoteShellArg(path.dirname(target))}\` 看这个目录当前账号能不能写`
785
924
  + `(EACCES 通常是目录属主不是您,或这卷不保存权限位),修好后重跑 install.sh;`
786
925
  + `两处残留 ${staged} 与 ${retired} 想清就 \`rm -rf\`,留着也不影响下一轮。`
787
926
  }
@@ -1498,7 +1637,7 @@ export function tagVerifyDecision({ sig, pinRef, repoDir, acceptUnverified = fal
1498
1637
  + `git -C "${repoDir}" tag -v ${pinRef}\n`
1499
1638
  + '确实在没有 gpg 的机器上要装,就修好工具链再重跑(`brew install gnupg` 或 `xcode-select --install`);'
1500
1639
  + '理解风险、决定就在这一档缺结论的情况下继续,才显式带上放行旗标重跑:\n'
1501
- + ` node installer/cli.js --repo "${repoDir}" --accept-unverified-signature\n`
1640
+ + ` node installer/cli.js --repo ${quoteShellArg(repoDir)} --accept-unverified-signature\n`
1502
1641
  + ` curl -fsSL ${INSTALL_SH_URL} | sh -s -- --accept-unverified-signature\n`
1503
1642
  + '它与 updater 的 `--consent unsigned-release` 同一形态:只批"缺证明",'
1504
1643
  + '签名存在而验不过(invalid)永不被它覆盖;`--no-prompt` 也不是这里说的同意。',
@@ -1817,7 +1956,7 @@ export async function registerAutoUpdate({
1817
1956
  caRoots: outcome.state && outcome.state.caRoots ? outcome.state.caRoots : null,
1818
1957
  }
1819
1958
  if (registered) {
1820
- say(`每日自动更新已注册(${agentLabel},${summary.scheduleMeasured ? `在册作业跑在 ${schedule}` : `默认 ${schedule}——这一档没能从在册作业读回实际时刻,所以下一句是默认值而不是实测`},状态根 ${stateRoot};指针 ${written.path})——一键关:node "${tree.cli}" disable`)
1959
+ say(`每日自动更新已注册(${agentLabel},${summary.scheduleMeasured ? `在册作业跑在 ${schedule}` : `默认 ${schedule}——这一档没能从在册作业读回实际时刻,所以下一句是默认值而不是实测`},状态根 ${stateRoot};指针 ${written.path})——一键关:node ${quoteShellArg(tree.cli)} disable`)
1821
1960
  // "已注册"这三个字的证据是 updater 把在册作业读回来核对过。launchd 装载成功但读不回在册作业时,
1822
1961
  // 这句话只能算一半成立,而那另一半(原话)必须跟着说出来——否则这台机器看起来有每日作业,实际
1823
1962
  // 有没有人跑没人知道。措辞仍来自唯一作者 outcome.message,这里只转述。
@@ -1837,13 +1976,13 @@ export async function registerAutoUpdate({
1837
1976
  } else if (ca) {
1838
1977
  say(paint(`注意(自动更新的网络这一跳):${outcome.message}`, 'yellow'))
1839
1978
  } else {
1840
- say(paint(`注意:这份 updater 没有回报根证书束的导出结果(旧版本);若本机 HTTPS 被中间人替换,每日检查会在第一道校验上失败,跑 node "${tree.cli}" enable 可重新导出。`, 'yellow'))
1979
+ say(paint(`注意:这份 updater 没有回报根证书束的导出结果(旧版本);若本机 HTTPS 被中间人替换,每日检查会在第一道校验上失败,跑 node ${quoteShellArg(tree.cli)} enable 可重新导出。`, 'yellow'))
1841
1980
  }
1842
1981
  } else {
1843
1982
  say(
1844
1983
  `自动更新已关闭(${switchedOffByEnv ? 'updater 报环境变量已关,见下面它自己的原话' : '--no-auto-update'}):`
1845
1984
  + `${agentLabel} 未注册/已卸载,状态里记 disabled=true——面板显示"自动更新已关闭(上次检查 …)"而不是"从未检查"。`
1846
- + `手动 node "${tree.cli}" check / apply 仍可用;重开:node "${tree.cli}" enable。`
1985
+ + `手动 node ${quoteShellArg(tree.cli)} check / apply 仍可用;重开:node ${quoteShellArg(tree.cli)} enable。`
1847
1986
  + `(updater 原话:${outcome.message})`,
1848
1987
  )
1849
1988
  }
@@ -1868,7 +2007,7 @@ export function updateGuidanceText(update) {
1868
2007
  if (update.state === 'registered') {
1869
2008
  const ca = update.caRoots
1870
2009
  const caLine = !ca
1871
- ? ` ⚠ 这份 updater 没有回报 node 要用的系统根证书束(旧版本);本机 HTTPS 若被中间人替换,每日检查会在第一道校验上失败。补上:node "${update.updaterCli}" enable。`
2010
+ ? ` ⚠ 这份 updater 没有回报 node 要用的系统根证书束(旧版本);本机 HTTPS 若被中间人替换,每日检查会在第一道校验上失败。补上:node ${quoteShellArg(update.updaterCli)} enable。`
1872
2011
  : ca.status === 'ok'
1873
2012
  ? ` node 用本机导出的系统根证书束 ${ca.certs} 张(${ca.path},已写进作业的 NODE_EXTRA_CA_CERTS)。`
1874
2013
  : ` ⚠ 本机没能导出 node 要用的系统根证书束(${ca.status});HTTPS 被中间人替换的机器上,每日检查会在第一道校验上失败,`
@@ -1878,7 +2017,7 @@ export function updateGuidanceText(update) {
1878
2017
  ` (作业 ${update.agentLabel},RunAtLoad=false,日志 ${update.stateRoot}/update.log);`,
1879
2018
  ' 只在 daemon 空闲应答探针、且候选发布版的八道校验全部通过时才换版,major 永远等人点按钮。',
1880
2019
  ...(caLine ? [caLine] : []),
1881
- ` 一键关:node "${update.updaterCli}" disable(卸该作业 + 状态记 disabled=true);重开:enable。`,
2020
+ ` 一键关:node ${quoteShellArg(update.updaterCli)} disable(卸该作业 + 状态记 disabled=true);重开:enable。`,
1882
2021
  ` 卸载本机安装时:bootout daemon 作业的同时**也必须** bootout ${update.agentLabel} 并删它的 plist。`,
1883
2022
  ]
1884
2023
  }
@@ -1886,7 +2025,7 @@ export function updateGuidanceText(update) {
1886
2025
  `6. 自动更新:已关闭(${update.reason === 'env' ? 'updater 判定环境变量为关,安装器没有第二套解读' : '--no-auto-update'})。`,
1887
2026
  ` ${update.agentLabel} 未注册,状态记 disabled=true:面板显示"自动更新已关闭(上次检查 …)",`,
1888
2027
  ' 不会静默消失;手动检查/安装仍是同一条 CLI(面板上那两个按钮也是它)。',
1889
- ` 重开:node "${update.updaterCli}" enable${update.reason === 'env' ? '(先把那个环境变量去掉,否则 updater 会拒绝注册)' : ''}。`,
2028
+ ` 重开:node ${quoteShellArg(update.updaterCli)} enable${update.reason === 'env' ? '(先把那个环境变量去掉,否则 updater 会拒绝注册)' : ''}。`,
1890
2029
  ` 它也负责卸载:bootout ${update.agentLabel} + 删 ~/Library/LaunchAgents 下那份 plist。`,
1891
2030
  ]
1892
2031
  }
@@ -2205,7 +2344,10 @@ export function usageText() {
2205
2344
  '用法: node installer/cli.js [选项]',
2206
2345
  '',
2207
2346
  '选项:',
2208
- ' --repo <目录> 指定项目根目录(默认自动向上查找)',
2347
+ ' --repo <目录> 指定项目根目录(默认自动向上查找)。这一枚与 GLASSPANE_REPO 都要先过',
2348
+ ' 判据(目录存在 + 目录里同时有 engine/Package.swift 与 mcp-shell/package.json):',
2349
+ ' 不合就当场拒绝,且拒在任何写入之前——从前它只测"目录在不在",于是',
2350
+ ' 一个存在的非仓库目录会被当成项目根去跑 npm install(2026-10-31 修)',
2209
2351
  ' --no-prompt 跳过破坏性步骤的确认(脚本/自动化场景)。被它拦住的是三件:',
2210
2352
  ' ① bootout 已加载的 launchd daemon 作业(会打断正在跑的 act;',
2211
2353
  ' install 与 --restore-launchd 走的是同一道门);',
@@ -2244,8 +2386,19 @@ export function usageText() {
2244
2386
  '退出码(脚本/agent 调用方读这个,别读屏幕文案):',
2245
2387
  ' 0 安装完成且 daemon 实测应答 hello;或本轮按要求压根不该有 daemon',
2246
2388
  ' (--no-daemon 且 --no-launchd)',
2247
- ' 1 收尾未通过 hello 校验(daemon 没起来/不应答),或构建/产物/launchd 出错',
2389
+ ' 1 收尾未通过 hello 校验(daemon 没起来/不应答),或构建/产物/launchd 出错;',
2390
+ ' 也包括这两条**什么都没构建就停下**的支路——它们同样回 1,按 rc 分叉的调用方别把 1',
2391
+ ' 读成"跑过但没成":① 平台拒绝(`process.platform` 不是 darwin,见 platformRefusal),',
2392
+ ' ② 环境预检未通过(缺 node/swift/npm 那一族,`checkEnvironment` 报的每条都列在输出里)。',
2393
+ ' 这两条的正文各自点名了下一步,读正文才知道该装什么。',
2248
2394
  ' 2 命令行参数错误',
2395
+ ' 用法错与 --help 同时出现时谁赢(install.sh 的 2c\' 那一节写的是同一份规则):',
2396
+ ' `--repo` 没接到取值、或接到的是旗标(`-` 开头,单双横线都算)——这一类**先赢**,仍旧退 2;',
2397
+ ' "未知参数"这一类**让位**:给了 --help 就打这一页并退 0,因为入口脚本没有本文件的旗标',
2398
+ ' 清单、判不出"未知",抄一份就是下一处没人对照的孪生抄本。',
2399
+ ' 还有一档**让位**(2026-10-31 定下,与 install.sh 的平台闸同一口径):主机不是 macOS 时,',
2400
+ ' "未知参数"先撞平台闸并回 1——那台机器就算 argv 写对了也跑不了,第一句该说的是这件事。',
2401
+ ' 所以在 Linux runner 上 `--no-such-flag` 回 1 而不是 2;要读这一页在两种主机上都用 --help(0)。',
2249
2402
  ' 跨二进制的用法错对照(**这是在记录一处已知分歧,不是修它**——那些码都是发出去的契约,',
2250
2403
  ' 本轮一个都没改):同样是"命令行参数错误",`node updater/cli.js` 回 2(与本文件一致),',
2251
2404
  ' 后台服务 `glasspaned` 回 64(并把整块用法打出去)。按 rc 分支的脚本要把 2 与 64 都当用法错。',
@@ -2307,7 +2460,7 @@ export function nextStepsText({
2307
2460
  // 已经拿到 rootDir),印 "<仓库目录>" 占位符等于没给可执行的东西。
2308
2461
  ...(daemonVerified ? [] : [
2309
2462
  paint('⚠ 后台服务未通过 hello 校验:下面第 1 步接好的 MCP 客户端会连不上 daemon。', 'red'),
2310
- ` 先修这一步:node "${path.join(rootDir, 'installer', 'cli.js')}" --restore-launchd`,
2463
+ ` 先修这一步:node ${quoteShellArg(path.join(rootDir, 'installer', 'cli.js'))} --restore-launchd`,
2311
2464
  '',
2312
2465
  ]),
2313
2466
  '1. MCP 客户端(Claude Desktop / Cursor / 任意 MCP host)接入配置片段:',
@@ -2339,7 +2492,7 @@ export function nextStepsText({
2339
2492
  '3. daemon 已注册 launchd 开机自启(--no-launchd 可跳过);维护命令:',
2340
2493
  ' glasspaned --approval-audit / --approval-verify / --prune-evidence / --evidence-stats',
2341
2494
  ` 作业被 bootout(等授权期间常发生)后的恢复**不需要手敲 launchctl**:`,
2342
- ` node "${path.join(rootDir, 'installer', 'cli.js')}" --restore-launchd`,
2495
+ ` node ${quoteShellArg(path.join(rootDir, 'installer', 'cli.js'))} --restore-launchd`,
2343
2496
  ` (检测→bootstrap→hello 校验自报席位;勾完 TCC 框重跑即自动换进程复验)`,
2344
2497
  `4. 主体名核对:设置面板「Daemon 状态 → 主体」应与上面「${entryName}」一致;不一致说明连到了别的构建实例。`,
2345
2498
  '5. registry 发布形态:MCP 服务器已可独立安装(`npm i -g glasspane-mcp`,命令名',
@@ -3060,7 +3213,7 @@ export function panelOpenHint({ panel, rootDir, settingsApp = null, exists = (p)
3060
3213
  runnable: true,
3061
3214
  target,
3062
3215
  text: info.viaBundle
3063
- ? `open "${target}"`
3216
+ ? `open ${quoteShellArg(target)}`
3064
3217
  : `直接执行裸二进制面板:"${target}"(当前没有 .app bundle,所以不经 open、没有 bundle 身份)`,
3065
3218
  }
3066
3219
  }
@@ -3093,7 +3246,7 @@ export function verificationFailureText({
3093
3246
  ? `安装未完成:socket 在(${socketPath}),但 daemon 没有正确应答 hello——见 ${daemonLog}`
3094
3247
  : `安装未完成:没有等到 daemon 在 ${socketPath} 应答 hello——见 ${daemonLog}`,
3095
3248
  `本命令退出码 ${exitCode}:install.sh 与调用它的脚本/agent 按安装失败处理,先别接 MCP。`,
3096
- `补救(不需要手敲 launchctl):node "${cliPath}" --restore-launchd`,
3249
+ `补救(不需要手敲 launchctl):node ${quoteShellArg(cliPath)} --restore-launchd`,
3097
3250
  '修好后重跑安装器即可(它会覆盖式重建产物与 plist)。',
3098
3251
  ].join('\n')
3099
3252
  }
@@ -3121,6 +3274,18 @@ export async function install({
3121
3274
  const homeDir = guard.home
3122
3275
  const pinRef = resolvePinRef(env)
3123
3276
 
3277
+ // 2026-10-31 P0:两个**显式**定位位排在 `fs.existsSync` 之前先过 looksLikeRepoHere。
3278
+ // 从前这里只问"在不在",于是一个存在的非仓库目录会被当成项目根交给 npm(见
3279
+ // locatedRootRefusal 的注释),而同一串 argv 在 install.sh 那一头回 1 且一个字节都没写。
3280
+ // 两条一键入口对同一串输入必须同判,且"能拒的守卫要在第一字节之前拒"是本仓的规矩。
3281
+ // 判据本体在 explicitLocatedRootRefusal 里——入口也调它一次,这样"这棵 argv 自己就不通"
3282
+ // 这件事不与主机平台有关(CI 的 Linux 那一格实测过:从前 install.sh 按判据拒、cli.js 按
3283
+ // "只支持 macOS"拒,同一串输入两句话)。
3284
+ {
3285
+ const refusal = explicitLocatedRootRefusal(options, env)
3286
+ if (refusal) throw new Error(refusal)
3287
+ }
3288
+
3124
3289
  let rootDir = explicitRoot ?? envRoot ?? resolveProjectRoot()
3125
3290
 
3126
3291
  if (!rootDir || !fs.existsSync(rootDir)) {
@@ -3551,24 +3716,47 @@ if (isMain) {
3551
3716
  // --restore-launchd/环境预检这四条还留着 `process.exit()`;Linux runner 上就是
3552
3717
  // 从这里现形的(那台机器没有 swift,预检拒绝必然走到,而测试原本指望走到 install
3553
3718
  // 的拒绝分支——一条依赖机器状态的断言)。
3554
- const { options, error } = parseArgs(process.argv.slice(2))
3719
+ const { options, error, errorKind } = parseArgs(process.argv.slice(2))
3720
+ // **两入口对同一串 argv 的用法错规则**(2026-10-31 P1;同一份规则写在 install.sh 的 2c' 上面):
3721
+ // 1. `--repo` 没接到取值、或接到的是一面旗标(`-` 开头,单双横线都算)——这是"这一层自己就
3722
+ // 说不通"的用法错,**先于 --help**:两条入口都退 2、都说那一句、都随后打 usage 页。
3723
+ // 带 --help 也一样退 2,因为 argv 在 --repo 那一枚上根本没写完。
3724
+ // 2. "未知参数"只有读了本文件的旗标清单才判得出来,而 install.sh 没有那份清单(也不许抄一份,
3725
+ // 那正是本仓反复修的"两份抄本没人对照")。所以这一档在 --help 面前**让位**:给了 --help
3726
+ // 就是要这一页,两条入口都退 0 并打出各自那一页;没给 --help 时由这里退 2。
3727
+ // 3. 单独的 --help / -h 仍旧退 0(CI 的 install-gate 与两份 README 钉的就是那个 0)。
3728
+ // 从前这里是 `else if (error)` 排在 `else if (options.help)` 前面,两个 kind 一起压过 help,
3729
+ // 于是 `--help --no-such-flag` 在这一头退 2、在 install.sh 那一头退 0(实测)——同一串 argv
3730
+ // 两个码,而按 rc 分叉的调用方读到的"2 = 命令行写错了"在两条入口之间漂移。
3555
3731
  // 平台判据住在 cli.js 这一侧才是权威的:`uname` 是 PATH 上一个可以被换掉的程序(本轮实测:
3556
3732
  // 桩一个 `uname` 说 Linux,install.sh 那一道只管挡"要 clone 的那一趟",源码在手边时一路走到
3557
3733
  // `exec node cli.js`,npm ci / tsc / swift build / launchd 注册全部真的发生),而
3558
- // `process.platform` 是 node 向主机问来的,桩不掉。放在 --help / 参数错误 / --restore-launchd
3559
- // 之后判:CI 的 install-gate 那一格跑在非 macOS 上,它读的正是 usage 与预检那几句。
3560
- const refusal = (error || options.help || options.restoreLaunchd) ? null : platformRefusal()
3561
- if (refusal) {
3562
- process.stderr.write(paint(`\n${refusal}\n`, 'red'))
3563
- process.exitCode = 1
3564
- } else if (error) {
3565
- process.stderr.write(`\n${paint(`参数错误:${error}`, 'red')}\n\n`)
3734
+ // `process.platform` 是 node 向主机问来的,桩不掉。
3735
+ // 但它**只压过"未知参数"那一档,不压 --help / --repo 的两类用法错 / 显式定位位的判据**
3736
+ // (2026-10-31,CI 的 Linux 那一格现形):从前这里把 `error` 也算进"跳过平台判据"的条件,
3737
+ // 于是 `--no-such-flag` 在非 macOS 上这头退 2、install.sh 那头退 1——而 install.sh 在把 argv
3738
+ // 交给本文件之前,只判得了它自己那份旗标(未知参数那一档必须由本文件回答)。同一串 argv
3739
+ // 两个码,按 rc 分叉的调用方就读了个寂寞。留下来的规则是:一台跑不了这个产品的机器上,
3740
+ // 第一句该说的是"这里跑不了"(rc 1),参数打错是它之后的事;`--help` 仍旧先赢(0)。
3741
+ const decision = entryDecision({ options, error, errorKind })
3742
+ // 每一支的退出码在这里**写死成字面量**:次序由 `entryDecision` 决定(那台跑不到的主机上的
3743
+ // 那一档因此可在本机整表验证),而"每条退出都走事件循环、每条分支都还在"由
3744
+ // `test/failure-exit.test.mjs` 扫这几行钉住——它认的是字面量,改成 `= decision.exitCode`
3745
+ // 会让那条闸看不见分支被删。
3746
+ if (decision.kind === 'usage-error') {
3747
+ process.stderr.write(`\n${paint(`参数错误:${decision.message}`, 'red')}\n\n`)
3566
3748
  process.stderr.write(usageText())
3567
3749
  process.exitCode = 2
3568
- } else if (options.help) {
3750
+ } else if (decision.kind === 'located-root') {
3751
+ process.stderr.write(`\n${paint(decision.message, 'red')}\n`)
3752
+ process.exitCode = 1
3753
+ } else if (decision.kind === 'help') {
3569
3754
  process.stdout.write(usageText())
3570
3755
  process.exitCode = 0
3571
- } else if (options.restoreLaunchd) {
3756
+ } else if (decision.kind === 'platform') {
3757
+ process.stderr.write(paint(`\n${decision.message}\n`, 'red'))
3758
+ process.exitCode = 1
3759
+ } else if (decision.kind === 'restore-launchd') {
3572
3760
  // 审计项④:恢复 + 校验全机器化,退出码即判定(0=daemon 就位且已按实际
3573
3761
  // 自报如实报告;1=作业/服务面失败),agent 可直接执行并按 message 续办。
3574
3762
  // finding C3:这一支也可能 bootout 一个已加载作业,所以它读同一个同意门——
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glasspane-install",
3
- "version": "1.26.0",
3
+ "version": "1.27.0",
4
4
  "description": "GlassPane one-command installer: terminal onboarding → install deps → build TS + Swift engine → start daemon → open settings GUI for permission guide",
5
5
  "type": "module",
6
6
  "license": "MIT",