Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .agent-os/specs/2025-07-22-phase1-completion/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ These are the tasks to be completed for the spec detailed in @.agent-os/specs/20
- [x] 1.5 Ensure session statistics preservation during pause state
- [x] 1.6 Verify all tests pass and UI responds correctly

- [ ] 2. **🚨 EMERGENCY: Enhance Emergency Stop System** (HIGH PRIORITY)
- [ ] 2.1 Write tests for enhanced emergency stop functionality
- [ ] 2.2 Implement multiple emergency stop key options (ESC, F1, Cmd+Period, Space)
- [ ] 2.3 Add configurable emergency stop key selection in settings
- [ ] 2.4 Implement immediate stop with <50ms response time guarantee
- [ ] 2.5 Add visual confirmation of emergency stop activation
- [ ] 2.6 Ensure emergency stop works even when app is in background
- [ ] 2.7 Add emergency stop status to automation panel and overlay
- [ ] 2.8 Verify emergency stop reliability across all automation states
- [x] 2. **🚨 EMERGENCY: Enhance Emergency Stop System** (HIGH PRIORITY)
- [x] 2.1 Write tests for enhanced emergency stop functionality
- [x] 2.2 Implement multiple emergency stop key options (ESC, F1, Cmd+Period, Space)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The task list here is slightly inconsistent with the implementation and the PR description. The DELETE key is supported as an emergency stop option in the code, but it's missing from this list. It's good practice to keep documentation and task lists aligned with the final implementation.

Suggested change
- [x] 2.2 Implement multiple emergency stop key options (ESC, F1, Cmd+Period, Space)
- [x] 2.2 Implement multiple emergency stop key options (ESC, F1, Cmd+Period, Space, DELETE)

- [x] 2.3 Add configurable emergency stop key selection in settings
- [x] 2.4 Implement immediate stop with <50ms response time guarantee
- [x] 2.5 Add visual confirmation of emergency stop activation
- [x] 2.6 Ensure emergency stop works even when app is in background
- [x] 2.7 Add emergency stop status to automation panel and overlay
- [x] 2.8 Verify emergency stop reliability across all automation states

- [ ] 3. **Build Enhanced Preset Management System**
- [ ] 3.1 Write tests for PresetManager and PresetConfiguration data structures
Expand Down
62 changes: 62 additions & 0 deletions Sources/ClickIt/Core/Click/ClickCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class ClickCoordinator: ObservableObject {
/// Current click session state
@Published var isActive: Bool = false

/// Pause state for automation
@Published var isPaused: Bool = false

/// Click statistics
@Published var clickCount: Int = 0
@Published var successRate: Double = 1.0
Expand Down Expand Up @@ -88,6 +91,7 @@ class ClickCoordinator: ObservableObject {
}

isActive = false
isPaused = false // Clear pause state when stopping
automationTask?.cancel()
automationTask = nil

Expand All @@ -103,6 +107,58 @@ class ClickCoordinator: ObservableObject {
print("ClickCoordinator: stopAutomation() completed")
}

/// EMERGENCY PRIORITY: Immediate automation termination for <50ms response guarantee
func emergencyStopAutomation() {
print("ClickCoordinator: EMERGENCY STOP - immediate termination")

// Critical: Set inactive state first to prevent any new operations
isActive = false
isPaused = false

// Immediate task cancellation without waiting
automationTask?.cancel()
automationTask = nil

// Priority cleanup - all operations must be synchronous for speed
timeManager.stopTracking()
VisualFeedbackOverlay.shared.hideOverlay()
automationConfig = nil

print("ClickCoordinator: EMERGENCY STOP completed")
}

/// Pauses the current automation session
func pauseAutomation() {
guard isActive && !isPaused else {
print("ClickCoordinator: pauseAutomation() - not active or already paused")
return
}

print("ClickCoordinator: pauseAutomation() called")
isPaused = true

// Pause elapsed time tracking
timeManager.pauseTracking()

print("ClickCoordinator: automation paused")
}

/// Resumes the current automation session
func resumeAutomation() {
guard isActive && isPaused else {
print("ClickCoordinator: resumeAutomation() - not active or not paused")
return
}

print("ClickCoordinator: resumeAutomation() called")
isPaused = false

// Resume elapsed time tracking
timeManager.resumeTracking()

print("ClickCoordinator: automation resumed")
}

/// Performs a single click with the given configuration
/// - Parameter configuration: Click configuration
/// - Returns: Result of the click operation
Expand Down Expand Up @@ -206,6 +262,12 @@ class ClickCoordinator: ObservableObject {
/// - Parameter configuration: Automation configuration
private func runAutomationLoop(configuration: AutomationConfiguration) async {
while isActive && !Task.isCancelled {
// Skip execution if paused, but continue loop
if isPaused {
try? await Task.sleep(nanoseconds: 50_000_000) // 50ms pause check interval
continue
}

let result = await executeAutomationStep(configuration: configuration)

if !result.success {
Expand Down
Loading
Loading