Handoff-style /model switch command and per-turn thinking level (#64)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei ZhengandClaude Fable 5 authored and GitHub committed 2026-07-26 16:31:51 +08:00
1 parent 816a823b75
commit 1e23452f48
58 files changed
+1064 -336

No files matched your search

+39 -2
View File
@@ -1,8 +1,9 @@
/**
* agent-mentions.ts unit tests: @ mention matching (cursor prefix / boundary
* rules), candidate filtering, send-time parsing of a leading @ mention,
* generation of the first new-conversation <handoff_from> origin block, and
* <scheduled_task> origin block parsing.
* generation of the first new-conversation <handoff_from> origin block,
* <scheduled_task> origin block parsing, and the /model switch's
* <model_switch_from> origin block round-trip.
*/
import { describe, expect, it } from "vitest";
import type { AgentSummary } from "@prismshadow/penguin-server/api";
@@ -10,7 +11,9 @@ import {
filterAgents,
handoffMessage,
matchMention,
modelSwitchMessage,
parseHandoffMessage,
parseModelSwitchMessage,
parseScheduledMessage,
splitLeadingMention,
} from "../src/features/chat/agent-mentions";
@@ -212,3 +215,37 @@ describe("parseScheduledMessage (parses the scheduled-task origin block, driving
).toBeNull();
});
});
describe("modelSwitchMessage / parseModelSwitchMessage (the /model switch origin block)", () => {
it("round-trips a full origin (session title with parentheses, trace path, workspace, previous pair)", () => {
const origin = {
sessionId: "session-2026-07-24-10-00-00-abcdef01",
sessionTitle: "Fix (the) parser",
tracePath: "/data/p/agents/a/traces/2026-07-24/session-x_001.jsonl",
workspace: "/data/ws",
prevProvider: "deepseek",
prevModelId: "deepseek-v4-pro",
};
expect(parseModelSwitchMessage(modelSwitchMessage(origin))).toEqual(origin);
});
it("minimal origin (session id only) round-trips; optional lines are omitted from the block", () => {
const text = modelSwitchMessage({ sessionId: "session-01" });
expect(text).not.toContain("trace:");
expect(text).not.toContain("workspace:");
expect(text).not.toContain("previous_model:");
expect(parseModelSwitchMessage(text)).toEqual({ sessionId: "session-01" });
});
it("plain messages and longer messages merely containing the block are not misdetected", () => {
expect(parseModelSwitchMessage("hello /model")).toBeNull();
expect(
parseModelSwitchMessage(`before\n${modelSwitchMessage({ sessionId: "s1" })}`),
).toBeNull();
expect(parseModelSwitchMessage(`${modelSwitchMessage({ sessionId: "s1" })}\nafter`)).toBeNull();
// A block without a session line is not an origin block.
expect(
parseModelSwitchMessage("<model_switch_from>\ntrace: /t.jsonl\n</model_switch_from>"),
).toBeNull();
});
});
-29
View File
@@ -77,7 +77,6 @@ function meta(sessionId: string): OmniMessage<SessionMetaPayload> {
model_context_window: 200000,
system_prompt: "",
tools: [],
thinking_level: "default",
agent_state: "/a",
workspace: "/w",
});
@@ -279,34 +278,6 @@ describe("approvals and events", () => {
expect(items(m)).toHaveLength(0);
});
it("captures the session's thinking level from the main session_meta (read-only input-area tag)", () => {
const m = createStreamModel();
expect(m.thinkingLevel).toBeNull();
// The shared helper's meta carries thinking_level "default" (Agent config leaves it unset).
pushMessage(m, meta("session-x"));
expect(m.thinkingLevel).toBe("default");
const m2 = createStreamModel();
pushMessage(
m2,
sessionMeta({
session_id: "session-y",
model_id: "m",
provider: "custom",
model_context_window: 200000,
system_prompt: "",
tools: [],
thinking_level: "medium",
agent_state: "/a",
workspace: "/w",
}),
);
expect(m2.thinkingLevel).toBe("medium");
// An origin-tagged (sub-session) session_meta routes to the nested model and must not clobber the main session's level.
pushMessage(m2, withOrigin(meta("child"), "child"));
expect(m2.thinkingLevel).toBe("medium");
});
it("request_end final state timeout/malformed produces a retry notice item (with attempt number); request_begin marks it as resent", () => {
const m = createStreamModel();
pushMessage(m, requestBegin());
+7 -5
View File
@@ -1,8 +1,10 @@
/**
* thinking-level.ts unit tests: the conversation-time picker's short-name lookup and the
* selectable list — the picker offers only low/medium/high/xhigh (many models cannot disable
* thinking), while "none" stays a displayable stored value; "" (no override yet) and
* session_meta's "default" resolve to null (trigger shows a placeholder; the session tag hides).
* thinking-level.ts unit tests: the conversation-time pickers' short-name lookup and the
* selectable list — both pickers offer only low/medium/high/xhigh (many models cannot disable
* thinking; there is no "follow config" row — the session picker auto-follows the Agent
* config by initializing its display to it), while "none" stays a displayable stored value;
* "" (internally "untouched"/no override) and a legacy meta's "default" resolve to null so
* callers substitute the config level or a placeholder.
*/
import { describe, expect, it } from "vitest";
import {
@@ -40,7 +42,7 @@ describe("thinking level lists", () => {
});
describe("thinkingLevelLabel", () => {
it("returns null for non-levels: '' (no override yet), session_meta's 'default', unknown, null", () => {
it("returns null for non-levels: '' (untouched/no override), a legacy meta's 'default', unknown, null", () => {
expect(thinkingLevelLabel(NAMES, "")).toBeNull();
expect(thinkingLevelLabel(NAMES, "default")).toBeNull();
expect(thinkingLevelLabel(NAMES, "ultra")).toBeNull();