Adds the harness plug-in kind (interface 1). packages/plugins/harness/pi and claude-code hold what core branched on: the adapter, thinking levels, preflight, version probe, sandbox mounts, builtins line, typed tool names, gate timeout, bundle files, adapter env, turn end and session-files path. Core reaches a module only through the loader. A session's route is the instance's harness, model and thinking vars, or the three fallback. vars; a missing one refuses no-route, and the system file's execution keys are never read for a session. The launcher checks the primary route, then the fallback: harness-off, harness-refused, thinking-unsupported, then preflight. A failed preflight falls back when a fallback is set, and any refusal of the fallback names the primary's failure too. Account checks run only when the route's module counts an account. The manifest records route, routeReason and harnessVersion, replacing piVersion and claudeVersion. pi gets --thinking, Claude Code --effort, both from MOSAIC_THINKING. The business file refuses a partial fallback. routes and routes.set are human-only bus verbs outside ORGANIZATION_KEYS; checkRoutes is shared by routes.set, instances.set and limits.set and checks only changed routes. The chief of staff changes an instance's model, and the assistant's whole vars (Q169), through limits.set, so its route write runs the same checks. A model outside launch.models refuses unknown-model, primary or fallback, and routes.set passes that code through. A new run binds only on a switched-on harness module name and records its transcript path, which the usage reader uses. Settings gains a Routing table with six selects per instance and loses the Role models fieldset; it posts changed rows to /api/routes. webui/src/bus.mjs is unchanged. Until Jason's `mosaic plugins set` adds "harness": ["claude-code"], a new launch refuses harness-off.
38 lines
2.5 KiB
JavaScript
38 lines
2.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { startBroker } from '../src/runtime.mjs';
|
|
import { Client } from '../src/client.mjs';
|
|
import { startTimeOf } from '../../seat/src/proc.mjs';
|
|
test('REQ-PLUG-1 runtime reaches transcript only through loader, over the real bus socket', async t => {
|
|
const root = mkdtempSync(join(tmpdir(), 'usage-runtime-'));
|
|
let runtime;
|
|
t.after(async () => { await runtime?.close(); rmSync(root, { recursive: true, force: true }); });
|
|
const dir = join(root, 'launches/demo/run1/session'); mkdirSync(dir, { recursive: true });
|
|
const business = { id: 'demo', human: 'jason', plugins: { 'usage-source': ['transcript'], harness: ['pi'] },
|
|
roles: { coder: { authority: { withinRole: [], crossRole: [] } } }, arbiters: { technical: 'coder', delivery: 'coder' } };
|
|
runtime = await startBroker({ dataRoot: root, businesses: { demo: business }, launches: [{
|
|
// Row 65: the launch names where its harness keeps the session files.
|
|
business: 'demo', role: 'coder', run: 'run1', harness: 'pi', provider: 'other-provider', model: 'other-model', transcript: dir,
|
|
pid: process.pid, startTime: startTimeOf(process.pid),
|
|
}] });
|
|
const client = new Client({ path: runtime.path, cap: runtime.launches[0].cap });
|
|
await client.call('role.claim');
|
|
const human = runtime.broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
|
const { id } = runtime.broker.request(human, { verb: 'message.send', args: { to: 'coder', body: 'Work' } });
|
|
await client.call('message.receive');
|
|
assert.deepEqual(await client.call('usage.begin', { turn: id }), { recorded: true });
|
|
writeFileSync(join(dir, 'session.jsonl'), JSON.stringify({ type: 'message', id: 'new', message: {
|
|
role: 'assistant', usage: { input: 2, output: 3, cacheWrite: 4, cacheRead: 5 },
|
|
} }) + '\n');
|
|
assert.deepEqual(await client.call('usage.end', { turn: id }), { recorded: true });
|
|
const view = await client.call('usage');
|
|
assert.deepEqual(view.total, { input: 2, output: 3, cacheWrite: 4, cacheRead: 5, unknownTurns: 0 });
|
|
assert.equal(view.byProvider[0].provider, 'other-provider');
|
|
const source = readFileSync(new URL('../src/usage.mjs', import.meta.url), 'utf8');
|
|
assert.match(source, /createLoader/); assert.match(source, /loader.modules\('usage-source'\)/);
|
|
assert.doesNotMatch(source, /import[^\n]*usage-source\/transcript/);
|
|
});
|