Files
loki/scripts/test/terminal-session-status.ts
CatoandClaude cf7b404820 fix(ux): signed in means the app; a task shows what was asked; sessions lead with what needs you; key names for OrangeCat (#1629)
* 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

* fix(ux): signed in means the app, and a retried task shows what was asked

Two more things the owner met on a phone on 2026-11-11.

- Opening loki.orangecat.ch while signed in showed the marketing page and
  its marketing menu; the way in was a button. A signed-in visitor now lands
  in the app (APP_HOME; RUNNER_HOME inside Fleet Runner). ?site still opens
  the homepage on purpose, and signed-out visitors are unchanged.
- A retried dispatch opens with the escalation block, longer than the 200
  characters isOperatorEnvelope read, so the whole packet ('Escalation
  state … rung 3/4', 'Exit contract') was drawn as the person's message. It
  is recognised now; the bubble shows the task, the packet is one tap away.

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

* feat(orangecat): tell OrangeCat which provider keys a person holds here, by name

The owner's xAI key was on Loki and not on OrangeCat: for the same linked
person Loki's chat answered on grok while OrangeCat's Cat sat on an
exhausted free pool, and neither product could say the other had a key.

The signed actor-status reply now carries modelKeys: vendor, model and the
last-characters hint, one per vendor, never a custom endpoint and never a
key. OrangeCat uses it to suggest adding the same key there.

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

* fix(sessions): the phone's session list leads with what needs you

The picker listed every open session in the order it was opened: 27 rows,
'Loki 2' to 'Loki 15', with the three waiting on the owner somewhere among
them (2026-11-11). orderSessions puts waiting, working and finished
sessions first, with the one in use, and folds the merely-open ones behind
one row, 'N more open sessions'.

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

* ops(hetzner): a read-only report of what uses the box's memory and disk

On 2026-11-11 the box sat at 91-95% memory and 91-93% disk; both sites
reset connections and CI could not sign in against production auth, and
nothing could say what was using either. disk-cleanup.sh reclaims disk;
nothing measured memory.

box-usage.yml runs scripts/hetzner/box-usage.sh over the same SSH setup as
box-doctor. It prints memory by program (names only, never a command
line), agent CLI and browser counts, out-of-memory kills, container
memory, and the largest directories, and changes nothing.

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

* fix(ops): the disk cleanup measures within a budget, so it reaches its plan

Its first run (2026-11-11, dry) was cancelled at 30 minutes having printed
four sizes and planned nothing: du on /opt alone took 14 minutes on a disk
full of node_modules, and the script measures every release before it
plans a single tier. Sizes are for the reader; what was freed is read from
df. Each size now gets 45 seconds and prints 'over 45s' instead of waiting.
The inventory also names /home/ubuntu and the agent directories under it,
which the first run never reached. Workflow limit raised to 60 minutes.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-11 10:38:32 +01:00

119 lines
4.0 KiB
TypeScript

/**
* What each terminal tab says its session is doing — working, needs you,
* finished, open — and which changes are worth telling someone who is looking
* at another session. Same order of precedence as Control's presenter, so the
* two surfaces can never disagree about one session.
*
* Run: npx tsx scripts/test/terminal-session-status.ts
*/
import type { FastProjectState } from "@/lib/control-fast-state";
import { orderSessions, isNewsworthy, sessionStatusOf } from "@/lib/terminal-session-status";
let failures = 0;
function check(name: string, fn: () => void) {
try {
fn();
console.log(` ✓ ${name}`);
} catch (err) {
failures++;
console.log(` ✗ ${name}`);
console.log(` ${err instanceof Error ? err.message : String(err)}`);
}
}
function assert(cond: boolean, msg: string) {
if (!cond) throw new Error(msg);
}
const base: FastProjectState = {
tab: "substrata",
agentRunning: true,
tabOpen: true,
activeAgents: ["claude"],
session: null,
currentPrompt: null,
readyAt: null,
lockAt: null,
closingAt: null,
closedAt: null,
};
const prompt = { key: "k", label: "Fix the build", startedAt: 1 };
const blocked = {
status: "blocked",
done: "",
next: "",
tests: "",
todos: "",
health: "awaiting user",
blockReason: "Which domain?",
} as unknown as FastProjectState["session"];
check("no report yet is no status, never a guess", () => {
assert(sessionStatusOf(null) === null, "expected null");
});
check("a turn in progress is working", () => {
assert(sessionStatusOf({ ...base, currentPrompt: prompt }) === "working", "expected working");
});
check("a handoff blocked on the person is needs-you", () => {
assert(sessionStatusOf({ ...base, session: blocked }) === "needs-you", "expected needs-you");
});
check("working outranks a stale blocked handoff, as in Control", () => {
assert(
sessionStatusOf({ ...base, session: blocked, currentPrompt: prompt }) === "working",
"expected working",
);
});
check("a finished turn with nothing running is done", () => {
assert(sessionStatusOf({ ...base, readyAt: 100 }) === "done", "expected done");
});
check("an open session with no signals is idle", () => {
assert(sessionStatusOf(base) === "idle", "expected idle");
});
check("finishing after work is news; starting work is not", () => {
assert(isNewsworthy("working", "done"), "working → done");
assert(!isNewsworthy("idle", "working"), "idle → working");
assert(!isNewsworthy("done", "done"), "no change");
});
check("starting to wait on the person is news", () => {
assert(isNewsworthy("working", "needs-you"), "working → needs-you");
assert(isNewsworthy("idle", "needs-you"), "idle → needs-you");
});
check("the first report of a session is never news", () => {
assert(!isNewsworthy(undefined, "needs-you"), "first sight should be quiet");
});
check("the session list leads with what needs the person and folds the quiet ones", () => {
const tabs = [
{ id: "loki-2", status: "idle" as const },
{ id: "loki-3", status: null },
{ id: "kivvi", status: "needs-you" as const },
{ id: "loki-4", status: "idle" as const },
{ id: "bias", status: "working" as const },
{ id: "loki-5", status: "idle" as const },
{ id: "solon", status: "done" as const },
{ id: "loki-6", status: "idle" as const },
];
const { first, quiet } = orderSessions(tabs, "loki-4");
assert(
first.map((t) => t.id).join(",") === "kivvi,bias,solon,loki-4",
`needs-you, working, finished, then the one in use: got ${first.map((t) => t.id)}`,
);
assert(quiet.length === 4 && !quiet.some((t) => t.id === "loki-4"), "the rest wait");
});
check("a few quiet sessions are simply listed", () => {
const { first, quiet } = orderSessions(
[
{ id: "a", status: "idle" as const },
{ id: "b", status: "needs-you" as const },
],
null,
);
assert(first.map((t) => t.id).join(",") === "b,a" && quiet.length === 0, "nothing folded");
});
if (failures) {
console.log(`\n${failures} failing`);
process.exit(1);
}
console.log("\nall passing");