Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): New chat honours the Project's default Agent; the login, goal and draft slash-menu copy says what actually happens (#773)

Yaowei Zhengbd3e82e9f82f
diff --git a/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.md b/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.md
new file mode 100644
index 00000000..8c764036
--- /dev/null
+++ b/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.md
@@ -0,0 +1,44 @@
+# New chat honours the Project's default Agent, and three pieces of copy say what happens
+
+- **Date:** 2026-09-17
+- **Type:** fix
+- **Scope:** `web`, `cli`
+- **PR:** [#773](https://github.com/Prism-Shadow/penguin-harness/pull/773)
+
+[中文版](2026-09-17-new-chat-defaults-and-copy.zh.md)
+
+The sidebar's "New chat" always opened its draft on `default_agent`, overriding the Agent chosen
+under **Project settings → New chat defaults**. A new chat now starts on the Project's new-chat
+defaults. Three pieces of copy that described behaviour the product no longer has were corrected
+alongside: the login page's forgotten-password hint, the "+" menu's image description in goal
+mode, and `/compact` in the draft page's slash menu.
+
+## New chat
+
+- Every "New chat" entry point — the sidebar's pinned button, its header button and group-header
+ "+", the collapsed rail, the chat page's empty state, an Agent card's "New chat" and a plugin's
+ quick start — names in route state only what it is about: an Agent group's "+" or an Agent card
+ names its Agent, a Workspace group's "+" its path. The pinned "New chat" and the collapsed rail
+ stopped naming `default_agent`, and a Workspace group's "+" stopped naming the current Agent.
+- A draft with no Agent named by its entry point or its cache starts on `[default_chat].agent_id`
+ while that names an Agent of the Project, then `default_agent`, then the first Agent
+ (`newChatAgentId`). The Agent picker waits for the Project's defaults instead of first showing
+ the last-used Agent, and saving new defaults over an open draft applies the same order.
+- Before navigating, these entry points also clear what an earlier draft with no typed text left
+ in the new-chat slot, keeping only the model carry-over and staged skills
+ (`prepareNewChatDraft`). An abandoned group "+" no longer stands in for the defaults on the next
+ "New chat", and an Evaluation Center draft whose prompt was deleted no longer files the next
+ ordinary conversation under **Evaluations** as an evaluation run. Typed text is still parked as
+ a draft conversation.
+
+## Copy
+
+- The login page's second footer line said `penguin server reset-admin-password` issues a fresh
+ initial password. It now says the server's next start prints a new first-login link, and that
+ opening it is how a new password is set. The command's own `--help` description in the CLI made the
+ same claim and now says the same thing.
+- In goal mode, the "+" menu's **Upload image** entry described images as sent as file paths on
+ every model. It now reads as it does outside goal mode, since a goal's images ride its first
+ message as ordinary image input and only a model without vision receives them as paths.
+- The draft page's slash menu stopped listing `/compact`, which did nothing there. The draft
+ offers `/goal` and the installed skills.
diff --git a/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.zh.md b/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.zh.md
new file mode 100644
index 00000000..68c3b9a7
--- /dev/null
+++ b/changelog/unreleased/2026-09-17-new-chat-defaults-and-copy.zh.md
@@ -0,0 +1,33 @@
+# 新建对话遵循 Project 的默认 Agent,三处文案如实描述行为
+
+- **Date:** 2026-09-17
+- **Type:** fix
+- **Scope:** `web`, `cli`
+- **PR:** [#773](https://github.com/Prism-Shadow/penguin-harness/pull/773)
+
+[English](2026-09-17-new-chat-defaults-and-copy.md)
+
+侧栏的「新建对话」此前总以 `default_agent` 打开草稿,覆盖了 **Project 设置 → 新对话默认值**中选定的
+Agent。现在新建对话从 Project 的新对话默认值开始。同时修正了三处描述已不存在行为的文案:登录页的忘记密码
+提示、目标模式下「+」菜单对图片的说明,以及草稿页 slash 菜单中的 `/compact`。
+
+## 新建对话
+
+- 每个「新建对话」入口——侧栏常驻按钮、侧栏标题栏的新建按钮与分组头「+」、收起栏、对话页的空状态、
+ Agent 卡片上的「新建对话」以及插件的快速开始——在路由状态中只指明与自身相关的字段:Agent 分组的「+」
+ 或 Agent 卡片指明其 Agent,Workspace 分组的「+」指明其路径。常驻的「新建对话」与收起栏不再指明
+ `default_agent`,Workspace 分组的「+」也不再指明当前 Agent。
+- 入口与草稿缓存都未指明 Agent 的草稿,依次取 `[default_chat].agent_id`(仍指向本 Project 的 Agent 时)、
+ `default_agent`、第一个 Agent(`newChatAgentId`)。Agent 选择器会等 Project 默认值加载完成,不再先显示
+ 最近使用的 Agent;在草稿打开时保存新的默认值,也按同一顺序重选。
+- 这些入口在跳转前还会清理新建对话槽位中、此前一份未输入正文的草稿留下的内容,只保留模型的延续选择与
+ 已选技能(`prepareNewChatDraft`)。因此放弃的分组「+」草稿不会在下一次「新建对话」时顶替默认值,删光了
+ 提示词的评估中心草稿也不会让下一个普通对话作为评估运行归入**评估任务**。已输入的正文照旧停放为草稿对话。
+
+## 文案
+
+- 登录页页脚第二行此前称 `penguin server reset-admin-password` 会重置为新的初始密码;现在改为:执行后
+ 服务再次启动时会打印新的首次登录链接,打开它即可设置新密码。CLI 中该命令自己的 `--help` 说明也有同样的误述,已一并改正。
+- 目标模式下,「+」菜单的**上传图片**一项此前称图片在任何模型上都以文件路径发送;现在与非目标模式显示
+ 相同的说明,因为目标的图片随其第一条消息作为普通图片输入发送,只有不支持视觉的模型才以路径接收。
+- 草稿页的 slash 菜单不再列出在该页不起作用的 `/compact`;草稿提供 `/goal` 与已安装的技能。
diff --git a/packages/cli/src/i18n.ts b/packages/cli/src/i18n.ts
index 7f3c82ce..7126377e 100644
--- a/packages/cli/src/i18n.ts
+++ b/packages/cli/src/i18n.ts
@@ -1397,7 +1397,7 @@ const en: Messages = {
desc: "Stop the server running on this data root and report the outcome as JSON",
},
resetPassword: {
- desc: "Reset the Web admin password to a fresh initial password (the server must be stopped)",
+ desc: "Reset the Web admin account so the next server start prints a new first-login link (the server must be stopped)",
serverRunning: (url) =>
`A PenguinHarness server is running on this data root: ${url}\n` +
`Stop it first, then run \`penguin server reset-admin-password\` again.`,
@@ -2145,7 +2145,7 @@ const zh: Messages = {
desc: "停止本数据根目录上运行的服务,并以 JSON 报告结果",
},
resetPassword: {
- desc: "把 Web 管理员密码重置为新的初始密码(须先停止服务)",
+ desc: "重置 Web 管理员账号,下次启动服务时会打印新的首次登录链接(须先停止服务)",
serverRunning: (url) =>
`该数据根目录已有 PenguinHarness 服务在运行:${url}\n` +
`请先停止它,再重新执行 \`penguin server reset-admin-password\`。`,
diff --git a/packages/web/src/components/layout/app-layout.tsx b/packages/web/src/components/layout/app-layout.tsx
index 33433ee5..6ab04f94 100644
--- a/packages/web/src/components/layout/app-layout.tsx
+++ b/packages/web/src/components/layout/app-layout.tsx
@@ -34,7 +34,7 @@ import {
import { NEW_CHAT_ICON, Sidebar } from "./sidebar";
import { UserMenu } from "./user-menu";
import { DRAFT_SESSION_ID } from "../../features/chat/chat-page";
-import { parkActiveDraft } from "../../features/chat/draft-sessions";
+import { prepareNewChatDraft } from "../../features/chat/new-chat";
import { ChangePasswordDialog } from "../account/change-password-dialog";
import { UpdateModal } from "../account/update-modal";
import { TerminalDockRuntime } from "../../features/terminal/terminal-view-pool";
@@ -70,7 +70,7 @@ const railItemClass = (active: boolean) =>
function CollapsedRail({ onExpand }: { onExpand: () => void }) {
const { user } = useAuth();
const navigate = useNavigate();
- const { agents, currentProject, setCurrentAgentId } = useProject();
+ const { currentProject, setCurrentAgentId } = useProject();
const { sessions, loading } = useSessions();
/**
* Passive: the layout above owns the one fetch per session, so the rail only reads the
@@ -108,12 +108,10 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {
navigate(`/chat/${lastSession.sessionId}`);
};
- /** Mirrors the pinned sidebar's "New chat": parks any typed-but-unsent draft text first (draft-sessions.ts), then a default_agent draft, falling back to the first Agent (an unresolved list defers resolution to the draft page). */
+ /** Mirrors the pinned sidebar's "New chat": parks any typed-but-unsent draft text first, then opens a draft that names nothing, so it starts on the Project's new-chat defaults (new-chat.ts). */
const newChat = () => {
- if (user && currentProject) parkActiveDraft(user.userId, currentProject.projectId);
- const agentId = (agents.find((a) => a.agentId === "default_agent") ?? agents[0])?.agentId;
- if (agentId) setCurrentAgentId(agentId);
- navigate(`/chat/${DRAFT_SESSION_ID}`, agentId ? { state: { agentId } } : undefined);
+ if (user && currentProject) prepareNewChatDraft(user.userId, currentProject.projectId);
+ navigate(`/chat/${DRAFT_SESSION_ID}`);
};
/** Page entries (rail positions 3-8): same routes, same labels as the pinned nav.
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index b3b1f370..bdaccc60 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -1,7 +1,8 @@
/**
* Single-column sidebar, top to bottom:
- * Project switcher -> new chat (default_agent draft) + page nav (Agents → Evaluation Center,
- * one collapsible group behind a nav-row-wide chevron button under its last entry: arrow
+ * Project switcher -> new chat (a draft on the Project's new-chat defaults) + page nav
+ * (Agents → Evaluation Center, one collapsible group behind a nav-row-wide chevron button
+ * under its last entry: arrow
* up = click to collapse, arrow down while collapsed = the way back; state persists in
* localStorage, the pinned new-chat block never collapses) -> Session area with three grouping
* modes (chosen in the section header's list options; the
@@ -29,9 +30,9 @@
* development list is the user's OWN conversations only: an organization's desk and ticket
* Sessions are filtered out of every group, bucket and folder here.
* Desktop keeps it pinned as the left column; mobile puts the whole thing in a drawer.
- * New chats always enter draft state (/chat/new, route state specifies the Agent and optionally
- * the Workspace): Model / Workspace / approval mode are all chosen on the draft input card, so
- * there's no longer a separate "quick / advanced" pair of new-chat dialogs.
+ * New chats always enter draft state (/chat/new; a group header's "+" names its group's Agent or
+ * Workspace in route state): Model / Workspace / approval mode are all chosen on the draft input
+ * card, so there's no longer a separate "quick / advanced" pair of new-chat dialogs.
* Color scheme is white/gray-based: active state uses a solid gray fill, running status uses a small color dot, no large blocks of color.
*/
import { useEffect, useMemo, useRef, useState } from "react";
@@ -172,11 +173,11 @@ import { WorkspaceSelect } from "../../features/chat/workspace-select";
import { clearDraft, sessionDraftKey } from "../../features/chat/draft-cache";
import {
draftSessionTitle,
- parkActiveDraft,
removeDraftSession,
useDraftSessions,
} from "../../features/chat/draft-sessions";
import type { DraftSessionEntry } from "../../features/chat/draft-sessions";
+import { prepareNewChatDraft } from "../../features/chat/new-chat";
import { CreateProjectDialog, ProjectSettingsDialog } from "./project-dialogs";
import { UserMenu } from "./user-menu";
import { navNoteFor, useUpdateBadges } from "../../lib/use-update-badges";
@@ -391,7 +392,6 @@ export function Sidebar({
setCurrentProjectId,
reloadProjects,
agents,
- currentAgent,
setCurrentAgentId,
} = useProject();
const {
@@ -1204,18 +1204,18 @@ export function Sidebar({
/**
* New chat: enters draft state (/chat/new) without creating a Session — Model / Workspace /
* approval mode are all chosen on the draft input card, and the Session is only actually
- * created when the first message is sent. The route state explicitly carries the target
- * Agent: the agent-mode group header's "+" uses that group's Agent, while the menu's "New
- * chat" uses default_agent; this explicit intent overrides the previously selected Agent in
- * the draft cache (the rest of the draft content, such as the message body, is preserved).
- * The workspace-mode group header's "+" additionally carries that group's Workspace path
- * ("" = a temporary workspace), pre-filling the draft's Workspace selection the same way.
+ * created when the first message is sent. Route state carries only what the clicked entry
+ * is about: the agent-mode group header's "+" names that group's Agent, the workspace-mode
+ * group header's "+" names that group's Workspace path ("" = a temporary workspace), and the
+ * pinned "New chat" and the header's create button name nothing. Every field left unnamed
+ * starts on the Project's new-chat defaults, then the built-in fallback (new-chat.ts).
*/
- const newChat = (agentId?: string, workspace?: string) => {
+ const newChat = ({ agentId, workspace }: { agentId?: string; workspace?: string } = {}) => {
// Typed-but-unsent text in the ACTIVE new-chat draft becomes a parked draft
// conversation first (a row in the list below, sendable anytime — draft-sessions.ts),
- // so this click always lands on an empty composer and never silently shelves content.
- if (user && currentProjectId) parkActiveDraft(user.userId, currentProjectId);
+ // so this click always lands on an empty composer and never silently shelves content;
+ // the selections a text-less earlier visit left behind are released with it.
+ if (user && currentProjectId) prepareNewChatDraft(user.userId, currentProjectId);
if (agentId) setCurrentAgentId(agentId);
const state = {
...(agentId ? { agentId } : {}),
@@ -1235,12 +1235,6 @@ export function Sidebar({
setDeletingDraft(null);
};
- /** Target of the menu's "New chat": default_agent, falling back to the first Agent (if the list isn't ready yet, resolution is deferred to the draft page). */
- const defaultAgentId = (agents.find((a) => a.agentId === "default_agent") ?? agents[0])?.agentId;
-
- /** A Session always needs an Agent, so the workspace-mode "+" uses the current Agent, falling back to default_agent. */
- const workspaceNewChatAgentId = currentAgent?.agentId ?? defaultAgentId;
-
/** What the header's create button makes, and its tooltip (the created object follows the grouping mode). */
const newEntity = newEntityForGroupMode(groupMode);
const newEntityLabel =
@@ -1868,7 +1862,7 @@ export function Sidebar({
<div className="shrink-0 px-2 pb-2 pt-2">
<button
type="button"
- onClick={() => newChat(defaultAgentId)}
+ onClick={() => newChat()}
className={`flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors duration-150 ${
activeSessionId === DRAFT_SESSION_ID
? "bg-gray-200/70 text-gray-900 dark:bg-gray-800 dark:text-gray-100"
@@ -2310,7 +2304,7 @@ export function Sidebar({
type="button"
title={S.chat.newSessionMenu}
aria-label={S.chat.newSessionMenu}
- onClick={() => newChat(agent.agentId)}
+ onClick={() => newChat({ agentId: agent.agentId })}
className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-gray-400 transition-colors duration-150 hover:bg-gray-200/70 hover:text-gray-800 dark:text-gray-500 dark:hover:bg-gray-800 dark:hover:text-gray-200"
>
<Icon d="M12 5v14M5 12h14" size={ICON_SIZE.groupHeaderAction} />
@@ -2411,12 +2405,12 @@ export function Sidebar({
actions={
<>
<GroupPinButton pinned={pinned} onToggle={() => togglePin(group.key)} />
- {/* New chat in this Workspace: pre-fills the group's path in the draft ("" = temporary workspace); the Agent is the current one, falling back to default_agent */}
+ {/* New chat in this Workspace: pre-fills the group's path in the draft ("" = temporary workspace); the Agent is the Project's new-chat default, like any other new chat */}
<button
type="button"
title={S.chat.newSessionInWorkspace}
aria-label={S.chat.newSessionInWorkspace}
- onClick={() => newChat(workspaceNewChatAgentId, group.fullPath ?? "")}
+ onClick={() => newChat({ workspace: group.fullPath ?? "" })}
className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-gray-400 transition-colors duration-150 hover:bg-gray-200/70 hover:text-gray-800 dark:text-gray-500 dark:hover:bg-gray-800 dark:hover:text-gray-200"
>
<Icon d="M12 5v14M5 12h14" size={ICON_SIZE.groupHeaderAction} />
diff --git a/packages/web/src/features/agents/agents-page.tsx b/packages/web/src/features/agents/agents-page.tsx
index ba1a5891..26f7a34e 100644
--- a/packages/web/src/features/agents/agents-page.tsx
+++ b/packages/web/src/features/agents/agents-page.tsx
@@ -62,7 +62,7 @@ import {
} from "../../components/ui/icons";
import { STAT_ICONS } from "../../lib/stat-icons";
import { DRAFT_SESSION_ID } from "../chat/chat-page";
-import { parkActiveDraft } from "../chat/draft-sessions";
+import { prepareNewChatDraft } from "../chat/new-chat";
import { ActivitySparkline } from "./activity-sparkline";
import {
SNAPSHOT_ACCEPT,
@@ -345,8 +345,9 @@ export function AgentsPage() {
* rather than the previous one from the cache.
*/
const newChat = (agentId: string) => {
- // Typed-but-unsent draft text becomes a parked draft conversation first (draft-sessions.ts).
- if (user && projectId) parkActiveDraft(user.userId, projectId);
+ // Typed-but-unsent draft text becomes a parked draft conversation first, and every field
+ // but the Agent starts on the Project's new-chat defaults (new-chat.ts).
+ if (user && projectId) prepareNewChatDraft(user.userId, projectId);
setCurrentAgentId(agentId);
navigate(`/chat/${DRAFT_SESSION_ID}`, { state: { agentId } });
};
diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsx
index 56a2ea28..ac1b1741 100644
--- a/packages/web/src/features/chat/chat-input.tsx
+++ b/packages/web/src/features/chat/chat-input.tsx
@@ -949,7 +949,7 @@ export function ChatInput({
*/
onHandoff?: (target: AgentSummary, input: TaskInputPart[]) => Promise<boolean>;
onStop: () => Promise<void>;
- /** Manual context compaction (/compact). Optional: without it the command is not offered (the subagent variant has no compaction surface). */
+ /** Manual context compaction (/compact). Optional: without it the command is not offered (the draft has no Session to compact, and the subagent variant has no compaction surface). */
onCompact?: () => Promise<void>;
/** Currently selected model reference ((provider, modelId) is the unique key); null = not yet chosen. */
modelRef: ModelRefDto | null;
@@ -1160,9 +1160,10 @@ export function ChatInput({
pendingModel !== null ||
selectedSkills.length > 0;
// Goal mode (engaged via the "+" menu or /goal): the text body becomes the objective. It is
- // exclusive with a staged /agent or /model switch (engaging either clears the other); attached
- // images ride along (core folds them into the objective as path lines) and selected skills ride
- // round-1 message as a [use_skills] block, exactly like a normal send.
+ // exclusive with a staged /agent or /model switch (engaging either clears the other). Attached
+ // images and selected skills ride the round-1 message exactly as in a normal send: the images
+ // as image input (path lines only on a model without vision), the skills as a [use_skills]
+ // block. Later rounds restate the objective text alone.
const [goalOn, setGoalOn] = useState(false);
const [goalBudgetText, setGoalBudgetText] = useState("");
const [goalBudgetOpen, setGoalBudgetOpen] = useState(false);
@@ -1195,9 +1196,8 @@ export function ChatInput({
// parseable budget — and an open editor showing an invalid draft disables Send outright:
// combined with the editor refusing to close over an invalid draft (below), no click sequence
// can fire a goal with a stale committed budget.
- // Images may come along with a goal objective (core folds them into `[attached image: …]`
- // lines so they survive the rounds), but they don't substitute for the text; file
- // attachments cannot — nothing folds those into a re-injected objective.
+ // Images may come along with a goal objective (they ride its round-1 message), but they don't
+ // substitute for the text; file attachments cannot — the server refuses them on a goal.
const canSend =
!running &&
!compacting &&
@@ -1250,10 +1250,10 @@ export function ChatInput({
}, [goalBudgetDraft]);
/**
- * Engage/exit goal mode; engaging clears any staged switch chip and every attachment
+ * Engage/exit goal mode; engaging clears any staged switch chip and every file attachment
* (genuinely exclusive: a handoff or a model switch opens another session, and the server
- * rejects non-text goal input). Selected skills stay — they ride the round-1 message as a
- * [use_skills] block, like a normal send.
+ * refuses file attachments on a goal). Attached images and selected skills stay — they ride
+ * the round-1 message, like a normal send.
*/
const toggleGoal = useCallback(
(on: boolean) => {
@@ -1266,9 +1266,9 @@ export function ChatInput({
onHandoffTargetChange?.(null);
setPendingModel(null);
onPendingModelChange?.(null);
- // Images ride a goal (folded into the objective as path lines), file attachments do not
- // — the server refuses those, so clear them or canSend would stay silently false with
- // the objective looking ready.
+ // Images ride a goal's round-1 message, file attachments do not — the server refuses
+ // those, so clear them or canSend would stay silently false with the objective looking
+ // ready.
setAttachments([]);
}
},
@@ -1536,8 +1536,9 @@ export function ChatInput({
},
]
: []),
- // Goal mode is a main-session concept: the subagent variant offers no way in.
- ...(variant === "session"
+ // Goal mode is offered wherever a main conversation is composed, the draft included (its
+ // first send starts the goal): only the subagent variant offers no way in.
+ ...(variant !== "subagent"
? [
{
cmd: "/goal",
@@ -1593,8 +1594,10 @@ export function ChatInput({
})),
];
}, [
+ variant,
onCompact,
onSwitchModel,
+ onHandoff,
models,
agents,
onTextChange,
@@ -1850,16 +1853,16 @@ export function ChatInput({
post: (input: TaskInputPart[], goal: { budget: number } | null) => Promise<boolean> = onSend,
) => {
const t = text.trim();
- // Goal mode: the trimmed text is the objective (no images, no staged switch — both are
- // cleared when the chip goes on). Selected skills prefix the round-1 message as a
+ // Goal mode: the trimmed text is the objective (no file attachments, no staged switch —
+ // both are cleared when the chip goes on). Selected skills prefix the round-1 message as a
// [use_skills] block, exactly like a normal send — the server strips leading marker blocks
// when recording the objective, and rounds after the first re-inject the objective alone.
if (goalOn) {
- // Objective only: attachments were already cleared when goal mode engaged (and blocked
+ // No file attachments: they were already cleared when goal mode engaged (and blocked
// from being added since), so there is nothing to carry here.
setBusy(true);
try {
- // Attached images go with the objective (see the goalOn declaration above).
+ // Attached images ride the round-1 message (see the goalOn declaration above).
const goalInput: TaskInputPart[] = [
{ type: "text", text: buildSkillsMessage(selectedSkills, t) },
];
@@ -2123,7 +2126,7 @@ export function ChatInput({
* picked in, not the order the reads happened to finish in.
*/
const addAttachments = (files: Iterable<File>) => {
- if (goalOn) return; // goal input is text-only, same rule as images
+ if (goalOn) return; // a goal takes no file attachments: the server refuses them
const { accepted: picked, rejected } = splitBySize(files, uploadLimits.attachmentMaxMb);
for (const file of rejected) {
toastError(S.chat.attachmentTooLarge(file.name, uploadLimits.attachmentMaxMb));
@@ -2728,9 +2731,10 @@ export function ChatInput({
label: S.chat.uploadImage,
// Without vision the images still send — as scratchpad file paths — so the
// entry stays usable and the hint says what will happen instead. Goal mode
- // sends them that way on any model, since the objective is re-injected as
- // text every round.
- desc: vision && !goalOn ? S.chat.uploadImageDesc : S.chat.imagesAsPathHint,
+ // changes nothing here: a goal's images ride its first message as ordinary
+ // image input, so the model's vision decides how they arrive, exactly as
+ // for any other send.
+ desc: vision ? S.chat.uploadImageDesc : S.chat.imagesAsPathHint,
active: images.length > 0,
onSelect: () => imageInputRef.current?.click(),
},
@@ -2743,8 +2747,8 @@ export function ChatInput({
// inlined into the conversation.
desc: S.chat.uploadFileDesc,
active: attachments.length > 0,
- // Unlike images, a file cannot ride a goal: nothing folds it into the
- // objective that every round re-injects, so the server refuses it.
+ // Unlike images, a file cannot ride a goal: the server refuses file
+ // attachments on a goal request.
disabled: goalOn,
onSelect: () => attachmentInputRef.current?.click(),
},
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index 1065ed9f..3f401b8d 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -95,7 +95,7 @@ import type { StagedThinkingSwitch } from "./thinking-level";
import { ChatDropRegion } from "./drop-zone";
import { ConversationOutline, OutlineMenuButton, useOutlineRailFit } from "./conversation-outline";
import { DraftView } from "./draft-view";
-import { parkActiveDraft } from "./draft-sessions";
+import { prepareNewChatDraft } from "./new-chat";
import { resolveRoutedSession, sessionForProject, sessionProbeKey } from "./session-project";
import { CHAT_DEFAULTS_CHANGED_EVENT, chatDefaultsChangedDetail } from "./chat-defaults-event";
import { advanceCostStat, applyUsageFetch, createCostStatHold } from "./header-stats";
@@ -1500,9 +1500,10 @@ export function ChatPage() {
// "New Chat" = enter draft state: no Session is created until the first message is sent.
// Typed-but-unsent text in the ACTIVE new-chat draft first becomes a parked draft
// conversation (a sidebar row, sendable anytime) instead of lingering invisibly in the
- // cache — the sidebar's own new-chat entries do the same (sidebar.tsx).
+ // cache, and the draft starts on the Project's new-chat defaults — the sidebar's own
+ // new-chat entries do the same (new-chat.ts).
const newChat = useCallback(() => {
- if (user && projectId) parkActiveDraft(user.userId, projectId);
+ if (user && projectId) prepareNewChatDraft(user.userId, projectId);
navigate(`/chat/${DRAFT_SESSION_ID}`);
}, [user, projectId, navigate]);
diff --git a/packages/web/src/features/chat/draft-view.tsx b/packages/web/src/features/chat/draft-view.tsx
index 4df1c9e6..9b654aab 100644
--- a/packages/web/src/features/chat/draft-view.tsx
+++ b/packages/web/src/features/chat/draft-view.tsx
@@ -21,14 +21,14 @@
* The one thing that does not resume is a prompt a "Create with AI" surface composed
* (`aiPrefill`, draft-cache.ts): nobody typed it, so leaving this page without editing
* or sending it clears the slot exactly as a send would (see dropAiPrefill).
- * The sidebar group header "+" / menu "New conversation" explicitly specify an
- * Agent via route state (overriding the cached selection); the workspace-mode
- * group header "+" additionally carries a Workspace path pre-filling the
- * Workspace selection ("" = temporary workspace). A direct visit or refresh
- * falls back to the cache. When neither route state nor the mount-time cache claims a
- * field, the Project's new-chat defaults ([default_chat]) prefill Agent / Workspace /
- * approval mode (precedence: route state > draft cache > project default > built-in
- * fallback); the model default already flows through models.defaultModel.
+ * Every "New chat" entry point first rewrites the slot to the model carry-over and staged
+ * skills, releasing whatever else an earlier visit left in the cache (prepareNewChatDraft,
+ * new-chat.ts), then names in route state only what it is about: an Agent group's "+" or
+ * an Agent card names its Agent, a Workspace group's "+" its path ("" = temporary
+ * workspace), and the plain "New chat" names nothing. A direct visit or refresh keeps the
+ * cache. Precedence per field: route state > draft cache > the Project's new-chat defaults
+ * ([default_chat]) > built-in fallback (for the Agent: default_agent, then the first —
+ * newChatAgentId); the model default already flows through models.defaultModel.
*
* Saving the Project's new-chat defaults resets the seeded selections so new chats pick
* the change up: the project-settings dialog strips the cached pins (next visits reseed
@@ -88,6 +88,7 @@ import {
chatDefaultsChangedDetail,
type ChatDefaultsChangedDetail,
} from "./chat-defaults-event";
+import { newChatAgentId } from "./new-chat";
import { effectiveThinkingLevel } from "./thinking-level";
import { WorkspaceSelect, pillClass } from "./workspace-select";
import { sameModelRef } from "../models/model-grouping";
@@ -156,7 +157,7 @@ export function DraftView({
}) {
const navigate = useNavigate();
const location = useLocation();
- const { agents, currentAgent, setCurrentAgentId } = useProject();
+ const { agents, setCurrentAgentId } = useProject();
const { add } = useSessions();
// The draft key includes a user dimension (#68 cross-account leakage). RequireAuth
// guarantees the user is logged in here; on the off chance there's no user (the
@@ -185,9 +186,9 @@ export function DraftView({
if (parkedMissing) navigate("/chat/new", { replace: true });
}, [parkedMissing, navigate]);
- const [agentId, setAgentId] = useState<string | null>(
- cached.agentId ?? currentAgent?.agentId ?? null,
- );
+ // Null until something names an Agent: the cache here, otherwise the resolution effect below
+ // once the Agent list and the Project's defaults are in — never a stand-in it would swap out.
+ const [agentId, setAgentId] = useState<string | null>(cached.agentId ?? null);
const [workspace, setWorkspace] = useState(cached.workspace ?? "");
// A terminal opened while drafting starts in the Workspace chosen here; "" is the
// temporary Workspace, whose directory the server only creates with the Session, so
@@ -247,28 +248,28 @@ export function DraftView({
* Fields the user already touched this mount: the project defaults arrive async (after
* mount), and an explicit pick made in the meantime must never be clobbered by them.
* The mount-time cache (`cached`) covers everything picked in PREVIOUS visits; these
- * refs cover the window between mount and the defaults resolving.
+ * refs cover the window between mount and the defaults resolving. The Agent needs no flag:
+ * the resolution below never replaces a valid selection.
*/
- const touchedRef = useRef({ agent: false, workspace: false, approval: false });
+ const touchedRef = useRef({ workspace: false, approval: false });
// Unified resolution of the Agent selection (a single effect, single writer):
- // explicit route state > current valid value (from cache / panel selection) >
- // default_agent > the first one. Explicit intent (sidebar group header "+" / menu
- // "New conversation") is applied only once per location.key — clicking "+" again
- // for the same Agent gets a new key and re-aligns, while the user's subsequent
- // reselection in the panel won't keep getting overridden. Merging this into one
- // effect is essential: splitting it into an "apply state" effect and a "fallback
- // on invalid value" effect would let the former write B in one render while the
- // latter, still judging by the stale closure's invalid value, writes the default
- // Agent and clobbers B.
+ // explicit route state > current valid value (from cache / panel selection) > the
+ // new-chat default Agent (newChatAgentId: the Project's `[default_chat].agent_id`, then
+ // default_agent, then the first one), which waits for the Project's defaults to resolve.
+ // Explicit intent (an Agent group's "+", an Agent card) is applied only once per
+ // location.key — clicking "+" again for the same Agent gets a new key and re-aligns, while
+ // the user's subsequent reselection in the panel won't keep getting overridden. Merging
+ // this into one effect is essential: splitting it into an "apply state" effect and a
+ // "fallback on invalid value" effect would let the former write B in one render while the
+ // latter, still judging by the stale closure's invalid value, writes the default Agent and
+ // clobbers B.
const routeState = location.state as {
agentId?: string;
workspace?: string;
} | null;
const stateAgentId = routeState?.agentId;
const appliedStateKey = useRef<string | null>(null);
- /** One-shot marker for the project-default Agent (seeding precedence, see below). */
- const appliedDefaultAgent = useRef(false);
useEffect(() => {
if (agents.length === 0) return; // list not ready yet, nothing to validate against — wait for the next pass
const valid = (id: string | null | undefined): id is string =>
@@ -285,26 +286,12 @@ export function DraftView({
return;
}
}
- // Project default ([default_chat].agent_id), inserted ahead of the fallback chain:
- // applied at most once per mount, and only when nothing above it claims the field —
- // no route override consumed this mount, no mount-time cached selection, no panel pick
- // since mount (precedence: route state > draft cache > project default > the
- // currentAgent/default_agent/first fallback the initial state and the line below give).
- if (chatDefaults?.agentId !== undefined && !appliedDefaultAgent.current) {
- appliedDefaultAgent.current = true;
- if (
- appliedStateKey.current === null &&
- cached.agentId === undefined &&
- !touchedRef.current.agent &&
- valid(chatDefaults.agentId)
- ) {
- setAgentId(chatDefaults.agentId);
- return;
- }
- }
if (valid(agentId)) return;
- setAgentId((agents.find((a) => a.agentId === "default_agent") ?? agents[0])?.agentId ?? null);
- }, [agents, agentId, location.key, stateAgentId, chatDefaults, cached.agentId]);
+ // Nothing names a valid Agent (no route override, no cached or picked one, or the one
+ // there was is gone): the new-chat default, once the Project's defaults are known.
+ if (chatDefaults === null) return;
+ setAgentId(newChatAgentId(agents, chatDefaults));
+ }, [agents, agentId, location.key, stateAgentId, chatDefaults]);
// Explicit Workspace from route state (the workspace-mode group header "+"): applied once per
// location.key, same convention as the Agent above, overriding the cached selection ("" pre-fills
@@ -383,30 +370,19 @@ export function DraftView({
const d = detail.defaults;
defaultsFromEventRef.current = true;
setChatDefaults(d);
- touchedRef.current = { agent: false, workspace: false, approval: false };
+ touchedRef.current = { workspace: false, approval: false };
setWorkspace(d.workspace ?? "");
setApprovalMode(d.approvalMode ?? "allow-all");
- const valid = (id: string | undefined): id is string =>
- id !== undefined && agents.some((a) => a.agentId === id);
- if (valid(d.agentId)) {
- setAgentId(d.agentId);
- } else if (agents.length > 0) {
- // No (valid) default Agent in the new block: the same fallback chain a fresh
- // mount runs — the global current Agent, then default_agent, then the first.
- // Skipped while the list is empty (nothing to validate against; keep the pick).
- setAgentId(
- currentAgent?.agentId ??
- (agents.find((a) => a.agentId === "default_agent") ?? agents[0])?.agentId ??
- null,
- );
- }
+ // The Agent a fresh mount would now start on (the new block's default while it names
+ // an Agent, then default_agent, then the first).
+ setAgentId(newChatAgentId(agents, d));
}
// New default model: adopt it directly (the event carries the authoritative pair).
// Setting null and leaning on the fallback effect would race ChatPage's models
// refetch and re-pin the STALE default from the old models prop.
if (detail.defaultModel !== undefined) setModelRef(detail.defaultModel);
},
- [agents, currentAgent],
+ [agents],
);
/** Latest-closure mirror for the window listener (same convention as persistRef). */
const onDefaultsChangedRef = useRef(onDefaultsChanged);
@@ -648,7 +624,6 @@ export function DraftView({
}, [cancelPendingSave, userId, projectId, draftId, modelRef]);
const selectAgent = (a: AgentSummary) => {
- touchedRef.current.agent = true; // an explicit pick outranks a late-arriving project default
setAgentId(a.agentId);
// Follow through to the global current Agent: keeps the sidebar memory and stats convention consistent.
setCurrentAgentId(a.agentId);
@@ -804,7 +779,6 @@ export function DraftView({
controlRef={composerRef}
onSend={onSend}
onStop={async () => undefined}
- onCompact={async () => undefined}
modelRef={modelRef}
models={models?.models ?? []}
onChangeModel={setModelRef}
diff --git a/packages/web/src/features/chat/new-chat.ts b/packages/web/src/features/chat/new-chat.ts
new file mode 100644
index 00000000..672ef11e
--- /dev/null
+++ b/packages/web/src/features/chat/new-chat.ts
@@ -0,0 +1,57 @@
+/**
+ * What every "New chat" entry point starts: the sidebar's pinned button, its header button and
+ * group-header "+", the collapsed rail, the chat page's empty state, an Agent card and a plugin's
+ * quick start all land on the new-chat draft (/chat/new) through the two rules here.
+ *
+ * Where a draft field comes from, highest first: what the entry point names in route state (an
+ * Agent group's or card's Agent, a Workspace group's path), then the Project's new-chat defaults
+ * (`[default_chat]`), then the built-in fallback. A generic "New chat" names nothing, so it
+ * starts on the defaults. A selection an abandoned, text-less draft left in the active slot is
+ * not a source: prepareNewChatDraft releases it first, or the leftover of one "+" click would
+ * stand in for the Project's defaults on every later "New chat".
+ */
+import type { AgentSummary, ChatDefaultsDto } from "@prismshadow/penguin-server/api";
+import { pickDefaultAgent } from "../ai-create/default-agent";
+import { clearDraft, draftKey, loadDraft, saveDraft } from "./draft-cache";
+import type { DraftCache, DraftStorage } from "./draft-cache";
+import { parkActiveDraft } from "./draft-sessions";
+
+/**
+ * The Agent a new conversation starts on when nothing names one: the Project's new-chat default
+ * while it still names an Agent of this Project, else the built-in `default_agent`, else the
+ * first Agent. Null only for an empty list.
+ */
+export function newChatAgentId(
+ agents: readonly AgentSummary[],
+ defaults: ChatDefaultsDto,
+): string | null {
+ const preferred = defaults.agentId;
+ if (preferred !== undefined && agents.some((a) => a.agentId === preferred)) return preferred;
+ return pickDefaultAgent(agents)?.agentId ?? null;
+}
+
+/**
+ * Clears the active new-chat slot for an entry point about to navigate to it: typed text is
+ * parked as a draft conversation (parkActiveDraft), then the slot is rewritten to the two things
+ * a new chat carries over, the model (as after any park or send) and staged skills. Everything
+ * else a text-less draft left there is released: its Agent / Workspace / approval-mode
+ * selections, so the draft seeds them afresh, and the evaluation-run mark (`source`), which
+ * would otherwise file the next ordinary conversation under Evaluations. The slot is rebuilt
+ * from what stays rather than stripped of what goes, so a field the cache gains later starts
+ * released too. Returns the parked entry's id, or null when nothing was typed.
+ */
+export function prepareNewChatDraft(
+ userId: string,
+ projectId: string,
+ storage?: DraftStorage,
+): string | null {
+ const parked = parkActiveDraft(userId, projectId, storage);
+ const key = draftKey(userId, projectId);
+ const { modelRef, skills } = loadDraft(key, storage);
+ const kept: DraftCache = {};
+ if (modelRef) kept.modelRef = modelRef;
+ if (skills) kept.skills = skills;
+ if (kept.modelRef || kept.skills) saveDraft(key, kept, storage);
+ else clearDraft(key, storage);
+ return parked;
+}
diff --git a/packages/web/src/features/chat/recall-draft.ts b/packages/web/src/features/chat/recall-draft.ts
index 7324e86c..f1bb822c 100644
--- a/packages/web/src/features/chat/recall-draft.ts
+++ b/packages/web/src/features/chat/recall-draft.ts
@@ -13,7 +13,7 @@
* (see ChatInput's toggleGoal), so keeping the chip would park the restored files behind
* a Send that can never enable — and by the time the composer sees them, their scratchpad
* copies are already deleted server-side, making the chips the only copy left. Images
- * never release the chip: a goal carries them (folded into the objective as path lines).
+ * never release the chip: a goal carries them on its round-1 message.
*/
export interface RecalledDraftMerge {
/** The new draft body: recalled text in front, the current draft behind. */
diff --git a/packages/web/src/features/plugins/plugins-page.tsx b/packages/web/src/features/plugins/plugins-page.tsx
index 97e1c3fc..58f4c5af 100644
--- a/packages/web/src/features/plugins/plugins-page.tsx
+++ b/packages/web/src/features/plugins/plugins-page.tsx
@@ -74,7 +74,7 @@ import { Skeleton, SkeletonCard } from "../../components/ui/skeleton";
import { toastError, toastSuccess } from "../../components/ui/toast";
import { DRAFT_SESSION_ID } from "../chat/chat-page";
import { draftKey, loadDraft, saveDraft } from "../chat/draft-cache";
-import { parkActiveDraft } from "../chat/draft-sessions";
+import { prepareNewChatDraft } from "../chat/new-chat";
import { localizedShortText, localizedText } from "../chat/skill-use";
import { PluginDetailModal } from "./plugin-detail";
import { formatRelativeDate } from "../../lib/format";
@@ -510,8 +510,9 @@ export function PluginsPage() {
if (!agentId) return;
if (userId && projectId) {
// Typed-but-unsent draft text becomes a parked draft conversation instead of being
- // clobbered by the canned invocation body (draft-sessions.ts).
- parkActiveDraft(userId, projectId);
+ // clobbered by the canned invocation body, and the Workspace and approval mode start on
+ // the Project's new-chat defaults (new-chat.ts).
+ prepareNewChatDraft(userId, projectId);
const key = draftKey(userId, projectId);
saveDraft(key, {
...loadDraft(key),
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index d6feac45..38a7ad4e 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -453,7 +453,7 @@ export const en: Strings = {
"First run: the server prints a first-login link in its startup output — open it to claim the built-in admin “admin” and set a password. No initial password exists to type here",
/** Login footer line 2: the offline rescue for a forgotten admin password (other users ask the admin instead). */
forgotAdminNote:
- "Forgot the admin password? Stop the server and run penguin server reset-admin-password to issue a fresh initial one",
+ "Forgot the admin password? Stop the server and run penguin server reset-admin-password; its next start prints a new first-login link — open it to set a new password",
/** Dialog raised over the login form when the server refused a sign-in link (spent, expired, or never valid). */
claimFailedTitle: "Sign-in link no longer works",
/** Desktop deployment: the shell mints a fresh link every time it starts, so restarting it is the way back in. */
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 9c5f4818..f38ed039 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -457,7 +457,7 @@ export const zh = {
"首次使用请打开服务端启动输出中的首次登录链接,认领内置管理员 admin 并设置密码。这里没有可输入的初始密码",
/** Login footer line 2: the offline rescue for a forgotten admin password (other users ask the admin instead). */
forgotAdminNote:
- "忘记管理员密码时,停止服务后执行 penguin server reset-admin-password 重置为新的初始密码",
+ "忘记管理员密码时,停止服务后执行 penguin server reset-admin-password;再次启动时会打印新的首次登录链接,打开它即可设置新密码",
/** Dialog raised over the login form when the server refused a sign-in link (spent, expired, or never valid). */
claimFailedTitle: "登录链接已失效",
/** Desktop deployment: the shell mints a fresh link every time it starts, so restarting it is the way back in. */
diff --git a/packages/web/test/new-chat.test.ts b/packages/web/test/new-chat.test.ts
new file mode 100644
index 00000000..be7f9e8d
--- /dev/null
+++ b/packages/web/test/new-chat.test.ts
@@ -0,0 +1,150 @@
+/**
+ * What a "New chat" entry point starts (src/features/chat/new-chat.ts):
+ * - newChatAgentId: the Project's `[default_chat].agent_id` while it names a listed Agent, else
+ * default_agent, else the first Agent;
+ * - prepareNewChatDraft: parks typed text, then rewrites the active slot to the model carry-over
+ * and staged skills alone, releasing everything else an earlier visit left there.
+ *
+ * Note: draft-sessions.ts keeps an in-memory mirror keyed by storage key, so every test uses
+ * its own user id to stay isolated from the others' keys.
+ */
+import { describe, expect, it } from "vitest";
+import type { AgentSummary } from "@prismshadow/penguin-server/api";
+import { draftKey, loadDraft, saveDraft } from "../src/features/chat/draft-cache";
+import type { DraftStorage } from "../src/features/chat/draft-cache";
+import { getDraftSession } from "../src/features/chat/draft-sessions";
+import { newChatAgentId, prepareNewChatDraft } from "../src/features/chat/new-chat";
+
+const agent = (agentId: string) => ({ agentId }) as AgentSummary;
+
+/** In-memory storage (vitest runs in a Node environment, no localStorage). */
+function memStorage(): DraftStorage {
+ const map = new Map<string, string>();
+ return {
+ getItem: (k) => map.get(k) ?? null,
+ setItem: (k, v) => void map.set(k, v),
+ removeItem: (k) => void map.delete(k),
+ };
+}
+
+describe("newChatAgentId", () => {
+ const agents = [agent("coder"), agent("default_agent"), agent("writer")];
+
+ it("starts on the Project's default Agent when one is set, ahead of default_agent", () => {
+ expect(newChatAgentId(agents, { agentId: "writer" })).toBe("writer");
+ });
+
+ it("falls back to default_agent when no default is set, wherever it sits in the list", () => {
+ expect(newChatAgentId(agents, {})).toBe("default_agent");
+ expect(newChatAgentId(agents, { workspace: "/srv/repo", approvalMode: "read-only" })).toBe(
+ "default_agent",
+ );
+ });
+
+ it("ignores a default that no longer names an Agent of the Project", () => {
+ expect(newChatAgentId(agents, { agentId: "deleted_agent" })).toBe("default_agent");
+ });
+
+ it("falls back to the first Agent without default_agent, and to null for an empty list", () => {
+ expect(newChatAgentId([agent("coder"), agent("writer")], {})).toBe("coder");
+ expect(newChatAgentId([agent("coder"), agent("writer")], { agentId: "gone" })).toBe("coder");
+ expect(newChatAgentId([], { agentId: "writer" })).toBeNull();
+ });
+});
+
+describe("prepareNewChatDraft", () => {
+ it("releases the selections a text-less draft left behind, keeping the model and staged skills", () => {
+ const s = memStorage();
+ // What an abandoned Workspace-group "+" leaves: its path and an Agent, pinned by the draft
+ // page's persist-on-mount, with nothing typed.
+ saveDraft(
+ draftKey("u-release", "proj"),
+ {
+ text: "",
+ agentId: "coder",
+ workspace: "/srv/group-path",
+ approvalMode: "read-only",
+ modelRef: { provider: "deepseek", modelId: "deepseek-v4-pro" },
+ skills: ["ship-it"],
+ },
+ s,
+ );
+ expect(prepareNewChatDraft("u-release", "proj", s)).toBeNull();
+ expect(loadDraft(draftKey("u-release", "proj"), s)).toEqual({
+ modelRef: { provider: "deepseek", modelId: "deepseek-v4-pro" },
+ skills: ["ship-it"],
+ });
+ });
+
+ it("drops an emptied evaluation draft's run mark, so the next New chat is not an evaluation run", () => {
+ const s = memStorage();
+ // Evaluation Center -> Use -> Evaluate seeds the slot with a composed prompt marked as an
+ // evaluation run. Editing the prompt drops aiPrefill, and deleting all of it leaves this
+ // behind (the draft page's persist): no text to park, but the run mark is still set, and a
+ // draft that reads it creates its Session with `source: "benchmark"`.
+ saveDraft(
+ draftKey("u-eval", "proj"),
+ {
+ text: "",
+ agentId: "evaluator",
+ workspace: "",
+ approvalMode: "allow-all",
+ modelRef: { provider: "deepseek", modelId: "deepseek-v4-pro" },
+ skills: ["agent-evaluation"],
+ source: "benchmark",
+ },
+ s,
+ );
+ expect(prepareNewChatDraft("u-eval", "proj", s)).toBeNull();
+ const slot = loadDraft(draftKey("u-eval", "proj"), s);
+ expect(slot.source).toBeUndefined();
+ expect(slot).toEqual({
+ modelRef: { provider: "deepseek", modelId: "deepseek-v4-pro" },
+ skills: ["agent-evaluation"],
+ });
+ });
+
+ it("empties a slot that holds nothing it keeps", () => {
+ const s = memStorage();
+ saveDraft(
+ draftKey("u-nothing-kept", "proj"),
+ { text: " ", agentId: "coder", handoffAgentId: "writer", source: "benchmark" },
+ s,
+ );
+ expect(prepareNewChatDraft("u-nothing-kept", "proj", s)).toBeNull();
+ expect(s.getItem(draftKey("u-nothing-kept", "proj"))).toBeNull();
+ });
+
+ it("parks typed text with its selections, leaving only the model carry-over in the slot", () => {
+ const s = memStorage();
+ saveDraft(
+ draftKey("u-typed", "proj"),
+ {
+ text: "half-written prompt",
+ agentId: "coder",
+ workspace: "/srv/repo",
+ approvalMode: "read-only",
+ modelRef: { provider: "anthropic", modelId: "claude-sonnet-5" },
+ },
+ s,
+ );
+ const id = prepareNewChatDraft("u-typed", "proj", s);
+ expect(id).toMatch(/^draft-[0-9a-f]{8}$/);
+ expect(loadDraft(draftKey("u-typed", "proj"), s)).toEqual({
+ modelRef: { provider: "anthropic", modelId: "claude-sonnet-5" },
+ });
+ // The parked entry is the only record of the typed draft, so it keeps every selection.
+ expect(getDraftSession("u-typed", "proj", id!, s)?.draft).toMatchObject({
+ text: "half-written prompt",
+ agentId: "coder",
+ workspace: "/srv/repo",
+ approvalMode: "read-only",
+ });
+ });
+
+ it("is a no-op on an empty slot", () => {
+ const s = memStorage();
+ expect(prepareNewChatDraft("u-empty", "proj", s)).toBeNull();
+ expect(loadDraft(draftKey("u-empty", "proj"), s)).toEqual({});
+ });
+});