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
+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) ??