@devries-cameron20 / t3code Mirror · read-only / commits / 7ee6e924cb
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 01:45 UTC

fix(web): reject file suggestions from an older composer query (#18845)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:48 UTC 7ee6e924cb8c826785a452801466e0b886fd095c
6 files changed +63 -19
apps/web/src/components/chat/ChatComposer.tsx
+4 -2
@@ -90,6 +90,7 @@ import {
90 detectComposerTrigger,
91 expandCollapsedComposerCursor,
92 formatAssistantCitationForComposer,
93 + isPathSuggestionCurrent,
94 replaceTextRange,
95 } from "../../composer-logic";
96 import { DISCONNECTED_COMPOSER_PLACEHOLDER } from "../../composerPlaceholder";
@@ -203,7 +204,6 @@ import {
204 type TerminalContextDraft,
205 type TerminalContextSelection,
206 } from "../../lib/terminalContext";
206 -import { useComposerPathSearch } from "../../lib/composerPathSearchState";
207 import {
208 replaceComposerContextReferences,
209 toKindScopedComposerContextId,
@@ -284,7 +284,7 @@ import {
284 type EnvironmentQueryTarget,
285 } from "~/state/pullRequests";
286 import { useEnvironmentQuery } from "~/state/query";
287 -import { useDebouncedValue } from "~/state/queries";
287 +import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
288 import { ProviderModelPicker } from "./ProviderModelPicker";
289 import { resolveModelPickerSelectedModel } from "./ModelPickerContent";
290 import {
@@ -2636,6 +2636,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2636 type: "path" as const,
2637 path: entry.path,
2638 pathKind: entry.kind,
2639 + searchTarget: workspaceEntries.searchedTarget,
2640 label: basenameOfPath(entry.path),
2641 description: entry.path.slice(0, Math.max(0, entry.path.lastIndexOf("/"))),
2642 })),
@@ -3809,6 +3810,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3810 const { snapshot, trigger } = resolveActiveComposerTrigger();
3811 if (!trigger) return;
3812 if (item.type === "path") {
3813 + if (!isPathSuggestionCurrent(item.searchTarget, trigger, environmentId, gitCwd)) return;
3814 const replacement = `${serializeComposerFileLink(item.path)} `;
3815 const replacementRangeEnd = extendReplacementRangeForTrailingSpace(
3816 snapshot.value,
apps/web/src/components/chat/ComposerCommandMenu.tsx
+2
@@ -1,4 +1,5 @@
1 import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
2 +import type { ComposerPathSearchTarget } from "@t3tools/client-runtime/state/threads";
3 import {
4 resolveProviderSkillSourceKind,
5 type ProviderSkillSourceKind,
@@ -36,6 +37,7 @@ export type ComposerCommandItem =
37 type: "path";
38 path: string;
39 pathKind: ProjectEntry["kind"];
40 + searchTarget: ComposerPathSearchTarget;
41 label: string;
42 description: string;
43 }
apps/web/src/composer-logic.test.ts
+36
@@ -22,6 +22,7 @@ import {
22 expandCollapsedComposerCursor,
23 formatAssistantCitationForComposer,
24 isCollapsedCursorAdjacentToInlineToken,
25 + isPathSuggestionCurrent,
26 parseStandaloneComposerSlashCommand,
27 replaceTextRange,
28 } from "./composer-logic";
@@ -48,6 +49,41 @@ const citation: AssistantCitation = {
49 };
50 const citationSource = serializeAssistantCitation(citation).replaceAll("+", "%20");
51
52 +describe("isPathSuggestionCurrent", () => {
53 + const searchedTarget = {
54 + environmentId: EnvironmentId.make("local"),
55 + cwd: "/repo",
56 + query: "alpha",
57 + };
58 +
59 + it("allows a file suggestion matching the live search", () => {
60 + expect(
61 + isPathSuggestionCurrent(
62 + searchedTarget,
63 + detectComposerTrigger("@alpha", 6),
64 + searchedTarget.environmentId,
65 + searchedTarget.cwd,
66 + ),
67 + ).toBe(true);
68 + });
69 +
70 + it.each([
71 + ["query", { ...searchedTarget, query: "beta" }],
72 + ["cwd", { ...searchedTarget, cwd: "/other-repo" }],
73 + ["environment", { ...searchedTarget, environmentId: EnvironmentId.make("remote") }],
74 + ] as const)("rejects a visible file suggestion after the live %s changes", (_change, current) => {
75 + const prompt = `@${current.query}`;
76 + expect(
77 + isPathSuggestionCurrent(
78 + searchedTarget,
79 + detectComposerTrigger(prompt, prompt.length),
80 + current.environmentId,
81 + current.cwd,
82 + ),
83 + ).toBe(false);
84 + });
85 +});
86 +
87 describe("formatAssistantCitationForComposer", () => {
88 it.each([undefined, "", " \n\t "])(
89 "keeps citation-only insertion for a blank comment %j",
apps/web/src/composer-logic.ts
+20 -1
@@ -1,5 +1,10 @@
1 import type { ClientSettings } from "@t3tools/contracts/settings";
2 -import type { AssistantCitation, ResolvedKeybindingsConfig } from "@t3tools/contracts";
2 +import type {
3 + AssistantCitation,
4 + EnvironmentId,
5 + ResolvedKeybindingsConfig,
6 +} from "@t3tools/contracts";
7 +import type { ComposerPathSearchTarget } from "@t3tools/client-runtime/state/threads";
8 import {
9 serializeAssistantCitation,
10 withAssistantCitationComment,
@@ -23,6 +28,20 @@ export interface ComposerTrigger {
28 rangeEnd: number;
29 }
30
31 +export function isPathSuggestionCurrent(
32 + searchTarget: ComposerPathSearchTarget,
33 + trigger: ComposerTrigger | null,
34 + environmentId: EnvironmentId | null,
35 + cwd: string | null,
36 +) {
37 + return (
38 + trigger?.kind === "path" &&
39 + searchTarget.environmentId === environmentId &&
40 + searchTarget.cwd === cwd &&
41 + searchTarget.query === trigger.query.trim()
42 + );
43 +}
44 +
45 export function formatAssistantCitationForComposer(citation: AssistantCitation, comment = "") {
46 return `${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `;
47 }
apps/web/src/lib/composerPathSearchState.ts deleted
-16
@@ -1,16 +0,0 @@
1 -import {
2 - type ComposerPathSearchState,
3 - type ComposerPathSearchTarget,
4 -} from "@t3tools/client-runtime/state/threads";
5 -
6 -import { useComposerPathSearch as useComposerPathSearchQuery } from "../state/queries";
7 -
8 -export function useComposerPathSearch(target: ComposerPathSearchTarget): ComposerPathSearchState {
9 - const state = useComposerPathSearchQuery(target);
10 - const entries = state.entries.map((entry) => ({ path: entry.path, kind: entry.kind }));
11 - return {
12 - entries,
13 - error: state.error,
14 - isPending: state.isPending,
15 - };
16 -}
apps/web/src/state/queries.ts
+1
@@ -272,6 +272,7 @@ export function useProjectPathSearch(
272 isPending:
273 !areProjectPathSearchTargetsEqual(normalizedTarget, debouncedTarget) ||
274 (hasTarget && (fileAccess.isPending || result.isPending)),
275 + searchedTarget: debouncedTarget,
276 searchedQuery: debouncedTarget.query ?? "",
277 truncated: result.data?.truncated ?? false,
278 refresh: result.refresh,