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"> <llm critical="ABSOLUTE">
<mandate>🚨 WORKFLOW EXECUTION ENFORCEMENT 🚨</mandate> <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> <enforcement>
IF you are reading this file directly (not as a Task agent): <check type="invocation_source">
HALT IMMEDIATELY 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
Display to user: ELSE IF this workflow was invoked by ANOTHER WORKFLOW (internal call):
❌ WORKFLOW EXECUTION VIOLATION DETECTED ❌ FORBIDDEN in main context
MUST delegate to workflow-executor Task agent
You attempted to execute workflow: {workflow_path} Display to user:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔄 Delegating workflow to fresh context agent...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
This is FORBIDDEN. Workflows MUST be executed by workflow-executor Task agent. Workflow: {workflow_name}
Reason: Internal workflow calls use Task agents (fresh context)
Correct action: Spawning workflow-executor agent...
<Task> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
subagent_type: general-purpose
description: Execute {workflow_name}
prompt: |
You are the workflow-executor agent.
LOAD EVERYTHING FIRST: Then spawn:
1. Read: {workflow_path}/workflow.yaml <Task>
2. Read: ALL files in {workflow_path}/steps/ subagent_type: general-purpose
3. Read: _bmad/core/tasks/workflow.xml description: Execute {workflow_name}
4. Read: Story file prompt: |
5. Read: Project context You are the workflow-executor agent.
THEN execute workflow following workflow.xml EXACTLY. Execute workflow: {workflow_path}
When step says invoke-workflow → Use Skill tool LOAD ALL CONTEXT FIRST:
When step says spawn agents → Use Task tool 1. Read: {workflow_path}/workflow.yaml
When step has quality_gate → Verify before proceeding 2. Read: ALL files in {workflow_path}/steps/
3. Read: _bmad/core/tasks/workflow.xml
4. Read: Story file (if applicable)
5. Read: Project context
Record evidence after EVERY step. THEN execute following workflow.xml rules EXACTLY.
Report back when ALL steps complete.
</Task>
STOPPING EXECUTION - Spawn the agent above. Report when complete.
</Task>
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> </enforcement>
</llm> </llm>