@seamnet/client 0.16.0 → 0.16.2
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/lib/guardian.js +17 -7
- package/lib/upgrade-all.js +28 -27
- package/package.json +1 -1
package/lib/guardian.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync, openSync, readlinkSync } from 'node:fs';
|
|
15
|
-
import { join, isAbsolute } from 'node:path';
|
|
15
|
+
import { join, isAbsolute, dirname } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
16
17
|
import { execSync, spawn } from 'node:child_process';
|
|
17
18
|
import { SEAM_DIR, CREDENTIALS_PATH, SOCKET_PATH, LOGS_DIR, PID_PATH } from './paths.js';
|
|
18
19
|
import { writeEntry as registryWrite, removeEntry as registryRemove } from './registry.js';
|
|
@@ -89,17 +90,26 @@ export async function guardianStart() {
|
|
|
89
90
|
const socketPath = resolveTmuxSocketPath();
|
|
90
91
|
const tmux = tmuxCmd(socketPath);
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
// SEAM_CC_SESSION env 优先:upgrade-all / 跨 shell 启动时,调用方知道目标 AI
|
|
94
|
+
// 的 tmux session,直接传过来;不传才回退到 `tmux display-message`(取 attached
|
|
95
|
+
// client 的 session)。回退在跨 shell 场景下会拿错 session——比如缝在自己的 tmux
|
|
96
|
+
// 里跑 `cd /home/claude_code/du && seam-client upgrade`,会把"缝"写进渡的 registry。
|
|
97
|
+
let ccSession = process.env.SEAM_CC_SESSION || '';
|
|
98
|
+
if (!ccSession) {
|
|
99
|
+
try {
|
|
100
|
+
ccSession = execSync(`${tmux} display-message -p '#S'`, { encoding: 'utf8' }).trim();
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
96
103
|
|
|
97
104
|
const cwd = process.cwd();
|
|
98
|
-
|
|
105
|
+
// guardian-run 进程从 guardian.js 自己所属的包启动(lib/guardian.js → ../bin/cli.js)。
|
|
106
|
+
// 不再相对 cwd 找 node_modules——那样既不支持全局安装(host-tool 模式),
|
|
107
|
+
// cwd 不是项目根时还会崩。模块自解析保证 spawn 出的 guardian 跟当前代码同版本。
|
|
108
|
+
const selfCli = join(dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'cli.js');
|
|
99
109
|
const logPath = join(LOGS_DIR, 'guardian.log');
|
|
100
110
|
const logFd = openSync(logPath, 'a');
|
|
101
111
|
|
|
102
|
-
const child = spawn(process.execPath, [
|
|
112
|
+
const child = spawn(process.execPath, [selfCli, 'guardian', 'run'], {
|
|
103
113
|
cwd,
|
|
104
114
|
detached: true,
|
|
105
115
|
stdio: ['ignore', logFd, logFd],
|
package/lib/upgrade-all.js
CHANGED
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 流程:
|
|
5
5
|
* 1. 全局升 npm 包(仅一次)
|
|
6
|
-
* 2. 读 ~/.seam-
|
|
7
|
-
* 3. 每个
|
|
8
|
-
*
|
|
6
|
+
* 2. 读 ~/.shared/seam-registry/*.json(当前在跑的 guardian 列表)
|
|
7
|
+
* 3. 每个 entry spawn 子进程 stop → start guardian
|
|
8
|
+
* (SEAM_HOME / SEAM_CC_SESSION / SEAM_CC_SOCKET 从 entry 取,
|
|
9
|
+
* 避免 guardianStart 回退到 `tmux display-message` 抓错 attached client。)
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* 仅升级"当前在跑的 guardian"——目录还在但 guardian 没开的,跳过。
|
|
12
|
+
* 想拉那些上来,下次自己 `seam-client guardian start` 即可,
|
|
13
|
+
* 那时已是新版 npm 包。
|
|
14
|
+
*
|
|
15
|
+
* 路人 CC(没装 seam-client / 没 register)天然不在 registry,不会被碰。
|
|
11
16
|
*/
|
|
12
17
|
|
|
13
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
18
|
import { join, dirname } from 'node:path';
|
|
15
|
-
import { homedir } from 'node:os';
|
|
16
19
|
import { execSync, spawnSync } from 'node:child_process';
|
|
17
20
|
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { readAll } from './registry.js';
|
|
18
22
|
|
|
19
23
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
24
|
const CLI_PATH = join(dirname(__filename), '..', 'bin', 'cli.js');
|
|
@@ -30,38 +34,35 @@ export async function upgradeAll() {
|
|
|
30
34
|
process.exit(1);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
console.log('\n2.
|
|
37
|
+
const entries = readAll();
|
|
38
|
+
if (entries.length === 0) {
|
|
39
|
+
console.log('\n2. registry 为空——没有正在运行的 guardian,结束。');
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
|
-
|
|
39
|
-
console.log(`\n2. ${lines.length} 个已注册 SEAM_HOME,逐个重启 guardian`);
|
|
42
|
+
console.log(`\n2. registry 里 ${entries.length} 个活 guardian,逐个重启`);
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
for (const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
let okCount = 0;
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const { userId, seam_home, tmux_session, tmux_socket } = entry;
|
|
47
|
+
console.log(`\n → ${userId} (home=${seam_home}, session=${tmux_session || '?'})`);
|
|
48
|
+
|
|
49
|
+
const env = {
|
|
50
|
+
...process.env,
|
|
51
|
+
SEAM_HOME: seam_home,
|
|
52
|
+
SEAM_CC_SESSION: tmux_session || '',
|
|
53
|
+
SEAM_CC_SOCKET: tmux_socket || '',
|
|
54
|
+
};
|
|
49
55
|
const stopRes = spawnSync('node', [CLI_PATH, 'stop'], { env, stdio: 'inherit' });
|
|
50
56
|
if (stopRes.status !== 0) {
|
|
51
|
-
console.log(' stop
|
|
57
|
+
console.log(' stop 非零退出(继续)');
|
|
52
58
|
}
|
|
53
59
|
const startRes = spawnSync('node', [CLI_PATH, 'guardian', 'start'], { env, stdio: 'inherit' });
|
|
54
60
|
if (startRes.status !== 0) {
|
|
55
61
|
console.error(` start 失败 (exit ${startRes.status})`);
|
|
56
62
|
} else {
|
|
57
|
-
|
|
63
|
+
okCount += 1;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
writeFileSync(homesPath, alive.length ? alive.join('\n') + '\n' : '');
|
|
63
|
-
console.log(`\n registry 清理:${lines.length} → ${alive.length}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`\nDone. ${alive.length} 个 AI guardian 已重启。`);
|
|
67
|
+
console.log(`\nDone. ${okCount}/${entries.length} 个 guardian 已重启。`);
|
|
67
68
|
}
|