Skip to content

Autorun Overhaul#13

Merged
pedramamini merged 62 commits intomainfrom
autorun-overhaul
Dec 4, 2025
Merged

Autorun Overhaul#13
pedramamini merged 62 commits intomainfrom
autorun-overhaul

Conversation

@pedramamini
Copy link
Collaborator

No description provided.

• Enhanced tab navigation to support Cmd+1-9 and Cmd+0 shortcuts 🎯
• Added draft indicator (pencil icon) for unsent messages in tabs ✏️
• Removed verbose console logging from process manager and IPC handlers 🧹
• Added interrupt button to ThinkingStatusPill for stopping AI responses 🛑
• Fixed list styling in markdown rendering with proper indentation 📝
• Improved tab scrolling behavior to center active tab in view 🎯
• Added confetti playground with customizable particle effects and settings 🎊
• Fixed share menu positioning in achievement card to prevent overflow 📐
• Updated keyboard shortcuts to prevent conflicts with system commands ⌨️
• Added onSend prop to PromptComposerModal to actually send messages (Cmd+Enter or Send button)
• Added token count estimation (~4 chars/token) displayed alongside character count in footer
• Improved header spacing for keyboard shortcut hint readability
• Disabled Send button when input is empty
• Optimized TerminalOutput by moving prose styles to container level (memoized)

Claude ID: 37fedb7c-fa1a-45d4-bb0e-5e607b9076bc
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
• Simplified input mode toggle button styling in InputArea
• Enhanced LogViewer keyboard navigation with Opt+Up/Down for page scrolling
• Added refresh spinner feedback in ProcessMonitor with auto-expand on load
• Fixed TabBar to only scroll on tab navigation, not when closing tabs

Claude ID: 1426ed68-c48a-4fd3-834f-33e16f851794
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
• Fixed tab input clearing - empty strings now persist when switching away
• Fixed named session resume - properly loads messages from closed sessions
• Improved draft indicator visibility - pencil icon now uses warning color
• Enhanced tab scrolling - uses requestAnimationFrame for reliable behavior
• Added starred parameter to named session selection callback

Claude ID: 1426ed68-c48a-4fd3-834f-33e16f851794
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
Use manual scroll calculation instead of scrollIntoView for more
predictable centering. Active tab is now centered on every tab change
using offsetLeft calculation relative to container width.
• Added debug action to manually release queued execution items 🐛
• Implemented queue processing for stuck items in execution pipeline 🚀
• Enhanced confetti animation with playground-style burst patterns 🎉
• Optimized markdown rendering with tighter line height spacing 📐
• Improved prose styles with better margin control and consistency ✨
• Added visual feedback for queue status in quick actions modal 📊
• Streamlined confetti colors for more cohesive celebration effects 🌈
• Fixed paragraph spacing in markdown with explicit margin rules 📝
• Removed redundant confetti waves for cleaner animation performance ⚡
• Enhanced list item rendering with better nested structure support 📋
- Rename Scratchpad.tsx to AutoRun.tsx
- Update component names: Scratchpad → AutoRun, ScratchpadInner → AutoRunInner
- Update interface name: ScratchpadProps → AutoRunProps
- Update import in RightPanel.tsx to use AutoRun
- Delete old Scratchpad.tsx file

Part of Phase 1.1 for Auto Run overhaul.
- Change RightPanelTab type union in types/index.ts
- Update tab array in RightPanel.tsx
- Update shortcut ID from goToScratchpad to goToAutoRun
- Update quick action ID and label in QuickActionsModal.tsx
- Update keyboard handler reference in App.tsx
Phase 1.2 of Scratchpad → Auto Run migration:
- Remove scratchPadContent field from Session interface
- Remove scratchPadCursorPosition, scratchPadEditScrollPos,
  scratchPadPreviewScrollPos, and scratchPadMode fields
- Remove ScratchPadMode type (no longer needed)
- Update all usages in App.tsx, RightPanel.tsx, useSessionManager.ts,
  and useBatchProcessor.ts with TODO placeholders
- Content will be stored in files instead of session state once
  IPC handlers are implemented in Phase 1.3
Add six new fields to support the Auto Run panel's file-based document runner:
- autoRunFolderPath: persisted folder path for Runner Docs
- autoRunSelectedFile: currently selected markdown filename
- autoRunMode: current editing mode (edit/preview)
- autoRunEditScrollPos: scroll position in edit mode
- autoRunPreviewScrollPos: scroll position in preview mode
- autoRunCursorPosition: cursor position in edit mode
Add IPC handler and preload API to list markdown documents in a folder:
- Handler filters for .md files, excludes hidden files
- Returns filenames without .md extension, sorted alphabetically
- Exposed via window.maestro.autorun.listDocs() API
Implements the autorun:readDoc handler that reads markdown documents from
the Auto Run folder. Includes security measures:
- Filename sanitization to prevent directory traversal attacks
- Path validation to ensure file is within the folder path
- Automatic .md extension handling
…ad API

Added three new IPC handlers for Auto Run image management:
- autorun:saveImage: Saves base64 images to {folder}/images/{docName}-{timestamp}.{ext}
- autorun:deleteImage: Safely deletes images with path traversal protection
- autorun:listImages: Lists images for a document by prefix matching

Also expanded preload.ts to expose the complete autorun API:
- readDoc, writeDoc (previously added but not exposed)
- saveImage, deleteImage, listImages (new)

All handlers include:
- Input sanitization and validation
- Directory traversal protection
- Image extension whitelisting
- Proper error handling and logging
…ation

Create modal component for first-time Auto Run setup with:
- Explanation text describing Auto Run functionality
- Folder selection via native dialog (Cmd+O shortcut)
- Feature list with Markdown Documents, Checkbox Tasks, Batch Execution
- Cancel/Continue buttons with proper focus management
- Layer stack integration with AUTORUN_SETUP priority (710)
… Run setup

- Import AutoRunSetupModal component
- Add autoRunSetupModalOpen state for modal visibility
- Create handleSetActiveRightTab to intercept autorun tab switch
- Show setup modal when switching to autorun tab with no folder configured
- Add handleAutoRunFolderSelected callback to save folder path to session
- Update keyboard shortcuts to use handleSetActiveRightTab
- Pass handleSetActiveRightTab to RightPanel for tab click handling
- Render AutoRunSetupModal when open
… logic

Implements Phase 3.1-3.2 of the Auto Run overhaul:
- Create AutoRunDocumentSelector.tsx with dropdown, refresh, and change folder
- Update AutoRun.tsx props to support external document/mode state
- Update RightPanel.tsx to pass new Auto Run props
- Add App.tsx state and handlers for document list, content, loading
- Add effect to load documents when session or folder changes
- Add UndoState interface and MAX_UNDO_HISTORY constant (50 entries)
- Create undoHistoryRef and redoHistoryRef Maps keyed by document filename
- Implement pushUndoState function with debounced snapshot scheduling
- Implement handleUndo (Cmd+Z) and handleRedo (Cmd+Shift+Z) functions
- Push undo state before programmatic content changes:
  - Cmd+L checkbox insertion
  - Enter key list continuation
  - Image paste/upload
  - Image/attachment removal
- Clear pending undo snapshot on document switch
- History persists across edit/preview mode toggles
- Per-document history (each document has separate undo/redo stacks)
- Update handlePaste to use autorun:saveImage API with {docName}-{timestamp}.{ext} format
- Update handleFileSelect to save images similarly using the new API
- Update AttachmentImage component to load images from relative paths within folderPath
- Update handleRemoveAttachment and deleteLightboxImage to use autorun:deleteImage API
- Update image list loading to use autorun:listImages API
- Images are now saved to {folder}/images/ subdirectory with relative markdown paths

This completes Phase 3.5 of the Auto Run overhaul, transitioning from
session-based attachment storage to file-system-based image storage that
persists with the Auto Run documents.
Extends the BatchRunState interface with new fields to support:
- Multi-document batch processing (documents array, currentDocumentIndex)
- Per-document task progress (currentDocTasksTotal, currentDocTasksCompleted)
- Overall progress across all documents (totalTasksAcrossAllDocs, completedTasksAcrossAllDocs)
- Loop mode for continuous processing (loopEnabled, loopIteration)
- File-based document storage (folderPath)

Legacy fields are preserved for backwards compatibility during migration.
Updates DEFAULT_BATCH_STATE and setBatchRunStates calls in useBatchProcessor.ts.
… list UI

- Add BatchDocumentEntry and BatchRunConfig interfaces to types
- Redesign BatchRunnerModal with document list section showing:
  - Draggable document rows with grip handles
  - Per-document task count badges
  - Total task count across all selected documents
  - Remove button for documents (when multiple selected)
- Add "+ Add Docs" button that opens document selector sub-modal
- Implement document selector modal with:
  - Checkbox selection for all available documents
  - Task count display per document
  - Cancel/Add buttons with selection count
- Implement HTML5 drag-and-drop for document reordering
- Update onGo callback to pass BatchRunConfig instead of just prompt
- Add loopEnabled state to track loop mode toggle
- Add Loop toggle button that appears when multiple documents exist
- Add curved arrow SVG indicator showing the loop will return to first doc
- Update handleGo to pass loopEnabled in BatchRunConfig
…atchRunnerModal

- Add reset toggle button for each document in the batch run list
- Add reset indicator (↻) shown when reset-on-completion is enabled
- Add duplicate button (+) that appears only for reset-enabled docs
- Implement duplicate insertion logic (inserts copy after original)
- Duplicates inherit the reset-on-completion setting from original
- Remove button now shown for duplicates or when multiple docs exist
…support

Update the batch run progress section to use new multi-document fields:
- Show document progress (e.g., "Document 2 of 5: FEATURE-PLAN")
- Show task progress within current document
- Show loop iteration count when loop mode is active
- Use totalTasksAcrossAllDocs/completedTasksAcrossAllDocs for overall progress
- Maintain backwards compatibility with legacy fields for single-doc runs
…-on-completion

Phase 4.6 complete - rewrote useBatchProcessor to support:
- Accept BatchRunConfig with documents array, prompt, and loopEnabled
- Process documents sequentially, skipping docs with 0 tasks
- Reset-on-completion: uncheck all tasks when doc finishes
- Loop mode: continue cycling through docs until all tasks done
- Safe exit conditions to prevent infinite loops
- Per-document and overall progress tracking

Also updated:
- App.tsx: handleStartBatchRun now accepts BatchRunConfig and folderPath
- BatchRunnerModal: removed deprecated scratchpadContent prop
- Added uncheckAllTasks helper function for reset-on-completion
…onfiguration storage

Added two new TypeScript interfaces to support the Playbooks feature:
- PlaybookDocumentEntry: Stores document filename and reset-on-completion setting
- Playbook: Stores saved batch run configurations with name, documents, loop setting, and prompt
…uration persistence

- Add playbooks:list, playbooks:create, playbooks:update, playbooks:delete IPC handlers
- Store playbooks per-session in userData/playbooks/{sessionId}.json
- Expose playbooks API via preload bridge with full TypeScript types
- Support CRUD operations for saved batch run configurations (documents, loop mode, prompts)
- Add playbooks, loadedPlaybook, and loadingPlaybooks state variables
- Add useEffect to load playbooks from storage on mount via IPC
- Add useMemo to compute isPlaybookModified by comparing current
  configuration (documents, loopEnabled, prompt) against loaded playbook
- Add sessionId prop for per-session playbook storage
- Pass sessionId to BatchRunnerModal from App.tsx
- Change goToAutoRun shortcut from Meta+Shift+s to Meta+Shift+1
- Update AutoRunnerHelpModal to replace remaining Scratchpad terminology:
  - "Scratchpad" -> "Auto Run documents"
  - "scratchpad" -> "Auto Run panel"
  - "scratchpad file" -> "Auto Run document file"
Added comprehensive keyboard shortcuts documentation including:
- Panel navigation shortcuts (including new ⌘⇧1 for Auto Run)
- Session management shortcuts
- Tab management shortcuts (AI mode)
- Mode & focus shortcuts
- Git & system shortcuts
- Quick access shortcuts
Document the complete Auto Run system architecture including:
- Component architecture table (AutoRun, BatchRunnerModal, Playbook modals)
- Data types (BatchDocumentEntry, WorktreeConfig, BatchRunConfig, BatchRunState, Playbook)
- Session fields for Auto Run state persistence
- IPC handlers for document and playbook operations
- Git worktree integration for parallel work isolation
- Execution flow from setup through batch processing
- Write queue integration behavior
- Replace 'Scratchpad' feature with 'Auto Run' in features list
- Update keyboard shortcut from Cmd+Shift+S to Cmd+Shift+1
- Rewrite Automatic Runner section as Auto Run with new features:
  - Multi-document batch runs
  - Playbooks for saved configurations
  - Git worktree support for parallel work
  - Loop mode and reset-on-completion
  - Auto-save and undo/redo
  - Image support with relative paths
…mentation

Rewrote the Auto Run help modal content to comprehensively document all
new Auto Run features including:

- Setting up a Runner Docs folder
- Document format (markdown with checkboxes)
- Creating tasks with quick insert shortcut
- Image attachments workflow
- Running single and multiple documents
- Reset on completion feature
- Loop mode for continuous workflows
- Playbooks for saving/loading configurations
- Git worktree for parallel work
- History tracking and read-only mode
- Stopping gracefully
- All keyboard shortcuts (Cmd+Shift+1, Cmd+E, Cmd+L, Cmd+Z/Shift+Z)

The new help guide covers 15 sections with icons and formatted examples.
Add Shift+number symbol mapping to isShortcut function. When Shift is
pressed with a number key, the browser reports the symbol character
(e.g., '!' for Shift+1) rather than the number. This mapping allows
shortcuts like Cmd+Shift+1 to work correctly on US keyboard layouts.
When an existing worktree is detected and the branch matches (no
mismatch), now shows an informational message displaying the current
branch name. Previously, branch info was only shown in warning states
(branch mismatch or different repo error).

This helps users confirm which branch is currently checked out in
their selected worktree path, even when everything is in order.
- Added onPRResult callback prop to useBatchProcessor hook
- On PR creation success: show success toast with PR URL
- On PR creation failure: show warning toast (not error) with error message
- PR creation failures don't fail the auto-run itself
- Updated App.tsx to pass onPRResult callback and display toasts
The playbooks:create IPC handler was not including worktreeSettings when
building the newPlaybook object. This fix:

- Adds worktreeSettings to the type definition in playbooks:create handler
- Explicitly copies worktreeSettings if provided when creating new playbook
- Adds worktreeSettings to the type definition in playbooks:update handler
- Updates preload.ts types to include worktreeSettings for both create/update

This ensures that when users save a playbook with worktree settings (branch
name template and createPROnCompletion preference), those settings are
properly persisted and restored when the playbook is loaded.
When a folder is configured but contains no markdown documents, the Auto Run
panel now displays a helpful empty state with a "No Documents Found" message
that explains the situation and provides buttons to either refresh the
document list or change the selected folder.
…ents

- Added isMissing field to BatchDocumentEntry interface for tracking
  documents that no longer exist in the Auto Run folder
- Updated handleLoadPlaybook to detect and mark missing documents
  when loading a playbook
- Added visual indicators in the document list:
  - Missing documents show strikethrough name with "MISSING" badge
  - Red-tinted background for missing document rows
  - Disabled drag handle for missing documents
  - Remove button available for easy cleanup
- Added warning banner when playbook has missing documents
- Updated Total Summary to exclude missing documents from count
- Updated "Go" button to be disabled when all documents are missing
- Filter out missing documents when starting batch execution
@claude
Copy link

claude bot commented Dec 3, 2025

Pull Request Review: Auto Run Overhaul

Summary

This is a comprehensive feature overhaul transforming the "Scratchpad" into a powerful "Auto Run" system with file-based document management, multi-document batch processing, playbook support, and Git worktree integration. The PR adds ~6k lines and touches 35 files across main/renderer processes.

Overall Assessment: Strong implementation with minor concerns

🎯 Strengths

Architecture & Design

  • Well-structured separation: Clean division between main process IPC handlers and renderer components
  • Proper security: Uses execFileNoThrow consistently for git operations (preventing command injection)
  • Good state management: Per-session batch state tracking with proper cleanup
  • React best practices: Memoization (useMemo, memo) to prevent unnecessary re-renders
  • Comprehensive documentation: Excellent additions to ARCHITECTURE.md and CLAUDE.md

Features

  • Git worktree integration: Enables true parallel work - very powerful feature
  • Playbook system: Smart reusable configurations with proper CRUD operations
  • Multi-document support: Clean queue management with drag-drop reordering
  • Rich UX: Image paste/preview, undo/redo, search, auto-save with 5s debounce
  • Progress tracking: Document-level and task-level progress with loop support

⚠️ Issues & Concerns

Security

1. Path Traversal Risk (src/main/index.ts:3492-3497)

const sanitizedFilename = path.basename(filename);
if (sanitizedFilename !== filename || filename.includes('..')) {
  return { success: false, content: '', error: 'Invalid filename' };
}

Issue: This check can be bypassed. path.basename('../../etc/passwd') returns 'passwd', which passes validation.
Fix: Use path.resolve() and verify the resolved path is within the expected directory:

const resolvedPath = path.resolve(folderPath, filename);
if (!resolvedPath.startsWith(path.resolve(folderPath))) {
  return { success: false, error: 'Path traversal attempt detected' };
}

2. Worktree Path Validation (src/main/index.ts:1183)

  • Current validation checks if worktree exists after setup, but doesn't prevent malicious paths upfront
  • Consider adding early validation of worktree paths before any git operations

Code Quality

3. Inconsistent Error Handling (BatchRunnerModal.tsx:206-220, useBatchProcessor.ts:206-212)

try {
  counts[doc] = await getDocumentTaskCount(doc);
} catch {
  counts[doc] = 0;  // Silent failure
}

Issue: Errors are silently swallowed without logging. Users won't know if file read failed vs. genuinely has 0 tasks.
Recommendation: Log errors to help debugging:

} catch (error) {
  console.error(`Failed to count tasks in ${doc}:`, error);
  counts[doc] = 0;
}

4. Magic Numbers (useBatchProcessor.ts:47, AutoRun.tsx:71)

const MAX_UNDO_HISTORY = 50;  // Good - defined as constant
setTimeout(() => textareaRef.current?.focus(), 100);  // Bad - magic number

Issue: Timeout values (100ms, 500ms, 1000ms, 5000ms) scattered throughout code without explanation.
Recommendation: Define constants with names explaining why that duration:

const FOCUS_DELAY_MS = 100; // Wait for React render cycle
const WORKTREE_VALIDATION_DEBOUNCE_MS = 500;
const UNDO_SNAPSHOT_DEBOUNCE_MS = 1000;
const AUTO_SAVE_DEBOUNCE_MS = 5000;

Performance

5. Potential Memory Leak (AutoRun.tsx:62, 997)

const imageCache = new Map<string, string>();

Issue: Global cache never clears old entries. As users work across many documents/sessions, base64 images accumulate in memory.
Recommendation: Implement LRU cache with max size or periodic cleanup.

6. Unnecessary Re-validation (BatchRunnerModal.tsx:239-339)

  • Worktree path validation runs on every character typed (with 500ms debounce)
  • For long paths, this creates many IPC calls
  • Recommendation: Only validate when user leaves the input field (onBlur) or clicks "Go"

Type Safety

7. Missing Type Guards (useBatchProcessor.ts:206-212)

const result = await window.maestro.autorun.readDoc(folderPath, filename + '.md');
if (!result.success || !result.content) {
  return { content: '', taskCount: 0 };
}

Issue: Assumes result has expected shape. If API changes, this silently fails.
Recommendation: Add runtime validation or use Zod/io-ts for IPC response validation.

Logic Issues

9. Race Condition (AutoRun.tsx:531-535)

useEffect(() => {
  if (!isEditingRef.current && content !== localContent) {
    setLocalContent(content);
  }
}, [content]);

Issue: If external update happens milliseconds after user starts typing, isEditingRef might not be set yet, causing user input to be overwritten.
Fix: Add timestamp check or version number to content updates to detect conflicts.

10. Infinite Loop Protection (useBatchProcessor.ts:578-583)

if (!anyTasksProcessedThisIteration) {
  console.warn('[BatchProcessor] No tasks processed but documents still have tasks - exiting');
  break;
}

Good: Protection exists, but the condition suggests a deeper bug. This should never trigger in normal operation.
Recommendation: Add telemetry/error reporting when this triggers to identify root cause.

Testing

11. No Test Coverage

  • No unit tests for critical logic:
    • countUnfinishedTasks regex matching
    • uncheckAllTasks replacement logic
    • Worktree setup/checkout flows
    • Document queue ordering with duplicates
  • Recommendation: Add tests for pure functions at minimum

📝 Minor Issues

12. Inconsistent naming (CLAUDE.md:8)

  • Uses both "Right Bar" and "Right Panel" for the same component
  • Standardize to one term

13. Hardcoded keyboard shortcuts (README.md:267)

  • Documentation uses Mac-style shortcuts without Windows equivalents in some places
  • Be consistent with "Cmd/Ctrl" format used elsewhere

14. Dead code (BatchRunnerModal.tsx:70-75)

function countUncheckedTasks(content: string): number {
  // ... unused function
}

Issue: This function is defined but never used (uses the one from useBatchProcessor instead)

15. Console.log statements (useBatchProcessor.ts:260, 279, 304, etc.)

  • Many console.log/warn statements for debugging
  • Recommendation: Use a proper logger with levels that can be disabled in production

🔧 Recommendations

High Priority

  1. Fix path traversal vulnerability (Issue Internal Logging #1) - SECURITY
  2. Add error logging for silent failures (Issue Raychaser/claude path 01 #3)
  3. Implement imageCache cleanup (Issue docs: enhance CLAUDE.md with work items and contribution workflow #5) - MEMORY LEAK

Medium Priority

  1. Define magic number constants (Issue Major Feature: Web Interface #4)
  2. Add type guards for IPC responses (Issue Added Main Panel Tab Support #7)
  3. Fix potential race condition in content sync (Issue Stability, Nuances, Tweaks #9)
  4. Add basic unit tests for regex functions (Issue Feature Request: Files Tab Auto Refresh #11)

Low Priority

  1. Optimize worktree validation frequency (Issue Laundry List of Fixes #6)
  2. Remove unused code (Issue feat: Add auto-refresh for file tree with configurable interval #14)
  3. Replace console statements with proper logging (Issue feat: Add mobile scratchpad and AutoRun controls #15)

✅ What Went Well

  • Git integration: The worktree implementation is solid and well-thought-out
  • User experience: Auto-save, undo/redo, image handling all work smoothly
  • Documentation: ARCHITECTURE.md additions are thorough and helpful
  • Code organization: Clear separation of concerns between components
  • IPC design: Handlers return consistent { success, ...data, error? } shape

🎬 Conclusion

This is a high-quality, feature-rich PR that significantly enhances Maestro's capabilities. The core architecture is sound, and the implementation follows React/TypeScript best practices.

Recommendation: Approve with required changes

The security issue (#1) must be fixed before merge. Other issues can be addressed in follow-up PRs if time-sensitive, but I'd recommend fixing at least the high-priority items (#3, #5) now to prevent future technical debt.

Great work on this ambitious feature! The playbook system and worktree integration are particularly impressive. 🚀

@claude
Copy link

claude bot commented Dec 3, 2025

PR Review: Autorun Overhaul

Overview

This is a substantial feature addition that transforms the simple scratchpad into a sophisticated document runner with multi-file support, playbooks, and git worktree integration. The implementation is generally well-architected and follows the project's conventions outlined in CLAUDE.md.

Summary Statistics:

  • 37 files changed (+6,217/-809 lines)
  • New components: AutoRun system with 7+ new React components
  • New IPC handlers: 15+ new handlers for autorun and git worktree operations
  • Architecture: Well-documented in ARCHITECTURE.md

✅ Strengths

1. Security - Excellent Path Sanitization

The IPC handlers demonstrate proper security practices:

  • ✅ All file operations use path.basename() to prevent directory traversal
  • ✅ Double validation: checks for .. in paths AND ensures basename(x) === x
  • ✅ Proper use of execFileNoThrow throughout (no shell injection vulnerabilities)
  • ✅ Image upload validation with extension whitelist
  • ✅ Git operations safely use execFileNoThrow with command arrays

Example (src/main/index.ts:3519-3522):

const sanitizedFilename = path.basename(filename);
if (sanitizedFilename \!== filename || filename.includes('..')) {
  return { success: false, content: '', error: 'Invalid filename' };
}

2. Architecture - Well-Structured and Documented

  • ✅ Clean separation of concerns with useBatchProcessor hook
  • ✅ Comprehensive documentation in ARCHITECTURE.md with data types, flow diagrams
  • ✅ Follows established patterns (layer stack for modals, IPC wrappers in services)
  • ✅ Type-safe interfaces throughout

3. Error Handling - Defensive Programming

  • ✅ All IPC handlers return { success: boolean, error?: string } pattern
  • ✅ Try-catch blocks around async operations
  • ✅ Graceful fallbacks (e.g., loop protection at line 580, task count validation)
  • ✅ Uncommitted changes check before git operations (line 1300-1306)

4. Loop Protection - Infinite Loop Prevention

The batch processor has multiple safeguards against infinite loops:

  • ✅ Stop request checks at 4 different points (lines 368, 379, 414, 522)
  • ✅ Safety check: exits if no tasks processed but docs still have tasks (line 580)
  • ✅ Progress tracking prevents silent failures

⚠️ Issues & Concerns

1. Critical: Race Condition in Image Cache (Priority: HIGH)

Location: src/renderer/components/AutoRun.tsx:62, 105-117

The imageCache is a module-level Map shared across all component instances. This creates potential issues:

Problems:

  • Multiple sessions could overwrite each other's cache entries
  • Cache never expires or clears (potential memory leak for long sessions)
  • No size limit (could grow unbounded with many images)

Recommendation:

  • Add cache size limit and LRU eviction
  • Or make cache session-specific

2. Bug: Potential State Inconsistency in Batch Processor (Priority: MEDIUM)

Location: src/renderer/hooks/useBatchProcessor.ts:536-548

When resetOnCompletion is enabled in loop mode, the total task count is incremented, but if the loop exits early (e.g., user stops), the UI might show incorrect progress.

Recommendation:
Only update total tasks at the start of each loop iteration, not during document reset.

3. Bug: Missing Cleanup on Component Unmount (Priority: MEDIUM)

Location: src/renderer/components/AutoRun.tsx:608

The attachmentPreviews Map state stores base64 image data which could be substantial. If a user switches documents frequently, these could accumulate without cleanup.

Recommendation:
Add cleanup effect for attachmentPreviews on unmount.

4. Performance: Excessive Re-renders (Priority: MEDIUM)

Location: src/renderer/components/AutoRun.tsx

The component has 51 hooks (useState, useEffect, useCallback, useMemo). This is quite high and could cause performance issues, especially with frequent content updates.

Recommendation:

  • Consider splitting into smaller sub-components (e.g., ImageGallery, SearchPanel, UndoControls)
  • Use React.memo() for child components to prevent unnecessary re-renders
  • Consider using useReducer for complex state updates

5. Code Quality: Magic Numbers (Priority: LOW)

Location: src/renderer/hooks/useBatchProcessor.ts:366

The while (true) loop has no max iteration limit. Add a safety constant like MAX_LOOP_ITERATIONS = 1000 to prevent infinite loops.

6. Missing Validation: Branch Name Sanitization (Priority: MEDIUM)

Location: src/main/index.ts:1212

The git:worktreeSetup handler accepts branchName without validation. While git commands use execFileNoThrow (safe from injection), invalid branch names could cause cryptic errors.

Recommendation:
Validate branch name format: /^[a-zA-Z0-9/_-]+$/


📊 Performance Considerations

Positive:

  • ✅ Image caching reduces repeated IPC calls
  • ✅ Debounced auto-save (5 seconds) prevents excessive writes
  • ✅ Task count calculated once per document, not per task

Areas for Improvement:

  1. Large Markdown Files: No pagination or virtualization for very large documents in preview mode
  2. Batch Processing: Sequential task execution could be slow for large task lists
  3. Undo History: 50 entries × (content size + cursor position) could be substantial for large files

🧪 Test Coverage

Missing: No test files found in the PR for:

  • useBatchProcessor hook (complex state machine logic)
  • Path sanitization functions
  • Undo/redo functionality
  • Loop termination conditions

Recommendation: Add unit tests, especially for:

  • countUnfinishedTasks() and uncheckAllTasks() functions
  • Path sanitization in IPC handlers
  • Batch processor state transitions

🎯 Recommendations Summary

Must Fix (Before Merge):

  1. Add cache size limit to imageCache or make it session-specific
  2. Add branch name validation to git:worktreeSetup
  3. Add max iteration limit to batch processor loop

Should Fix (Soon After):

  1. Fix state inconsistency in resetOnCompletion + loop mode
  2. Add cleanup for attachmentPreviews on unmount
  3. Split AutoRun component into smaller sub-components

Nice to Have:

  1. Add unit tests for batch processor
  2. Add virtualization for large markdown preview
  3. Document the image cache strategy in ARCHITECTURE.md

📝 Documentation

Excellent work on documentation!

  • ✅ ARCHITECTURE.md has comprehensive Auto Run section
  • ✅ README.md updated with usage instructions
  • ✅ Keyboard shortcuts documented
  • ✅ CLAUDE.md updated with new terminology

Overall Assessment

Rating: 8.5/10 - This is a high-quality feature implementation with strong security practices and good architecture. The issues identified are mostly minor except for the cache management concern. The code demonstrates solid engineering practices overall.

Recommendation: Approve with minor changes - Address the cache size limit and branch name validation, then this is ready to merge.

Great work on this substantial feature! 🚀

- Add lastActivityAt timestamps to tab switcher for better session sorting
- Filter "All Named" sessions to current project only (projectRoot-scoped)
- Add relative time formatting (e.g., "5m ago", "2h ago") in tab switcher
- Change slash command behavior: Tab/Enter now fills text instead of executing
- Allow slash commands to be queued when agent is busy (like regular messages)
- Add projectRoot field to Session for stable Claude session storage path
- Fix markdown list indentation and positioning
- Add GitHub Actions workflow for auto-assigning issues/PRs to pedramamini
- Update CLAUDE.md with projectRoot field documentation

Claude ID: 747fc9d0-a5a2-441d-bc0a-8cd3d579a004
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
@claude
Copy link

claude bot commented Dec 3, 2025

PR Review: Auto Run Overhaul

This is a substantial feature addition that transforms the Scratchpad into a sophisticated Auto Run system with Git worktree integration, playbooks, and multi-document batch processing. Overall, the implementation is well-structured with strong security practices. Here are my findings:


Strengths

1. Excellent Security Practices

  • Path traversal protection: All file handlers properly sanitize inputs using path.basename() and validate resolved paths (src/main/index.ts:3536-3553, 3630-3660)
  • Safe command execution: Consistently uses execFileNoThrow instead of shell-based execution throughout git operations
  • Input validation: Whitelist approach for image extensions, proper filename sanitization
  • Worktree validation: Checks for same repository before operations (src/main/index.ts:1235-1246)

2. Well-Structured Architecture

  • Clean separation between main process (IPC handlers) and renderer (React components)
  • Proper use of TypeScript interfaces for type safety
  • Modal layer stack integration follows existing patterns correctly
  • Comprehensive documentation in ARCHITECTURE.md and CLAUDE.md

3. Robust Error Handling

  • IPC handlers return structured { success, error } responses consistently
  • Graceful fallbacks (e.g., src/renderer/hooks/useBatchProcessor.ts:206-211)
  • Uncommitted changes detection before git operations (src/main/index.ts:1294-1307)

4. Good UX Design

  • Real-time progress tracking with document/task counters
  • Debounced worktree validation (500ms) to avoid excessive checks
  • Auto-save with 5-second debounce
  • Visual indicators for worktree status, branch mismatches, missing documents

⚠️ Issues & Recommendations

Security Concerns

1. Image Path Validation Could Be Stronger (Medium Priority)

Location: src/main/index.ts:3683-3690

if (
  normalizedPath.includes('..') ||
  path.isAbsolute(normalizedPath) ||
  \!normalizedPath.startsWith('images/')
) {
  return { success: false, error: 'Invalid image path' };
}

Issue: On Windows, normalizedPath could use backslashes (images\\file.png), so the check \!normalizedPath.startsWith('images/') might fail.

Recommendation:

const normalized = normalizedPath.replace(/\\/g, '/');
if (\!normalized.startsWith('images/')) { ... }

2. No Size Limit for Base64 Images (Low Priority)

Location: src/main/index.ts:3663

The handler accepts unlimited base64 data, which could cause memory issues with very large images.

Recommendation: Add a reasonable size limit (e.g., 10MB):

const MAX_IMAGE_SIZE = 10 * 1024 * 1024; // 10MB
const buffer = Buffer.from(base64Data, 'base64');
if (buffer.length > MAX_IMAGE_SIZE) {
  return { success: false, error: 'Image too large' };
}

Code Quality

3. Inline require() in IPC Handler (Low Priority)

Location: src/main/index.ts:1177, 1214

const path = require('path');

Issue: Inconsistent with the rest of the file which uses ES6 imports at the top.

Recommendation: Move to top-level imports like other modules.

4. Magic Numbers in Task Counting (Low Priority)

Location: src/renderer/hooks/useBatchProcessor.ts:4-8

const UNCHECKED_TASK_REGEX = /^[\s]*-\s*\[\s*\]\s*.+$/gm;
const CHECKED_TASK_REGEX = /^(\s*-\s*)\[x\]/gim;

Issue: Case-insensitive flag i on CHECKED_TASK_REGEX but not on UNCHECKED_TASK_REGEX. This could lead to inconsistent behavior.

Recommendation: Apply consistent case handling or document the difference.

5. No Cleanup of Old Claude Sessions (Medium Priority)

Location: src/renderer/hooks/useBatchProcessor.ts:433-437

const claudeSessionIds: string[] = [];
// ...sessions accumulate
claudeSessionIds.push(result.claudeSessionId);

Issue: In loop mode with many iterations, this array grows unbounded and could consume memory.

Recommendation: Consider capping array size or clearing old entries after a threshold.

Performance

6. Sequential Task Count Loading (Medium Priority)

Location: src/renderer/components/BatchRunnerModal.tsx:185-202

for (const doc of allDocuments) {
  try {
    counts[doc] = await getDocumentTaskCount(doc);
  } catch {
    counts[doc] = 0;
  }
}

Issue: Task counts load sequentially, blocking on each file read.

Recommendation: Use Promise.all() for parallel loading:

const countPromises = allDocuments.map(async (doc) => {
  try {
    return [doc, await getDocumentTaskCount(doc)];
  } catch {
    return [doc, 0];
  }
});
const entries = await Promise.all(countPromises);
const counts = Object.fromEntries(entries);

7. Debounce Cleanup Missing Dependencies (Low Priority)

Location: src/renderer/components/BatchRunnerModal.tsx:338

return () => clearTimeout(timeoutId);

Issue: The cleanup only clears the timeout but the effect dependencies might cause stale closures.

Recommendation: This is acceptable, but consider using a ref-based approach for more complex validation logic.

Potential Bugs

8. Branch Mismatch Logic Could Fail with Empty Branch (Low Priority)

Location: src/main/index.ts:1257

branchMismatch: currentBranch \!== branchName && branchName \!== ''

Issue: If currentBranch is empty string and branchName is empty string, this evaluates correctly. However, if currentBranch is undefined, comparison fails.

Recommendation: Normalize to empty string:

const currentBranch = currentBranchResult.exitCode === 0 
  ? currentBranchResult.stdout.trim() 
  : '';

(Already done correctly at line 1250)

9. Infinite Loop Protection Could Be More Robust (Low Priority)

Location: src/renderer/hooks/useBatchProcessor.ts:578-583

The protection relies on anyTasksProcessedThisIteration, but a document could have malformed checkboxes that always report unchecked tasks without processing.

Recommendation: Add a maximum iteration counter as a safety valve:

const MAX_LOOP_ITERATIONS = 1000;
if (loopIteration > MAX_LOOP_ITERATIONS) {
  console.error('Max loop iterations exceeded - stopping');
  break;
}

Documentation

10. Missing Type Exports (Low Priority)

Location: src/renderer/types/index.ts

New types like BatchRunConfig, WorktreeConfig, Playbook are defined but not explicitly exported in a centralized way.

Recommendation: Ensure all types are exported from types/index.ts for easier imports.


📝 Minor Observations

  1. Consistent Naming: Great use of standardized terminology ("Auto Run" vs old "Scratchpad")
  2. Test Coverage: No new tests added for this substantial feature (expected for this project)
  3. Migration Path: Existing sessions with scratchpad data will smoothly transition
  4. GitHub Workflow: New auto-assign workflow is a nice touch (src/.github/workflows/auto-assign.yml)

🎯 Summary

This is a high-quality PR that adds significant value to Maestro. The security practices are excellent, the architecture follows established patterns, and the feature is well-documented.

Recommended Actions Before Merge:

  1. Must Fix: None - no blocking issues
  2. ⚠️ Should Fix:
  3. 💡 Nice to Have: Add image size limit, infinite loop protection

Approval Status: ✅ Approved with minor suggestions

The suggestions above are improvements but don't block merging. The code is production-ready as-is.


Great work on this feature! The Git worktree integration is particularly clever for enabling parallel Auto Run execution. 🚀

- Fix cloudflared not being found when running from /Applications by using
  expanded PATH (includes /opt/homebrew/bin, /usr/local/bin, etc.) in
  cliDetection.ts, matching how agent-detector.ts handles binary detection
- Cache and use full cloudflared path in tunnel-manager.ts to ensure the
  binary is found when spawning the tunnel process
- Add debugging logs for process exit events to help diagnose thinking pill
  issues (App.tsx)
- Add hint about Cmd+/ shortcut in settings modal shortcuts section
- Add Cmd+U shortcut hint to tab filter tooltip

Claude ID: 110ec97f-d876-4fb9-b577-ee7a7cd4f9e5
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
@claude
Copy link

claude bot commented Dec 3, 2025

Pull Request Review: Auto Run Overhaul

Overview

This is a substantial and well-architected feature addition that transforms the scratchpad into a file-system-based document runner with multi-document batch processing, playbooks, and Git worktree support. The PR adds ~6,400 lines across 42 files with excellent documentation and adherence to the project's security patterns.

Strengths

1. Excellent Security Practices ✅

  • Path traversal protection: All file operations properly sanitize inputs using path.basename() and validate with path.resolve()
  • Input validation: Extension whitelisting for images, filename sanitization, directory boundary checks
  • Safe command execution: Consistent use of execFileNoThrow for all Git operations

2. Robust Error Handling ✅

  • Comprehensive try-catch blocks with detailed error messages
  • Graceful degradation (empty playbooks file returns empty array)
  • Clear user feedback through logger integration
  • Proper validation of Git worktree state with uncommitted changes detection

3. Well-Designed Architecture ✅

  • Clean separation of concerns: IPC handlers, React components, business logic hooks
  • Type-safe interfaces throughout (BatchRunState, BatchDocumentEntry, WorktreeConfig, Playbook)
  • Reusable components (AutoRunDocumentSelector, PlaybookNameModal, PlaybookDeleteConfirmModal)

4. Git Worktree Integration ✅

  • Detects existing worktrees vs main repos (src/main/index.ts:1135-1196)
  • Validates branch mismatches before operations
  • Checks for uncommitted changes before checkout (lines 1294-1307)

5. Excellent Documentation ✅

  • Comprehensive ARCHITECTURE.md update with data types and execution flow
  • Updated README.md with clear user-facing documentation
  • Inline code comments explaining complex logic

Issues & Concerns

🔴 Critical: Potential Infinite Loop

Location: src/renderer/hooks/useBatchProcessor.ts:366-595

The main processing loop can potentially run forever. While there is a safety check at line 580, if the checkbox regex fails to match certain formats, tasks might appear to exist but never get processed.

Recommendation: Add a maximum iteration limit as a safety net.

🟡 Medium: Race Condition in Auto-Save

The component uses a 5-second debounce for auto-save, but rapid document switching could cause the wrong content to be saved to the wrong document.

Recommendation: Clear the debounce timer when switching documents and add document ID validation before saving.

🟡 Medium: Missing Input Validation for Git Branch Names

No validation for invalid branch name characters. Git branches cannot contain spaces, certain special characters, or start with a dash.

🟡 Medium: Worktree Cleanup Not Implemented

When a worktree is created but Auto Run is stopped or fails, there is no mechanism to clean up the worktree.

🟢 Minor: Regex Edge Cases

The unchecked regex requires at least one character after the checkbox, so empty checkboxes like - [ ] won't match. Change .+ to .* in the regex.

🟢 Minor: Image Cache Never Cleared

The image cache grows indefinitely, which could consume significant memory in long-running sessions.

Test Coverage Concerns

❌ No Tests Included: This is a large feature with complex logic, but no test files were added.

Recommendation: Add tests for path traversal attacks, checkbox regex matching, loop termination conditions, worktree state validation, and playbook CRUD operations.

Final Verdict

Overall Assessment: 🟢 Approve with Minor Concerns

This is a high-quality, production-ready feature with excellent security practices, thorough documentation, and thoughtful architecture.

Score Breakdown

  • Security: 9.5/10 (Excellent path traversal protection)
  • Architecture: 9/10 (Clean separation of concerns, good type safety)
  • Error Handling: 8.5/10 (Comprehensive, could use more edge case handling)
  • Documentation: 10/10 (Outstanding)
  • Code Quality: 9/10 (Clean, readable, follows conventions)
  • Test Coverage: 3/10 (Missing tests for critical logic)

Recommendation: Merge after addressing the infinite loop protection and auto-save race condition. The missing tests can be added in a follow-up PR if time is a constraint.

Great work! This is a substantial improvement to Maestro's automation capabilities.

…k actions

- Add Enter key support for queued message removal confirmation dialog
- Add kill process capability to System Process Monitor with confirmation
- Add toggle markdown rendering option to Cmd+K Quick Actions menu

Claude ID: d504ac29-93b3-46e9-8929-9be234bbcf07
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
@claude
Copy link

claude bot commented Dec 4, 2025

Pull Request Review

This is a massive and impressive PR that transforms the "Scratchpad" feature into a comprehensive "Auto Run" system with file-based document management, multi-document batch processing, playbooks, and Git worktree support. With 8,075 additions across 47 files, this is effectively a major feature release.

🎯 Overall Assessment

Code Quality: 8.5/10 - Well-structured, follows established patterns, excellent security practices
Architecture: 9/10 - Clean separation of concerns, thoughtful abstraction layers
Security: 9/10 - Strong input validation and path traversal protection throughout
Test Coverage: N/A - No tests visible in this PR (see recommendations)

✅ Strengths

1. Excellent Security Practices

The file operation handlers demonstrate strong security awareness:

  • ✅ Consistent use of execFileNoThrow for all git operations (42 occurrences)
  • ✅ Path traversal protection with path.resolve() + startsWith() checks
  • ✅ Filename sanitization with path.basename() and .. checks
  • ✅ Extension whitelisting for image uploads
  • ✅ Input validation on all IPC handlers

Example from autorun:readDoc (lines 3570-3588):

const sanitizedFilename = path.basename(filename);
if (sanitizedFilename \!== filename || filename.includes('..')) {
  return { success: false, content: '', error: 'Invalid filename' };
}
const resolvedPath = path.resolve(filePath);
const resolvedFolder = path.resolve(folderPath);
if (\!resolvedPath.startsWith(resolvedFolder)) {
  return { success: false, error: 'Invalid file path' };
}

2. Well-Designed Architecture

  • Clear separation between main process (IPC handlers) and renderer (React components)
  • Proper TypeScript interfaces for all data structures
  • Consistent error handling patterns with { success, error } response objects
  • Logical file organization following CLAUDE.md conventions

3. Comprehensive Feature Implementation

  • Multi-document batch processing with queue management
  • Playbook system for reusable configurations
  • Git worktree integration for parallel work
  • Per-document undo/redo with debounced snapshots
  • Auto-save with 5-second debounce
  • Image management with file-system storage

4. Documentation

  • Excellent updates to ARCHITECTURE.md with detailed Auto Run section
  • Updated CLAUDE.md with new terminology
  • Comprehensive README.md updates with usage examples
  • Clear inline comments explaining complex logic

⚠️ Issues & Recommendations

🔴 Critical Issues

1. Inconsistent require() Usage (src/main/index.ts)

The code uses require('path') inside handlers instead of the imported path module at lines 1189 and 1226.

Fix: Use the path import from line 2 throughout. This is inconsistent with the rest of the codebase.

2. Missing Error Handling in Worktree Setup (lines 1273-1285)

The worktree creation doesn't check if the branch name is empty, which could create branches with unexpected names.

Fix: Add validation before creating worktree:

if (\!branchName || branchName.trim() === '') {
  return { success: false, error: 'Branch name cannot be empty' };
}

🟡 Medium Priority Issues

3. Race Condition in Auto-Save

The 5-second debounce for auto-save could lose data if the user switches documents or closes the app before the debounce fires.

Recommendation: Add immediate save on document switch, window close/blur events, and modal close.

4. Playbook File Path Uses Session ID (lines 3816-3818)

Playbooks are stored per session ID, not per project. If a user creates a new session in the same project, they lose access to playbooks.

Recommendation: Consider using session.projectRoot hash or allow playbook sharing across sessions in the same project.

5. No Validation for Duplicate Playbook Names

The playbooks:create handler doesn't check for duplicate names, which could confuse users.

Recommendation: Add name uniqueness validation or auto-append (1), (2), etc.

6. Git Operations Lack Timeout Configuration

All git operations use execFileNoThrow without explicit timeouts. Large repositories could hang.

Recommendation: Add configurable timeouts, especially for worktree add, push, and pr create operations.

🟢 Minor Issues / Suggestions

7. Debug Logging Left in Production Code (lines 704-705, 752-755)

Consider removing or gating debug logs behind a flag in production builds.

8. Magic Numbers

  • Line 3686: Consider adding millisecond precision check for timestamp collisions
  • useBatchProcessor.ts line 23: Document max loop iterations to prevent infinite loops

9. Markdown Checkbox Regex Could Be More Robust

The regex might match unintended patterns with excessive whitespace.

Suggestion: Tighten to require reasonable formatting.

📊 Performance Considerations

✅ Good Practices

  • Debounced auto-save (5s) reduces write operations
  • Memoized document task counts
  • Layer stack for modal priority management
  • File operations are async throughout

⚠️ Potential Concerns

  1. No Rate Limiting on File Writes - User could trigger many writes rapidly through undo/redo
  2. Playbook List Loads on Every Modal Open - Consider caching with invalidation
  3. Image List Operation (lines 3755-3789) reads entire directory each time - could be slow with many images
  4. Undo History Unbounded - MAX_UNDO_HISTORY is 50 but no size limit on content

Recommendations:

  • Add rate limiting to auto-save and undo operations
  • Cache playbook list in renderer with IPC event for invalidation
  • Paginate or lazy-load images when count > 100
  • Add memory limit to undo history (e.g., max 10MB total)

🧪 Testing Recommendations

This PR has no test coverage. Given the complexity, I recommend:

  1. Unit Tests:

    • countUnfinishedTasks and uncheckAllTasks functions
    • Path sanitization helpers
    • Git worktree validation logic
  2. Integration Tests:

    • File read/write operations with path traversal attempts
    • Playbook CRUD operations
    • Multi-document batch processing flow
  3. E2E Tests:

    • Auto-save behavior across document switches
    • Undo/redo with document switching
    • Worktree setup and teardown

🔒 Security Assessment

Overall: Very Good - The security practices are significantly better than typical Electron apps.

What's Done Right:

✅ No shell injection vulnerabilities (consistent execFileNoThrow usage)
✅ Path traversal protection on all file operations
✅ Input sanitization and validation
✅ Extension whitelisting for uploads
✅ Proper use of path.resolve() and path.normalize()

Additional Security Recommendations:

  1. Add CSRF Protection for Web Server - If not already present
  2. Validate Markdown Content - Consider sanitizing or limiting markdown features to prevent XSS if rendered in web views
  3. Rate Limit IPC Handlers - Prevent renderer from DOS-ing main process
  4. Add File Size Limits - Currently no limits on document or image sizes

🎨 Code Style & Conventions

Adherence to CLAUDE.md: Excellent

✅ Uses correct terminology (Auto Run not Scratchpad)
✅ Follows established IPC handler patterns
✅ Proper TypeScript interfaces
✅ Consistent error handling
✅ Inline styles for theme colors (not Tailwind classes for colors)

Minor Style Issues:

  • Inconsistent line spacing in some handlers
  • Some deeply nested conditionals could be extracted to helper functions
  • Variable naming is generally good but some abbreviations (cwd, dir) could be more explicit

📝 Final Recommendations

Before Merge:

  1. ✅ Fix require('path') usage (lines 1189, 1226)
  2. ✅ Add branch name validation in worktree setup
  3. ✅ Add immediate save on document switch
  4. ⚠️ Consider playbook storage location (project vs session)

Post-Merge (Future PRs):

  1. Add test coverage (especially for file operations)
  2. Implement rate limiting for file operations
  3. Add timeout configuration for git operations
  4. Cache playbook list with invalidation
  5. Add file size limits
  6. Consider adding telemetry for Auto Run usage

🎉 Conclusion

This is excellent work that significantly expands Maestro's capabilities. The implementation is thoughtful, secure, and well-architected. The few issues identified are relatively minor and don't block merging, but should be addressed soon after.

The Auto Run feature is a powerful addition that will enable sophisticated workflow automation. The code demonstrates strong engineering practices, particularly around security and error handling.

Recommendation: Approve with minor changes

Great job on this massive feature! The attention to detail in security and architecture is impressive. 👏

@claude
Copy link

claude bot commented Dec 4, 2025

Pull Request Review - Auto Run Feature Overhaul

Overview

This is a substantial PR (8,086 additions across 40+ commits) that transforms the Scratchpad feature into a comprehensive Auto Run system with file-system-based document management, multi-document batch processing, playbooks, and Git worktree integration. The implementation is generally solid with good security practices, but there are several areas that need attention.

Critical Security Issues

1. Path Traversal Vulnerability in Playbook Storage

Location: src/main/index.ts:3811-3819

The sessionId parameter is not sanitized before being used in a file path. A malicious session ID could write to arbitrary locations.

Fix: Sanitize the sessionId with path.basename() and character filtering.

2. Missing Input Validation in Image Extension

Location: src/main/index.ts:3666-3677

The extension parameter is validated against a whitelist, but there is no length check.

Recommendation: Add length validation (max 10 chars).

3. Incomplete Path Validation in autorun:deleteImage

Location: src/main/index.ts:3714-3724

While this checks for .. after normalization, path normalization on Windows may not catch all traversal attempts. Also, symbolic links could bypass this check.

Recommendation: Use fs.realpath() to resolve the actual path and verify it is within the expected directory.

High Priority Issues

4. Race Condition in Worktree Setup

Location: src/main/index.ts:1223-1301

The git:worktreeSetup handler checks if a path exists, then later creates a worktree. This is susceptible to TOCTOU (time-of-check-time-of-use) race conditions.

Recommendation: Add file locking or retry logic with exponential backoff.

5. Missing Error Handling for Concurrent Document Access

Location: src/renderer/hooks/useBatchProcessor.ts

Multiple batch runs could attempt to modify the same document simultaneously. There is no file locking mechanism.

Recommendation: Add a lock file mechanism or detect concurrent modifications by checking file modification timestamps.

6. Unbounded Undo History Memory Usage

Location: src/renderer/components/AutoRun.tsx:70-71

MAX_UNDO_HISTORY = 50. Each undo state stores the full document content. For large documents (1MB), 50 entries = 50MB per document.

Recommendation: Implement diff-based undo or add total size limits.

Code Quality Issues

7. Inconsistent Error Handling

Some IPC handlers return structured errors, while others throw exceptions. This makes error handling on the renderer side unpredictable.

Recommendation: Standardize on the structured error response pattern.

8. Hardcoded require() in Handler Function

Location: src/main/index.ts:1189

The path module is already imported at the top. This local require is redundant.

9. Missing Validation on Playbook Name

Location: src/main/index.ts:3852-3867

The playbook name is never validated. Extremely long names could cause UI issues.

Recommendation: Add max length (100 chars) and whitespace validation.

10. Potential Memory Leak in Image Cache

Location: src/renderer/components/AutoRun.tsx:62

The imageCache Map grows indefinitely and never clears. Images stored as base64 can be very large.

Recommendation: Implement LRU cache with size limits.

Performance Considerations

11. Inefficient Document Task Counting

Every time the batch runner modal renders, it may re-count tasks for all documents.

Recommendation: Cache task counts and invalidate only when documents change.

12. UI Blocking in Worktree Validation

Location: src/main/index.ts:1150-1151

The UI may appear frozen during validation. Consider adding loading states.

Positive Aspects

  1. Good Security Practices: Most IPC handlers properly sanitize inputs using path.basename() and validate file extensions
  2. Consistent Use of execFileNoThrow: All git operations use the safe wrapper instead of shell commands
  3. Comprehensive Type Definitions: Strong TypeScript types throughout
  4. Well-Structured Architecture: Clear separation between main and renderer processes
  5. Good Documentation: ARCHITECTURE.md and CLAUDE.md updates are thorough
  6. Feature-Rich: Playbooks, multi-document support, and worktree integration are well-designed

Minor Issues

  • Line 703-708: Debug logging could be removed in production
  • Line 1189, 1226: Redundant require('path') calls
  • Missing JSDoc comments on complex functions
  • No test coverage mentioned for new IPC handlers

Recommendations Summary

Must Fix Before Merge:

  1. Fix playbook path traversal vulnerability
  2. Add proper path validation in deleteImage with realpath

Should Fix:
3. Add input validation for image extension length
4. Standardize error handling across IPC handlers
5. Implement undo history size limits
6. Add playbook name validation

Nice to Have:
7. Add file locking for concurrent access
8. Implement image cache limits
9. Add race condition handling for worktree setup
10. Remove debug logging

Test Coverage Suggestions

This PR would benefit from:

  • Integration tests for git worktree operations
  • Unit tests for path sanitization functions
  • End-to-end tests for multi-document batch processing
  • Security tests for path traversal attempts

Overall, this is an impressive feature addition with solid architecture. The main concerns are the security issues around path handling, which should be addressed before merging. Once those are fixed, this will be a great addition to Maestro.

Great work on the extensive feature set!

…vements

- Add recursive subfolder scanning with tree display in document selector
- Add folder selector in Create Document modal for creating docs in subfolders
- Add loop max control (infinity/max toggle with slider, max 25 iterations)
- Update info panel: document progress bars, "Loop X of Y" display
- Re-scan documents at start of each loop for fresh task counts
- Improve slider UX (larger infinity symbol, wider slider)

Claude ID: {{CLAUDE_SESSION_ID}}
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
@claude
Copy link

claude bot commented Dec 4, 2025

Pull Request Review

This is an impressive and comprehensive PR that implements a complete Auto Run system overhaul. The changes are well-structured and follow the project's conventions. Here's my detailed review:


🎯 Overall Assessment

Scope: 47 files, 8,348 additions
Impact: Major feature addition with extensive architectural changes
Code Quality: ✅ Generally excellent with strong security practices


✅ Strengths

1. Excellent Security Practices

The Auto Run IPC handlers demonstrate robust security measures:

  • Path traversal protection on all file operations (lines 3620-3636, 3663-3680, 3772-3789 in src/main/index.ts)
  • Input sanitization using path.basename() and validation (lines 3719-3730)
  • Allowlist validation for image extensions (lines 3726-3730)
  • Proper use of execFileNoThrow for Git commands (no shell injection vulnerabilities)
  • Path resolution verification to ensure files stay within intended directories

2. Comprehensive Error Handling

  • Consistent structured responses with { success, error } pattern
  • Proper async/await with try-catch blocks throughout
  • Graceful fallbacks (e.g., git:getDefaultBranch trying multiple strategies)
  • Detailed error logging with context

3. Well-Structured Architecture

  • Clear separation of concerns (IPC handlers, React components, hooks)
  • Consistent TypeScript interfaces (BatchRunConfig, WorktreeConfig, Playbook)
  • Good use of React patterns (hooks, memoization, refs)
  • Layer stack integration for modal priority management

4. Documentation

  • ✅ Updated ARCHITECTURE.md with comprehensive Auto Run documentation
  • ✅ Updated CLAUDE.md with standardized terminology
  • ✅ Updated README.md with feature details and usage instructions
  • Clear inline comments explaining complex logic (e.g., worktree detection logic at lines 1185-1196)

⚠️ Areas of Concern

1. Performance - Large State Objects

Issue: BatchRunnerModal.tsx has 31 useState declarations and 9 useEffect hooks

  • Lines 124-188: Extensive state management
  • Risk: Potential re-render cascades and state synchronization issues

Recommendation:

// Consider using useReducer for related state
type BatchRunnerState = {
  documents: BatchDocumentEntry[];
  taskCounts: Record<string, number>;
  worktree: WorktreeState;
  playbook: PlaybookState;
  // ... grouped state
};

const [state, dispatch] = useReducer(batchRunnerReducer, initialState);

2. Missing Input Validation

File: src/main/index.ts:3658-3705 (autorun:writeDoc)

Issue: No validation of content parameter:

  • Could accept extremely large payloads (DoS risk)
  • No content sanitization

Recommendation:

// Add size limit
if (content.length > 10_000_000) { // 10MB limit
  return { success: false, error: 'Content too large' };
}

3. Race Condition Risk

File: src/main/index.ts:1273-1301 (git:worktreeSetup)

Issue: Check-then-act pattern between lines 1275-1285:

const branchExistsResult = await execFileNoThrow(...); // Check
const branchExists = branchExistsResult.exitCode === 0;
// ... later ...
createResult = await execFileNoThrow('git', ['worktree', 'add', ...]); // Act

Impact: Concurrent calls could attempt to create the same worktree/branch
Recommendation: Consider file locking or serialization for worktree operations per repository

4. Error Messages Leak Path Information

File: src/main/index.ts:3636-3637, 3679-3680

Issue:

if (\!resolvedPath.startsWith(resolvedFolder + path.sep)) {
  return { success: false, content: '', error: 'Invalid file path' };
}

Concern: Error messages could leak filesystem structure in logs
Recommendation: Ensure these paths aren't exposed to untrusted clients (appears OK for desktop app context)

5. Debug Logging Left in Production Code

File: src/main/index.ts:703-755

logger.debug('[Sessions:setAll] Received sessions with autoRunFolderPaths:', ...);
logger.debug('[Sessions:setAll] After store, autoRunFolderPaths:', ...);

Recommendation: Remove or ensure debug logs are disabled in production builds

6. Potential Memory Leak

File: src/renderer/hooks/useBatchProcessor.ts

Issue: The hook manages batchRunStates as state but doesn't provide cleanup mechanism
Recommendation: Add cleanup on session removal to prevent stale state accumulation


🐛 Potential Bugs

1. Path Separator Edge Case

File: src/main/index.ts:3635

if (\!resolvedPath.startsWith(resolvedFolder + path.sep)) { ... }

Issue: Fails when resolvedPath === resolvedFolder (file at root of folder)
Fix: Should be || resolvedPath \!== resolvedFolder (already correct elsewhere at line 3678)
Status: ✅ Actually handled correctly with the additional check on line 3635-3636

2. Missing Null Check

File: src/main/index.ts:1189

const path = require('path'); // Redeclaring path module

Issue: Shadows imported path module
Fix: Use the already imported path from top of file


🧪 Test Coverage

Critical Areas Needing Tests:

  1. Security Tests

    • Path traversal attempts in autorun:readDoc/writeDoc
    • Malicious filenames with ../, absolute paths, etc.
  2. Git Worktree Tests

    • Concurrent worktree creation
    • Branch mismatch scenarios
    • Uncommitted changes detection
  3. Batch Processor Tests

    • Loop mode with reset-on-completion
    • Stop during multi-document processing
    • Document with zero tasks (should skip)
  4. Edge Cases

    • Empty folder for Auto Run
    • Invalid markdown syntax
    • Extremely long document names

🎨 Code Quality Suggestions

1. Magic Numbers

// Line 286 in BatchRunnerModal.tsx
useEffect(() => {
  const timer = setTimeout(() => {
    // Debounce validation
  }, 500); // Magic number

Recommendation:

const WORKTREE_VALIDATION_DEBOUNCE_MS = 500;

2. Simplify Complex Conditionals

File: src/main/index.ts:3774-3778

if (
  normalizedPath.includes('..') ||
  path.isAbsolute(normalizedPath) ||
  \!normalizedPath.startsWith('images/')
) { ... }

Recommendation: Extract to named function:

const isValidImagePath = (relativePath: string): boolean => {
  const normalized = path.normalize(relativePath);
  return \!normalized.includes('..') && 
         \!path.isAbsolute(normalized) && 
         normalized.startsWith('images/');
};

3. Type Safety

Multiple uses of any[] in playbook handlers (lines 3913, 3933, etc.)
Recommendation: Define PlaybookDocumentEntry[] type explicitly


📊 Performance Considerations

1. Recursive Directory Scanning

File: src/main/index.ts:3549-3588

  • ✅ Good: Filters hidden files
  • ⚠️ Concern: No depth limit (could hang on deep directories)

Recommendation:

const scanDirectory = async (dirPath: string, relativePath: string = '', depth = 0): Promise<TreeNode[]> => {
  if (depth > MAX_FOLDER_DEPTH) return []; // Add limit
  // ...
}

2. Debounce Auto-Save

✅ Well implemented at 5 seconds (mentioned in README)
✅ Uses proper cleanup in useEffect


🔒 Security Summary

Area Status Notes
Path Traversal ✅ Excellent Multiple layers of protection
Command Injection ✅ Excellent Uses execFileNoThrow correctly
Input Validation ⚠️ Good Missing content size limits
Error Exposure ✅ Acceptable No sensitive data in errors
Access Control ✅ Good Desktop app context appropriate

🎯 Final Recommendations

Must Fix Before Merge:

  1. Remove const path = require('path') on line 1189 (shadows import)
  2. Add content size validation to autorun:writeDoc
  3. Remove debug logging or ensure it's production-safe

Should Fix Soon:

  1. Consider refactoring BatchRunnerModal state management with useReducer
  2. Add serialization/locking for worktree operations
  3. Add depth limit to recursive directory scanning

Nice to Have:

  1. Extract magic numbers to named constants
  2. Add comprehensive test coverage for security scenarios
  3. Improve type safety (replace any[] with proper types)

🏆 Conclusion

This is a well-crafted PR that demonstrates:

  • Strong security awareness
  • Thorough error handling
  • Excellent documentation
  • Consistent coding patterns

The Auto Run feature is production-ready with minor fixes. The architecture is solid and extensible for future enhancements.

Recommendation:Approve with minor changes

Great work on this comprehensive feature! The attention to security details is particularly commendable. 🎉

When sending a slash command (e.g., /commit) while the session was idle,
the command would appear both as a sent message AND in the QUEUED section.
This happened because the code was adding the item to executionQueue and
immediately processing it, but the queue item wasn't removed until exit.

The fix simply doesn't add to the queue when processing immediately since
the item isn't actually queued - it's being executed right away.

Claude ID: {{CLAUDE_SESSION_ID}}
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
@pedramamini pedramamini merged commit 9b9f184 into main Dec 4, 2025
1 check passed
@pedramamini pedramamini deleted the autorun-overhaul branch December 4, 2025 11:27
@claude
Copy link

claude bot commented Dec 4, 2025

Code Review: Auto Run Overhaul

This is a substantial and well-architected feature addition that transforms the scratchpad into a powerful file-based document runner. Overall, the implementation is solid with good attention to detail.


Architecture & Design

Strengths:

  • Excellent separation of concerns: The batch processor logic is cleanly isolated in useBatchProcessor.ts, making it testable and maintainable
  • Git worktree integration: Clever use of worktrees for true parallelization without file conflicts (src/main/index.ts:1144-1430)
  • Playbook persistence: Well-designed save/load system for batch configurations
  • Multi-document support: Clean abstraction with BatchDocumentEntry supporting duplicates, reset-on-completion, and flexible ordering
  • Loop mode with safety: Proper infinite loop prevention through non-reset document tracking (useBatchProcessor.ts:583-607)

Documentation:

  • The ARCHITECTURE.md additions are comprehensive and provide excellent guidance (ARCHITECTURE.md:598-775)
  • CLAUDE.md updates maintain consistency with existing conventions

Potential Issues

1. Error Handling in Git Worktree Operations

Location: src/main/index.ts:1224-1430

The worktree setup has comprehensive validation, but path resolution could fail on malformed paths.

Recommendation: Add try-catch around path operations and validate that paths are within expected bounds to prevent directory traversal issues.

2. Race Condition in Batch Processing

Location: useBatchProcessor.ts:446-470

When re-reading documents after task completion, there is a potential race if the file is modified externally.

Recommendation: Consider adding file watch timestamps or checksums to detect external modifications and warn the user.

3. Console Logging Proliferation

Issue: 374 console.log/warn/error statements across the codebase

While debugging statements are helpful during development, production code should use the logger system.

Recommendation: Replace console statements with the existing logger system, especially in main process handlers.

4. Memory Leak Risk in Image Cache

Location: AutoRun.tsx:64

The image cache grows unbounded and stores base64 strings in memory. With many images, this could cause memory issues.

Recommendation: Implement cache eviction (LRU) or size limits, especially for long-running sessions.


Security Considerations

1. Path Traversal Prevention - CRITICAL

Location: src/main/index.ts:1356-1370

The autorun file operations need validation to ensure files are within the specified folder. User input is used directly in file paths without bounds checking.

Recommendation: Add validation before file operations to prevent directory traversal attacks.

2. Command Injection in Branch Names

Location: BatchRunnerModal.tsx:179

User-provided branch names are passed to git commands. While execFileNoThrow provides protection, branch names should still be validated.

Recommendation: Add branch name validation (alphanumeric, hyphens, underscores only).


Performance Considerations

1. Sequential Document Processing

Location: useBatchProcessor.ts:381-559

Documents are processed strictly sequentially, even when worktrees are used.

Consideration: With worktrees enabling true isolation, consider offering parallel document processing as an advanced option.

2. Task Count Recalculation

Location: useBatchProcessor.ts:314-317

Initial total task calculation reads all documents sequentially and could be parallelized with Promise.all().

3. Unnecessary Re-renders

Location: BatchRunnerModal.tsx:106-200

Many state variables without memoization could cause unnecessary re-renders in a complex modal.

Recommendation: Consider using useMemo for derived values and useCallback for event handlers.


Test Coverage

Observation: The PR adds 8351 lines with significant complexity, but no test files are visible.

Recommendations:

  • Unit tests for countUnfinishedTasks() and uncheckAllTasks() functions
  • Integration tests for worktree setup/teardown
  • Tests for loop mode exit conditions (especially the infinite loop prevention)
  • Tests for playbook CRUD operations
  • Mock-based tests for batch processor state machine

Code Quality

1. TODOs in Production Code

Found in src/renderer/App.tsx:3735 and src/renderer/hooks/useSessionManager.ts:261

Recommendation: Resolve TODOs before merging or create tracked issues.

2. Magic Numbers

Constants like MAX_UNDO_HISTORY should be extracted to a constants file for easier configuration.

3. Type Safety

Use proper TypeScript types throughout (found theme: any in BatchRunnerModal.tsx:87).


What Works Well

  1. Default prompt template: Comprehensive and well-structured with clear instructions
  2. Synopsis parsing: Robust handling of AI responses with fallbacks
  3. Drag-and-drop document ordering: Intuitive UX for batch configuration
  4. PR auto-creation: Seamless integration with GitHub workflow
  5. Progress tracking: Detailed document and task-level progress with visual feedback
  6. Undo/redo system: Proper history management with cursor position tracking
  7. Image paste support: Native clipboard integration with automatic storage

Summary

  • Architecture: Excellent
  • Security: Needs validation improvements (CRITICAL)
  • Performance: Good, optimization opportunities exist
  • Test Coverage: Missing
  • Documentation: Comprehensive
  • Error Handling: Some gaps in edge cases

Recommendations for Merge

Must Fix Before Merge:

  1. Add path traversal validation to autorun file operations (SECURITY)
  2. Resolve or track all TODO comments
  3. Add branch name validation for git operations

Should Fix Before Merge:
4. Replace console.log statements with logger
5. Implement image cache size limits
6. Add error handling for edge cases in worktree operations

Nice to Have (Can defer to follow-up PRs):
7. Add unit tests for core batch processing logic
8. Parallelize task count calculation
9. Consider parallel document processing option
10. Extract magic numbers to constants


Final Thoughts

This is high-quality work that adds significant value to Maestro. The architecture is sound, the feature is well-designed, and the documentation is excellent. The main concerns are around security validation, testing, and production-ready error handling. With the critical path traversal validation and TODO resolution, this would be ready to merge.

Great job on the worktree integration - that is a sophisticated solution to enable true parallelization!

@claude claude bot mentioned this pull request Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments