@nordhavnhq/runner 0.95.0 → 0.97.0
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/cli/agent.d.ts +5 -5
- package/dist/cli/agent.js +19 -60
- package/dist/cli/lifecycle.js +6 -6
- package/dist/cli/link.d.ts +0 -22
- package/dist/cli/link.js +37 -39
- package/dist/cli/logs.js +2 -5
- package/dist/cli/ps.js +4 -5
- package/dist/cli/update.js +28 -16
- package/dist/index.js +26 -34
- package/dist/runtime/up.js +9 -12
- package/dist/update/install.d.ts +9 -0
- package/dist/update/install.js +31 -1
- package/dist/update/manifest.d.ts +14 -4
- package/dist/update/manifest.js +30 -11
- package/dist/update/policy.js +8 -8
- package/dist/update/updater.d.ts +8 -0
- package/dist/update/updater.js +14 -1
- package/dist/utils/format.d.ts +1 -1
- package/dist/utils/format.js +2 -2
- package/dist/version.json +3 -3
- package/node_modules/@nordhavnhq/runner-browser/package.json +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/constants.js +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/package.json +1 -1
- package/package.json +3 -3
package/dist/cli/agent.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type CliCtx } from './prompts.js';
|
|
2
2
|
/**
|
|
3
|
-
* `agent add` and `agent
|
|
4
|
-
* `nordhavn link <code>`
|
|
5
|
-
* Kept as commands that say so, for muscle memory.
|
|
3
|
+
* `agent add`, `agent relink` and `agent remove` are gone: a runner hosts one
|
|
4
|
+
* agent, `nordhavn link <code>` connects (or replaces) it and `nordhavn unlink`
|
|
5
|
+
* removes it with the pairing. Kept as commands that say so, for muscle memory.
|
|
6
6
|
*/
|
|
7
7
|
export declare function removedAgentCommand(): Promise<void>;
|
|
8
|
-
|
|
9
|
-
export declare function
|
|
8
|
+
/** `nordhavn agent`: the one agent this runner hosts. */
|
|
9
|
+
export declare function show(ctx: CliCtx): Promise<void>;
|
package/dist/cli/agent.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { loadConfig,
|
|
2
|
-
import { dim, green, red, bold, showHelp
|
|
1
|
+
import { loadConfig, agentHomeDir, agentRef } from '../config.js';
|
|
2
|
+
import { dim, green, red, bold, showHelp } from '../utils/format.js';
|
|
3
3
|
import { wantsHelp } from './prompts.js';
|
|
4
4
|
/**
|
|
5
|
-
* `agent add` and `agent
|
|
6
|
-
* `nordhavn link <code>`
|
|
7
|
-
* Kept as commands that say so, for muscle memory.
|
|
5
|
+
* `agent add`, `agent relink` and `agent remove` are gone: a runner hosts one
|
|
6
|
+
* agent, `nordhavn link <code>` connects (or replaces) it and `nordhavn unlink`
|
|
7
|
+
* removes it with the pairing. Kept as commands that say so, for muscle memory.
|
|
8
8
|
*/
|
|
9
9
|
export async function removedAgentCommand() {
|
|
10
10
|
console.log('');
|
|
11
|
-
console.log(red(' Removed: a runner hosts one agent
|
|
11
|
+
console.log(red(' Removed: a runner hosts one agent.'));
|
|
12
|
+
console.log(dim(' Connect or replace it: `nordhavn link <code>` with a code from the agent\'s page in the studio.'));
|
|
13
|
+
console.log(dim(' Remove it: `nordhavn unlink`.\n'));
|
|
12
14
|
process.exit(1);
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
/** `nordhavn agent`: the one agent this runner hosts. */
|
|
17
|
+
export async function show(ctx) {
|
|
15
18
|
if (wantsHelp(ctx)) {
|
|
16
|
-
showHelp('nordhavn agent
|
|
19
|
+
showHelp('nordhavn agent', 'Show the agent of this runner', [], ['nordhavn agent']);
|
|
17
20
|
return;
|
|
18
21
|
}
|
|
19
22
|
console.log('');
|
|
@@ -22,59 +25,15 @@ export async function remove(ctx) {
|
|
|
22
25
|
console.log(red(' Not configured. Run `nordhavn init` first.\n'));
|
|
23
26
|
process.exit(1);
|
|
24
27
|
}
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
27
|
-
console.log(
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
const agent = requireAgent(config, ref);
|
|
31
|
-
const removedRef = agentRef(config, agent);
|
|
32
|
-
const updated = removeAgent(config, agent);
|
|
33
|
-
await saveConfig(updated);
|
|
34
|
-
console.log(green(` ✓ Agent "${removedRef}" removed.`));
|
|
35
|
-
console.log(dim(` ${updated.agents.length} agent(s) remaining.\n`));
|
|
36
|
-
}
|
|
37
|
-
export async function list(ctx) {
|
|
38
|
-
if (wantsHelp(ctx)) {
|
|
39
|
-
showHelp('nordhavn agent ls', 'List all configured agents', [], ['nordhavn agent ls']);
|
|
28
|
+
const agent = config.agents[0];
|
|
29
|
+
if (!agent) {
|
|
30
|
+
console.log(dim(' No agent yet. Run `nordhavn link <code>` with a code from the agent\'s page in the studio.\n'));
|
|
40
31
|
return;
|
|
41
32
|
}
|
|
33
|
+
const state = agent.enabled ? green('●') : dim('○');
|
|
34
|
+
const org = agent.organisationSlug ? dim(` · ${agent.organisationSlug}`) : '';
|
|
35
|
+
console.log(` ${state} ${bold(agentRef(config, agent))}${org}${agent.enabled ? '' : dim(' · disabled')}`);
|
|
36
|
+
console.log(dim(` home: ${agentHomeDir(config, agent)}`));
|
|
42
37
|
console.log('');
|
|
43
|
-
|
|
44
|
-
if (!config) {
|
|
45
|
-
console.log(red(' Not configured. Run `nordhavn init` first.\n'));
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
if (config.agents.length === 0) {
|
|
49
|
-
console.log(dim(' No agent configured. Run `nordhavn link <code>` with a code from the agent\'s page in the studio.\n'));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Organisation is noise while there is only one pairing, and essential once
|
|
53
|
-
// there are several - so it only appears when it can actually differ.
|
|
54
|
-
const showOrg = config.hosts.length > 1;
|
|
55
|
-
console.log(bold(' Agents\n'));
|
|
56
|
-
for (const agent of config.agents) {
|
|
57
|
-
const state = agent.enabled ? green('●') : dim('○');
|
|
58
|
-
const home = agentHomeDir(config, agent).replace(config.home, '').replace(/^[/\\]/, '');
|
|
59
|
-
const org = showOrg ? dim(` · ${agent.organisationSlug ?? 'unknown organisation'}`) : '';
|
|
60
|
-
console.log(` ${state} ${bold(agentRef(config, agent))} ${dim(`· ${home}/`)}${org}`);
|
|
61
|
-
}
|
|
62
|
-
console.log('');
|
|
63
|
-
console.log(dim(` Home: ${config.home}`));
|
|
64
|
-
console.log(dim(` ${config.agents.length} agent(s) configured.\n`));
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Resolve a user-typed agent reference or exit with a readable error. A bare
|
|
68
|
-
* slug that names several agents is refused rather than guessed at.
|
|
69
|
-
*/
|
|
70
|
-
function requireAgent(config, ref) {
|
|
71
|
-
const found = resolveAgentRef(config, ref);
|
|
72
|
-
if ('agent' in found)
|
|
73
|
-
return found.agent;
|
|
74
|
-
if ('ambiguous' in found) {
|
|
75
|
-
printAmbiguous(config, ref, found.ambiguous);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
console.log(red(` Agent "${ref}" not found.\n`));
|
|
79
|
-
process.exit(1);
|
|
38
|
+
console.log(dim(' Replace it: `nordhavn link <code>` · remove it: `nordhavn unlink`.\n'));
|
|
80
39
|
}
|
package/dist/cli/lifecycle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadConfig, agentRef, resolveAgentRef } from '../config.js';
|
|
2
2
|
import { liveStatus, readAllStatuses, isAlive, isStatusAlive, spawnDetachedAgent, } from '../runtime/daemon.js';
|
|
3
|
-
import { dim, green, red, showHelp,
|
|
3
|
+
import { dim, green, red, showHelp, printAmbiguous } from '../utils/format.js';
|
|
4
4
|
import { wantsHelp } from './prompts.js';
|
|
5
5
|
function wantsDebug(ctx) {
|
|
6
6
|
return ctx.cmdArgs.includes('--debug') || ctx.cmdArgs.includes('-v');
|
|
@@ -39,7 +39,7 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
39
39
|
}
|
|
40
40
|
export async function down(ctx) {
|
|
41
41
|
if (wantsHelp(ctx)) {
|
|
42
|
-
showHelp('nordhavn down
|
|
42
|
+
showHelp('nordhavn down', 'Take the agent of this runner offline', [], ['nordhavn down']);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
console.log('');
|
|
@@ -50,7 +50,7 @@ export async function down(ctx) {
|
|
|
50
50
|
if (isStatusAlive(s))
|
|
51
51
|
pids.add(s.pid);
|
|
52
52
|
if (pids.size === 0) {
|
|
53
|
-
console.log(dim('
|
|
53
|
+
console.log(dim(' The agent is not running.\n'));
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
let killed = 0;
|
|
@@ -63,7 +63,7 @@ export async function down(ctx) {
|
|
|
63
63
|
console.log(red(` Failed to signal pid ${pid}: ${err.message}`));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
console.log(green(` ✓ Stopped ${killed} runtime
|
|
66
|
+
console.log(green(killed > 1 ? ` ✓ Stopped ${killed} runtime processes.\n` : ' ✓ Agent stopped.\n'));
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
const config = await loadConfig();
|
|
@@ -98,7 +98,7 @@ export async function down(ctx) {
|
|
|
98
98
|
}
|
|
99
99
|
export async function restart(ctx) {
|
|
100
100
|
if (wantsHelp(ctx)) {
|
|
101
|
-
showHelp('nordhavn restart
|
|
101
|
+
showHelp('nordhavn restart', 'Restart the agent of this runner in the background', [], ['nordhavn restart']);
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
console.log('');
|
|
@@ -112,7 +112,7 @@ export async function restart(ctx) {
|
|
|
112
112
|
? [resolveRefOrExit(config, ctx.subarg)]
|
|
113
113
|
: readAllStatuses().filter(s => isStatusAlive(s)).map(s => s.ref);
|
|
114
114
|
if (targets.length === 0) {
|
|
115
|
-
console.log(dim('
|
|
115
|
+
console.log(dim(' The agent is not running. Start it with `nordhavn up -d`.\n'));
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
const knownRefs = new Set(config.agents.map(a => agentRef(config, a)));
|
package/dist/cli/link.d.ts
CHANGED
|
@@ -17,26 +17,4 @@ import { type CliCtx } from './prompts.js';
|
|
|
17
17
|
* `projectsRoots` describe this machine, not an organisation.
|
|
18
18
|
*/
|
|
19
19
|
export declare function link(ctx: CliCtx): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Remove a pairing and every agent that belongs to it - the inverse of `link`,
|
|
22
|
-
* for a client whose work is finished or a studio this machine should no longer
|
|
23
|
-
* answer to.
|
|
24
|
-
*
|
|
25
|
-
* Refuses while any of the organisation's agents are still running. Their host
|
|
26
|
-
* token disappears with the pairing, so the process would keep spinning on a
|
|
27
|
-
* connection it can no longer make instead of failing where the operator can
|
|
28
|
-
* see it. Stopping them from here is tempting but wrong: a foreground session
|
|
29
|
-
* can drive agents from several organisations at once, and killing it would
|
|
30
|
-
* take the others down too - which is exactly why `down` refuses that case as
|
|
31
|
-
* well.
|
|
32
|
-
*
|
|
33
|
-
* The studio-side `Runner` row is left alone: there is no local endpoint to
|
|
34
|
-
* revoke it, and unlike a re-pair there is no code being redeemed that could
|
|
35
|
-
* carry the proof of ownership along (see `pairingProofs`), so this says
|
|
36
|
-
* so rather than pretending the machine is gone from the organisation.
|
|
37
|
-
*
|
|
38
|
-
* Agent home directories are left on disk, matching `agent remove`. That is why
|
|
39
|
-
* `flatHomeOrg` is not cleared here - see `removePairing` and
|
|
40
|
-
* `canClaimFlatHome` for how the flat layout is protected afterwards.
|
|
41
|
-
*/
|
|
42
20
|
export declare function unlink(ctx: CliCtx): Promise<void>;
|
package/dist/cli/link.js
CHANGED
|
@@ -233,9 +233,34 @@ export async function link(ctx) {
|
|
|
233
233
|
* `flatHomeOrg` is not cleared here - see `removePairing` and
|
|
234
234
|
* `canClaimFlatHome` for how the flat layout is protected afterwards.
|
|
235
235
|
*/
|
|
236
|
+
/** One pairing per runner, so `unlink` needs no argument: the organisation of
|
|
237
|
+
* that pairing. An explicit argument still works (old configs, scripts). */
|
|
238
|
+
function pairedOrganisation(config) {
|
|
239
|
+
if (config.hosts.length !== 1)
|
|
240
|
+
return undefined;
|
|
241
|
+
return config.hosts[0].organisationSlug ?? NAMELESS_ORG_LABEL;
|
|
242
|
+
}
|
|
243
|
+
/** The agent of `org` that is still running, if any. Matched on the ref the
|
|
244
|
+
* status file was written under and on the organisation it recorded: a status
|
|
245
|
+
* file written before a rename or by an older runner can carry the other one. */
|
|
246
|
+
function runningAgentOf(config, org) {
|
|
247
|
+
const target = config.hosts.find(h => h.organisationSlug === org)
|
|
248
|
+
?? (org === NAMELESS_ORG_LABEL ? config.hosts.find(h => h.organisationSlug === null) : undefined);
|
|
249
|
+
if (!target)
|
|
250
|
+
return undefined;
|
|
251
|
+
const live = readAllStatuses().filter(s => isStatusAlive(s));
|
|
252
|
+
for (const agent of config.agents.filter(a => a.organisationSlug === target.organisationSlug)) {
|
|
253
|
+
const ref = agentRef(config, agent);
|
|
254
|
+
const status = live.find(s => s.ref === ref)
|
|
255
|
+
?? live.find(s => s.slug === agent.slug && s.organisationSlug === agent.organisationSlug);
|
|
256
|
+
if (status)
|
|
257
|
+
return { ref, status };
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
236
261
|
export async function unlink(ctx) {
|
|
237
262
|
if (wantsHelp(ctx)) {
|
|
238
|
-
showHelp('nordhavn unlink
|
|
263
|
+
showHelp('nordhavn unlink', 'Remove the pairing and its agent from this runner', [], ['nordhavn unlink']);
|
|
239
264
|
return;
|
|
240
265
|
}
|
|
241
266
|
console.log('');
|
|
@@ -245,48 +270,22 @@ export async function unlink(ctx) {
|
|
|
245
270
|
process.exit(1);
|
|
246
271
|
return;
|
|
247
272
|
}
|
|
248
|
-
const org = ctx.subarg;
|
|
273
|
+
const org = ctx.subarg ?? pairedOrganisation(config);
|
|
249
274
|
if (!org) {
|
|
250
|
-
console.log(
|
|
251
|
-
console.log(dim(' `nordhavn ps` names the organisations this machine is paired with.\n'));
|
|
252
|
-
process.exit(1);
|
|
275
|
+
console.log(dim(' This runner is not paired.\n'));
|
|
253
276
|
return;
|
|
254
277
|
}
|
|
255
278
|
// Refuse before mutating anything: a running agent means the operator has a
|
|
256
279
|
// process to deal with first, and a half-applied unlink would leave it
|
|
257
280
|
// holding a token no host backs any more.
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// organisation it recorded - a status file written before a rename or by
|
|
267
|
-
// an older runner can carry the other one.
|
|
268
|
-
.map(({ ref, agent }) => ({
|
|
269
|
-
ref,
|
|
270
|
-
status: live.find(s => s.ref === ref)
|
|
271
|
-
?? live.find(s => s.slug === agent.slug && s.organisationSlug === agent.organisationSlug),
|
|
272
|
-
}))
|
|
273
|
-
.filter((r) => r.status !== undefined);
|
|
274
|
-
if (running.length > 0) {
|
|
275
|
-
const shared = running.some(r => r.status.mode === 'foreground');
|
|
276
|
-
console.log(red(` ${running.length} agent(s) from "${org}" are still running:`));
|
|
277
|
-
for (const r of running)
|
|
278
|
-
console.log(red(` ${r.ref} ${dim(`(${r.status.mode}, pid ${r.status.pid})`)}`));
|
|
279
|
-
console.log('');
|
|
280
|
-
console.log(dim(' Stop them first, then unlink again:'));
|
|
281
|
-
console.log(dim(` nordhavn down ${running[0].ref}${running.length > 1 ? ' (repeat per agent)' : ''}`));
|
|
282
|
-
if (shared) {
|
|
283
|
-
console.log(dim(' A foreground session can drive other organisations\' agents too - `down` will'));
|
|
284
|
-
console.log(dim(' refuse it and tell you to Ctrl+C that session instead.'));
|
|
285
|
-
}
|
|
286
|
-
console.log('');
|
|
287
|
-
process.exit(1);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
281
|
+
const running = runningAgentOf(config, org);
|
|
282
|
+
if (running) {
|
|
283
|
+
console.log(red(` ${running.ref} is still running ${dim(`(${running.status.mode}, pid ${running.status.pid})`)}.`));
|
|
284
|
+
console.log(dim(running.status.mode === 'foreground'
|
|
285
|
+
? ' Stop it first (Ctrl+C in its terminal), then unlink again.\n'
|
|
286
|
+
: ' Stop it first with `nordhavn down`, then unlink again.\n'));
|
|
287
|
+
process.exit(1);
|
|
288
|
+
return;
|
|
290
289
|
}
|
|
291
290
|
const result = removePairing(config, org);
|
|
292
291
|
if ('missing' in result) {
|
|
@@ -300,8 +299,7 @@ export async function unlink(ctx) {
|
|
|
300
299
|
const name = result.host.organisationSlug ?? NAMELESS_ORG_LABEL;
|
|
301
300
|
console.log(green(` ✓ Unlinked "${name}" (${result.host.name}).`));
|
|
302
301
|
if (result.removedAgents.length > 0) {
|
|
303
|
-
console.log(dim(` Removed
|
|
304
|
-
console.log(dim(' Their home directories are left on disk, as `agent remove` leaves them.'));
|
|
302
|
+
console.log(dim(` Removed agent ${result.removedAgents.map(a => a.slug).join(', ')}; its home directory stays on disk.`));
|
|
305
303
|
}
|
|
306
304
|
// Only worth explaining when the flat layer is actually still occupied -
|
|
307
305
|
// otherwise the next `link` simply reclaims it and there is nothing to know.
|
package/dist/cli/logs.js
CHANGED
|
@@ -93,10 +93,7 @@ function follow(target, multi) {
|
|
|
93
93
|
}
|
|
94
94
|
export async function logs(ctx) {
|
|
95
95
|
if (wantsHelp(ctx)) {
|
|
96
|
-
showHelp('nordhavn logs [
|
|
97
|
-
helpOpt(dim('[agent]'), 'Agent to show; every agent with logs if omitted. Use slug@organisation when a slug exists in more than one'),
|
|
98
|
-
helpOpt(dim('--once'), 'Print the recent lines and exit instead of following'),
|
|
99
|
-
], ['nordhavn logs', 'nordhavn logs atlas', 'nordhavn logs atlas@klant-x', 'nordhavn logs --once']);
|
|
96
|
+
showHelp('nordhavn logs [--once]', 'Tail the log of the agent when it runs in the background', [helpOpt(dim('--once'), 'Print the recent lines and exit instead of following')], ['nordhavn logs', 'nordhavn logs --once']);
|
|
100
97
|
return;
|
|
101
98
|
}
|
|
102
99
|
// Follow live by default; --once is the one-shot dump (for piping/scrollback).
|
|
@@ -127,7 +124,7 @@ export async function logs(ctx) {
|
|
|
127
124
|
.filter(f => f.endsWith('.log'))
|
|
128
125
|
.map(f => ({ ref: f.slice(0, -4), file: join(logsDir(), f) }));
|
|
129
126
|
if (targets.length === 0) {
|
|
130
|
-
console.log(dim(' No agent
|
|
127
|
+
console.log(dim(' No agent log yet. Start the agent with `nordhavn up -d`.\n'));
|
|
131
128
|
return;
|
|
132
129
|
}
|
|
133
130
|
}
|
package/dist/cli/ps.js
CHANGED
|
@@ -32,7 +32,7 @@ function cellFor(status) {
|
|
|
32
32
|
}
|
|
33
33
|
export async function ps(ctx) {
|
|
34
34
|
if (wantsHelp(ctx)) {
|
|
35
|
-
showHelp('nordhavn ps', 'Show the runtime status of
|
|
35
|
+
showHelp('nordhavn ps', 'Show the runtime status of the agent', [], ['nordhavn ps']);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
console.log('');
|
|
@@ -73,9 +73,8 @@ export async function ps(ctx) {
|
|
|
73
73
|
console.log(` ${dot} ${pad(bold(ref), refWidth)}${org}${pad(label, 16)}${pad(dim(uptime), 10)}${pad(dim(mode), 13)}${dim(pid)}`);
|
|
74
74
|
}
|
|
75
75
|
console.log('');
|
|
76
|
-
console.log(dim(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
76
|
+
console.log(dim(live.size > 0
|
|
77
|
+
? ' `nordhavn logs` to follow output · `nordhavn down` to stop'
|
|
78
|
+
: ' `nordhavn up` to start'));
|
|
80
79
|
console.log('');
|
|
81
80
|
}
|
package/dist/cli/update.js
CHANGED
|
@@ -2,7 +2,7 @@ import { loadConfig } from '../config.js';
|
|
|
2
2
|
import { isAlive, spawnDetachedAgent } from '../runtime/daemon.js';
|
|
3
3
|
import { VERSION, bold, cyan, dim, green, red, yellow, isNewerVersion, showHelp, helpOpt } from '../utils/format.js';
|
|
4
4
|
import { detectInstallKind } from '../update/install-kind.js';
|
|
5
|
-
import { performUpdate } from '../update/install.js';
|
|
5
|
+
import { installNotWritable, ownershipFix, performUpdate } from '../update/install.js';
|
|
6
6
|
import { fetchManifest, manifestUrl } from '../update/manifest.js';
|
|
7
7
|
import { liveRuntimes, signalRestart } from '../update/peers.js';
|
|
8
8
|
import { autoUpdateOptedOut, updateHint } from '../update/policy.js';
|
|
@@ -22,13 +22,9 @@ export async function update(ctx) {
|
|
|
22
22
|
const check = ctx.cmdArgs.includes('--check');
|
|
23
23
|
const force = ctx.cmdArgs.includes('--force');
|
|
24
24
|
console.log('');
|
|
25
|
+
// The release comes from npm: no pairing needed. The config only says whether auto update is off.
|
|
25
26
|
const config = await loadConfig();
|
|
26
|
-
const url = manifestUrl(
|
|
27
|
-
if (!url) {
|
|
28
|
-
console.log(red(' Not configured. Run `nordhavn init` first.\n'));
|
|
29
|
-
process.exit(1);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
27
|
+
const url = manifestUrl();
|
|
32
28
|
const kind = detectInstallKind();
|
|
33
29
|
let manifest;
|
|
34
30
|
try {
|
|
@@ -41,15 +37,7 @@ export async function update(ctx) {
|
|
|
41
37
|
}
|
|
42
38
|
const newer = isNewerVersion(manifest.version, VERSION);
|
|
43
39
|
if (check) {
|
|
44
|
-
|
|
45
|
-
console.log(` ${dim('installed')} ${bold(VERSION)}`);
|
|
46
|
-
console.log(` ${dim('latest')} ${bold(manifest.version)}${manifest.releasedAt ? dim(` (${manifest.releasedAt})`) : ''}`);
|
|
47
|
-
console.log(` ${dim('install')} ${kind.kind === 'global' ? `global ${dim(kind.prefix)}` : kind.kind}`);
|
|
48
|
-
console.log(` ${dim('auto update')} ${auto}`);
|
|
49
|
-
console.log('');
|
|
50
|
-
console.log(newer
|
|
51
|
-
? ` ${yellow('update available')}: run ${cyan(updateHint(kind.kind))}\n`
|
|
52
|
-
: ` ${green('up to date')}\n`);
|
|
40
|
+
printCheck(kind, manifest, autoUpdateOptedOut(config), newer);
|
|
53
41
|
return;
|
|
54
42
|
}
|
|
55
43
|
if (kind.kind !== 'global') {
|
|
@@ -62,6 +50,13 @@ export async function update(ctx) {
|
|
|
62
50
|
console.log(green(` Up to date (${VERSION}).\n`));
|
|
63
51
|
return;
|
|
64
52
|
}
|
|
53
|
+
const notWritable = installNotWritable(kind.packageDir);
|
|
54
|
+
if (notWritable) {
|
|
55
|
+
console.log(red(` Cannot update: ${notWritable}.`));
|
|
56
|
+
console.log(dim(` Give the install back to your user once, then auto update works too:\n ${ownershipFix(kind.packageDir)}\n`));
|
|
57
|
+
process.exit(1);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
65
60
|
const runtimes = liveRuntimes();
|
|
66
61
|
const busy = runtimes.filter(r => r.activeRuns > 0);
|
|
67
62
|
if (busy.length > 0 && !force) {
|
|
@@ -88,6 +83,23 @@ export async function update(ctx) {
|
|
|
88
83
|
await moveRuntimes(runtimes);
|
|
89
84
|
console.log('');
|
|
90
85
|
}
|
|
86
|
+
function printCheck(kind, manifest, optedOut, newer) {
|
|
87
|
+
const notWritable = kind.kind === 'global' ? installNotWritable(kind.packageDir) : null;
|
|
88
|
+
const auto = kind.kind !== 'global'
|
|
89
|
+
? `no (${kind.reason})`
|
|
90
|
+
: optedOut ? 'off' : notWritable ? `no (${notWritable})` : 'on';
|
|
91
|
+
console.log(` ${dim('installed')} ${bold(VERSION)}`);
|
|
92
|
+
console.log(` ${dim('latest')} ${bold(manifest.version)}${manifest.releasedAt ? dim(` (${manifest.releasedAt})`) : ''}`);
|
|
93
|
+
console.log(` ${dim('source')} ${dim(manifestUrl())}`);
|
|
94
|
+
console.log(` ${dim('install')} ${kind.kind === 'global' ? `global ${dim(kind.prefix)}` : kind.kind}`);
|
|
95
|
+
console.log(` ${dim('auto update')} ${auto}`);
|
|
96
|
+
if (notWritable && kind.kind === 'global')
|
|
97
|
+
console.log(dim(` fix: ${ownershipFix(kind.packageDir)}`));
|
|
98
|
+
console.log('');
|
|
99
|
+
console.log(newer
|
|
100
|
+
? ` ${yellow('update available')}: run ${cyan(updateHint(kind.kind))}\n`
|
|
101
|
+
: ` ${green('up to date')}\n`);
|
|
102
|
+
}
|
|
91
103
|
/**
|
|
92
104
|
* Running runtimes onto the new version. One that knows self-update gets the
|
|
93
105
|
* restart signal and restarts once idle. An older detached one is stopped and
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// First: maps pre-rename env names (JUSTMADE_*, HAVEN_*) before anything reads them.
|
|
3
3
|
import './legacy-env.js';
|
|
4
|
-
import { dim, bold, cyan, red, accent, logo,
|
|
4
|
+
import { dim, bold, cyan, red, accent, logo, stripAnsi, VERSION } from './utils/format.js';
|
|
5
5
|
import { init } from './cli/init.js';
|
|
6
6
|
import { link, unlink } from './cli/link.js';
|
|
7
|
-
import { removedAgentCommand,
|
|
7
|
+
import { removedAgentCommand, show } from './cli/agent.js';
|
|
8
8
|
import { folderCommand } from './cli/folder.js';
|
|
9
9
|
import { up } from './runtime/up.js';
|
|
10
10
|
import { ps } from './cli/ps.js';
|
|
@@ -21,15 +21,10 @@ const args = process.argv.slice(2);
|
|
|
21
21
|
const command = args[0] ?? '';
|
|
22
22
|
let resolvedCommand = command;
|
|
23
23
|
let cmdArgs = args.slice(1);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
resolvedCommand = `agent:${args[1]}`;
|
|
31
|
-
cmdArgs = args.slice(2);
|
|
32
|
-
}
|
|
24
|
+
// `nordhavn agent` shows the runner's agent; `agent ls` is the old spelling.
|
|
25
|
+
if (command === 'agent' && args[1] && args[1] !== '-h' && args[1] !== '--help') {
|
|
26
|
+
resolvedCommand = `agent:${args[1]}`;
|
|
27
|
+
cmdArgs = args.slice(2);
|
|
33
28
|
}
|
|
34
29
|
if (command === 'folder' && args[1]) {
|
|
35
30
|
if (args[1] === '-h' || args[1] === '--help') {
|
|
@@ -44,10 +39,14 @@ if (command === 'folder' && args[1]) {
|
|
|
44
39
|
const aliases = {
|
|
45
40
|
add: 'agent:add',
|
|
46
41
|
remove: 'agent:remove',
|
|
47
|
-
ls: 'agent
|
|
48
|
-
list: 'agent
|
|
42
|
+
ls: 'agent',
|
|
43
|
+
list: 'agent',
|
|
44
|
+
'agent:ls': 'agent',
|
|
45
|
+
'agent:list': 'agent',
|
|
49
46
|
'-h': 'help',
|
|
50
47
|
'--help': 'help',
|
|
48
|
+
// Only as the command itself: `nordhavn up -v` stays the debug flag.
|
|
49
|
+
'-v': 'version',
|
|
51
50
|
'--version': 'version',
|
|
52
51
|
'-V': 'version',
|
|
53
52
|
};
|
|
@@ -65,21 +64,15 @@ const commands = {
|
|
|
65
64
|
init,
|
|
66
65
|
link,
|
|
67
66
|
unlink,
|
|
67
|
+
agent: show,
|
|
68
68
|
'agent:add': removedAgentCommand,
|
|
69
|
-
'agent:remove':
|
|
69
|
+
'agent:remove': removedAgentCommand,
|
|
70
70
|
'agent:relink': removedAgentCommand,
|
|
71
|
-
'agent:ls': list,
|
|
72
71
|
folder: folderCommand,
|
|
73
72
|
'folder:add': folderCommand,
|
|
74
73
|
'folder:rm': folderCommand,
|
|
75
74
|
'folder:ls': folderCommand,
|
|
76
75
|
'folder:help': folderCommand,
|
|
77
|
-
'agent:help': async () => {
|
|
78
|
-
showHelp('nordhavn agent <action> [args]', 'Manage agents', [
|
|
79
|
-
helpOpt(cyan('ls'), 'List the agent of this runner'),
|
|
80
|
-
helpOpt(`${cyan('remove')} ${dim('<slug>')}`, 'Remove an agent'),
|
|
81
|
-
], ['nordhavn agent ls', 'nordhavn link AB7F2QXR']);
|
|
82
|
-
},
|
|
83
76
|
up: (c) => up({ ref: c.subarg, wantsHelp: wantsHelpFlag(c), debug: wantsDebug(c), detach: wantsDetach(c) }),
|
|
84
77
|
ps,
|
|
85
78
|
down,
|
|
@@ -105,24 +98,21 @@ function printRootHelp() {
|
|
|
105
98
|
// padding to drift out of sync.
|
|
106
99
|
const sections = [
|
|
107
100
|
{ title: 'Runtime', rows: [
|
|
108
|
-
[
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[cyan('ps'), 'Show
|
|
112
|
-
[
|
|
113
|
-
[
|
|
101
|
+
[cyan('up'), 'Bring the agent online (foreground)'],
|
|
102
|
+
[cyan('up -d'), 'Bring the agent online in the background'],
|
|
103
|
+
[cyan('down'), 'Take the agent offline'],
|
|
104
|
+
[cyan('ps'), 'Show the agent\'s status'],
|
|
105
|
+
[cyan('logs'), 'Tail the agent\'s log live (--once to dump)'],
|
|
106
|
+
[cyan('restart'), 'Restart the agent in the background'],
|
|
114
107
|
[`${cyan('relay')} ${dim('[off]')}`, 'Git relay: push for you from here (off disconnects)'],
|
|
115
108
|
] },
|
|
116
109
|
{ title: 'Setup', rows: [
|
|
117
110
|
[cyan('init'), 'Configure this runner (studio URL + home)'],
|
|
118
|
-
[`${cyan('link')} ${dim('<code>')}`, 'Pair this
|
|
119
|
-
[
|
|
111
|
+
[`${cyan('link')} ${dim('<code>')}`, 'Pair this runner with an agent (replaces the current one)'],
|
|
112
|
+
[cyan('unlink'), 'Remove the pairing and its agent'],
|
|
113
|
+
[cyan('agent'), 'Show the agent of this runner'],
|
|
120
114
|
[`${cyan('update')} ${dim('[--check]')}`, 'Install the latest runner release'],
|
|
121
|
-
[cyan('--version')
|
|
122
|
-
] },
|
|
123
|
-
{ title: 'Agents', rows: [
|
|
124
|
-
[cyan('agent ls'), 'List the agent of this runner'],
|
|
125
|
-
[`${cyan('agent remove')} ${dim('<slug>')}`, 'Remove an agent'],
|
|
115
|
+
[`${cyan('-v')}, ${cyan('--version')}`, 'Print the installed version'],
|
|
126
116
|
] },
|
|
127
117
|
{ title: 'Folders', rows: [
|
|
128
118
|
[cyan('folder ls'), 'List folders and the projects they expose'],
|
|
@@ -142,4 +132,6 @@ function printRootHelp() {
|
|
|
142
132
|
}
|
|
143
133
|
console.log('');
|
|
144
134
|
}
|
|
135
|
+
console.log(dim(' One runner hosts one agent. Another agent on this machine gets its own profile:'));
|
|
136
|
+
console.log(dim(` ${cyan('NORDHAVN_PROFILE=<name> nordhavn init')}, then ${cyan('nordhavn link <code>')}.`) + '\n');
|
|
145
137
|
}
|
package/dist/runtime/up.js
CHANGED
|
@@ -35,16 +35,14 @@ import { detectInstallKind } from '../update/install-kind.js';
|
|
|
35
35
|
import { createRuntimeUpdater, updateHint } from '../update/policy.js';
|
|
36
36
|
import { RESTART_SIGNAL, canSignalRestart } from '../update/peers.js';
|
|
37
37
|
import { RESTART_EXIT_CODE, SUPERVISED_ENV, supervise } from '../update/supervisor.js';
|
|
38
|
-
import { UPDATE_CHECK_INTERVAL_MS } from '../update/updater.js';
|
|
39
38
|
/** The host tools, warming the codebase index after a git tool moved a checkout's files. */
|
|
40
39
|
const toolProvider = withSonarPrewarm(hostToolProvider);
|
|
41
40
|
export async function up(opts) {
|
|
42
41
|
if (opts.wantsHelp) {
|
|
43
|
-
showHelp('nordhavn up [
|
|
44
|
-
helpOpt(dim('[agent]'), 'Bring only this agent up (optional, all enabled if omitted). Use slug@organisation when a slug exists in more than one'),
|
|
42
|
+
showHelp('nordhavn up [-d] [--debug]', 'Bring the agent of this runner online in the studio', [
|
|
45
43
|
helpOpt(dim('--detach, -d'), 'Run in the background; the terminal returns immediately'),
|
|
46
44
|
helpOpt(dim('--debug, -v'), 'Verbose event log (inference + tool timings, reconnect details)'),
|
|
47
|
-
], ['nordhavn up', 'nordhavn up
|
|
45
|
+
], ['nordhavn up', 'nordhavn up -d']);
|
|
48
46
|
return;
|
|
49
47
|
}
|
|
50
48
|
// A foreground run of a release install is a thin supervisor around the real
|
|
@@ -98,7 +96,7 @@ export async function up(opts) {
|
|
|
98
96
|
if (config.agents.length === 0)
|
|
99
97
|
console.log(red(' No agent configured. Run `nordhavn link <code>` with a code from the agent\'s page in the studio.\n'));
|
|
100
98
|
else
|
|
101
|
-
console.log(red('
|
|
99
|
+
console.log(red(' The agent of this runner is disabled.\n'));
|
|
102
100
|
process.exit(1);
|
|
103
101
|
return;
|
|
104
102
|
}
|
|
@@ -116,7 +114,7 @@ export async function up(opts) {
|
|
|
116
114
|
console.log(dim(` Run \`nordhavn link <code>\` with a code from that organisation.`));
|
|
117
115
|
}
|
|
118
116
|
if (pairable.length === 0) {
|
|
119
|
-
console.log(red('\n
|
|
117
|
+
console.log(red('\n The agent has no matching pairing on this runner.\n'));
|
|
120
118
|
process.exit(1);
|
|
121
119
|
return;
|
|
122
120
|
}
|
|
@@ -142,7 +140,7 @@ export async function up(opts) {
|
|
|
142
140
|
runnable.push(agent);
|
|
143
141
|
}
|
|
144
142
|
if (runnable.length === 0) {
|
|
145
|
-
console.log(red('\n
|
|
143
|
+
console.log(red('\n The agent is already running. See `nordhavn ps`.\n'));
|
|
146
144
|
process.exit(1);
|
|
147
145
|
return;
|
|
148
146
|
}
|
|
@@ -340,7 +338,7 @@ export async function up(opts) {
|
|
|
340
338
|
if (live <= 0 || connectedCount < live)
|
|
341
339
|
return;
|
|
342
340
|
welcomeShown = true;
|
|
343
|
-
welcome(
|
|
341
|
+
welcome(agentRef(config, runnable[0]));
|
|
344
342
|
};
|
|
345
343
|
for (const agent of runnable) {
|
|
346
344
|
// Local identity for everything file- and map-keyed. Tracked in a mutable
|
|
@@ -671,7 +669,7 @@ export async function up(opts) {
|
|
|
671
669
|
// looks healthy in `ps` while doing nothing at all.
|
|
672
670
|
if (stoppedAgents.size >= totalAgents && !shuttingDown) {
|
|
673
671
|
console.log('');
|
|
674
|
-
console.log(red(
|
|
672
|
+
console.log(red(' The agent stopped - nothing left to run.\n'));
|
|
675
673
|
process.exit(1);
|
|
676
674
|
}
|
|
677
675
|
// The remaining agents may already all be connected, in which case this
|
|
@@ -1180,8 +1178,7 @@ export async function up(opts) {
|
|
|
1180
1178
|
process.on(RESTART_SIGNAL, () => updater.requestRestart());
|
|
1181
1179
|
// Besides the studio's announcement on connect: look for a release now and
|
|
1182
1180
|
// then, for a runtime that stays connected for days.
|
|
1183
|
-
|
|
1184
|
-
setInterval(() => { void updater.check(); }, UPDATE_CHECK_INTERVAL_MS).unref();
|
|
1181
|
+
updater.schedule();
|
|
1185
1182
|
// Heartbeat: every 30s, ping live sockets and recycle stale ones.
|
|
1186
1183
|
// Connecting sockets are left alone - connectWebSocket's own connect-timeout
|
|
1187
1184
|
// guards a stalled handshake. Closed sockets are already being reconnected
|
|
@@ -1253,7 +1250,7 @@ function launchDetached(config, agents, debug) {
|
|
|
1253
1250
|
}
|
|
1254
1251
|
console.log('');
|
|
1255
1252
|
if (started > 0) {
|
|
1256
|
-
console.log(` ${green(
|
|
1253
|
+
console.log(` ${green('The agent runs in the background.')}`);
|
|
1257
1254
|
console.log(dim(' `nordhavn ps` to view status · `nordhavn logs` to follow output · `nordhavn down` to stop.\n'));
|
|
1258
1255
|
}
|
|
1259
1256
|
else {
|
package/dist/update/install.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ import { type ReleaseManifest } from './manifest.js';
|
|
|
5
5
|
* crashed install must not block every later one.
|
|
6
6
|
*/
|
|
7
7
|
export declare function acquireLock(path: string, staleMs?: number): (() => void) | null;
|
|
8
|
+
/**
|
|
9
|
+
* Why npm cannot replace the install as the current user, or null when it can:
|
|
10
|
+
* npm needs write access to the package folder and the scope folder around it.
|
|
11
|
+
* A runner installed with `sudo npm i -g` is owned by root, and every attempt
|
|
12
|
+
* would end in EACCES.
|
|
13
|
+
*/
|
|
14
|
+
export declare function installNotWritable(packageDir: string, platform?: NodeJS.Platform): string | null;
|
|
15
|
+
/** The command that gives a root-owned install back to the current user. */
|
|
16
|
+
export declare function ownershipFix(packageDir: string): string;
|
|
8
17
|
/**
|
|
9
18
|
* Arguments for the global install. npm 12 blocks install scripts unless
|
|
10
19
|
* allowed; ffmpeg's platform package only marks its binary executable, which
|
package/dist/update/install.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile, execFileSync } from 'node:child_process';
|
|
2
|
-
import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
2
|
+
import { accessSync, closeSync, constants as fsConstants, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { basename, delimiter, dirname, join } from 'node:path';
|
|
5
5
|
import { isNewerVersion } from '../utils/format.js';
|
|
@@ -78,6 +78,35 @@ async function waitForLock(path, timeoutMs = LOCK_WAIT_MS, pollMs = 1000) {
|
|
|
78
78
|
await new Promise(resolve => setTimeout(resolve, pollMs));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Why npm cannot replace the install as the current user, or null when it can:
|
|
83
|
+
* npm needs write access to the package folder and the scope folder around it.
|
|
84
|
+
* A runner installed with `sudo npm i -g` is owned by root, and every attempt
|
|
85
|
+
* would end in EACCES.
|
|
86
|
+
*/
|
|
87
|
+
export function installNotWritable(packageDir, platform = process.platform) {
|
|
88
|
+
if (platform === 'win32')
|
|
89
|
+
return null;
|
|
90
|
+
for (const dir of [dirname(packageDir), packageDir]) {
|
|
91
|
+
try {
|
|
92
|
+
accessSync(dir, fsConstants.W_OK);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return `${dir} is not writable by this user (installed with sudo?)`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
function assertWritable(packageDir) {
|
|
101
|
+
const reason = installNotWritable(packageDir);
|
|
102
|
+
if (reason)
|
|
103
|
+
throw new Error(`${reason}; fix: ${ownershipFix(packageDir)}`);
|
|
104
|
+
}
|
|
105
|
+
/** The command that gives a root-owned install back to the current user. */
|
|
106
|
+
export function ownershipFix(packageDir) {
|
|
107
|
+
const user = process.env.USER || '$(whoami)';
|
|
108
|
+
return `sudo chown -R ${user} "${dirname(packageDir)}"`;
|
|
109
|
+
}
|
|
81
110
|
/**
|
|
82
111
|
* The npm that belongs to the node running this process, run through that
|
|
83
112
|
* node: the npm first on PATH may belong to another node (nvm) and install
|
|
@@ -158,6 +187,7 @@ export async function performUpdate(opts) {
|
|
|
158
187
|
const onDisk = readPackageVersion(opts.packageDir);
|
|
159
188
|
if (onDisk && !isNewerVersion(opts.manifest.version, onDisk))
|
|
160
189
|
return 'already-installed';
|
|
190
|
+
assertWritable(opts.packageDir);
|
|
161
191
|
opts.onStep?.(`downloading ${opts.manifest.url}`);
|
|
162
192
|
const data = await downloadTarball(opts.manifest);
|
|
163
193
|
work = mkdtempSync(join(tmpdir(), 'nordhavn-update-'));
|
|
@@ -2,12 +2,22 @@ export interface ReleaseManifest {
|
|
|
2
2
|
version: string;
|
|
3
3
|
url: string;
|
|
4
4
|
sha512: string;
|
|
5
|
-
size
|
|
5
|
+
/** Byte size of the tarball; the npm registry does not give it. */
|
|
6
|
+
size?: number;
|
|
6
7
|
releasedAt?: string;
|
|
7
8
|
}
|
|
8
|
-
/**
|
|
9
|
-
export declare
|
|
10
|
-
/**
|
|
9
|
+
/** The package the runner is published as. */
|
|
10
|
+
export declare const RUNNER_PACKAGE = "@nordhavnhq/runner";
|
|
11
|
+
/**
|
|
12
|
+
* Where this runner reads the latest release from: the npm registry
|
|
13
|
+
* (NORDHAVN_UPDATE_REGISTRY overrides it), or NORDHAVN_UPDATE_MANIFEST_URL
|
|
14
|
+
* when set (tests, staging).
|
|
15
|
+
*/
|
|
16
|
+
export declare function manifestUrl(env?: NodeJS.ProcessEnv): string;
|
|
17
|
+
/**
|
|
18
|
+
* Validates a parsed manifest, the bucket format or an npm registry version
|
|
19
|
+
* document; throws with what is wrong.
|
|
20
|
+
*/
|
|
11
21
|
export declare function parseManifest(data: unknown): ReleaseManifest;
|
|
12
22
|
export declare function fetchManifest(url: string): Promise<ReleaseManifest>;
|
|
13
23
|
/** Base64 sha512 of the bytes, the manifest's format. */
|
package/dist/update/manifest.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
|
|
2
|
+
/** The package the runner is published as. */
|
|
3
|
+
export const RUNNER_PACKAGE = '@nordhavnhq/runner';
|
|
4
|
+
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
3
5
|
const FETCH_TIMEOUT_MS = 30_000;
|
|
4
6
|
const DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Where this runner reads the latest release from: the npm registry
|
|
9
|
+
* (NORDHAVN_UPDATE_REGISTRY overrides it), or NORDHAVN_UPDATE_MANIFEST_URL
|
|
10
|
+
* when set (tests, staging).
|
|
11
|
+
*/
|
|
12
|
+
export function manifestUrl(env = process.env) {
|
|
7
13
|
const override = env.NORDHAVN_UPDATE_MANIFEST_URL?.trim();
|
|
8
14
|
if (override)
|
|
9
15
|
return override;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return studioUrl.replace(/\/+$/, '') + MANIFEST_PATH;
|
|
16
|
+
const registry = (env.NORDHAVN_UPDATE_REGISTRY?.trim() || DEFAULT_REGISTRY).replace(/\/+$/, '');
|
|
17
|
+
return `${registry}/${RUNNER_PACKAGE.replace('/', '%2f')}/latest`;
|
|
13
18
|
}
|
|
14
19
|
/** Plain http is only accepted for a server on this machine (a test server). */
|
|
15
20
|
function isAllowedUrl(raw) {
|
|
@@ -24,18 +29,32 @@ function isAllowedUrl(raw) {
|
|
|
24
29
|
return true;
|
|
25
30
|
return url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
26
31
|
}
|
|
27
|
-
/**
|
|
32
|
+
/** An npm registry version document as a manifest: only a sha512 integrity is accepted. */
|
|
33
|
+
function fromNpmDoc(doc) {
|
|
34
|
+
const integrity = typeof doc.dist?.integrity === 'string' ? doc.dist.integrity : '';
|
|
35
|
+
const sha512 = integrity.split(/\s+/).find(i => i.startsWith('sha512-'))?.slice('sha512-'.length);
|
|
36
|
+
return {
|
|
37
|
+
version: typeof doc.version === 'string' ? doc.version : undefined,
|
|
38
|
+
url: typeof doc.dist?.tarball === 'string' ? doc.dist.tarball : undefined,
|
|
39
|
+
sha512,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates a parsed manifest, the bucket format or an npm registry version
|
|
44
|
+
* document; throws with what is wrong.
|
|
45
|
+
*/
|
|
28
46
|
export function parseManifest(data) {
|
|
29
|
-
|
|
30
|
-
if (!m || typeof m !== 'object')
|
|
47
|
+
if (!data || typeof data !== 'object')
|
|
31
48
|
throw new Error('manifest is not an object');
|
|
49
|
+
const npm = 'dist' in data;
|
|
50
|
+
const m = npm ? fromNpmDoc(data) : data;
|
|
32
51
|
if (typeof m.version !== 'string' || !/^\d+\.\d+\.\d+/.test(m.version))
|
|
33
52
|
throw new Error('manifest has no valid version');
|
|
34
53
|
if (typeof m.url !== 'string' || !isAllowedUrl(m.url))
|
|
35
54
|
throw new Error('manifest url must be https');
|
|
36
55
|
if (typeof m.sha512 !== 'string' || !m.sha512)
|
|
37
56
|
throw new Error('manifest has no sha512');
|
|
38
|
-
if (typeof m.size !== 'number' || !Number.isFinite(m.size) || m.size <= 0)
|
|
57
|
+
if (!npm && (typeof m.size !== 'number' || !Number.isFinite(m.size) || m.size <= 0))
|
|
39
58
|
throw new Error('manifest has no valid size');
|
|
40
59
|
return { version: m.version, url: m.url, sha512: m.sha512, size: m.size, releasedAt: m.releasedAt };
|
|
41
60
|
}
|
|
@@ -53,7 +72,7 @@ export function sha512Base64(data) {
|
|
|
53
72
|
}
|
|
54
73
|
/** Throws unless the bytes are exactly what the manifest describes. */
|
|
55
74
|
export function verifyTarball(data, manifest) {
|
|
56
|
-
if (data.byteLength !== manifest.size) {
|
|
75
|
+
if (manifest.size !== undefined && data.byteLength !== manifest.size) {
|
|
57
76
|
throw new Error(`tarball size ${data.byteLength} does not match the manifest (${manifest.size})`);
|
|
58
77
|
}
|
|
59
78
|
const expected = manifest.sha512.replace(/^sha512-/, '');
|
package/dist/update/policy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VERSION } from '../utils/format.js';
|
|
2
2
|
import { currentPackageDir, detectInstallKind, readPackageVersion, runningPackageDir } from './install-kind.js';
|
|
3
|
-
import { performUpdate } from './install.js';
|
|
3
|
+
import { installNotWritable, performUpdate } from './install.js';
|
|
4
4
|
import { fetchManifest, manifestUrl } from './manifest.js';
|
|
5
5
|
import { signalRestart } from './peers.js';
|
|
6
6
|
import { Updater } from './updater.js';
|
|
@@ -19,20 +19,16 @@ export function updateHint(kind) {
|
|
|
19
19
|
export function createRuntimeUpdater(opts) {
|
|
20
20
|
const kind = detectInstallKind();
|
|
21
21
|
const optedOut = autoUpdateOptedOut(opts.config);
|
|
22
|
-
const url = manifestUrl(
|
|
22
|
+
const url = manifestUrl();
|
|
23
23
|
const manualReason = kind.kind !== 'global'
|
|
24
24
|
? kind.reason
|
|
25
|
-
: optedOut ? 'automatic updates are off' :
|
|
25
|
+
: optedOut ? 'automatic updates are off' : installNotWritable(kind.packageDir);
|
|
26
26
|
const packageDir = kind.kind === 'global' ? kind.packageDir : runningPackageDir();
|
|
27
27
|
const updater = new Updater({
|
|
28
28
|
currentVersion: VERSION,
|
|
29
29
|
enabled: manualReason === null,
|
|
30
30
|
isIdle: opts.isIdle,
|
|
31
|
-
fetchLatest: () =>
|
|
32
|
-
if (!url)
|
|
33
|
-
return Promise.reject(new Error('no manifest url'));
|
|
34
|
-
return fetchManifest(url);
|
|
35
|
-
},
|
|
31
|
+
fetchLatest: () => fetchManifest(url),
|
|
36
32
|
install: async (manifest) => {
|
|
37
33
|
if (kind.kind !== 'global')
|
|
38
34
|
throw new Error(`not a global install: ${kind.reason}`);
|
|
@@ -45,5 +41,9 @@ export function createRuntimeUpdater(opts) {
|
|
|
45
41
|
restart: opts.restart,
|
|
46
42
|
log: opts.log,
|
|
47
43
|
});
|
|
44
|
+
// A release install that cannot update itself (root-owned, opted out) says so
|
|
45
|
+
// once at start; a linked or dev run is expected not to.
|
|
46
|
+
if (kind.kind === 'global' && manualReason)
|
|
47
|
+
opts.log(`no automatic update: ${manualReason}`);
|
|
48
48
|
return { updater, kind, manualReason };
|
|
49
49
|
}
|
package/dist/update/updater.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ReleaseManifest } from './manifest.js';
|
|
2
2
|
import type { PerformUpdateResult } from './install.js';
|
|
3
|
+
/** How often a running runtime asks npm for a newer release (a small JSON request). */
|
|
3
4
|
export declare const UPDATE_CHECK_INTERVAL_MS: number;
|
|
5
|
+
/** The first check after start: the studio's announcement on connect may be missing or behind. */
|
|
6
|
+
export declare const UPDATE_FIRST_CHECK_MS: number;
|
|
4
7
|
export interface UpdaterDeps {
|
|
5
8
|
currentVersion: string;
|
|
6
9
|
/** Global install and not opted out: install on its own. Otherwise only `requestRestart` acts. */
|
|
@@ -29,6 +32,11 @@ export declare class Updater {
|
|
|
29
32
|
private now;
|
|
30
33
|
/** A newer version was announced (the studio's `connected` frame). */
|
|
31
34
|
offer(version: string | null | undefined): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks npm shortly after start, then every UPDATE_CHECK_INTERVAL_MS, for
|
|
37
|
+
* a runtime that stays up for days. Nothing when updates are not enabled.
|
|
38
|
+
*/
|
|
39
|
+
schedule(): void;
|
|
32
40
|
/** The periodic check: read the manifest itself. */
|
|
33
41
|
check(): Promise<void>;
|
|
34
42
|
/** A chat or task ended: an install or restart that waited for idle may go now. */
|
package/dist/update/updater.js
CHANGED
|
@@ -6,7 +6,10 @@ import { isNewerVersion } from '../utils/format.js';
|
|
|
6
6
|
// chat or task is running, and restarts into it once idle again (a run may
|
|
7
7
|
// have started during the install). A failure is logged and left for the next
|
|
8
8
|
// trigger; the process keeps running the version it has.
|
|
9
|
-
|
|
9
|
+
/** How often a running runtime asks npm for a newer release (a small JSON request). */
|
|
10
|
+
export const UPDATE_CHECK_INTERVAL_MS = 60 * 60_000;
|
|
11
|
+
/** The first check after start: the studio's announcement on connect may be missing or behind. */
|
|
12
|
+
export const UPDATE_FIRST_CHECK_MS = 2 * 60_000;
|
|
10
13
|
/** After a failed attempt, triggers within this window are ignored (the periodic check is not). */
|
|
11
14
|
const FAILURE_BACKOFF_MS = 60 * 60_000;
|
|
12
15
|
export class Updater {
|
|
@@ -32,6 +35,16 @@ export class Updater {
|
|
|
32
35
|
this.target = version;
|
|
33
36
|
return this.attempt(false);
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks npm shortly after start, then every UPDATE_CHECK_INTERVAL_MS, for
|
|
40
|
+
* a runtime that stays up for days. Nothing when updates are not enabled.
|
|
41
|
+
*/
|
|
42
|
+
schedule() {
|
|
43
|
+
if (!this.deps.enabled)
|
|
44
|
+
return;
|
|
45
|
+
setTimeout(() => { void this.check(); }, UPDATE_FIRST_CHECK_MS).unref();
|
|
46
|
+
setInterval(() => { void this.check(); }, UPDATE_CHECK_INTERVAL_MS).unref();
|
|
47
|
+
}
|
|
35
48
|
/** The periodic check: read the manifest itself. */
|
|
36
49
|
async check() {
|
|
37
50
|
if (!this.deps.enabled || this.installing || this.restartPending)
|
package/dist/utils/format.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function isNewerVersion(a: string, b: string): boolean;
|
|
|
24
24
|
* that updates this kind of install (see update/policy.ts). */
|
|
25
25
|
export declare function updateNotice(current: string, latest: string, how?: string): void;
|
|
26
26
|
export declare function contractNotice(ours: string, studios: string): void;
|
|
27
|
-
export declare function welcome(
|
|
27
|
+
export declare function welcome(agent: string): void;
|
|
28
28
|
export declare function log(sym: LogSymbol, agent: string, msg: string): void;
|
|
29
29
|
export declare function truncate(s: string, len?: number): string;
|
|
30
30
|
export declare function formatCost(micros: number): string;
|
package/dist/utils/format.js
CHANGED
|
@@ -74,8 +74,8 @@ export function contractNotice(ours, studios) {
|
|
|
74
74
|
console.log(` ${dim('one of the two is behind; update the runner with')} ${cyan('nordhavn update')}`);
|
|
75
75
|
console.log('');
|
|
76
76
|
}
|
|
77
|
-
export function welcome(
|
|
78
|
-
const agentStr = `${
|
|
77
|
+
export function welcome(agent) {
|
|
78
|
+
const agentStr = `${agent} online`;
|
|
79
79
|
console.log('');
|
|
80
80
|
console.log(` ${dim('─'.repeat(54))}`);
|
|
81
81
|
console.log(` ${green('◆')} ${accent('welcome to nordhavn')} ${dim('·')} ${cyan(agentStr)}`);
|
package/dist/version.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordhavnhq/runner-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.0",
|
|
4
4
|
"description": "Nordhavn OS agent browser: Playwright sessions, the browser tools, the confirm-first guard and the live view, for the runner and the browser host",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -85,7 +85,7 @@ export function fatalCloseHint(code, reason) {
|
|
|
85
85
|
case CLOSE_HOST_REVOKED:
|
|
86
86
|
return `this runner was revoked in the studio - pair again with \`nordhavn link <code>\``;
|
|
87
87
|
case CLOSE_AGENT_DELETED:
|
|
88
|
-
return `this agent no longer exists in the studio - remove it with \`nordhavn
|
|
88
|
+
return `this agent no longer exists in the studio - connect another one with \`nordhavn link <code>\`, or remove it with \`nordhavn unlink\``;
|
|
89
89
|
default:
|
|
90
90
|
return reason || `closed with code ${code}`;
|
|
91
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordhavnhq/runner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.0",
|
|
4
4
|
"description": "Nordhavn OS runner CLI: runs agents headless on a host and supplies the host tools",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
26
26
|
"@vscode/ripgrep": "^1.18.0",
|
|
27
27
|
"mysql2": "^3.24.6",
|
|
28
|
-
"@nordhavnhq/runner-runtime": "0.
|
|
29
|
-
"@nordhavnhq/runner-browser": "0.
|
|
28
|
+
"@nordhavnhq/runner-runtime": "0.97.0",
|
|
29
|
+
"@nordhavnhq/runner-browser": "0.97.0"
|
|
30
30
|
},
|
|
31
31
|
"bundleDependencies": [
|
|
32
32
|
"@nordhavnhq/runner-runtime",
|