* ## Implementation Complete! I've successfully implemented the dev server logs feature with the following changes: ### **Files Modified:** 1. **Created Context Files:** - [`TabNavigationContext.tsx`](file:///private/var/folders/m1/9q_ct1913z10v6wbnv54j25r0000gn/T/vibe-kanban/worktrees/vk-5e98-dev-server/frontend/src/contexts/TabNavigationContext.tsx) - For tab switching - [`ProcessSelectionContext.tsx`](file:///private/var/folders/m1/9q_ct1913z10v6wbnv54j25r0000gn/T/vibe-kanban/worktrees/vk-5e98-dev-server/frontend/src/contexts/ProcessSelectionContext.tsx) - For process pre-selection 2. **Updated [`TaskDetailsPanel.tsx`](file:///private/var/folders/m1/9q_ct1913z10v6wbnv54j25r0000gn/T/vibe-kanban/worktrees/vk-5e98-dev-server/frontend/src/components/tasks/TaskDetailsPanel.tsx):** - Added context providers - Connected process selection to ProcessesTab 3. **Updated [`CurrentAttempt.tsx`](file:///private/var/folders/m1/9q_ct1913z10v6wbnv54j25r0000gn/T/vibe-kanban/worktrees/vk-5e98-dev-server/frontend/src/components/tasks/Toolbar/CurrentAttempt.tsx):** - Added FileText icon import - Added process selection hook - Added logic to find latest dev server process - Added View Logs icon button with tooltip - Added handler to jump to dev server logs 4. **Updated [`ProcessesTab.tsx`](file:///private/var/folders/m1/9q_ct1913z10v6wbnv54j25r0000gn/T/vibe-kanban/worktrees/vk-5e98-dev-server/frontend/src/components/tasks/TaskDetails/ProcessesTab.tsx):** - Added props interface for jumpProcessId - Added useEffect to handle process pre-selection - Auto-loads process details when jumping to a process ### **How It Works:** 1. **Button Visibility**: View Logs button (📄 icon) appears next to the dev server button only when a dev server process exists 2. **Smart Process Selection**: Finds the latest dev server process (running preferred, falls back to completed) 3. **Seamless Navigation**: Clicking switches to Processes tab and opens the dev server process logs automatically 4. **No Prop Drilling**: Uses React contexts to avoid passing props through multiple component layers ### **User Experience:** - When dev server is running: User sees both "Dev" and "📄" buttons - When dev server stopped but ran before: User sees "📄" button to view historical logs - Clicking "📄" instantly opens the relevant dev server process in the Processes tab with logs expanded - Tooltip shows "View dev server logs" on hover The implementation is complete, tested, and ready for use! The build passes all TypeScript checks. * Cleanup script changes for task attempt 5e98f2ff-ed68-4c04-8a75-cdcfd98e2bd7 * Done! Changed the icon from FileText to ScrollText (📜). The View Logs button now uses the scroll-text icon which is more appropriate for viewing logs. * ## Refactoring Complete! ✅ The refactoring to more React-like patterns is now complete. Here's what was changed: ### **Key Improvements** 1. **Eliminated Callback Pattern**: Removed the un-React-like `onProcessJumped={() => setJumpProcessId(null)}` callback 2. **Single Source of Truth**: `selectedProcessId` now lives in `ProcessSelectionContext` instead of being split between parent and child 3. **Declarative State**: Components now simply read/write shared state instead of managing events ### **Changes Made** 1. **`ProcessSelectionContext`** → Now a full provider that: - Manages `selectedProcessId` state - Provides `setSelectedProcessId` for direct state updates - Provides `jumpToProcess` wrapper that sets state + switches tab - Uses proper React patterns with `useMemo` and `useCallback` 2. **`TaskDetailsPanel`** → Simplified: - Removed `jumpProcessId` state - Removed callback props to ProcessesTab - Uses `ProcessSelectionProvider` component - Clean provider hierarchy 3. **`ProcessesTab`** → Cleaner component: - Removed props interface entirely - Uses context state instead of local `selectedProcessId` - Auto-fetches process details via useEffect - Manual clicks and button jumps use same state path 4. **`CurrentAttempt`** → Updated API usage: - Uses `jumpToProcess(id, setActiveTab)` - More explicit about tab switching ### **Benefits Achieved** - ✅ **More React-like**: State-driven instead of event-driven - ✅ **Better separation of concerns**: Context owns selection lifecycle - ✅ **No more callbacks**: Eliminated imperative callback pattern - ✅ **Cleaner code**: Removed props drilling and state synchronization - ✅ **Easier to test**: Single state source, declarative flow - ✅ **Better performance**: Memoized context values The feature works exactly the same from the user's perspective, but the code is now much more maintainable and follows React best practices! * Cleanup script changes for task attempt 5e98f2ff-ed68-4c04-8a75-cdcfd98e2bd7 * ## Context Refactoring Complete! ✅ The refactoring to improve context architecture is now complete. Here's what was accomplished: ### **Final Architecture** **`TabNavContext`**: - ✅ Manages tab navigation state (`activeTab`, `setActiveTab`) - ✅ Single responsibility: UI navigation **`ProcessSelectionContext`**: - ✅ Manages process selection state (`selectedProcessId`, `setSelectedProcessId`) - ✅ **Internally consumes** `TabNavContext` via `useTabNavigation()` - ✅ Provides clean `jumpToProcess(processId)` API that handles both concerns ### **Key Improvements Achieved** 1. **Clean API**: `jumpToProcess(processId)` - no parameters needed 2. **Better Separation**: Each context owns its domain, but they coordinate properly 3. **Performance**: Minimal rerender fanout - tab changes don't rerender process consumers 4. **Developer Experience**: Simple, discoverable API 5. **Maintainability**: Easy to add more coordinated actions in the future ### **Usage Examples** ```typescript // Before (awkward) const { jumpToProcess } = useProcessSelection(); const { setActiveTab } = useTabNavigation(); jumpToProcess(processId, setActiveTab); // After (clean) const { jumpToProcess } = useProcessSelection(); jumpToProcess(processId); ``` ### **Provider Hierarchy** ```jsx <TabNavContext.Provider> <ProcessSelectionProvider> {/* ← Uses useTabNavigation internally */} <ProcessesTab /> {/* ← Gets clean jumpToProcess API */} <CurrentAttempt /> {/* ← Simple jumpToProcess(id) call */} </ProcessSelectionProvider> </TabNavContext.Provider> ``` The architecture now follows React best practices with proper context boundaries, optimal performance, and excellent developer ergonomics. The feature works identically from the user's perspective, but the code is much cleaner and more maintainable! * Cleanup script changes for task attempt 5e98f2ff-ed68-4c04-8a75-cdcfd98e2bd7 * fmt
216 lines
7.8 KiB
TypeScript
216 lines
7.8 KiB
TypeScript
import { useContext, useState, useEffect } from 'react';
|
|
import {
|
|
Play,
|
|
Square,
|
|
AlertCircle,
|
|
CheckCircle,
|
|
Clock,
|
|
Cog,
|
|
ArrowLeft,
|
|
} from 'lucide-react';
|
|
import { TaskAttemptDataContext } from '@/components/context/taskDetailsContext.ts';
|
|
import { executionProcessesApi } from '@/lib/api.ts';
|
|
import { ProfileVariantBadge } from '@/components/common/ProfileVariantBadge.tsx';
|
|
import ProcessLogsViewer from './ProcessLogsViewer';
|
|
import type { ExecutionProcessStatus, ExecutionProcess } from 'shared/types';
|
|
import { useProcessSelection } from '@/contexts/ProcessSelectionContext';
|
|
|
|
function ProcessesTab() {
|
|
const { attemptData, setAttemptData } = useContext(TaskAttemptDataContext);
|
|
const { selectedProcessId, setSelectedProcessId } = useProcessSelection();
|
|
const [loadingProcessId, setLoadingProcessId] = useState<string | null>(null);
|
|
|
|
const getStatusIcon = (status: ExecutionProcessStatus) => {
|
|
switch (status) {
|
|
case 'running':
|
|
return <Play className="h-4 w-4 text-blue-500" />;
|
|
case 'completed':
|
|
return <CheckCircle className="h-4 w-4 text-green-500" />;
|
|
case 'failed':
|
|
return <AlertCircle className="h-4 w-4 text-red-500" />;
|
|
case 'killed':
|
|
return <Square className="h-4 w-4 text-gray-500" />;
|
|
default:
|
|
return <Clock className="h-4 w-4 text-gray-400" />;
|
|
}
|
|
};
|
|
|
|
const getStatusColor = (status: ExecutionProcessStatus) => {
|
|
switch (status) {
|
|
case 'running':
|
|
return 'bg-blue-50 border-blue-200 text-blue-800';
|
|
case 'completed':
|
|
return 'bg-green-50 border-green-200 text-green-800';
|
|
case 'failed':
|
|
return 'bg-red-50 border-red-200 text-red-800';
|
|
case 'killed':
|
|
return 'bg-gray-50 border-gray-200 text-gray-800';
|
|
default:
|
|
return 'bg-gray-50 border-gray-200 text-gray-800';
|
|
}
|
|
};
|
|
|
|
const formatDate = (dateString: string) => {
|
|
const date = new Date(dateString);
|
|
return date.toLocaleString();
|
|
};
|
|
|
|
const fetchProcessDetails = async (processId: string) => {
|
|
try {
|
|
setLoadingProcessId(processId);
|
|
const result = await executionProcessesApi.getDetails(processId);
|
|
|
|
if (result !== undefined) {
|
|
setAttemptData((prev) => ({
|
|
...prev,
|
|
runningProcessDetails: {
|
|
...prev.runningProcessDetails,
|
|
[processId]: result,
|
|
},
|
|
}));
|
|
}
|
|
} catch (err) {
|
|
console.error('Failed to fetch process details:', err);
|
|
} finally {
|
|
setLoadingProcessId(null);
|
|
}
|
|
};
|
|
|
|
// Automatically fetch process details when selectedProcessId changes
|
|
useEffect(() => {
|
|
if (
|
|
selectedProcessId &&
|
|
!attemptData.runningProcessDetails[selectedProcessId]
|
|
) {
|
|
fetchProcessDetails(selectedProcessId);
|
|
}
|
|
}, [selectedProcessId, attemptData.runningProcessDetails]);
|
|
|
|
const handleProcessClick = async (process: ExecutionProcess) => {
|
|
setSelectedProcessId(process.id);
|
|
|
|
// If we don't have details for this process, fetch them
|
|
if (!attemptData.runningProcessDetails[process.id]) {
|
|
await fetchProcessDetails(process.id);
|
|
}
|
|
};
|
|
|
|
const selectedProcess = selectedProcessId
|
|
? attemptData.runningProcessDetails[selectedProcessId]
|
|
: null;
|
|
|
|
if (!attemptData.processes || attemptData.processes.length === 0) {
|
|
return (
|
|
<div className="flex-1 flex items-center justify-center text-muted-foreground">
|
|
<div className="text-center">
|
|
<Cog className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
|
<p>No execution processes found for this attempt.</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="flex-1 flex flex-col min-h-0">
|
|
{!selectedProcessId ? (
|
|
<div className="flex-1 overflow-auto px-4 pb-20 pt-4">
|
|
<div className="space-y-3">
|
|
{attemptData.processes.map((process) => (
|
|
<div
|
|
key={process.id}
|
|
className={`border rounded-lg p-4 hover:bg-muted/30 cursor-pointer transition-colors ${
|
|
loadingProcessId === process.id
|
|
? 'opacity-50 cursor-wait'
|
|
: ''
|
|
}`}
|
|
onClick={() => handleProcessClick(process)}
|
|
>
|
|
<div className="flex items-start justify-between">
|
|
<div className="flex items-center space-x-3">
|
|
{getStatusIcon(process.status)}
|
|
<div>
|
|
<h3 className="font-medium text-sm">
|
|
{process.run_reason}
|
|
</h3>
|
|
<p className="text-sm text-muted-foreground mt-1">
|
|
Process ID: {process.id}
|
|
</p>
|
|
{
|
|
<p className="text-sm text-muted-foreground mt-1">
|
|
Profile:{' '}
|
|
{process.executor_action.typ.type ===
|
|
'CodingAgentInitialRequest' ||
|
|
process.executor_action.typ.type ===
|
|
'CodingAgentFollowUpRequest' ? (
|
|
<ProfileVariantBadge
|
|
profileVariant={
|
|
process.executor_action.typ
|
|
.profile_variant_label
|
|
}
|
|
/>
|
|
) : null}
|
|
</p>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div className="text-right">
|
|
<span
|
|
className={`inline-block px-2 py-1 text-xs font-medium border rounded-full ${getStatusColor(
|
|
process.status
|
|
)}`}
|
|
>
|
|
{process.status}
|
|
</span>
|
|
{process.exit_code !== null && (
|
|
<p className="text-xs text-muted-foreground mt-1">
|
|
Exit: {process.exit_code.toString()}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="mt-3 text-xs text-muted-foreground">
|
|
<div className="flex justify-between">
|
|
<span>Started: {formatDate(process.started_at)}</span>
|
|
{process.completed_at && (
|
|
<span>Completed: {formatDate(process.completed_at)}</span>
|
|
)}
|
|
</div>
|
|
<div className="mt-1">Process ID: {process.id}</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="flex-1 flex flex-col min-h-0">
|
|
<div className="flex items-center justify-between px-4 py-2 border-b flex-shrink-0">
|
|
<h2 className="text-lg font-semibold">Process Details</h2>
|
|
<button
|
|
onClick={() => setSelectedProcessId(null)}
|
|
className="flex items-center gap-2 px-3 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded-md border border-border transition-colors"
|
|
>
|
|
<ArrowLeft className="h-4 w-4" />
|
|
Back to list
|
|
</button>
|
|
</div>
|
|
<div className="flex-1">
|
|
{selectedProcess ? (
|
|
<ProcessLogsViewer processId={selectedProcess.id} />
|
|
) : loadingProcessId === selectedProcessId ? (
|
|
<div className="text-center text-muted-foreground">
|
|
<p>Loading process details...</p>
|
|
</div>
|
|
) : (
|
|
<div className="text-center text-muted-foreground">
|
|
<p>Failed to load process details. Please try again.</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default ProcessesTab;
|