@stevezhou/sisu 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.
package/README.md CHANGED
@@ -10,8 +10,11 @@ One login. Cloud quota. Local runtime. Auth lives in `~/.sisu`, shared with SiSu
10
10
  npm install -g @stevezhou/sisu
11
11
  sisu --help
12
12
  sisu login
13
+ sisu
13
14
  ```
14
15
 
16
+ `npm install -g` is the same shape as `@xai-official/grok`: a small JS package. On macOS Apple Silicon the postinstall pulls the prebuilt Grok Build TUI into `~/.sisu/bin`. Other platforms keep the Node TUI until those binaries are published.
17
+
15
18
  Requires Node.js 20 or newer. `npx sisu` works without a global install.
16
19
 
17
20
  ## Login
@@ -19,8 +19,10 @@ function grokBuildBinaryCandidates() {
19
19
  const env = (process.env.SISU_GROK_BIN || '').trim();
20
20
  const root = (0, suite_1.grokBuildRoot)();
21
21
  const packaged = path_1.default.resolve(__dirname, '..', 'bin', 'xai-grok-pager');
22
+ const npmInstalled = path_1.default.join((0, store_1.getSisuHome)(), 'bin', process.platform === 'win32' ? 'xai-grok-pager.exe' : 'xai-grok-pager');
22
23
  return [
23
24
  env,
25
+ npmInstalled,
24
26
  packaged,
25
27
  path_1.default.join(root, 'target', 'release', 'xai-grok-pager'),
26
28
  path_1.default.join(root, 'target', 'debug', 'xai-grok-pager'),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stevezhou/sisu",
3
- "version": "0.2.0",
4
- "description": "SiSu CLI — local grok-build runtime, SiSu cloud models",
3
+ "version": "0.2.1",
4
+ "description": "SiSu CLI — Grok Build TUI + SiSu login, models, and quota",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://www.sisu.chat",
7
7
  "bugs": {
@@ -23,7 +23,9 @@
23
23
  "files": [
24
24
  "dist",
25
25
  "README.md",
26
- "NOTICE"
26
+ "NOTICE",
27
+ "scripts/postinstall.js",
28
+ "scripts/install-pager.js"
27
29
  ],
28
30
  "publishConfig": {
29
31
  "access": "public"
@@ -32,6 +34,7 @@
32
34
  "build": "tsc",
33
35
  "prepack": "tsc",
34
36
  "prepublishOnly": "npm test",
37
+ "postinstall": "node scripts/postinstall.js",
35
38
  "test": "jest --runInBand",
36
39
  "typecheck": "tsc --noEmit"
37
40
  },
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+ /** Install the grok-build pager the same way @xai-official/grok does:
3
+ * tiny npm package + platform binary (brotli) unpacked into ~/.sisu/bin.
4
+ */
5
+ const fs = require('fs')
6
+ const https = require('https')
7
+ const os = require('os')
8
+ const path = require('path')
9
+ const zlib = require('zlib')
10
+
11
+ const SUPPORTED = new Set(['darwin-arm64'])
12
+ const BIN = process.platform === 'win32' ? 'xai-grok-pager.exe' : 'xai-grok-pager'
13
+
14
+ function readVersion() {
15
+ try {
16
+ return require('../package.json').version
17
+ } catch {
18
+ return ''
19
+ }
20
+ }
21
+
22
+ function sisuHome() {
23
+ const override = (process.env.SISU_HOME || '').trim()
24
+ if (override) return override
25
+ return path.join(os.homedir(), '.sisu')
26
+ }
27
+
28
+ function pagerBinDir() {
29
+ return path.join(sisuHome(), 'bin')
30
+ }
31
+
32
+ function pagerBinPath() {
33
+ return path.join(pagerBinDir(), BIN)
34
+ }
35
+
36
+ function platformKey() {
37
+ return `${process.platform}-${process.arch}`
38
+ }
39
+
40
+ function releaseAssetUrl(version, key) {
41
+ return `https://github.com/hyzhou1990/sisu-cli/releases/download/v${version}/xai-grok-pager-${key}.br`
42
+ }
43
+
44
+ function writeBinary(bytes, dest) {
45
+ fs.mkdirSync(path.dirname(dest), { recursive: true, mode: 0o700 })
46
+ const tmp = `${dest}.tmp.${process.pid}`
47
+ fs.writeFileSync(tmp, bytes)
48
+ if (process.platform !== 'win32') fs.chmodSync(tmp, 0o755)
49
+ fs.renameSync(tmp, dest)
50
+ }
51
+
52
+ function decodePayload(buf) {
53
+ try {
54
+ return zlib.brotliDecompressSync(buf)
55
+ } catch {
56
+ return buf
57
+ }
58
+ }
59
+
60
+ function download(url) {
61
+ return new Promise((resolve, reject) => {
62
+ const req = https.get(url, { headers: { 'User-Agent': 'sisu-cli' } }, (res) => {
63
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
64
+ res.resume()
65
+ download(res.headers.location).then(resolve, reject)
66
+ return
67
+ }
68
+ if (res.statusCode !== 200) {
69
+ res.resume()
70
+ reject(new Error(`download ${url} failed (${res.statusCode})`))
71
+ return
72
+ }
73
+ const chunks = []
74
+ res.on('data', (chunk) => chunks.push(chunk))
75
+ res.on('end', () => resolve(Buffer.concat(chunks)))
76
+ res.on('error', reject)
77
+ })
78
+ req.on('error', reject)
79
+ req.setTimeout(120_000, () => {
80
+ req.destroy(new Error('download timed out'))
81
+ })
82
+ })
83
+ }
84
+
85
+ async function installPager(options = {}) {
86
+ const key = options.platform || platformKey()
87
+ const version = options.version || readVersion()
88
+ const dest = options.dest || pagerBinPath()
89
+ if (!SUPPORTED.has(key)) {
90
+ return { ok: false, skipped: true, reason: `no prebuilt pager for ${key}` }
91
+ }
92
+ if (!options.force && fs.existsSync(dest)) {
93
+ return { ok: true, dest, skipped: true, reason: 'already installed' }
94
+ }
95
+ if (options.file) {
96
+ const raw = decodePayload(fs.readFileSync(options.file))
97
+ writeBinary(raw, dest)
98
+ return { ok: true, dest }
99
+ }
100
+ if (!version) return { ok: false, reason: 'missing package version' }
101
+ const url = options.url || releaseAssetUrl(version, key)
102
+ const payload = await download(url)
103
+ writeBinary(decodePayload(payload), dest)
104
+ return { ok: true, dest, url }
105
+ }
106
+
107
+ module.exports = {
108
+ SUPPORTED,
109
+ decodePayload,
110
+ installPager,
111
+ pagerBinPath,
112
+ platformKey,
113
+ releaseAssetUrl,
114
+ writeBinary,
115
+ }
116
+
117
+ if (require.main === module) {
118
+ installPager({ force: process.argv.includes('--force') }).then(
119
+ (result) => {
120
+ if (result.ok) {
121
+ if (!result.skipped) process.stdout.write(`installed grok pager to ${result.dest}\n`)
122
+ process.exit(0)
123
+ }
124
+ process.stderr.write(`sisu pager: ${result.reason}\n`)
125
+ process.exit(result.skipped ? 0 : 1)
126
+ },
127
+ (error) => {
128
+ process.stderr.write(`sisu pager: ${error instanceof Error ? error.message : String(error)}\n`)
129
+ process.exit(1)
130
+ },
131
+ )
132
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /** Best-effort: fetch the grok-build pager like @xai-official/grok postinstall.
3
+ * Never fail `npm install` — Node TUI still works without the binary.
4
+ */
5
+ const { installPager } = require('./install-pager')
6
+
7
+ installPager().then(
8
+ (result) => {
9
+ if (result.ok && !result.skipped) {
10
+ process.stdout.write(`sisu: grok pager -> ${result.dest}\n`)
11
+ } else if (!result.ok && result.reason) {
12
+ process.stdout.write(`sisu: ${result.reason} (Node TUI still works)\n`)
13
+ }
14
+ },
15
+ (error) => {
16
+ process.stdout.write(`sisu: pager download skipped (${error instanceof Error ? error.message : String(error)})\n`)
17
+ },
18
+ )