@@ -7,13 +7,22 @@ import type {
77 ThreadId ,
88 ThreadPullRequestLink ,
99} from "@t3tools/contracts" ;
10- import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems" ;
10+ import {
11+ type ComposerEnvironmentCandidate ,
12+ matchComposerEnvironmentItems ,
13+ matchComposerThreadItems ,
14+ } from "@t3tools/client-runtime/composerThreadItems" ;
1115import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models" ;
1216
1317const EMPTY_THREAD_SHELLS : ReadonlyArray < EnvironmentThreadShell > = [ ] ;
18+ const EMPTY_ENVIRONMENTS : ReadonlyArray < ComposerEnvironmentCandidate > = [ ] ;
1419import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts" ;
1520import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences" ;
16- import { pullRequestComposerContext , threadComposerContext } from "../../lib/composerContext" ;
21+ import {
22+ environmentComposerContext ,
23+ pullRequestComposerContext ,
24+ threadComposerContext ,
25+ } from "../../lib/composerContext" ;
1726import { uuidv4 } from "../../lib/uuid" ;
1827import {
1928 getComposerDraftSnapshot ,
@@ -201,6 +210,7 @@ export function useComposerCommandMenu({
201210 ownerKey,
202211 environmentId,
203212 threadShells = EMPTY_THREAD_SHELLS ,
213+ environments = EMPTY_ENVIRONMENTS ,
204214 currentThreadId = null ,
205215 projectCwd,
206216 pullRequestProjectId = null ,
@@ -219,6 +229,7 @@ export function useComposerCommandMenu({
219229 readonly ownerKey : string | null ;
220230 readonly environmentId : EnvironmentId | null ;
221231 readonly threadShells ?: ReadonlyArray < EnvironmentThreadShell > ;
232+ readonly environments ?: ReadonlyArray < ComposerEnvironmentCandidate > ;
222233 readonly currentThreadId ?: ThreadId | null ;
223234 readonly projectCwd : string | null ;
224235 readonly pullRequestProjectId ?: ProjectId | null ;
@@ -452,8 +463,12 @@ export function useComposerCommandMenu({
452463 now,
453464 } )
454465 : [ ] ;
466+ const environmentItems = environmentId
467+ ? matchComposerEnvironmentItems ( { environments, environmentId, query : trigger . query } )
468+ : [ ] ;
455469 return [
456470 ...threadItems ,
471+ ...environmentItems ,
457472 ...pathSearch . entries . map ( ( entry ) => {
458473 const parts = entry . path . split ( "/" ) ;
459474 return {
@@ -473,6 +488,32 @@ export function useComposerCommandMenu({
473488
474489 const onSelect = ( item : ComposerCommandItem ) => {
475490 if ( ! trigger ) return ;
491+ if ( item . type === "environment" ) {
492+ if ( ! ownerKey || trigger . kind !== "path" ) return ;
493+ const record = environmentComposerContext ( item . environmentId , item . label ) ;
494+ const existing = getComposerDraftSnapshot ( ownerKey ) . context ?. records ?? [ ] ;
495+ const alreadyAttached = existing . some ( ( entry ) => entry . contextId === record . contextId ) ;
496+ if ( ! alreadyAttached && existing . length >= COMPOSER_CONTEXT_MAX_RECORDS ) {
497+ Dialog . alert ( "Too many context items" , "Remove some context from the draft and try again." ) ;
498+ return ;
499+ }
500+ const result = replaceTextRange (
501+ draftMessage ,
502+ trigger . rangeStart ,
503+ trigger . rangeEnd ,
504+ `${ formatComposerContextReference ( record ) } ` ,
505+ ) ;
506+ onChangeDraftMessage ( result . text ) ;
507+ if ( ! alreadyAttached ) {
508+ const draft = getComposerDraftSnapshot ( ownerKey ) ;
509+ setComposerDraftContext ( ownerKey , {
510+ version : 1 ,
511+ records : [ ...( draft . context ?. records ?? [ ] ) , record ] ,
512+ } ) ;
513+ }
514+ setSelection ( { start : result . cursor , end : result . cursor } ) ;
515+ return ;
516+ }
476517 if ( item . type === "thread" ) {
477518 if ( ! ownerKey || trigger . kind !== "path" ) return ;
478519 const shell = threadShells . find (
0 commit comments