feat(bus): the bus and the broker core (row 37, S2, rocko)
Rocko's round 2 candidate, approved by Darkwing (#1519 comment 26757).
build.patch 40d7e838, manifest 61519059, 24 files under packages/bus,
schema v3b (179ffe35, lead decision 60). Integration gate in a git
worktree of 942dca9e (S1 in the tree) plus the patch: bus 43/43 and
business 60/60 on Node 24 and 26, every package test and every
scripts/test-*.sh green, test-task 98/98 with the live-provider cases.
Rulings from lead decisions 62 and 63: the human proof is cooperative in
slice 1, and a self-raised cross-role decision routes to the human.
Single-use gated approvals follow in row 43.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Started with fork() by the trusted host; boot refs/capabilities travel over IPC,
|
||||
// never command arguments, stdout or service-token-bearing environment variables.
|
||||
import { startBroker } from './runtime.mjs';
|
||||
import { BusError } from './broker.mjs';
|
||||
let runtime,
|
||||
booted = false,
|
||||
closing = false;
|
||||
async function close(code) {
|
||||
if (closing) return;
|
||||
closing = true;
|
||||
try {
|
||||
await runtime?.close();
|
||||
} catch {
|
||||
code = 2;
|
||||
}
|
||||
process.exitCode = code;
|
||||
if (process.connected) process.disconnect();
|
||||
}
|
||||
if (!process.send) {
|
||||
process.stderr.write('trusted-host-required\n');
|
||||
process.exitCode = 2;
|
||||
} else {
|
||||
const timer = setTimeout(() => close(2), 10000);
|
||||
process.on('message', async (message) => {
|
||||
try {
|
||||
if (message?.op === 'bindLaunch' && runtime) {
|
||||
try {
|
||||
process.send({ ok: true, launch: runtime.bindLaunch(message.record) });
|
||||
} catch (e) {
|
||||
process.send({ ok: false, error: e instanceof BusError ? e.code : 'bind-refused' });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message?.op === 'close') {
|
||||
clearTimeout(timer);
|
||||
await close(0);
|
||||
return;
|
||||
}
|
||||
if (message?.op !== 'boot' || booted) throw new BusError('invalid-host-request');
|
||||
booted = true;
|
||||
clearTimeout(timer);
|
||||
runtime = await startBroker(message.config);
|
||||
if (closing) {
|
||||
await runtime.close();
|
||||
return;
|
||||
}
|
||||
process.send({ ok: true, path: runtime.path, launches: runtime.launches, readers: runtime.readers });
|
||||
} catch (e) {
|
||||
process.send?.({ ok: false, error: e instanceof BusError ? e.code : 'startup-refused' }, () =>
|
||||
close(2),
|
||||
);
|
||||
}
|
||||
});
|
||||
process.on('disconnect', () => close(2));
|
||||
process.on('SIGTERM', () => close(0));
|
||||
process.on('SIGINT', () => close(0));
|
||||
}
|
||||
Reference in New Issue
Block a user