@@ -32,6 +32,7 @@ import {
3232} from "@t3tools/client-runtime/environment" ;
3333import type {
3434 EnvironmentId ,
35+ ScopedProjectRef ,
3536 ScopedThreadRef ,
3637 SidebarProjectGroupingMode ,
3738 SidebarThreadGroupingAxis ,
@@ -97,6 +98,7 @@ import { isModelPickerOpen } from "../modelPickerVisibility";
9798import { selectThreadTerminalUiState , useTerminalUiStateStore } from "../terminalUiStateStore" ;
9899import { isMacPlatform } from "~/lib/utils" ;
99100import { useOpenPrLink } from "../lib/openPullRequestLink" ;
101+ import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors" ;
100102import { readLocalApi } from "../localApi" ;
101103import { getProjectOrderKey , selectProjectGroupingSettings } from "../logicalProject" ;
102104import {
@@ -117,6 +119,7 @@ import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments"
117119import { useProjects , useThreadShells } from "../state/entities" ;
118120import { environmentServerConfigsAtom , primaryServerKeybindingsAtom } from "../state/server" ;
119121import { vcsEnvironment } from "../state/vcs" ;
122+ import { projectEnvironment } from "../state/projects" ;
120123import { threadEnvironment } from "../state/threads" ;
121124import { useEnvironmentQuery } from "../state/query" ;
122125import { useAtomCommand } from "../state/use-atom-command" ;
@@ -1957,6 +1960,9 @@ export default function Sidebar() {
19571960 archiveThread,
19581961 deleteThread,
19591962 } = useThreadActions ( ) ;
1963+ const deleteProject = useAtomCommand ( projectEnvironment . delete , {
1964+ reportFailure : false ,
1965+ } ) ;
19601966 const updateThreadMetadata = useAtomCommand ( threadEnvironment . updateMetadata , {
19611967 reportFailure : false ,
19621968 } ) ;
@@ -2202,10 +2208,93 @@ export default function Sidebar() {
22022208 }
22032209 return count ;
22042210 } ) ;
2205- const handleProjectSettings = useCallback (
2206- ( event : ReactMouseEvent < HTMLButtonElement > , projectGroup : SidebarProjectSnapshot ) => {
2207- event . preventDefault ( ) ;
2208- event . stopPropagation ( ) ;
2211+ // Removing a project is the one destructive thing a section header can do,
2212+ // so it never sits next to New thread as a click target: it lives in the
2213+ // header's context menu, the same gesture threads already use for Delete.
2214+ //
2215+ // Ported from LegacySidebar, which is where this action lived while the new
2216+ // sidebar had no project rows to hang it on.
2217+ const handleRemoveProject = useCallback (
2218+ async ( projectGroup : SidebarProjectSnapshot , projectRef : ScopedProjectRef , label : string ) => {
2219+ const api = readLocalApi ( ) ;
2220+ if ( ! api ) return ;
2221+ const member =
2222+ projectGroup . memberProjects . find (
2223+ ( candidate ) =>
2224+ candidate . environmentId === projectRef . environmentId &&
2225+ candidate . id === projectRef . projectId ,
2226+ ) ?? null ;
2227+ if ( member === null ) return ;
2228+
2229+ const projectThreads = threads . filter (
2230+ ( thread ) =>
2231+ thread . environmentId === projectRef . environmentId &&
2232+ thread . projectId === projectRef . projectId ,
2233+ ) ;
2234+ const details = [
2235+ `Path: ${ member . workspaceRoot } ` ,
2236+ ...( member . environmentLabel ? [ `Environment: ${ member . environmentLabel } ` ] : [ ] ) ,
2237+ ] ;
2238+ // A project with threads costs its history, so the prompt says how much
2239+ // and the removal has to be forced. An empty one only loses the entry.
2240+ const message =
2241+ projectThreads . length > 0
2242+ ? [
2243+ `Remove project "${ label } " and delete its ${ projectThreads . length } thread${
2244+ projectThreads . length === 1 ? "" : "s"
2245+ } ?`,
2246+ ...details ,
2247+ "This permanently clears conversation history for those threads." ,
2248+ "This removes only this project entry." ,
2249+ "This action cannot be undone." ,
2250+ ] . join ( "\n" )
2251+ : [
2252+ `Remove project "${ label } "?` ,
2253+ ...details ,
2254+ "This removes only this project entry." ,
2255+ ] . join ( "\n" ) ;
2256+ const confirmed = await settlePromise ( ( ) =>
2257+ api . dialogs . confirm ( message , { variant : "destructive" } ) ,
2258+ ) ;
2259+ if ( confirmed . _tag === "Failure" || ! confirmed . value ) return ;
2260+
2261+ const result = await deleteProject ( {
2262+ environmentId : projectRef . environmentId ,
2263+ input : {
2264+ projectId : projectRef . projectId ,
2265+ ...( projectThreads . length > 0 ? { force : true } : { } ) ,
2266+ } ,
2267+ } ) ;
2268+ if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
2269+ const error = squashAtomCommandFailure ( result ) ;
2270+ console . error ( "Failed to remove project" , {
2271+ projectId : projectRef . projectId ,
2272+ environmentId : projectRef . environmentId ,
2273+ ...safeErrorLogAttributes ( error ) ,
2274+ } ) ;
2275+ toastManager . add (
2276+ stackedThreadToast ( {
2277+ type : "error" ,
2278+ title : `Failed to remove "${ label } "` ,
2279+ description : error instanceof Error ? error . message : "Unknown error removing project." ,
2280+ } ) ,
2281+ ) ;
2282+ return ;
2283+ }
2284+ // The draft parked in a project that no longer exists would otherwise
2285+ // keep a row in the sidebar pointing at nothing.
2286+ const draftStore = useComposerDraftStore . getState ( ) ;
2287+ const projectDraftThread = draftStore . getDraftThreadByProjectRef ( projectRef ) ;
2288+ if ( projectDraftThread ) {
2289+ draftStore . clearDraftThread ( projectDraftThread . draftId ) ;
2290+ }
2291+ draftStore . clearProjectDraftThreadId ( projectRef ) ;
2292+ } ,
2293+ [ deleteProject , threads ] ,
2294+ ) ;
2295+
2296+ const handleProjectSettingsGroup = useCallback (
2297+ ( projectGroup : SidebarProjectSnapshot ) => {
22092298 if ( isMobile ) {
22102299 setOpenMobile ( false ) ;
22112300 }
@@ -2216,6 +2305,14 @@ export default function Sidebar() {
22162305 } ,
22172306 [ isMobile , router , setOpenMobile ] ,
22182307 ) ;
2308+ const handleProjectSettings = useCallback (
2309+ ( event : ReactMouseEvent < HTMLButtonElement > , projectGroup : SidebarProjectSnapshot ) => {
2310+ event . preventDefault ( ) ;
2311+ event . stopPropagation ( ) ;
2312+ handleProjectSettingsGroup ( projectGroup ) ;
2313+ } ,
2314+ [ handleProjectSettingsGroup ] ,
2315+ ) ;
22192316
22202317 // Settled threads stay in the live shell stream (settled ≠ archived), so
22212318 // the partition works directly off live shells: no archived-snapshot
@@ -4157,6 +4254,75 @@ export default function Sidebar() {
41574254 /> ,
41584255 ) ;
41594256 }
4257+ /**
4258+ * Right-click on a section header. Same gesture threads use
4259+ * for their own destructive actions, which is why Remove
4260+ * project lives here instead of as a third icon one slip
4261+ * away from New thread.
4262+ */
4263+ const handleGroupContextMenu = async (
4264+ group : ( typeof activeThreadGroups ) [ number ] ,
4265+ position : { readonly x : number ; readonly y : number } ,
4266+ ) => {
4267+ const api = readLocalApi ( ) ;
4268+ if ( ! api ) return ;
4269+ const { environmentId, projectId } = group . target ;
4270+ if ( group . axis === "environment" && environmentId !== null ) {
4271+ const clicked = await settlePromise ( ( ) =>
4272+ api . contextMenu . show (
4273+ [ { id : "new-project" , label : `New project in ${ group . label } ` } ] ,
4274+ position ,
4275+ ) ,
4276+ ) ;
4277+ if ( clicked . _tag === "Failure" || clicked . value !== "new-project" ) {
4278+ return ;
4279+ }
4280+ openAddProjectCommandPalette ( environmentId ) ;
4281+ return ;
4282+ }
4283+ if ( group . axis !== "project" || environmentId === null || projectId === null ) {
4284+ return ;
4285+ }
4286+ const projectRef = scopeProjectRef ( environmentId , projectId ) ;
4287+ const projectGroup =
4288+ projectGroupByProjectKey . get ( `${ environmentId } :${ projectId } ` ) ?? null ;
4289+ const clicked = await settlePromise ( ( ) =>
4290+ api . contextMenu . show (
4291+ [
4292+ { id : "new-thread" , label : "New thread" } ,
4293+ ...( projectGroup === null
4294+ ? [ ]
4295+ : [ { id : "settings" as const , label : "Project settings" } ] ) ,
4296+ ...( projectGroup === null
4297+ ? [ ]
4298+ : [
4299+ {
4300+ id : "remove" as const ,
4301+ label : "Remove project" ,
4302+ destructive : true ,
4303+ } ,
4304+ ] ) ,
4305+ ] ,
4306+ position ,
4307+ ) ,
4308+ ) ;
4309+ if ( clicked . _tag === "Failure" || ! clicked . value ) return ;
4310+ switch ( clicked . value ) {
4311+ case "new-thread" :
4312+ void handleNewThreadRef . current ( projectRef ) ;
4313+ return ;
4314+ case "settings" :
4315+ if ( projectGroup ) {
4316+ void handleProjectSettingsGroup ( projectGroup ) ;
4317+ }
4318+ return ;
4319+ case "remove" :
4320+ if ( projectGroup ) {
4321+ void handleRemoveProject ( projectGroup , projectRef , group . label ) ;
4322+ }
4323+ return ;
4324+ }
4325+ } ;
41604326 // Always visible, not hover-only: these are the way into a
41614327 // project now that the selector is gone, and an action you
41624328 // have to hunt for by hovering is an action most people
@@ -4360,6 +4526,13 @@ export default function Sidebar() {
43604526 < li
43614527 key = { `group-header:${ group . key } ` }
43624528 data-thread-selection-safe
4529+ onContextMenu = { ( event ) => {
4530+ event . preventDefault ( ) ;
4531+ void handleGroupContextMenu ( group , {
4532+ x : event . clientX ,
4533+ y : event . clientY ,
4534+ } ) ;
4535+ } }
43634536 className = { cn (
43644537 "relative flex list-none items-center gap-1 pe-1" ,
43654538 // Top level carries the weight of a shelf header;
0 commit comments