@super-coding/cli 0.2.0 → 0.2.1

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.
@@ -0,0 +1,21 @@
1
+ // 默认设备名:优先本机「电脑名称」,取不到回退 hostname。
2
+ // macOS 上 hostname 常被 DHCP/mDNS 改写(如 192-168-x-x.*、MacBook-Pro.local),
3
+ // 用户在「系统设置 → 通用 → 关于」里看到的名字是 ComputerName(scutil --get ComputerName)。
4
+ import { execFileSync } from "node:child_process";
5
+ import { hostname } from "node:os";
6
+ const defaultExec = (cmd, args) => execFileSync(cmd, args, { timeout: 2_000, encoding: "utf8" });
7
+ /** 本机默认设备名:darwin 取 ComputerName,其余平台取 hostname;都为空时给固定兜底 */
8
+ export function localMachineName(opts = {}) {
9
+ const platform = opts.platform ?? process.platform;
10
+ if (platform === "darwin") {
11
+ try {
12
+ const name = (opts.exec ?? defaultExec)("scutil", ["--get", "ComputerName"]).trim();
13
+ if (name)
14
+ return name;
15
+ }
16
+ catch {
17
+ // scutil 不可用/超时:回退 hostname
18
+ }
19
+ }
20
+ return (opts.hostnameFn ?? hostname)().trim() || "unknown-device";
21
+ }
@@ -1,6 +1,6 @@
1
1
  import { randomInt } from "node:crypto";
2
- import { hostname } from "node:os";
3
2
  import { saveDevice } from "./device-store.js";
3
+ import { localMachineName } from "./machine-name.js";
4
4
  /** 字母表去除易混淆字符(0/O、1/I/L) */
5
5
  const ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
6
6
  const CODE_LENGTH = 6;
@@ -28,7 +28,7 @@ const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
28
28
  * 超时抛出 PairingTimeoutError(exitCode = 2)。
29
29
  */
30
30
  export async function runPairing(serverUrl, opts = {}) {
31
- const { fetchImpl = fetch, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, timeoutMs = DEFAULT_TIMEOUT_MS, machine_name = hostname(), sleep = defaultSleep, log = console.log, configDir, } = opts;
31
+ const { fetchImpl = fetch, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, timeoutMs = DEFAULT_TIMEOUT_MS, machine_name = localMachineName(), sleep = defaultSleep, log = console.log, configDir, } = opts;
32
32
  const base = serverUrl.replace(/\/+$/, "");
33
33
  const code = generateCode();
34
34
  // register:remote 重启窗口的瞬时 5xx/网络错误重试,不因一次抖动杀死 daemon
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-coding/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Super Coding CLI:把本机 Claude Code / Cursor 接入远程控制台(scode 命令与后台 daemon)",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",