Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
96 changes: 87 additions & 9 deletions .cursor/rules/execute-tasks.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,43 @@ alwaysApply: true
- Direct copy/paste operations
- Immediate answers to factual questions

### 🔍 SESSION AWARENESS & WORKFLOW DISCOVERY
**⚠️ MANDATORY PRE-WORKFLOW CHECK:** Before starting ANY new workflow, check for existing sessions:**

#### STEP 0: CHECK EXISTING SESSIONS (REQUIRED FIRST STEP)
```
workflow_cache_management(operation="list")
```
**Purpose:** Check for existing workflow sessions to avoid conflicts and enable session resumption
**Results:**
- **Active Session Found & Applicable:** Resume existing workflow using its session_id
- **Active Session Found & NOT Applicable:** Start new workflow for current task
- **No Active Sessions:** Proceed to workflow discovery
- **Multiple Sessions:** Choose appropriate session, complete irrelevant ones, or start new

#### Session Applicability Assessment:
Before resuming any existing session, verify:
- Is the existing workflow relevant to the current task?
- Are you continuing the same work or starting something different?
- **If the task is different or unrelated → START NEW WORKFLOW**

#### Session Resumption Pattern:
If existing session found AND applicable to current task, resume with:
```
workflow_guidance(session_id="found-session-id", action="next", context='{"choose": "current_node"}')
```

#### Session Conflict Resolution:
If multiple active sessions exist:
1. **Check session status** with `workflow_cache_management(operation="list")`
2. **Evaluate session relevance** to current task
3. **CRITICAL:** Only resume if directly related to current task
4. **If unrelated:** Complete or abandon existing sessions and start new workflow

### 🔄 MANDATORY WORKFLOW ENTRY PROCESS
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, you MUST follow this exact sequence:
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, follow this exact sequence:

#### STEP 1: DISCOVER (REQUIRED FIRST STEP)
#### STEP 1: DISCOVER (REQUIRED AFTER SESSION CHECK)
```
workflow_discovery(task_description="[Exact user request]")
```
Expand Down Expand Up @@ -74,19 +107,64 @@ The workflow system operates on these principles:
5. **No Hardcoded Routes**: All transitions defined in YAML `next_allowed_nodes`

### 📋 Available Workflow Tools
- `workflow_discovery` - **START HERE ALWAYS** - Discover available YAML workflows
- `workflow_cache_management` - **CHECK FIRST ALWAYS** - List and manage cached sessions for conflict resolution
- `workflow_discovery` - **START HERE FOR NEW WORKFLOWS** - Discover available YAML workflows
- `workflow_guidance` - Main execution engine for dynamic workflows
- `workflow_state` - Check and update current workflow state
- `workflow_state` - Check specific session state (requires session_id)
- `workflow_creation_guidance` - Create custom workflows when existing ones don't fit

### 📚 Supporting Tools
- Context7: Real-time documentation lookup
- GitHub: Repository file access
- Standard coding tools: file operations, terminal, search, etc.

### 🆔 SESSION ID MANAGEMENT
**All workflows auto-generate unique session IDs for multi-session support:**

#### Session ID Usage Patterns:
```
# Check existing sessions first (MANDATORY)
workflow_cache_management(operation="list")

# If no active sessions, start new workflow
workflow_discovery(task_description="Your task")
workflow_guidance(action="start", context="workflow: Selected Workflow")

# Continue with session_id for targeted operations (returned in response)
workflow_guidance(session_id="abc-123", action="next", context='{"choose": "option"}')
workflow_state(session_id="abc-123", operation="get")
```

#### Multi-Session Benefits:
- **Parallel Workflows**: Run multiple workflows simultaneously
- **Session Continuity**: Resume specific workflows after interruption
- **Session Isolation**: Keep different tasks completely separate
- **Session Tracking**: Monitor progress of individual workflows

#### Session Discovery Commands:
```
# List all cached sessions for current client (DISCOVERY PRIMARY METHOD)
workflow_cache_management(operation="list")

# Get specific session state
workflow_state(session_id="session-id", operation="get")

# Restore sessions from cache after restart
workflow_cache_management(operation="restore")
```

#### Best Practices:
- **ALWAYS check existing sessions BEFORE starting new workflows**
- **ALWAYS save session_id** from workflow start responses
- **ALWAYS include session_id** in subsequent workflow calls when available
- **Use session_id** when managing multiple concurrent workflows
- **Check session cache** after MCP server restarts for workflow continuity

### ⚡ Enforcement Rules
1. **NEVER skip workflow discovery** for multi-step tasks
2. **ALWAYS start with `workflow_discovery()`** before other workflow tools
3. **NEVER use legacy approaches** when workflow tools are available
4. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
5. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)
1. **NEVER skip session checking** before starting workflows
2. **ALWAYS start with `workflow_cache_management(operation="list")`** for session awareness
3. **ALWAYS use `workflow_discovery()`** for new workflows after session check
4. **NEVER use legacy approaches** when workflow tools are available
5. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
6. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)
7. **ALWAYS handle session conflicts** before proceeding with new workflows
168 changes: 136 additions & 32 deletions src/accordo_cli/utils/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,43 @@ class BootstrapManager:
- Direct copy/paste operations
- Immediate answers to factual questions

### 🔍 SESSION AWARENESS & WORKFLOW DISCOVERY
**⚠️ MANDATORY PRE-WORKFLOW CHECK:** Before starting ANY new workflow, check for existing sessions:**

#### STEP 0: CHECK EXISTING SESSIONS (REQUIRED FIRST STEP)
```
workflow_cache_management(operation="list")
```
**Purpose:** Check for existing workflow sessions to avoid conflicts and enable session resumption
**Results:**
- **Active Session Found & Applicable:** Resume existing workflow using its session_id
- **Active Session Found & NOT Applicable:** Start new workflow for current task
- **No Active Sessions:** Proceed to workflow discovery
- **Multiple Sessions:** Choose appropriate session, complete irrelevant ones, or start new

#### Session Applicability Assessment:
Before resuming any existing session, verify:
- Is the existing workflow relevant to the current task?
- Are you continuing the same work or starting something different?
- **If the task is different or unrelated → START NEW WORKFLOW**

#### Session Resumption Pattern:
If existing session found AND applicable to current task, resume with:
```
workflow_guidance(session_id="found-session-id", action="next", context='{"choose": "current_node"}')
```

#### Session Conflict Resolution:
If multiple active sessions exist:
1. **Check session status** with `workflow_cache_management(operation="list")`
2. **Evaluate session relevance** to current task
3. **CRITICAL:** Only resume if directly related to current task
4. **If unrelated:** Complete or abandon existing sessions and start new workflow

### 🔄 MANDATORY WORKFLOW ENTRY PROCESS
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, you MUST follow this exact sequence:
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, follow this exact sequence:

#### STEP 1: DISCOVER (REQUIRED FIRST STEP)
#### STEP 1: DISCOVER (REQUIRED AFTER SESSION CHECK)
```
workflow_discovery(task_description="[Exact user request]")
```
Expand Down Expand Up @@ -90,33 +123,30 @@ class BootstrapManager:
5. **No Hardcoded Routes**: All transitions defined in YAML `next_allowed_nodes`

### 📋 Available Workflow Tools
- `workflow_discovery` - **START HERE ALWAYS** - Discover available YAML workflows
- `workflow_cache_management` - **CHECK FIRST ALWAYS** - List and manage cached sessions for conflict resolution
- `workflow_discovery` - **START HERE FOR NEW WORKFLOWS** - Discover available YAML workflows
- `workflow_guidance` - Main execution engine for dynamic workflows
- `workflow_state` - Check and update current workflow state
- `workflow_state` - Check specific session state (requires session_id)
- `workflow_creation_guidance` - Create custom workflows when existing ones don't fit

### 📚 Supporting Tools
- Context7: Real-time documentation lookup
- GitHub: Repository file access
- Standard coding tools: file operations, terminal, search, etc.

### ⚡ Enforcement Rules
1. **NEVER skip workflow discovery** for multi-step tasks
2. **ALWAYS start with `workflow_discovery()`** before other workflow tools
3. **NEVER use legacy approaches** when workflow tools are available
4. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
5. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)

### 🆔 SESSION ID MANAGEMENT (NEW)
### 🆔 SESSION ID MANAGEMENT
**All workflows auto-generate unique session IDs for multi-session support:**

#### Session ID Usage Patterns:
```
# Start workflow - returns session_id in response
# Check existing sessions first (MANDATORY)
workflow_cache_management(operation="list")

# If no active sessions, start new workflow
workflow_discovery(task_description="Your task")
workflow_guidance(action="start", context="workflow: Selected Workflow")

# Continue with session_id for targeted operations
# Continue with session_id for targeted operations (returned in response)
workflow_guidance(session_id="abc-123", action="next", context='{"choose": "option"}')
workflow_state(session_id="abc-123", operation="get")
```
Expand All @@ -127,11 +157,33 @@ class BootstrapManager:
- **Session Isolation**: Keep different tasks completely separate
- **Session Tracking**: Monitor progress of individual workflows

#### Session Discovery Commands:
```
# List all cached sessions for current client (DISCOVERY PRIMARY METHOD)
workflow_cache_management(operation="list")

# Get specific session state
workflow_state(session_id="session-id", operation="get")

# Restore sessions from cache after restart
workflow_cache_management(operation="restore")
```

#### Best Practices:
- **ALWAYS check existing sessions BEFORE starting new workflows**
- **ALWAYS save session_id** from workflow start responses
- **ALWAYS include session_id** in subsequent workflow calls
- **ALWAYS include session_id** in subsequent workflow calls when available
- **Use session_id** when managing multiple concurrent workflows
- **Fallback handling**: System supports backward compatibility without session_id"""
- **Check session cache** after MCP server restarts for workflow continuity

### ⚡ Enforcement Rules
1. **NEVER skip session checking** before starting workflows
2. **ALWAYS start with `workflow_cache_management(operation="list")`** for session awareness
3. **ALWAYS use `workflow_discovery()`** for new workflows after session check
4. **NEVER use legacy approaches** when workflow tools are available
5. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
6. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)
7. **ALWAYS handle session conflicts** before proceeding with new workflows"""

# Core content without YAML frontmatter for other assistants
CORE_CONTENT = """## Task Execution Guidelines
Expand All @@ -154,10 +206,43 @@ class BootstrapManager:
- Direct copy/paste operations
- Immediate answers to factual questions

### 🔍 SESSION AWARENESS & WORKFLOW DISCOVERY
**⚠️ MANDATORY PRE-WORKFLOW CHECK:** Before starting ANY new workflow, check for existing sessions:**

#### STEP 0: CHECK EXISTING SESSIONS (REQUIRED FIRST STEP)
```
workflow_cache_management(operation="list")
```
**Purpose:** Check for existing workflow sessions to avoid conflicts and enable session resumption
**Results:**
- **Active Session Found & Applicable:** Resume existing workflow using its session_id
- **Active Session Found & NOT Applicable:** Start new workflow for current task
- **No Active Sessions:** Proceed to workflow discovery
- **Multiple Sessions:** Choose appropriate session, complete irrelevant ones, or start new

#### Session Applicability Assessment:
Before resuming any existing session, verify:
- Is the existing workflow relevant to the current task?
- Are you continuing the same work or starting something different?
- **If the task is different or unrelated → START NEW WORKFLOW**

#### Session Resumption Pattern:
If existing session found AND applicable to current task, resume with:
```
workflow_guidance(session_id="found-session-id", action="next", context='{"choose": "current_node"}')
```

#### Session Conflict Resolution:
If multiple active sessions exist:
1. **Check session status** with `workflow_cache_management(operation="list")`
2. **Evaluate session relevance** to current task
3. **CRITICAL:** Only resume if directly related to current task
4. **If unrelated:** Complete or abandon existing sessions and start new workflow

### 🔄 MANDATORY WORKFLOW ENTRY PROCESS
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, you MUST follow this exact sequence:
**⚠️ NON-NEGOTIABLE:** For ALL qualifying tasks, follow this exact sequence:

#### STEP 1: DISCOVER (REQUIRED FIRST STEP)
#### STEP 1: DISCOVER (REQUIRED AFTER SESSION CHECK)
```
workflow_discovery(task_description="[Exact user request]")
```
Expand Down Expand Up @@ -205,33 +290,30 @@ class BootstrapManager:
5. **No Hardcoded Routes**: All transitions defined in YAML `next_allowed_nodes`

### 📋 Available Workflow Tools
- `workflow_discovery` - **START HERE ALWAYS** - Discover available YAML workflows
- `workflow_cache_management` - **CHECK FIRST ALWAYS** - List and manage cached sessions for conflict resolution
- `workflow_discovery` - **START HERE FOR NEW WORKFLOWS** - Discover available YAML workflows
- `workflow_guidance` - Main execution engine for dynamic workflows
- `workflow_state` - Check and update current workflow state
- `workflow_state` - Check specific session state (requires session_id)
- `workflow_creation_guidance` - Create custom workflows when existing ones don't fit

### 📚 Supporting Tools
- Context7: Real-time documentation lookup
- GitHub: Repository file access
- Standard coding tools: file operations, terminal, search, etc.

### ⚡ Enforcement Rules
1. **NEVER skip workflow discovery** for multi-step tasks
2. **ALWAYS start with `workflow_discovery()`** before other workflow tools
3. **NEVER use legacy approaches** when workflow tools are available
4. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
5. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)

### 🆔 SESSION ID MANAGEMENT (NEW)
### 🆔 SESSION ID MANAGEMENT
**All workflows auto-generate unique session IDs for multi-session support:**

#### Session ID Usage Patterns:
```
# Start workflow - returns session_id in response
# Check existing sessions first (MANDATORY)
workflow_cache_management(operation="list")

# If no active sessions, start new workflow
workflow_discovery(task_description="Your task")
workflow_guidance(action="start", context="workflow: Selected Workflow")

# Continue with session_id for targeted operations
# Continue with session_id for targeted operations (returned in response)
workflow_guidance(session_id="abc-123", action="next", context='{"choose": "option"}')
workflow_state(session_id="abc-123", operation="get")
```
Expand All @@ -242,11 +324,33 @@ class BootstrapManager:
- **Session Isolation**: Keep different tasks completely separate
- **Session Tracking**: Monitor progress of individual workflows

#### Session Discovery Commands:
```
# List all cached sessions for current client (DISCOVERY PRIMARY METHOD)
workflow_cache_management(operation="list")

# Get specific session state
workflow_state(session_id="session-id", operation="get")

# Restore sessions from cache after restart
workflow_cache_management(operation="restore")
```

#### Best Practices:
- **ALWAYS check existing sessions BEFORE starting new workflows**
- **ALWAYS save session_id** from workflow start responses
- **ALWAYS include session_id** in subsequent workflow calls
- **ALWAYS include session_id** in subsequent workflow calls when available
- **Use session_id** when managing multiple concurrent workflows
- **Fallback handling**: System supports backward compatibility without session_id"""
- **Check session cache** after MCP server restarts for workflow continuity

### ⚡ Enforcement Rules
1. **NEVER skip session checking** before starting workflows
2. **ALWAYS start with `workflow_cache_management(operation="list")`** for session awareness
3. **ALWAYS use `workflow_discovery()`** for new workflows after session check
4. **NEVER use legacy approaches** when workflow tools are available
5. **ALWAYS follow YAML schema transitions** rather than making ad-hoc decisions
6. **WHEN UNCERTAIN → USE WORKFLOWS** (fail-safe principle)
7. **ALWAYS handle session conflicts** before proceeding with new workflows"""

def _log_info(self, message: str) -> None:
"""Log info message with colored output."""
Expand Down
4 changes: 2 additions & 2 deletions src/accordo_workflow_mcp/prompts/phase_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def _handle_dynamic_workflow(
{status}"""
else:
# Transition failed (likely due to missing approval)
return f"❌ **Transition Failed:** Unable to transition to '{choice}'. Current node requires explicit user approval before transition. Provide 'user_approval': true in your context to proceed, ONLY WHEN THE USER HAS PROVIDED EXPLICIT APPROVAL."
return f"❌ **Transition Failed:** Unable to transition to '{choice}'. Current node requires explicit user approval before transition. Provide 'user_approval': true in your context to proceed, ONLY WHEN THE USER HAS PROVIDED EXPLICIT APPROVAL. NEVER CONSIDER PAST USER APPROVALS AS CURRENT USER APPROVAL."

elif choice in (current_node.next_allowed_workflows or []):
# Workflow transition - not implemented yet
Expand Down Expand Up @@ -1667,7 +1667,7 @@ def _handle_cache_list_operation(client_id: str) -> str:
result += f"- Newest entry: {session['newest_entry']}\n"
else:
# Individual session info
result += f"**Session: {session['session_id'][:8]}...**\n"
result += f"**Session: {session['session_id']}**\n"
result += f"- Workflow: {session.get('workflow_name', 'Unknown')}\n"
result += f"- Status: {session.get('status', 'Unknown')}\n"
result += f"- Current Node: {session.get('current_node', 'Unknown')}\n"
Expand Down
Loading