Files
loki/scripts/test/project-state-sentence.ts
CatoandClaude Fable 5.1 fb25ac6734 feat: say who you're talking to, and whether the change is live (#1067)
* fix(terminal): name the conversation after the agent in the session; "Loki" is the supervisor only

The view switch read "Loki | Terminal" (#1041). That named the coding agent's
own conversation after a different AI: Loki runs on whichever model is first
in its chain, and the thing in the session is Claude Code today, Codex
tomorrow. The operator reported the result on 2026-10-07: "there can be one
model powering the chat, and another model is open in the terminal".

- TerminalViewSwitch takes the running agent's label: "Claude | Terminal",
  "Codex | Terminal", "Chat | Terminal" when unnamed.
- "Loki" goes back to the supervisor panel: the desktop pane button and the
  session-sheet section, whose row now says it answers on Loki's own model.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jbux2e4GEruUYXn1PC3VhM

* feat(projects): the Build strip ends on the outcome — live at skif.ch, or waiting on you

The project page knew whether an agent was working, how the last run was
graded, and (in the run's fix ledger) whether the change had merged and
deployed. It read the first two and said "work reached the repo" — true, and
not what the person who asked for the change wanted to know.

- lib/project-state-sentence: one sentence per project (headline, detail,
  tone, waitingOnYou), from the build status plus the shipping ledger. Ends on
  the outcome ("Live at skif.ch", "In review — goes live by itself", "Merged,
  but not live"), never on the mechanism; no PR numbers, CI or auto-merge in
  the words. `waitingOnYou` is true only when nothing moves until the
  operator acts — a change in review is not waiting on anyone.
- LastAttempt carries `shipping` (normalized payload.fix), and `landed`
  honours a deployed ledger, so a timed-out run that shipped is not "nothing".
- ProjectBuildStatus renders the sentence; its kicker follows the tone, and a
  link to the live site or the change sits in the text — the action slot
  stays the one button that starts work.

Control's card already shows the ledger line; Today lists only flagged
projects. Both unchanged here.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jbux2e4GEruUYXn1PC3VhM

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-07 07:12:11 -07:00

101 lines
4.1 KiB
TypeScript

// One sentence per project, ending on the outcome. The project page's Build
// strip used to end on "work reached the repo" — true, and not what the
// person who asked for the change wanted to know. Operator, 2026-10-07: "is
// solving the problem feeling like magic? if not, what is stopping it".
// Run: npx tsx scripts/test/project-state-sentence.ts
import { projectStateSentence, siteName } from "@/lib/project-state-sentence";
import type { BuildStatus, LastAttempt } from "@/lib/project-build-status";
import { FIX_SHIP_STATE } from "@/lib/feedback/fix-shipping";
import { MINUTE_MS } from "@/lib/constants/time";
let pass = 0;
let fail = 0;
function ok(cond: unknown, label: string) {
if (cond) pass++;
else {
fail++;
console.error(`✗ ${label}`);
}
}
const NOW = Date.now();
const last = (over: Partial<LastAttempt>): LastAttempt => ({
outcome: "success",
startedAtMs: NOW - 30 * MINUTE_MS,
finishedAtMs: NOW - 10 * MINUTE_MS,
durationMinutes: 20,
landed: true,
shipping: null,
error: null,
...over,
});
const idle = (l: LastAttempt | null): BuildStatus => ({ kind: "idle", last: l });
// Words, not identifiers. "#43", "PR", "CI", "auto-merge" are how the system
// gets there and never what it says.
const JARGON = /\b(PR|CI|auto-merge|#\d+|commit|repo)\b/;
{
const s = projectStateSentence({ kind: "building", sinceMs: NOW - 9 * MINUTE_MS, label: null });
ok(s.headline === "Building now" && s.tone === "working" && !s.waitingOnYou, "building");
}
{
const s = projectStateSentence({ kind: "stalled", sinceMs: NOW - 40 * MINUTE_MS });
ok(s.waitingOnYou && s.tone === "waiting", "a dispatch nobody picked up waits on you");
}
{
const s = projectStateSentence(idle(null));
ok(s.headline === "Nothing built yet" && s.waitingOnYou, "nothing built yet waits on you");
}
{
const s = projectStateSentence(
idle(last({ outcome: "partial", shipping: { state: FIX_SHIP_STATE.DEPLOYED, prNumber: 43 } })),
{ liveUrl: "https://www.skif.ch/" },
);
ok(s.headline === "Live at skif.ch", `deployed → live at the site (got "${s.headline}")`);
ok(s.tone === "live" && !s.waitingOnYou, "live is the end state, nothing to do");
ok(!JARGON.test(s.headline) && !JARGON.test(s.detail), "no jargon in the live sentence");
}
{
const s = projectStateSentence(
idle(last({ shipping: { state: FIX_SHIP_STATE.PR_OPEN, prNumber: 43, prUrl: "https://x" } })),
);
ok(!s.waitingOnYou, "a change in review goes live by itself — not waiting on you");
ok(/goes live by itself/.test(s.headline), `says so (got "${s.headline}")`);
ok(!JARGON.test(s.headline) && !JARGON.test(s.detail), "no jargon in the review sentence");
}
{
const s = projectStateSentence(
idle(last({ shipping: { state: FIX_SHIP_STATE.DEPLOY_FAILED, deployName: "Deploy" } })),
);
ok(s.waitingOnYou && /not live/.test(s.headline), "a failed deploy waits on you, says not live");
}
{
const s = projectStateSentence(idle(last({ shipping: { state: FIX_SHIP_STATE.PR_CLOSED } })));
ok(s.waitingOnYou && !/live/.test(s.detail.replace("going live", "")), "a dropped change waits");
}
{
// The ledger outranks the run's own grade: a partial run that shipped is live.
const s = projectStateSentence(
idle(last({ outcome: "partial", landed: false, shipping: { state: FIX_SHIP_STATE.DEPLOYED } })),
);
ok(s.tone === "live", "ledger beats outcome");
}
{
const s = projectStateSentence(idle(last({ outcome: "timeout", landed: false })));
ok(
/Stopped before it was done/.test(s.headline) && /nothing was saved/.test(s.detail),
"timeout",
);
ok(!JARGON.test(s.detail), "no 'repo' in the failure sentence");
}
{
const s = projectStateSentence(idle(last({ outcome: "success", landed: true })));
ok(s.headline === "Done, not yet live" && s.waitingOnYou, "saved but unshipped waits on you");
}
ok(siteName("https://www.skif.ch/path") === "skif.ch", "site name drops www and path");
ok(siteName("not a url") === null && siteName(null) === null, "bad or missing url → null");
console.log(`${fail ? "✗" : "✓"} project-state-sentence: ${pass} passed, ${fail} failed`);
if (fail) process.exit(1);