mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 14:07:42 +01:00
fix(terminal): a command is typed then entered, one Loki sheet on the phone, Keys keeps the terminal (#1316)
From a phone the owner switched the model and the session answered
"Model 'opusWhy is the name of the repo…' not found": the command and
its Enter went in one write, Claude Code read it as a paste, the Enter
became a newline, and the next message was typed after it. Then
"What's going on?" opened a sheet with a second composer and a second
model picker, which led to Loki chat and its own "Choose a model".
- Every command button types its words, then Enter as its own
keystroke after a beat (lib/session-keystrokes typeCommand), and
commands queue behind each other so two quick taps never interleave.
Covers the model sheet, the commands sheet, the screen's action chips,
the rail's "Type it" steps and a "/model opus" typed in the box.
- On a phone, "What's going on?" opens the answer: TerminalLokiRail in
sheet form has no composer, no model picker, no run-status filler, a
visible question button and one link to continue in Loki chat.
- Keys open hides the next-step row, so the terminal keeps its lines.
- Loki's model picker is named as Loki's ("Loki answers with"), and on
a phone its button shows the model's name beside the count instead of
"your key" alone.
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
f568852158
commit
882016e080
16 files changed
+347
-75
No files matched your search
@@ -140,7 +140,20 @@ src/
|
||||
│ │ button on the terminal's corner — never a second text
|
||||
│ │ box. While the phone keyboard is up, the app bar and the
|
||||
│ │ view switch step aside and next steps go to one row
|
||||
│ │ (`fc-keyboard-open` in globals.css).
|
||||
│ │ (`fc-keyboard-open` in globals.css). Keys open hides
|
||||
│ │ the next-step row. A command button anywhere TYPES its
|
||||
│ │ words, then Enter as its own keystroke (lib/session-
|
||||
│ │ keystrokes typeCommand) — in one write Claude Code reads
|
||||
│ │ "/model opus\r" as a paste and the CR as a newline.
|
||||
│ │ Three surfaces talk, on purpose, and only three: the
|
||||
│ │ session box (the agent), TerminalLokiRail (Loki about
|
||||
│ │ this session — beside it on a wide screen; on a phone
|
||||
│ │ "What's going on?" opens it as a SHEET showing the
|
||||
│ │ answer and its steps, with no composer and no model
|
||||
│ │ picker, `presentation="sheet"`), and /loki (Loki chat).
|
||||
│ │ Two "models" exist and are named apart: the agent's
|
||||
│ │ (SessionInfo chip, "Opus 5.5") and the one answering
|
||||
│ │ Loki (loki/ModelPicker, "Loki answers with").
|
||||
│ │ See docs/development/responsive-design.md.
|
||||
│ ├── activity/ → ActivityView, EventStream, DigestPanel (fleet activity timeline + digests)
|
||||
│ ├── today/ → StickyNoteCard (captures; Loki "add X to my list"), CalendarCard, WeatherCard, CommitmentsCard, SubscriptionsCard, HabitsList
|
||||
|
||||
@@ -107,7 +107,7 @@ async function main() {
|
||||
await trigger.getByText("1 left").waitFor();
|
||||
assert.equal(budgetCalls, 1);
|
||||
await trigger.click();
|
||||
const dialog = page.getByRole("dialog", { name: "Choose a model" });
|
||||
const dialog = page.getByRole("dialog", { name: "Loki answers with" });
|
||||
await dialog.getByText("Budget reading 2", { exact: true }).waitFor();
|
||||
assert.equal(await dialog.getByRole("button", { name: /Grok 4.7/ }).isEnabled(), true);
|
||||
assert.equal(await dialog.getByRole("button", { name: /GPT-OSS 120B/ }).isVisible(), false);
|
||||
|
||||
@@ -28,10 +28,10 @@ async function main() {
|
||||
stdin: {
|
||||
resolveDir: process.cwd(),
|
||||
loader: "jsx",
|
||||
contents: `import React from 'react';import{createRoot}from'react-dom/client';import{ClaudeChatView}from'./src/components/terminal/ClaudeChatView';import{TerminalMobileHeader}from'./src/components/terminal/TerminalMobileHeader';import{MobileNav}from'./src/components/shell/MobileNav';import{SessionComposer}from'./src/components/terminal/SessionComposer';import{TerminalMobileDock}from'./src/components/terminal/TerminalMobileDock';import{badgeNames}from'./src/components/terminal/terminal-strip-tabs';
|
||||
contents: `import React from 'react';import{createRoot}from'react-dom/client';import{ClaudeChatView}from'./src/components/terminal/ClaudeChatView';import{TerminalMobileHeader}from'./src/components/terminal/TerminalMobileHeader';import{MobileNav}from'./src/components/shell/MobileNav';import{SessionComposer}from'./src/components/terminal/SessionComposer';import{TerminalMobileDock}from'./src/components/terminal/TerminalMobileDock';import{badgeNames}from'./src/components/terminal/terminal-strip-tabs';import{TerminalLokiRail}from'./src/components/terminal/TerminalLokiRail';import{TerminalLokiSheet}from'./src/components/terminal/TerminalExplain';
|
||||
const roster=[{id:'claude',label:'Claude'},{id:'codex',label:'Codex'}];
|
||||
const root=createRoot(document.getElementById('app'));
|
||||
window.mount=(fixture)=>{window.fixture=fixture;const agent=badgeNames(fixture.badge,roster);root.render(<div className="app-shell-frame flex min-h-screen bg-surface-page text-text-primary"><div className="app-main-column"><div className="ui-app-topbar" style={{height:48}}>Loki</div><main className="app-main"><div className="app-page app-viewport-pane flex flex-col" data-fc-place="tab"><TerminalMobileHeader title="Center SOM" state="live" agent={agent} onOpenSheet={()=>{}} immersive={false} onToggleImmersive={()=>{}} view={fixture.terminal?"terminal":"chat"} onViewChange={()=>{}}/>{fixture.terminal?<div className="flex flex-1 flex-col"><div className="flex-1 bg-black p-2 text-xs text-white">terminal</div><TerminalMobileDock onKey={()=>{}} keysOpen={false} onKeysOpenChange={()=>{}} immersive={false} session={{tab:'center-som',channel:'cloud',agent:'claude',onKey:async bytes=>{window.written.push(bytes)}}} box={tools=><SessionComposer tab="center-som" channel="cloud" onKey={async bytes=>{window.written.push(bytes)}} live agent="claude" agentLabel={agent} suggestions={["run the project's unit tests","open the main source file for review"]} onExplain={()=>{}} project="center-som" density="comfortable" tools={tools}/>}/></div>:<ClaudeChatView key={fixture.key} tab="center-som" channel="cloud" onLive={()=>{}} onKey={async bytes=>{window.written.push(bytes)}} onShowTerminal={()=>{}} onExplain={()=>{}}/>}</div></main></div><MobileNav/></div>)};window.written=[];`,
|
||||
window.mount=(fixture)=>{window.fixture=fixture;const agent=badgeNames(fixture.badge,roster);root.render(<div className="app-shell-frame flex min-h-screen bg-surface-page text-text-primary"><div className="app-main-column"><div className="ui-app-topbar" style={{height:48}}>Loki</div><main className="app-main"><div className="app-page app-viewport-pane flex flex-col" data-fc-place="tab"><TerminalMobileHeader title="Center SOM" state="live" agent={agent} onOpenSheet={()=>{}} immersive={false} onToggleImmersive={()=>{}} view={fixture.terminal?"terminal":"chat"} onViewChange={()=>{}}/>{fixture.terminal?<div className="flex flex-1 flex-col"><div className="flex-1 bg-black p-2 text-xs text-white">terminal</div><TerminalMobileDock onKey={()=>{}} keysOpen={false} onKeysOpenChange={()=>{}} immersive={false} session={{tab:'center-som',channel:'cloud',agent:'claude',onKey:async bytes=>{window.written.push(bytes)}}} box={tools=><SessionComposer tab="center-som" channel="cloud" onKey={async bytes=>{window.written.push(bytes)}} live agent="claude" agentLabel={agent} suggestions={["run the project's unit tests","open the main source file for review"]} onExplain={()=>{}} project="center-som" density="comfortable" tools={tools}/>}/></div>:<ClaudeChatView key={fixture.key} tab="center-som" channel="cloud" onLive={()=>{}} onKey={async bytes=>{window.written.push(bytes)}} onShowTerminal={()=>{}} onExplain={()=>{}}/>}</div></main></div><MobileNav/>{fixture.loki&&<TerminalLokiSheet onClose={()=>{}}><TerminalLokiRail presentation="sheet" project="Center SOM" tab="center-som" runId={null} ptyState="live" projectId={null} canSwitchAgent={false} onSwitchAgent={()=>{}} askOnly agent="claude" onKey={()=>{}}/></TerminalLokiSheet>}</div>)};window.written=[];`,
|
||||
},
|
||||
bundle: true,
|
||||
write: false,
|
||||
@@ -242,10 +242,13 @@ async function main() {
|
||||
);
|
||||
await page.screenshot({ path: ".tmp/session-sheet/commands-390.png" });
|
||||
await commands.getByText("Use Opus").click();
|
||||
await page.waitForFunction(
|
||||
() => (window as unknown as { written: string[] }).written.length === 2,
|
||||
);
|
||||
assert.deepEqual(
|
||||
await page.evaluate(() => (window as unknown as { written: string[] }).written),
|
||||
["/model opus\r"],
|
||||
"a command in the sheet is typed into the session",
|
||||
["/model opus", "\r"],
|
||||
"a command in the sheet is typed into the session, Enter on its own",
|
||||
);
|
||||
await page.evaluate(() => Object.assign(window, { written: [] }));
|
||||
await page.keyboard.press("Escape");
|
||||
@@ -284,11 +287,17 @@ async function main() {
|
||||
// sheet stays open saying what is changing.
|
||||
await sheet.getByRole("button", { name: "Sonnet" }).click();
|
||||
await sheet.getByRole("button", { name: "High", exact: true }).click();
|
||||
// The command and its Enter are separate writes with a beat between,
|
||||
// and the second command waits for the first's Enter — two quick taps
|
||||
// never interleave (lib/session-keystrokes typeCommand).
|
||||
await page.waitForFunction(
|
||||
() => (window as unknown as { written: string[] }).written.length === 4,
|
||||
);
|
||||
const written = await page.evaluate(() => (window as unknown as { written: string[] }).written);
|
||||
assert.deepEqual(
|
||||
written,
|
||||
["/model sonnet\r", "/effort high\r"],
|
||||
"each choice is the command with the choice named",
|
||||
["/model sonnet", "\r", "/effort high", "\r"],
|
||||
"each choice is the command with the choice named, then Enter on its own",
|
||||
);
|
||||
assert.ok(
|
||||
await sheet.getByText("Switching to Sonnet").isVisible(),
|
||||
@@ -319,10 +328,9 @@ async function main() {
|
||||
);
|
||||
// A choice already in force sends nothing.
|
||||
await sheet.getByRole("button", { name: "Sonnet" }).click();
|
||||
assert.equal(
|
||||
(await page.evaluate(() => (window as unknown as { written: string[] }).written)).length,
|
||||
2,
|
||||
);
|
||||
await page.waitForTimeout(300);
|
||||
const after = await page.evaluate(() => (window as unknown as { written: string[] }).written);
|
||||
assert.equal(after.length, 4, `a choice in force sends nothing (got ${JSON.stringify(after)})`);
|
||||
|
||||
// Claude Code answers in the log the moment it switches: the sheet,
|
||||
// still open, settles on its word — not on the next answer.
|
||||
@@ -368,9 +376,12 @@ async function main() {
|
||||
// A family the account cannot use: Claude Code's refusal, in its words,
|
||||
// and the model in force stays marked.
|
||||
await sheet.getByRole("button", { name: "Fable" }).click();
|
||||
await page.waitForFunction(
|
||||
() => (window as unknown as { written: string[] }).written.at(-1) === "\r",
|
||||
);
|
||||
assert.equal(
|
||||
(await page.evaluate(() => (window as unknown as { written: string[] }).written)).at(-1),
|
||||
"/model fable\r",
|
||||
(await page.evaluate(() => (window as unknown as { written: string[] }).written)).at(-2),
|
||||
"/model fable",
|
||||
);
|
||||
await mount({
|
||||
key: "chat2",
|
||||
@@ -402,6 +413,45 @@ async function main() {
|
||||
await page.screenshot({ path: ".tmp/session-sheet/sheet-refused-390.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// "What's going on?" on a phone: a sheet with the question, room for
|
||||
// the answer, and one way to Loki chat — no second box, no second model
|
||||
// picker, nothing about the run when nothing is tracked.
|
||||
await mount({
|
||||
key: "chat2",
|
||||
items,
|
||||
connected: true,
|
||||
received: true,
|
||||
sessionId: "s",
|
||||
badge: "claude",
|
||||
loki: true,
|
||||
});
|
||||
const loki = page.getByRole("dialog").filter({ hasText: "Loki on Center SOM" });
|
||||
await loki.waitFor();
|
||||
const lokiBox = await loki.evaluate((d) => {
|
||||
const r = d.getBoundingClientRect();
|
||||
return {
|
||||
top: Math.round(r.top),
|
||||
bottom: Math.round(r.bottom),
|
||||
composers: d.querySelectorAll(".ck-composer").length,
|
||||
pickers: d.querySelectorAll(".ui-loki-model-trigger").length,
|
||||
text: d.textContent ?? "",
|
||||
};
|
||||
});
|
||||
assert.ok(lokiBox.top >= 0 && lokiBox.bottom <= 780, "the sheet is on screen");
|
||||
assert.equal(lokiBox.composers, 0, "no second box in it");
|
||||
assert.equal(lokiBox.pickers, 0, "no second model picker in it");
|
||||
assert.ok(!lokiBox.text.includes("Nothing running"), "no run-status filler");
|
||||
assert.ok(
|
||||
await loki.getByRole("button", { name: "What's going on?" }).isVisible(),
|
||||
"the question is there to ask",
|
||||
);
|
||||
assert.ok(
|
||||
await loki.getByRole("link", { name: /Continue in Loki chat/ }).isVisible(),
|
||||
"and one way to Loki chat",
|
||||
);
|
||||
await page.screenshot({ path: ".tmp/session-sheet/loki-sheet-390.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// An older runner sends no reply: the next answer naming the model
|
||||
// settles it instead.
|
||||
await mount({
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* nothing on the page told them the answer was a command.
|
||||
*/
|
||||
import { commandsFor } from "@/config/agent-commands";
|
||||
import { commandIn, commandGuide, screenActions } from "@/lib/terminal-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;
|
||||
@@ -21,6 +22,7 @@ const signedOut = screenActions(
|
||||
);
|
||||
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 ?? ""));
|
||||
|
||||
check(
|
||||
@@ -92,4 +94,41 @@ check(
|
||||
ctx.content.includes("Invalid API key"),
|
||||
);
|
||||
|
||||
console.log(`\n${passed} passed`);
|
||||
// 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);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* "What's going on?" on a phone opens the ANSWER, not a second chat: Loki's
|
||||
* panel in sheet form has no box of its own, no model picker, no run-status
|
||||
* filler — the answer, its next steps, and one way to Loki chat. The rail
|
||||
* beside the session on a wide screen keeps all of that.
|
||||
*
|
||||
* The phone's sheet used to be the whole rail (owner, 2026-10-19: "too
|
||||
* many different screens… spaghetti UI"): "Nothing running on Xhiva Art.
|
||||
* Send a task below…" above an answer, above a composer with Loki's model
|
||||
* picker reading "Auto" — a hand's width from the session box reading
|
||||
* "Opus 5.5".
|
||||
*
|
||||
* Run: npx tsx scripts/test/terminal-loki-sheet.ts
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { TerminalLokiRail } from "@/components/terminal/TerminalLokiRail";
|
||||
|
||||
const render = (presentation: "rail" | "sheet") =>
|
||||
renderToStaticMarkup(
|
||||
createElement(TerminalLokiRail, {
|
||||
presentation,
|
||||
project: "Xhiva Art",
|
||||
tab: "xhiva-art",
|
||||
runId: null,
|
||||
ptyState: "live",
|
||||
projectId: null,
|
||||
canSwitchAgent: false,
|
||||
onSwitchAgent: () => {},
|
||||
askOnly: true,
|
||||
agent: "claude",
|
||||
onKey: () => {},
|
||||
}),
|
||||
);
|
||||
|
||||
const sheet = render("sheet");
|
||||
assert.ok(!sheet.includes("ck-composer"), "the sheet has no composer of its own");
|
||||
assert.ok(!sheet.includes("ui-loki-model-trigger"), "and no model picker of Loki's");
|
||||
assert.ok(!sheet.includes("Nothing running on"), "no run-status filler");
|
||||
assert.ok(!sheet.includes("Checking this run"), "no run-status filler while loading");
|
||||
assert.ok(sheet.includes("Continue in Loki chat"), "one way to Loki chat, at the foot");
|
||||
assert.ok(sheet.includes("Loki on Xhiva Art"), "it says whose session it reads");
|
||||
assert.ok(
|
||||
/aria-label="What's going on\?"[^>]*>(?:(?!sr-only).)*What's going on\?/s.test(sheet),
|
||||
"the question is a labelled button, visible at phone width",
|
||||
);
|
||||
assert.ok(!sheet.includes('aria-label="Open the full Loki chat"'), "no second link up top");
|
||||
|
||||
const rail = render("rail");
|
||||
assert.ok(rail.includes("ck-composer"), "the rail beside the session keeps its Ask box");
|
||||
assert.ok(rail.includes("Nothing running on"), "and says what the run is doing");
|
||||
assert.ok(!rail.includes("Continue in Loki chat"), "with the chat link in its header instead");
|
||||
|
||||
// The surface renders the one panel in the split as the rail and in the
|
||||
// phone's sheet as the sheet — one component, told which it is.
|
||||
const surface = readFileSync("src/components/terminal/TerminalSurface.tsx", "utf8");
|
||||
assert.match(surface, /<TerminalLokiSheet[^]*?renderLokiRail\("sheet"\)/, "the sheet is the sheet");
|
||||
assert.match(surface, /ui-term-split-rail[^]*?renderLokiRail\("rail"\)/, "the split is the rail");
|
||||
|
||||
console.log("✓ terminal-loki-sheet: the phone's answer sheet has no second chat in it");
|
||||
@@ -96,6 +96,10 @@ const read = (f: string) => readFileSync(join(process.cwd(), "src/components/ter
|
||||
ok(!/inputMode|TerminalInputSwitch|TabVoiceMic/.test(read(f)), `${f}: no input-mode switch`);
|
||||
ok(!surface.includes("<TerminalComposer"), "no second box for the agent under the terminal");
|
||||
ok(/askOnly\b/.test(surface), "Loki's panel only asks; words for the agent go in the box");
|
||||
ok(
|
||||
surface.includes("suggestions={keysOpen ? [] : screenNext.steps}"),
|
||||
"keys open: the next-step row steps aside so the terminal keeps its lines",
|
||||
);
|
||||
const box = read("SessionComposer.tsx");
|
||||
ok(!/voice=\{false\}|attach=\{false\}/.test(box), "the box keeps its microphone and attachments");
|
||||
ok(box.includes("onEmptySlash"), "/ opens the prompt library and the agent's commands");
|
||||
|
||||
+10
-4
@@ -3210,6 +3210,10 @@
|
||||
@apply flex flex-col;
|
||||
max-height: min(var(--modal-max-height), 70vh);
|
||||
}
|
||||
/* Inside the sheet the panel is the sheet: no second frame around it. */
|
||||
.ui-term-loki-insheet {
|
||||
@apply rounded-none border-0 bg-transparent;
|
||||
}
|
||||
|
||||
/* Liveness dot. Bigger than ui-dot because at arm's length on a phone the
|
||||
1.5px status dot is a smudge, and this one answers the only question that
|
||||
@@ -7817,11 +7821,13 @@
|
||||
.ui-loki-model-name {
|
||||
@apply truncate;
|
||||
}
|
||||
/* On a phone the button holds the count, not the name ("✦ 12 left ▾"):
|
||||
the row has ~200px for this and the project chip together, the name was
|
||||
already cut to "A…" there, and the name is first in the menu. */
|
||||
/* On a phone the button reads the model's NAME and the count, short:
|
||||
"Auto · 12 left". It used to drop the name there, and "your key" alone
|
||||
read as a second, unexplained model beside the session box's
|
||||
"Opus 5.5" (owner, 2026-10-19). The count stays: a person running
|
||||
several things wants it before they type (2026-10-15). */
|
||||
.ui-loki-model-name-counted {
|
||||
@apply max-sm:hidden;
|
||||
@apply max-sm:max-w-16;
|
||||
}
|
||||
.ui-loki-model-caret {
|
||||
@apply h-3 w-3 shrink-0 transition-transform;
|
||||
|
||||
@@ -299,7 +299,7 @@ export function ModelPicker({
|
||||
disabled={disabled}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={open}
|
||||
aria-label={`Model: ${current}${budget ? ` — ${budget.headline}` : ""}`}
|
||||
aria-label={`Loki answers with: ${current}${budget ? ` — ${budget.headline}` : ""}`}
|
||||
title={
|
||||
budget ? budget.headline : value ? `Starts at ${current}` : "Auto — best available model"
|
||||
}
|
||||
@@ -340,7 +340,7 @@ export function ModelPicker({
|
||||
</button>
|
||||
|
||||
{open && !phone && (
|
||||
<div className="ui-loki-model-menu" role="dialog" aria-label="Choose a model">
|
||||
<div className="ui-loki-model-menu" role="dialog" aria-label="Loki answers with">
|
||||
{list}
|
||||
</div>
|
||||
)}
|
||||
@@ -366,7 +366,7 @@ export function ModelPicker({
|
||||
id={headingId}
|
||||
className="flex-1 text-center text-base font-semibold text-text-primary"
|
||||
>
|
||||
Choose a model
|
||||
Loki answers with
|
||||
</h2>
|
||||
<span className="w-11" aria-hidden />
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { BuilderChannel } from "@/lib/event-stream-types";
|
||||
import { useDispatchLiveStatus } from "@/hooks/use-dispatch-live-status";
|
||||
import { dispatchToneDotClass } from "@/lib/dispatch-status";
|
||||
import { commandIn } from "@/lib/terminal-commands";
|
||||
import { ESC, typeMessage } from "@/lib/session-keystrokes";
|
||||
import { ESC, typeCommand, typeMessage } from "@/lib/session-keystrokes";
|
||||
import { SuggestionChips } from "./SuggestionChips";
|
||||
import { LokiFiles } from "./LokiFiles";
|
||||
import { SessionPicker } from "./SessionPicker";
|
||||
@@ -163,7 +163,7 @@ export function SessionComposer({
|
||||
try {
|
||||
const command = attachments.length === 0 ? commandIn(message, agent) : null;
|
||||
if (command) {
|
||||
await onKey(`${command}\r`);
|
||||
await typeCommand(onKey, command);
|
||||
setSent({ kind: "typed", what: command });
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type TranscriptItem,
|
||||
} from "@/lib/claude-transcript";
|
||||
import type { BuilderChannel } from "@/lib/constants/statuses";
|
||||
import { typeCommand } from "@/lib/session-keystrokes";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
@@ -153,7 +154,7 @@ export function SessionInfo({
|
||||
const modelListCmd = commandOfKind(agent, "model");
|
||||
const effortCmd = commandOfKind(agent, "effort");
|
||||
const agentName = agent === "claude" ? "Claude Code" : "The agent";
|
||||
const type = (text: string) => void onKey(`${text}\r`);
|
||||
const type = (text: string) => void typeCommand(onKey, text);
|
||||
|
||||
// The chip names the model and nothing else, like the Claude app's: with
|
||||
// the mode beside it, "Opus 5.5 · Auto" truncated in the terminal view's
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import { useEffect, useState, type MutableRefObject } from "react";
|
||||
import { Lightbulb, SquareTerminal } from "lucide-react";
|
||||
import { commandsFor } from "@/config/agent-commands";
|
||||
import { commandAction, type TerminalAction } from "@/lib/terminal-commands";
|
||||
import { runAction, type TerminalAction } from "@/lib/terminal-commands";
|
||||
import { typeCommand } from "@/lib/session-keystrokes";
|
||||
import { useScreenActions } from "./use-screen-actions";
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ export function TerminalActions({
|
||||
const [typed, setTyped] = useTypedNotice();
|
||||
if (actions.length === 0 && !typed) return null;
|
||||
const run = (a: TerminalAction) => {
|
||||
onKey(a.bytes);
|
||||
void runAction(onKey, a);
|
||||
setTyped(a.display);
|
||||
};
|
||||
return (
|
||||
@@ -129,7 +130,7 @@ export function TerminalCommandList({
|
||||
type="button"
|
||||
className="ui-term-command"
|
||||
onClick={() => {
|
||||
onKey(commandAction(c, c.hint).bytes);
|
||||
void typeCommand(onKey, c.text);
|
||||
setTyped(c.text);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { SessionAsk } from "@/hooks/use-session-ask";
|
||||
import { useDispatchLiveStatus } from "@/hooks/use-dispatch-live-status";
|
||||
import { dispatchToneDotClass } from "@/lib/dispatch-status";
|
||||
import { commandIn } from "@/lib/terminal-commands";
|
||||
import { typeCommand } from "@/lib/session-keystrokes";
|
||||
import { SuggestionChips } from "./SuggestionChips";
|
||||
import { TerminalCommandList } from "./TerminalActions";
|
||||
import { terminalComposerModes, type SessionComposerMode } from "./terminal-composer-modes";
|
||||
@@ -143,7 +144,7 @@ export function TerminalComposer({
|
||||
}
|
||||
const command = onKey && attachments.length === 0 ? commandIn(prompt, agent) : null;
|
||||
if (command) {
|
||||
onKey?.(`${command}\r`);
|
||||
if (onKey) void typeCommand(onKey, command);
|
||||
setError(null);
|
||||
setTypedCommand(command);
|
||||
return true;
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import { LOKI_STATUS_COPY } from "@/lib/loki/stream";
|
||||
import type { LiveTurn } from "@/hooks/use-loki-stream";
|
||||
import { commandIn } from "@/lib/terminal-commands";
|
||||
import { typeCommand } from "@/lib/session-keystrokes";
|
||||
import { TerminalComposer } from "./TerminalComposer";
|
||||
|
||||
/**
|
||||
@@ -79,9 +80,19 @@ export function TerminalLokiRail({
|
||||
onStep,
|
||||
agent = null,
|
||||
onKey,
|
||||
presentation = "rail",
|
||||
}: {
|
||||
/** The CLI running in the tab — which commands a step may type. */
|
||||
agent?: string | null;
|
||||
/** `rail`: the panel beside the session on a wide screen — run status,
|
||||
* the conversation, its own Ask box. `sheet`: what "What's going on?"
|
||||
* opens on a phone — the ANSWER, its next steps, and a way to Loki chat;
|
||||
* no second composer, no second model picker, no run-status filler.
|
||||
* The phone's sheet used to be the whole rail: "Nothing running on Xhiva
|
||||
* Art. Send a task below…" over an answer, under a box of its own with
|
||||
* Loki's model picker reading "Auto" beside the session box's "Opus 5.5"
|
||||
* (owner, 2026-10-19: "spaghetti UI"). */
|
||||
presentation?: "rail" | "sheet";
|
||||
/** Types into the session (the keyboard's path). A step that is the agent's
|
||||
* own command ("/model opus") goes here: Inject would wrap it in project
|
||||
* context and the agent would read a sentence about a model. */
|
||||
@@ -235,15 +246,19 @@ export function TerminalLokiRail({
|
||||
view?.stalled && view.diagnostic && view.diagnostic !== view.nextAction
|
||||
? view.diagnostic
|
||||
: null;
|
||||
const hasStatusBody = Boolean(
|
||||
(loading && !view) || error || !view || lines.summary || lines.next || diagnostic,
|
||||
);
|
||||
const sheet = presentation === "sheet";
|
||||
// The sheet says nothing about the run unless there is something to say:
|
||||
// a tracked run's status, a stall, or a dead provider. "Checking this
|
||||
// run…" and "Nothing running…" are the rail's, where there is room.
|
||||
const filler = !sheet && ((loading && !view) || (!loading && !view && !error));
|
||||
const hasStatusBody = Boolean(filler || error || lines.summary || lines.next || diagnostic);
|
||||
const hasBody = hasStatusBody || Boolean(view?.quotaDeath && canSwitchAgent);
|
||||
const quiet = sheet && !hasBody && session.messages.length === 0 && !session.live;
|
||||
|
||||
return (
|
||||
<aside className="ui-term-loki">
|
||||
<aside className={sheet ? "ui-term-loki ui-term-loki-insheet" : "ui-term-loki"}>
|
||||
<header className="ui-term-loki-head">
|
||||
<h2 className="ui-term-loki-title">Loki</h2>
|
||||
<h2 className="ui-term-loki-title">{sheet ? `Loki on ${project}` : "Loki"}</h2>
|
||||
<div className="flex items-center gap-2">
|
||||
{presented && <span className="ui-badge">{presented.label}</span>}
|
||||
<button
|
||||
@@ -255,30 +270,40 @@ export function TerminalLokiRail({
|
||||
className="ui-term-pane-btn"
|
||||
>
|
||||
<Sparkles className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
{/* Icon-only on the narrowest phones, where the label beside the
|
||||
run badge and the open-chat button would push the header wide. */}
|
||||
<span className="max-[400px]:sr-only">What's going on?</span>
|
||||
{/* Icon-only on the narrowest phones in the rail, where the label
|
||||
beside the run badge and the open-chat button would push the
|
||||
header wide. The sheet has no open-chat button up here. */}
|
||||
<span className={sheet ? undefined : "max-[400px]:sr-only"}>What's going on?</span>
|
||||
</button>
|
||||
<Link
|
||||
href={fleetSurfaceHref("chat", project)}
|
||||
className="ui-term-pane-btn"
|
||||
title="Open the full Loki chat"
|
||||
aria-label="Open the full Loki chat"
|
||||
>
|
||||
<ArrowUpRight className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
</Link>
|
||||
{!sheet && (
|
||||
<Link
|
||||
href={fleetSurfaceHref("chat", project)}
|
||||
className="ui-term-pane-btn"
|
||||
title="Open the full Loki chat"
|
||||
aria-label="Open the full Loki chat"
|
||||
>
|
||||
<ArrowUpRight className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{quiet && (
|
||||
<p className="px-3 py-3 text-sm text-text-secondary">
|
||||
Loki reads the session's screen and says what the agent is doing, in plain words,
|
||||
with what you can tell it next.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{hasBody && (
|
||||
<div className="ui-term-loki-body">
|
||||
{loading && !view && (
|
||||
{loading && !view && !sheet && (
|
||||
<p className="flex items-center gap-1 text-xs text-text-muted">
|
||||
<Loader2 className="ui-spinner-xs" /> Checking this run…
|
||||
</p>
|
||||
)}
|
||||
{error && <p className="text-xs text-status-warning">{error}</p>}
|
||||
{!loading && !view && !error && (
|
||||
{!loading && !view && !error && !sheet && (
|
||||
<p className="text-xs text-text-muted">
|
||||
Nothing running on {project}. Send a task below and its progress shows here.
|
||||
</p>
|
||||
@@ -355,7 +380,7 @@ export function TerminalLokiRail({
|
||||
<button
|
||||
key={action}
|
||||
type="button"
|
||||
onClick={() => onKey?.(`${command}\r`)}
|
||||
onClick={() => void typeCommand(onKey!, command)}
|
||||
title="Type this into the terminal and press Enter"
|
||||
className="ui-term-action"
|
||||
>
|
||||
@@ -383,24 +408,38 @@ export function TerminalLokiRail({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* The phone's sheet has no box of its own: the session box under it is
|
||||
where words go, and a conversation with Loki is Loki chat, one tap
|
||||
away, where this thread already is. */}
|
||||
{sheet && (
|
||||
<div className="ui-sheet-foot flex-row gap-2">
|
||||
<Link href={fleetSurfaceHref("chat", project)} className="ui-btn-secondary flex-1">
|
||||
Continue in Loki chat
|
||||
<ArrowUpRight className="h-4 w-4" aria-hidden="true" />
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* THE composer, in Ask/Inject form — the same component (and the
|
||||
same attach, voice and model controls) as Loki chat and the
|
||||
session box. It used to be a bare textarea of its own. */}
|
||||
<div className="ui-term-loki-composer">
|
||||
<TerminalComposer
|
||||
agent={agent}
|
||||
onKey={onKey}
|
||||
askContext={askContext}
|
||||
project={project}
|
||||
tab={tab}
|
||||
modes={askOnly ? ["ask"] : ["ask", "inject"]}
|
||||
defaultMode={askOnly ? "ask" : "inject"}
|
||||
ask={session}
|
||||
draft={draft}
|
||||
ptyLive={ptyState === "live" || Boolean(view?.lastProgressAt)}
|
||||
density="compact"
|
||||
/>
|
||||
</div>
|
||||
{!sheet && (
|
||||
<div className="ui-term-loki-composer">
|
||||
<TerminalComposer
|
||||
agent={agent}
|
||||
onKey={onKey}
|
||||
askContext={askContext}
|
||||
project={project}
|
||||
tab={tab}
|
||||
modes={askOnly ? ["ask"] : ["ask", "inject"]}
|
||||
defaultMode={askOnly ? "ask" : "inject"}
|
||||
ask={session}
|
||||
draft={draft}
|
||||
ptyLive={ptyState === "live" || Boolean(view?.lastProgressAt)}
|
||||
density="compact"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@@ -558,9 +558,10 @@ export function TerminalSurface({
|
||||
);
|
||||
|
||||
// New element per call — never reuse one descriptor in the split AND the sheet.
|
||||
const renderLokiRail = () =>
|
||||
const renderLokiRail = (presentation: "rail" | "sheet") =>
|
||||
projectKey ? (
|
||||
<TerminalLokiRail
|
||||
presentation={presentation}
|
||||
key={`${projectKey}:${initialRunId ?? "latest"}:${channel}`}
|
||||
project={projectKey}
|
||||
tab={activeTab}
|
||||
@@ -835,7 +836,7 @@ export function TerminalSurface({
|
||||
one click away again on the way out. */}
|
||||
{railShown && (
|
||||
<div className="ui-term-split-rail" aria-label="Loki comments and inject">
|
||||
{renderLokiRail()}
|
||||
{renderLokiRail("rail")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -863,10 +864,13 @@ export function TerminalSurface({
|
||||
live={liveState === "live"}
|
||||
agent={activeAgentId}
|
||||
agentLabel={headerAgent ?? "the agent"}
|
||||
suggestions={screenNext.steps}
|
||||
offerFeedback={screenNext.asksForFeedback}
|
||||
// Keys open is a person driving the screen: the next-step row
|
||||
// steps aside so the terminal keeps its lines (it was three
|
||||
// rows tall under the deck, the chips and the box).
|
||||
suggestions={keysOpen ? [] : screenNext.steps}
|
||||
offerFeedback={!keysOpen && screenNext.asksForFeedback}
|
||||
project={projectKey}
|
||||
onExplain={projectKey ? explainer.ask : undefined}
|
||||
onExplain={projectKey && !keysOpen ? explainer.ask : undefined}
|
||||
draft={sessionDraft}
|
||||
focusRequest={focusRequest}
|
||||
density={immersive ? "compact" : "comfortable"}
|
||||
@@ -882,7 +886,7 @@ export function TerminalSurface({
|
||||
)}
|
||||
{explainer.sheetOpen && projectKey && (
|
||||
<TerminalLokiSheet onClose={() => explainer.setSheetOpen(false)}>
|
||||
{renderLokiRail()}
|
||||
{renderLokiRail("sheet")}
|
||||
</TerminalLokiSheet>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -12,11 +12,50 @@ export const ENTER = "\r";
|
||||
export const ESC = "\x1b";
|
||||
const SUBMIT_DELAY_MS = 150;
|
||||
|
||||
export async function typeMessage(
|
||||
/**
|
||||
* One at a time. A message or command is two writes with a beat between,
|
||||
* so two sent within that beat would interleave: Sonnet then High, tapped
|
||||
* quickly, typed "/model sonnet/effort high" and two Enters. Each waits for
|
||||
* the one before it to finish its Enter.
|
||||
*/
|
||||
let queue: Promise<void> = Promise.resolve();
|
||||
function inTurn(run: () => Promise<void>): Promise<void> {
|
||||
const turn = queue.then(run);
|
||||
queue = turn.catch(() => {});
|
||||
return turn;
|
||||
}
|
||||
|
||||
export function typeMessage(
|
||||
onKey: (bytes: string) => void | Promise<void>,
|
||||
text: string,
|
||||
): Promise<void> {
|
||||
await onKey(`${PASTE_START}${text}${PASTE_END}`);
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, SUBMIT_DELAY_MS));
|
||||
await onKey(ENTER);
|
||||
return inTurn(async () => {
|
||||
await onKey(`${PASTE_START}${text}${PASTE_END}`);
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, SUBMIT_DELAY_MS));
|
||||
await onKey(ENTER);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A COMMAND typed as a person types it: the words, a beat, then Enter as its
|
||||
* own keystroke.
|
||||
*
|
||||
* "/model opus\r" in one write is not what a person types: Claude Code reads
|
||||
* a multi-character write as pasted text, and a carriage return inside a
|
||||
* paste is a newline, not a submit. The command then sat in its composer,
|
||||
* and the owner's next message was typed after it and submitted as one
|
||||
* line — "/model opusWhy is the name of the repo…" → "Model 'opusWhy is the
|
||||
* name…' not found" (2026-10-19). The runner's own injectPty learned the
|
||||
* same lesson on long prompts (desktop/src/main/pty-runtime.ts); this is the
|
||||
* one path every command button in the browser takes.
|
||||
*/
|
||||
export function typeCommand(
|
||||
onKey: (bytes: string) => void | Promise<void>,
|
||||
command: string,
|
||||
): Promise<void> {
|
||||
return inTurn(async () => {
|
||||
await onKey(command.replace(/[\r\n]+$/, ""));
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, SUBMIT_DELAY_MS));
|
||||
await onKey(ENTER);
|
||||
});
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
import { commandOfKind, commandsFor, type AgentCommand } from "@/config/agent-commands";
|
||||
import { TERMINAL_KEYS } from "@/config/terminal-keys";
|
||||
import { typeCommand } from "@/lib/session-keystrokes";
|
||||
|
||||
/** Rows from the bottom of the screen worth reading — the live part. */
|
||||
export const COMMAND_WINDOW_ROWS = 40;
|
||||
@@ -25,8 +26,11 @@ export type TerminalAction = {
|
||||
label: string;
|
||||
/** What will be typed, shown in the terminal's own font. */
|
||||
display: string;
|
||||
/** Verbatim bytes written into the session. */
|
||||
/** Verbatim bytes written into the session — for a key. A command is
|
||||
* TYPED instead (`typed`): its words, then Enter as its own keystroke.
|
||||
* `bytes` still says what the whole action amounts to. */
|
||||
bytes: string;
|
||||
typed?: string;
|
||||
/** One sentence: what the screen says, and what this does about it. */
|
||||
why: string;
|
||||
};
|
||||
@@ -50,10 +54,19 @@ export function commandAction(command: AgentCommand, why: string): TerminalActio
|
||||
label: command.label,
|
||||
display: command.text,
|
||||
bytes: `${command.text}\r`,
|
||||
typed: command.text,
|
||||
why,
|
||||
};
|
||||
}
|
||||
|
||||
/** Send an action into the session: a key as its bytes, a command typed. */
|
||||
export function runAction(
|
||||
onKey: (bytes: string) => void | Promise<void>,
|
||||
action: TerminalAction,
|
||||
): Promise<void> {
|
||||
return action.typed ? typeCommand(onKey, action.typed) : Promise.resolve(onKey(action.bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Up to three things to type, most urgent first. Empty when the screen needs
|
||||
* nothing typed — the task chips cover that case, and inventing a command for
|
||||
|
||||
Reference in new issue
Block a user