feat(chat): persist safe Codex next-turn model selection
This commit is contained in:
@@ -10,6 +10,15 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu
|
||||
|
||||
### Chat audit follow-up (2026-10-20, partial — fresh UI captures pending)
|
||||
|
||||
Codex model follow-up (partial, fixture-tested; fresh UI captures pending):
|
||||
model controls now include Codex, using the app-server `model/list` catalog and
|
||||
current `thread/read`/`thread/list` model metadata. Selecting a model saves a
|
||||
per-chat Pipelines registry choice, explicitly labelled **next turn**, and adds
|
||||
the verified `model` override to the next user-initiated `turn/start`, including
|
||||
after a Pipelines restart. This does not call `thread/resume`, start a goal, edit
|
||||
Codex configuration, or claim the remote thread changed before a turn is sent.
|
||||
Versioned protocol evidence and synthetic fixtures: `internal/codex/testdata/`.
|
||||
|
||||
The following supersedes older C8/B18 implementation details below:
|
||||
- Web attachments are limited to **1 MiB total and eight files**, matching the
|
||||
server. Unsupported harnesses reject attachments before upload storage/queueing.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/** Harnesses with a verified catalog and model-selection path. */
|
||||
export function supportsChatModels(backend) {
|
||||
return ["", "opencode", "codex"].includes(String(backend ?? "").trim());
|
||||
}
|
||||
|
||||
/** Never turn an unknown remote model into an invented model name. */
|
||||
export function chatModelLabel(session) {
|
||||
const model = String(session?.model ?? "").trim() || "Model";
|
||||
return session?.model_selection === "next_turn" ? `${model} · next turn` : model;
|
||||
}
|
||||
|
||||
export function chatModelSelectionNote(backend) {
|
||||
return backend === "codex"
|
||||
? "Saved by Pipelines for the next turn you send. Does not resume this thread or edit global Codex configuration."
|
||||
: "Applies to the next turn in this chat.";
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import { backChevronIcon, h } from "../dom.js";
|
||||
import { readChatStars, writeChatStars } from "../chatStars.js";
|
||||
import { chatModelLabel, chatModelSelectionNote, supportsChatModels } from "../chatModels.js";
|
||||
import { describeError } from "../format.js";
|
||||
import { SHELL_OUTPUT_LIMIT, nativeChatMessageId, newChatOperationId } from "../repository.js";
|
||||
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
|
||||
@@ -2578,8 +2579,8 @@ function renderChatSnackbar() {
|
||||
/** The chat header's model control: current model, opens the switcher. */
|
||||
function renderChatModelButton(session) {
|
||||
const backend = String(session?.backend ?? "").trim();
|
||||
if (backend !== "" && backend !== "opencode") return null;
|
||||
const label = String(session?.model ?? "").trim() || "Model";
|
||||
if (!supportsChatModels(backend)) return null;
|
||||
const label = chatModelLabel(session);
|
||||
return h(
|
||||
"button",
|
||||
{
|
||||
@@ -2617,7 +2618,7 @@ function closeChatModelPicker() {
|
||||
|
||||
async function loadChatModels(sessionId) {
|
||||
const backend = state.chatSessions.find((row) => row.id === sessionId)?.backend ?? "opencode";
|
||||
if (backend !== "" && backend !== "opencode") {
|
||||
if (!supportsChatModels(backend)) {
|
||||
state.chatModelsLoading = false;
|
||||
state.chatModelsError = `${chatBackendLabel(backend)} does not support changing models from this client.`;
|
||||
if (state.chatModelPicker?.id === sessionId) renderContent();
|
||||
@@ -2644,8 +2645,8 @@ async function selectChatModel(session, model) {
|
||||
state.chatModelsError = "";
|
||||
renderContent();
|
||||
try {
|
||||
await repo.switchChatModel(session.id, model.provider, model.id);
|
||||
applyChatSessionModel(session.id, model.provider, model.id);
|
||||
const selected = await repo.switchChatModel(session.id, model.provider, model.id);
|
||||
applyChatSessionModel(session.id, model.provider, model.id, selected.selection);
|
||||
state.chatModelPicker = null;
|
||||
} catch (error) {
|
||||
state.chatModelsError = describeError(error);
|
||||
@@ -2655,9 +2656,9 @@ async function selectChatModel(session, model) {
|
||||
}
|
||||
|
||||
/** Apply a successful model switch to the list row and the open thread. */
|
||||
function applyChatSessionModel(sessionId, provider, model) {
|
||||
function applyChatSessionModel(sessionId, provider, model, selection = "") {
|
||||
state.chatSessions = (state.chatSessions ?? []).map((row) =>
|
||||
row.id === sessionId ? { ...row, model, model_provider: provider } : row,
|
||||
row.id === sessionId ? { ...row, model, model_provider: provider, model_selection: selection } : row,
|
||||
);
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (thread) setThread(sessionId, { model, modelProvider: provider });
|
||||
@@ -2682,7 +2683,7 @@ function renderChatModelDialog(session) {
|
||||
panel.append(
|
||||
h("p", {
|
||||
class: "chat-model-helper muted",
|
||||
text: "Applies to the next turn in this chat.",
|
||||
text: chatModelSelectionNote(session.backend),
|
||||
}),
|
||||
);
|
||||
if (state.chatModelsLoading) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { chatModelLabel, chatModelSelectionNote, supportsChatModels } from "../src/chatModels.js";
|
||||
import { PipelinesRepository } from "../src/repository.js";
|
||||
|
||||
test("Codex and OpenCode expose model selection, unverified backends do not", () => {
|
||||
for (const backend of [undefined, "", "opencode", "codex"]) assert.equal(supportsChatModels(backend), true);
|
||||
for (const backend of ["claude", "unknown"]) assert.equal(supportsChatModels(backend), false);
|
||||
});
|
||||
|
||||
test("model control distinguishes saved next-turn choice from remote current model", () => {
|
||||
assert.equal(chatModelLabel({ model: "fixture-current" }), "fixture-current");
|
||||
assert.equal(chatModelLabel({ model: "fixture-selected", model_selection: "next_turn" }), "fixture-selected · next turn");
|
||||
assert.equal(chatModelLabel({ model: null }), "Model");
|
||||
assert.match(chatModelSelectionNote("codex"), /Saved by Pipelines for the next turn/);
|
||||
assert.match(chatModelSelectionNote("codex"), /Does not resume/);
|
||||
});
|
||||
|
||||
test("model switch reply preserves local next-turn acknowledgement", async () => {
|
||||
let sent;
|
||||
const repo = new PipelinesRepository({ call: async (request) => {
|
||||
sent = request;
|
||||
return { chat_model: { ...request.chat_model, selection: "next_turn" } };
|
||||
} });
|
||||
const selected = await repo.switchChatModel("fixture-thread", "fixture-provider", "fixture-model");
|
||||
assert.deepEqual(sent.chat_model, { session_id: "fixture-thread", provider: "fixture-provider", model: "fixture-model" });
|
||||
assert.equal(selected.selection, "next_turn");
|
||||
});
|
||||
Reference in New Issue
Block a user