GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): a stashed prompt ending in a skill or file chip restores as… · Pipyakas/t3code@32f6f44

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components
    • ChatView.browser.test.tsx
    • chat
      • useComposerStash.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ChatView.browser.test.tsx‎

Copy file name to clipboard
+36-124Lines changed: 36 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createMemoryHistory } from "@tanstack/react-router";
22
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
3-
import { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3+
import { ThreadId } from "@t3tools/contracts";
44
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
55
import type * as Context from "effect/Context";
66
import { expect, it, vi } from "vite-plus/test";
7-
import { cdp, page, userEvent } from "vite-plus/test/browser";
7+
import { page, userEvent } from "vite-plus/test/browser";
88

99
import { AppRoot } from "~/AppRoot";
1010
// The route loads ChatView lazily, and its first transform (React Compiler over ~4k lines)
@@ -13,23 +13,13 @@ import "~/components/ChatView";
1313
import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
1414
import { selectThreadDiffPanelSelection, useDiffPanelStore } from "~/diffPanelStore";
1515
import { __setClientSettingsForTests } from "~/hooks/useSettings";
16-
import { environmentContextRecord } from "~/lib/composerContextRecords";
17-
import { usePromptStashStore } from "~/promptStashStore";
1816
import { useRightPanelStore } from "~/rightPanelStore";
1917
import { getRouter } from "~/router";
20-
import { appAtomRegistry } from "~/rpc/atomRegistry";
21-
import { environmentThreadDetails } from "~/state/threads";
2218
import {
2319
ENVIRONMENT_ID,
2420
PROJECT_ID,
25-
answerAssetUrls,
26-
assistantItem,
27-
dispatchedCommands,
28-
emitThreadEvent,
29-
hasPendingAssetUrl,
3021
installFakeEnvironment,
3122
threadWithHistory,
32-
threadWithQuestion,
3323
type FakeDriver,
3424
} from "../../test/fakeEnvironment";
3525
import { act, render } from "../../test/render";
@@ -49,118 +39,6 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
4939
trackRpcRequestSent: () => {},
5040
}));
5141

52-
it("a machine chip stashed in one thread restores with its machine in another", async () => {
53-
const other = threadWithHistory("thread-stash-restore", 1);
54-
const asking = threadWithQuestion("thread-stash-question", "Which file should change?");
55-
using _environment = installFakeEnvironment([other, asking]);
56-
__setClientSettingsForTests({
57-
...DEFAULT_CLIENT_SETTINGS,
58-
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
59-
});
60-
const draftId = DraftId.make("draft-stash-machine");
61-
const machine = environmentContextRecord(EnvironmentId.make("environment-build"), "Build box");
62-
const drafts = useComposerDraftStore.getState();
63-
drafts.setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
64-
threadId: ThreadId.make("thread-stash-machine"),
65-
});
66-
drafts.setPrompt(draftId, "Deploy on ");
67-
drafts.addEnvironmentContexts(draftId, [machine]);
68-
const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
69-
await router.load();
70-
await using _app = await render(<AppRoot router={router} />, {
71-
// AppRoot brings its own router.
72-
router: false,
73-
});
74-
const editor = page.getByTestId("composer-editor");
75-
const pressStashShortcut = async () => {
76-
await userEvent.click(editor);
77-
await userEvent.keyboard("{ControlOrMeta>}s{/ControlOrMeta}");
78-
};
79-
await vi.waitFor(() => expect(editor.element().textContent).toContain("Deploy on"));
80-
// A draft can't stash until the shell snapshot lists its project.
81-
await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
82-
await pressStashShortcut();
83-
await vi.waitFor(() => expect(usePromptStashStore.getState().entries).toHaveLength(1));
84-
85-
// An answer carries no machines, so an open question refuses the restore and keeps the entry.
86-
await router.navigate({ to: `/${ENVIRONMENT_ID}/${asking.id}` });
87-
await expect.element(page.getByText("Which file should change?")).toBeVisible();
88-
await userEvent.click(page.getByRole("button", { name: /^Stashed prompts/ }));
89-
await userEvent.click(page.getByRole("button", { name: /^Restore stashed prompt/ }));
90-
await vi.waitFor(() =>
91-
expect(document.body.textContent).toContain("Stashed machines can't go in an answer"),
92-
);
93-
expect(usePromptStashStore.getState().entries).toHaveLength(1);
94-
95-
await router.navigate({ to: `/${ENVIRONMENT_ID}/${other.id}` });
96-
await expect.element(page.getByText("Answer 0 for thread-stash-restore.")).toBeVisible();
97-
await pressStashShortcut();
98-
99-
await vi.waitFor(() => expect(editor.element().textContent).toContain("Deploy on"));
100-
expect(
101-
useComposerDraftStore.getState().getComposerDraft(scopeThreadRef(ENVIRONMENT_ID, other.id))
102-
?.environmentContexts,
103-
).toEqual([machine]);
104-
expect(
105-
useComposerDraftStore.getState().getComposerDraft(draftId)?.environmentContexts ?? [],
106-
).toEqual([]);
107-
});
108-
109-
it("a question that opens while a stashed file is checked keeps a machine stash", async () => {
110-
const thread = threadWithHistory("thread-stash-late-question", 1);
111-
const asking = threadWithQuestion("thread-stash-late-question", "Which file should change?");
112-
const [request] = asking.runtimeRequests ?? [];
113-
const question = asking.items.at(-1);
114-
if (!request || !question) throw new Error("threadWithQuestion has no question");
115-
using _environment = installFakeEnvironment([thread]);
116-
__setClientSettingsForTests({
117-
...DEFAULT_CLIENT_SETTINGS,
118-
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
119-
});
120-
usePromptStashStore.getState().stashEntry({
121-
id: "stash-late-question",
122-
createdAt: "2026-01-01T00:00:00.000Z",
123-
prompt: "Deploy on ",
124-
attachments: [],
125-
files: [
126-
{
127-
id: "file-notes",
128-
name: "notes.txt",
129-
mimeType: "text/plain",
130-
sizeBytes: 5,
131-
attachmentId: "attachment-notes",
132-
environmentId: ENVIRONMENT_ID,
133-
},
134-
],
135-
droppedImageNames: [],
136-
records: [environmentContextRecord(EnvironmentId.make("environment-build"), "Build box")],
137-
});
138-
const router = getRouter(
139-
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }),
140-
);
141-
await router.load();
142-
await using _app = await render(<AppRoot router={router} />, {
143-
// AppRoot brings its own router.
144-
router: false,
145-
});
146-
await expect.element(page.getByText("Answer 0 for thread-stash-late-question.")).toBeVisible();
147-
await userEvent.click(page.getByRole("button", { name: /^Stashed prompts/ }));
148-
await userEvent.click(page.getByRole("button", { name: /^Restore stashed prompt/ }));
149-
150-
// The question opens while the restore still waits on the server's file check.
151-
await vi.waitFor(() => expect(hasPendingAssetUrl()).toBe(true));
152-
await emitThreadEvent(thread.id, { type: "turn-item.updated", payload: question });
153-
await emitThreadEvent(thread.id, { type: "runtime-request.updated", payload: request });
154-
await expect.element(page.getByText("Which file should change?")).toBeVisible();
155-
await answerAssetUrls();
156-
157-
await vi.waitFor(() =>
158-
expect(document.body.textContent).toContain("Stashed machines can't go in an answer"),
159-
);
160-
expect(usePromptStashStore.getState().entries).toHaveLength(1);
161-
usePromptStashStore.getState().takeEntry("stash-late-question");
162-
});
163-
16442
it("a new draft does not load its reserved thread before the server lists it", async () => {
16543
using _environment = installFakeEnvironment([]);
16644
using fetchSpy = vi.spyOn(globalThis, "fetch");
@@ -279,3 +157,37 @@ it("retains each thread's diff selection when returning from another thread or S
279157
turnId: a.runs[0]!.id,
280158
});
281159
});
160+
161+
it("a stashed prompt ending in a file chip restores with the chip", async () => {
162+
using _environment = installFakeEnvironment([]);
163+
__setClientSettingsForTests({
164+
...DEFAULT_CLIENT_SETTINGS,
165+
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
166+
});
167+
const draftId = DraftId.make("draft-28338");
168+
const drafts = useComposerDraftStore.getState();
169+
drafts.setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
170+
threadId: ThreadId.make("thread-28338"),
171+
});
172+
drafts.setPrompt(draftId, "Check [package.json](package.json) ");
173+
const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
174+
await router.load();
175+
await using _app = await render(<AppRoot router={router} />, {
176+
// AppRoot brings its own router.
177+
router: false,
178+
});
179+
const chip = page.getByRole("button", { name: "Preview package.json" });
180+
await expect.element(chip).toBeVisible();
181+
// The stash shortcut is a no-op until the shell snapshot lists the project.
182+
await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
183+
184+
const editor = page.getByTestId("composer-editor");
185+
await userEvent.click(editor);
186+
await userEvent.keyboard("{ControlOrMeta>}s{/ControlOrMeta}");
187+
await expect.element(chip).not.toBeInTheDocument();
188+
await userEvent.keyboard("{ControlOrMeta>}s{/ControlOrMeta}");
189+
190+
await vi.waitFor(() => expect(editor.element().textContent).toContain("Check"));
191+
expect(editor.element().textContent).not.toContain("[package.json](package.json)");
192+
await expect.element(chip).toBeVisible();
193+
});
Collapse file

‎apps/web/src/components/chat/useComposerStash.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/chat/useComposerStash.ts
+24-37Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ import {
2828
import { type PendingUserInput } from "../../session-logic";
2929
import { type ReviewCommentContext } from "../../reviewCommentContext";
3030
import { collapseExpandedComposerCursor } from "../../composer-logic";
31+
import { collectComposerPromptInlineTokens } from "../../composer-editor-mentions";
3132
import { compressImageForStash } from "../../lib/imageCompression";
3233
import { formatInlineContextReference } from "~/lib/composerContextReferences";
3334
import { isCommandPaletteOpen } from "../../commandPaletteBus";
3435
import { pendingDraftWork } from "./pendingDraftWork";
35-
import { countPreparingComposerImages } from "./preparingComposerImages";
3636
import {
37+
isResponseContextRecord,
3738
previewAnnotationContextRecord,
3839
reviewCommentContextRecord,
3940
terminalContextRecord,
@@ -127,6 +128,7 @@ export function useComposerStash(input: {
127128
} = input;
128129
const getComposerDraft = useComposerDraftStore((store) => store.getComposerDraft);
129130
const setComposerDraftPrompt = useComposerDraftStore((store) => store.setPrompt);
131+
const setComposerDraftReplyTo = useComposerDraftStore((store) => store.setReplyTo);
130132
const addComposerDraftImages = useComposerDraftStore((store) => store.addImages);
131133
const addComposerDraftFiles = useComposerDraftStore((store) => store.addFiles);
132134
const removeComposerDraftPreviewAnnotation = useComposerDraftStore(
@@ -142,9 +144,6 @@ export function useComposerStash(input: {
142144
(store) => store.clearComposerPromptAndImages,
143145
);
144146
const setComposerDraftThreadContexts = useComposerDraftStore((store) => store.setThreadContexts);
145-
const setComposerDraftEnvironmentContexts = useComposerDraftStore(
146-
(store) => store.setEnvironmentContexts,
147-
);
148147
const [isStashMenuOpen, setIsStashMenuOpen] = useState(false);
149148
// Each stash bumps the key; the badge replays its one-shot pulse animation per key.
150149
const [stashPulseKey, setStashPulseKey] = useState(0);
@@ -159,23 +158,6 @@ export function useComposerStash(input: {
159158
setStashPulseKey((key) => key + 1);
160159
};
161160

162-
// Stable, so the check after the verify await sees a question that opened during it.
163-
const refuseMachinesInAnswer = useStableCallback((menuEntry: PromptStashEntry) => {
164-
// An answer to an agent's question carries no machines, so restoring here would drop them.
165-
if (
166-
pendingUserInputs.length > 0 &&
167-
menuEntry.records?.some((record) => record.kind === "environment")
168-
) {
169-
toastManager.add({
170-
type: "error",
171-
title: "Stashed machines can't go in an answer",
172-
description: "Restore this prompt after the agent's question is answered.",
173-
});
174-
return true;
175-
}
176-
return false;
177-
});
178-
179161
const restoreStashEntry = async (menuEntry: PromptStashEntry) => {
180162
const filesToVerify = menuEntry.files ?? [];
181163
if (filesToVerify.some((file) => file.environmentId !== environmentId)) {
@@ -186,7 +168,6 @@ export function useComposerStash(input: {
186168
});
187169
return;
188170
}
189-
if (refuseMachinesInAnswer(menuEntry)) return;
190171
setIsStashMenuOpen(false);
191172

192173
// An expired upload restores as a needs-reattach row instead of a reference
@@ -209,8 +190,7 @@ export function useComposerStash(input: {
209190
// so abort and leave the entry restorable where the user now is.
210191
if (
211192
isRevertingCheckpoint() ||
212-
!isComposerDraftTargetOpen(composerTargetKey(composerDraftTarget)) ||
213-
refuseMachinesInAnswer(menuEntry)
193+
!isComposerDraftTargetOpen(composerTargetKey(composerDraftTarget))
214194
) {
215195
return;
216196
}
@@ -230,6 +210,17 @@ export function useComposerStash(input: {
230210
const rewrittenContextIds = entry.records
231211
? importContextRecords(entry.records, null, composerDraftTarget)
232212
: new Map<string, string>();
213+
// A reply only makes sense in the thread that holds the response, and one already pending wins.
214+
const stashedReply = entry.records?.find(isResponseContextRecord);
215+
if (
216+
stashedReply &&
217+
!getComposerDraft(composerDraftTarget)?.replyTo &&
218+
typeof composerDraftTarget !== "string" &&
219+
stashedReply.citation.threadId === composerDraftTarget.threadId &&
220+
stashedReply.citation.environmentId === composerDraftTarget.environmentId
221+
) {
222+
setComposerDraftReplyTo(composerDraftTarget, stashedReply);
223+
}
233224
const restoredPrompt = replaceComposerContextReferences(entry.prompt, (reference) => {
234225
const contextId = rewrittenContextIds.get(reference.contextId);
235226
return contextId
@@ -478,13 +469,19 @@ export function useComposerStash(input: {
478469
});
479470
return;
480471
}
481-
const prompt = promptRef.current.trim();
472+
const replyTo = getComposerDraft(composerDraftTarget)?.replyTo;
473+
const trimmedPrompt = promptRef.current.trim();
474+
// A trailing chip only parses with whitespace after it, so keep one space to restore it.
475+
const endsWithChip =
476+
collectComposerPromptInlineTokens(promptRef.current).at(-1)?.end ===
477+
promptRef.current.trimEnd().length;
478+
const prompt = endsWithChip ? `${trimmedPrompt} ` : trimmedPrompt;
482479
const attachmentDraft = readAttachmentDraft();
483480
const images = [...attachmentDraft.images];
484481
const files = [...attachmentDraft.files];
485482
const stashedRecords: ComposerContextRecord[] = [
483+
...(replyTo ? [replyTo] : []),
486484
...composerThreadContexts,
487-
...(getComposerDraft(composerDraftTarget)?.environmentContexts ?? []),
488485
...readTerminalContexts().map(terminalContextRecord),
489486
...composerReviewComments.map(reviewCommentContextRecord),
490487
...composerPreviewAnnotations.map((annotation) =>
@@ -505,16 +502,6 @@ export function useComposerStash(input: {
505502
}
506503
return;
507504
}
508-
// The snapshot only holds compressed images; a still-compressing one would land in the
509-
// emptied composer instead of travelling with this entry.
510-
if (countPreparingComposerImages(attachmentTargetKey) > 0) {
511-
toastManager.add({
512-
type: "info",
513-
title: "Still compressing a pasted image.",
514-
description: "Stash again once it finishes compressing.",
515-
});
516-
return;
517-
}
518505
const stashedFiles: PersistedComposerFileAttachment[] = [];
519506
for (const file of files) {
520507
if (composerFileNeedsReattach(file)) {
@@ -598,7 +585,7 @@ export function useComposerStash(input: {
598585
clearComposerDraftPromptAndImages(stashTarget);
599586
clearComposerDraftTerminalContexts(stashTarget);
600587
setComposerDraftThreadContexts(stashTarget, []);
601-
setComposerDraftEnvironmentContexts(stashTarget, []);
588+
setComposerDraftReplyTo(stashTarget, null);
602589
for (const comment of composerReviewComments) {
603590
removeComposerDraftReviewComment(stashTarget, comment.id);
604591
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.