@rarog/server 1.1.0 → 1.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rarog/server",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Rarog is a free, open-source (MIT) iPhone and iPad app, plus a server on your Mac or Linux machine, that shows the Claude Code sessions running in Herdr TUI and lets you drive them.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@number0/iroh": "1.2.0",
|
|
37
|
-
"@rarog/shared": "1.1.
|
|
37
|
+
"@rarog/shared": "1.1.1",
|
|
38
38
|
"qrcode": "1.5.4",
|
|
39
39
|
"ws": "8.21.3",
|
|
40
40
|
"zod": "4.4.3"
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* `update-provenance.ts` checks that one file, and npm installs exactly that file with `--ignore-scripts`. It finishes
|
|
11
11
|
* nothing: `update.ts` hands a new version to that version's own `rarog update --finish`. After npm has replaced the
|
|
12
12
|
* package files this process only reads one file and starts a child, so it never loads a module from the new files
|
|
13
|
-
* (no dynamic import).
|
|
13
|
+
* (no dynamic import). `nodeInstallsHere` tells `update.ts` whether the npm of another node (the service's) installs
|
|
14
|
+
* into this installation.
|
|
14
15
|
*/
|
|
15
16
|
import { spawn } from 'node:child_process';
|
|
16
17
|
import { mkdirSync, mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
@@ -295,6 +296,35 @@ function npmPrefixOf(root) {
|
|
|
295
296
|
const binDir = npmBinDir(root);
|
|
296
297
|
return binDir === null ? null : path.dirname(binDir);
|
|
297
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* `node` is the node of the npm prefix of the installation at `root` (`<prefix>/bin`), and `npm prefix -g` of the npm
|
|
301
|
+
* next to it, in the environment `env`, is that prefix: a user `prefix=` in `.npmrc` can move it away from the node's
|
|
302
|
+
* own directory. Only then a whole `rarog update` on `node` installs into this installation and finishes on that node.
|
|
303
|
+
* Each reason for `false` is a line to `line`; Ctrl-C during npm = {@link SetupInterrupted}.
|
|
304
|
+
*/
|
|
305
|
+
export async function nodeInstallsHere(input) {
|
|
306
|
+
const { node, root, line } = input;
|
|
307
|
+
const prefix = packageManagerOf(root) === 'npm' ? npmPrefixOf(root) : null;
|
|
308
|
+
if (prefix === null || !sameDir(path.dirname(node), path.join(prefix, 'bin'))) {
|
|
309
|
+
line(` ${node} is not the node of the npm prefix of ${root}`);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
const found = npmCliOf(node);
|
|
313
|
+
if ('failure' in found) {
|
|
314
|
+
line(` ${found.failure}`);
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
const run = await runNpm({
|
|
318
|
+
execPath: node, npmCli: found.file, env: npmEnv(input.env, NPM_AGE_GATE_CONFIG), cwd: input.cwd,
|
|
319
|
+
}, PREFIX_ARGS, line);
|
|
320
|
+
if (run.interrupted)
|
|
321
|
+
throw new SetupInterrupted('npm prefix was interrupted (Ctrl-C)');
|
|
322
|
+
const said = run.stdout.trim();
|
|
323
|
+
if (run.code === 0 && said !== '' && sameDir(said, prefix))
|
|
324
|
+
return true;
|
|
325
|
+
line(` npm prefix -g of ${node}: ${run.code === 0 ? said : `exit ${String(run.code)}`}`);
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
298
328
|
/**
|
|
299
329
|
* The Download step on `view`: the header with the versions, then one step line. Ctrl-C during npm =
|
|
300
330
|
* {@link SetupInterrupted}.
|
package/server/src/cli/update.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* `rarog update`: the newest version of the npm package from the registry (the Download step, `update-registry.ts`),
|
|
3
3
|
* then `rarog update --finish` of the version installed: a new version finishes in its own process (this one only
|
|
4
4
|
* started it, so a fault in the old version's finish cannot block the new one), the same version finishes here.
|
|
5
|
+
* Started on another node than the service's, when that node is the one of this prefix, it first runs again on the
|
|
6
|
+
* service's node, so the finish never moves the service to the terminal's node.
|
|
5
7
|
*
|
|
6
8
|
* `rarog update --finish` finishes the installed version without the registry. In order: the Claude SDK it pins
|
|
7
9
|
* (downloaded without a question), the service pointed at this installation when the run that has just installed it
|
|
@@ -16,11 +18,11 @@
|
|
|
16
18
|
* launchctl does not tell is refused before any step.
|
|
17
19
|
*/
|
|
18
20
|
import { spawn } from 'node:child_process';
|
|
19
|
-
import { realpathSync } from 'node:fs';
|
|
21
|
+
import { accessSync, constants, realpathSync } from 'node:fs';
|
|
20
22
|
import path from 'node:path';
|
|
21
23
|
import { INSTALL_MODE, INSTALL_ROOT } from '../install/mode.js';
|
|
22
|
-
import { rarogCli, repairCommands, shellQuote } from '../install/repair.js';
|
|
23
|
-
import { transientInstall } from '../install/service-target.js';
|
|
24
|
+
import { installationCli, rarogCli, repairCommands, shellQuote } from '../install/repair.js';
|
|
25
|
+
import { serviceArgvNode, transientInstall } from '../install/service-target.js';
|
|
24
26
|
import { readPackageVersion } from '../version.js';
|
|
25
27
|
import { trackChild } from './child-output.js';
|
|
26
28
|
import { EXIT_INTERRUPTED, EXIT_OK, EXIT_REFUSED, Refusal, Usage, err, homeOf, out, platformOf } from './io.js';
|
|
@@ -33,7 +35,7 @@ import { closingCheck, setupCliTarget } from './setup-check.js';
|
|
|
33
35
|
import { SCREEN_TITLE, SERVICE_UNDETERMINED, entry, serviceStateFix } from './setup-context.js';
|
|
34
36
|
import { SetupView } from './setup-screen.js';
|
|
35
37
|
import { unitFilePath } from './systemd-unit.js';
|
|
36
|
-
import { downloadStep } from './update-registry.js';
|
|
38
|
+
import { downloadStep, nodeInstallsHere } from './update-registry.js';
|
|
37
39
|
import { UPDATE_LOCK_TOKEN, markInstalled, takeUpdateLock, updateLockOf } from './update-lock.js';
|
|
38
40
|
import { sentenceFor, usageFor } from './screen/prose.js';
|
|
39
41
|
export const UPDATE_USAGE = ` rarog update [--beta] [--data-dir <dir>] [--verbose]
|
|
@@ -51,6 +53,11 @@ export const UPDATE_USAGE = ` rarog update [--beta] [--data-dir <dir>] [--verbo
|
|
|
51
53
|
project folders and leaves config.json as it is.
|
|
52
54
|
--data-dir: the installation's data directory from rarog serve --data-dir.
|
|
53
55
|
--verbose: every detail line on the screen.`;
|
|
56
|
+
/**
|
|
57
|
+
* Set in the environment of `rarog update` run again on the service's node: that run never switches again, so a
|
|
58
|
+
* node that still differs ends in a refusal, not in a loop.
|
|
59
|
+
*/
|
|
60
|
+
export const UPDATE_NODE_GUARD = 'RAROG_UPDATE_ON_SERVICE_NODE';
|
|
54
61
|
/** Command name of the run log (`<dataDir>/logs/update-….log`). */
|
|
55
62
|
export const UPDATE_LOG_COMMAND = 'update';
|
|
56
63
|
/** Step lines of a finish: four steps and the closing Check. */
|
|
@@ -166,6 +173,107 @@ function serviceAgainst(io, platform, root) {
|
|
|
166
173
|
? { kind: 'unloaded', what: `the service file ${file} is there, but launchd has no ${SERVICE_LABEL} loaded` }
|
|
167
174
|
: HERE;
|
|
168
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* The node the service starts when it starts this installation on another node than this process's: every source
|
|
178
|
+
* names the same executable node (macOS: the definition launchd has loaded and the plist; Linux: the unit file).
|
|
179
|
+
* `null` otherwise: no service, an unreadable one, sources that disagree, another installation, this process's node,
|
|
180
|
+
* or a load state launchctl does not tell. The Download step offers it only when it is the node of this prefix.
|
|
181
|
+
*/
|
|
182
|
+
function otherServiceNode(io, platform, root) {
|
|
183
|
+
const current = { node: process.execPath, bin: path.join(root, 'bin', 'rarog.mjs') };
|
|
184
|
+
const home = homeOf(io.env);
|
|
185
|
+
const sources = [];
|
|
186
|
+
if (platform === 'linux') {
|
|
187
|
+
if (entry(unitFilePath(home)) !== 'present')
|
|
188
|
+
return null;
|
|
189
|
+
const found = unitArgv(io);
|
|
190
|
+
if ('issue' in found)
|
|
191
|
+
return null;
|
|
192
|
+
sources.push(found.argv);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const loaded = loadedDefinition(SERVICE_LABEL, io, platform);
|
|
196
|
+
if (loaded.kind === 'unknown')
|
|
197
|
+
return null;
|
|
198
|
+
if (loaded.kind === 'loaded')
|
|
199
|
+
sources.push(loaded.argv);
|
|
200
|
+
if (entry(servicePlistPath(home)) === 'present') {
|
|
201
|
+
const found = servicePlistArgv(io);
|
|
202
|
+
if ('issue' in found)
|
|
203
|
+
return null;
|
|
204
|
+
sources.push(found.argv);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const nodes = new Set();
|
|
208
|
+
for (const argv of sources) {
|
|
209
|
+
if (serviceInstallationMismatch(argv, 'package', current)?.kind !== 'node')
|
|
210
|
+
return null;
|
|
211
|
+
nodes.add(serviceArgvNode(argv) ?? '');
|
|
212
|
+
}
|
|
213
|
+
const [node] = nodes;
|
|
214
|
+
if (nodes.size !== 1 || node === undefined || node === '')
|
|
215
|
+
return null;
|
|
216
|
+
try {
|
|
217
|
+
accessSync(node, constants.X_OK);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return node;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The service's node when this installation's update has to run on it: the service starts this installation on
|
|
226
|
+
* another node ({@link otherServiceNode}), that node is the one of this installation's npm prefix, and its npm installs
|
|
227
|
+
* there (`nodeInstallsHere`). `null` otherwise; `line` gets the reason.
|
|
228
|
+
*/
|
|
229
|
+
async function updateNodeOfService(io, platform, root, line) {
|
|
230
|
+
const node = otherServiceNode(io, platform, root);
|
|
231
|
+
if (node === null)
|
|
232
|
+
return null;
|
|
233
|
+
return await nodeInstallsHere({ node, root, env: io.env, cwd: homeOf(io.env), line }) ? node : null;
|
|
234
|
+
}
|
|
235
|
+
/** The arguments of a command as the user types them: the words bare, the value of `--data-dir` quoted. */
|
|
236
|
+
function typed(args) {
|
|
237
|
+
return args.map((arg, i) => (args[i - 1] === '--data-dir' ? shellQuote(arg) : arg)).join(' ');
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* `rarog update` (`argv` starts with `update`) on another node than the service's, when the update has to run on the
|
|
241
|
+
* service's node ({@link updateNodeOfService}): this process becomes the same command with the same arguments on that
|
|
242
|
+
* node (`process.execve`, the same PID), so its npm installs and the new version's finish runs on the node the service
|
|
243
|
+
* starts (a finish on this node would move the service here). One line says so; that run takes the update lock
|
|
244
|
+
* itself and gets {@link UPDATE_NODE_GUARD}. A run with the guard that still sees another node refuses instead of
|
|
245
|
+
* switching again. `null` = this run goes on.
|
|
246
|
+
*/
|
|
247
|
+
async function onServiceNode(argv, io, platform, root, replaceWith) {
|
|
248
|
+
let node;
|
|
249
|
+
try {
|
|
250
|
+
node = await updateNodeOfService(io, platform, root, () => { });
|
|
251
|
+
}
|
|
252
|
+
catch (failure) {
|
|
253
|
+
if (failure instanceof SetupInterrupted)
|
|
254
|
+
return EXIT_INTERRUPTED;
|
|
255
|
+
throw failure;
|
|
256
|
+
}
|
|
257
|
+
if (node === null)
|
|
258
|
+
return null;
|
|
259
|
+
const bin = path.join(root, 'bin', 'rarog.mjs');
|
|
260
|
+
const command = installationCli({ node, bin }, typed(argv));
|
|
261
|
+
if (io.env[UPDATE_NODE_GUARD] !== undefined) {
|
|
262
|
+
throw new Refusal(`the service starts ${node}, but this run on it runs on ${process.execPath}; nothing was`
|
|
263
|
+
+ ` changed; run ${command}.`);
|
|
264
|
+
}
|
|
265
|
+
const replace = replaceWith ?? (typeof process.execve === 'function' ? process.execve : null);
|
|
266
|
+
if (replace === null) {
|
|
267
|
+
// `bin/rarog.mjs` lets only a Node with `process.execve` in; a second process would not stop with this one.
|
|
268
|
+
throw new Refusal(`the service starts ${node}, and this Node (v${process.versions.node}) has no process.execve`
|
|
269
|
+
+ ` to run the update on it; nothing was changed; run ${command}.`);
|
|
270
|
+
}
|
|
271
|
+
out(io, `rarog update: the service starts ${node}, so this update runs on it.`);
|
|
272
|
+
// The same process becomes the run on the service's node: every signal reaches it as it would reach `rarog update`
|
|
273
|
+
// started there, and no process is left behind that could exit while the update goes on.
|
|
274
|
+
const code = replace(node, [node, bin, ...argv], { ...withoutToken(io.env), [UPDATE_NODE_GUARD]: '1' });
|
|
275
|
+
return typeof code === 'number' ? code : EXIT_REFUSED;
|
|
276
|
+
}
|
|
169
277
|
/** `rarog update` and `rarog update --finish` — `argv` starts with `update`; tests give `deps`. */
|
|
170
278
|
export async function updateCommand(argv, io, deps = DEFAULT_DEPS) {
|
|
171
279
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
@@ -200,6 +308,12 @@ export async function updateCommand(argv, io, deps = DEFAULT_DEPS) {
|
|
|
200
308
|
throw new Refusal(`${what}: no ${path.join(rarogConfigDir(io.env), 'config.json')}, so there is no installation`
|
|
201
309
|
+ ` to ${flags.finish ? 'finish' : 'update'}; run ${rarogCli('setup', mode)} first.`);
|
|
202
310
|
}
|
|
311
|
+
// Before the lock: the run on the service's node takes it itself.
|
|
312
|
+
if (!flags.finish) {
|
|
313
|
+
const code = await onServiceNode(argv, io, platform, root, deps.replaceProcess);
|
|
314
|
+
if (code !== null)
|
|
315
|
+
return code;
|
|
316
|
+
}
|
|
203
317
|
// `rarog update` installs, so it always takes the lock itself; a finish inherits the lock of a run that installed.
|
|
204
318
|
const dir = rarogConfigDir(io.env);
|
|
205
319
|
const lock = flags.finish ? updateLockOf(dir, io.env, what) : takeUpdateLock(dir, what);
|
|
@@ -364,8 +478,16 @@ async function runSteps(io, view, steps, run, deps, at) {
|
|
|
364
478
|
// The update lock does not name this installation as the one just installed: the refusal of rarog restart.
|
|
365
479
|
start('service', 'Service', false);
|
|
366
480
|
view.detail(` ${service.what}`);
|
|
367
|
-
//
|
|
368
|
-
|
|
481
|
+
// A service on the node of this prefix whose npm installs here: this command again on that node, which the service
|
|
482
|
+
// already starts (`rarog service install` here would move the service to this process's node).
|
|
483
|
+
const node = service.other === 'node'
|
|
484
|
+
? await updateNodeOfService(io, run.platform, run.root, (text) => { view.detail(text); }) : null;
|
|
485
|
+
const again = [...(run.flags.finish ? ['update', '--finish'] : ['update']),
|
|
486
|
+
...(run.flags.dataDir === null ? [] : ['--data-dir', run.flags.dataDir])];
|
|
487
|
+
// Otherwise the command of this installation (the absolute form outside `PATH`, `screenFix`); the step line says why.
|
|
488
|
+
show(view, 'fail', `starts another ${service.other}; nothing was changed`, node === null
|
|
489
|
+
? rarogCli('service install', 'package')
|
|
490
|
+
: installationCli({ node, bin: path.join(run.root, 'bin', 'rarog.mjs') }, typed(again)));
|
|
369
491
|
return EXIT_REFUSED;
|
|
370
492
|
}
|
|
371
493
|
const results = [];
|