@north-light/cli 0.3.731 → 0.3.733
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/api/client.d.ts +3 -2
- package/dist/api/client.js +3 -3
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/builtin-memory/northlight-apps/get-started.md +4 -4
- package/dist/clients/attach/overlays/graph.d.ts +2 -0
- package/dist/clients/attach/overlays/graph.js +1 -1
- package/dist/clients/attach/viewer.js +478 -478
- package/dist/commands/sys/daemon.js +1 -1
- package/dist/commands/sys/import/move.d.ts +2 -0
- package/dist/commands/sys/import/move.js +9 -7
- package/dist/commands/sys/join.js +1 -1
- package/dist/commands/sys/signin.js +2 -2
- package/dist/core/canvas/canvas.d.ts +1 -1
- package/dist/core/canvas/canvas.js +16 -16
- package/dist/core/canvas/schema-pg/034-authz-epoch-triggers.sql +43 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/canvas/tree.d.ts +4 -0
- package/dist/core/canvas/tree.js +6 -6
- package/dist/core/directory/join.d.ts +6 -26
- package/dist/core/directory/join.js +1 -1
- package/dist/core/environment-starter-script.d.ts +1 -1
- package/dist/core/environment-starter-script.js +1 -1
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/providers/call.js +1 -1
- package/dist/core/runtime/runner/blaxel/image-build.js +3 -3
- package/dist/core/runtime/runner/blaxel/release-image.js +2 -2
- package/dist/core/storage/client.js +2 -2
- package/dist/daemon/api/handlers/canvas.js +5 -5
- package/dist/daemon/api/handlers/shares.js +1 -1
- package/dist/daemon/crtrd.js +8 -8
- package/dist/daemon/manage.d.ts +2 -7
- package/dist/daemon/manage.js +3 -3
- package/docs/apps/get-started.md +4 -4
- package/docs/cli/join-northlight.md +16 -22
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/client.js +4 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/clients/attach/overlays/graph.js +18 -1
- package/packages/crouter-api/dist/commands/sys/daemon.js +1 -3
- package/packages/crouter-api/dist/commands/sys/import/move.js +12 -0
- package/packages/crouter-api/dist/commands/sys/join.js +5 -37
- package/packages/crouter-api/dist/commands/sys/signin.js +6 -4
- package/packages/crouter-api/dist/core/canvas/canvas.js +7 -3
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/canvas/tree.js +20 -0
- package/packages/crouter-api/dist/core/directory/join.js +35 -86
- package/packages/crouter-api/dist/core/environment-starter-script.js +1 -1
- package/packages/crouter-api/dist/core/grants/sync.js +1 -1
- package/packages/crouter-api/dist/core/providers/call.js +1 -1
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +1 -1
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/release-image.js +1 -1
- package/packages/crouter-api/dist/core/storage/client.js +1 -1
- package/packages/crouter-api/dist/daemon/manage.js +2 -16
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/dist/core/directory/join-lock.d.ts +0 -13
- package/dist/core/directory/join-lock.js +0 -1
- package/packages/crouter-api/dist/core/directory/join-lock.js +0 -61
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
// `crtr sys join` registers this runtime with its directory before the daemon starts.
|
|
2
2
|
import { defineLeaf } from '../../core/command.js';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { pluginsDir } from '../../core/scope.js';
|
|
6
3
|
import { joinDirectory } from '../../core/directory/join.js';
|
|
7
|
-
import { apiSocketPath } from '../../core/canvas/paths.js';
|
|
8
4
|
import { listProcessTable } from '../../core/canvas/pid.js';
|
|
9
|
-
import { daemonAnswers } from '../../core/layout-migrate/index.js';
|
|
10
5
|
import { envNodeId } from '../../shared/env.js';
|
|
11
|
-
import { isDaemonRunning } from '../../daemon/pidfile.js';
|
|
12
|
-
import { findDaemonPids, spawnDaemon, stopAllDaemons } from '../../daemon/manage.js';
|
|
13
6
|
/** Whether a broker (a node's engine) is an ancestor of this process, or cannot be ruled out. Stopping the daemon kills every broker, so a join run from one would die mid-way. */
|
|
14
7
|
export function insideBroker() {
|
|
15
8
|
const table = listProcessTable();
|
|
@@ -27,33 +20,14 @@ export function insideBroker() {
|
|
|
27
20
|
}
|
|
28
21
|
return false;
|
|
29
22
|
}
|
|
30
|
-
/** Daemon control for a person's computer. A container whose daemon is the launcher's PID 1 keeps the offline contract. */
|
|
31
|
-
function daemonControl() {
|
|
32
|
-
if (process.platform === 'linux' && (process.env['CRTR_LAUNCHER_SOCKET'] || existsSync('/run/crtr/launcher.sock')))
|
|
33
|
-
return undefined;
|
|
34
|
-
return {
|
|
35
|
-
// The process table too: a successor spawned just before the join took its lock has no pidfile or socket yet, but boots on the settings the join is about to replace.
|
|
36
|
-
running: async () => isDaemonRunning() || findDaemonPids().length > 0 || await daemonAnswers(apiSocketPath()),
|
|
37
|
-
stop: async () => { await stopAllDaemons(); },
|
|
38
|
-
start: async () => { await spawnDaemon(); },
|
|
39
|
-
// A bare `crtr cloud …` is an unknown command until a daemon's grant sync has installed the `cloud` plugin.
|
|
40
|
-
firstSync: async () => {
|
|
41
|
-
const dir = pluginsDir('user');
|
|
42
|
-
const deadline = Date.now() + 20_000;
|
|
43
|
-
while (dir && Date.now() < deadline && !existsSync(join(dir, 'cloud', 'commands.json')))
|
|
44
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
45
|
-
},
|
|
46
|
-
insideNode: insideBroker,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
23
|
export const sysJoinLeaf = defineLeaf({
|
|
50
24
|
name: 'join',
|
|
51
|
-
description: 'register
|
|
52
|
-
whenToUse: '
|
|
25
|
+
description: 'register a hosted runtime with its directory using the provisioning enrollment token, before its daemon starts',
|
|
26
|
+
whenToUse: 'only at a hosted runtime\'s first boot, before the daemon starts, with the enrollment token provisioning passed in. A person\'s own computer registers through `crtr sys signin`.',
|
|
53
27
|
help: {
|
|
54
28
|
name: 'sys join',
|
|
55
29
|
summary: 'exchange a directory enrollment token for a new runtime client key and record the returned identity',
|
|
56
|
-
guide: 'Generates a new ES256 client key, sends only its public key to `PUT <directory>/v1/runtimes/registration` with the token as bearer, and learns the runtime id, client id, issuer, owner and URL from the answer. Only after that answer does it write the key file. It writes no settings and touches no canvas.db: the daemon\'s next start replaces this install\'s person with the owner everywhere in canvas.db
|
|
30
|
+
guide: 'Generates a new ES256 client key, sends only its public key to `PUT <directory>/v1/runtimes/registration` with the token as bearer, and learns the runtime id, client id, issuer, owner and URL from the answer. Only after that answer does it write the key file. It writes no settings and touches no canvas.db: the daemon\'s next start replaces this install\'s person with the owner everywhere in canvas.db and sets `runtime.issuer` and `runtime.audience` from the key file. It never touches a daemon: while one answers it refuses `daemon_running`. Presenting the token of the stored successful registration again finishes without calling the directory. Any other token generates a new key and registers again.',
|
|
57
31
|
params: [
|
|
58
32
|
{ kind: 'flag', name: 'directory', type: 'string', required: true, constraint: 'Directory base URL (http or https) that minted the token.' },
|
|
59
33
|
{ kind: 'flag', name: 'token', type: 'string', required: true, sensitive: true, constraint: 'Single-use enrollment token. Sensitive: never echoed in output or errors.' },
|
|
@@ -67,19 +41,13 @@ export const sysJoinLeaf = defineLeaf({
|
|
|
67
41
|
{ name: 'canvas_rewrite', type: 'string', required: true, constraint: 'Always `next daemon start`: when canvas.db identity fields are rewritten.' },
|
|
68
42
|
{ name: 'url', type: 'string', required: true, constraint: 'Runtime URL, written to `runtime.audience`.' },
|
|
69
43
|
{ name: 'registered', type: 'boolean', required: true, constraint: 'False when the token matched the stored registration and the directory was not called.' },
|
|
70
|
-
{ name: 'daemon', type: 'string', required: true, constraint: '`restarted` (a daemon was stopped and started on the joined settings), `started` (none was running; join started one and waited, up to 20s, for its first grant sync to install the account\'s provider plugins, so `crtr cloud …` resolves), `not_running` (none was started: a hosted container\'s launcher owns its daemon), or `restart_failed` (joined, but the new daemon did not start: see `daemon_error`, then run `crtr sys daemon start`).' },
|
|
71
|
-
{ name: 'daemon_error', type: 'string', required: false, constraint: 'Why the new daemon did not start, with `daemon: restart_failed`.' },
|
|
72
44
|
],
|
|
73
45
|
outputKind: 'object',
|
|
74
46
|
effects: [
|
|
75
|
-
'Holds `<runtime>/join.lock` (its pid) from the start until the daemon is back; `ensureDaemon` and `sys daemon start` (without `--force`) decline to start a daemon while a live process holds it (including a start already in flight when the join began). A lock whose holder died is reclaimed.',
|
|
76
|
-
'A running daemon is stopped (SIGTERM, then SIGKILL, plus strays) after the directory accepts the registration and before the local writes, then started again. Every broker dies with it and is revived by the new daemon. If the join fails after the stop, the daemon is started again anyway. With no daemon running join starts one anyway, because a bare `crtr cloud …` is an unknown command (it never autostarts a daemon) until a daemon\'s grant sync has installed the provider plugins. Refuses `join_inside_node` when run from inside a node and a daemon is running; refuses `daemon_running` where a container launcher owns the daemon.',
|
|
77
47
|
'On a new token: calls the directory once; on success writes `<runtime>/secrets/runtime-client.json` (mode 0600) with the private key, registration and the token\'s SHA-256, replacing any earlier key file. A refused or failed call writes nothing.',
|
|
78
48
|
'Sends name, platform, crtr version, installed plugin ids and sandbox state with the public key. Before the request it writes `runtime-client.pending.json` (mode 0600); a rerun with the same token and directory reuses that key, so a lost reply is retried safely. The file is deleted on success or a refusal.',
|
|
79
|
-
'
|
|
80
|
-
'Rewrites the legacy local person\'s profile grantees to `app:terminal`.',
|
|
81
|
-
'At the next daemon start, before any listener, the person this install minted (or still the legacy local person) is replaced by the owner in every canvas.db column that holds a person: node, token, grant, cron, audit and usage subjects and grantees, the person\'s identity, and queued cron births. References to the install\'s local terminal grant are cleared and that local grant mirror is deleted so grant sync installs the directory\'s. Free text is unchanged. The start after that changes nothing.',
|
|
49
|
+
'At the next daemon start, before any listener, the person this install minted is replaced by the owner in every canvas.db column that holds a person, and the legacy local person\'s profile grantees become `app:terminal`.',
|
|
82
50
|
],
|
|
83
51
|
},
|
|
84
|
-
run: async (input) => ({ ...(await joinDirectory(input['directory'], input['token'], input['name'] || undefined
|
|
52
|
+
run: async (input) => ({ ...(await joinDirectory(input['directory'], input['token'], input['name'] || undefined)), canvas_rewrite: 'next daemon start' }),
|
|
85
53
|
});
|
|
@@ -12,7 +12,7 @@ import { envNodeId } from '../../shared/env.js';
|
|
|
12
12
|
import { ExitCode } from '../../types.js';
|
|
13
13
|
import { insideBroker } from './join.js';
|
|
14
14
|
import { cliClient } from '../api-client.js';
|
|
15
|
-
import { defaultDirectoryUrl, finishMove, runMove, settleEarlierMove } from './import/move.js';
|
|
15
|
+
import { defaultDirectoryUrl, finishMove, registerThisMac, runMove, settleEarlierMove } from './import/move.js';
|
|
16
16
|
import { WAIT_FOR_PID_ENV } from './import/start.js';
|
|
17
17
|
/** Open the confirm page in the person's browser; a failure to open it is harmless because the code and address are printed too. */
|
|
18
18
|
function openBrowser(url) {
|
|
@@ -62,12 +62,12 @@ function startDetachedMove(notify) {
|
|
|
62
62
|
const MOVING = (account) => `Signed in as ${account}. crtr is now moving this computer's records to Northlight; every agent here pauses for seconds to minutes. End your turn now; this conversation carries on when the move finishes.`;
|
|
63
63
|
export const sysSigninLeaf = defineLeaf({
|
|
64
64
|
name: 'signin',
|
|
65
|
-
description: 'sign this computer\'s crtr in to the person\'s Northlight account',
|
|
65
|
+
description: 'sign this computer\'s crtr in to the person\'s Northlight account and register it as one of their machines',
|
|
66
66
|
whenToUse: 'the person agreed to sign in to Northlight (a Northlight command needs the account, or they asked), or a command answered `not_signed_in` or `move_unfinished`',
|
|
67
67
|
help: {
|
|
68
68
|
name: 'sys signin',
|
|
69
|
-
summary: 'pair this computer with the person\'s Northlight account in the browser,
|
|
70
|
-
guide: 'Prints a code and opens the directory\'s confirm page; the person signs in or signs up there if asked, checks the code and clicks Allow. The command waits for that. On a computer whose records are still local it then moves them into the account: run from a terminal it prints each step and returns when done; run from inside a node it returns at once and the node is messaged when the move finishes or fails. A computer already moved accepts only the account it moved into. For an unfinished move (`move_unfinished`), it checks the account\'s move result and finishes the switch-over if the records arrived. If the stored sign-in is missing or revoked, it first pairs only the account recorded for that move. Until the result is known, agents remain paused. The sign-in ends after 90 days without use, when revoked on the account page, or with `crtr sys signout`.',
|
|
69
|
+
summary: 'pair this computer with the person\'s Northlight account in the browser, move this computer\'s records into it, and register it with the directory',
|
|
70
|
+
guide: 'Prints a code and opens the directory\'s confirm page; the person signs in or signs up there if asked, checks the code and clicks Allow. The command waits for that. On a computer whose records are still local it then moves them into the account: run from a terminal it prints each step and returns when done; run from inside a node it returns at once and the node is messaged when the move finishes or fails. A computer already moved accepts only the account it moved into. For an unfinished move (`move_unfinished`), it checks the account\'s move result and finishes the switch-over if the records arrived. If the stored sign-in is missing or revoked, it first pairs only the account recorded for that move. Until the result is known, agents remain paused. Once the records are in the account the computer is also registered as one of the account\'s machines: a signing key is made here (the private key never leaves this computer) and only its public half goes to the directory, under the same sign-in. A computer already registered keeps its registration; one signed in earlier without it is registered by running this again. The sign-in ends after 90 days without use, when revoked on the account page, or with `crtr sys signout`.',
|
|
71
71
|
params: [
|
|
72
72
|
{ kind: 'flag', name: 'directory-url', type: 'string', required: false, constraint: 'Directory base URL (http or https). Default: the one in `runtime/machine.json`, else the stored sign-in\'s, else Northlight\'s.' },
|
|
73
73
|
],
|
|
@@ -81,6 +81,7 @@ export const sysSigninLeaf = defineLeaf({
|
|
|
81
81
|
'Calls the directory (`POST /v1/developer/logins`, then polls `/v1/developer/logins/poll`) and, once approved, writes `runtime/secrets/person-credential` (0600) and replaces the cached bearer. A declined, abandoned or refused sign-in writes nothing and leaves an existing sign-in as it was.',
|
|
82
82
|
'On a computer whose records are local: the move of `crtr sys import start --kind machine` (drains the daemon, uploads, restarts it in machine role); a move confirmed failed before the account holds the records ends the drain and signs this computer out again. If the account\'s result is unknown, the move record and drain remain for recovery. From inside a node it runs as a detached process logging to `runtime/import/move.log`.',
|
|
83
83
|
'On a moved computer: restarts the daemon so it reconnects to Northlight.',
|
|
84
|
+
'Unless this computer is already registered: calls `PUT <directory>/v1/runtimes/registration` with the sign-in bearer and a new public ES256 key, then writes `runtime/secrets/runtime-client.json` (0600) holding the private key and the returned runtime identity.',
|
|
84
85
|
],
|
|
85
86
|
},
|
|
86
87
|
run: async (input) => {
|
|
@@ -97,6 +98,7 @@ export const sysSigninLeaf = defineLeaf({
|
|
|
97
98
|
const machine = readMachineConfig();
|
|
98
99
|
if (machine !== undefined) {
|
|
99
100
|
const { account } = await signIn(directoryUrl, showSignIn, { accept: sameAccountOnly(machine) });
|
|
101
|
+
await registerThisMac(directoryUrl);
|
|
100
102
|
await stopAllDaemons();
|
|
101
103
|
await spawnDaemon();
|
|
102
104
|
return { account };
|
|
@@ -582,8 +582,9 @@ export async function updateNodeTelemetry(nodeId, telemetry) {
|
|
|
582
582
|
/** Stored fields the attach graph displays, plus the two live execution cues it
|
|
583
583
|
* needs. This keeps the interactive graph off the full node-summary projection
|
|
584
584
|
* and its unused runtime, outcome, and placement fields. */
|
|
585
|
-
export async function graphNodes() {
|
|
586
|
-
const
|
|
585
|
+
export async function graphNodes(ids) {
|
|
586
|
+
const db = await openDb();
|
|
587
|
+
const sql = `SELECT
|
|
587
588
|
node_id, name, description, cycles, kind, status, frozen_at,
|
|
588
589
|
telemetry_context_tokens, telemetry_last_activity,
|
|
589
590
|
pi_pid, turn_open_at, turn_closed_at,
|
|
@@ -591,7 +592,10 @@ export async function graphNodes() {
|
|
|
591
592
|
fault_operation_id, fault_anchor_entry_id, fault_retry_disposition,
|
|
592
593
|
fault_retry_by, fault_retry_attempt, fault_retry_max, fault_retry_next_at,
|
|
593
594
|
fault_provider_error_json
|
|
594
|
-
FROM node_rows WHERE ${NOT_A_SPARE} ORDER BY created
|
|
595
|
+
FROM node_rows WHERE ${NOT_A_SPARE}${ids === undefined ? '' : ' AND node_id = ANY(?::text[])'} ORDER BY created`;
|
|
596
|
+
const rows = (ids === undefined
|
|
597
|
+
? await db.prepare(sql).all()
|
|
598
|
+
: await db.prepareUncached(sql).all([...ids]));
|
|
595
599
|
return rows.map((row) => {
|
|
596
600
|
const pid = row['pi_pid'] ?? null;
|
|
597
601
|
const pidAlive = isPidPresent(pid);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/** The canvas schema version this build supports: the number of the highest delta in `schema-pg/` (the baseline
|
|
7
7
|
* `schema-pg.sql` is version 1). `scripts/install-runtime.mjs` reads this module from a candidate generation to refuse
|
|
8
8
|
* one below the live database's `schema_min_reader`. */
|
|
9
|
-
export const CANVAS_SCHEMA_VERSION =
|
|
9
|
+
export const CANVAS_SCHEMA_VERSION = 34;
|
|
10
10
|
/** The Postgres schema holding the canvas tables: `CRTR_DATABASE_SCHEMA` (`crtr` in the cloud deploy). Unset or empty
|
|
11
11
|
* means the role's own search_path (`public` on a Mac and on a VM). A name that is not a plain identifier is an error:
|
|
12
12
|
* it is put in a `search_path` connection option. */
|
|
@@ -84,6 +84,26 @@ export async function setSubscriptionActive(subscriber, publisher, active) {
|
|
|
84
84
|
AND watch IN (SELECT watch_id FROM watches WHERE watcher = ? AND object = ?)`).run(active ? null : configToJson(PASSIVE), (await nodeObject(db, subscriber)).id, (await nodeObject(db, publisher)).id);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
/** `node` and every node in the tree that contains it: climb first managers (oldest subscriber) to the top, then take that
|
|
88
|
+
* top node's whole subtree. The attach graph climbs the same way, so the tree it draws is exactly this set. Empty when `node`
|
|
89
|
+
* is not a node. */
|
|
90
|
+
export async function treeContaining(node) {
|
|
91
|
+
const db = await openDb();
|
|
92
|
+
const self = await getById(db, node);
|
|
93
|
+
if (self?.type !== 'node')
|
|
94
|
+
return [];
|
|
95
|
+
let top = self.id;
|
|
96
|
+
const seen = new Set([top]);
|
|
97
|
+
for (;;) {
|
|
98
|
+
const manager = (await treeEdges(db, 'AND oo.id = ?', top))[0]?.from_id;
|
|
99
|
+
if (manager === undefined || seen.has(manager))
|
|
100
|
+
break;
|
|
101
|
+
seen.add(manager);
|
|
102
|
+
top = manager;
|
|
103
|
+
}
|
|
104
|
+
const below = (await db.prepareUncached(SUBTREE_ALL_IDS_SQL).all(top, top)).map((r) => r.id);
|
|
105
|
+
return [top, ...below];
|
|
106
|
+
}
|
|
87
107
|
/** Who watches `publisher` in the tree — the targets a push fans out to. */
|
|
88
108
|
export async function subscribersOf(publisher) {
|
|
89
109
|
return (await treeEdges(await openDb(), 'AND oo.id = ?', publisher)).map((e) => ({ node_id: e.from_id, active: e.active, created: e.created }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Runtime
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Runtime registration: send the directory a new public ES256 key under a credential (a hosted runtime's single-use enrollment token at first
|
|
2
|
+
// boot, or a signed-in person's bearer from `crtr sys signin`), then record the returned identity and the private key in the runtime-client file.
|
|
3
|
+
// It writes no settings (the daemon applies them at its start); the private key never leaves this computer.
|
|
4
4
|
import { createHash, generateKeyPairSync, randomUUID } from 'node:crypto';
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
6
6
|
import { hostname } from 'node:os';
|
|
@@ -14,7 +14,6 @@ import { atomicWriteJson, readJsonIfExists } from '../fs-utils.js';
|
|
|
14
14
|
import { launcherPresent } from '../grants/sandboxes.js';
|
|
15
15
|
import { crtrVersion } from '../../shared/crtr-version.js';
|
|
16
16
|
import { pluginsDir } from '../scope.js';
|
|
17
|
-
import { withJoinLock } from './join-lock.js';
|
|
18
17
|
function clientPath() {
|
|
19
18
|
return join(secretsDir(), 'runtime-client.json');
|
|
20
19
|
}
|
|
@@ -55,7 +54,7 @@ export function installedPluginIds() {
|
|
|
55
54
|
return [];
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
async function register(directory, token, publicJwk, name) {
|
|
57
|
+
async function register(directory, token, publicJwk, name, retry) {
|
|
59
58
|
const endpoint = `${directory.replace(/\/$/, '')}/v1/runtimes/registration`;
|
|
60
59
|
let response;
|
|
61
60
|
try {
|
|
@@ -77,7 +76,7 @@ async function register(directory, token, publicJwk, name) {
|
|
|
77
76
|
throw new InputError({
|
|
78
77
|
error: 'join_refused',
|
|
79
78
|
message: `directory refused the registration: ${response.status} ${text.slice(0, 500)}`,
|
|
80
|
-
next:
|
|
79
|
+
next: retry,
|
|
81
80
|
});
|
|
82
81
|
}
|
|
83
82
|
try {
|
|
@@ -113,12 +112,12 @@ export function joinedClient() {
|
|
|
113
112
|
function daemonRunningError(socket) {
|
|
114
113
|
return new InputError({
|
|
115
114
|
error: 'daemon_running',
|
|
116
|
-
message: `cannot
|
|
117
|
-
next: '
|
|
115
|
+
message: `cannot register while a daemon answers on ${socket}`,
|
|
116
|
+
next: 'Stop the daemon that owns this volume, then run `crtr sys join` again.',
|
|
118
117
|
});
|
|
119
118
|
}
|
|
120
119
|
/** Register (or reuse the stored registration) without touching local state beyond the pending key. */
|
|
121
|
-
async function obtainRegistration(directory, token, name, tokenHash) {
|
|
120
|
+
async function obtainRegistration(directory, token, name, tokenHash, retry) {
|
|
122
121
|
const stored = readJsonIfExists(clientPath());
|
|
123
122
|
if (stored?.token_sha256 === tokenHash)
|
|
124
123
|
return { joined: registration(stored), registered: false };
|
|
@@ -133,86 +132,36 @@ async function obtainRegistration(directory, token, name, tokenHash) {
|
|
|
133
132
|
atomicWriteJson(pendingPath(), pending, { mode: 0o600 });
|
|
134
133
|
}
|
|
135
134
|
const { jwk, public_jwk: publicJwk } = pending;
|
|
136
|
-
const joined = await register(directory, token, publicJwk, name);
|
|
135
|
+
const joined = await register(directory, token, publicJwk, name, retry);
|
|
137
136
|
return { joined, registered: true, client: { jwk, kid: jwk.kid, alg: 'ES256', ...joined, token_sha256: tokenHash } };
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
* With `daemon` control, a running daemon is no obstacle: the join holds the
|
|
142
|
-
* join lock (so no viewer's redial can autostart a daemon while it is down),
|
|
143
|
-
* registers with the directory while the daemon still serves, stops the
|
|
144
|
-
* daemon, writes the identity, and starts the daemon again so its start
|
|
145
|
-
* applies the person change to canvas.db. Without it, a running daemon refuses. */
|
|
146
|
-
export async function joinDirectory(directory, token, name = hostname(), daemon) {
|
|
138
|
+
function requireDirectory(directory) {
|
|
147
139
|
if (!isUrl(directory))
|
|
148
140
|
throw new InputError({ error: 'invalid_directory', message: 'directory must be an http or https URL', received: directory, field: 'directory', next: 'Pass the directory base URL, for example https://directory.example.' });
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
rmSync(pendingPath(), { force: true });
|
|
160
|
-
}
|
|
161
|
-
return { ...joined, registered, daemon: 'not_running' };
|
|
141
|
+
}
|
|
142
|
+
/** Register this runtime under `credential` and record the identity. A second call with the same credential finishes without calling the directory. */
|
|
143
|
+
async function registerAndStore(directory, credential, name, retry) {
|
|
144
|
+
requireDirectory(directory);
|
|
145
|
+
if (credential === '')
|
|
146
|
+
throw new InputError({ error: 'invalid_token', message: 'credential is empty', field: 'token', next: 'Pass the enrollment token provisioning supplied.' });
|
|
147
|
+
const { joined, registered, client } = await obtainRegistration(directory, credential, name, createHash('sha256').update(credential).digest('hex'), retry);
|
|
148
|
+
if (client) {
|
|
149
|
+
atomicWriteJson(clientPath(), client, { mode: 0o600 });
|
|
150
|
+
rmSync(pendingPath(), { force: true });
|
|
162
151
|
}
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw refuseInsideNode();
|
|
179
|
-
stopped = true;
|
|
180
|
-
await daemon.stop();
|
|
181
|
-
if (await daemon.running())
|
|
182
|
-
throw daemonRunningError(socket);
|
|
183
|
-
}
|
|
184
|
-
if (client) {
|
|
185
|
-
atomicWriteJson(clientPath(), client, { mode: 0o600 });
|
|
186
|
-
rmSync(pendingPath(), { force: true });
|
|
187
|
-
}
|
|
188
|
-
// Nothing may start a daemon now (the lock is held), so one seen here began before the lock and read the old settings.
|
|
189
|
-
if (await daemon.running()) {
|
|
190
|
-
if (daemon.insideNode())
|
|
191
|
-
throw refuseInsideNode();
|
|
192
|
-
stopped = true;
|
|
193
|
-
await daemon.stop();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
failure = error;
|
|
198
|
-
}
|
|
199
|
-
// Bring the daemon back whether or not the join finished: it was running when we began. The lock is held until it serves, so no redial races it.
|
|
200
|
-
// With none running, start one anyway: grant sync is what installs `cloud`, and a bare `crtr cloud …` is an unknown
|
|
201
|
-
// command (it never reaches the daemon, so never autostarts one) until some daemon has synced.
|
|
202
|
-
let restart = { daemon: 'not_running' };
|
|
203
|
-
if (failure === undefined || stopped) {
|
|
204
|
-
try {
|
|
205
|
-
await daemon.start();
|
|
206
|
-
restart = { daemon: stopped ? 'restarted' : 'started' };
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
restart = { daemon: 'restart_failed', daemon_error: error instanceof Error ? error.message : String(error) };
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (failure !== undefined)
|
|
213
|
-
throw failure;
|
|
214
|
-
if (restart.daemon === 'started')
|
|
215
|
-
await daemon.firstSync?.();
|
|
216
|
-
return { ...joined, registered, ...restart };
|
|
217
|
-
});
|
|
152
|
+
return { ...joined, registered };
|
|
153
|
+
}
|
|
154
|
+
/** A hosted runtime's first boot: register with the provisioning enrollment token before any daemon exists. Refuses `daemon_running` when one answers. */
|
|
155
|
+
export async function joinDirectory(directory, token, name = hostname()) {
|
|
156
|
+
const socket = apiSocketPath();
|
|
157
|
+
if (await daemonAnswers(socket))
|
|
158
|
+
throw daemonRunningError(socket);
|
|
159
|
+
return registerAndStore(directory, token, name, 'Provisioning must supply a new enrollment token; they are single-use and expire after 10 minutes.');
|
|
160
|
+
}
|
|
161
|
+
/** `crtr sys signin`'s registration: the signed-in person's bearer registers this computer as one of the person's runtimes, once. A computer that
|
|
162
|
+
* already holds a registration for this directory's owner (a join, or an earlier signin) is left as it is. */
|
|
163
|
+
export async function registerSignedInMac(directory, bearer) {
|
|
164
|
+
if (readJoined() !== null)
|
|
165
|
+
return null;
|
|
166
|
+
return registerAndStore(directory, bearer, hostname(), 'Run `crtr sys signin` again.');
|
|
218
167
|
}
|
|
@@ -11,7 +11,7 @@ export const STARTER_SETUP_SCRIPT = `#!/usr/bin/env bash
|
|
|
11
11
|
# (/var/lib/crtr/apps/<app>/home, created at run time), not /home/crtr, so dotfiles written to /home/crtr are not read through ~.
|
|
12
12
|
# - Private GitHub Packages (@northlight-systems) already work: /home/crtr/.npmrc holds the auth line and NPM_CONFIG_USERCONFIG points at it,
|
|
13
13
|
# with the token filled in from NODE_AUTH_TOKEN at run time. pnpm 12 ignores a token in a repository's own .npmrc, so do not rely on one.
|
|
14
|
-
# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm. Packages are not pre-installed: run \`pnpm install\` in a sandbox,
|
|
14
|
+
# - Already done for you: git, gh, curl, ripgrep, jq, Node 24, pnpm. Packages are not pre-installed: run \`pnpm install\` in a sandbox,
|
|
15
15
|
# or install at build time below.
|
|
16
16
|
# - Output goes to /work/.crtr/setup.log in the image. If this script exits non-zero, sandboxes refuse to start and point at that log.
|
|
17
17
|
# - The image keeps /work, /home/crtr, /usr, /etc and /lib. Anything written to /root or /tmp is lost.
|
|
@@ -37,7 +37,7 @@ export function runtimeId(client = runtimeClient()) {
|
|
|
37
37
|
}
|
|
38
38
|
/** The text a person sees when the directory no longer recognises this machine. */
|
|
39
39
|
export function machineRevokedMessage(issuer) {
|
|
40
|
-
return `This machine was removed from your Northlight account. To use it again,
|
|
40
|
+
return `This machine was removed from your Northlight account. To use it again, run \`crtr sys signin\`.`;
|
|
41
41
|
}
|
|
42
42
|
/** The directory answered `invalid_client` to this runtime's key: the machine was revoked. */
|
|
43
43
|
export class MachineRevokedError extends Error {
|
|
@@ -92,7 +92,7 @@ export async function identity(caller) {
|
|
|
92
92
|
if (caller.class === 'person') {
|
|
93
93
|
const sub = (await callerTerminalGrant())?.sub;
|
|
94
94
|
if (!sub)
|
|
95
|
-
throw new ProviderError('grant_revoked', 'This machine has no active Northlight grant for your terminal. Run `crtr sys
|
|
95
|
+
throw new ProviderError('grant_revoked', 'This machine has no active Northlight grant for your terminal. Run `crtr sys signin` again.');
|
|
96
96
|
return { sub, grantee: sub };
|
|
97
97
|
}
|
|
98
98
|
if (!caller.sub || !caller.grantee)
|
|
@@ -60,7 +60,7 @@ export function recipeDockerfile(recipe, revision, packagesToken = false) {
|
|
|
60
60
|
const hasScript = recipe.setup_script !== null && recipe.setup_script.trim() !== '';
|
|
61
61
|
const base = [
|
|
62
62
|
`FROM ${NODE_BASE_IMAGE}`,
|
|
63
|
-
'RUN apk add --no-cache bash git curl ripgrep github-cli',
|
|
63
|
+
'RUN apk add --no-cache bash git curl ripgrep jq github-cli',
|
|
64
64
|
`RUN printf '%s\\n' ${GH_WRAPPER_LINES.map(shellQuote).join(' ')} > ${GH_WRAPPER_PATH} && chmod 755 ${GH_WRAPPER_PATH}`,
|
|
65
65
|
`COPY --from=${SANDBOX_API_IMAGE} /sandbox-api /usr/local/bin/sandbox-api`,
|
|
66
66
|
`RUN adduser -D -h /home/${RUN_USER} -s /bin/sh ${RUN_USER} && mkdir -p /work/.crtr ${RECIPE_PI_AGENT_DIR} && chown -R ${RUN_USER} /work /var/lib/crtr`,
|
|
@@ -47,7 +47,7 @@ export function releaseImageDockerfile(version, sha256) {
|
|
|
47
47
|
`RUN mkdir -p ${dir} && tar -xzf /tmp/${RELEASE_TARBALL_FILE} -C ${dir} && echo ${sha256} > ${dir}/${RELEASE_SHA_FILE} && : > ${dir}/${RELEASE_COMPLETE_FILE}`,
|
|
48
48
|
'',
|
|
49
49
|
`FROM ${NODE_BASE_IMAGE}`,
|
|
50
|
-
'RUN apk add --no-cache bash git curl ripgrep python3',
|
|
50
|
+
'RUN apk add --no-cache bash git curl ripgrep jq python3',
|
|
51
51
|
`COPY --from=${SANDBOX_API_IMAGE} /sandbox-api /usr/local/bin/sandbox-api`,
|
|
52
52
|
`RUN adduser -D -h /home/${RUN_USER} -s /bin/sh ${RUN_USER} && mkdir -p /run/crtr /var/lib/crtr /work/.crtr && chown -R ${RUN_USER} /run/crtr /var/lib/crtr /work`,
|
|
53
53
|
'COPY --from=release /opt/crtr /opt/crtr',
|
|
@@ -52,7 +52,7 @@ export function storageClient() {
|
|
|
52
52
|
const config = storageConfig();
|
|
53
53
|
const issuer = directoryIssuer();
|
|
54
54
|
if (!config || !issuer) {
|
|
55
|
-
throw new RunError(503, 'storage_unavailable', 'file storage is not configured on this runtime: it has no `runtime.storage` setting (service_url, base_url) or no joined directory. Only a hosted runtime has file storage (its provisioner sets CRTR_BOOT_STORAGE_URL), and the directory issues storage tokens only to a sandboxed runtime, so a computer
|
|
55
|
+
throw new RunError(503, 'storage_unavailable', 'file storage is not configured on this runtime: it has no `runtime.storage` setting (service_url, base_url) or no joined directory. Only a hosted runtime has file storage (its provisioner sets CRTR_BOOT_STORAGE_URL), and the directory issues storage tokens only to a sandboxed runtime, so a registered computer cannot send or receive files yet. Retrying does not help: run this command from your hosted runtime.', undefined, undefined, undefined, false);
|
|
56
56
|
}
|
|
57
57
|
const key = `${issuer}\n${config.service_url}\n${config.base_url}`;
|
|
58
58
|
if (cached?.key !== key)
|
|
@@ -20,7 +20,6 @@ import { readMachineConfig } from './machine-link/config.js';
|
|
|
20
20
|
import { exclusiveLockOwnerPid } from '../core/exclusive-lock.js';
|
|
21
21
|
import { onDiskMigrationLockPath } from '../core/canvas/paths.js';
|
|
22
22
|
import { envNoDaemonAutostart } from '../shared/env.js';
|
|
23
|
-
import { awaitJoinLockRelease, joinInProgress, joinInProgressError, joinLockHolder } from '../core/directory/join-lock.js';
|
|
24
23
|
import { waitForDaemonAvailability } from '../api/index.js';
|
|
25
24
|
import { localClient } from '../api/node-transport.js';
|
|
26
25
|
// Daemon env sanitization
|
|
@@ -230,8 +229,6 @@ export function runDaemonBodiesDump(out) {
|
|
|
230
229
|
export function runDaemonInstallId() {
|
|
231
230
|
return runDaemonEntry(['import-dump', '', 'install-id']);
|
|
232
231
|
}
|
|
233
|
-
/** How long a handover successor waits for a running join: a registration call (30 s) plus the join's own stop and start. */
|
|
234
|
-
const JOIN_WAIT_WINDOW_MS = 3 * 60_000;
|
|
235
232
|
// Shutdown stays short even though startup may include corpus migration.
|
|
236
233
|
const DAEMON_SHUTDOWN_WINDOW_MS = 20_000;
|
|
237
234
|
const DAEMON_VERIFY_POLL_MS = 10;
|
|
@@ -464,7 +461,7 @@ export async function stopDaemonProcess(pid, timeoutMs = DAEMON_SHUTDOWN_WINDOW_
|
|
|
464
461
|
throw new Error(`daemon ${pid} survived both SIGTERM and SIGKILL`);
|
|
465
462
|
}
|
|
466
463
|
/** Stop the recorded daemon and sweep every stray crtrd of this canvas home.
|
|
467
|
-
* Resolves once none remains. Shared by `crtr sys daemon stop` and `crtr sys
|
|
464
|
+
* Resolves once none remains. Shared by `crtr sys daemon stop` and `crtr sys signin`. */
|
|
468
465
|
export async function stopAllDaemons() {
|
|
469
466
|
const pid = readPidfile();
|
|
470
467
|
const recorded = pid !== null && isPidAlive(pid);
|
|
@@ -557,13 +554,6 @@ export async function spawnDaemon(opts = {}) {
|
|
|
557
554
|
const launchArgs = await resolveDaemonLaunch().catch((error) => {
|
|
558
555
|
throw new DaemonLaunchError(error);
|
|
559
556
|
});
|
|
560
|
-
// The one spawn point every start reaches (autostart, `sys daemon start`, a handover successor): an
|
|
561
|
-
// autostart begun before a join took its lock lands here after it, and must not start a daemon.
|
|
562
|
-
if (opts.waitForJoinLock === true)
|
|
563
|
-
await awaitJoinLockRelease(JOIN_WAIT_WINDOW_MS);
|
|
564
|
-
const joiner = joinLockHolder();
|
|
565
|
-
if (joiner !== null && joiner !== process.pid && opts.ignoreJoinLock !== true)
|
|
566
|
-
throw joinInProgressError(joiner);
|
|
567
557
|
// Route stdout+stderr to an append-mode file instead of discarding them
|
|
568
558
|
// (stdio:'ignore'). This fd is RAW RESIDUE only — third-party/runtime
|
|
569
559
|
// output the daemon doesn't control, plus the narrow set of authorized raw
|
|
@@ -693,8 +683,7 @@ export function daemonAutostartStartupFailure() {
|
|
|
693
683
|
return autostartStartupFailure;
|
|
694
684
|
}
|
|
695
685
|
/** Start the daemon if it is not already running. No-op if already up, if
|
|
696
|
-
* autostart is suppressed for this invocation, while
|
|
697
|
-
* the join lock (see core/directory/join-lock.ts), while an attempt is in flight,
|
|
686
|
+
* autostart is suppressed for this invocation, while an attempt is in flight,
|
|
698
687
|
* or while backing off from a recent failure.
|
|
699
688
|
* Does not throw: a spawn error is recorded, and a launch or early-exit failure
|
|
700
689
|
* is reported through `daemonAutostartStartupFailure()` so a waiting client
|
|
@@ -705,9 +694,6 @@ export function ensureDaemon(deps = {}) {
|
|
|
705
694
|
const now = deps.now ?? Date.now;
|
|
706
695
|
if (autostartDisabled())
|
|
707
696
|
return;
|
|
708
|
-
// `crtr sys join` holds the daemon down on purpose; a viewer's redial must not bring it back.
|
|
709
|
-
if (joinInProgress())
|
|
710
|
-
return;
|
|
711
697
|
if (autostartInFlight)
|
|
712
698
|
return;
|
|
713
699
|
if (now() < autostartNextAttemptAt)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.733",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.733",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.733",
|
|
31
|
+
"@north-light/identity": "0.3.733"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.733",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.733",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.733",
|
|
32
|
+
"@north-light/plugin": "0.3.733",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.733",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.733",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.733",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.733",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.733",
|
|
11927
|
+
"@north-light/identity": "0.3.733"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.733",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.733",
|
|
11936
|
+
"@north-light/identity": "0.3.733",
|
|
11937
|
+
"@north-light/plugin": "0.3.733",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { InputError } from '../io.js';
|
|
2
|
-
export declare function joinLockPath(): string;
|
|
3
|
-
/** The live process holding the lock, or null when no join is running (no lock, or a holder that died). */
|
|
4
|
-
export declare function joinLockHolder(): number | null;
|
|
5
|
-
/** Whether a join is in progress. The joiner starts its own daemon through `spawnDaemon`, never through the implicit paths that ask this. */
|
|
6
|
-
export declare function joinInProgress(): boolean;
|
|
7
|
-
export declare function joinInProgressError(pid: number | null): InputError;
|
|
8
|
-
/** Resolve once no other live process holds the join lock, or after `timeoutMs`. For a start that must happen
|
|
9
|
-
* but must read the settings a join is about to commit (a daemon handover's successor): it waits the join out
|
|
10
|
-
* instead of bypassing the lock, so nothing but the join starts a daemon while the lock is held. */
|
|
11
|
-
export declare function awaitJoinLockRelease(timeoutMs: number, pollMs?: number): Promise<void>;
|
|
12
|
-
/** Run `operation` holding the join lock. Throws `join_in_progress` when a live process holds it. */
|
|
13
|
-
export declare function withJoinLock<T>(operation: () => Promise<T>): Promise<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var a=Object.defineProperty;var n=(o,r)=>a(o,"name",{value:r,configurable:!0});import{mkdirSync as l}from"node:fs";import{join as m}from"node:path";import{crtrHome as e}from"../canvas/paths.js";import{isPidAlive as f}from"../canvas/pid.js";import{exclusiveLockOwnerPid as d,withExclusiveDirectoryLockAsync as p}from"../exclusive-lock.js";import{InputError as h}from"../io.js";const w=1e3;function s(){return m(e(),"join.lock")}n(s,"joinLockPath");function t(){const o=d(s());return o!==null&&f(o)?o:null}n(t,"joinLockHolder");function E(){return t()!==null}n(E,"joinInProgress");function j(o){return new h({error:"join_in_progress",message:o===null?"`crtr sys join` is running and holds the daemon down until it finishes":`\`crtr sys join\` (pid ${o}) is running and holds the daemon down until it finishes`,next:"Wait for the join to finish; it starts the daemon again itself. If it is stuck, `crtr sys daemon start --force`."})}n(j,"joinInProgressError");async function _(o,r=100){const c=Date.now()+o;for(;;){const i=t();if(i===null||i===process.pid||Date.now()>=c)return;await new Promise(u=>setTimeout(u,r))}}n(_,"awaitJoinLockRelease");async function v(o){return l(e(),{recursive:!0}),p(s(),o,{timeoutMs:w,timeoutError:n(()=>j(t()),"timeoutError")})}n(v,"withJoinLock");export{_ as awaitJoinLockRelease,E as joinInProgress,j as joinInProgressError,t as joinLockHolder,s as joinLockPath,v as withJoinLock};
|