Show stdio

This commit is contained in:
Louis Knight-Webb
2025-06-16 20:23:57 -04:00
parent 18db6be0f2
commit 6cd2510a29

View File

@@ -1,124 +1,210 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from "react";
import { Card, CardContent } from '@/components/ui/card' import { Card, CardContent } from "@/components/ui/card";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogHeader, DialogHeader,
DialogTitle DialogTitle,
} from '@/components/ui/dialog' } from "@/components/ui/dialog";
import { Label } from '@/components/ui/label' import { Label } from "@/components/ui/label";
import { Button } from '@/components/ui/button' import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Input } from "@/components/ui/input";
import { makeAuthenticatedRequest } from '@/lib/auth' import { Textarea } from "@/components/ui/textarea";
import type { TaskStatus, TaskAttempt, TaskAttemptActivity, ExecutorConfig } from 'shared/types' import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { makeAuthenticatedRequest } from "@/lib/auth";
import type {
TaskStatus,
TaskAttempt,
TaskAttemptActivity,
ExecutorConfig,
} from "shared/types";
interface Task { interface Task {
id: string id: string;
project_id: string project_id: string;
title: string title: string;
description: string | null description: string | null;
status: TaskStatus status: TaskStatus;
created_at: string created_at: string;
updated_at: string updated_at: string;
} }
interface ApiResponse<T> { interface ApiResponse<T> {
success: boolean success: boolean;
data: T | null data: T | null;
message: string | null message: string | null;
} }
interface TaskDetailsDialogProps { interface TaskDetailsDialogProps {
isOpen: boolean isOpen: boolean;
onOpenChange: (open: boolean) => void onOpenChange: (open: boolean) => void;
task: Task | null task: Task | null;
projectId: string projectId: string;
onError: (error: string) => void onError: (error: string) => void;
} }
const statusLabels: Record<TaskStatus, string> = { const statusLabels: Record<TaskStatus, string> = {
todo: 'To Do', todo: "To Do",
inprogress: 'In Progress', inprogress: "In Progress",
inreview: 'In Review', inreview: "In Review",
done: 'Done', done: "Done",
cancelled: 'Cancelled' cancelled: "Cancelled",
} };
export function TaskDetailsDialog({ isOpen, onOpenChange, task, projectId, onError }: TaskDetailsDialogProps) { export function TaskDetailsDialog({
const [taskAttempts, setTaskAttempts] = useState<TaskAttempt[]>([]) isOpen,
const [taskAttemptsLoading, setTaskAttemptsLoading] = useState(false) onOpenChange,
const [selectedAttempt, setSelectedAttempt] = useState<TaskAttempt | null>(null) task,
const [attemptActivities, setAttemptActivities] = useState<TaskAttemptActivity[]>([]) projectId,
const [activitiesLoading, setActivitiesLoading] = useState(false) onError,
const [selectedExecutor, setSelectedExecutor] = useState<ExecutorConfig>({ type: "echo" }) }: TaskDetailsDialogProps) {
const [creatingAttempt, setCreatingAttempt] = useState(false) const [taskAttempts, setTaskAttempts] = useState<TaskAttempt[]>([]);
const [taskAttemptsLoading, setTaskAttemptsLoading] = useState(false);
const [selectedAttempt, setSelectedAttempt] = useState<TaskAttempt | null>(
null
);
const [attemptActivities, setAttemptActivities] = useState<
TaskAttemptActivity[]
>([]);
const [activitiesLoading, setActivitiesLoading] = useState(false);
const [selectedExecutor, setSelectedExecutor] = useState<ExecutorConfig>({
type: "echo",
});
const [creatingAttempt, setCreatingAttempt] = useState(false);
// Edit mode state
const [isEditMode, setIsEditMode] = useState(false);
const [editedTitle, setEditedTitle] = useState("");
const [editedDescription, setEditedDescription] = useState("");
const [editedStatus, setEditedStatus] = useState<TaskStatus>("todo");
const [savingTask, setSavingTask] = useState(false);
useEffect(() => { useEffect(() => {
if (isOpen && task) { if (isOpen && task) {
fetchTaskAttempts(task.id) fetchTaskAttempts(task.id);
// Initialize edit state with current task values
setEditedTitle(task.title);
setEditedDescription(task.description || "");
setEditedStatus(task.status);
setIsEditMode(false);
} }
}, [isOpen, task]) }, [isOpen, task]);
const fetchTaskAttempts = async (taskId: string) => { const fetchTaskAttempts = async (taskId: string) => {
try { try {
setTaskAttemptsLoading(true) setTaskAttemptsLoading(true);
const response = await makeAuthenticatedRequest(`/api/projects/${projectId}/tasks/${taskId}/attempts`) const response = await makeAuthenticatedRequest(
`/api/projects/${projectId}/tasks/${taskId}/attempts`
);
if (response.ok) { if (response.ok) {
const result: ApiResponse<TaskAttempt[]> = await response.json() const result: ApiResponse<TaskAttempt[]> = await response.json();
if (result.success && result.data) { if (result.success && result.data) {
setTaskAttempts(result.data) setTaskAttempts(result.data);
} }
} else { } else {
onError('Failed to load task attempts') onError("Failed to load task attempts");
} }
} catch (err) { } catch (err) {
onError('Failed to load task attempts') onError("Failed to load task attempts");
} finally { } finally {
setTaskAttemptsLoading(false) setTaskAttemptsLoading(false);
}
} }
};
const fetchAttemptActivities = async (attemptId: string) => { const fetchAttemptActivities = async (attemptId: string) => {
if (!task) return if (!task) return;
try { try {
setActivitiesLoading(true) setActivitiesLoading(true);
const response = await makeAuthenticatedRequest(`/api/projects/${projectId}/tasks/${task.id}/attempts/${attemptId}/activities`) const response = await makeAuthenticatedRequest(
`/api/projects/${projectId}/tasks/${task.id}/attempts/${attemptId}/activities`
);
if (response.ok) { if (response.ok) {
const result: ApiResponse<TaskAttemptActivity[]> = await response.json() const result: ApiResponse<TaskAttemptActivity[]> =
await response.json();
if (result.success && result.data) { if (result.success && result.data) {
setAttemptActivities(result.data) setAttemptActivities(result.data);
} }
} else { } else {
onError('Failed to load attempt activities') onError("Failed to load attempt activities");
} }
} catch (err) { } catch (err) {
onError('Failed to load attempt activities') onError("Failed to load attempt activities");
} finally { } finally {
setActivitiesLoading(false) setActivitiesLoading(false);
}
} }
};
const handleAttemptClick = (attempt: TaskAttempt) => { const handleAttemptClick = (attempt: TaskAttempt) => {
setSelectedAttempt(attempt) setSelectedAttempt(attempt);
fetchAttemptActivities(attempt.id) fetchAttemptActivities(attempt.id);
} };
const createNewAttempt = async () => { const saveTaskChanges = async () => {
if (!task) return if (!task) return;
try { try {
setCreatingAttempt(true) setSavingTask(true);
const worktreePath = `/tmp/task-${task.id}-attempt-${Date.now()}` const response = await makeAuthenticatedRequest(
`/api/projects/${projectId}/tasks/${task.id}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: editedTitle,
description: editedDescription || null,
status: editedStatus,
}),
}
);
if (response.ok) {
setIsEditMode(false);
// Update the local task state would require parent component to refresh
// For now, just exit edit mode
} else {
onError("Failed to save task changes");
}
} catch (err) {
onError("Failed to save task changes");
} finally {
setSavingTask(false);
}
};
const cancelEdit = () => {
if (task) {
setEditedTitle(task.title);
setEditedDescription(task.description || "");
setEditedStatus(task.status);
}
setIsEditMode(false);
};
const createNewAttempt = async () => {
if (!task) return;
try {
setCreatingAttempt(true);
const worktreePath = `/tmp/task-${task.id}-attempt-${Date.now()}`;
const response = await makeAuthenticatedRequest( const response = await makeAuthenticatedRequest(
`/api/projects/${projectId}/tasks/${task.id}/attempts`, `/api/projects/${projectId}/tasks/${task.id}/attempts`,
{ {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
task_id: task.id, task_id: task.id,
@@ -128,63 +214,310 @@ export function TaskDetailsDialog({ isOpen, onOpenChange, task, projectId, onErr
executor_config: selectedExecutor, executor_config: selectedExecutor,
}), }),
} }
) );
if (response.ok) { if (response.ok) {
// Refresh the attempts list // Refresh the attempts list
await fetchTaskAttempts(task.id) await fetchTaskAttempts(task.id);
} else { } else {
onError('Failed to create task attempt') onError("Failed to create task attempt");
} }
} catch (err) { } catch (err) {
onError('Failed to create task attempt') onError("Failed to create task attempt");
} finally { } finally {
setCreatingAttempt(false) setCreatingAttempt(false);
}
} }
};
return ( return (
<Dialog open={isOpen} onOpenChange={onOpenChange}> <Dialog open={isOpen} onOpenChange={onOpenChange} className="max-w-7xl">
<DialogContent className="max-w-4xl max-h-[80vh] overflow-y-auto"> <DialogContent className="max-h-[85vh] overflow-y-auto">
<DialogHeader> <DialogHeader>
<DialogTitle>Task Details: {task?.title}</DialogTitle> <div className="flex justify-between items-start">
<DialogTitle className="text-xl">
{isEditMode ? "Edit Task" : "Task Details"}
</DialogTitle>
<div className="flex gap-2">
{isEditMode ? (
<>
<Button
onClick={saveTaskChanges}
disabled={savingTask}
size="sm"
>
{savingTask ? "Saving..." : "Save"}
</Button>
<Button onClick={cancelEdit} variant="outline" size="sm">
Cancel
</Button>
</>
) : (
<Button
onClick={() => setIsEditMode(true)}
variant="outline"
size="sm"
>
Edit
</Button>
)}
</div>
</div>
</DialogHeader> </DialogHeader>
<div className="space-y-6">
{/* Task Info */} <div className="grid grid-cols-3 gap-6">
<div className="space-y-2"> {/* Main Content */}
<h3 className="text-lg font-semibold">Task Information</h3> <div className="col-span-2 space-y-6">
<div className="grid grid-cols-2 gap-4"> {/* Task Details */}
<Card>
<CardContent className="p-6">
<div className="space-y-4">
<div> <div>
<Label>Title</Label> <Label className="text-sm font-medium">Title</Label>
<p className="text-sm text-muted-foreground">{task?.title}</p> {isEditMode ? (
<Input
value={editedTitle}
onChange={(e) => setEditedTitle(e.target.value)}
className="mt-1"
placeholder="Enter task title..."
/>
) : (
<h2 className="text-lg font-semibold mt-1">
{task?.title}
</h2>
)}
</div> </div>
<div> <div>
<Label>Status</Label> <Label className="text-sm font-medium">Description</Label>
<p className="text-sm text-muted-foreground"> {isEditMode ? (
{task ? statusLabels[task.status] : ''} <Textarea
value={editedDescription}
onChange={(e) => setEditedDescription(e.target.value)}
className="mt-1 min-h-[100px]"
placeholder="Enter task description..."
/>
) : (
<div className="mt-1 p-3 bg-gray-50 rounded-md min-h-[60px]">
{task?.description ? (
<p className="text-sm text-gray-700 whitespace-pre-wrap">
{task.description}
</p> </p>
) : (
<p className="text-sm text-gray-500 italic">
No description provided
</p>
)}
</div>
)}
</div> </div>
</div> </div>
{task?.description && ( </CardContent>
</Card>
{/* Task Attempt Output */}
{selectedAttempt &&
(selectedAttempt.stdout || selectedAttempt.stderr) && (
<Card className="bg-black">
<CardContent className="p-6">
<h3 className="text-lg font-semibold mb-4 text-green-400">
Execution Output
</h3>
<div className="space-y-4">
{selectedAttempt.stdout && (
<div> <div>
<Label>Description</Label> <Label className="text-sm font-medium mb-2 block text-green-400">
<p className="text-sm text-muted-foreground">{task.description}</p> STDOUT
</Label>
<div
className="bg-black border border-green-400 rounded-md p-4 font-mono text-sm text-green-400 max-h-96 overflow-y-auto whitespace-pre-wrap shadow-inner"
style={{
fontFamily:
'ui-monospace, SFMono-Regular, "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
}}
>
{selectedAttempt.stdout}
</div>
</div>
)}
{selectedAttempt.stderr && (
<div>
<Label className="text-sm font-medium mb-2 block text-red-400">
STDERR
</Label>
<div
className="bg-black border border-red-400 rounded-md p-4 font-mono text-sm text-red-400 max-h-96 overflow-y-auto whitespace-pre-wrap shadow-inner"
style={{
textShadow: "0 0 2px #ff0000",
fontFamily:
'ui-monospace, SFMono-Regular, "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
}}
>
{selectedAttempt.stderr}
</div>
</div>
)}
</div>
</CardContent>
</Card>
)}
</div>
{/* Sidebar */}
<div className="space-y-4">
<Card>
<CardContent className="p-4">
<h4 className="font-semibold mb-3">Details</h4>
<div className="space-y-3">
<div>
<Label className="text-xs text-muted-foreground">
Status
</Label>
{isEditMode ? (
<Select
value={editedStatus}
onValueChange={(value) =>
setEditedStatus(value as TaskStatus)
}
>
<SelectTrigger className="mt-1">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="todo">To Do</SelectItem>
<SelectItem value="inprogress">
In Progress
</SelectItem>
<SelectItem value="inreview">In Review</SelectItem>
<SelectItem value="done">Done</SelectItem>
<SelectItem value="cancelled">Cancelled</SelectItem>
</SelectContent>
</Select>
) : (
<div
className={`mt-1 px-2 py-1 rounded-full text-xs font-medium w-fit ${
task?.status === "todo"
? "bg-gray-100 text-gray-800"
: task?.status === "inprogress"
? "bg-blue-100 text-blue-800"
: task?.status === "inreview"
? "bg-yellow-100 text-yellow-800"
: task?.status === "done"
? "bg-green-100 text-green-800"
: "bg-red-100 text-red-800"
}`}
>
{task ? statusLabels[task.status] : ""}
</div> </div>
)} )}
</div> </div>
<Separator />
<div>
<Label className="text-xs text-muted-foreground">
Created
</Label>
<p className="text-sm mt-1">
{task
? new Date(task.created_at).toLocaleDateString()
: ""}
</p>
</div>
<div>
<Label className="text-xs text-muted-foreground">
Updated
</Label>
<p className="text-sm mt-1">
{task
? new Date(task.updated_at).toLocaleDateString()
: ""}
</p>
</div>
<div>
<Label className="text-xs text-muted-foreground">
Project ID
</Label>
<p className="text-xs text-muted-foreground mt-1 font-mono">
{projectId}
</p>
</div>
</div>
</CardContent>
</Card>
{/* Task Attempts */} {/* Task Attempts */}
<div className="space-y-4"> <Card>
<div className="flex justify-between items-center"> <CardContent className="p-4">
<h3 className="text-lg font-semibold">Task Attempts</h3> <h4 className="font-semibold mb-3">Task Attempts</h4>
<div className="flex items-center gap-2"> <div className="space-y-3">
<div className="flex items-center gap-2"> <div>
<Label className="text-sm">Executor:</Label> <Label className="text-xs text-muted-foreground mb-2 block">
Select Attempt
</Label>
{taskAttemptsLoading ? (
<div className="text-center py-2 text-sm text-muted-foreground">
Loading...
</div>
) : taskAttempts.length === 0 ? (
<div className="text-center py-2 text-sm text-muted-foreground">
No attempts found
</div>
) : (
<Select
value={selectedAttempt?.id || ""}
onValueChange={(value) => {
const attempt = taskAttempts.find(
(a) => a.id === value
);
if (attempt) {
handleAttemptClick(attempt);
}
}}
>
<SelectTrigger>
<SelectValue placeholder="Select an attempt..." />
</SelectTrigger>
<SelectContent>
{taskAttempts.map((attempt) => (
<SelectItem key={attempt.id} value={attempt.id}>
<div className="flex flex-col">
<span className="font-medium">
{new Date(
attempt.created_at
).toLocaleDateString()}{" "}
{new Date(
attempt.created_at
).toLocaleTimeString()}
</span>
<span className="text-xs text-muted-foreground">
Executor
</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
)}
</div>
<Separator />
<div className="space-y-2">
<Label className="text-xs text-muted-foreground">
New Attempt
</Label>
<div className="flex flex-col gap-2">
<Select <Select
value={selectedExecutor.type} value={selectedExecutor.type}
onValueChange={(value) => setSelectedExecutor({ type: value as "echo" | "claude" })} onValueChange={(value) =>
setSelectedExecutor({
type: value as "echo" | "claude",
})
}
> >
<SelectTrigger className="w-32"> <SelectTrigger>
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
@@ -192,111 +525,78 @@ export function TaskDetailsDialog({ isOpen, onOpenChange, task, projectId, onErr
<SelectItem value="claude">Claude</SelectItem> <SelectItem value="claude">Claude</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
</div>
<Button <Button
onClick={createNewAttempt} onClick={createNewAttempt}
disabled={creatingAttempt} disabled={creatingAttempt}
size="sm" size="sm"
className="w-full"
> >
{creatingAttempt ? 'Creating...' : 'Create New Attempt'} {creatingAttempt ? "Creating..." : "Create Attempt"}
</Button> </Button>
</div> </div>
</div> </div>
{taskAttemptsLoading ? (
<div className="text-center py-4">Loading attempts...</div>
) : taskAttempts.length === 0 ? (
<div className="text-center py-4 text-muted-foreground">
No attempts found for this task
</div>
) : (
<div className="space-y-2">
{taskAttempts.map((attempt) => (
<Card
key={attempt.id}
className={`cursor-pointer transition-colors ${
selectedAttempt?.id === attempt.id ? 'bg-blue-50 border-blue-200' : 'hover:bg-gray-50'
}`}
onClick={() => handleAttemptClick(attempt)}
>
<CardContent className="p-4">
<div className="space-y-2">
<div className="flex justify-between items-start">
<div>
<p className="font-medium">Worktree: {attempt.worktree_path}</p>
<p className="text-sm text-muted-foreground">
Created: {new Date(attempt.created_at).toLocaleDateString()}
</p>
</div>
</div>
<div className="grid grid-cols-2 gap-4 text-sm">
<div>
<Label className="text-xs">Base Commit</Label>
<p className="text-muted-foreground">
{attempt.base_commit || 'None'}
</p>
</div>
<div>
<Label className="text-xs">Merge Commit</Label>
<p className="text-muted-foreground">
{attempt.merge_commit || 'None'}
</p>
</div>
</div>
</div> </div>
</CardContent> </CardContent>
</Card> </Card>
))}
</div>
)}
</div>
{/* Activity History */} {/* Activity History */}
{selectedAttempt && ( {selectedAttempt && (
<div className="space-y-4"> <Card>
<h3 className="text-lg font-semibold"> <CardContent className="p-4">
Activity History for Attempt: {selectedAttempt.worktree_path} <h4 className="font-semibold mb-3">Activity History</h4>
</h3> <p className="text-xs text-muted-foreground mb-3">
{selectedAttempt.worktree_path}
</p>
{activitiesLoading ? ( {activitiesLoading ? (
<div className="text-center py-4">Loading activities...</div> <div className="text-center py-4">
Loading activities...
</div>
) : attemptActivities.length === 0 ? ( ) : attemptActivities.length === 0 ? (
<div className="text-center py-4 text-muted-foreground"> <div className="text-center py-4 text-muted-foreground">
No activities found for this attempt No activities found
</div> </div>
) : ( ) : (
<div className="space-y-2"> <div className="space-y-2">
{attemptActivities.map((activity) => ( {attemptActivities.map((activity) => (
<Card key={activity.id}> <div
<CardContent className="p-4"> key={activity.id}
<div className="flex justify-between items-start"> className="border-l-2 border-gray-200 pl-3 pb-2"
<div className="space-y-1"> >
<div className="flex items-center space-x-2"> <div className="flex items-center justify-between">
<span className={`px-2 py-1 rounded-full text-xs font-medium ${ <span
activity.status === 'init' ? 'bg-gray-100 text-gray-800' : className={`px-2 py-1 rounded-full text-xs font-medium ${
activity.status === 'inprogress' ? 'bg-blue-100 text-blue-800' : activity.status === "init"
'bg-yellow-100 text-yellow-800' ? "bg-gray-100 text-gray-800"
}`}> : activity.status === "inprogress"
{activity.status === 'init' ? 'Init' : ? "bg-blue-100 text-blue-800"
activity.status === 'inprogress' ? 'In Progress' : : "bg-yellow-100 text-yellow-800"
'Paused'} }`}
>
{activity.status === "init"
? "Init"
: activity.status === "inprogress"
? "In Progress"
: "Paused"}
</span> </span>
</div>
{activity.note && (
<p className="text-sm text-muted-foreground">{activity.note}</p>
)}
</div>
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
{new Date(activity.created_at).toLocaleString()} {new Date(activity.created_at).toLocaleString()}
</p> </p>
</div> </div>
</CardContent> {activity.note && (
</Card> <p className="text-sm text-muted-foreground mt-1">
{activity.note}
</p>
)}
</div>
))} ))}
</div> </div>
)} )}
</div> </CardContent>
</Card>
)} )}
</div> </div>
</div>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
) );
} }