@@ -8,14 +8,18 @@ import type {
88 ThreadId ,
99} from "@t3tools/contracts" ;
1010import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems" ;
11- import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models" ;
11+ import type {
12+ EnvironmentProject ,
13+ EnvironmentThreadShell ,
14+ } from "@t3tools/client-runtime/state/models" ;
1215import { deriveThreadAgentFleet } from "@t3tools/client-runtime/state/agent-fleet" ;
1316import {
1417 matchesSubagentQuery ,
1518 subagentContextRecord ,
1619} from "@t3tools/client-runtime/state/subagent-handles" ;
1720
1821const EMPTY_THREAD_SHELLS : ReadonlyArray < EnvironmentThreadShell > = [ ] ;
22+ const EMPTY_PROJECTS : ReadonlyArray < EnvironmentProject > = [ ] ;
1923const EMPTY_SUBAGENTS : ReadonlyArray < OrchestrationV2Subagent > = [ ] ;
2024const EMPTY_PROVIDERS : ReadonlyArray < ServerProvider > = [ ] ;
2125import {
@@ -184,6 +188,7 @@ export function useComposerCommandMenu({
184188 ownerKey,
185189 environmentId,
186190 threadShells = EMPTY_THREAD_SHELLS ,
191+ projects = EMPTY_PROJECTS ,
187192 currentThreadId = null ,
188193 threadSubagents = EMPTY_SUBAGENTS ,
189194 providers = EMPTY_PROVIDERS ,
@@ -204,6 +209,8 @@ export function useComposerCommandMenu({
204209 readonly environmentId : EnvironmentId | null ;
205210 /** Candidates for `@` thread suggestions; the caller reads them from the entity store. */
206211 readonly threadShells ?: ReadonlyArray < EnvironmentThreadShell > ;
212+ /** Names the project beside each `@` thread suggestion. */
213+ readonly projects ?: ReadonlyArray < EnvironmentProject > ;
207214 /** Left out of `@` thread suggestions: a thread is never context for itself. */
208215 readonly currentThreadId ?: ThreadId | null ;
209216 /** The current thread's subagent records, for the `@` menu's Agents tab. */
@@ -381,27 +388,54 @@ export function useComposerCommandMenu({
381388 . map ( ( shell ) => shell . source ) ,
382389 } ) . filter ( ( entry ) => entry . subagent !== null ) ;
383390 } , [ currentThreadId , environmentId , pathTriggerOpen , threadShells , threadSubagents ] ) ;
384- // The tab the user picked for this `@`; otherwise Agents when the query starts a handle.
391+ const chatItems = useMemo (
392+ ( ) =>
393+ trigger ?. kind === "path" && environmentId
394+ ? matchComposerThreadItems ( {
395+ shells : threadShells ,
396+ environmentId,
397+ excludeThreadId : currentThreadId ,
398+ query : trigger . query ,
399+ projectTitles : new Map (
400+ projects
401+ . filter ( ( project ) => project . environmentId === environmentId )
402+ . map ( ( project ) => [ project . id , project . title ] ) ,
403+ ) ,
404+ } )
405+ : [ ] ,
406+ [ currentThreadId , environmentId , projects , threadShells , trigger ] ,
407+ ) ;
408+ // The tab the user picked for this `@`; otherwise Agents when the query starts a handle,
409+ // Chats when only chats match, else Files.
385410 const [ pathTabChoice , setPathTabChoice ] = useState < {
386411 readonly rangeStart : number ;
387412 readonly tab : ComposerPathTab ;
388413 } | null > ( null ) ;
389414 const pathTab = useMemo ( ( ) => {
390- if ( trigger ?. kind !== "path" || agentFleet . length === 0 ) return null ;
415+ if ( trigger ?. kind !== "path" ) return null ;
391416 const needle = trigger . query . trim ( ) . toLowerCase ( ) ;
417+ const showAgents = agentFleet . length > 0 ;
392418 const prefersAgents =
393419 needle . length > 0 && agentFleet . some ( ( entry ) => entry . handle . startsWith ( needle ) ) ;
420+ const prefersChats =
421+ needle . length > 0 &&
422+ chatItems . length > 0 &&
423+ ! pathSearch . isPending &&
424+ pathSearch . entries . length === 0 ;
394425 const rangeStart = trigger . rangeStart ;
395426 return {
396427 active :
397- pathTabChoice ?. rangeStart === rangeStart
428+ pathTabChoice ?. rangeStart === rangeStart && ( pathTabChoice . tab !== "agents" || showAgents )
398429 ? pathTabChoice . tab
399430 : prefersAgents
400431 ? ( "agents" as const )
401- : ( "files" as const ) ,
432+ : prefersChats
433+ ? ( "chats" as const )
434+ : ( "files" as const ) ,
435+ showAgents,
402436 onChange : ( tab : ComposerPathTab ) => setPathTabChoice ( { rangeStart, tab } ) ,
403437 } ;
404- } , [ agentFleet , pathTabChoice , trigger ] ) ;
438+ } , [ agentFleet , chatItems , pathSearch . entries , pathSearch . isPending , pathTabChoice , trigger ] ) ;
405439 const pullRequestSearch = useComposerPullRequestSearch ( {
406440 environmentId,
407441 projectId : pullRequestProjectId ,
@@ -560,39 +594,28 @@ export function useComposerCommandMenu({
560594 } ) ) ;
561595 }
562596
597+ if ( trigger . kind === "path" && pathTab ?. active === "chats" ) return chatItems ;
598+
563599 if ( trigger . kind === "path" ) {
564- const threadItems = environmentId
565- ? matchComposerThreadItems ( {
566- shells : threadShells ,
567- environmentId,
568- excludeThreadId : currentThreadId ,
569- query : trigger . query ,
570- } )
571- : [ ] ;
572- return [
573- ...threadItems ,
574- ...pathSearch . entries . map ( ( entry ) => {
575- const parts = entry . path . split ( "/" ) ;
576- return {
577- id : `path:${ entry . path } ` ,
578- type : "path" as const ,
579- path : entry . path ,
580- kind : entry . kind ,
581- label : parts [ parts . length - 1 ] ?? entry . path ,
582- description : parts . length > 1 ? parts . slice ( 0 , - 1 ) . join ( "/" ) : "" ,
583- } ;
584- } ) ,
585- ] ;
600+ return pathSearch . entries . map ( ( entry ) => {
601+ const parts = entry . path . split ( "/" ) ;
602+ return {
603+ id : `path:${ entry . path } ` ,
604+ type : "path" as const ,
605+ path : entry . path ,
606+ kind : entry . kind ,
607+ label : parts [ parts . length - 1 ] ?? entry . path ,
608+ description : parts . length > 1 ? parts . slice ( 0 , - 1 ) . join ( "/" ) : "" ,
609+ } ;
610+ } ) ;
586611 }
587612
588613 return [ ] ;
589614 } , [
590615 agentFleet ,
591- currentThreadId ,
592- environmentId ,
616+ chatItems ,
593617 pathTab ?. active ,
594618 providers ,
595- threadShells ,
596619 hasThread ,
597620 hasCompactableConversation ,
598621 onUpdateInteractionMode ,
@@ -746,7 +769,7 @@ export function useComposerCommandMenu({
746769 isLoading :
747770 trigger ?. kind === "pull-request"
748771 ? pullRequestSearch . isPending
749- : pathTab ? .active !== "agents" && pathSearch . isPending ,
772+ : ( pathTab === null || pathTab . active === "files" ) && pathSearch . isPending ,
750773 error :
751774 trigger ?. kind === "pull-request"
752775 ? pullRequestProjectId === null || pullRequestRepository === null
0 commit comments