salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r141/wt3 (disk cleanup #824)

This commit is contained in:
mos committed 2026-11-06 10:04:01 -06:00
1 parent 18aee8fa17
commit 255167f8ca
26 files changed
+862 -52

No files matched your search

+9
View File
@@ -32,6 +32,8 @@ mosaic agents [--business <id>] [--json]
mosaic trail <task|decision> [--business <id>] [--json]
mosaic talk <role> <text> [--wait <seconds> | --follow] [--business <id>]
mosaic follow [--business <id>]
mosaic name <instance> <name> [--business <id>]
mosaic names [--business <id>] [--json]
mosaic stop <run>
mosaic launches off|on [--business <id>]
mosaic launches list [--json]
@@ -102,6 +104,13 @@ mosaic launches list [--json]
and `--follow` together refuse. These commands consume the same human
inbox; run one receiving CLI at a time. Console only reads history, so a
reply to a Console send stays unread in `inbox` until it is marked read.
- `name` gives a role instance a name (row 141, #1635, REQ-MSG-2) and prints
`named <instance> <name>`. `talk` and every `message.send` then accept the
name where they took the instance. A name is unique in the business and
can't be an instance key, a role definition, `human` or `tester`; the bus
refuses with `name-taken`, `name-is-instance` or `name-is-role`. Naming an
instance again replaces its name and frees the old one. `names` lists each
named instance and its current name.
- `launches off` and `on` are the broker's `launch.revoke` and
`launch.restore`. While off, every `role.launch` refuses with
`launch-revoked`; running sessions keep running. Stop them with `stop`.
+18
View File
@@ -40,6 +40,8 @@ export const USAGE = `usage:
mosaic trail <task|decision> [--business <id>] [--json] [--tester]
mosaic talk <role> <text> [--wait <seconds> | --follow] [--business <id>] [--tester]
mosaic follow [--business <id>] [--tester]
mosaic name <instance> <name> [--business <id>]
mosaic names [--business <id>] [--json]
mosaic stop <run>
mosaic launches off|on [--business <id>]
mosaic launches list [--json]
@@ -269,6 +271,21 @@ async function human(verb, rest, io, deps) {
return print(await call("agents"), formatAgents);
}
// Row 141 (#1635, REQ-MSG-2): `mosaic name` sets the name `talk` and message.send accept for an
// instance; `mosaic names` lists the current ones. Both are the human's.
async function names(verb, rest, io, deps) {
const parsed = parse(rest, { flags: verb === "names" ? ["--json"] : [], values: ["--business"] });
if (parsed.positional.length !== (verb === "name" ? 2 : 0)) throw usage(verb === "name" ? "name takes an instance and a name" : "names takes no arguments");
const call = callFor(parsed, io, deps);
if (verb === "name") {
const [instance, name] = parsed.positional;
await call("name.set", { instance, name });
return io.stdout.write(`named ${instance} ${name}\n`);
}
const rows = await call("names");
io.stdout.write(parsed.flags.has("--json") ? `${JSON.stringify(rows, null, 2)}\n` : rows.map((r) => `${r.instance} ${r.name}\n`).join(""));
}
const TALK_WAIT_S = 900;
const TESTER_PREFIX = "[mos test]";
const TALK_POLL_MS = 2000;
@@ -487,6 +504,7 @@ export async function main(argv, io = { env: process.env, stdin: process.stdin,
if (verb === "plugins") return pluginsCommand(rest, io, (p) => callFor(p, io, deps));
if (verb === "talk") return talk(rest, io, deps);
if (verb === "follow") return talk(rest, io, deps, true);
if (verb === "name" || verb === "names") return names(verb, rest, io, deps);
if (verb === "stop") return stop(rest, io, deps);
if (verb === "launches") return launches(rest, io, deps);
if (verb === "bus") return bus(rest, io, deps);
+59
View File
@@ -0,0 +1,59 @@
// Row 141 (#1635, REQ-MSG-2): `mosaic name` and `mosaic names`, through the in-process broker from
// helpers.mjs. The broker's own checks are in packages/bus/tests/names.test.mjs.
import { test } from "node:test";
import assert from "node:assert/strict";
import { main, USAGE } from "../src/cli.mjs";
import { CliError } from "../src/errors.mjs";
import { broker, io, tmp } from "./helpers.mjs";
function setup(t) {
const bus = broker(t);
const dataRoot = tmp(t);
const run = async (argv, x = io()) => {
try {
await main(argv, x, { system: { dataRoot }, transport: bus.transport });
return { code: 0, io: x };
} catch (e) {
if (!(e instanceof CliError)) throw e;
return { code: e.exitCode, error: e.message, io: x };
}
};
return { ...bus, run };
}
test("the human names an instance, lists it, and talk's message.send reaches it by that name", async (t) => {
const s = setup(t);
const named = await s.run(["name", "coder", "rex", "--business", "demo"]);
assert.equal(named.code, 0, named.error);
assert.equal(named.io.out.text, "named coder rex\n");
assert.deepEqual(s.calls.at(-1), { business: "demo", verb: "name.set", args: { instance: "coder", name: "rex" } });
const listed = await s.run(["names", "--business", "demo"]);
assert.equal(listed.code, 0, listed.error);
assert.equal(listed.io.out.text, "coder rex\n");
const json = await s.run(["names", "--json", "--business", "demo"]);
assert.deepEqual(
JSON.parse(json.io.out.text).map(({ instance, name }) => ({ instance, name })),
[{ instance: "coder", name: "rex" }],
);
const sent = await s.run(["talk", "rex", "hello", "--wait", "0", "--business", "demo"]);
assert.equal(sent.code, 0, sent.error);
assert.match(sent.io.out.text, /^sent [0-9a-f]{8} to rex\n/);
const [m] = s.b.request(s.coder, { verb: "message.receive" });
assert.equal(m.to_role, "coder");
assert.equal(m.to_name, "rex");
});
test("name and names refuse the wrong number of arguments with the usage", async (t) => {
const s = setup(t);
for (const argv of [["name", "coder"], ["name", "coder", "rex", "extra"], ["names", "coder"]]) {
const r = await s.run([...argv, "--business", "demo"]);
assert.equal(r.code, 4, argv.join(" "));
assert.ok(r.error.endsWith(USAGE), r.error);
}
assert.equal(s.calls.length, 0);
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\]$/m);
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\]$/m);
});