Add local repository support and permission request handling

This commit is contained in:
Chris Scott committed 2025-11-28 10:26:03 -05:00
1 parent 9a2ebc9652
commit 83834e7ed7
22 files changed
+685 -120

No files matched your search

@@ -28,7 +28,7 @@ export function AddBranchWorkspaceDialog({
const mutation = useMutation({
mutationFn: () =>
createRepo(repoUrl, branch || undefined, undefined, useWorktree),
createRepo(repoUrl, undefined, branch || undefined, undefined, useWorktree),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["repos"] });
setBranch("");
+74 -14
View File
@@ -12,23 +12,33 @@ interface AddRepoDialogProps {
}
export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
const [repoType, setRepoType] = useState<'remote' | 'local'>('remote')
const [repoUrl, setRepoUrl] = useState('')
const [localPath, setLocalPath] = useState('')
const [branch, setBranch] = useState('')
const queryClient = useQueryClient()
const mutation = useMutation({
mutationFn: () => createRepo(repoUrl, branch || undefined, undefined, false),
mutationFn: () => {
if (repoType === 'local') {
return createRepo(undefined, localPath, branch || undefined, undefined, false)
} else {
return createRepo(repoUrl, undefined, branch || undefined, undefined, false)
}
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['repos'] })
setRepoUrl('')
setLocalPath('')
setBranch('')
setRepoType('remote')
onOpenChange(false)
},
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
if (repoUrl) {
if ((repoType === 'remote' && repoUrl) || (repoType === 'local' && localPath)) {
mutation.mutate()
}
}
@@ -43,15 +53,61 @@ export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4 mt-4">
<div className="space-y-2">
<label className="text-sm text-zinc-400">Repository URL</label>
<Input
placeholder="https://github.com/user/repo.git"
value={repoUrl}
onChange={(e) => setRepoUrl(e.target.value)}
disabled={mutation.isPending}
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
/>
<label className="text-sm text-zinc-400">Repository Type</label>
<div className="flex gap-4">
<label className="flex items-center space-x-2 cursor-pointer">
<input
type="radio"
name="repoType"
value="remote"
checked={repoType === 'remote'}
onChange={(e) => setRepoType(e.target.value as 'remote')}
disabled={mutation.isPending}
className="text-blue-600 bg-[#1a1a1a] border-[#2a2a2a]"
/>
<span className="text-sm text-white">Remote Repository</span>
</label>
<label className="flex items-center space-x-2 cursor-pointer">
<input
type="radio"
name="repoType"
value="local"
checked={repoType === 'local'}
onChange={(e) => setRepoType(e.target.value as 'local')}
disabled={mutation.isPending}
className="text-blue-600 bg-[#1a1a1a] border-[#2a2a2a]"
/>
<span className="text-sm text-white">Local Repository</span>
</label>
</div>
</div>
{repoType === 'remote' ? (
<div className="space-y-2">
<label className="text-sm text-zinc-400">Repository URL</label>
<Input
placeholder="https://github.com/user/repo.git"
value={repoUrl}
onChange={(e) => setRepoUrl(e.target.value)}
disabled={mutation.isPending}
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
/>
</div>
) : (
<div className="space-y-2">
<label className="text-sm text-zinc-400">Local Path</label>
<Input
placeholder="my-local-project"
value={localPath}
onChange={(e) => setLocalPath(e.target.value)}
disabled={mutation.isPending}
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
/>
<p className="text-xs text-zinc-500">
Directory name will be created in the repos folder
</p>
</div>
)}
<div className="space-y-2">
<label className="text-sm text-zinc-400">Branch</label>
@@ -64,21 +120,25 @@ export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
/>
<p className="text-xs text-zinc-500">
{branch
? `Clones repository directly to '${branch}' branch`
: "Clones repository to default branch"
? repoType === 'remote'
? `Clones repository directly to '${branch}' branch`
: `Initializes repository with '${branch}' branch`
: repoType === 'remote'
? "Clones repository to default branch"
: "Initializes repository with 'main' branch"
}
</p>
</div>
<Button
type="submit"
disabled={!repoUrl || mutation.isPending}
disabled={(!repoUrl && repoType === 'remote') || (!localPath && repoType === 'local') || mutation.isPending}
className="w-full bg-blue-600 hover:bg-blue-700 text-white"
>
{mutation.isPending ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Cloning...
{repoType === 'local' ? 'Initializing...' : 'Cloning...'}
</>
) : (
'Add Repository'
+17 -11
View File
@@ -18,7 +18,7 @@ interface BranchSwitcherProps {
repoId: number;
currentBranch: string;
isWorktree?: boolean;
repoUrl: string;
repoUrl?: string | null;
repoLocalPath?: string;
}
@@ -28,7 +28,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
const queryClient = useQueryClient();
const { data: gitStatus } = useGitStatus(repoId);
const { data: branches } = useQuery({
const { data: branches, isLoading: branchesLoading } = useQuery({
queryKey: ["branches", repoId],
queryFn: () => listBranches(repoId),
enabled: !!repoId,
@@ -60,8 +60,12 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="bg-card border-border min-w-[200px]">
{branches?.remote && branches.remote.length > 0 ? (
branches.remote.map((branch: string) => (
{branchesLoading ? (
<DropdownMenuItem disabled className="text-muted-foreground">
Loading branches...
</DropdownMenuItem>
) : branches?.local && branches.local.length > 0 ? (
branches.local.map((branch: string) => (
<DropdownMenuItem
key={branch}
onClick={() => switchBranchMutation.mutate(branch)}
@@ -77,7 +81,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
))
) : (
<DropdownMenuItem disabled className="text-muted-foreground">
Loading branches...
No branches available
</DropdownMenuItem>
)}
<DropdownMenuSeparator />
@@ -95,7 +99,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
)}
</div>
</DropdownMenuItem>
{!isWorktree && (
{!isWorktree && repoUrl && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
@@ -112,11 +116,13 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
</DropdownMenuContent>
</DropdownMenu>
<AddBranchWorkspaceDialog
open={addBranchOpen}
onOpenChange={setAddBranchOpen}
repoUrl={repoUrl}
/>
{repoUrl && (
<AddBranchWorkspaceDialog
open={addBranchOpen}
onOpenChange={setAddBranchOpen}
repoUrl={repoUrl}
/>
)}
<GitChangesSheet
isOpen={gitChangesOpen}
+27 -19
View File
@@ -8,11 +8,13 @@ import { AddBranchWorkspaceDialog } from "./AddBranchWorkspaceDialog";
interface RepoCardProps {
repo: {
id: number;
repoUrl: string;
repoUrl?: string | null;
localPath?: string;
branch?: string;
currentBranch?: string;
cloneStatus: string;
isWorktree?: boolean;
isLocal?: boolean;
};
onDelete: (id: number) => void;
isDeleting: boolean;
@@ -29,7 +31,9 @@ export function RepoCard({
}: RepoCardProps) {
const navigate = useNavigate();
const [addBranchOpen, setAddBranchOpen] = useState(false);
const repoName = repo.repoUrl.split("/").slice(-1)[0].replace(".git", "");
const repoName = repo.repoUrl
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
: repo.localPath || "Local Repo";
const branchToDisplay = repo.currentBranch || repo.branch;
const isReady = repo.cloneStatus === "ready";
@@ -115,18 +119,20 @@ export function RepoCard({
<ExternalLink className="w-4 h-4 mr-2" />
Open
</Button>
<Button
size="sm"
variant="outline"
onClick={(e) => {
e.stopPropagation();
setAddBranchOpen(true);
}}
disabled={!isReady}
className="h-10 sm:h-9 w-10 p-0"
>
<GitBranch className="w-4 h-4" />
</Button>
{repo.repoUrl && (
<Button
size="sm"
variant="outline"
onClick={(e) => {
e.stopPropagation();
setAddBranchOpen(true);
}}
disabled={!isReady}
className="h-10 sm:h-9 w-10 p-0"
>
<GitBranch className="w-4 h-4" />
</Button>
)}
<Button
size="sm"
@@ -148,11 +154,13 @@ export function RepoCard({
</div>
</div>
<AddBranchWorkspaceDialog
open={addBranchOpen}
onOpenChange={setAddBranchOpen}
repoUrl={repo.repoUrl}
/>
{repo.repoUrl && (
<AddBranchWorkspaceDialog
open={addBranchOpen}
onOpenChange={setAddBranchOpen}
repoUrl={repo.repoUrl}
/>
)}
</div>
);
}
+7 -4
View File
@@ -76,8 +76,8 @@ export function RepoList() {
if (repo.isWorktree) {
acc.push(repo);
} else {
const key = repo.repoUrl;
const existing = acc.find(r => r.repoUrl === key && !r.isWorktree);
const key = repo.repoUrl || repo.localPath;
const existing = acc.find(r => (r.repoUrl || r.localPath) === key && !r.isWorktree);
if (!existing) {
acc.push(repo);
@@ -88,10 +88,13 @@ export function RepoList() {
}, [] as typeof repos);
const filteredRepos = dedupedRepos.filter((repo) => {
const repoName = repo.repoUrl.split("/").slice(-1)[0].replace(".git", "");
const repoName = repo.repoUrl
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
: repo.localPath;
const searchTarget = repo.repoUrl || repo.localPath || "";
return (
repoName.toLowerCase().includes(searchQuery.toLowerCase()) ||
repo.repoUrl.toLowerCase().includes(searchQuery.toLowerCase())
searchTarget.toLowerCase().includes(searchQuery.toLowerCase())
);
});
@@ -0,0 +1,164 @@
import { useState } from 'react'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import type { Permission, PermissionResponse } from '@/api/types'
import { cn } from '@/lib/utils'
interface PermissionRequestDialogProps {
permission: Permission | null
pendingCount: number
onRespond: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
onDismiss: (permissionID: string) => void
}
function getPermissionTypeLabel(type: string): string {
switch (type) {
case 'bash':
return 'Run Command'
case 'edit':
return 'Edit File'
case 'webfetch':
return 'Fetch URL'
default:
return type.charAt(0).toUpperCase() + type.slice(1)
}
}
function getPermissionDescription(permission: Permission): string {
const patterns = Array.isArray(permission.pattern)
? permission.pattern
: permission.pattern
? [permission.pattern]
: []
if (patterns.length > 0) {
return patterns.join('\n')
}
if (permission.metadata?.command) {
return String(permission.metadata.command)
}
if (permission.metadata?.path) {
return String(permission.metadata.path)
}
if (permission.metadata?.url) {
return String(permission.metadata.url)
}
return ''
}
export function PermissionRequestDialog({
permission,
pendingCount,
onRespond,
onDismiss,
}: PermissionRequestDialogProps) {
const [isLoading, setIsLoading] = useState(false)
const [loadingAction, setLoadingAction] = useState<PermissionResponse | null>(null)
if (!permission) return null
const handleResponse = async (response: PermissionResponse) => {
setIsLoading(true)
setLoadingAction(response)
try {
await onRespond(permission.id, permission.sessionID, response)
} catch (error) {
console.error('Failed to respond to permission:', error)
onDismiss(permission.id)
} finally {
setIsLoading(false)
setLoadingAction(null)
}
}
const typeLabel = getPermissionTypeLabel(permission.type)
const description = getPermissionDescription(permission)
const hasMultiple = pendingCount > 1
return (
<Dialog open={true} onOpenChange={() => {}}>
<DialogContent hideCloseButton className="sm:max-w-md">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
Permission Request
{hasMultiple && (
<span className="text-xs font-normal text-muted-foreground bg-muted px-2 py-0.5 rounded-full">
+{pendingCount - 1} more
</span>
)}
</DialogTitle>
<DialogDescription>
{permission.title || `Allow ${typeLabel.toLowerCase()}?`}
</DialogDescription>
</DialogHeader>
<div className="space-y-3">
<div className="flex items-center gap-2">
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
{typeLabel}
</span>
</div>
{description && (
<div className="bg-muted/50 border rounded-md p-3 max-h-32 overflow-y-auto">
<pre className="text-sm font-mono whitespace-pre-wrap break-all">
{description}
</pre>
</div>
)}
<div className="text-xs text-muted-foreground">
Session: <span className="font-mono">{permission.sessionID.slice(0, 12)}...</span>
</div>
</div>
<DialogFooter className="flex-row gap-2 sm:justify-between">
<Button
variant="outline"
onClick={() => handleResponse('reject')}
disabled={isLoading}
className={cn(
"flex-1",
loadingAction === 'reject' && "opacity-70"
)}
>
{loadingAction === 'reject' ? 'Denying...' : 'Deny'}
</Button>
<Button
variant="secondary"
onClick={() => handleResponse('once')}
disabled={isLoading}
className={cn(
"flex-1",
loadingAction === 'once' && "opacity-70"
)}
>
{loadingAction === 'once' ? 'Allowing...' : 'Allow Once'}
</Button>
<Button
variant="default"
onClick={() => handleResponse('always')}
disabled={isLoading}
className={cn(
"flex-1",
loadingAction === 'always' && "opacity-70"
)}
>
{loadingAction === 'always' ? 'Allowing...' : 'Allow Always'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -7,11 +7,12 @@ import { useState } from "react";
interface Repo {
id: number;
repoUrl: string;
repoUrl?: string | null;
fullPath: string;
localPath: string;
currentBranch?: string;
isWorktree?: boolean;
isLocal?: boolean;
cloneStatus: 'ready' | 'cloning' | 'error';
}
@@ -56,7 +57,7 @@ export function SessionDetailHeader({
);
}
const repoName = repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository";
const repoName = repo.repoUrl?.split("/").pop()?.replace(".git", "") || repo.localPath || "Repository";
const currentBranch = repo.currentBranch || "main";
const handleTitleClick = () => {