mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(session): surface background shell and subagent work (#360)
* feat(session): surface background shell and subagent work * fix(session): address review feedback on background work UI
This commit is contained in:
1 parent
8b806e865f
commit
1389e8e59c
20 files changed
+802
-13
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { listShells, removeShell, type ShellInfo } from '@/api/opencode'
|
||||
import { shellsQueryKey } from '@/lib/queryInvalidation'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
export function useSessionShells(sessionID: string | undefined, directory: string | undefined) {
|
||||
const query = useQuery({
|
||||
queryKey: shellsQueryKey(directory),
|
||||
queryFn: () => listShells(directory ?? ''),
|
||||
enabled: Boolean(directory),
|
||||
staleTime: Infinity,
|
||||
})
|
||||
|
||||
const shells = useMemo(
|
||||
() =>
|
||||
(query.data ?? []).filter(
|
||||
(shell) => shell.status === 'running' && shell.metadata.sessionID === sessionID,
|
||||
),
|
||||
[query.data, sessionID],
|
||||
)
|
||||
|
||||
return shells
|
||||
}
|
||||
|
||||
export function useKillShell(directory: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => removeShell(id, directory ?? ''),
|
||||
onSuccess: (_result, id) => {
|
||||
queryClient.setQueryData<ShellInfo[]>(shellsQueryKey(directory), (current) =>
|
||||
current?.filter((shell) => shell.id !== id),
|
||||
)
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to kill shell command')
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user