web: create a chat through the directory picker (C2)

This commit is contained in:
2026-10-19 14:25:42 +01:00
parent 2fe63012f9
commit a7872c3f31
9 changed files with 841 additions and 36 deletions
+129
View File
@@ -12,6 +12,13 @@ import {
CHAT_COMMAND_FAILED_LABEL,
CHAT_COMMAND_GLYPH,
CHAT_COMMAND_LABEL,
CHAT_CREATE_BACK_LABEL,
CHAT_CREATE_CANCEL,
CHAT_CREATE_CONFIRM,
CHAT_CREATE_LOADING,
CHAT_CREATE_MODEL_NOTE,
CHAT_CREATE_PROMPT,
CHAT_CREATE_TITLE,
CHAT_FOLLOW_THRESHOLD_PX,
CHAT_QUEUED_NOTICE,
COMPOSER_SEND,
@@ -60,12 +67,16 @@ import {
attachmentDisplayName,
attachmentError,
attachmentFiles,
HOME_DIRECTORY,
HOME_LABEL,
backgroundTasksRunningLabel,
chatBottomDistancePx,
chatCommandEffect,
chatCommandForEnter,
chatCommandHelp,
chatCommandSuggestions,
chatCreateFailed,
chatCreateSucceeded,
chatFirstScroll,
chatFollowsAt,
chatHeaderMeta,
@@ -73,6 +84,7 @@ import {
chatNoticeLabel,
chatOpensAtNewest,
chatShowJumpToLatest,
chatStartInLabel,
chatStreamState,
closeChatConfirmation,
composerAction,
@@ -80,7 +92,9 @@ import {
composerSendEnabled,
composerSubmit,
decisionLabel,
defaultDirectoryChoice,
deltaPartId,
directoryChoices,
directoryLabel,
dismissChatNotice,
filterSessions,
@@ -92,6 +106,7 @@ import {
mergeHistoryPage,
mergeShellFrame,
mergeToolPart,
newChatCreateState,
newChatThread,
parseChatInput,
partRendering,
@@ -104,6 +119,7 @@ import {
runningBackgroundShells,
runningToolElapsedMillis,
runningToolStamps,
selectChatDirectory,
sessionActivity,
sessionActivityBadge,
sessionChipLabel,
@@ -1612,3 +1628,116 @@ test("a step that ends does not clear a background shell that outlives the turn"
assert.equal(resumed.selectedShellId, null);
assert.equal(resumed.shellOutput, null);
});
// ---- The create flow's directory picker (C2, ChatDirectories.kt) -----------
test("directoryChoices makes the first non-blank directory home and keeps recents in server order", () => {
const choices = directoryChoices(["/Users/alan", "", "/work/one", " ", "/work/two"]);
assert.deepEqual(choices, [
{
label: "Home (~)",
path: "/Users/alan",
home: true,
createDirectory: "~",
secondary: "/Users/alan",
},
{
label: "/work/one",
path: "/work/one",
home: false,
createDirectory: "/work/one",
secondary: null,
},
{
label: "/work/two",
path: "/work/two",
home: false,
createDirectory: "/work/two",
secondary: null,
},
]);
});
test("directoryChoices always yields home first, even for an empty or blank reply", () => {
for (const reply of [[], ["", " "], null, undefined]) {
const choices = directoryChoices(reply);
assert.equal(choices.length, 1);
assert.deepEqual(choices[0], {
label: HOME_LABEL,
path: HOME_DIRECTORY,
home: true,
createDirectory: HOME_DIRECTORY,
secondary: HOME_DIRECTORY,
});
}
});
test("the home row is the only one with a secondary path; recents are labelled by full path", () => {
const choices = directoryChoices(["/home/operator", "/repo/a", "/repo/b"]);
assert.deepEqual(
choices.map((choice) => [choice.label, choice.secondary]),
[
["Home (~)", "/home/operator"],
["/repo/a", null],
["/repo/b", null],
],
);
assert.equal(defaultDirectoryChoice(choices)?.label, HOME_LABEL);
assert.equal(defaultDirectoryChoice([]), null);
});
test("newChatCreateState starts on home, not sending, with the caller's operation id", () => {
assert.deepEqual(newChatCreateState("web-chat-op"), {
directory: HOME_DIRECTORY,
operationId: "web-chat-op",
creating: false,
error: "",
});
});
test("selectChatDirectory sends the chosen value and clears a previous refusal", () => {
const state = { ...newChatCreateState("op"), error: "refused" };
const recent = { label: "/repo/a", path: "/repo/a", home: false, createDirectory: "/repo/a", secondary: null };
assert.deepEqual(selectChatDirectory(state, recent), {
directory: "/repo/a",
operationId: "op",
creating: false,
error: "",
});
assert.equal(selectChatDirectory(state, "~").directory, "~");
assert.deepEqual(selectChatDirectory(state, ""), state);
});
test("chatCreateFailed keeps the pane open with the server's message; success stops sending", () => {
const creating = { ...newChatCreateState("op"), creating: true };
assert.deepEqual(chatCreateFailed(creating, "the directory is not available"), {
directory: "~",
operationId: "op",
creating: false,
error: "the directory is not available",
});
});
test("chatCreateSucceeded puts the created session at the head and dedupes by id", () => {
const a = { id: "a", title: "A" };
const b = { id: "b", title: "B" };
const created = { id: "b", title: "New chat" };
assert.deepEqual(chatCreateSucceeded([a, b], created), [created, a]);
assert.deepEqual(chatCreateSucceeded([], created), [created]);
assert.deepEqual(chatCreateSucceeded([a], null), [a]);
});
test("the create flow's wording is the app's verbatim", () => {
assert.equal(CHAT_CREATE_TITLE, "Start a chat");
assert.equal(CHAT_CREATE_BACK_LABEL, "Cancel new chat");
assert.equal(CHAT_CREATE_LOADING, "Loading directories…");
assert.equal(CHAT_CREATE_PROMPT, "Where should this chat live?");
assert.equal(
CHAT_CREATE_MODEL_NOTE,
"This server has no request for choosing a chat's model, so a new chat uses the server's default.",
);
assert.equal(CHAT_CREATE_CONFIRM, "New chat");
assert.equal(CHAT_CREATE_CANCEL, "Cancel");
assert.equal(chatStartInLabel(HOME_DIRECTORY), "Start in ~");
assert.equal(chatStartInLabel("/repo/a"), "Start in /repo/a");
});