fix: allow slash commands in main context, enforce Task agents for internal calls

**Problem:**
- workflow.xml enforced Task agent for ALL workflow executions
- User slash commands like /batch-super-dev need interactive prompts
- Can't run in Task agent (no user interaction)

**Solution:**
- Detect invocation source
- User slash command: Allow in main context
- Internal workflow call: Force Task agent delegation

**Detection:**
- Slash command: User message contains '/bmad_' or <command-name> tag
- Internal call: Invoked from within another workflow step

**Benefits:**
- Interactive workflows work (user can respond to prompts)
- Internal calls still get fresh context (Task agents)
- Balance between enforcement and UX

Tested: /bmad_bmm_batch-super-dev now runs without violation error.
This commit is contained in:
Jonah Schulte 2026-01-26 18:28:46 -05:00
parent 6b8a9a0519
commit 39f78c6412
1 changed files with 41 additions and 28 deletions

View File

@ -18,45 +18,58 @@
<llm critical="ABSOLUTE">
<mandate>🚨 WORKFLOW EXECUTION ENFORCEMENT 🚨</mandate>
<mandate>YOU ARE FORBIDDEN FROM EXECUTING THIS WORKFLOW DIRECTLY</mandate>
<mandate>YOU MUST DELEGATE TO workflow-executor TASK AGENT</mandate>
<enforcement>
IF you are reading this file directly (not as a Task agent):
HALT IMMEDIATELY
<check type="invocation_source">
IF this workflow was invoked by USER via slash command (e.g., /bmad_bmm_batch-super-dev):
✅ ALLOWED in main context
Reason: User-initiated workflows need interactive prompts
Continue execution below
ELSE IF this workflow was invoked by ANOTHER WORKFLOW (internal call):
❌ FORBIDDEN in main context
MUST delegate to workflow-executor Task agent
Display to user:
❌ WORKFLOW EXECUTION VIOLATION DETECTED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔄 Delegating workflow to fresh context agent...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
You attempted to execute workflow: {workflow_path}
Workflow: {workflow_name}
Reason: Internal workflow calls use Task agents (fresh context)
This is FORBIDDEN. Workflows MUST be executed by workflow-executor Task agent.
Spawning workflow-executor agent...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Correct action:
Then spawn:
<Task>
subagent_type: general-purpose
description: Execute {workflow_name}
prompt: |
You are the workflow-executor agent.
LOAD EVERYTHING FIRST:
Execute workflow: {workflow_path}
LOAD ALL CONTEXT FIRST:
1. Read: {workflow_path}/workflow.yaml
2. Read: ALL files in {workflow_path}/steps/
3. Read: _bmad/core/tasks/workflow.xml
4. Read: Story file
4. Read: Story file (if applicable)
5. Read: Project context
THEN execute workflow following workflow.xml EXACTLY.
THEN execute following workflow.xml rules EXACTLY.
When step says invoke-workflow → Use Skill tool
When step says spawn agents → Use Task tool
When step has quality_gate → Verify before proceeding
Record evidence after EVERY step.
Report back when ALL steps complete.
Report when complete.
</Task>
STOPPING EXECUTION - Spawn the agent above.
HALT - Let Task agent handle workflow.
</check>
<detection>
How to detect invocation source:
- Slash command: User message contains "/bmad_" or conversation has <command-name> tag
- Internal call: No slash command, invoked from within another workflow step
</detection>
</enforcement>
</llm>