mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
feat: standardize logging across UI components
- Replaced console.log and console.error statements with logger methods from @automaker/utils in various UI components, ensuring consistent log formatting and improved readability. - Enhanced error handling by utilizing logger methods to provide clearer context for issues encountered during operations. - Updated multiple views and hooks to integrate the new logging system, improving maintainability and debugging capabilities. This update significantly enhances the observability of UI components, facilitating easier troubleshooting and monitoring.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { useEffect, useCallback, useMemo } from 'react';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
import { createLogger } from '@automaker/utils/logger';
|
||||
import { useAppStore } from '@/store/app-store';
|
||||
import { getElectronAPI } from '@/lib/electron';
|
||||
import type { AutoModeEvent } from '@/types/electron';
|
||||
|
||||
const logger = createLogger('AutoMode');
|
||||
|
||||
// Type guard for plan_approval_required event
|
||||
function isPlanApprovalEvent(
|
||||
event: AutoModeEvent
|
||||
@@ -67,7 +70,7 @@ export function useAutoMode() {
|
||||
if (!api?.autoMode) return;
|
||||
|
||||
const unsubscribe = api.autoMode.onEvent((event: AutoModeEvent) => {
|
||||
console.log('[AutoMode Event]', event);
|
||||
logger.info('Event:', event);
|
||||
|
||||
// Events include projectPath from backend - use it to look up project ID
|
||||
// Fall back to current projectId if not provided in event
|
||||
@@ -84,7 +87,7 @@ export function useAutoMode() {
|
||||
|
||||
// Skip event if we couldn't determine the project
|
||||
if (!eventProjectId) {
|
||||
console.warn('[AutoMode] Could not determine project for event:', event);
|
||||
logger.warn('Could not determine project for event:', event);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +106,7 @@ export function useAutoMode() {
|
||||
case 'auto_mode_feature_complete':
|
||||
// Feature completed - remove from running tasks and UI will reload features on its own
|
||||
if (event.featureId) {
|
||||
console.log('[AutoMode] Feature completed:', event.featureId, 'passes:', event.passes);
|
||||
logger.info('Feature completed:', event.featureId, 'passes:', event.passes);
|
||||
removeRunningTask(eventProjectId, event.featureId);
|
||||
addAutoModeActivity({
|
||||
featureId: event.featureId,
|
||||
@@ -121,7 +124,7 @@ export function useAutoMode() {
|
||||
// Check if this is a user-initiated cancellation or abort (not a real error)
|
||||
if (event.errorType === 'cancellation' || event.errorType === 'abort') {
|
||||
// User cancelled/aborted the feature - just log as info, not an error
|
||||
console.log('[AutoMode] Feature cancelled/aborted:', event.error);
|
||||
logger.info('Feature cancelled/aborted:', event.error);
|
||||
// Remove from running tasks
|
||||
if (eventProjectId) {
|
||||
removeRunningTask(eventProjectId, event.featureId);
|
||||
@@ -130,7 +133,7 @@ export function useAutoMode() {
|
||||
}
|
||||
|
||||
// Real error - log and show to user
|
||||
console.error('[AutoMode Error]', event.error);
|
||||
logger.error('Error:', event.error);
|
||||
|
||||
// Check for authentication errors and provide a more helpful message
|
||||
const isAuthError =
|
||||
@@ -182,7 +185,7 @@ export function useAutoMode() {
|
||||
case 'auto_mode_phase':
|
||||
// Log phase transitions (Planning, Action, Verification)
|
||||
if (event.featureId && event.phase && event.message) {
|
||||
console.log(`[AutoMode] Phase: ${event.phase} for ${event.featureId}`);
|
||||
logger.debug(`[AutoMode] Phase: ${event.phase} for ${event.featureId}`);
|
||||
addAutoModeActivity({
|
||||
featureId: event.featureId,
|
||||
type: event.phase,
|
||||
@@ -195,7 +198,7 @@ export function useAutoMode() {
|
||||
case 'plan_approval_required':
|
||||
// Plan requires user approval before proceeding
|
||||
if (isPlanApprovalEvent(event)) {
|
||||
console.log(`[AutoMode] Plan approval required for ${event.featureId}`);
|
||||
logger.debug(`[AutoMode] Plan approval required for ${event.featureId}`);
|
||||
setPendingPlanApproval({
|
||||
featureId: event.featureId,
|
||||
projectPath: event.projectPath || currentProject?.path || '',
|
||||
@@ -208,7 +211,7 @@ export function useAutoMode() {
|
||||
case 'planning_started':
|
||||
// Log when planning phase begins
|
||||
if (event.featureId && event.mode && event.message) {
|
||||
console.log(`[AutoMode] Planning started (${event.mode}) for ${event.featureId}`);
|
||||
logger.debug(`[AutoMode] Planning started (${event.mode}) for ${event.featureId}`);
|
||||
addAutoModeActivity({
|
||||
featureId: event.featureId,
|
||||
type: 'planning',
|
||||
@@ -221,7 +224,7 @@ export function useAutoMode() {
|
||||
case 'plan_approved':
|
||||
// Log when plan is approved by user
|
||||
if (event.featureId) {
|
||||
console.log(`[AutoMode] Plan approved for ${event.featureId}`);
|
||||
logger.debug(`[AutoMode] Plan approved for ${event.featureId}`);
|
||||
addAutoModeActivity({
|
||||
featureId: event.featureId,
|
||||
type: 'action',
|
||||
@@ -236,7 +239,7 @@ export function useAutoMode() {
|
||||
case 'plan_auto_approved':
|
||||
// Log when plan is auto-approved (requirePlanApproval=false)
|
||||
if (event.featureId) {
|
||||
console.log(`[AutoMode] Plan auto-approved for ${event.featureId}`);
|
||||
logger.debug(`[AutoMode] Plan auto-approved for ${event.featureId}`);
|
||||
addAutoModeActivity({
|
||||
featureId: event.featureId,
|
||||
type: 'action',
|
||||
@@ -253,7 +256,7 @@ export function useAutoMode() {
|
||||
AutoModeEvent,
|
||||
{ type: 'plan_revision_requested' }
|
||||
>;
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[AutoMode] Plan revision requested for ${event.featureId} (v${revisionEvent.planVersion})`
|
||||
);
|
||||
addAutoModeActivity({
|
||||
@@ -269,7 +272,7 @@ export function useAutoMode() {
|
||||
// Task started - show which task is being worked on
|
||||
if (event.featureId && 'taskId' in event && 'taskDescription' in event) {
|
||||
const taskEvent = event as Extract<AutoModeEvent, { type: 'auto_mode_task_started' }>;
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[AutoMode] Task ${taskEvent.taskId} started for ${event.featureId}: ${taskEvent.taskDescription}`
|
||||
);
|
||||
addAutoModeActivity({
|
||||
@@ -284,7 +287,7 @@ export function useAutoMode() {
|
||||
// Task completed - show progress
|
||||
if (event.featureId && 'taskId' in event) {
|
||||
const taskEvent = event as Extract<AutoModeEvent, { type: 'auto_mode_task_complete' }>;
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[AutoMode] Task ${taskEvent.taskId} completed for ${event.featureId} (${taskEvent.tasksCompleted}/${taskEvent.tasksTotal})`
|
||||
);
|
||||
addAutoModeActivity({
|
||||
@@ -302,7 +305,7 @@ export function useAutoMode() {
|
||||
AutoModeEvent,
|
||||
{ type: 'auto_mode_phase_complete' }
|
||||
>;
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[AutoMode] Phase ${phaseEvent.phaseNumber} completed for ${event.featureId}`
|
||||
);
|
||||
addAutoModeActivity({
|
||||
@@ -330,18 +333,18 @@ export function useAutoMode() {
|
||||
// Start auto mode - UI only, feature pickup is handled in board-view.tsx
|
||||
const start = useCallback(() => {
|
||||
if (!currentProject) {
|
||||
console.error('No project selected');
|
||||
logger.error('No project selected');
|
||||
return;
|
||||
}
|
||||
|
||||
setAutoModeRunning(currentProject.id, true);
|
||||
console.log(`[AutoMode] Started with maxConcurrency: ${maxConcurrency}`);
|
||||
logger.debug(`[AutoMode] Started with maxConcurrency: ${maxConcurrency}`);
|
||||
}, [currentProject, setAutoModeRunning, maxConcurrency]);
|
||||
|
||||
// Stop auto mode - UI only, running tasks continue until natural completion
|
||||
const stop = useCallback(() => {
|
||||
if (!currentProject) {
|
||||
console.error('No project selected');
|
||||
logger.error('No project selected');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -350,14 +353,14 @@ export function useAutoMode() {
|
||||
// Stopping auto mode only turns off the toggle to prevent new features
|
||||
// from being picked up. Running tasks will complete naturally and be
|
||||
// removed via the auto_mode_feature_complete event.
|
||||
console.log('[AutoMode] Stopped - running tasks will continue');
|
||||
logger.info('Stopped - running tasks will continue');
|
||||
}, [currentProject, setAutoModeRunning]);
|
||||
|
||||
// Stop a specific feature
|
||||
const stopFeature = useCallback(
|
||||
async (featureId: string) => {
|
||||
if (!currentProject) {
|
||||
console.error('No project selected');
|
||||
logger.error('No project selected');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -371,7 +374,7 @@ export function useAutoMode() {
|
||||
|
||||
if (result.success) {
|
||||
removeRunningTask(currentProject.id, featureId);
|
||||
console.log('[AutoMode] Feature stopped successfully:', featureId);
|
||||
logger.info('Feature stopped successfully:', featureId);
|
||||
addAutoModeActivity({
|
||||
featureId,
|
||||
type: 'complete',
|
||||
@@ -379,11 +382,11 @@ export function useAutoMode() {
|
||||
passes: false,
|
||||
});
|
||||
} else {
|
||||
console.error('[AutoMode] Failed to stop feature:', result.error);
|
||||
logger.error('Failed to stop feature:', result.error);
|
||||
throw new Error(result.error || 'Failed to stop feature');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[AutoMode] Error stopping feature:', error);
|
||||
logger.error('Error stopping feature:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user