@stevezhou/sisu 0.3.18 → 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 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` reinstalls that stamped pager for the installed CLI version. It is not a grok-style background auto-updater.
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
@@ -11,6 +11,7 @@ const client_1 = require("./client");
11
11
  const logo_1 = require("./logo");
12
12
  const store_1 = require("./store");
13
13
  const tui_1 = require("./tui");
14
+ const update_1 = require("./update");
14
15
  const req = (0, module_1.createRequire)(__filename);
15
16
  function defaultInstallPager(options) {
16
17
  const { installPager } = req('../scripts/install-pager.js');
@@ -31,7 +32,7 @@ Usage:
31
32
  sisu login --token <jwt> [--api <url>]
32
33
  sisu logout
33
34
  sisu status
34
- sisu update reinstall the stamped local pager for this CLI version
35
+ sisu update upgrade CLI to latest and reinstall the pager
35
36
  sisu open <dir> --project <project-id>
36
37
  sisu ls [--project <project-id>]
37
38
  sisu exec "<prompt>" [--project <id>] [--model <name>] [--new] [--stub]
@@ -106,16 +107,17 @@ async function runCli(argv, deps = {}) {
106
107
  return (0, tui_1.runTui)((0, tui_1.defaultTuiIo)(), { pagerArgs: pagerResumeArgs(argv) });
107
108
  }
108
109
  if (command === 'update') {
109
- const install = deps.installPager ?? defaultInstallPager;
110
- const result = await install({ force: true });
111
- if (result.ok) {
112
- process.stdout.write(result.skipped
113
- ? `pager already current${result.dest ? ` at ${result.dest}` : ''}\n`
114
- : `installed pager${result.dest ? ` to ${result.dest}` : ''}\n`);
115
- return 0;
116
- }
117
- process.stderr.write(`sisu update: ${result.reason || 'pager install failed'}\n`);
118
- return result.skipped ? 0 : 1;
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
+ });
119
121
  }
120
122
  if (command === 'status') {
121
123
  process.stdout.write(`${await (0, commands_1.statusCommand)(http_1.defaultHttp)}\n`);
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stevezhou/sisu",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "description": "SiSu CLI — 思溯 / SiSu · 思有所溯",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://www.sisu.chat",