Files
loki/scripts/test/dispatch-card.ts
CatoandClaude Opus 5.5 227c7529f6 fix(watch): "Chat" and "Watch it" open the agent's conversation, one tap from its terminal (#1073)
* fix(watch): "Chat" and "Watch it" open the agent's conversation, one tap from its terminal

The Watch panel's Chat button opened the general Loki chat, which knows
nothing about the run, and "Watch it" landed on whichever terminal view
localStorage remembered. The terminal page already shows the same session
as the agent's conversation or its raw PTY behind one switch; nothing
deep-linked to it.

- /terminal accepts ?view=chat|terminal; the link wins over the remembered
  view without overwriting it until the reader flips the switch.
- withTerminalView() in lib/fleet-context builds those links.
- Feedback Watch: Chat -> the run's conversation, Terminal -> the raw PTY.
- Loki dispatch card "Watch it" opens the conversation.
- Watch it work: "Follow <agent> live" beside "Open the full terminal".

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

* fix(terminal): read ?view= in useTerminalView so TerminalSurface stays under max-lines-per-function

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-07 09:17:32 -07:00

85 lines
2.5 KiB
TypeScript

/**
* The card under a Loki dispatch: one headline, one next step.
* Case from the report (2026-10-05): queued for this computer, Fleet Runner
* offline — the card offered Control state / Cloud terminal / This computer.
*/
import { presentDispatchCard, terminalHref } from "@/lib/dispatch-card";
let passed = 0;
function check(label: string, cond: boolean): void {
if (!cond) throw new Error(`✗ ${label}`);
passed++;
console.log(` ✓ ${label}`);
}
const base = {
live: null,
staticLabel: "Dispatched",
warn: false,
failed: false,
channel: null,
project: "loki",
projectCount: 1,
} as const;
const queued = {
status: "queued" as const,
label: "Queued",
detail: "waiting for a builder to pick it up",
tone: "neutral" as const,
};
const reported = presentDispatchCard({ ...base, live: queued, warn: true, channel: "local" });
check("names the builder it waits for", reported.headline === "Waiting for this computer");
check("the next step is connecting Fleet Runner", reported.primary?.href === "/download");
check(
"no cloud terminal for local work",
!reported.secondary.some((l) => l.href.includes("terminal")),
);
check("says nothing is lost", /stays queued/.test(reported.detail ?? ""));
const running = presentDispatchCard({
...base,
live: {
status: "working",
label: "Agent is working",
detail: "still working · 2m",
tone: "positive",
},
channel: "local",
});
check("while it runs, watch it", running.primary?.label === "Watch it");
check(
"…as the agent's conversation, on the machine it runs on",
running.primary?.href === "/terminal?source=machine&tab=loki&view=chat",
);
check(
"cloud work opens the cloud terminal",
terminalHref("loki", "cloud") === "/terminal?project=loki",
);
const failed = presentDispatchCard({ ...base, failed: true });
check(
"a failure goes to Control",
failed.primary?.href === "/control?focus=loki" && failed.tone === "negative",
);
const done = presentDispatchCard({
...base,
live: {
status: "completed",
label: "Completed",
detail: "successful outcome recorded",
tone: "positive",
},
});
check("a finished run shows its result", done.primary?.label === "See the result");
const many = presentDispatchCard({ ...base, projectCount: 3 });
check(
"a fan-out links to all of them",
many.secondary.some((l) => l.label === "All 3 in Control"),
);
check("no project, no links", presentDispatchCard({ ...base, project: null }).primary === null);
console.log(`\n${passed}/${passed} dispatch-card cases passed`);