Files
loki/scripts/test/terminal-commands.ts
CatoandClaude Fable 5.2 9ac77daea4 fix(nav): a phone can find the Terminal and sign Claude in; a failed task says why (#1628)
* design: Loki has no orange; the public call to action is the achromatic accent

The app's own buttons went monochrome on 2026-10-19; the public site kept
a warm orange (#ff5c00) on Start a project, Get started, the auth submit,
the focus ring and the essay progress bar. It is not Bitcoin orange and it
means nothing on a product that is not about Bitcoin (owner, 2026-11-11).

- --accent-warm, --accent-warm-hover and --public-accent are removed; every
  class that used them reads --accent-primary / --accent-hover, so one
  filled button exists in Loki and it is theme-aware
- --on-accent is the inverted text. It was a fixed near-black, which on the
  near-black light-theme accent left .ui-btn-xs.ui-btn-primary unreadable
- the focus ring and the public glow are neutral
- token-drift declares the divergence from @bitbaum/design-tokens; the
  widget theme is regenerated from the tokens

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

* fix(workbench): a failed task says why and gives the words back

Sent an OrangeCat task from the workbench on 2026-11-11. Claude was signed
out on the cloud runner; the status API said so with the fix, and the
composer showed the two words 'Dispatch failed' over an emptied box.

- dispatchFailureForPerson: a signed-out agent is named in the sender's
  words; any other reason is passed through instead of dropped
- the composer shows that reason under the label and offers 'Put my words
  back', since the box is cleared on send

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

* fix(nav): the phone's chat screen names Home, Projects and Terminal

The owner, signed in on a phone on 2026-11-11, could not find the terminal.
The chat is the default screen and hides the tab bar; its left button opened
a list of chats and nothing else, and its menu offered 'Projects' (which
only set the chat's project) and 'Everything else'. The page itself was
called Sessions, so no menu contained the word.

- CHAT_PLACES (config/navigation.ts) is one list of Home, Projects, Terminal
- the chat menu lists them by name, then 'All pages'; the item that sets
  the chat's project says so
- the chats panel the left button opens lists the same three, phones only
- the page is called Terminal in the nav, its title and its links

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

* fix(sessions): a signed-out Claude is one button in the chat view

A session opens in its Chat view. When Claude's login had expired, that view
showed the agent's own line, 'Please run /login', and reply chips that would
fail the same way; the 'Sign in /login' button existed only in the Terminal
view. The owner, on a phone, could not find how to sign in (2026-11-11).

The chat view reads the reply through the same detector as the terminal
(screenActions) and offers 'Sign Claude in', which types /login and switches
to the terminal where the link is printed.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-11 09:31:18 +01:00

143 lines
5.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* What the terminal needs TYPED, read off its screen (lib/terminal-commands).
* The report (2026-10-12): a person looking at the terminal "doesn't know what
* to do" — signed out, or wanting Opus instead of the current model — and
* nothing on the page told them the answer was a command.
*/
import { commandsFor } from "@/config/agent-commands";
import { commandIn, commandGuide, runAction, screenActions } from "@/lib/terminal-commands";
import { typeCommand } from "@/lib/session-keystrokes";
import { summaryPrompt, terminalContextAttachment } from "@/lib/terminal-summary";
let passed = 0;
function check(label: string, condition: boolean): void {
if (!condition) throw new Error(`✗ ${label}`);
passed++;
console.log(` ✓ ${label}`);
}
const signedOut = screenActions(
["╭────────────╮", "│ > fix the header", "Invalid API key · Please run /login"],
"claude",
);
check("signed out → /login, first", signedOut[0]?.display === "/login");
check("typed with Enter", signedOut[0]?.bytes === "/login\r");
check("a command is TYPED: the words, then Enter on its own", signedOut[0]?.typed === "/login");
check("says why in plain words", /signed out/i.test(signedOut[0]?.why ?? ""));
// The exact line a signed-out Claude left in a session on 2026-11-11. The chat
// view reads the reply through this same detector to offer "Sign Claude in".
check(
"a reply asking for /login offers the sign-in command",
screenActions(["Login reached its time limit · Please run /login"], "claude")[0]?.typed ===
"/login",
);
check(
"an agent with no sign-in command gets none invented",
screenActions(["Invalid API key · Please run /login"], "cursor").length === 0,
);
check(
"gemini signs in with its own command",
screenActions(["Please sign in: not logged in"], "gemini")[0]?.display === "/auth",
);
const quota = screenActions(["Claude usage limit reached. Your limit will reset at 5pm"], "claude");
check("out of quota → choose another model", quota[0]?.display === "/model");
const lowContext = screenActions(["Context left until auto-compact: 6%"], "claude");
check("memory nearly full → /compact", lowContext[0]?.display === "/compact");
check(
"plenty of memory left → nothing",
screenActions(["Context left until auto-compact: 42%"], "claude").length === 0,
);
const menu = screenActions(
[" Select model", " 1. Default (recommended)", " ❯ 2. Opus", " 3. Haiku"],
"claude",
);
check("an open menu → Enter first", menu[0]?.bytes === "\r");
check("names the highlighted choice", menu[0]?.why.includes("2. Opus") === true);
check(
"and a way out",
menu.some((a) => a.bytes === "\x1b"),
);
check(
"a menu is answered before anything else on screen",
screenActions(["Invalid API key · Please run /login", "❯ 1. Yes", " 2. No"], "claude")[0]
?.bytes === "\r",
);
check(
"a working screen needs nothing typed",
screenActions(["✻ Building the header…", "Read 3 files"], "claude").length === 0,
);
// A summary or answer's step: commands are typed, prose stays a task.
check("bare command", commandIn("/model opus", "claude") === "/model opus");
check("in backticks", commandIn("`/login`", "claude") === "/login");
check("with a verb in front", commandIn("Type /compact.", "claude") === "/compact");
check(
"a path is a task, not a command",
commandIn("/api/users returns 500 — fix it", "claude") === null,
);
check("an unknown command is not typed", commandIn("/deploy now", "claude") === null);
check("no commands known → never a command", commandIn("/model", "cursor") === null);
const guide = commandGuide("claude") ?? "";
check(
"the guide lists every command",
commandsFor("claude").every((c) => guide.includes(c.text)),
);
check("the summary knows the commands", summaryPrompt("skif", "claude").includes("/model opus"));
check(
"an unknown agent's summary has no command rule",
!summaryPrompt("skif", null).includes("/login"),
);
const ctx = terminalContextAttachment("claude", "Invalid API key · Please run /login");
check(
"an Ask carries the agent, commands and screen",
ctx.content.includes("claude") &&
ctx.content.includes("/login —") &&
ctx.content.includes("Invalid API key"),
);
// A command and its Enter are two writes with a beat between: in one write
// Claude Code reads them as a paste, the CR becomes a newline, and the next
// message is typed after the half-typed command ("/model opusWhy is the
// name of the repo…" → "Model 'opusWhy…' not found", owner, 2026-10-19).
const typed = (async () => {
const writes: { bytes: string; at: number }[] = [];
const record = (bytes: string) => {
writes.push({ bytes, at: Date.now() });
};
await typeCommand(record, "/model opus\r");
check(
"the words first, Enter second, as separate writes",
writes.map((w) => w.bytes).join("|") === "/model opus|\r",
);
check("with a beat between them", writes[1]!.at - writes[0]!.at >= 100);
writes.length = 0;
await runAction(record, signedOut[0]!);
check("a screen action that is a command is typed the same way", writes.length === 2);
await runAction(record, { id: "k", label: "Enter", display: "⏎", bytes: "\r", why: "" });
check("a key is still its bytes, at once", writes.at(-1)!.bytes === "\r" && writes.length === 3);
writes.length = 0;
// Two commands at once (Sonnet, then High, tapped within the beat) go one
// after the other, each with its own Enter — never "/model sonnet/effort high".
await Promise.all([typeCommand(record, "/model sonnet"), typeCommand(record, "/effort high")]);
check(
"two quick commands never interleave",
writes.map((w) => w.bytes).join("|") === "/model sonnet|\r|/effort high|\r",
);
})();
// The runner loads this file without top-level await: finish on the promise.
typed.then(
() => console.log(`\n${passed} passed`),
(e: unknown) => {
console.error(e instanceof Error ? e.message : e);
process.exit(1);
},
);