@nordhavnhq/runner 0.96.0 → 0.98.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/git-credential.d.ts +2 -0
- package/dist/cli/git-credential.js +64 -0
- package/dist/cli/update.js +28 -16
- package/dist/index.js +6 -1
- package/dist/runtime/dev-start.js +2 -1
- package/dist/runtime/git-credentials.d.ts +41 -0
- package/dist/runtime/git-credentials.js +72 -0
- package/dist/runtime/up.js +1 -3
- package/dist/tools/console.d.ts +9 -1
- package/dist/tools/console.js +18 -4
- package/dist/tools/git.d.ts +2 -1
- package/dist/tools/git.js +11 -4
- 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/version.json +3 -3
- package/node_modules/@nordhavnhq/runner-browser/package.json +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/package.json +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { getConfigPath, hostedAgent } from '../config.js';
|
|
3
|
+
import { formatCredentialOutput, GIT_RUN_ENV, parseCredentialInput } from '../runtime/git-credentials.js';
|
|
4
|
+
/**
|
|
5
|
+
* `nordhavn git-credential [--config <path>] get`: the git credential helper
|
|
6
|
+
* of a run (runtime/git-credentials.ts). git starts it, it is not for people.
|
|
7
|
+
*
|
|
8
|
+
* For `get` on https://github.com it asks the studio for the token of the
|
|
9
|
+
* person the run (`NORDHAVN_GIT_RUN`) works for and prints it the way git
|
|
10
|
+
* reads it. Refused (nobody connected GitHub, the run ended), it says why on
|
|
11
|
+
* stderr, where git shows it, and answers `quit=1` so git asks nobody else.
|
|
12
|
+
* `store` and `erase` do nothing: the studio keeps the token, not this machine.
|
|
13
|
+
*/
|
|
14
|
+
async function readStdin() {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
for await (const chunk of process.stdin)
|
|
17
|
+
chunks.push(chunk);
|
|
18
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
19
|
+
}
|
|
20
|
+
function refuse(reason) {
|
|
21
|
+
process.stderr.write(`nordhavn: ${reason}\n`);
|
|
22
|
+
process.stdout.write('quit=1\n');
|
|
23
|
+
}
|
|
24
|
+
export async function gitCredential(ctx) {
|
|
25
|
+
const args = ctx.cmdArgs;
|
|
26
|
+
const at = args.indexOf('--config');
|
|
27
|
+
const configPath = at >= 0 ? args[at + 1] : getConfigPath();
|
|
28
|
+
const operation = args.filter((arg, i) => !arg.startsWith('--') && (at < 0 || i !== at + 1))[0];
|
|
29
|
+
const input = parseCredentialInput(await readStdin());
|
|
30
|
+
if (operation !== 'get')
|
|
31
|
+
return;
|
|
32
|
+
if (input.protocol !== 'https' || input.host !== 'github.com')
|
|
33
|
+
return;
|
|
34
|
+
const queueUid = process.env[GIT_RUN_ENV];
|
|
35
|
+
if (!queueUid)
|
|
36
|
+
return refuse('this git runs outside an agent run, so there is no GitHub account to use.');
|
|
37
|
+
let config;
|
|
38
|
+
try {
|
|
39
|
+
config = JSON.parse(await readFile(configPath, 'utf8'));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return refuse(`cannot read the runner config at ${configPath}.`);
|
|
43
|
+
}
|
|
44
|
+
const agent = hostedAgent(config);
|
|
45
|
+
if (!agent || !config.studioUrl)
|
|
46
|
+
return refuse('this runner hosts no agent.');
|
|
47
|
+
let response;
|
|
48
|
+
try {
|
|
49
|
+
response = await fetch(`${config.studioUrl.replace(/\/+$/, '')}/api/agents/git/credential`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'Authorization': `Bearer ${agent.token}`, 'Content-Type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ queueUid, host: input.host }),
|
|
53
|
+
signal: AbortSignal.timeout(20_000),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return refuse(`the studio did not answer (${err.message}).`);
|
|
58
|
+
}
|
|
59
|
+
const body = await response.json().catch(() => ({}));
|
|
60
|
+
if (!response.ok || !body.username || !body.password) {
|
|
61
|
+
return refuse(body.message ?? `the studio refused the GitHub credential (${response.status}).`);
|
|
62
|
+
}
|
|
63
|
+
process.stdout.write(formatCredentialOutput({ username: body.username, password: body.password, expiresAt: body.expiresAt ?? null }));
|
|
64
|
+
}
|
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
|
@@ -11,6 +11,7 @@ import { ps } from './cli/ps.js';
|
|
|
11
11
|
import { down, restart } from './cli/lifecycle.js';
|
|
12
12
|
import { logs } from './cli/logs.js';
|
|
13
13
|
import { relay } from './cli/relay.js';
|
|
14
|
+
import { gitCredential } from './cli/git-credential.js';
|
|
14
15
|
import { update } from './cli/update.js';
|
|
15
16
|
import { migrateLegacyDir } from './paths.js';
|
|
16
17
|
// Before anything reads config: move a pre-rename ~/.justmade-studio (or
|
|
@@ -45,6 +46,8 @@ const aliases = {
|
|
|
45
46
|
'agent:list': 'agent',
|
|
46
47
|
'-h': 'help',
|
|
47
48
|
'--help': 'help',
|
|
49
|
+
// Only as the command itself: `nordhavn up -v` stays the debug flag.
|
|
50
|
+
'-v': 'version',
|
|
48
51
|
'--version': 'version',
|
|
49
52
|
'-V': 'version',
|
|
50
53
|
};
|
|
@@ -77,6 +80,8 @@ const commands = {
|
|
|
77
80
|
restart,
|
|
78
81
|
logs,
|
|
79
82
|
relay,
|
|
83
|
+
// Started by git (runtime/git-credentials.ts), not listed in the help.
|
|
84
|
+
'git-credential': gitCredential,
|
|
80
85
|
update,
|
|
81
86
|
version: async () => { console.log(VERSION); },
|
|
82
87
|
};
|
|
@@ -110,7 +115,7 @@ function printRootHelp() {
|
|
|
110
115
|
[cyan('unlink'), 'Remove the pairing and its agent'],
|
|
111
116
|
[cyan('agent'), 'Show the agent of this runner'],
|
|
112
117
|
[`${cyan('update')} ${dim('[--check]')}`, 'Install the latest runner release'],
|
|
113
|
-
[cyan('--version')
|
|
118
|
+
[`${cyan('-v')}, ${cyan('--version')}`, 'Print the installed version'],
|
|
114
119
|
] },
|
|
115
120
|
{ title: 'Folders', rows: [
|
|
116
121
|
[cyan('folder ls'), 'List folders and the projects they expose'],
|
|
@@ -83,7 +83,8 @@ export function devCommandRefusal(command, cwd) {
|
|
|
83
83
|
// One command, nothing chained, piped, redirected, quoted or substituted beside it.
|
|
84
84
|
if (/[;&|`$<>()\\'"]/.test(line))
|
|
85
85
|
return 'A dev command is a single command, without ; & | ` $ < > ( ) \\ or quotes';
|
|
86
|
-
|
|
86
|
+
// A dev server never needs root, also not on a runner that allows sudo.
|
|
87
|
+
const blocked = isBlocked(line, { allowSudo: false });
|
|
87
88
|
if (blocked)
|
|
88
89
|
return blocked;
|
|
89
90
|
if (!isLongRunningCommand(line))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git over https with the GitHub account of the person a run works for.
|
|
3
|
+
*
|
|
4
|
+
* With `NORDHAVN_GIT_CREDENTIALS=studio` in the runner's own environment (the
|
|
5
|
+
* container image sets it) every git the runner starts for a run - its git
|
|
6
|
+
* tools and the agent's shell - gets one credential helper for
|
|
7
|
+
* https://github.com: `nordhavn git-credential`. That helper asks the studio
|
|
8
|
+
* (`POST /api/agents/git/credential`, agent token + the run's queueUid) and
|
|
9
|
+
* hands git the person's token. Helpers from the machine's own git config are
|
|
10
|
+
* reset for github.com, so nothing else (a stored token, the macOS keychain)
|
|
11
|
+
* answers instead and the token is never written to disk.
|
|
12
|
+
*
|
|
13
|
+
* Off (the default on a laptop), git keeps using the machine's own setup: the
|
|
14
|
+
* person's keychain, ssh keys, the git relay.
|
|
15
|
+
*
|
|
16
|
+
* The helper lives in the env as `GIT_CONFIG_COUNT` / `GIT_CONFIG_KEY_n` /
|
|
17
|
+
* `GIT_CONFIG_VALUE_n` (git 2.31+), so no config file of the checkout or the
|
|
18
|
+
* home changes. `NORDHAVN_GIT_RUN` names the run; it is no secret on its own,
|
|
19
|
+
* the agent token stays in the runner's config.
|
|
20
|
+
*/
|
|
21
|
+
export declare const GIT_RUN_ENV = "NORDHAVN_GIT_RUN";
|
|
22
|
+
export declare function studioGitCredentials(env?: NodeJS.ProcessEnv): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The env that points git at the studio credential of run `queueUid`, or
|
|
25
|
+
* `{}` when studio credentials are off or the run has no uid. `cli` is the
|
|
26
|
+
* nordhavn entry script (`process.argv[1]` of the runner).
|
|
27
|
+
*/
|
|
28
|
+
export declare function gitCredentialEnv(queueUid: string | null | undefined, options?: {
|
|
29
|
+
env?: NodeJS.ProcessEnv;
|
|
30
|
+
node?: string;
|
|
31
|
+
cli?: string;
|
|
32
|
+
configPath?: string;
|
|
33
|
+
}): NodeJS.ProcessEnv;
|
|
34
|
+
/** `key=value` lines git hands a credential helper on stdin. */
|
|
35
|
+
export declare function parseCredentialInput(input: string): Record<string, string>;
|
|
36
|
+
/** What the helper prints for git: a credential, or `quit` with a reason on stderr. */
|
|
37
|
+
export declare function formatCredentialOutput(reply: {
|
|
38
|
+
username: string;
|
|
39
|
+
password: string;
|
|
40
|
+
expiresAt: string | null;
|
|
41
|
+
}): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getConfigPath } from '../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Git over https with the GitHub account of the person a run works for.
|
|
4
|
+
*
|
|
5
|
+
* With `NORDHAVN_GIT_CREDENTIALS=studio` in the runner's own environment (the
|
|
6
|
+
* container image sets it) every git the runner starts for a run - its git
|
|
7
|
+
* tools and the agent's shell - gets one credential helper for
|
|
8
|
+
* https://github.com: `nordhavn git-credential`. That helper asks the studio
|
|
9
|
+
* (`POST /api/agents/git/credential`, agent token + the run's queueUid) and
|
|
10
|
+
* hands git the person's token. Helpers from the machine's own git config are
|
|
11
|
+
* reset for github.com, so nothing else (a stored token, the macOS keychain)
|
|
12
|
+
* answers instead and the token is never written to disk.
|
|
13
|
+
*
|
|
14
|
+
* Off (the default on a laptop), git keeps using the machine's own setup: the
|
|
15
|
+
* person's keychain, ssh keys, the git relay.
|
|
16
|
+
*
|
|
17
|
+
* The helper lives in the env as `GIT_CONFIG_COUNT` / `GIT_CONFIG_KEY_n` /
|
|
18
|
+
* `GIT_CONFIG_VALUE_n` (git 2.31+), so no config file of the checkout or the
|
|
19
|
+
* home changes. `NORDHAVN_GIT_RUN` names the run; it is no secret on its own,
|
|
20
|
+
* the agent token stays in the runner's config.
|
|
21
|
+
*/
|
|
22
|
+
export const GIT_RUN_ENV = 'NORDHAVN_GIT_RUN';
|
|
23
|
+
const HELPER_KEY = 'credential.https://github.com.helper';
|
|
24
|
+
export function studioGitCredentials(env = process.env) {
|
|
25
|
+
return env.NORDHAVN_GIT_CREDENTIALS?.trim().toLowerCase() === 'studio';
|
|
26
|
+
}
|
|
27
|
+
/** A word for `sh -c`, in double quotes. */
|
|
28
|
+
function shellWord(value) {
|
|
29
|
+
return `"${value.replace(/(["\\$`])/g, '\\$1')}"`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The env that points git at the studio credential of run `queueUid`, or
|
|
33
|
+
* `{}` when studio credentials are off or the run has no uid. `cli` is the
|
|
34
|
+
* nordhavn entry script (`process.argv[1]` of the runner).
|
|
35
|
+
*/
|
|
36
|
+
export function gitCredentialEnv(queueUid, options = {}) {
|
|
37
|
+
if (!queueUid || !studioGitCredentials(options.env))
|
|
38
|
+
return {};
|
|
39
|
+
const node = options.node ?? process.execPath;
|
|
40
|
+
const cli = options.cli ?? process.argv[1] ?? 'nordhavn';
|
|
41
|
+
// The config path goes on the command line: a command's HOME is the agent's
|
|
42
|
+
// home, where the runner's config is not.
|
|
43
|
+
const configPath = options.configPath ?? getConfigPath();
|
|
44
|
+
return {
|
|
45
|
+
GIT_CONFIG_COUNT: '2',
|
|
46
|
+
// An empty value clears every helper git collected so far for this URL.
|
|
47
|
+
GIT_CONFIG_KEY_0: HELPER_KEY,
|
|
48
|
+
GIT_CONFIG_VALUE_0: '',
|
|
49
|
+
GIT_CONFIG_KEY_1: HELPER_KEY,
|
|
50
|
+
GIT_CONFIG_VALUE_1: `!${shellWord(node)} ${shellWord(cli)} git-credential --config ${shellWord(configPath)}`,
|
|
51
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
52
|
+
[GIT_RUN_ENV]: queueUid,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** `key=value` lines git hands a credential helper on stdin. */
|
|
56
|
+
export function parseCredentialInput(input) {
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const line of input.split('\n')) {
|
|
59
|
+
const at = line.indexOf('=');
|
|
60
|
+
if (at > 0)
|
|
61
|
+
out[line.slice(0, at)] = line.slice(at + 1).replace(/\r$/, '');
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/** What the helper prints for git: a credential, or `quit` with a reason on stderr. */
|
|
66
|
+
export function formatCredentialOutput(reply) {
|
|
67
|
+
const lines = [`username=${reply.username}`, `password=${reply.password}`];
|
|
68
|
+
const expiry = reply.expiresAt ? Math.floor(new Date(reply.expiresAt).getTime() / 1000) : NaN;
|
|
69
|
+
if (Number.isFinite(expiry))
|
|
70
|
+
lines.push(`password_expiry_utc=${expiry}`);
|
|
71
|
+
return `${lines.join('\n')}\n`;
|
|
72
|
+
}
|
package/dist/runtime/up.js
CHANGED
|
@@ -35,7 +35,6 @@ 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) {
|
|
@@ -1179,8 +1178,7 @@ export async function up(opts) {
|
|
|
1179
1178
|
process.on(RESTART_SIGNAL, () => updater.requestRestart());
|
|
1180
1179
|
// Besides the studio's announcement on connect: look for a release now and
|
|
1181
1180
|
// then, for a runtime that stays connected for days.
|
|
1182
|
-
|
|
1183
|
-
setInterval(() => { void updater.check(); }, UPDATE_CHECK_INTERVAL_MS).unref();
|
|
1181
|
+
updater.schedule();
|
|
1184
1182
|
// Heartbeat: every 30s, ping live sockets and recycle stale ones.
|
|
1185
1183
|
// Connecting sockets are left alone - connectWebSocket's own connect-timeout
|
|
1186
1184
|
// guards a stalled handshake. Closed sockets are already being reconnected
|
package/dist/tools/console.d.ts
CHANGED
|
@@ -25,7 +25,15 @@ export declare function commandEnv(context: ToolContext | undefined, base: strin
|
|
|
25
25
|
* result that is no JSON object gets the warning as a last line.
|
|
26
26
|
*/
|
|
27
27
|
export declare function withProjectNode(result: string, node: ProjectNode | null): Promise<string>;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Whether this runner lets an agent use sudo: only when the operator says so
|
|
30
|
+
* with `NORDHAVN_ALLOW_SUDO=1`, as the container image does (the agent owns
|
|
31
|
+
* that machine, docs/runner.md). On a person's own machine it stays blocked.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sudoAllowed(): boolean;
|
|
34
|
+
export declare function isBlocked(command: string, options?: {
|
|
35
|
+
allowSudo?: boolean;
|
|
36
|
+
}): string | null;
|
|
29
37
|
/** Block any attempt to publish commits to a remote from the shell. Exported for tests. */
|
|
30
38
|
export declare function detectGitPush(command: string): string | null;
|
|
31
39
|
export declare function detectPathEscape(command: string, roots: string[], base: string, readRoots?: string[], shellHome?: string): string | null;
|
package/dist/tools/console.js
CHANGED
|
@@ -8,6 +8,7 @@ import { stopAllProcesses, trackProcess, waitForPreview } from '../runtime/proce
|
|
|
8
8
|
import { projectNodeLabel, projectNodeNote, resolveProjectNode, withNodeBin } from '../runtime/project-node.js';
|
|
9
9
|
import { recordTouched, snapshotCheckout } from './_touched.js';
|
|
10
10
|
import { isForcedRecursiveRm, unquote } from './_shell-words.js';
|
|
11
|
+
import { gitCredentialEnv } from '../runtime/git-credentials.js';
|
|
11
12
|
// ─── Long-running / Dev Server Detection ────
|
|
12
13
|
// These patterns indicate a command that starts a persistent server
|
|
13
14
|
// and will never exit on its own (dev servers, watchers, etc.)
|
|
@@ -98,15 +99,15 @@ const runCommandDefinition = {
|
|
|
98
99
|
required: ['command'],
|
|
99
100
|
},
|
|
100
101
|
};
|
|
102
|
+
const SUDO_PATTERN = /\bsudo\b/;
|
|
101
103
|
// Commands that are never allowed
|
|
102
104
|
const BLOCKED_PATTERNS = [
|
|
103
|
-
/\bsudo\b/,
|
|
104
105
|
/\bmkfs\b/,
|
|
105
106
|
/\bdd\s+/,
|
|
106
107
|
/\b:(){ :|:& };:/, // fork bomb
|
|
107
108
|
/\bchmod\s+-R\s+777/,
|
|
108
|
-
/\bcurl\b.*\|\s*(sh|bash)/, // curl pipe to shell
|
|
109
|
-
/\bwget\b.*\|\s*(sh|bash)/,
|
|
109
|
+
/\bcurl\b.*\|\s*(sudo\s+)?(sh|bash)/, // curl pipe to shell
|
|
110
|
+
/\bwget\b.*\|\s*(sudo\s+)?(sh|bash)/,
|
|
110
111
|
];
|
|
111
112
|
/**
|
|
112
113
|
* The variables of the runner's own environment a command an agent starts
|
|
@@ -165,6 +166,8 @@ export function commandEnv(context, base, source = process.env, nodeBin) {
|
|
|
165
166
|
HOME: shellHome(context, base),
|
|
166
167
|
// JUSTMADE_SCRATCH: the pre-rename name, for prompts and scripts that still use it.
|
|
167
168
|
...(context?.scratchRoot ? { NORDHAVN_SCRATCH: context.scratchRoot, JUSTMADE_SCRATCH: context.scratchRoot } : {}),
|
|
169
|
+
// git signs in to GitHub as the person behind this run (runtime/git-credentials.ts).
|
|
170
|
+
...gitCredentialEnv(context?.queueUid),
|
|
168
171
|
};
|
|
169
172
|
return nodeBin ? withNodeBin(out, nodeBin) : out;
|
|
170
173
|
}
|
|
@@ -187,9 +190,20 @@ export async function withProjectNode(result, node) {
|
|
|
187
190
|
catch { /* plain text */ }
|
|
188
191
|
return warning ? `${result}\n${warning}` : result;
|
|
189
192
|
}
|
|
190
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Whether this runner lets an agent use sudo: only when the operator says so
|
|
195
|
+
* with `NORDHAVN_ALLOW_SUDO=1`, as the container image does (the agent owns
|
|
196
|
+
* that machine, docs/runner.md). On a person's own machine it stays blocked.
|
|
197
|
+
*/
|
|
198
|
+
export function sudoAllowed() {
|
|
199
|
+
return process.env.NORDHAVN_ALLOW_SUDO === '1';
|
|
200
|
+
}
|
|
201
|
+
export function isBlocked(command, options = {}) {
|
|
191
202
|
if (isForcedRecursiveRm(command))
|
|
192
203
|
return 'Blocked: a recursive forced rm (rm -rf and its spellings) is not allowed';
|
|
204
|
+
if (!(options.allowSudo ?? sudoAllowed()) && SUDO_PATTERN.test(command)) {
|
|
205
|
+
return `Blocked: command matches restricted pattern ${SUDO_PATTERN}`;
|
|
206
|
+
}
|
|
193
207
|
for (const pattern of BLOCKED_PATTERNS) {
|
|
194
208
|
if (pattern.test(command)) {
|
|
195
209
|
return `Blocked: command matches restricted pattern ${pattern}`;
|
package/dist/tools/git.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ToolDefinition } from '@nordhavnhq/runner-runtime';
|
|
2
2
|
import type { ToolContext } from './index.js';
|
|
3
|
-
|
|
3
|
+
/** `env` goes on top of the runner's own, e.g. the run's git credential (`remoteEnv`). */
|
|
4
|
+
export declare function runGit(cwd: string, args: string[], env?: NodeJS.ProcessEnv): Promise<{
|
|
4
5
|
stdout: string;
|
|
5
6
|
stderr: string;
|
|
6
7
|
}>;
|
package/dist/tools/git.js
CHANGED
|
@@ -6,6 +6,7 @@ import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
|
6
6
|
import { splitOwnFiles } from '@nordhavnhq/runner-runtime';
|
|
7
7
|
import { githubRepo, relayBranch, RELAY_BUNDLE_MAX_BYTES } from '../runtime/git-relay.js';
|
|
8
8
|
import { unpushedAnnotatedTags } from '../runtime/git-unpushed.js';
|
|
9
|
+
import { gitCredentialEnv } from '../runtime/git-credentials.js';
|
|
9
10
|
import { hasWriteScope, missingScopeError, missingWriteScope, resolveInCheckout, resolveInJail } from './_jail.js';
|
|
10
11
|
import { commitOutsideScope, outOfScopeError, outOfScopePaths, scopePathspec } from './_commit-scope.js';
|
|
11
12
|
import { runWorktreeSetup } from './_worktree-setup.js';
|
|
@@ -49,14 +50,20 @@ const PROTECTED_BRANCHES = ['main', 'master'];
|
|
|
49
50
|
const BRANCH_NAMING = /^(feat|fix|chore|test|task)\//;
|
|
50
51
|
const DIFF_MAX_LINES = 200;
|
|
51
52
|
// ─── Helpers ────────────────────────────────
|
|
52
|
-
|
|
53
|
+
/** `env` goes on top of the runner's own, e.g. the run's git credential (`remoteEnv`). */
|
|
54
|
+
export async function runGit(cwd, args, env) {
|
|
53
55
|
const { stdout, stderr } = await execFileAsync('git', args, {
|
|
54
56
|
cwd,
|
|
55
57
|
maxBuffer: 10 * 1024 * 1024,
|
|
56
58
|
timeout: 60_000,
|
|
59
|
+
...(env && Object.keys(env).length > 0 ? { env: { ...process.env, ...env } } : {}),
|
|
57
60
|
});
|
|
58
61
|
return { stdout, stderr };
|
|
59
62
|
}
|
|
63
|
+
/** What a git that talks to a remote gets: the GitHub credential of the person behind this run, when the runner uses studio credentials. */
|
|
64
|
+
function remoteEnv(context) {
|
|
65
|
+
return gitCredentialEnv(context?.queueUid);
|
|
66
|
+
}
|
|
60
67
|
/** Extract a readable message from a failed execFile call. */
|
|
61
68
|
export function gitErrorMessage(err) {
|
|
62
69
|
const e = err;
|
|
@@ -1016,7 +1023,7 @@ export async function executePush(params, context) {
|
|
|
1016
1023
|
args.push('-u');
|
|
1017
1024
|
args.push(remote, branch);
|
|
1018
1025
|
// git push reports progress and result on stderr; keep both for the model.
|
|
1019
|
-
const { stdout, stderr } = await runGit(repo, args);
|
|
1026
|
+
const { stdout, stderr } = await runGit(repo, args, remoteEnv(context));
|
|
1020
1027
|
const output = [stdout.trim(), stderr.trim()].filter(Boolean).join('\n');
|
|
1021
1028
|
return JSON.stringify({
|
|
1022
1029
|
success: true,
|
|
@@ -1058,7 +1065,7 @@ export async function executeFetch(params, context) {
|
|
|
1058
1065
|
if (params.prune === true)
|
|
1059
1066
|
args.push('--prune');
|
|
1060
1067
|
try {
|
|
1061
|
-
const { stdout, stderr } = await runGit(repo, args);
|
|
1068
|
+
const { stdout, stderr } = await runGit(repo, args, remoteEnv(context));
|
|
1062
1069
|
const output = [stdout.trim(), stderr.trim()].filter(Boolean).join('\n');
|
|
1063
1070
|
return JSON.stringify({
|
|
1064
1071
|
success: true,
|
|
@@ -1112,7 +1119,7 @@ export async function executePull(params, context) {
|
|
|
1112
1119
|
const flag = strategy === 'rebase' ? '--rebase' : strategy === 'merge' ? '--no-rebase' : '--ff-only';
|
|
1113
1120
|
try {
|
|
1114
1121
|
const identity = await identityArgs(repo, context);
|
|
1115
|
-
const { stdout, stderr } = await runGit(repo, [...identity, 'pull', flag, remote, branch]);
|
|
1122
|
+
const { stdout, stderr } = await runGit(repo, [...identity, 'pull', flag, remote, branch], remoteEnv(context));
|
|
1116
1123
|
const output = [stdout.trim(), stderr.trim()].filter(Boolean).join('\n');
|
|
1117
1124
|
return JSON.stringify({
|
|
1118
1125
|
success: true,
|
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/version.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordhavnhq/runner-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.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",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordhavnhq/runner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.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.98.0",
|
|
29
|
+
"@nordhavnhq/runner-browser": "0.98.0"
|
|
30
30
|
},
|
|
31
31
|
"bundleDependencies": [
|
|
32
32
|
"@nordhavnhq/runner-runtime",
|