@devries-cameron20 / t3code-1 / commits / b7b905de9c
Fork 0

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

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:24 UTC b7b905de9cf34c027d1ad65964146578e13506c7
2 files changed +365 -296
apps/web/src/components/chat/ChatComposer.tsx
+21 -296
@@ -1,4 +1,3 @@
1 -import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
1 import { useComposerTypingGuard } from "./useComposerTypingGuard";
2 import { insertAttachmentReferencesForDraft } from "./composerAttachmentReferences";
3 import { DESKTOP_PASTE_AS_TEXT_EVENT } from "../../lib/desktopPasteAsText";
@@ -6,10 +5,6 @@ import { runtimeModeConfig, runtimeModeOptions as runtimeModes } from "./runtime
5 import { isLocalEnvironmentDisabled } from "../../localEnvironment";
6 import { usePrimaryEnvironmentId } from "../../state/environments";
7 import { useRightPanelStore } from "~/rightPanelStore";
9 -import {
10 - composerPullRequestsFromLinks,
11 - filterComposerPullRequestMatches,
12 -} from "@t3tools/shared/composerPullRequestMatches";
8 import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste";
9 import { elementContextToPreviewAnnotation } from "../../lib/elementContext";
10 import {
@@ -27,7 +22,6 @@ import type {
22 EnvironmentId,
23 ModelSelection,
24 ProjectId,
30 - PullRequestListInput,
25 PreviewAnnotationPayload,
26 ProviderApprovalDecision,
27 ThreadContextRecord,
@@ -134,6 +128,7 @@ import {
128 import { ComposerStashBadge } from "./ComposerStashBadge";
129 import { ComposerStashMenu } from "./ComposerStashMenu";
130 import { useComposerTriggerState } from "./useComposerTriggerState";
131 +import { useComposerMenuItems } from "./useComposerMenuItems";
132 import { useComposerFocusState } from "./useComposerFocusState";
133 import { useComposerMultilinePrompt } from "./useComposerMultilinePrompt";
134 import {
@@ -246,9 +241,8 @@ import {
241 copiedComposerAttachmentFile,
242 rememberCopiedComposerAttachments,
243 } from "~/lib/copiedComposerAttachments";
249 -import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems";
244 import { useThreadContextDrop, threadContextDropTargetProps } from "./threadContextDrag";
251 -import { readThreadShell, useThreadShells } from "~/state/entities";
245 +import { readThreadShell } from "~/state/entities";
246 import { requestConfirmDialog } from "~/confirmDialog";
247 import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
248 import type {
@@ -262,13 +256,6 @@ import { readPreparedConnection } from "~/state/session";
256 import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
257 import { orchestrationEnvironment } from "~/state/orchestration";
258 import { threadContextAttachment } from "~/lib/threadContextAttachment";
265 -import {
266 - pullRequestEnvironment,
267 - usePullRequestList,
268 - type EnvironmentQueryTarget,
269 -} from "~/state/pullRequests";
270 -import { useEnvironmentQuery } from "~/state/query";
271 -import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
259 import {
260 type ComposerCommandItem,
261 ComposerCommandMenu,
@@ -296,14 +283,6 @@ import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
283 import { ComposerControl, ComposerControlSeparator } from "./ComposerControl";
284 import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
285 import { buildPullRequestReferenceContext } from "../pullRequest/pullRequestDetail.logic";
299 -import {
300 - matchesPullRequestQuery,
301 - rankPullRequestMatches,
302 -} from "../pullRequest/pullRequestList.logic";
303 -import {
304 - searchSlashCommandItems,
305 - slashCommandItemsForPromptPosition,
306 -} from "./composerSlashCommandSearch";
286 import {
287 getComposerPromptInjectionState,
288 getComposerProviderState,
@@ -327,7 +306,6 @@ import {
306 subscribeToPendingSnapShotAnimations,
307 } from "../../lib/snapShotAnimation";
308 import { resizeSnapShotSource } from "../../lib/snapShotSource";
330 -import { basenameOfPath } from "../../pierre-icons";
309 import { cn, isMacPlatform, randomUUID } from "~/lib/utils";
310 import {
311 getComposerPromptLengthValidationMessage,
@@ -357,11 +335,7 @@ type ComposerCommandMenuPosition = {
335 width: number;
336 };
337
360 -const COMPOSER_PULL_REQUEST_LIST_LIMIT = 99;
338 const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidError);
362 -const COMPOSER_PULL_REQUEST_RESULT_LIMIT = 12;
363 -const EMPTY_PULL_REQUEST_LIST_TARGETS: ReadonlyArray<EnvironmentQueryTarget<PullRequestListInput>> =
364 - [];
339
340 const COMPOSER_SCROLL_COLLAPSE_THRESHOLD_PX = 24;
341 const COMPOSER_SCROLL_GESTURE_RESET_MS = 120;
@@ -1006,14 +980,11 @@ import {
980 } from "@t3tools/client-runtime/state/composer-dispatch";
981 import type { ContextWindowSnapshot } from "../../lib/contextWindow";
982 import {
1009 - getProviderSlashCommandsForSlashMenu,
1010 - getProviderSkillsForSlashMenu,
983 hasCompleteProviderWorkspaceSnapshot,
984 hasCurrentProviderWorkspaceSnapshot,
985 resolveProviderSkillsForCwd,
986 resolveProviderSlashCommandsForCwd,
987 } from "@t3tools/client-runtime/providerSkills";
1016 -import { searchProviderSkills } from "../../providerSkillSearch";
988 import { useDelayedStatus } from "../../hooks/useDelayedStatus";
989 import { useMediaQuery } from "../../hooks/useMediaQuery";
990 import { useSoftwareKeyboardOpen } from "../../hooks/useSoftwareKeyboardOpen";
@@ -2260,25 +2231,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2231 elementContextCount: composerPreviewAnnotations.length + composerReviewComments.length,
2232 });
2233 const composerTriggerKind = composerTrigger?.kind ?? null;
2263 - const pathTriggerQuery = composerTrigger?.kind === "path" ? composerTrigger.query : "";
2264 - const pullRequestTriggerQuery =
2265 - composerTrigger?.kind === "pull-request" ? composerTrigger.query : "";
2266 - const pullRequestTextQuery =
2267 - composerTriggerKind === "pull-request" &&
2268 - pullRequestTriggerQuery.length > 0 &&
2269 - !/^\d+$/u.test(pullRequestTriggerQuery)
2270 - ? pullRequestTriggerQuery
2271 - : null;
2272 - const debouncedPullRequestTextQuery = useDebouncedValue(pullRequestTextQuery, 180);
2273 - const settledPullRequestTextQuery =
2274 - pullRequestTextQuery === debouncedPullRequestTextQuery ? pullRequestTextQuery : null;
2275 - const isPathTrigger = composerTriggerKind === "path";
2276 - const environmentThreadShells = useThreadShells(isPathTrigger);
2277 - const workspaceEntries = useComposerPathSearch({
2278 - environmentId,
2279 - cwd: isPathTrigger ? gitCwd : null,
2280 - query: isPathTrigger ? pathTriggerQuery : null,
2281 - });
2234 const compactSlashCommandAvailable =
2235 composerTrigger?.kind === "slash-command" &&
2236 prompt.slice(0, composerTrigger.rangeStart).trim() === "" &&
@@ -2289,220 +2241,25 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2241 composerTerminalContexts.length === 0 &&
2242 composerPreviewAnnotations.length === 0 &&
2243 composerReviewComments.length === 0;
2292 -
2293 - const pullRequestListTargets =
2294 - composerTriggerKind !== "pull-request" ||
2295 - pullRequestProjectId === null ||
2296 - (pullRequestTextQuery !== null && settledPullRequestTextQuery === null)
2297 - ? EMPTY_PULL_REQUEST_LIST_TARGETS
2298 - : [
2299 - {
2300 - environmentId,
2301 - input: {
2302 - state: "all" as const,
2303 - projectId: pullRequestProjectId,
2304 - limit: COMPOSER_PULL_REQUEST_LIST_LIMIT,
2305 - ...(settledPullRequestTextQuery === null
2306 - ? {}
2307 - : { query: settledPullRequestTextQuery }),
2308 - },
2309 - },
2310 - ];
2311 - const pullRequestLookup = usePullRequestList(pullRequestListTargets);
2312 - const pullRequestTriggerNumber = (() => {
2313 - if (composerTrigger?.kind !== "pull-request" || composerTrigger.query.length === 0) {
2314 - return null;
2315 - }
2316 - const number = Number(composerTrigger.query);
2317 - return Number.isSafeInteger(number) && number > 0 ? number : null;
2318 - })();
2319 - const debouncedPullRequestNumber = useDebouncedValue(pullRequestTriggerNumber, 180);
2320 - const settledPullRequestNumber =
2321 - pullRequestTriggerNumber === debouncedPullRequestNumber ? pullRequestTriggerNumber : null;
2322 - const recentHasExactPullRequest =
2323 - settledPullRequestNumber !== null &&
2324 - pullRequestLookup.data?.entries.some(
2325 - (entry) =>
2326 - entry.projectId === pullRequestProjectId &&
2327 - entry.repository.trim().toLowerCase() === pullRequestRepository?.trim().toLowerCase() &&
2328 - entry.number === settledPullRequestNumber,
2329 - ) === true;
2330 - const exactPullRequestLookup = useEnvironmentQuery(
2331 - settledPullRequestNumber === null ||
2332 - pullRequestProjectId === null ||
2333 - pullRequestRepository === null ||
2334 - recentHasExactPullRequest
2335 - ? null
2336 - : pullRequestEnvironment.detail({
2337 - environmentId,
2338 - input: {
2339 - projectId: pullRequestProjectId,
2340 - repository: pullRequestRepository,
2341 - number: settledPullRequestNumber,
2342 - },
2343 - }),
2344 - );
2345 -
2346 - const linkedPullRequests =
2347 - pullRequestProjectId === null
2348 - ? []
2349 - : composerPullRequestsFromLinks(threadPullRequests ?? [], pullRequestProjectId);
2350 -
2351 - const composerMenuItems = ((): ComposerCommandItem[] => {
2352 - if (!composerTrigger) return [];
2353 - if (composerTrigger.kind === "path") {
2354 - return [
2355 - ...matchComposerThreadItems({
2356 - shells: environmentThreadShells,
2357 - environmentId,
2358 - excludeThreadId: activeThreadId,
2359 - query: composerTrigger.query,
2360 - }),
2361 - ...workspaceEntries.entries.map((entry) => ({
2362 - id: `path:${entry.kind}:${entry.path}`,
2363 - type: "path" as const,
2364 - path: entry.path,
2365 - pathKind: entry.kind,
2366 - searchTarget: workspaceEntries.searchedTarget,
2367 - label: basenameOfPath(entry.path),
2368 - description: entry.path.slice(0, Math.max(0, entry.path.lastIndexOf("/"))),
2369 - })),
2370 - ];
2371 - }
2372 - if (composerTrigger.kind === "slash-command") {
2373 - const builtInSlashCommandItems = [
2374 - {
2375 - id: "slash:model",
2376 - type: "slash-command",
2377 - command: "model",
2378 - label: "/model",
2379 - description: "Switch response model for this thread",
2380 - },
2381 - ...(planModeUiEnabled
2382 - ? ([
2383 - {
2384 - id: "slash:plan",
2385 - type: "slash-command",
2386 - command: "plan",
2387 - label: "/plan",
2388 - description: "Switch this thread into plan mode",
2389 - },
2390 - {
2391 - id: "slash:default",
2392 - type: "slash-command",
2393 - command: "default",
2394 - label: "/default",
2395 - description: "Switch this thread back to normal build mode",
2396 - },
2397 - ] as const)
2398 - : []),
2399 - ] satisfies ReadonlyArray<Extract<ComposerCommandItem, { type: "slash-command" }>>;
2400 - const slashMenuSkills = getProviderSkillsForSlashMenu(
2401 - selectedProviderSkills,
2402 - settings.showSkillsInSlashMenu,
2403 - );
2404 - const providerSlashCommandItems = getProviderSlashCommandsForSlashMenu(
2405 - selectedProviderSlashCommands,
2406 - slashMenuSkills,
2407 - ).map((command) => ({
2408 - id: `provider-slash-command:${selectedProvider}:${command.name}`,
2409 - type: "provider-slash-command" as const,
2410 - provider: selectedProvider,
2411 - command,
2412 - label: `/${command.name}`,
2413 - description: command.description ?? command.input?.hint ?? "Run provider command",
2414 - }));
2415 - const query = composerTrigger.query.trim().toLowerCase();
2416 - const skillItems = slashMenuSkills.map((skill) => ({
2417 - id: `skill:${selectedProvider}:${skill.name}`,
2418 - type: "skill" as const,
2419 - provider: selectedProvider,
2420 - skill,
2421 - label: `/skill:${skill.name}`,
2422 - description:
2423 - skill.shortDescription ??
2424 - skill.description ??
2425 - (skill.scope ? `${skill.scope} skill` : ""),
2426 - }));
2427 - const visibleProviderSlashCommandItems = providerSlashCommandItems.filter(
2428 - (item) => item.command.name !== "compact" || compactSlashCommandAvailable,
2429 - );
2430 - const slashCommandItems = slashCommandItemsForPromptPosition(
2431 - [...builtInSlashCommandItems, ...visibleProviderSlashCommandItems, ...skillItems],
2432 - composerTrigger.rangeStart === 0,
2433 - );
2434 - return searchSlashCommandItems(slashCommandItems, query);
2435 - }
2436 - if (composerTrigger.kind === "skill") {
2437 - return searchProviderSkills(selectedProviderSkills, composerTrigger.query).map((skill) => ({
2438 - id: `skill:${selectedProvider}:${skill.name}`,
2439 - type: "skill" as const,
2440 - provider: selectedProvider,
2441 - skill,
2442 - label: formatProviderSkillDisplayName(skill),
2443 - description:
2444 - skill.shortDescription ??
2445 - skill.description ??
2446 - (skill.scope ? `${skill.scope} skill` : "Run provider skill"),
2447 - }));
2448 - }
2449 - if (
2450 - composerTrigger.kind === "pull-request" &&
2451 - pullRequestProjectId !== null &&
2452 - pullRequestRepository !== null
2453 - ) {
2454 - const exactPullRequest =
2455 - exactPullRequestLookup.data?.number === pullRequestTriggerNumber
2456 - ? [exactPullRequestLookup.data]
2457 - : [];
2458 - const matches = /^\d*$/u.test(composerTrigger.query)
2459 - ? filterComposerPullRequestMatches({
2460 - entries: [...exactPullRequest, ...(pullRequestLookup.data?.entries ?? [])],
2461 - linked: linkedPullRequests,
2462 - projectId: pullRequestProjectId,
2463 - repository: pullRequestRepository,
2464 - query: composerTrigger.query,
2465 - limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
2466 - })
2467 - : rankPullRequestMatches(
2468 - (pullRequestLookup.data?.entries ?? []).filter((entry) => {
2469 - if (
2470 - entry.projectId !== pullRequestProjectId ||
2471 - entry.repository.trim().toLowerCase() !== pullRequestRepository.trim().toLowerCase()
2472 - ) {
2473 - return false;
2474 - }
2475 - const provider = pullRequestLookup.data?.providers.find(
2476 - (candidate) => candidate.host === entry.host,
2477 - );
2478 - return (
2479 - provider?.searchesOnHost === true ||
2480 - matchesPullRequestQuery(entry, composerTrigger.query)
2481 - );
2482 - }),
2483 - composerTrigger.query,
2484 - ).slice(0, COMPOSER_PULL_REQUEST_RESULT_LIMIT);
2485 - return matches.map((pullRequest) => ({
2486 - id: `pull-request:${pullRequest.projectId}:${pullRequest.repository}:${pullRequest.number}`,
2487 - type: "pull-request",
2488 - pullRequest: {
2489 - number: pullRequest.number,
2490 - title: pullRequest.title,
2491 - url: pullRequest.url,
2492 - headBranch: pullRequest.headBranch,
2493 - baseBranch: pullRequest.baseBranch,
2494 - state: pullRequest.state,
2495 - isDraft: pullRequest.isDraft,
2496 - },
2497 - label: `#${pullRequest.number}`,
2498 - description:
2499 - pullRequest.repository.trim().toLowerCase() === pullRequestRepository.trim().toLowerCase()
2500 - ? pullRequest.title
2501 - : `${pullRequest.repository} · ${pullRequest.title}`,
2502 - }));
2503 - }
2504 - return [];
2505 - })();
2244 + const {
2245 + items: composerMenuItems,
2246 + isLoading: isComposerMenuLoading,
2247 + emptyState: composerMenuEmptyState,
2248 + } = useComposerMenuItems({
2249 + composerTrigger,
2250 + environmentId,
2251 + gitCwd,
2252 + activeThreadId,
2253 + pullRequestProjectId,
2254 + pullRequestRepository,
2255 + threadPullRequests,
2256 + planModeUiEnabled,
2257 + compactSlashCommandAvailable,
2258 + selectedProvider,
2259 + selectedProviderSkills,
2260 + selectedProviderSlashCommands,
2261 + showSkillsInSlashMenu: settings.showSkillsInSlashMenu,
2262 + });
2263
2264 const composerMenuOpen = Boolean(composerTrigger);
2265 const composerMenuSearchKey = composerTrigger
@@ -2550,38 +2307,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2307 activePendingProgress.activeQuestion?.allowCustomAnswer !== false));
2308 const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
2309
2553 - const isComposerMenuLoading =
2554 - (composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending) ||
2555 - (composerTriggerKind === "pull-request" &&
2556 - pullRequestProjectId !== null &&
2557 - pullRequestRepository !== null &&
2558 - (pullRequestLookup.isPending ||
2559 - pullRequestTextQuery !== debouncedPullRequestTextQuery ||
2560 - pullRequestTriggerNumber !== debouncedPullRequestNumber ||
2561 - exactPullRequestLookup.isPending));
2562 - const composerMenuEmptyState = (() => {
2563 - if (composerTriggerKind === "skill") {
2564 - return "No skills found. Try / to browse provider commands.";
2565 - }
2566 - if (composerTriggerKind === "pull-request") {
2567 - if (pullRequestProjectId === null || pullRequestRepository === null) {
2568 - return "Pull requests are not available for this project.";
2569 - }
2570 - if (
2571 - pullRequestLookup.error !== null ||
2572 - pullRequestLookup.data?.errors.some((error) => error.projectId === pullRequestProjectId)
2573 - ) {
2574 - return "Pull requests could not be read for this project.";
2575 - }
2576 - return composerTrigger?.query
2577 - ? `No pull request matches ${composerTrigger.query}.`
2578 - : "No pull requests found in this repository.";
2579 - }
2580 - return composerTriggerKind === "path"
2581 - ? "No matching files or folders."
2582 - : "No matching command.";
2583 - })();
2584 -
2310 const setPromptFromTraits = (nextPrompt: string) => {
2311 if (nextPrompt === promptRef.current) {
2312 scheduleComposerFocus();
apps/web/src/components/chat/useComposerMenuItems.ts new
+344
@@ -0,0 +1,344 @@
1 +import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems";
2 +import type {
3 + EnvironmentId,
4 + ProjectId,
5 + ProviderDriverKind,
6 + PullRequestListInput,
7 + ServerProvider,
8 + ThreadId,
9 + ThreadPullRequestLink,
10 +} from "@t3tools/contracts";
11 +import {
12 + composerPullRequestsFromLinks,
13 + filterComposerPullRequestMatches,
14 +} from "@t3tools/shared/composerPullRequestMatches";
15 +import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
16 +
17 +import type { ComposerTrigger } from "../../composer-logic";
18 +import { basenameOfPath } from "../../pierre-icons";
19 +import {
20 + getProviderSkillsForSlashMenu,
21 + getProviderSlashCommandsForSlashMenu,
22 +} from "@t3tools/client-runtime/providerSkills";
23 +import { searchProviderSkills } from "../../providerSkillSearch";
24 +import { useThreadShells } from "~/state/entities";
25 +import {
26 + pullRequestEnvironment,
27 + usePullRequestList,
28 + type EnvironmentQueryTarget,
29 +} from "~/state/pullRequests";
30 +import { useEnvironmentQuery } from "~/state/query";
31 +import { useComposerPathSearch, useDebouncedValue } from "~/state/queries";
32 +import {
33 + matchesPullRequestQuery,
34 + rankPullRequestMatches,
35 +} from "../pullRequest/pullRequestList.logic";
36 +import type { ComposerCommandItem } from "./ComposerCommandMenu";
37 +import {
38 + searchSlashCommandItems,
39 + slashCommandItemsForPromptPosition,
40 +} from "./composerSlashCommandSearch";
41 +
42 +const COMPOSER_PULL_REQUEST_LIST_LIMIT = 99;
43 +const COMPOSER_PULL_REQUEST_RESULT_LIMIT = 12;
44 +const EMPTY_PULL_REQUEST_LIST_TARGETS: ReadonlyArray<EnvironmentQueryTarget<PullRequestListInput>> =
45 + [];
46 +
47 +/** Builds the @, /, $ and # suggestion lists, running the searches each trigger needs. */
48 +export function useComposerMenuItems({
49 + composerTrigger,
50 + environmentId,
51 + gitCwd,
52 + activeThreadId,
53 + pullRequestProjectId,
54 + pullRequestRepository,
55 + threadPullRequests,
56 + planModeUiEnabled,
57 + compactSlashCommandAvailable,
58 + selectedProvider,
59 + selectedProviderSkills,
60 + selectedProviderSlashCommands,
61 + showSkillsInSlashMenu,
62 +}: {
63 + readonly composerTrigger: ComposerTrigger | null;
64 + readonly environmentId: EnvironmentId;
65 + readonly gitCwd: string | null;
66 + readonly activeThreadId: ThreadId | null;
67 + readonly pullRequestProjectId: ProjectId | null;
68 + readonly pullRequestRepository: string | null;
69 + readonly threadPullRequests: ReadonlyArray<ThreadPullRequestLink> | undefined;
70 + readonly planModeUiEnabled: boolean;
71 + readonly compactSlashCommandAvailable: boolean;
72 + readonly selectedProvider: ProviderDriverKind;
73 + readonly selectedProviderSkills: ServerProvider["skills"];
74 + readonly selectedProviderSlashCommands: ServerProvider["slashCommands"];
75 + readonly showSkillsInSlashMenu: boolean;
76 +}) {
77 + const composerTriggerKind = composerTrigger?.kind ?? null;
78 + const pathTriggerQuery = composerTrigger?.kind === "path" ? composerTrigger.query : "";
79 + const pullRequestTriggerQuery =
80 + composerTrigger?.kind === "pull-request" ? composerTrigger.query : "";
81 + const pullRequestTextQuery =
82 + composerTriggerKind === "pull-request" &&
83 + pullRequestTriggerQuery.length > 0 &&
84 + !/^\d+$/u.test(pullRequestTriggerQuery)
85 + ? pullRequestTriggerQuery
86 + : null;
87 + const debouncedPullRequestTextQuery = useDebouncedValue(pullRequestTextQuery, 180);
88 + const settledPullRequestTextQuery =
89 + pullRequestTextQuery === debouncedPullRequestTextQuery ? pullRequestTextQuery : null;
90 + const isPathTrigger = composerTriggerKind === "path";
91 + const environmentThreadShells = useThreadShells(isPathTrigger);
92 + const workspaceEntries = useComposerPathSearch({
93 + environmentId,
94 + cwd: isPathTrigger ? gitCwd : null,
95 + query: isPathTrigger ? pathTriggerQuery : null,
96 + });
97 +
98 + const pullRequestListTargets =
99 + composerTriggerKind !== "pull-request" ||
100 + pullRequestProjectId === null ||
101 + (pullRequestTextQuery !== null && settledPullRequestTextQuery === null)
102 + ? EMPTY_PULL_REQUEST_LIST_TARGETS
103 + : [
104 + {
105 + environmentId,
106 + input: {
107 + state: "all" as const,
108 + projectId: pullRequestProjectId,
109 + limit: COMPOSER_PULL_REQUEST_LIST_LIMIT,
110 + ...(settledPullRequestTextQuery === null
111 + ? {}
112 + : { query: settledPullRequestTextQuery }),
113 + },
114 + },
115 + ];
116 + const pullRequestLookup = usePullRequestList(pullRequestListTargets);
117 + const pullRequestTriggerNumber = (() => {
118 + if (composerTrigger?.kind !== "pull-request" || composerTrigger.query.length === 0) {
119 + return null;
120 + }
121 + const number = Number(composerTrigger.query);
122 + return Number.isSafeInteger(number) && number > 0 ? number : null;
123 + })();
124 + const debouncedPullRequestNumber = useDebouncedValue(pullRequestTriggerNumber, 180);
125 + const settledPullRequestNumber =
126 + pullRequestTriggerNumber === debouncedPullRequestNumber ? pullRequestTriggerNumber : null;
127 + const recentHasExactPullRequest =
128 + settledPullRequestNumber !== null &&
129 + pullRequestLookup.data?.entries.some(
130 + (entry) =>
131 + entry.projectId === pullRequestProjectId &&
132 + entry.repository.trim().toLowerCase() === pullRequestRepository?.trim().toLowerCase() &&
133 + entry.number === settledPullRequestNumber,
134 + ) === true;
135 + const exactPullRequestLookup = useEnvironmentQuery(
136 + settledPullRequestNumber === null ||
137 + pullRequestProjectId === null ||
138 + pullRequestRepository === null ||
139 + recentHasExactPullRequest
140 + ? null
141 + : pullRequestEnvironment.detail({
142 + environmentId,
143 + input: {
144 + projectId: pullRequestProjectId,
145 + repository: pullRequestRepository,
146 + number: settledPullRequestNumber,
147 + },
148 + }),
149 + );
150 +
151 + const linkedPullRequests =
152 + pullRequestProjectId === null
153 + ? []
154 + : composerPullRequestsFromLinks(threadPullRequests ?? [], pullRequestProjectId);
155 +
156 + const items = ((): ComposerCommandItem[] => {
157 + if (!composerTrigger) return [];
158 + if (composerTrigger.kind === "path") {
159 + return [
160 + ...matchComposerThreadItems({
161 + shells: environmentThreadShells,
162 + environmentId,
163 + excludeThreadId: activeThreadId,
164 + query: composerTrigger.query,
165 + }),
166 + ...workspaceEntries.entries.map((entry) => ({
167 + id: `path:${entry.kind}:${entry.path}`,
168 + type: "path" as const,
169 + path: entry.path,
170 + pathKind: entry.kind,
171 + searchTarget: workspaceEntries.searchedTarget,
172 + label: basenameOfPath(entry.path),
173 + description: entry.path.slice(0, Math.max(0, entry.path.lastIndexOf("/"))),
174 + })),
175 + ];
176 + }
177 + if (composerTrigger.kind === "slash-command") {
178 + const builtInSlashCommandItems = [
179 + {
180 + id: "slash:model",
181 + type: "slash-command",
182 + command: "model",
183 + label: "/model",
184 + description: "Switch response model for this thread",
185 + },
186 + ...(planModeUiEnabled
187 + ? ([
188 + {
189 + id: "slash:plan",
190 + type: "slash-command",
191 + command: "plan",
192 + label: "/plan",
193 + description: "Switch this thread into plan mode",
194 + },
195 + {
196 + id: "slash:default",
197 + type: "slash-command",
198 + command: "default",
199 + label: "/default",
200 + description: "Switch this thread back to normal build mode",
201 + },
202 + ] as const)
203 + : []),
204 + ] satisfies ReadonlyArray<Extract<ComposerCommandItem, { type: "slash-command" }>>;
205 + const slashMenuSkills = getProviderSkillsForSlashMenu(
206 + selectedProviderSkills,
207 + showSkillsInSlashMenu,
208 + );
209 + const providerSlashCommandItems = getProviderSlashCommandsForSlashMenu(
210 + selectedProviderSlashCommands,
211 + slashMenuSkills,
212 + ).map((command) => ({
213 + id: `provider-slash-command:${selectedProvider}:${command.name}`,
214 + type: "provider-slash-command" as const,
215 + provider: selectedProvider,
216 + command,
217 + label: `/${command.name}`,
218 + description: command.description ?? command.input?.hint ?? "Run provider command",
219 + }));
220 + const query = composerTrigger.query.trim().toLowerCase();
221 + const skillItems = slashMenuSkills.map((skill) => ({
222 + id: `skill:${selectedProvider}:${skill.name}`,
223 + type: "skill" as const,
224 + provider: selectedProvider,
225 + skill,
226 + label: `/skill:${skill.name}`,
227 + description:
228 + skill.shortDescription ??
229 + skill.description ??
230 + (skill.scope ? `${skill.scope} skill` : ""),
231 + }));
232 + const visibleProviderSlashCommandItems = providerSlashCommandItems.filter(
233 + (item) => item.command.name !== "compact" || compactSlashCommandAvailable,
234 + );
235 + const slashCommandItems = slashCommandItemsForPromptPosition(
236 + [...builtInSlashCommandItems, ...visibleProviderSlashCommandItems, ...skillItems],
237 + composerTrigger.rangeStart === 0,
238 + );
239 + return searchSlashCommandItems(slashCommandItems, query);
240 + }
241 + if (composerTrigger.kind === "skill") {
242 + return searchProviderSkills(selectedProviderSkills, composerTrigger.query).map((skill) => ({
243 + id: `skill:${selectedProvider}:${skill.name}`,
244 + type: "skill" as const,
245 + provider: selectedProvider,
246 + skill,
247 + label: formatProviderSkillDisplayName(skill),
248 + description:
249 + skill.shortDescription ??
250 + skill.description ??
251 + (skill.scope ? `${skill.scope} skill` : "Run provider skill"),
252 + }));
253 + }
254 + if (
255 + composerTrigger.kind === "pull-request" &&
256 + pullRequestProjectId !== null &&
257 + pullRequestRepository !== null
258 + ) {
259 + const exactPullRequest =
260 + exactPullRequestLookup.data?.number === pullRequestTriggerNumber
261 + ? [exactPullRequestLookup.data]
262 + : [];
263 + const matches = /^\d*$/u.test(composerTrigger.query)
264 + ? filterComposerPullRequestMatches({
265 + entries: [...exactPullRequest, ...(pullRequestLookup.data?.entries ?? [])],
266 + linked: linkedPullRequests,
267 + projectId: pullRequestProjectId,
268 + repository: pullRequestRepository,
269 + query: composerTrigger.query,
270 + limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
271 + })
272 + : rankPullRequestMatches(
273 + (pullRequestLookup.data?.entries ?? []).filter((entry) => {
274 + if (
275 + entry.projectId !== pullRequestProjectId ||
276 + entry.repository.trim().toLowerCase() !== pullRequestRepository.trim().toLowerCase()
277 + ) {
278 + return false;
279 + }
280 + const provider = pullRequestLookup.data?.providers.find(
281 + (candidate) => candidate.host === entry.host,
282 + );
283 + return (
284 + provider?.searchesOnHost === true ||
285 + matchesPullRequestQuery(entry, composerTrigger.query)
286 + );
287 + }),
288 + composerTrigger.query,
289 + ).slice(0, COMPOSER_PULL_REQUEST_RESULT_LIMIT);
290 + return matches.map((pullRequest) => ({
291 + id: `pull-request:${pullRequest.projectId}:${pullRequest.repository}:${pullRequest.number}`,
292 + type: "pull-request",
293 + pullRequest: {
294 + number: pullRequest.number,
295 + title: pullRequest.title,
296 + url: pullRequest.url,
297 + headBranch: pullRequest.headBranch,
298 + baseBranch: pullRequest.baseBranch,
299 + state: pullRequest.state,
300 + isDraft: pullRequest.isDraft,
301 + },
302 + label: `#${pullRequest.number}`,
303 + description:
304 + pullRequest.repository.trim().toLowerCase() === pullRequestRepository.trim().toLowerCase()
305 + ? pullRequest.title
306 + : `${pullRequest.repository} · ${pullRequest.title}`,
307 + }));
308 + }
309 + return [];
310 + })();
311 + const isLoading =
312 + (composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending) ||
313 + (composerTriggerKind === "pull-request" &&
314 + pullRequestProjectId !== null &&
315 + pullRequestRepository !== null &&
316 + (pullRequestLookup.isPending ||
317 + pullRequestTextQuery !== debouncedPullRequestTextQuery ||
318 + pullRequestTriggerNumber !== debouncedPullRequestNumber ||
319 + exactPullRequestLookup.isPending));
320 + const emptyState = (() => {
321 + if (composerTriggerKind === "skill") {
322 + return "No skills found. Try / to browse provider commands.";
323 + }
324 + if (composerTriggerKind === "pull-request") {
325 + if (pullRequestProjectId === null || pullRequestRepository === null) {
326 + return "Pull requests are not available for this project.";
327 + }
328 + if (
329 + pullRequestLookup.error !== null ||
330 + pullRequestLookup.data?.errors.some((error) => error.projectId === pullRequestProjectId)
331 + ) {
332 + return "Pull requests could not be read for this project.";
333 + }
334 + return composerTrigger?.query
335 + ? `No pull request matches ${composerTrigger.query}.`
336 + : "No pull requests found in this repository.";
337 + }
338 + return composerTriggerKind === "path"
339 + ? "No matching files or folders."
340 + : "No matching command.";
341 + })();
342 +
343 + return { items, isLoading, emptyState };
344 +}