Skip to content
TypeScript

refactor(web): composer suggestion lists are built by useComposerMenuItems (#22722)

Julius Marmingeb7b905de9cf3
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index d121edac8b0..106d84fd125 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -1,4 +1,3 @@
-import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
import { useComposerTypingGuard } from "./useComposerTypingGuard";
import { insertAttachmentReferencesForDraft } from "./composerAttachmentReferences";
import { DESKTOP_PASTE_AS_TEXT_EVENT } from "../../lib/desktopPasteAsText";
@@ -6,10 +5,6 @@ import { runtimeModeConfig, runtimeModeOptions as runtimeModes } from "./runtime
import { isLocalEnvironmentDisabled } from "../../localEnvironment";
import { usePrimaryEnvironmentId } from "../../state/environments";
import { useRightPanelStore } from "~/rightPanelStore";
-import {
- composerPullRequestsFromLinks,
- filterComposerPullRequestMatches,
-} from "@t3tools/shared/composerPullRequestMatches";
import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste";
import { elementContextToPreviewAnnotation } from "../../lib/elementContext";
import {
@@ -27,7 +22,6 @@ import type {
EnvironmentId,
ModelSelection,
ProjectId,
- PullRequestListInput,
PreviewAnnotationPayload,
ProviderApprovalDecision,
ThreadContextRecord,
@@ -134,6 +128,7 @@ import {
import { ComposerStashBadge } from "./ComposerStashBadge";
import { ComposerStashMenu } from "./ComposerStashMenu";
import { useComposerTriggerState } from "./useComposerTriggerState";
+import { useComposerMenuItems } from "./useComposerMenuItems";
import { useComposerFocusState } from "./useComposerFocusState";
import { useComposerMultilinePrompt } from "./useComposerMultilinePrompt";
import {
@@ -246,9 +241,8 @@ import {
copiedComposerAttachmentFile,
rememberCopiedComposerAttachments,
} from "~/lib/copiedComposerAttachments";
-import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems";
import { useThreadContextDrop, threadContextDropTargetProps } from "./threadContextDrag";
-import { readThreadShell, useThreadShells } from "~/state/entities";
+import { readThreadShell } from "~/state/entities";
import { requestConfirmDialog } from "~/confirmDialog";
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
import type {
@@ -262,13 +256,6 @@ import { readPreparedConnection } from "~/state/session";
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
import { orchestrationEnvironment } from "~/state/orchestration";
import { threadContextAttachment } from "~/lib/threadContextAttachment";
-import {
- pullRequestEnvironment,
- usePullRequestList,
- type EnvironmentQueryTarget,
-} from "~/state/pullRequests";
-import { useEnvironmentQuery } from "~/state/query";
-import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
import {
type ComposerCommandItem,
ComposerCommandMenu,
@@ -296,14 +283,6 @@ import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
import { ComposerControl, ComposerControlSeparator } from "./ComposerControl";
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
import { buildPullRequestReferenceContext } from "../pullRequest/pullRequestDetail.logic";
-import {
- matchesPullRequestQuery,
- rankPullRequestMatches,
-} from "../pullRequest/pullRequestList.logic";
-import {
- searchSlashCommandItems,
- slashCommandItemsForPromptPosition,
-} from "./composerSlashCommandSearch";
import {
getComposerPromptInjectionState,
getComposerProviderState,
@@ -327,7 +306,6 @@ import {
subscribeToPendingSnapShotAnimations,
} from "../../lib/snapShotAnimation";
import { resizeSnapShotSource } from "../../lib/snapShotSource";
-import { basenameOfPath } from "../../pierre-icons";
import { cn, isMacPlatform, randomUUID } from "~/lib/utils";
import {
getComposerPromptLengthValidationMessage,
@@ -357,11 +335,7 @@ type ComposerCommandMenuPosition = {
width: number;
};
-const COMPOSER_PULL_REQUEST_LIST_LIMIT = 99;
const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidError);
-const COMPOSER_PULL_REQUEST_RESULT_LIMIT = 12;
-const EMPTY_PULL_REQUEST_LIST_TARGETS: ReadonlyArray<EnvironmentQueryTarget<PullRequestListInput>> =
- [];
const COMPOSER_SCROLL_COLLAPSE_THRESHOLD_PX = 24;
const COMPOSER_SCROLL_GESTURE_RESET_MS = 120;
@@ -1006,14 +980,11 @@ import {
} from "@t3tools/client-runtime/state/composer-dispatch";
import type { ContextWindowSnapshot } from "../../lib/contextWindow";
import {
- getProviderSlashCommandsForSlashMenu,
- getProviderSkillsForSlashMenu,
hasCompleteProviderWorkspaceSnapshot,
hasCurrentProviderWorkspaceSnapshot,
resolveProviderSkillsForCwd,
resolveProviderSlashCommandsForCwd,
} from "@t3tools/client-runtime/providerSkills";
-import { searchProviderSkills } from "../../providerSkillSearch";
import { useDelayedStatus } from "../../hooks/useDelayedStatus";
import { useMediaQuery } from "../../hooks/useMediaQuery";
import { useSoftwareKeyboardOpen } from "../../hooks/useSoftwareKeyboardOpen";
@@ -2260,25 +2231,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
elementContextCount: composerPreviewAnnotations.length + composerReviewComments.length,
});
const composerTriggerKind = composerTrigger?.kind ?? null;
- const pathTriggerQuery = composerTrigger?.kind === "path" ? composerTrigger.query : "";
- const pullRequestTriggerQuery =
- composerTrigger?.kind === "pull-request" ? composerTrigger.query : "";
- const pullRequestTextQuery =
- composerTriggerKind === "pull-request" &&
- pullRequestTriggerQuery.length > 0 &&
- !/^\d+$/u.test(pullRequestTriggerQuery)
- ? pullRequestTriggerQuery
- : null;
- const debouncedPullRequestTextQuery = useDebouncedValue(pullRequestTextQuery, 180);
- const settledPullRequestTextQuery =
- pullRequestTextQuery === debouncedPullRequestTextQuery ? pullRequestTextQuery : null;
- const isPathTrigger = composerTriggerKind === "path";
- const environmentThreadShells = useThreadShells(isPathTrigger);
- const workspaceEntries = useComposerPathSearch({
- environmentId,
- cwd: isPathTrigger ? gitCwd : null,
- query: isPathTrigger ? pathTriggerQuery : null,
- });
const compactSlashCommandAvailable =
composerTrigger?.kind === "slash-command" &&
prompt.slice(0, composerTrigger.rangeStart).trim() === "" &&
@@ -2289,220 +2241,25 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
composerTerminalContexts.length === 0 &&
composerPreviewAnnotations.length === 0 &&
composerReviewComments.length === 0;
-
- const pullRequestListTargets =
- composerTriggerKind !== "pull-request" ||
- pullRequestProjectId === null ||
- (pullRequestTextQuery !== null && settledPullRequestTextQuery === null)
- ? EMPTY_PULL_REQUEST_LIST_TARGETS
- : [
- {
- environmentId,
- input: {
- state: "all" as const,
- projectId: pullRequestProjectId,
- limit: COMPOSER_PULL_REQUEST_LIST_LIMIT,
- ...(settledPullRequestTextQuery === null
- ? {}
- : { query: settledPullRequestTextQuery }),
- },
- },
- ];
- const pullRequestLookup = usePullRequestList(pullRequestListTargets);
- const pullRequestTriggerNumber = (() => {
- if (composerTrigger?.kind !== "pull-request" || composerTrigger.query.length === 0) {
- return null;
- }
- const number = Number(composerTrigger.query);
- return Number.isSafeInteger(number) && number > 0 ? number : null;
- })();
- const debouncedPullRequestNumber = useDebouncedValue(pullRequestTriggerNumber, 180);
- const settledPullRequestNumber =
- pullRequestTriggerNumber === debouncedPullRequestNumber ? pullRequestTriggerNumber : null;
- const recentHasExactPullRequest =
- settledPullRequestNumber !== null &&
- pullRequestLookup.data?.entries.some(
- (entry) =>
- entry.projectId === pullRequestProjectId &&
- entry.repository.trim().toLowerCase() === pullRequestRepository?.trim().toLowerCase() &&
- entry.number === settledPullRequestNumber,
- ) === true;
- const exactPullRequestLookup = useEnvironmentQuery(
- settledPullRequestNumber === null ||
- pullRequestProjectId === null ||
- pullRequestRepository === null ||
- recentHasExactPullRequest
- ? null
- : pullRequestEnvironment.detail({
- environmentId,
- input: {
- projectId: pullRequestProjectId,
- repository: pullRequestRepository,
- number: settledPullRequestNumber,
- },
- }),
- );
-
- const linkedPullRequests =
- pullRequestProjectId === null
- ? []
- : composerPullRequestsFromLinks(threadPullRequests ?? [], pullRequestProjectId);
-
- const composerMenuItems = ((): ComposerCommandItem[] => {
- if (!composerTrigger) return [];
- if (composerTrigger.kind === "path") {
- return [
- ...matchComposerThreadItems({
- shells: environmentThreadShells,
- environmentId,
- excludeThreadId: activeThreadId,
- query: composerTrigger.query,
- }),
- ...workspaceEntries.entries.map((entry) => ({
- id: `path:${entry.kind}:${entry.path}`,
- 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("/"))),
- })),
- ];
- }
- if (composerTrigger.kind === "slash-command") {
- const builtInSlashCommandItems = [
- {
- id: "slash:model",
- type: "slash-command",
- command: "model",
- label: "/model",
- description: "Switch response model for this thread",
- },
- ...(planModeUiEnabled
- ? ([
- {
- id: "slash:plan",
- type: "slash-command",
- command: "plan",
- label: "/plan",
- description: "Switch this thread into plan mode",
- },
- {
- id: "slash:default",
- type: "slash-command",
- command: "default",
- label: "/default",
- description: "Switch this thread back to normal build mode",
- },
- ] as const)
- : []),
- ] satisfies ReadonlyArray<Extract<ComposerCommandItem, { type: "slash-command" }>>;
- const slashMenuSkills = getProviderSkillsForSlashMenu(
- selectedProviderSkills,
- settings.showSkillsInSlashMenu,
- );
- const providerSlashCommandItems = getProviderSlashCommandsForSlashMenu(
- selectedProviderSlashCommands,
- slashMenuSkills,
- ).map((command) => ({
- id: `provider-slash-command:${selectedProvider}:${command.name}`,
- type: "provider-slash-command" as const,
- provider: selectedProvider,
- command,
- label: `/${command.name}`,
- description: command.description ?? command.input?.hint ?? "Run provider command",
- }));
- const query = composerTrigger.query.trim().toLowerCase();
- const skillItems = slashMenuSkills.map((skill) => ({
- id: `skill:${selectedProvider}:${skill.name}`,
- type: "skill" as const,
- provider: selectedProvider,
- skill,
- label: `/skill:${skill.name}`,
- description:
- skill.shortDescription ??
- skill.description ??
- (skill.scope ? `${skill.scope} skill` : ""),
- }));
- const visibleProviderSlashCommandItems = providerSlashCommandItems.filter(
- (item) => item.command.name !== "compact" || compactSlashCommandAvailable,
- );
- const slashCommandItems = slashCommandItemsForPromptPosition(
- [...builtInSlashCommandItems, ...visibleProviderSlashCommandItems, ...skillItems],
- composerTrigger.rangeStart === 0,
- );
- return searchSlashCommandItems(slashCommandItems, query);
- }
- if (composerTrigger.kind === "skill") {
- return searchProviderSkills(selectedProviderSkills, composerTrigger.query).map((skill) => ({
- id: `skill:${selectedProvider}:${skill.name}`,
- type: "skill" as const,
- provider: selectedProvider,
- skill,
- label: formatProviderSkillDisplayName(skill),
- description:
- skill.shortDescription ??
- skill.description ??
- (skill.scope ? `${skill.scope} skill` : "Run provider skill"),
- }));
- }
- if (
- composerTrigger.kind === "pull-request" &&
- pullRequestProjectId !== null &&
- pullRequestRepository !== null
- ) {
- const exactPullRequest =
- exactPullRequestLookup.data?.number === pullRequestTriggerNumber
- ? [exactPullRequestLookup.data]
- : [];
- const matches = /^\d*$/u.test(composerTrigger.query)
- ? filterComposerPullRequestMatches({
- entries: [...exactPullRequest, ...(pullRequestLookup.data?.entries ?? [])],
- linked: linkedPullRequests,
- projectId: pullRequestProjectId,
- repository: pullRequestRepository,
- query: composerTrigger.query,
- limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
- })
- : rankPullRequestMatches(
- (pullRequestLookup.data?.entries ?? []).filter((entry) => {
- if (
- entry.projectId !== pullRequestProjectId ||
- entry.repository.trim().toLowerCase() !== pullRequestRepository.trim().toLowerCase()
- ) {
- return false;
- }
- const provider = pullRequestLookup.data?.providers.find(
- (candidate) => candidate.host === entry.host,
- );
- return (
- provider?.searchesOnHost === true ||
- matchesPullRequestQuery(entry, composerTrigger.query)
- );
- }),
- composerTrigger.query,
- ).slice(0, COMPOSER_PULL_REQUEST_RESULT_LIMIT);
- return matches.map((pullRequest) => ({
- id: `pull-request:${pullRequest.projectId}:${pullRequest.repository}:${pullRequest.number}`,
- type: "pull-request",
- pullRequest: {
- number: pullRequest.number,
- title: pullRequest.title,
- url: pullRequest.url,
- headBranch: pullRequest.headBranch,
- baseBranch: pullRequest.baseBranch,
- state: pullRequest.state,
- isDraft: pullRequest.isDraft,
- },
- label: `#${pullRequest.number}`,
- description:
- pullRequest.repository.trim().toLowerCase() === pullRequestRepository.trim().toLowerCase()
- ? pullRequest.title
- : `${pullRequest.repository} · ${pullRequest.title}`,
- }));
- }
- return [];
- })();
+ const {
+ items: composerMenuItems,
+ isLoading: isComposerMenuLoading,
+ emptyState: composerMenuEmptyState,
+ } = useComposerMenuItems({
+ composerTrigger,
+ environmentId,
+ gitCwd,
+ activeThreadId,
+ pullRequestProjectId,
+ pullRequestRepository,
+ threadPullRequests,
+ planModeUiEnabled,
+ compactSlashCommandAvailable,
+ selectedProvider,
+ selectedProviderSkills,
+ selectedProviderSlashCommands,
+ showSkillsInSlashMenu: settings.showSkillsInSlashMenu,
+ });
const composerMenuOpen = Boolean(composerTrigger);
const composerMenuSearchKey = composerTrigger
@@ -2550,38 +2307,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
activePendingProgress.activeQuestion?.allowCustomAnswer !== false));
const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
- const isComposerMenuLoading =
- (composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending) ||
- (composerTriggerKind === "pull-request" &&
- pullRequestProjectId !== null &&
- pullRequestRepository !== null &&
- (pullRequestLookup.isPending ||
- pullRequestTextQuery !== debouncedPullRequestTextQuery ||
- pullRequestTriggerNumber !== debouncedPullRequestNumber ||
- exactPullRequestLookup.isPending));
- const composerMenuEmptyState = (() => {
- if (composerTriggerKind === "skill") {
- return "No skills found. Try / to browse provider commands.";
- }
- if (composerTriggerKind === "pull-request") {
- if (pullRequestProjectId === null || pullRequestRepository === null) {
- return "Pull requests are not available for this project.";
- }
- if (
- pullRequestLookup.error !== null ||
- pullRequestLookup.data?.errors.some((error) => error.projectId === pullRequestProjectId)
- ) {
- return "Pull requests could not be read for this project.";
- }
- return composerTrigger?.query
- ? `No pull request matches ${composerTrigger.query}.`
- : "No pull requests found in this repository.";
- }
- return composerTriggerKind === "path"
- ? "No matching files or folders."
- : "No matching command.";
- })();
-
const setPromptFromTraits = (nextPrompt: string) => {
if (nextPrompt === promptRef.current) {
scheduleComposerFocus();
diff --git a/apps/web/src/components/chat/useComposerMenuItems.ts b/apps/web/src/components/chat/useComposerMenuItems.ts
new file mode 100644
index 00000000000..cfbcf73c60e
--- /dev/null
+++ b/apps/web/src/components/chat/useComposerMenuItems.ts
@@ -0,0 +1,344 @@
+import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems";
+import type {
+ EnvironmentId,
+ ProjectId,
+ ProviderDriverKind,
+ PullRequestListInput,
+ ServerProvider,
+ ThreadId,
+ ThreadPullRequestLink,
+} from "@t3tools/contracts";
+import {
+ composerPullRequestsFromLinks,
+ filterComposerPullRequestMatches,
+} from "@t3tools/shared/composerPullRequestMatches";
+import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
+
+import type { ComposerTrigger } from "../../composer-logic";
+import { basenameOfPath } from "../../pierre-icons";
+import {
+ getProviderSkillsForSlashMenu,
+ getProviderSlashCommandsForSlashMenu,
+} from "@t3tools/client-runtime/providerSkills";
+import { searchProviderSkills } from "../../providerSkillSearch";
+import { useThreadShells } from "~/state/entities";
+import {
+ pullRequestEnvironment,
+ usePullRequestList,
+ type EnvironmentQueryTarget,
+} from "~/state/pullRequests";
+import { useEnvironmentQuery } from "~/state/query";
+import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
+import {
+ matchesPullRequestQuery,
+ rankPullRequestMatches,
+} from "../pullRequest/pullRequestList.logic";
+import type { ComposerCommandItem } from "./ComposerCommandMenu";
+import {
+ searchSlashCommandItems,
+ slashCommandItemsForPromptPosition,
+} from "./composerSlashCommandSearch";
+
+const COMPOSER_PULL_REQUEST_LIST_LIMIT = 99;
+const COMPOSER_PULL_REQUEST_RESULT_LIMIT = 12;
+const EMPTY_PULL_REQUEST_LIST_TARGETS: ReadonlyArray<EnvironmentQueryTarget<PullRequestListInput>> =
+ [];
+
+/** Builds the @, /, $ and # suggestion lists, running the searches each trigger needs. */
+export function useComposerMenuItems({
+ composerTrigger,
+ environmentId,
+ gitCwd,
+ activeThreadId,
+ pullRequestProjectId,
+ pullRequestRepository,
+ threadPullRequests,
+ planModeUiEnabled,
+ compactSlashCommandAvailable,
+ selectedProvider,
+ selectedProviderSkills,
+ selectedProviderSlashCommands,
+ showSkillsInSlashMenu,
+}: {
+ readonly composerTrigger: ComposerTrigger | null;
+ readonly environmentId: EnvironmentId;
+ readonly gitCwd: string | null;
+ readonly activeThreadId: ThreadId | null;
+ readonly pullRequestProjectId: ProjectId | null;
+ readonly pullRequestRepository: string | null;
+ readonly threadPullRequests: ReadonlyArray<ThreadPullRequestLink> | undefined;
+ readonly planModeUiEnabled: boolean;
+ readonly compactSlashCommandAvailable: boolean;
+ readonly selectedProvider: ProviderDriverKind;
+ readonly selectedProviderSkills: ServerProvider["skills"];
+ readonly selectedProviderSlashCommands: ServerProvider["slashCommands"];
+ readonly showSkillsInSlashMenu: boolean;
+}) {
+ const composerTriggerKind = composerTrigger?.kind ?? null;
+ const pathTriggerQuery = composerTrigger?.kind === "path" ? composerTrigger.query : "";
+ const pullRequestTriggerQuery =
+ composerTrigger?.kind === "pull-request" ? composerTrigger.query : "";
+ const pullRequestTextQuery =
+ composerTriggerKind === "pull-request" &&
+ pullRequestTriggerQuery.length > 0 &&
+ !/^\d+$/u.test(pullRequestTriggerQuery)
+ ? pullRequestTriggerQuery
+ : null;
+ const debouncedPullRequestTextQuery = useDebouncedValue(pullRequestTextQuery, 180);
+ const settledPullRequestTextQuery =
+ pullRequestTextQuery === debouncedPullRequestTextQuery ? pullRequestTextQuery : null;
+ const isPathTrigger = composerTriggerKind === "path";
+ const environmentThreadShells = useThreadShells(isPathTrigger);
+ const workspaceEntries = useComposerPathSearch({
+ environmentId,
+ cwd: isPathTrigger ? gitCwd : null,
+ query: isPathTrigger ? pathTriggerQuery : null,
+ });
+
+ const pullRequestListTargets =
+ composerTriggerKind !== "pull-request" ||
+ pullRequestProjectId === null ||
+ (pullRequestTextQuery !== null && settledPullRequestTextQuery === null)
+ ? EMPTY_PULL_REQUEST_LIST_TARGETS
+ : [
+ {
+ environmentId,
+ input: {
+ state: "all" as const,
+ projectId: pullRequestProjectId,
+ limit: COMPOSER_PULL_REQUEST_LIST_LIMIT,
+ ...(settledPullRequestTextQuery === null
+ ? {}
+ : { query: settledPullRequestTextQuery }),
+ },
+ },
+ ];
+ const pullRequestLookup = usePullRequestList(pullRequestListTargets);
+ const pullRequestTriggerNumber = (() => {
+ if (composerTrigger?.kind !== "pull-request" || composerTrigger.query.length === 0) {
+ return null;
+ }
+ const number = Number(composerTrigger.query);
+ return Number.isSafeInteger(number) && number > 0 ? number : null;
+ })();
+ const debouncedPullRequestNumber = useDebouncedValue(pullRequestTriggerNumber, 180);
+ const settledPullRequestNumber =
+ pullRequestTriggerNumber === debouncedPullRequestNumber ? pullRequestTriggerNumber : null;
+ const recentHasExactPullRequest =
+ settledPullRequestNumber !== null &&
+ pullRequestLookup.data?.entries.some(
+ (entry) =>
+ entry.projectId === pullRequestProjectId &&
+ entry.repository.trim().toLowerCase() === pullRequestRepository?.trim().toLowerCase() &&
+ entry.number === settledPullRequestNumber,
+ ) === true;
+ const exactPullRequestLookup = useEnvironmentQuery(
+ settledPullRequestNumber === null ||
+ pullRequestProjectId === null ||
+ pullRequestRepository === null ||
+ recentHasExactPullRequest
+ ? null
+ : pullRequestEnvironment.detail({
+ environmentId,
+ input: {
+ projectId: pullRequestProjectId,
+ repository: pullRequestRepository,
+ number: settledPullRequestNumber,
+ },
+ }),
+ );
+
+ const linkedPullRequests =
+ pullRequestProjectId === null
+ ? []
+ : composerPullRequestsFromLinks(threadPullRequests ?? [], pullRequestProjectId);
+
+ const items = ((): ComposerCommandItem[] => {
+ if (!composerTrigger) return [];
+ if (composerTrigger.kind === "path") {
+ return [
+ ...matchComposerThreadItems({
+ shells: environmentThreadShells,
+ environmentId,
+ excludeThreadId: activeThreadId,
+ query: composerTrigger.query,
+ }),
+ ...workspaceEntries.entries.map((entry) => ({
+ id: `path:${entry.kind}:${entry.path}`,
+ 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("/"))),
+ })),
+ ];
+ }
+ if (composerTrigger.kind === "slash-command") {
+ const builtInSlashCommandItems = [
+ {
+ id: "slash:model",
+ type: "slash-command",
+ command: "model",
+ label: "/model",
+ description: "Switch response model for this thread",
+ },
+ ...(planModeUiEnabled
+ ? ([
+ {
+ id: "slash:plan",
+ type: "slash-command",
+ command: "plan",
+ label: "/plan",
+ description: "Switch this thread into plan mode",
+ },
+ {
+ id: "slash:default",
+ type: "slash-command",
+ command: "default",
+ label: "/default",
+ description: "Switch this thread back to normal build mode",
+ },
+ ] as const)
+ : []),
+ ] satisfies ReadonlyArray<Extract<ComposerCommandItem, { type: "slash-command" }>>;
+ const slashMenuSkills = getProviderSkillsForSlashMenu(
+ selectedProviderSkills,
+ showSkillsInSlashMenu,
+ );
+ const providerSlashCommandItems = getProviderSlashCommandsForSlashMenu(
+ selectedProviderSlashCommands,
+ slashMenuSkills,
+ ).map((command) => ({
+ id: `provider-slash-command:${selectedProvider}:${command.name}`,
+ type: "provider-slash-command" as const,
+ provider: selectedProvider,
+ command,
+ label: `/${command.name}`,
+ description: command.description ?? command.input?.hint ?? "Run provider command",
+ }));
+ const query = composerTrigger.query.trim().toLowerCase();
+ const skillItems = slashMenuSkills.map((skill) => ({
+ id: `skill:${selectedProvider}:${skill.name}`,
+ type: "skill" as const,
+ provider: selectedProvider,
+ skill,
+ label: `/skill:${skill.name}`,
+ description:
+ skill.shortDescription ??
+ skill.description ??
+ (skill.scope ? `${skill.scope} skill` : ""),
+ }));
+ const visibleProviderSlashCommandItems = providerSlashCommandItems.filter(
+ (item) => item.command.name !== "compact" || compactSlashCommandAvailable,
+ );
+ const slashCommandItems = slashCommandItemsForPromptPosition(
+ [...builtInSlashCommandItems, ...visibleProviderSlashCommandItems, ...skillItems],
+ composerTrigger.rangeStart === 0,
+ );
+ return searchSlashCommandItems(slashCommandItems, query);
+ }
+ if (composerTrigger.kind === "skill") {
+ return searchProviderSkills(selectedProviderSkills, composerTrigger.query).map((skill) => ({
+ id: `skill:${selectedProvider}:${skill.name}`,
+ type: "skill" as const,
+ provider: selectedProvider,
+ skill,
+ label: formatProviderSkillDisplayName(skill),
+ description:
+ skill.shortDescription ??
+ skill.description ??
+ (skill.scope ? `${skill.scope} skill` : "Run provider skill"),
+ }));
+ }
+ if (
+ composerTrigger.kind === "pull-request" &&
+ pullRequestProjectId !== null &&
+ pullRequestRepository !== null
+ ) {
+ const exactPullRequest =
+ exactPullRequestLookup.data?.number === pullRequestTriggerNumber
+ ? [exactPullRequestLookup.data]
+ : [];
+ const matches = /^\d*$/u.test(composerTrigger.query)
+ ? filterComposerPullRequestMatches({
+ entries: [...exactPullRequest, ...(pullRequestLookup.data?.entries ?? [])],
+ linked: linkedPullRequests,
+ projectId: pullRequestProjectId,
+ repository: pullRequestRepository,
+ query: composerTrigger.query,
+ limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
+ })
+ : rankPullRequestMatches(
+ (pullRequestLookup.data?.entries ?? []).filter((entry) => {
+ if (
+ entry.projectId !== pullRequestProjectId ||
+ entry.repository.trim().toLowerCase() !== pullRequestRepository.trim().toLowerCase()
+ ) {
+ return false;
+ }
+ const provider = pullRequestLookup.data?.providers.find(
+ (candidate) => candidate.host === entry.host,
+ );
+ return (
+ provider?.searchesOnHost === true ||
+ matchesPullRequestQuery(entry, composerTrigger.query)
+ );
+ }),
+ composerTrigger.query,
+ ).slice(0, COMPOSER_PULL_REQUEST_RESULT_LIMIT);
+ return matches.map((pullRequest) => ({
+ id: `pull-request:${pullRequest.projectId}:${pullRequest.repository}:${pullRequest.number}`,
+ type: "pull-request",
+ pullRequest: {
+ number: pullRequest.number,
+ title: pullRequest.title,
+ url: pullRequest.url,
+ headBranch: pullRequest.headBranch,
+ baseBranch: pullRequest.baseBranch,
+ state: pullRequest.state,
+ isDraft: pullRequest.isDraft,
+ },
+ label: `#${pullRequest.number}`,
+ description:
+ pullRequest.repository.trim().toLowerCase() === pullRequestRepository.trim().toLowerCase()
+ ? pullRequest.title
+ : `${pullRequest.repository} · ${pullRequest.title}`,
+ }));
+ }
+ return [];
+ })();
+ const isLoading =
+ (composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending) ||
+ (composerTriggerKind === "pull-request" &&
+ pullRequestProjectId !== null &&
+ pullRequestRepository !== null &&
+ (pullRequestLookup.isPending ||
+ pullRequestTextQuery !== debouncedPullRequestTextQuery ||
+ pullRequestTriggerNumber !== debouncedPullRequestNumber ||
+ exactPullRequestLookup.isPending));
+ const emptyState = (() => {
+ if (composerTriggerKind === "skill") {
+ return "No skills found. Try / to browse provider commands.";
+ }
+ if (composerTriggerKind === "pull-request") {
+ if (pullRequestProjectId === null || pullRequestRepository === null) {
+ return "Pull requests are not available for this project.";
+ }
+ if (
+ pullRequestLookup.error !== null ||
+ pullRequestLookup.data?.errors.some((error) => error.projectId === pullRequestProjectId)
+ ) {
+ return "Pull requests could not be read for this project.";
+ }
+ return composerTrigger?.query
+ ? `No pull request matches ${composerTrigger.query}.`
+ : "No pull requests found in this repository.";
+ }
+ return composerTriggerKind === "path"
+ ? "No matching files or folders."
+ : "No matching command.";
+ })();
+
+ return { items, isLoading, emptyState };
+}