# Requirements Document - Workflow Detection Fix

## Introduction

This document specifies the requirements for fixing the workflow detection system in GeniusIA v2. The system currently fails to detect workflows because the SessionManager and WorkflowDetector components are not integrated into the main Orchestrator, and there is a critical bug in VisionAnalysis that prevents action analysis.

## Glossary

- **Orchestrator**: The main cognitive loop that coordinates all system components
- **SessionManager**: Component that segments user actions into logical sessions
- **WorkflowDetector**: Component that identifies repeated patterns in sessions
- **VisionAnalysis**: Component that analyzes visual regions around user actions
- **SuggestionManager**: Component that generates suggestions based on detected workflows
- **Action**: A user interaction event (click, keypress, etc.)
- **Session**: A group of related actions within a time window
- **Workflow**: A repeated pattern of actions that can be automated

## Requirements

### Requirement 1

**User Story:** As a user, I want the system to detect my repeated action sequences, so that it can learn my workflows and suggest automations.

#### Acceptance Criteria

1. WHEN the Orchestrator processes user actions THEN the system SHALL pass those actions to the SessionManager for segmentation
2. WHEN the SessionManager receives actions THEN the system SHALL group them into sessions based on time windows and window context
3. WHEN a session is completed THEN the system SHALL pass it to the WorkflowDetector for pattern analysis
4. WHEN the WorkflowDetector identifies a repeated pattern THEN the system SHALL notify the SuggestionManager
5. WHEN the SuggestionManager receives a workflow notification THEN the system SHALL generate appropriate suggestions for the user

### Requirement 2

**User Story:** As a developer, I want the VisionAnalysis component to work correctly, so that action signatures can be created and compared.

#### Acceptance Criteria

1. WHEN VisionAnalysis analyzes an action THEN the system SHALL use the correct attribute name for the LLM manager
2. WHEN VisionAnalysis encounters an error THEN the system SHALL log the error and continue processing
3. WHEN VisionAnalysis creates an action signature THEN the system SHALL include visual embeddings and element descriptions

### Requirement 3

**User Story:** As a user, I want the system to persist detected workflows, so that they are available across sessions.

#### Acceptance Criteria

1. WHEN a workflow is detected THEN the system SHALL save it to the user profile directory
2. WHEN the system starts THEN the system SHALL load previously detected workflows
3. WHEN a workflow is executed successfully THEN the system SHALL update its confidence score

### Requirement 4

**User Story:** As a developer, I want comprehensive logging of the workflow detection process, so that I can debug issues.

#### Acceptance Criteria

1. WHEN actions are segmented into sessions THEN the system SHALL log session creation with action count
2. WHEN workflows are detected THEN the system SHALL log workflow details including pattern and confidence
3. WHEN workflow detection fails THEN the system SHALL log the error with context
