`mosaic business instances BUSINESS` reads the role instances, and `mosaic business instance add|set` writes one add or change through the broker's new human-only `instances` and `instances.set` verbs. The writer is packages/business/src/instance-settings.mjs. It takes the caller's revision, validates the next document, refuses a definition that declares credentials (organization-credentials-out-of-scope), keeps protected instances as they are, logs the human as the actor, and says when the running bus needs a restart. Neither command restarts the bus. The writer refuses the instance ids human and tester with invalid-request, because the broker refuses a business whose roles use either name when the bus starts. The Console's Settings view shows the instances and, under --send only, posts to POST /api/instances with the exact Origin and same-origin Fetch Metadata. A refusal keeps the draft. An answer without the view's shape is outcome-unknown (503). The page's public/ diff carries the decision 123 go in mos-0832. Neither verb is in ORGANIZATION_KEYS, so no agent tool reaches them. Owner Darkwing, brief in row 165 (#1662). Round 3 rebases round 2 onto4f45cadc0(row 156). The public/ +/- digest is 939ecd28...9444, unchanged at landing. Reviewers on candidate manifest e30b54da...f580: Dewey approve 29052, Filbert approve 29053. Seat run on4f45cadc0: 1436/0 singles, 37/37 mutants killed. Sage gate one8b09735a: GATE_PASSED 25/25, packages 2282/0, queue node 156/0, script selftests 422/0, 23:59:13Z to 00:05:35Z. Rebased onto50a57e454over two SESSIONS-only commits. Nothing live.
84 lines
5.6 KiB
JavaScript
84 lines
5.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import { createChat } from './chat.mjs';
|
|
import { startServer, previewOptions, DEFAULT_BOARD } from './serve.mjs';
|
|
import { busCaller } from './bus.mjs';
|
|
import { views } from '../../bus/src/views.mjs';
|
|
import { loadSystem, socketPath, REPO, rolesDir } from '../../cli/src/config.mjs';
|
|
import { configDir } from '../../business/src/business.mjs';
|
|
import { consoleReads, redactor } from './reads.mjs';
|
|
import { statSync } from 'node:fs';
|
|
import { isAbsolute } from 'node:path';
|
|
import { ID_PATTERN } from '../../business/src/vocabulary.mjs';
|
|
const args = process.argv.slice(2);
|
|
const usage = 'node packages/webui/src/cli.mjs serve [--port N] [--checkout PATH] [--board http://127.0.0.1:7331] [--business ID] [--public-host NAME --auth-header HEADER --allow-user ID [--send]]';
|
|
try {
|
|
if (args.length === 1 && ['--help', '-h'].includes(args[0])) { console.log(usage); process.exit(0); }
|
|
if (args.shift() !== 'serve') throw new Error(usage);
|
|
const options = { board: DEFAULT_BOARD, port: 7330 }, preview = {};
|
|
let sendOn = false;
|
|
while (args.length) {
|
|
const flag = args.shift();
|
|
// Row 76 (#1570): the one flag without a value.
|
|
if (flag === '--send') { sendOn = true; continue; }
|
|
const value = args.shift();
|
|
if (!value) throw new Error(`missing value for ${flag}`);
|
|
if (flag === '--port') {
|
|
if (!/^\d+$/.test(value) || Number(value) > 65535) throw new Error('port must be 0..65535');
|
|
options.port = Number(value);
|
|
} else if (flag === '--board') options.board = value;
|
|
// Row 77 (#1571): the canonical checkout the queue read runs from, when
|
|
// serve runs from a pinned copy; everything else loads from the copy.
|
|
else if (flag === '--checkout') {
|
|
let dir = false;
|
|
try { dir = isAbsolute(value) && statSync(value).isDirectory(); } catch { /* refused below */ }
|
|
if (!dir) throw new Error('--checkout must be the absolute path of a directory');
|
|
options.checkout = value;
|
|
}
|
|
else if (flag === '--business') {
|
|
if (!ID_PATTERN.test(value)) throw new Error('business must be a business id');
|
|
options.business = value;
|
|
}
|
|
// Row 74 (#1568): the preview mode, all three or none, checked before any config is read.
|
|
else if (flag === '--public-host') preview.publicHost = value;
|
|
else if (flag === '--auth-header') preview.authHeader = value;
|
|
else if (flag === '--allow-user') preview.allowUser = value;
|
|
else throw new Error(`unknown option: ${flag}`);
|
|
}
|
|
options.preview = previewOptions(preview);
|
|
if (sendOn && !options.preview) throw new Error('--send needs the preview mode (--public-host, --auth-header and --allow-user)');
|
|
// The bus views (slice 1 S5) need the system config. Without it the
|
|
// board still serves and the bus routes answer not-configured.
|
|
// The Queue, Business and Settings reads (row 54) need no bus; without
|
|
// the system config, Business can't resolve authority and Settings has
|
|
// no notifier. A refusal printed here names no path (redactor).
|
|
// --send without a bus refuses to start rather than serve a composer that can't send.
|
|
let bus = null, send = null, settingsWrite = null, projectFiles = null, projectFile = null, projectSave = null, chat = null, nameWrite = null, assistantStop = null, instancesWrite = null, busLine, system = null;
|
|
try {
|
|
system = loadSystem();
|
|
const { dataRoot } = system;
|
|
const call = busCaller({ dataRoot, socket: socketPath(dataRoot), business: options.business ?? null });
|
|
chat = createChat({ call });
|
|
// Row 155 (#1649): `names` is a webui read only, so it sits beside the shared views. Row 165
|
|
// (#1662): so is `instances`, and its write `instances.set` is only under --send.
|
|
bus = { ...views({ call }), names: () => call('names'), instances: () => call('instances') };
|
|
// Row 148: the spec and docs editor reads like the other reads and saves only under --send.
|
|
projectFiles = args => call('project.files', args);
|
|
projectFile = args => call('project.file', args);
|
|
if (sendOn) {send = args => call('message.send', args);settingsWrite=args=>call('limits.set',args);projectSave=args=>call('project.file.save',args);nameWrite=args=>call('name.set',args);assistantStop=args=>call('assistant.stop',args);instancesWrite=args=>call('instances.set',args);}
|
|
busLine = `Bus: ${options.business ?? 'the running bus host\'s business'}`;
|
|
} catch (err) {
|
|
const why = redactor({ configDir: configDir() })(err.message);
|
|
if (sendOn) throw new Error(`--send needs the bus configured (${why})`);
|
|
busLine = `Bus: not configured (${why})`;
|
|
}
|
|
const reads = consoleReads({ root: REPO, queueRoot: options.checkout ?? REPO, system, configDir: configDir(), rolesDir: rolesDir(), business: options.business ?? null });
|
|
const server = await startServer({ board: options.board, port: options.port, bus, reads, preview: options.preview, send, settingsWrite, projectFiles, projectFile, projectSave, chat, nameWrite, assistantStop, instancesWrite });
|
|
const previewLine = options.preview ? `\nPreview: https://${options.preview.host}/ through the proxy, signed-in user from ${options.preview.header}, ${send ? 'reads and human messages to roles (--send); one line per send below' : 'read-only'}` : '';
|
|
const queueLine = options.checkout ? '\nQueue: read from the --checkout directory' : '';
|
|
console.log(`Mosaic Console: http://127.0.0.1:${server.address().port}/\nBoard: ${options.board}\n${busLine}${queueLine}${previewLine}\nCtrl-C stops this server.`);
|
|
for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => server.close());
|
|
} catch (err) {
|
|
console.error(`refused: ${err.message}`);
|
|
process.exitCode = 2;
|
|
}
|