@stevezhou/sisu 0.3.17 → 0.3.19
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/README.md +1 -1
- package/dist/main.js +30 -13
- package/dist/tui.js +5 -3
- package/dist/update.js +94 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Postinstall also puts `sisu` on a PATH users actually have: `~/.local/bin` on Un
|
|
|
40
40
|
|
|
41
41
|
`npx sisu` works without a global install.
|
|
42
42
|
|
|
43
|
-
`sisu update`
|
|
43
|
+
`sisu update` upgrades the CLI to the latest npm release (same prefix as this install) and lets postinstall fetch that version's pager. If you are already on latest, it force-reinstalls the pager. It is not a grok-style background auto-updater.
|
|
44
44
|
|
|
45
45
|
## Login
|
|
46
46
|
|
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.helpText = helpText;
|
|
5
|
+
exports.pagerResumeArgs = pagerResumeArgs;
|
|
5
6
|
exports.runCli = runCli;
|
|
6
7
|
const module_1 = require("module");
|
|
7
8
|
const commands_1 = require("./commands");
|
|
@@ -10,6 +11,7 @@ const client_1 = require("./client");
|
|
|
10
11
|
const logo_1 = require("./logo");
|
|
11
12
|
const store_1 = require("./store");
|
|
12
13
|
const tui_1 = require("./tui");
|
|
14
|
+
const update_1 = require("./update");
|
|
13
15
|
const req = (0, module_1.createRequire)(__filename);
|
|
14
16
|
function defaultInstallPager(options) {
|
|
15
17
|
const { installPager } = req('../scripts/install-pager.js');
|
|
@@ -30,7 +32,7 @@ Usage:
|
|
|
30
32
|
sisu login --token <jwt> [--api <url>]
|
|
31
33
|
sisu logout
|
|
32
34
|
sisu status
|
|
33
|
-
sisu update
|
|
35
|
+
sisu update upgrade CLI to latest and reinstall the pager
|
|
34
36
|
sisu open <dir> --project <project-id>
|
|
35
37
|
sisu ls [--project <project-id>]
|
|
36
38
|
sisu exec "<prompt>" [--project <id>] [--model <name>] [--new] [--stub]
|
|
@@ -41,6 +43,7 @@ Usage:
|
|
|
41
43
|
sisu thread <conversation-id>
|
|
42
44
|
sisu training --on|--off
|
|
43
45
|
sisu interactive TUI (思溯 / SiSu · 思有所溯)
|
|
46
|
+
sisu --resume <id> reopen a local pager session
|
|
44
47
|
sisu --version
|
|
45
48
|
sisu help
|
|
46
49
|
|
|
@@ -57,6 +60,19 @@ function flag(args, name) {
|
|
|
57
60
|
return undefined;
|
|
58
61
|
return args[index + 1];
|
|
59
62
|
}
|
|
63
|
+
function pagerResumeArgs(argv) {
|
|
64
|
+
const [command, ...args] = argv;
|
|
65
|
+
if (command === '--resume') {
|
|
66
|
+
return args[0] && !args[0].startsWith('-') ? ['--resume', args[0]] : ['--resume'];
|
|
67
|
+
}
|
|
68
|
+
if (command && command !== 'tui')
|
|
69
|
+
return [];
|
|
70
|
+
const index = args.indexOf('--resume');
|
|
71
|
+
if (index === -1)
|
|
72
|
+
return [];
|
|
73
|
+
const id = args[index + 1];
|
|
74
|
+
return id && !id.startsWith('-') ? ['--resume', id] : ['--resume'];
|
|
75
|
+
}
|
|
60
76
|
function parseArgs(args) {
|
|
61
77
|
const flags = {};
|
|
62
78
|
const rest = [];
|
|
@@ -87,20 +103,21 @@ async function runCli(argv, deps = {}) {
|
|
|
87
103
|
process.stdout.write(`sisu ${client_1.SISU_CLIENT_VERSION} — ${logo_1.SISU_BRAND.zh} ${logo_1.SISU_BRAND.en} · ${logo_1.SISU_BRAND.headline}\n`);
|
|
88
104
|
return 0;
|
|
89
105
|
}
|
|
90
|
-
if (!command || command === 'tui') {
|
|
91
|
-
return (0, tui_1.runTui)((0, tui_1.defaultTuiIo)());
|
|
106
|
+
if (!command || command === 'tui' || command === '--resume') {
|
|
107
|
+
return (0, tui_1.runTui)((0, tui_1.defaultTuiIo)(), { pagerArgs: pagerResumeArgs(argv) });
|
|
92
108
|
}
|
|
93
109
|
if (command === 'update') {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
return (0, update_1.runUpdate)({
|
|
111
|
+
fetchLatest: deps.fetchLatest ?? (() => (0, update_1.fetchLatestVersion)(http)),
|
|
112
|
+
installPackage: deps.installPackage ?? ((version) => (0, update_1.installNpmPackage)(version)),
|
|
113
|
+
installPager: deps.installPager ?? defaultInstallPager,
|
|
114
|
+
write: (text) => {
|
|
115
|
+
process.stdout.write(text);
|
|
116
|
+
},
|
|
117
|
+
writeErr: (text) => {
|
|
118
|
+
process.stderr.write(text);
|
|
119
|
+
},
|
|
120
|
+
});
|
|
104
121
|
}
|
|
105
122
|
if (command === 'status') {
|
|
106
123
|
process.stdout.write(`${await (0, commands_1.statusCommand)(http_1.defaultHttp)}\n`);
|
package/dist/tui.js
CHANGED
|
@@ -264,8 +264,10 @@ async function runTui(io, deps = {}) {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
if (usePager && (deps.spawnGrokPager || !deps.pager)) {
|
|
267
|
-
const
|
|
268
|
-
|
|
267
|
+
const pagerArgs = deps.pagerArgs ?? [];
|
|
268
|
+
const spawnOnce = (deps.spawnGrokPager
|
|
269
|
+
? () => deps.spawnGrokPager(pagerArgs)
|
|
270
|
+
: () => {
|
|
269
271
|
const grokBin = (0, launch_1.findGrokBuildBinary)();
|
|
270
272
|
if (!grokBin || !process.stdout.isTTY) {
|
|
271
273
|
return Promise.resolve(null);
|
|
@@ -291,7 +293,7 @@ async function runTui(io, deps = {}) {
|
|
|
291
293
|
return (0, transcriptEvents_1.postTranscriptEvent)(http, current.api_base || store_1.DEFAULT_API_BASE, current.token, event);
|
|
292
294
|
},
|
|
293
295
|
});
|
|
294
|
-
const child = (0, child_process_1.spawn)(grokBin,
|
|
296
|
+
const child = (0, child_process_1.spawn)(grokBin, pagerArgs, {
|
|
295
297
|
stdio: 'inherit',
|
|
296
298
|
env,
|
|
297
299
|
cwd: process.cwd(),
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.planUpdate = planUpdate;
|
|
7
|
+
exports.npmGlobalPrefix = npmGlobalPrefix;
|
|
8
|
+
exports.npmCliPath = npmCliPath;
|
|
9
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
10
|
+
exports.installNpmPackage = installNpmPackage;
|
|
11
|
+
exports.runUpdate = runUpdate;
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const client_1 = require("./client");
|
|
16
|
+
const http_1 = require("./http");
|
|
17
|
+
const launch_1 = require("./runtime/launch");
|
|
18
|
+
const store_1 = require("./store");
|
|
19
|
+
function planUpdate(current, latest) {
|
|
20
|
+
if (latest && (0, launch_1.comparePagerStamp)(latest, current) > 0) {
|
|
21
|
+
return { action: 'upgrade', from: current, to: latest };
|
|
22
|
+
}
|
|
23
|
+
return { action: 'pager', version: current };
|
|
24
|
+
}
|
|
25
|
+
function npmGlobalPrefix(packageRoot = path_1.default.join(__dirname, '..')) {
|
|
26
|
+
const resolved = path_1.default.resolve(packageRoot);
|
|
27
|
+
const needle = `${path_1.default.sep}node_modules${path_1.default.sep}`;
|
|
28
|
+
const idx = resolved.lastIndexOf(needle);
|
|
29
|
+
if (idx <= 0)
|
|
30
|
+
return '';
|
|
31
|
+
const before = resolved.slice(0, idx);
|
|
32
|
+
if (path_1.default.basename(before) === 'lib')
|
|
33
|
+
return path_1.default.dirname(before);
|
|
34
|
+
return before;
|
|
35
|
+
}
|
|
36
|
+
function npmCliPath(home = (0, store_1.getSisuHome)()) {
|
|
37
|
+
const unix = path_1.default.join(home, 'node', 'bin', 'npm');
|
|
38
|
+
const win = path_1.default.join(home, 'node', 'npm.cmd');
|
|
39
|
+
if (fs_1.default.existsSync(unix))
|
|
40
|
+
return unix;
|
|
41
|
+
if (fs_1.default.existsSync(win))
|
|
42
|
+
return win;
|
|
43
|
+
return process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
44
|
+
}
|
|
45
|
+
async function fetchLatestVersion(http = http_1.defaultHttp) {
|
|
46
|
+
const response = await http('https://registry.npmjs.org/@stevezhou/sisu/latest', {
|
|
47
|
+
headers: { Accept: 'application/json' },
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok)
|
|
50
|
+
throw new Error(`npm registry ${response.status}`);
|
|
51
|
+
const body = (await response.json());
|
|
52
|
+
const version = String(body.version || '').trim();
|
|
53
|
+
if (!version)
|
|
54
|
+
throw new Error('npm registry missing version');
|
|
55
|
+
return version;
|
|
56
|
+
}
|
|
57
|
+
function installNpmPackage(version, options = {}) {
|
|
58
|
+
const npm = options.npm || npmCliPath();
|
|
59
|
+
const prefix = options.prefix === undefined ? npmGlobalPrefix() : options.prefix;
|
|
60
|
+
const args = ['install', '-g', `@stevezhou/sisu@${version}`];
|
|
61
|
+
if (prefix)
|
|
62
|
+
args.push('--prefix', prefix);
|
|
63
|
+
const result = (options.spawn || child_process_1.spawnSync)(npm, args, { stdio: 'inherit' });
|
|
64
|
+
if ((result.status ?? 1) !== 0) {
|
|
65
|
+
throw new Error(`npm install failed (${result.status ?? 'spawn'})`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function runUpdate(options) {
|
|
69
|
+
const current = options.currentVersion || client_1.SISU_CLIENT_VERSION;
|
|
70
|
+
const writeErr = options.writeErr || options.write;
|
|
71
|
+
let latest = null;
|
|
72
|
+
try {
|
|
73
|
+
latest = await options.fetchLatest();
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
options.write(`sisu update: could not check npm (${error instanceof Error ? error.message : String(error)}); reinstalling pager\n`);
|
|
77
|
+
}
|
|
78
|
+
const plan = planUpdate(current, latest);
|
|
79
|
+
if (plan.action === 'upgrade') {
|
|
80
|
+
options.write(`sisu: cli ${plan.from} -> ${plan.to}\n`);
|
|
81
|
+
await options.installPackage(plan.to);
|
|
82
|
+
options.write(`sisu: cli ${plan.to} installed (pager via postinstall). restart sisu.\n`);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
const result = await options.installPager({ force: true });
|
|
86
|
+
if (result.ok) {
|
|
87
|
+
options.write(result.skipped
|
|
88
|
+
? `pager already current${result.dest ? ` at ${result.dest}` : ''}\n`
|
|
89
|
+
: `installed pager${result.dest ? ` to ${result.dest}` : ''}\n`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
writeErr(`sisu update: ${result.reason || 'pager install failed'}\n`);
|
|
93
|
+
return result.skipped ? 0 : 1;
|
|
94
|
+
}
|