shennian 0.2.14 → 0.2.16
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/dist/bin/shennian.js
CHANGED
|
File without changes
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
import { execSync, spawn } from 'node:child_process';
|
|
1
2
|
import type { Command } from 'commander';
|
|
2
3
|
import type { CliRelayClient } from '../relay/client.js';
|
|
4
|
+
type RestartAfterUpgradeDeps = {
|
|
5
|
+
platform?: NodeJS.Platform;
|
|
6
|
+
kill?: typeof process.kill;
|
|
7
|
+
pid?: number;
|
|
8
|
+
spawn?: typeof spawn;
|
|
9
|
+
execSync?: typeof execSync;
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
};
|
|
12
|
+
export declare function restartCurrentDaemonAfterUpgrade(deps?: RestartAfterUpgradeDeps): void;
|
|
3
13
|
export declare function registerUpgradeCommand(program: Command): void;
|
|
4
14
|
export declare function handleUpgradeStart(client: CliRelayClient, reqId: string, targetVersion?: string): Promise<void>;
|
|
5
15
|
export declare function handleUpgradeStatus(client: CliRelayClient, reqId: string): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
// @arch docs/architecture/cli/upgrade.md
|
|
2
|
+
// @test packages/cli/src/__tests__/upgrade-command.test.ts
|
|
2
3
|
import chalk from 'chalk';
|
|
4
|
+
import { execSync, spawn } from 'node:child_process';
|
|
5
|
+
import os from 'node:os';
|
|
3
6
|
import { getCurrentVersion, fetchLatestVersion, compareVersions, performUpgrade, checkForUpdate, } from '../upgrade/engine.js';
|
|
4
7
|
const SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
8
|
+
export function restartCurrentDaemonAfterUpgrade(deps = {}) {
|
|
9
|
+
const platform = deps.platform ?? os.platform();
|
|
10
|
+
const kill = deps.kill ?? process.kill;
|
|
11
|
+
const currentPid = deps.pid ?? process.pid;
|
|
12
|
+
const env = deps.env ?? process.env;
|
|
13
|
+
const spawnFn = deps.spawn ?? spawn;
|
|
14
|
+
const execSyncFn = deps.execSync ?? execSync;
|
|
15
|
+
if (platform === 'win32') {
|
|
16
|
+
const command = env.ComSpec || 'cmd.exe';
|
|
17
|
+
const delayedStart = [
|
|
18
|
+
'timeout /t 2 /nobreak >nul',
|
|
19
|
+
'wscript "%USERPROFILE%\\.shennian\\autostart.vbs"',
|
|
20
|
+
].join(' & ');
|
|
21
|
+
try {
|
|
22
|
+
const child = spawnFn(command, ['/d', '/s', '/c', `"${delayedStart}"`], {
|
|
23
|
+
detached: true,
|
|
24
|
+
stdio: 'ignore',
|
|
25
|
+
windowsHide: true,
|
|
26
|
+
});
|
|
27
|
+
child.unref();
|
|
28
|
+
kill(currentPid, 'SIGTERM');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
try {
|
|
33
|
+
execSyncFn('schtasks /run /tn "ShennianAgent"', { stdio: 'pipe' });
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Fall through to process exit; manual start/status still works.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
try {
|
|
42
|
+
const child = spawnFn('sh', ['-c', 'sleep 2; shennian start >/dev/null 2>&1'], {
|
|
43
|
+
detached: true,
|
|
44
|
+
stdio: 'ignore',
|
|
45
|
+
env,
|
|
46
|
+
});
|
|
47
|
+
child.unref();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// launchd/systemd may still restart this process; otherwise manual start/status still works.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
kill(currentPid, 'SIGTERM');
|
|
54
|
+
}
|
|
5
55
|
// ─── Interactive CLI upgrade command ─────────────────────────────────────────
|
|
6
56
|
export function registerUpgradeCommand(program) {
|
|
7
57
|
program
|
|
@@ -67,8 +117,7 @@ export function registerUpgradeCommand(program) {
|
|
|
67
117
|
console.log();
|
|
68
118
|
console.log(chalk.green(`✓ Upgraded ${result.from} → ${result.to}`));
|
|
69
119
|
console.log(chalk.gray(' Daemon is restarting...'));
|
|
70
|
-
|
|
71
|
-
process.kill(process.pid, 'SIGTERM');
|
|
120
|
+
restartCurrentDaemonAfterUpgrade();
|
|
72
121
|
}
|
|
73
122
|
else {
|
|
74
123
|
console.log();
|
|
@@ -122,7 +171,7 @@ export async function handleUpgradeStart(client, reqId, targetVersion) {
|
|
|
122
171
|
sendEvent({ state: 'restarting', machineId: 'self', from: result.from, to: result.to });
|
|
123
172
|
// Brief delay so the event is flushed before we exit
|
|
124
173
|
await new Promise((r) => setTimeout(r, 500));
|
|
125
|
-
|
|
174
|
+
restartCurrentDaemonAfterUpgrade();
|
|
126
175
|
}
|
|
127
176
|
else {
|
|
128
177
|
sendEvent({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shennian",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "Shennian — AI Agent Mobile Console CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -32,14 +32,20 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=18"
|
|
34
34
|
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"build:publish": "node -e \"const fs=require('node:fs'); fs.rmSync('dist', { recursive: true, force: true }); fs.rmSync('.tsbuildinfo.publish', { force: true })\" && tsc -p tsconfig.publish.json",
|
|
38
|
+
"dev": "tsc --watch",
|
|
39
|
+
"prepublishOnly": "pnpm build:publish"
|
|
40
|
+
},
|
|
35
41
|
"dependencies": {
|
|
36
42
|
"@mariozechner/pi-agent-core": "^0.64.0",
|
|
37
43
|
"@sinclair/typebox": "^0.34.49",
|
|
44
|
+
"@shennian/wire": "^0.1.2",
|
|
38
45
|
"chalk": "^5.4.1",
|
|
39
46
|
"commander": "^13.1.0",
|
|
40
47
|
"qrcode-terminal": "^0.12.0",
|
|
41
|
-
"ws": "^8.18.1"
|
|
42
|
-
"@shennian/wire": "0.1.2"
|
|
48
|
+
"ws": "^8.18.1"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
51
|
"@types/node": "^20",
|
|
@@ -47,10 +53,5 @@
|
|
|
47
53
|
"@types/ws": "^8.18.1",
|
|
48
54
|
"tsx": "^4.19.4",
|
|
49
55
|
"typescript": "^5.9.3"
|
|
50
|
-
},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"build": "tsc",
|
|
53
|
-
"build:publish": "node -e \"const fs=require('node:fs'); fs.rmSync('dist', { recursive: true, force: true }); fs.rmSync('.tsbuildinfo.publish', { force: true })\" && tsc -p tsconfig.publish.json",
|
|
54
|
-
"dev": "tsc --watch"
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
|
+
}
|