chat: add the Codex backend

Store a chat's harness with its operator session, expose chat_backends and a
backend choice in New chat, and route each session through a manager. The Codex
adapter uses the App Server's Unix WebSocket for threads, turns, history,
questions and interrupt; OpenCode remains the default and Claude is not
advertised until its sidecar and login are wired.
This commit is contained in:
2026-10-20 12:10:39 +01:00
parent 74b74adee7
commit f7a3a49f94
25 changed files with 1287 additions and 32 deletions
+1
View File
@@ -165,6 +165,7 @@ to it, but the server never lists it and a reload drops it.
| B2 | Pipeline list mini graph | `list_pipelines` (`shape`) | done — each summary now carries the current version's parsed graph as `shape`; the browser draws a label-free miniature from the real `layoutGraph` with terminal-free stage routes. The row shows the name, the shape and only `{N stages}`; the cryptic `id {n} · v{n} · …` line is gone. Verified at 390×844 against the live server: 9 rows, 9 miniatures, and the detail still owns the full Graph tab. Additive field; older clients ignore it. |
| B3 | Equal phone dock cells | — | done — the narrow dock is a four-cell grid (one cell per destination plus Search) with a subgrid for the tablist, so every control has the same width and height. At 390×844 the measured widths are 92/92/92/92 and the row is 48px high. The phone shell uses `100svh` so a browser toolbar cannot hide the tab row while leaving only the Connected/Settings status row visible. |
| B4 | Full-height pipeline Source | — | done — the Source block no longer caps itself at `60vh`; it is as tall as its content and the detail pane owns the scroll. Verified at 390×844: a 4386px definition sits in the full pane (656px viewport) and scrolls. |
| B13 | Codex chat backend | `chat_backends`, `chat_create.backend` | done — OpenCode stays the default. `chat_backends` lists `codex` when the Codex App Server control socket is present; New chat shows a harness choice, the selected backend is stored on the operator-session row and echoed on every session. The Codex adapter connects to the existing App Server over its Unix WebSocket, maps `thread/start`, `turn/start`, `thread/read`, item/tool events, `item/tool/requestUserInput` to the existing question card, and carries the native user-message id so optimistic and history turns reconcile. Verified live: created a Codex chat from the browser, sent a prompt, saw the streamed answer, read it back through `chat_messages`, and saw the Codex chip and title in the list. Claude is not advertised yet: its OAuth session is expired and the SDK/CLI sidecar is still to be built. |
| B12 | One detail header, optimistic sends, thinking above the bubble | — | done — every non-chat detail (pipeline, run, template) now extracts its own `#detailTitle` into a shared `.detail-head` with the same 44px chevron Back control; on phones the button and title are vertically centred, and on wide screens the back control is hidden while the title stays in the header. Chat/create already use the same control. Sending now appends the operator's optimistic user turn immediately (using the native message id OpenCode persists), so the running placeholder cannot appear before their message. While a turn runs, Send stays present beside Stop; a follow-up is queued. The reasoning/thinking block moved outside and above the answer bubble, like the tool summary below it. |
| B11 | Enter composes; live shell bars stay in place | — | done — Enter now inserts a newline (a real CDP Enter produced `first\n` and no prompt), while Ctrl/Cmd+Enter sends; a slash draft still runs its command on Enter. The chat star reserves a 26px corner in the row head, so it no longer covers Streaming/New/Idle. Background-shell frames patch the tasks bar in place instead of full-rendering the pane, keeping the composer mounted. The shell cache was bumped to v2 so an installed PWA picks up these client changes. |
| B10 | Chat titles are shared across devices | `chat_rename` | done — the rename dialog writes the title to the server's operator-session registry (`SetOperatorSessionTitle`) instead of a device-local override. `chat_sessions` already prefers that title, so a second browser opened with a fresh profile showed `Shared rename probe` without any local storage; restoring it to `New chat` did the same. Old local titles are uploaded once on the next list load and then removed. The helper now reads `This name is shared with every device.` |
+16
View File
@@ -949,3 +949,19 @@
.chat-composer-input { padding: 10px 12px; font-size: 15px; }
.chat-turn { font-size: 15px; }
}
/* Chat harness selection and the row's non-OpenCode backend chip. */
.chat-create-backends { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-create-backend { padding: 6px 12px; border: 1px solid var(--border); color: var(--muted); }
.chat-create-backend.selected { border-color: var(--accent); background: var(--tint-selected); color: var(--text); }
.chat-backend-chip {
flex: 0 0 auto;
padding: 1px 6px;
border: 1px solid var(--border);
border-radius: var(--radius-pill);
color: var(--muted);
font-size: 10px;
line-height: 16px;
text-transform: uppercase;
letter-spacing: 0.04em;
}
+2 -1
View File
@@ -336,6 +336,7 @@ const state = {
chatDirectoriesLoaded: false,
chatDirectoriesError: "",
chatCreate: null,
chatBackends: ["opencode"],
};
// The app-wide run-event watch (R10), owned by the connection rather than any
@@ -1692,7 +1693,6 @@ async function applyRoute(route) {
if (!state.chatLoaded) await loadCurrentView();
if (r.kind === "chat") {
state.chatActiveId = null;
state.chatCreate = null;
renderContent();
return;
}
@@ -1710,6 +1710,7 @@ async function applyRoute(route) {
renderContent();
return;
}
state.chatCreate = null;
state.chatActiveId = r.id;
renderContent();
await openChatSession(r.id, { updateRoute: false });
+8
View File
@@ -936,6 +936,7 @@ export function defaultDirectoryChoice(choices) {
export function newChatCreateState(operationId) {
return {
directory: HOME_DIRECTORY,
backend: "opencode",
operationId: str(operationId),
creating: false,
error: "",
@@ -954,6 +955,13 @@ export function selectChatDirectory(create, choice) {
return { ...create, directory, error: "" };
}
/** Choose the harness for a new chat. */
export function selectChatBackend(create, backend) {
const value = str(backend);
if (value === "") return { ...create };
return { ...create, backend: value, error: "" };
}
/** The create failed: stop sending and keep the server's own reason in the pane. */
export function chatCreateFailed(create, message) {
return { ...create, creating: false, error: str(message) };
+2
View File
@@ -62,6 +62,7 @@ export const Protocol = Object.freeze({
CHAT_REOPEN: "chat_reopen",
CHAT_STAR: "chat_star",
CHAT_RENAME: "chat_rename",
CHAT_BACKENDS: "chat_backends",
// The shared live stream (C5). `chat_subscribe` attaches this connection to one
// session's stream (body: the session id); the server then pushes `chat_event`
// frames without a matching request id, so every client watching a session sees
@@ -116,6 +117,7 @@ export const ChatKeys = Object.freeze({
EVENT: "chat_event",
ANSWER: "chat_answer",
RENAME: "chat_rename",
BACKENDS: "chat_backends",
// The composer's payloads (C8/C9). `chat_interrupt` deliberately has no key of
// its own: its body is the same `chat_query` the other session-scoped commands
// carry (internal/protocol/chat.go ChatQuery, Chat.kt interruptRequest), so a
+13 -2
View File
@@ -234,6 +234,11 @@ export class PipelinesRepository {
return (await this.#client.call({ type: Protocol.CHAT_SESSIONS }))[ChatKeys.SESSIONS] ?? [];
}
/** The installed chat harnesses a new session can use. */
async chatBackends() {
return (await this.#client.call({ type: Protocol.CHAT_BACKENDS }))[ChatKeys.BACKENDS] ?? ["opencode"];
}
/**
* Loads a bounded chronological history page. `cursor` is the opaque
* continuation the server returned as `next_cursor`; it is passed back
@@ -469,10 +474,16 @@ export class PipelinesRepository {
* `chat_sessions` for the operator. Automated checks that drive this real page
* set it, so a run can never leave a stray "New chat" in the operator's list.
*/
async chatCreate(title, directory, operationId = newChatOperationId(), { ephemeral = false } = {}) {
async chatCreate(title, directory, operationId = newChatOperationId(), { backend = "opencode", ephemeral = false } = {}) {
const response = await this.#client.call({
type: Protocol.CHAT_CREATE,
[ChatKeys.CREATE]: { title, directory, operation_id: operationId, ...(ephemeral ? { ephemeral: true } : {}) },
[ChatKeys.CREATE]: {
title,
directory,
operation_id: operationId,
...(backend && backend !== "opencode" ? { backend } : {}),
...(ephemeral ? { ephemeral: true } : {}),
},
});
const session = response[ChatKeys.SESSION];
if (!session) {
+52 -1
View File
@@ -135,6 +135,7 @@ import {
seedChatSeen,
sessionActivity,
sessionActivityBadge,
selectChatBackend as selectChatBackendModel,
selectChatDirectory as selectChatDirectoryModel,
sessionTitle,
sessionWorkLabel,
@@ -396,6 +397,22 @@ function currentChatPosition(el) {
return { index, offset };
}
/** The installed chat harnesses, loaded when the create pane opens. */
async function loadChatBackends() {
try {
const backends = await repo.chatBackends();
if (Array.isArray(backends) && backends.length) state.chatBackends = backends;
} catch {
// Keep the OpenCode default; create reports an unavailable backend clearly.
}
renderContent();
}
function selectChatBackend(value) {
state.chatCreate = selectChatBackendModel(state.chatCreate, value);
renderContent();
}
/** The list of the server's operator sessions, narrowed by the search field. */
async function loadChatSessions(force = false) {
if (state.connection.kind !== "connected") {
@@ -490,6 +507,7 @@ function startNewChat() {
renderContent();
focusDetailHeading();
loadChatDirectories();
loadChatBackends();
}
/**
@@ -543,7 +561,9 @@ async function createNewChat() {
try {
// Not ephemeral: this is the operator's own create path (the UI smoke uses the
// same path for its one real session and closes it afterwards).
const created = await repo.chatCreate("New chat", create.directory, create.operationId);
const created = await repo.chatCreate("New chat", create.directory, create.operationId, {
backend: create.backend,
});
state.chatCreate = null;
state.chatSessions = chatCreateSucceeded(state.chatSessions, created);
await openChatSession(created.id);
@@ -1906,6 +1926,11 @@ function renderChatRow(session, duplicateTitles = new Set()) {
});
const head = h("span", { class: "row-head" });
head.append(h("span", { class: "row-title chat-row-title", text: sessionTitle(session) }));
if (session.backend && session.backend !== "opencode") {
head.append(
h("span", { class: "chat-backend-chip", text: chatBackendLabel(session.backend) }),
);
}
// Only the status word, coloured, with no dot and no operator chip. A closed
// session says so here instead of carrying a second chip.
const statusWord = session.closed ? "Closed" : badge;
@@ -1932,6 +1957,15 @@ function renderChatRow(session, duplicateTitles = new Set()) {
* order, the model note and the footer naming the value that will be sent. Every
* server string is set with textContent.
*/
function chatBackendLabel(backend) {
switch (backend) {
case "codex": return "Codex";
case "claude": return "Claude";
case "opencode": return "OpenCode";
default: return String(backend ?? "");
}
}
function renderChatCreate() {
const create = state.chatCreate;
const pane = h("div", { class: "detail chat-detail chat-create" });
@@ -1976,6 +2010,23 @@ function renderChatCreate() {
} else {
pane.append(h("div", { class: "chat-create-prompt muted", text: CHAT_CREATE_PROMPT }));
if ((state.chatBackends ?? []).length > 1) {
const harness = h("div", { class: "chat-create-backends", role: "group", "aria-label": "Chat harness" });
for (const backend of state.chatBackends) {
const active = (create.backend ?? "opencode") === backend;
harness.append(
h("button", {
class: `ghost chat-create-backend${active ? " selected" : ""}`,
type: "button",
"aria-pressed": active ? "true" : "false",
text: chatBackendLabel(backend),
onclick: () => selectChatBackend(backend),
}),
);
}
pane.append(harness);
}
const choices = directoryChoices(state.chatDirectories);
const selected =
choices.find((choice) => choice.createDirectory === create.directory) ??
+3
View File
@@ -1722,6 +1722,7 @@ test("the home row is the only one with a secondary path; recents are labelled b
test("newChatCreateState starts on home, not sending, with the caller's operation id", () => {
assert.deepEqual(newChatCreateState("web-chat-op"), {
directory: HOME_DIRECTORY,
backend: "opencode",
operationId: "web-chat-op",
creating: false,
error: "",
@@ -1733,6 +1734,7 @@ test("selectChatDirectory sends the chosen value and clears a previous refusal",
const recent = { label: "/repo/a", path: "/repo/a", home: false, createDirectory: "/repo/a", secondary: null };
assert.deepEqual(selectChatDirectory(state, recent), {
directory: "/repo/a",
backend: "opencode",
operationId: "op",
creating: false,
error: "",
@@ -1745,6 +1747,7 @@ test("chatCreateFailed keeps the pane open with the server's message; success st
const creating = { ...newChatCreateState("op"), creating: true };
assert.deepEqual(chatCreateFailed(creating, "the directory is not available"), {
directory: "~",
backend: "opencode",
operationId: "op",
creating: false,
error: "the directory is not available",