Files
loki/scripts/test/terminal-input-switch.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

116 lines
5.2 KiB
TypeScript

// The terminal screen must offer screenshots, talking and the conversation
// view without a menu, and name each thing once.
//
// Operator asks: 2026-10-03 "make it possible on this screen to attach
// screenshots and talk and make a switch to a chat view easier"; 2026-10-05
// "Switch to Loki would show it as a loki session, which would be a view like
// the view of this chat" and "navigation should be easy and intuitive".
// Run: npx tsx scripts/test/terminal-input-switch.ts
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { readFileSync } from "fs";
import { join } from "path";
import { TerminalInputSwitch } from "@/components/terminal/TerminalInputSwitch";
import { TerminalViewSwitch } from "@/components/terminal/TerminalViewSwitch";
import { TERMINAL_INPUT_MODES } from "@/config/terminal-modes";
let pass = 0;
let fail = 0;
function ok(cond: unknown, label: string) {
if (cond) pass++;
else {
fail++;
console.error(`✗ ${label}`);
}
}
const noop = () => {};
const render = (props: Parameters<typeof TerminalInputSwitch>[0]) =>
renderToStaticMarkup(createElement(TerminalInputSwitch, props));
const read = (f: string) => readFileSync(join(process.cwd(), "src/components/terminal", f), "utf8");
{
const html = renderToStaticMarkup(
createElement(TerminalInputSwitch, { inputMode: "type", onInputModeChange: noop }),
);
for (const mode of TERMINAL_INPUT_MODES)
ok(html.includes(`>${mode.label}</button>`), `offers ${mode.label}`);
ok(/aria-pressed="true"[^>]*>(?:<svg[\s\S]*?<\/svg>)*Type</.test(html), "marks the current mode");
const prompt = html.split("<button").find((b) => b.includes(">Prompt</button>")) ?? "";
ok(
prompt.includes("lucide-paperclip") && prompt.includes("lucide-mic"),
"Prompt shows attach and mic icons",
);
ok(
/screenshot/i.test(TERMINAL_INPUT_MODES.find((m) => m.id === "prompt")!.hint),
"Prompt's hint names screenshots",
);
ok(!html.includes("Loki"), "input modes only — Loki is a view, not an input mode");
}
{
// Claude | Terminal: the conversation is named after the AGENT in the
// session, never "Loki" — that is the supervisor, on its own model.
for (const view of ["chat", "terminal"] as const) {
const html = renderToStaticMarkup(
createElement(TerminalViewSwitch, { view, onViewChange: noop, agentLabel: "Claude" }),
);
ok(
html.includes(">Claude</button>") && html.includes(">Terminal</button>"),
"names both views",
);
ok(!html.includes("Loki"), "the agent's conversation is not called Loki");
const pressed = html.split("<button").find((b) => b.includes('aria-pressed="true"')) ?? "";
ok(pressed.includes(view === "chat" ? ">Claude<" : ">Terminal<"), `marks ${view} as current`);
}
const codex = renderToStaticMarkup(
createElement(TerminalViewSwitch, { view: "chat", onViewChange: noop, agentLabel: "Codex" }),
);
ok(codex.includes(">Codex</button>"), "follows the agent that is actually running");
const unnamed = renderToStaticMarkup(
createElement(TerminalViewSwitch, { view: "chat", onViewChange: noop }),
);
ok(unnamed.includes(">Chat</button>"), "an unnamed agent reads as Chat, not Loki");
}
{
// Wired where you look, at every width, and in both views.
ok(read("TerminalMobileDock.tsx").includes("<TerminalInputSwitch"), "phone dock: input modes");
ok(read("TerminalModeBar.tsx").includes("<TerminalInputSwitch"), "desktop bar: input modes");
ok(read("TerminalMobileHeader.tsx").includes("<TerminalViewSwitch"), "phone header: views");
ok(read("TerminalModeBar.tsx").includes("<TerminalViewSwitch"), "desktop bar: views");
const surface = read("TerminalSurface.tsx");
ok(
(surface.match(/onViewChange=\{[^}]*termView\.setView/g) ?? []).length === 2,
"both switches change the view",
);
ok(
/<TerminalSessionSheet[\s\S]*?onOpenLoki=\{/.test(surface),
"the Loki panel is reachable from the session sheet",
);
ok(!read("TerminalMobileHeader.tsx").includes("onOpenLoki"), "no second 'Loki' in the header");
ok(
read("TerminalPaneActions.tsx").includes("\n Loki\n"),
"the desktop panel button is the one thing called Loki",
);
ok(
read("TerminalMobileHeader.tsx").includes("agentLabel={agent}") &&
read("TerminalModeBar.tsx").includes("agentLabel={activeAgent?.label"),
"both switches are named after the running agent",
);
// One Loki entry point on a phone: the header's. The dock's chip was the
// same button a second time, one row below (2026-10-05).
ok(
!read("TerminalMobileDock.tsx").includes("onOpenLoki"),
"the phone dock does not repeat the header's Loki button",
);
}
{
// The phone hides Voice (the composer's mic dictates) — but never strands
// someone who is already in it.
const hidden = render({ inputMode: "prompt", onInputModeChange: noop, hide: ["voice"] });
ok(!hidden.includes(">Voice</button>"), "a hidden mode is not offered");
const current = render({ inputMode: "voice", onInputModeChange: noop, hide: ["voice"] });
ok(current.includes(">Voice</button>"), "the current mode is always shown");
}
console.log(`${fail ? "✗" : "✓"} terminal-input-switch: ${pass} passed, ${fail} failed`);
if (fail) process.exit(1);