ssh-net 26.10.33 → 26.10.34

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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@
7
7
  GitHub Release(Actions 自动跑测试后 npm publish;跳号与 0.x 的完整
8
8
  考据见 git 史)。
9
9
 
10
+ ## [26.10.34] - 2026-10-03
11
+
12
+ ### 精简:冗余清理(代码/测试/文档三面,对外行为仅删 update 别名)
13
+
14
+ - **`update` 别名删除**:与 `upgrade` 两名一实(同 26.10.31 删 checkin
15
+ 的先例),help 与文档只推 `upgrade`——习惯敲 update 的改敲 upgrade
16
+ - **死代码删除**:state 的 `removeAllEdges`、sshconfig 的 User 解析
17
+ (hostTable 只喂 HostName,user 一律来自 topology)、paths 的 `home`
18
+ 导出、status 三个无消费的返回字段(runtimeVersion/links/run 的
19
+ status)、fake ssh 的 release 放行通路(link 循环时代遗留、零调用)
20
+ - **重复收敛**:uplink-edge plist 的 glob 三份拷贝 →
21
+ `launchd.edgeAliasesOnDisk`;`_register` 四分支合并为「部署/唤醒」两
22
+ 条路径(行为不变,返回文案原样);core·node 的 relay 口 issue 文案、
23
+ 测试的 sleep/waitForLog 与 edge 正常形态 fake 组合各收敛为一份
24
+ - **文档修正**:design §2.1「LAN IP 在 topology」为去 IP 改造前残留、
25
+ §5 预检段补 26.10.33 的默认形态限定并删一处逐字重复句;
26
+ vscode-mark/putFirst 注释漂移与 ci.yml 过期用例数清理
27
+
10
28
  ## [26.10.33] - 2026-10-03
11
29
 
12
30
  ### 修复:edge 端口预检按 link 形态收窄
package/libexec/cli.mjs CHANGED
@@ -24,7 +24,6 @@ import { run as upgradeRun } from './commands/upgrade.mjs';
24
24
  const COMMANDS = {
25
25
  install: { run: installRun, desc: '按本机角色安装;edge 可带 --with-link/--without-link 管理转发附加件' },
26
26
  upgrade: { run: upgradeRun, desc: '一键升级(npm i -g @latest + install 按 marker 刷新运行时)' },
27
- update: { run: upgradeRun, desc: 'upgrade 的别名' },
28
27
  uninstall: { run: uninstallRun, desc: '停用并删除全部作业、运行时与状态(再 npm uninstall -g)' },
29
28
  start: { run: startRun, desc: 'edge 开隧道(relay|peer,缺省或 -a=relay+peer)/ core·node 启动' },
30
29
  stop: { run: stopRun, desc: 'edge 关隧道(relay|peer,缺省或 -a 全关)/ core·node 停服' },
@@ -145,7 +145,7 @@ async function installEdge(ctx, args) {
145
145
  removeJob(ctx, label, plistPath);
146
146
  fs.rmSync(path.join(paths.binDir, 'ssh-net-link-core'), { force: true });
147
147
  fs.rmSync(path.join(paths.binDir, linkLinkName(topo.core.alias)), { force: true });
148
- // 退役状态残留(paths 已无这些键名,按 state 布局直接删)
148
+ // 退役状态残留(26.10.31 退役;按约定一个月后删本两行)
149
149
  fs.rmSync(path.join(paths.stateDir, 'ROUTE_PEER'), { force: true });
150
150
  fs.rmSync(path.join(paths.stateDir, 'LINK_ON'), { force: true });
151
151
  }
@@ -153,7 +153,7 @@ async function installEdge(ctx, args) {
153
153
  // conf.d 片段(design §4.2):edge 是 routes 的唯一安装角色——routes 含
154
154
  // 选路 Match 与尾部 VS Code 打标块;新签名带本机别名
155
155
  const routesChanged = syncConfFile(paths.routesFile, renderRoutes(topo, ctx.self.alias));
156
- // 打标块并入 routes 后的旧文件清理(26.11 退役;按约定一个月后删本行)
156
+ // 打标块并入 routes 后的旧文件清理(26.10.32 退役;按约定一个月后删本行)
157
157
  fs.rmSync(path.join(paths.confDir, 'vscode-mark'), { force: true });
158
158
  const fragMsg = routesChanged ? '(选路片段已更新)' : '';
159
159
  if (!comp && !routesChanged && flag === undefined) {
@@ -165,16 +165,6 @@ async function installEdge(ctx, args) {
165
165
  return `${head}${comp}${fragMsg}`;
166
166
  }
167
167
 
168
- /** 磁盘上已注册的 uplink-edge 别名(plist glob;topology 已删的机器靠它兜底)。 */
169
- function registeredEdgeAliases(ctx) {
170
- let files = [];
171
- try {
172
- files = fs.readdirSync(ctx.paths.launchAgentsDir)
173
- .filter((f) => f.startsWith('local.ssh-net-uplink-edge-') && f.endsWith('.plist'));
174
- } catch { /* 目录不存在 */ }
175
- return files.map((f) => f.slice('local.ssh-net-uplink-edge-'.length, -'.plist'.length));
176
- }
177
-
178
168
  function installCore(ctx) {
179
169
  const { topo, paths } = ctx;
180
170
  reconcileEdgeFragments(ctx);
@@ -182,7 +172,7 @@ function installCore(ctx) {
182
172
  // 已注册的回拨组件在 install 时一并迁移/对账(旧版带机器名实体拷贝 →
183
173
  // 软链):否则 upgrade 后 core status 要对每台未联系的 edge 报组件异常,
184
174
  // 直到它下次报名才自愈(2026-09-30 补)
185
- const edges = registeredEdgeAliases(ctx);
175
+ const edges = launchd.edgeAliasesOnDisk(paths.launchAgentsDir);
186
176
  const entities = [
187
177
  ['ssh-net-uplink-relay', 'ssh-net-uplink-relay'],
188
178
  ];
@@ -103,6 +103,16 @@ function rollbackEdgeRegistration(ctx, edge, prevV6) {
103
103
  else writeEdgeRegistration(ctx, edge, prevV6);
104
104
  }
105
105
 
106
+ /** 未注册/重部署分支的部署失败回滚:state 恢复旧 v6(无旧值则删)、
107
+ * 片段删除——没有 job 兜底的片段就是假入口。回滚失败不遮蔽原始错误。 */
108
+ function rollbackRegistration(ctx, edge, prevV6) {
109
+ try {
110
+ if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
111
+ else ctx.state.writeEdgeV6(edge.alias, prevV6);
112
+ removeConfFile(ctx.paths.edgeHostFile(edge.alias));
113
+ } catch { /* 回滚失败不遮蔽原始错误 */ }
114
+ }
115
+
106
116
  /** start peer 的实现:控制面立即报名 + 置 relay+peer 开关。返回给人看的
107
117
  * 文案(带上报名详情:v6 与 core 的响应)。先报名、成功后才落开关——
108
118
  * 未安装(fatal)零副作用;可重试的报名失败(relay 不通、当场无 v6)
@@ -162,71 +172,34 @@ export function runRegister(ctx, args = []) {
162
172
  [['ssh-net-uplink-edge', 'ssh-net-uplink-edge']],
163
173
  [[edgeLinkName(alias), 'ssh-net-uplink-edge']]);
164
174
 
165
- // 未注册:首次报名,plist 后 enable + bootstrap。部署失败回滚登记:
166
- // 不回滚的话 conf.d/edge-<别名> 是没有 job 兜底的假入口(install 的
167
- // reconcileEdgeFragments 自己定义的不变式),只能等下轮报名或人工 install 修。
168
- // 回滚形态:state 恢复旧 v6、**片段删除**(而非重写)——未注册态的片段按
169
- // reconcile 不变式本就不该在(休眠/会话重建时已被 retire 清掉),重写它
170
- // 恰好造出上面注释要避免的假入口。回滚自身失败不遮蔽原始错误
171
- if (!st.registered) {
172
- writeEdgeRegistration(ctx, edge, v6);
173
- try {
174
- const r = syncPlist(ctx, { label, plistPath, content });
175
- if (r.lintError) throw new Error(`uplink-edge plist 校验失败:${r.lintError}`);
176
- } catch (err) {
177
- try {
178
- if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
179
- else ctx.state.writeEdgeV6(edge.alias, prevV6);
180
- removeConfFile(ctx.paths.edgeHostFile(edge.alias));
181
- } catch { /* 回滚失败不遮蔽原始错误 */ }
182
- throw err;
183
- }
184
- return `registered ${alias}`;
185
- }
186
-
187
- // 已注册但渲染结果与磁盘不符(topology 的 user 等变了):重新部署。
188
- // syncPlist 走 bootout→落盘→enable→bootstrap,bootstrap 即首发,无需 kickstart。
189
- // 失败回滚与首注册同款(state 恢复 + **片段删除**):syncPlist 内容变化路径
190
- // 先 bootout,失败时 job 已不在册——没有 job 兜底的片段就是假入口;且
191
- // 重写会用改过的新 user 拼旧 v6,既不准确也不诚实。下轮报名自愈
192
- if (existing !== content) {
175
+ // 未注册(首次报名)或已注册但渲染结果与磁盘不符(topology 的 user 等变了):
176
+ // 重新部署。syncPlist 走 bootout→落盘→enable→bootstrap,bootstrap 即首发,
177
+ // 无需 kickstart。部署失败回滚登记:不回滚的话 conf.d/edge-<别名> 是没有
178
+ // job 兜底的假入口(install 的 reconcileEdgeFragments 自己定义的不变式),
179
+ // 只能等下轮报名或人工 install 修。回滚形态:state 恢复旧 v6、**片段删除**
180
+ // (而非重写)——未注册态的片段按 reconcile 不变式本就不该在(休眠/会话
181
+ // 重建时已被 retire 清掉),内容变化路径 syncPlist 先 bootout、失败时 job
182
+ // 已不在册,重写同样造出假入口。下轮报名自愈;回滚失败不遮蔽原始错误
183
+ if (!st.registered || existing !== content) {
193
184
  writeEdgeRegistration(ctx, edge, v6);
194
185
  try {
195
186
  const r = syncPlist(ctx, { label, plistPath, content });
196
187
  if (r.lintError) throw new Error(`uplink-edge plist 校验失败:${r.lintError}`);
197
188
  } catch (err) {
198
- try {
199
- if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
200
- else ctx.state.writeEdgeV6(edge.alias, prevV6);
201
- removeConfFile(ctx.paths.edgeHostFile(edge.alias));
202
- } catch { /* 回滚失败不遮蔽原始错误 */ }
189
+ rollbackRegistration(ctx, edge, prevV6);
203
190
  throw err;
204
191
  }
205
- return `redeployed ${alias}`;
206
- }
207
-
208
- // 休眠中:写 v6 → enable 清 override → kickstart 唤醒(enable 本身不首发)。
209
- // enable 失败不用回滚:disabled 分支排在前面,下轮照走本分支
210
- if (st.disabled) {
211
- writeEdgeRegistration(ctx, edge, v6);
212
- let r = launchd.enable(ctx.runner, ctx.uid, label);
213
- if (r.code !== 0) throw new Error(`enable 失败:${r.stderr.trim()}`);
214
- r = launchd.kickstart(ctx.runner, ctx.uid, label);
215
- if (r.code !== 0) {
216
- try {
217
- rollbackEdgeRegistration(ctx, edge, prevV6);
218
- } catch { /* 回滚失败不遮蔽原始错误 */ }
219
- throw new Error(`kickstart 失败:${r.stderr.trim()}`);
220
- }
221
- return `woken ${alias}`;
192
+ return st.registered ? `redeployed ${alias}` : `registered ${alias}`;
222
193
  }
223
194
 
224
- // enabled(running 且 v6 相同 / v6 变了 / not-running 三种形态合并):
225
- // 报名只会由活 edge 上的真实 ssh 触发,无条件重拨正是人等连接时要的语义,
226
- // 进程重启即六连败计数清零。两处同写先于 kickstart:顺带 reconcile
227
- // conf.d 片段(uplink-edge 六连败休眠删片段与报名存在删/写竞态,缺则补)。
228
- // kickstart 失败回滚 state 到 job 实际在用的 v6:不回滚则磁盘已是新值,
229
- // job 仍拿旧 v6 拨到六连败休眠
195
+ // 休眠中(disable 睡着)或 enabled(running 且 v6 相同 / v6 变了 /
196
+ // not-running 三种形态合并):写 v6 → enable(休眠唤醒要清 override;
197
+ // enabled 幂等无害)→ kickstart。报名只会由活 edge 上的真实 ssh 触发,
198
+ // 无条件重拨正是人等连接时要的语义,进程重启即六连败计数清零。enable
199
+ // 失败不用回滚(disabled 态没变,下轮报名照走本分支)。两处同写先于
200
+ // kickstart:顺带 reconcile conf.d 片段(uplink-edge 六连败休眠删片段与
201
+ // 报名存在删/写竞态,缺则补)。kickstart 失败回滚 state 到 job 实际在用
202
+ // 的 v6:不回滚则磁盘已是新值,job 仍拿旧 v6 拨到六连败休眠
230
203
  writeEdgeRegistration(ctx, edge, v6);
231
204
  const en = launchd.enable(ctx.runner, ctx.uid, label);
232
205
  if (en.code !== 0) throw new Error(`enable 失败:${en.stderr.trim()}`);
@@ -237,5 +210,5 @@ export function runRegister(ctx, args = []) {
237
210
  } catch { /* 回滚失败不遮蔽原始错误 */ }
238
211
  throw new Error(`kickstart 失败:${r.stderr.trim()}`);
239
212
  }
240
- return `kickstarted ${alias}`;
213
+ return st.disabled ? `woken ${alias}` : `kickstarted ${alias}`;
241
214
  }
@@ -9,7 +9,7 @@
9
9
  import fs from 'node:fs';
10
10
  import path from 'node:path';
11
11
  import {
12
- auditScript, auditLink, readRuntimeVersion, runtimeVersionIssue,
12
+ auditScript, auditLink, runtimeVersionIssue,
13
13
  } from '../lib/runtime.mjs';
14
14
  import { packageScriptPath } from '../lib/paths.mjs';
15
15
  import * as launchd from '../lib/launchd.mjs';
@@ -59,12 +59,6 @@ function runtimeIssues(ctx, { entities, serviceLinks }) {
59
59
  return { issues, links };
60
60
  }
61
61
 
62
- /** 版本对账问题(各角色共用);版本值不单列展示,不一致才说话。 */
63
- function versionInfo(ctx) {
64
- const issue = runtimeVersionIssue(ctx.paths);
65
- return { issue, runtimeVersion: readRuntimeVersion(ctx.paths) };
66
- }
67
-
68
62
  /** forward 的人话标签:写出目标(loopback 是落地机环回)。 */
69
63
  function forwardLabel(f) {
70
64
  const target = f.targetAlias === 'loopback'
@@ -73,6 +67,15 @@ function forwardLabel(f) {
73
67
  return `端口转发 127.0.0.1:${f.listenPort} → ${target}`;
74
68
  }
75
69
 
70
+ /** relay 口没在监听时的 issue(core/node 同款文案):不可达与没监听分开报——
71
+ * 把 relay 不可达断言成「没在监听」会把故障点错指向本机转发,排障方向
72
+ * 完全不同。 */
73
+ function relayPortIssue(relayAlias, port, r) {
74
+ return r.reachable === false
75
+ ? `连不上 ${relayAlias}(${r.detail || 'ssh 探测失败'}),入口 ${port} 状态未知——查 ${relayAlias} 可达性或本机网络`
76
+ : `${relayAlias} 入口 ${port} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${relayAlias} 或本机网络)`;
77
+ }
78
+
76
79
  async function relayPortListening(ctx, port) {
77
80
  // relay 别名的 User/HostName 由 ssh config Host 块提供;
78
81
  // BatchMode 防换机器/换钥匙时在终端闪密码提示;IdentitiesOnly 防 agent
@@ -106,7 +109,7 @@ async function relayPathOk(ctx) {
106
109
  async function collectEdge(ctx) {
107
110
  const { topo, paths, state } = ctx;
108
111
  const issues = [];
109
- const { issue: vIssue, runtimeVersion } = versionInfo(ctx);
112
+ const vIssue = runtimeVersionIssue(ctx.paths);
110
113
  if (vIssue) issues.push(vIssue);
111
114
  // link 附加件以 marker 为准:默认只有 5 实体、无服务软链;装了才加
112
115
  // link-core(转发口只取决于装没装,不是运行时开关)
@@ -203,16 +206,16 @@ async function collectEdge(ctx) {
203
206
  : [];
204
207
  return {
205
208
  role: 'edge', alias: ctx.self.alias, switches, relayReady, peerReady,
206
- linkInstalled, job, links, ports, forwardViews,
209
+ linkInstalled, job, ports, forwardViews,
207
210
  coreAlias: topo.core.alias, relayAlias: topo.relay.alias,
208
- v6, v6ProbeOk, runtimeVersion, issues,
211
+ v6, v6ProbeOk, issues,
209
212
  };
210
213
  }
211
214
 
212
215
  async function collectCore(ctx) {
213
216
  const { topo, paths } = ctx;
214
217
  const issues = [];
215
- const { issue: vIssue, runtimeVersion } = versionInfo(ctx);
218
+ const vIssue = runtimeVersionIssue(ctx.paths);
216
219
  if (vIssue) issues.push(vIssue);
217
220
  const { issues: rtIssues } = runtimeIssues(ctx, {
218
221
  entities: [['ssh-net-uplink-relay', 'ssh-net-uplink-relay']],
@@ -275,30 +278,20 @@ async function collectCore(ctx) {
275
278
 
276
279
  const relayPort = await relayPortP;
277
280
  if (!relayJob.running) issues.push('relay 未在运行——ssh-net start 可拉起');
278
- if (!relayPort.listening) {
279
- // 连不上 relay 时入口状态未知,别断言成「没在监听」——那是把故障点
280
- // 指向本机转发,实际更可能是 relay 不可达(排障方向完全不同)
281
- if (relayPort.reachable === false)
282
- issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${topo.core.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
283
- else
284
- issues.push(`${topo.relay.alias} 入口 ${topo.core.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${topo.relay.alias} 或本机网络)`);
285
- }
281
+ if (!relayPort.listening)
282
+ issues.push(relayPortIssue(topo.relay.alias, topo.core.relayPort, relayPort));
286
283
 
287
284
  // topology 已删(edge 改名/退役)但磁盘上还有回拨 job:不渲染成 edges 行
288
285
  //(state/conf.d 都按新别名走),单独点破。残留无害——六连败后自休眠、
289
286
  // 端口争抢由胜者持有且监听功能等价——但不可见会让改名现场少一条线索
290
287
  const knownAliases = new Set(topo.edges.map((e) => e.alias));
291
- try {
292
- for (const f of fs.readdirSync(paths.launchAgentsDir)) {
293
- if (!f.startsWith('local.ssh-net-uplink-edge-') || !f.endsWith('.plist')) continue;
294
- const alias = f.slice('local.ssh-net-uplink-edge-'.length, -'.plist'.length);
295
- if (!knownAliases.has(alias))
296
- issues.push(`${alias} 的回拨 job 还在但 topology 已没有这个 edge(改名/退役残留,无害)——清理:launchctl bootout gui/${ctx.uid}/${f.replace(/\.plist$/, '')} 后删该 plist;或无视(它六连败后会自休眠)`);
297
- }
298
- } catch { /* LaunchAgents 目录不存在(未装) */ }
288
+ for (const alias of launchd.edgeAliasesOnDisk(paths.launchAgentsDir)) {
289
+ if (!knownAliases.has(alias))
290
+ issues.push(`${alias} 的回拨 job 还在但 topology 已没有这个 edge(改名/退役残留,无害)——清理:launchctl bootout gui/${ctx.uid}/${edgeLabel(alias)} 后删该 plist;或无视(它六连败后会自休眠)`);
291
+ }
299
292
 
300
293
  return {
301
- role: 'core', alias: ctx.self.alias, runtimeVersion,
294
+ role: 'core', alias: ctx.self.alias,
302
295
  relayAlias: topo.relay.alias, relayJob, relayPort, edges, issues,
303
296
  };
304
297
  }
@@ -306,7 +299,7 @@ async function collectCore(ctx) {
306
299
  async function collectNode(ctx) {
307
300
  const { topo } = ctx;
308
301
  const issues = [];
309
- const { issue: vIssue, runtimeVersion } = versionInfo(ctx);
302
+ const vIssue = runtimeVersionIssue(ctx.paths);
310
303
  if (vIssue) issues.push(vIssue);
311
304
  const { issues: rtIssues } = runtimeIssues(ctx, {
312
305
  entities: [['ssh-net-uplink-relay', 'ssh-net-uplink-relay']],
@@ -319,16 +312,11 @@ async function collectNode(ctx) {
319
312
  const relayPort = await relayPortListening(ctx, ctx.self.relayPort);
320
313
  if (active !== 'active')
321
314
  issues.push(`系统服务 ${unit} 状态 ${active}——systemctl status ${unit} 查看`);
322
- if (!relayPort.listening) {
323
- // 与 core 侧同款区分:relay 不可达 ≠ 入口没在监听,排障方向不同
324
- if (relayPort.reachable === false)
325
- issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${ctx.self.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
326
- else
327
- issues.push(`${ctx.topo.relay.alias} 入口 ${ctx.self.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${ctx.topo.relay.alias} 或本机网络)`);
328
- }
315
+ if (!relayPort.listening)
316
+ issues.push(relayPortIssue(topo.relay.alias, ctx.self.relayPort, relayPort));
329
317
 
330
318
  return {
331
- role: 'node', alias: ctx.self.alias, runtimeVersion,
319
+ role: 'node', alias: ctx.self.alias,
332
320
  relayAlias: topo.relay.alias, unit, active, relayPort, issues,
333
321
  };
334
322
  }
@@ -439,5 +427,5 @@ export function renderText(s) {
439
427
 
440
428
  export async function run(ctx) {
441
429
  const s = await collect(ctx);
442
- return { text: renderText(s), issues: s.issues, status: s };
430
+ return { text: renderText(s), issues: s.issues };
443
431
  }
@@ -4,6 +4,7 @@
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import { removeJob } from '../lib/manage.mjs';
7
+ import * as launchd from '../lib/launchd.mjs';
7
8
  import * as systemd from '../lib/systemd.mjs';
8
9
  import {
9
10
  linkLabel, plistFileName,
@@ -12,17 +13,6 @@ import {
12
13
 
13
14
  const rm = (p) => fs.rmSync(p, { recursive: true, force: true });
14
15
 
15
- /** 列出磁盘上全部 uplink-edge plist(topology 已删的机器只能靠 glob 发现)。 */
16
- function edgePlistFiles(ctx) {
17
- let files = [];
18
- try {
19
- files = fs
20
- .readdirSync(ctx.paths.launchAgentsDir)
21
- .filter((f) => f.startsWith('local.ssh-net-uplink-edge-') && f.endsWith('.plist'));
22
- } catch { /* 目录不存在 */ }
23
- return files;
24
- }
25
-
26
16
  function uninstallEdge(ctx) {
27
17
  const label = linkLabel(ctx.topo.core.alias);
28
18
  removeJob(ctx, label, path.join(
@@ -41,8 +31,9 @@ function uninstallCore(ctx) {
41
31
  const dir = ctx.paths.launchAgentsDir;
42
32
  // label → plist 路径:磁盘 glob(topology 已删的残留)∪ topology 在册 edge
43
33
  const edgeJobs = new Map();
44
- for (const f of edgePlistFiles(ctx)) {
45
- edgeJobs.set(f.replace(/\.plist$/, ''), path.join(dir, f));
34
+ for (const alias of launchd.edgeAliasesOnDisk(dir)) {
35
+ const label = edgeLabel(alias);
36
+ edgeJobs.set(label, path.join(dir, plistFileName(label)));
46
37
  }
47
38
  for (const e of ctx.topo.edges) {
48
39
  const label = edgeLabel(e.alias);
@@ -4,9 +4,32 @@
4
4
  // - 休眠判据只用 print-disabled 字典(print 正文无稳定字段)
5
5
  // - 任何 bootstrap 前无条件先 enable(override 残留时 bootstrap error 5)
6
6
  // - enable 本身不触发首发,唤醒必须 kickstart -k
7
+ import fs from 'node:fs';
8
+ import { edgeLabel } from './render.mjs';
9
+
7
10
  /** @param {number} uid */
8
11
  export const guiDomain = (uid) => `gui/${uid}`;
9
12
 
13
+ const EDGE_PLIST_PREFIX = edgeLabel(''); // 'local.ssh-net-uplink-edge-'
14
+
15
+ /**
16
+ * 磁盘 LaunchAgents 里 uplink-edge job plist 的别名清单(install/status/
17
+ * uninstall 共用;topology 已删的机器只能靠这个 glob 兜底发现,目录不存在
18
+ * 时空)。
19
+ * @param {string} launchAgentsDir
20
+ * @returns {string[]}
21
+ */
22
+ export function edgeAliasesOnDisk(launchAgentsDir) {
23
+ try {
24
+ return fs
25
+ .readdirSync(launchAgentsDir)
26
+ .filter((f) => f.startsWith(EDGE_PLIST_PREFIX) && f.endsWith('.plist'))
27
+ .map((f) => f.slice(EDGE_PLIST_PREFIX.length, -'.plist'.length));
28
+ } catch {
29
+ return [];
30
+ }
31
+ }
32
+
10
33
  /**
11
34
  * print 正文解析。
12
35
  * @param {{code:number|null, stderr:string, stdout:string}} result
@@ -11,8 +11,7 @@
11
11
  // state/ 易变状态(两开关、edges v6、PROBE_FAIL、ENSURE)
12
12
  // link.enabled link 附加件的持久安装意图(树根,不放 state/)
13
13
  // conf.d/ 渲染给 ssh Include 的配置片段(生成物,不进 dotfiles):
14
- // routes edge:Match 选路块(install 渲染)
15
- // vscode-mark edge:VS Code 连接打标块(install 渲染常量)
14
+ // routes edge:Match 选路块 + 尾部 VS Code 打标块(install 渲染)
16
15
  // edge-<别名> core:edge 在线入口(_register 写/休眠删)
17
16
  // ~/.ssh/config dotfiles 托管,顶部 Include conf.d/* + 静态主机块(IP 唯一来源)
18
17
  import path from 'node:path';
@@ -45,7 +44,6 @@ export function machinePaths(env = process.env) {
45
44
  const sshNetDir = path.join(home, '.ssh', 'ssh-net');
46
45
  const stateDir = path.join(sshNetDir, 'state');
47
46
  return Object.freeze({
48
- home,
49
47
  sshDir: path.join(home, '.ssh'),
50
48
  sshConfigFile: path.join(home, '.ssh', 'config'),
51
49
  sshNetDir,
@@ -53,9 +51,9 @@ export function machinePaths(env = process.env) {
53
51
  binDir: path.join(sshNetDir, 'bin'),
54
52
  runtimeVersionFile: path.join(sshNetDir, 'runtime-version'),
55
53
  stateDir,
56
- // ssh Include 片段目录(design §4.2,2026-10-01):routes、vscode-mark
57
- // 仅 edge install 写;edge-<别名> 仅 core _register/休眠写删;node 不建。
58
- // Include glob 零匹配静默,主 config 五台可同份
54
+ // ssh Include 片段目录(design §4.2,2026-10-01):routes 仅 edge install
55
+ // 写(含尾部 VS Code 打标块);edge-<别名> 仅 core _register/休眠写删;
56
+ // node 不建。Include glob 零匹配静默,主 config 五台可同份
59
57
  confDir: path.join(sshNetDir, 'conf.d'),
60
58
  routesFile: path.join(sshNetDir, 'conf.d', 'routes'),
61
59
  /** @param {string} alias edge 别名 */
@@ -1,7 +1,7 @@
1
1
  // 渲染唯一来源(design §2.3、§4.2、§6.1、§6.2):
2
2
  // - plist/systemd unit:每机差异只以位置参数出现(端口、别名、user、转发列表)
3
- // - conf.d 片段:routes(edge 选路 Match)、vscode-mark(edge 上 VS Code 连接打标)
4
- // 与 edge-<别名>(core 上的 edge 入口)
3
+ // - conf.d 片段:routes(edge 选路 Match + 尾部 VS Code 打标块)与
4
+ // edge-<别名>(core 上的 edge 入口)
5
5
  // 纯字符串函数;渲染快照测试钉死输出;结构性断言(XML 闭合、只绑环回)在测试侧另查。
6
6
  import { CALLBACK_PORT } from './constants.mjs';
7
7
 
@@ -13,7 +13,6 @@
13
13
  /**
14
14
  * @typedef {Object} StaticHost
15
15
  * @property {string} [hostname] HostName;缺省时 ssh 以别名为地址
16
- * @property {string} [user] User
17
16
  */
18
17
 
19
18
  const GLOB_CHARS = new Set(['*', '?', '!']);
@@ -35,10 +34,6 @@ export function parseStaticHosts(text) {
35
34
  let currentPatterns = [];
36
35
  let inMatch = false;
37
36
 
38
- const putFirst = (host, key, value) => {
39
- if (host[key] === undefined) host[key] = value;
40
- };
41
-
42
37
  for (const raw of text.split('\n')) {
43
38
  const line = raw.trim();
44
39
  if (line.length === 0 || line.startsWith('#')) continue;
@@ -53,7 +48,7 @@ export function parseStaticHosts(text) {
53
48
  if (keyword === 'host') {
54
49
  inMatch = false;
55
50
  // 精确模式入表(多模式逐个);同一别名多个 Host 块时 ssh 取首次值——
56
- // 已存在的记录对象继续沿用,putFirst 保证不被后块覆盖
51
+ // 已存在的记录对象继续沿用,首次值写入不被后块覆盖
57
52
  currentPatterns = cols.slice(1).filter(isExactPattern);
58
53
  for (const p of currentPatterns) {
59
54
  if (!table.has(p)) table.set(p, {});
@@ -61,11 +56,13 @@ export function parseStaticHosts(text) {
61
56
  continue;
62
57
  }
63
58
  if (inMatch || currentPatterns.length === 0) continue;
64
- if (keyword === 'hostname' || keyword === 'user') {
59
+ if (keyword === 'hostname') {
65
60
  const value = cols.slice(1).join(' ');
66
61
  if (value) {
67
- for (const p of currentPatterns)
68
- putFirst(table.get(p), keyword === 'hostname' ? 'hostname' : 'user', value);
62
+ for (const p of currentPatterns) {
63
+ const host = table.get(p);
64
+ if (host.hostname === undefined) host.hostname = value;
65
+ }
69
66
  }
70
67
  }
71
68
  }
@@ -18,7 +18,6 @@ const SWITCH_NAMES = ['relay', 'peer'];
18
18
  * @property {(alias: string) => string | null} readEdgeV6
19
19
  * @property {(alias: string, v6: string) => void} writeEdgeV6
20
20
  * @property {(alias: string) => void} removeEdgeV6 不存在时静默
21
- * @property {() => void} removeAllEdges
22
21
  */
23
22
 
24
23
  /**
@@ -104,9 +103,5 @@ export function createStateStore({ stateDir, switchFiles, edgesDir }) {
104
103
  throw err;
105
104
  }
106
105
  },
107
-
108
- removeAllEdges() {
109
- fs.rmSync(edgesDir, { recursive: true, force: true });
110
- },
111
106
  };
112
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-net",
3
- "version": "26.10.33",
3
+ "version": "26.10.34",
4
4
  "type": "module",
5
5
  "description": "个人 SSH 组网:v6 直连优先、relay 兜底、关机有界重试后静默",
6
6
  "bin": {