salvage 2026-11-06: uncommitted work from src/mosaic-stack-rocko-124-r2 (disk cleanup #824)
This commit is contained in:
1 parent
23533625d4
commit
c31fa7286f
38 files changed
+1395
-28
No files matched your search
@@ -810,3 +810,12 @@ provider/model pairs), `families` (old family names to keys), and optional
|
||||
mappings refuse. Every held role must map too. A migrated file prints unchanged.
|
||||
Jason installs the output himself in Mos's window with the PM run idle, and
|
||||
the re-pin follows in the same window (decision 145).
|
||||
|
||||
## Token usage
|
||||
|
||||
`mosaic usage [--business ID] [--json]` reads the bus's accounting, without
|
||||
opening its database or transcripts. Text lists the total and run, instance,
|
||||
provider/model, provider and account groups, with input/output/cacheWrite/
|
||||
cacheRead and unknown turns beside every total. JSON retains the full view.
|
||||
Account is unassigned today. Unknown turns can have used tokens: known sums
|
||||
are a best reading of session-editable transcripts, not proof or a limit check.
|
||||
@@ -29,7 +29,10 @@ import { quitLine, runApp } from "./app.mjs";
|
||||
import { readSessions, stopSession } from "../../seat/src/session.mjs";
|
||||
import { SeatError } from "../../seat/src/seat.mjs";
|
||||
|
||||
import { usageCommand, USAGE_USAGE } from "./usage.mjs";
|
||||
|
||||
export const USAGE = `usage:
|
||||
${USAGE_USAGE}
|
||||
${LIMITS_USAGE}
|
||||
${PLUGINS_USAGE}
|
||||
${PROJECT_USAGE}
|
||||
@@ -539,6 +542,7 @@ export async function main(argv, io = { env: process.env, stdin: process.stdin,
|
||||
if (verb === "threads") return threadsCommand(rest, io, (p) => callFor(p, io, deps));
|
||||
if (verb === "thread") return threadCommand(rest, io, (p) => callFor(p, io, deps), formatMessage);
|
||||
if (verb === "limits") return limitsCommand(rest,io,p=>callFor(p,io,deps));
|
||||
if (verb === "usage") return usageCommand(rest, io, p => callFor(p, io, deps));
|
||||
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);
|
||||
|
||||
@@ -320,7 +320,7 @@ export function createLauncher({
|
||||
const outerStart = startTimeOf(child.pid);
|
||||
const runner = await runnerOf(child);
|
||||
if (!outerStart) throw new Error("the session process exited at once");
|
||||
const launch = await host.bindLaunch({ business: b.id, role: instance, run, harness: model.harness, pid: child.pid, startTime: outerStart, ...(thread ? { thread } : {}) });
|
||||
const launch = await host.bindLaunch({ business: b.id, role: instance, run, harness: model.harness, provider: model.provider, model: model.model, pid: child.pid, startTime: outerStart, ...(thread ? { thread } : {}) });
|
||||
bound = true;
|
||||
entry = {
|
||||
business: b.id, instance, ...(thread ? { thread } : {}), run, launchedBy, harness: model.harness, model: model.model, provider: model.provider, modelKey: model.modelKey,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { CliError } from './errors.mjs';
|
||||
export const USAGE_USAGE = 'mosaic usage [--business ID] [--json]';
|
||||
export async function usageCommand(args, io, callFor) {
|
||||
const parsed = { flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === '--json' && !parsed.flags.has(arg)) parsed.flags.add(arg);
|
||||
else if (arg === '--business' && args[i + 1] && !args[i + 1].startsWith('--') && !parsed.values[arg]) parsed.values[arg] = args[++i];
|
||||
else throw new CliError(USAGE_USAGE, 4);
|
||||
}
|
||||
const result = await callFor(parsed)('usage', {});
|
||||
if (parsed.flags.has('--json')) { io.stdout.write(JSON.stringify(result, null, 2) + '\n'); return; }
|
||||
const counts = row => `input=${row.input} output=${row.output} cacheWrite=${row.cacheWrite} cacheRead=${row.cacheRead} unknown=${row.unknownTurns}`;
|
||||
const lines = [`Total: ${counts(result.total)}`];
|
||||
for (const group of ['byRun', 'byInstance', 'byModel', 'byProvider', 'byAccount']) {
|
||||
for (const row of result[group]) {
|
||||
const name = ['run', 'instance', 'provider', 'model', 'account'].filter(key => key in row)
|
||||
.map(key => row[key] ?? '(unassigned)').join(' / ');
|
||||
lines.push(`${group} ${name}: ${counts(row)}`);
|
||||
}
|
||||
}
|
||||
io.stdout.write(lines.join('\n') + '\n');
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { main } from '../src/cli.mjs';
|
||||
import { fixture, io, tmp } from './helpers.mjs';
|
||||
const count = { input: 11, output: 3, cacheWrite: 5, cacheRead: 7, unknownTurns: 2 };
|
||||
const view = { total: count, byRun: [{ run: 'run1', ...count }], byInstance: [{ instance: 'coder', ...count }],
|
||||
byModel: [{ provider: 'anthropic', model: 'fixture-model', ...count }], byProvider: [{ provider: 'anthropic', ...count }],
|
||||
byAccount: [{ account: null, ...count }] };
|
||||
test('REQ-LIMIT-4 mosaic usage shows each token kind and unknown turns beside every total', async t => {
|
||||
const f = fixture(tmp(t), 'acme'), calls = [];
|
||||
const deps = { transport: business => async (verb, args) => { calls.push({ business, verb, args }); return view; } };
|
||||
const text = io(f.env); await main(['usage', '--business', 'acme'], text, deps);
|
||||
for (const expected of ['input=11', 'output=3', 'cacheWrite=5', 'cacheRead=7', 'unknown=2', 'run1', 'coder', 'fixture-model', 'anthropic', '(unassigned)']) assert.ok(text.out.text.includes(expected), expected);
|
||||
assert.equal((text.out.text.match(/unknown=2/g) ?? []).length, 6);
|
||||
const json = io(f.env); await main(['usage', '--business', 'acme', '--json'], json, deps);
|
||||
assert.deepEqual(JSON.parse(json.out.text), view);
|
||||
assert.deepEqual(calls[0], { business: 'acme', verb: 'usage', args: {} });
|
||||
await assert.rejects(main(['usage', '--bad'], io(f.env), deps), { exitCode: 4 });
|
||||
});
|
||||
|
||||
test('usage is dispatched by scripts/mosaic and the shared read adapter', async () => {
|
||||
const { spawnSync } = await import('node:child_process');
|
||||
const { views } = await import('../../bus/src/views.mjs');
|
||||
const calls = [];
|
||||
const result = await views({ call: (...args) => { calls.push(args); return view; } }).usage();
|
||||
assert.deepEqual(result, view); assert.deepEqual(calls, [['usage']]);
|
||||
const script = new URL('../../../scripts/mosaic', import.meta.url).pathname;
|
||||
const command = spawnSync(script, ['usage', '--bad'], { encoding: 'utf8', env: { PATH: process.env.PATH } });
|
||||
assert.equal(command.status, 4); assert.match(command.stderr, /mosaic usage/);
|
||||
});
|
||||
Reference in new issue
Block a user