mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Merge forge/terminal-dev-loop into beta
feat: integrated terminal, project actions and dev server preview (OM-17, OM-18, OM-19) Integration with #380 and #379: - Adopt the git-config identity model: drop the branch's identity stubs (getShellEnv, getAssignedGitIdentityEnv, repo identity ids, duplicate createGitService and getMainCheckoutPath); terminals receive only the GitHub token env and take their commit identity from git config. - Add RepoWorkspaceService as the single owner of OpenCode workspace side effects: worktree setup commands on create and terminal cleanup on remove, used by the workspace routes, the session launcher (ocm tool and multi-run) and multi-run discard, with one worktree-sibling matcher. - Run repo-delete terminal cleanup inside the worktree branch deletion flow. - Combine the CreateWorktreeDialog tests and update docs for the identity model and setup command coverage.
This commit is contained in:
commit
b13707b5b3
135 files changed
+12726
-492
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import type { CreatePreviewSessionResponse, PreviewPortsResponse } from '@opencode-manager/shared/types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
|
||||
function previewPortsQueryKey(directory: string | undefined) {
|
||||
return ['previewPorts', directory ?? null] as const
|
||||
}
|
||||
|
||||
function listPreviewPorts(directory?: string): Promise<PreviewPortsResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/preview/ports`, {
|
||||
params: { directory },
|
||||
})
|
||||
}
|
||||
|
||||
export function createPreviewSession(port: number): Promise<CreatePreviewSessionResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/preview/sessions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ port }),
|
||||
})
|
||||
}
|
||||
|
||||
export interface UsePreviewPortsOptions {
|
||||
enabled: boolean
|
||||
refetchInterval?: number | false
|
||||
}
|
||||
|
||||
export function usePreviewPorts(directory: string | undefined, options: UsePreviewPortsOptions) {
|
||||
return useQuery({
|
||||
queryKey: previewPortsQueryKey(directory),
|
||||
queryFn: () => listPreviewPorts(directory),
|
||||
enabled: options.enabled,
|
||||
refetchInterval: options.refetchInterval,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type {
|
||||
MoveProjectItemRequest,
|
||||
ProjectAction,
|
||||
ProjectConfigResponse,
|
||||
RunProjectActionResponse,
|
||||
TrustRepoConfigRequest,
|
||||
} from '@opencode-manager/shared/types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
|
||||
function projectConfigQueryKey(repoId: number, directory: string | undefined) {
|
||||
return ['projectConfig', repoId, directory ?? null] as const
|
||||
}
|
||||
|
||||
export function getProjectConfig(repoId: number, directory?: string): Promise<ProjectConfigResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config`, {
|
||||
params: { directory },
|
||||
})
|
||||
}
|
||||
|
||||
function updateProjectActions(
|
||||
repoId: number,
|
||||
actions: ProjectAction[],
|
||||
directory?: string,
|
||||
): Promise<ProjectConfigResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/actions`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ actions }),
|
||||
params: { directory },
|
||||
})
|
||||
}
|
||||
|
||||
function updateWorktreeSetup(
|
||||
repoId: number,
|
||||
commands: string[],
|
||||
directory?: string,
|
||||
): Promise<ProjectConfigResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/worktree-setup`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ commands }),
|
||||
params: { directory },
|
||||
})
|
||||
}
|
||||
|
||||
function trustRepoConfig(repoId: number, request: TrustRepoConfigRequest): Promise<ProjectConfigResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/trust`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
}
|
||||
|
||||
function moveProjectItem(repoId: number, request: MoveProjectItemRequest): Promise<ProjectConfigResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/move`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
}
|
||||
|
||||
function runProjectAction(
|
||||
repoId: number,
|
||||
actionId: string,
|
||||
directory?: string,
|
||||
): Promise<RunProjectActionResponse> {
|
||||
return fetchWrapper(
|
||||
`${API_BASE_URL}/api/repos/${repoId}/project-config/actions/${encodeURIComponent(actionId)}/run`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory }),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export function useProjectConfig(repoId: number, directory: string | undefined, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: projectConfigQueryKey(repoId, directory),
|
||||
queryFn: () => getProjectConfig(repoId, directory),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateProjectActions(repoId: number, directory: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (actions: ProjectAction[]) => updateProjectActions(repoId, actions, directory),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateWorktreeSetup(repoId: number, directory: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (commands: string[]) => updateWorktreeSetup(repoId, commands, directory),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useTrustRepoConfig(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (request: TrustRepoConfigRequest) => trustRepoConfig(repoId, request),
|
||||
onSuccess: (_data, request) => {
|
||||
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, request.directory) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useMoveProjectItem(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (request: MoveProjectItemRequest) => moveProjectItem(repoId, request),
|
||||
onSuccess: (_data, request) => {
|
||||
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, request.directory) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useRunProjectAction(repoId: number, directory: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (actionId: string) => runProjectAction(repoId, actionId, directory),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
|
||||
queryClient.invalidateQueries({ queryKey: ['terminals', repoId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { Repo } from './types'
|
||||
import { FetchError, fetchWrapper, fetchWrapperVoid, fetchWrapperBlob } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { saveFile } from '@/lib/download'
|
||||
import type { DiscoverReposResponse, AssistantModeStatus, AssistantModeInitRequest, DeleteRepoRequest, DeleteRepoResult, RepoGitIdentity } from '@opencode-manager/shared/types'
|
||||
import type { DiscoverReposResponse, AssistantModeStatus, AssistantModeInitRequest, DeleteRepoRequest, DeleteRepoResult, RepoGitIdentity, WorktreeSetupResult } from '@opencode-manager/shared/types'
|
||||
|
||||
export interface CreateRepoOptions {
|
||||
repoUrl?: string
|
||||
@@ -63,7 +63,7 @@ export async function deleteRepoWorkspace(repoId: number, directory: string): Pr
|
||||
})
|
||||
}
|
||||
|
||||
export async function createRepoWorkspace(repoId: number): Promise<RepoWorktree> {
|
||||
export async function createRepoWorkspace(repoId: number): Promise<RepoWorktree & { worktreeSetup?: WorktreeSetupResult }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/workspaces`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { CreateTerminalRequest, ResizeTerminalRequest, TerminalInfo } from '@opencode-manager/shared/types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
|
||||
|
||||
function terminalsQueryKey(repoId: number, directory: string | undefined) {
|
||||
return ['terminals', repoId, directory ?? null] as const
|
||||
}
|
||||
|
||||
function terminalsRepoQueryKey(repoId: number) {
|
||||
return ['terminals', repoId] as const
|
||||
}
|
||||
|
||||
async function listTerminals(repoId: number, directory?: string): Promise<TerminalInfo[]> {
|
||||
const data = await fetchWrapper<{ terminals: TerminalInfo[] }>(
|
||||
`${API_BASE_URL}/api/repos/${repoId}/terminals`,
|
||||
{ params: { directory } },
|
||||
)
|
||||
return data.terminals
|
||||
}
|
||||
|
||||
async function createTerminal(repoId: number, body: CreateTerminalRequest): Promise<TerminalInfo> {
|
||||
return fetchWrapper<TerminalInfo>(`${API_BASE_URL}/api/repos/${repoId}/terminals`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
export async function resizeTerminal(repoId: number, ptyID: string, body: ResizeTerminalRequest): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/terminals/${encodeURIComponent(ptyID)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
async function removeTerminal(repoId: number, ptyID: string, directory?: string): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/terminals/${encodeURIComponent(ptyID)}`, {
|
||||
method: 'DELETE',
|
||||
params: { directory },
|
||||
})
|
||||
}
|
||||
|
||||
interface UseTerminalsOptions {
|
||||
enabled: boolean
|
||||
refetchInterval?: number | false
|
||||
}
|
||||
|
||||
export function useTerminals(repoId: number, directory: string | undefined, options: UseTerminalsOptions) {
|
||||
return useQuery({
|
||||
queryKey: terminalsQueryKey(repoId, directory),
|
||||
queryFn: () => listTerminals(repoId, directory),
|
||||
enabled: options.enabled,
|
||||
refetchInterval: options.refetchInterval,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateTerminal(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: CreateTerminalRequest) => createTerminal(repoId, body),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: terminalsRepoQueryKey(repoId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
interface RemoveTerminalVariables {
|
||||
ptyID: string
|
||||
directory?: string
|
||||
}
|
||||
|
||||
export function useRemoveTerminal(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ ptyID, directory }: RemoveTerminalVariables) => removeTerminal(repoId, ptyID, directory),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: terminalsRepoQueryKey(repoId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import type { SessionInfo } from '@opencode-manager/shared/opencode'
|
||||
import type { WorktreeSetupResult } from '@opencode-manager/shared/types'
|
||||
|
||||
export interface Repo {
|
||||
id: number
|
||||
name?: string
|
||||
@@ -15,10 +18,9 @@ export interface Repo {
|
||||
gitCredentialId?: string
|
||||
isWorktree?: boolean
|
||||
isLocal?: boolean
|
||||
worktreeSetup?: WorktreeSetupResult
|
||||
}
|
||||
|
||||
import type { SessionInfo } from '@opencode-manager/shared/opencode'
|
||||
|
||||
export type Session = SessionInfo
|
||||
export type PermissionResponse = 'once' | 'always' | 'reject'
|
||||
|
||||
|
||||
Reference in new issue
Block a user