Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
detectComposerTrigger,
expandCollapsedComposerCursor,
formatAssistantCitationForComposer,
isPathSuggestionCurrent,
replaceTextRange,
} from "../../composer-logic";
import { DISCONNECTED_COMPOSER_PLACEHOLDER } from "../../composerPlaceholder";
Expand Down Expand Up @@ -203,7 +204,6 @@ import {
type TerminalContextDraft,
type TerminalContextSelection,
} from "../../lib/terminalContext";
import { useComposerPathSearch } from "../../lib/composerPathSearchState";
import {
replaceComposerContextReferences,
toKindScopedComposerContextId,
Expand Down Expand Up @@ -279,7 +279,7 @@ import {
type EnvironmentQueryTarget,
} from "~/state/pullRequests";
import { useEnvironmentQuery } from "~/state/query";
import { useDebouncedValue } from "~/state/queries";
import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
import { ProviderModelPicker } from "./ProviderModelPicker";
import { resolveModelPickerSelectedModel } from "./ModelPickerContent";
import {
Expand Down Expand Up @@ -2629,6 +2629,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
type: "path" as const,
path: entry.path,
pathKind: entry.kind,
searchTarget: workspaceEntries.searchedTarget,
label: basenameOfPath(entry.path),
description: entry.path.slice(0, Math.max(0, entry.path.lastIndexOf("/"))),
})),
Expand Down Expand Up @@ -3768,6 +3769,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const { snapshot, trigger } = resolveActiveComposerTrigger();
if (!trigger) return;
if (item.type === "path") {
if (!isPathSuggestionCurrent(item.searchTarget, trigger, environmentId, gitCwd)) return;
const replacement = `${serializeComposerFileLink(item.path)} `;
const replacementRangeEnd = extendReplacementRangeForTrailingSpace(
snapshot.value,
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/chat/ComposerCommandMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
import type { ComposerPathSearchTarget } from "@t3tools/client-runtime/state/threads";
import {
resolveProviderSkillSourceKind,
type ProviderSkillSourceKind,
Expand Down Expand Up @@ -36,6 +37,7 @@ export type ComposerCommandItem =
type: "path";
path: string;
pathKind: ProjectEntry["kind"];
searchTarget: ComposerPathSearchTarget;
label: string;
description: string;
}
Expand Down
36 changes: 36 additions & 0 deletions apps/web/src/composer-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
expandCollapsedComposerCursor,
formatAssistantCitationForComposer,
isCollapsedCursorAdjacentToInlineToken,
isPathSuggestionCurrent,
parseStandaloneComposerSlashCommand,
replaceTextRange,
} from "./composer-logic";
Expand All @@ -48,6 +49,41 @@ const citation: AssistantCitation = {
};
const citationSource = serializeAssistantCitation(citation).replaceAll("+", "%20");

describe("isPathSuggestionCurrent", () => {
const searchedTarget = {
environmentId: EnvironmentId.make("local"),
cwd: "/repo",
query: "alpha",
};

it("allows a file suggestion matching the live search", () => {
expect(
isPathSuggestionCurrent(
searchedTarget,
detectComposerTrigger("@alpha", 6),
searchedTarget.environmentId,
searchedTarget.cwd,
),
).toBe(true);
});

it.each([
["query", { ...searchedTarget, query: "beta" }],
["cwd", { ...searchedTarget, cwd: "/other-repo" }],
["environment", { ...searchedTarget, environmentId: EnvironmentId.make("remote") }],
] as const)("rejects a visible file suggestion after the live %s changes", (_change, current) => {
const prompt = `@${current.query}`;
expect(
isPathSuggestionCurrent(
searchedTarget,
detectComposerTrigger(prompt, prompt.length),
current.environmentId,
current.cwd,
),
).toBe(false);
});
});

describe("formatAssistantCitationForComposer", () => {
it.each([undefined, "", " \n\t "])(
"keeps citation-only insertion for a blank comment %j",
Expand Down
21 changes: 20 additions & 1 deletion apps/web/src/composer-logic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { ClientSettings } from "@t3tools/contracts/settings";
import type { AssistantCitation, ResolvedKeybindingsConfig } from "@t3tools/contracts";
import type {
AssistantCitation,
EnvironmentId,
ResolvedKeybindingsConfig,
} from "@t3tools/contracts";
import type { ComposerPathSearchTarget } from "@t3tools/client-runtime/state/threads";
import {
serializeAssistantCitation,
withAssistantCitationComment,
Expand All @@ -23,6 +28,20 @@ export interface ComposerTrigger {
rangeEnd: number;
}

export function isPathSuggestionCurrent(
searchTarget: ComposerPathSearchTarget,
trigger: ComposerTrigger | null,
environmentId: EnvironmentId | null,
cwd: string | null,
) {
return (
trigger?.kind === "path" &&
searchTarget.environmentId === environmentId &&
searchTarget.cwd === cwd &&
searchTarget.query === trigger.query.trim()
);
}

export function formatAssistantCitationForComposer(citation: AssistantCitation, comment = "") {
return `${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `;
}
Expand Down
16 changes: 0 additions & 16 deletions apps/web/src/lib/composerPathSearchState.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/web/src/state/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export function useProjectPathSearch(
isPending:
!areProjectPathSearchTargetsEqual(normalizedTarget, debouncedTarget) ||
(hasTarget && (fileAccess.isPending || result.isPending)),
searchedTarget: debouncedTarget,
searchedQuery: debouncedTarget.query ?? "",
truncated: result.data?.truncated ?? false,
refresh: result.refresh,
Expand Down
Loading