mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 20:48:18 +01:00
Priority 4 of the 2026-09-17 review: "Show agent, model, machine, and known cost/quota information before dispatch." All three were already settable on the project profile — agent, "Runs on", Model — as three separate controls, stacked, and nothing stated the combination. So the operator chose a builder in one row, a model two rows down, pressed a prompt button, and the first statement of what actually ran arrived afterwards, on the run record. Now, directly above the prompt buttons that dispatch: Dispatch runs Claude Code · opus · This computer [last run $0.42] COST IS THE LAST RUN'S, AND SAYS SO. What this dispatch will cost cannot be known before it runs, and a predicted number beside a button reads as a quote. What the previous run on this project cost is measured, and it is the best available answer to "what am I about to spend" — labelled as the past, in the tag and in its title text, never as an estimate. A real sub-cent run renders "<$0.01", not "$0.00". Rounding a run that cost something down to free is exactly the move that turns a measurement back into a claim, and it is pinned by a test. QUOTA IS EVIDENCE, NOT A BLOCK. The one piece available without asking anything: the previous run here died with capacity language (looksLikeAgentCapacityIssue, the same predicate the provider chooser uses). Quota refills, so the caution says "may still be spent" and leaves the decision with the operator. An ordinary crash is not evidence about quota, which is also pinned. Nothing is invented: a project that has pinned no builder gets no machine in the sentence, and an agent with no model choice gets no empty slot. On the standing model instruction — Opus preserved, Fable excluded: there is nothing to exclude. `fable` does not appear anywhere in this repo (the two grep hits are the word "undiffable"), and this change adds no model list of its own; it renders whatever the agent registry already offers. Tests: 7 cases, proved by mutation — dropping the sub-cent branch fails with actual '$0.00'. tsc clean, lint 0 errors, check:design ok, test:unit 205/205. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
/**
|
|
* The pre-dispatch sentence: agent, model, machine, and what the LAST run cost.
|
|
*
|
|
* The properties worth pinning are the ones that would turn a measurement back
|
|
* into a claim — a predicted price, a real run rounded to free, or a stale
|
|
* capacity wall stated as fact.
|
|
*/
|
|
|
|
import assert from "node:assert/strict";
|
|
import { describeDispatchTarget } from "@/lib/dispatch-target";
|
|
|
|
let passed = 0;
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
check("the three choices read as one sentence", () => {
|
|
const v = describeDispatchTarget({
|
|
agentLabel: "Claude Code",
|
|
model: "opus",
|
|
channel: "local",
|
|
});
|
|
assert.equal(v.line, "Claude Code · opus · This computer");
|
|
});
|
|
|
|
check("a project that pinned no builder does not invent one", () => {
|
|
const v = describeDispatchTarget({ agentLabel: "Claude Code", channel: null });
|
|
assert.equal(v.line, "Claude Code");
|
|
assert.ok(!/computer|Cloud/.test(v.line), "no machine claimed when none is pinned");
|
|
});
|
|
|
|
check("an agent with no model choice is not given an empty slot", () => {
|
|
const v = describeDispatchTarget({ agentLabel: "Codex", model: " ", channel: "cloud" });
|
|
assert.equal(v.line, "Codex · Cloud builder");
|
|
});
|
|
|
|
// Cost is the PREVIOUS run's, measured. A forecast beside a button reads as a
|
|
// quote for work nobody has done.
|
|
check("a real sub-cent run never renders as free", () => {
|
|
assert.equal(
|
|
describeDispatchTarget({ agentLabel: "x", lastRun: { costUsd: 0.004 } }).cost,
|
|
"<$0.01",
|
|
);
|
|
assert.equal(describeDispatchTarget({ agentLabel: "x", lastRun: { costUsd: 0 } }).cost, "$0.00");
|
|
assert.equal(
|
|
describeDispatchTarget({ agentLabel: "x", lastRun: { costUsd: 1.5 } }).cost,
|
|
"$1.50",
|
|
);
|
|
});
|
|
|
|
check("a run that was never priced says nothing rather than zero", () => {
|
|
assert.equal(describeDispatchTarget({ agentLabel: "x", lastRun: { costUsd: null } }).cost, null);
|
|
assert.equal(describeDispatchTarget({ agentLabel: "x", lastRun: null }).cost, null);
|
|
assert.equal(describeDispatchTarget({ agentLabel: "x" }).cost, null);
|
|
});
|
|
|
|
check("a capacity wall on the last run is a caution, not a verdict", () => {
|
|
const v = describeDispatchTarget({
|
|
agentLabel: "Claude Code",
|
|
lastRun: { error: "Claude usage limit reached" },
|
|
});
|
|
assert.ok(v.caution, "the operator is told before spending another run on it");
|
|
assert.match(v.caution ?? "", /may still be spent/, "quota refills — it must not assert a block");
|
|
});
|
|
|
|
check("an ordinary failure is not evidence about quota", () => {
|
|
const v = describeDispatchTarget({
|
|
agentLabel: "Claude Code",
|
|
lastRun: { error: "ENOENT: no such file or directory" },
|
|
});
|
|
assert.equal(v.caution, null, "a crash on a bad path is not an empty tank");
|
|
});
|
|
|
|
console.log(`\ndispatch-target: ${passed} checks passed`);
|