refactor: adjust prompt structure for command execution clarity

This commit is contained in:
catlog22
2026-01-24 14:51:05 +08:00
parent f2b0a5bbc9
commit bf896342f4

View File

@@ -401,20 +401,19 @@ async function executeCommandChain(chain, analysis) {
state.updated_at = new Date().toISOString(); state.updated_at = new Date().toISOString();
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2)); Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
// Assemble prompt: Task context + Command instruction // Assemble prompt: Command first, then context
let promptContent = formatCommand(cmd, state.execution_results, analysis); let promptContent = formatCommand(cmd, state.execution_results, analysis);
// Build full prompt with context // Build full prompt: Command → Task → Previous Results
let prompt = `Task: ${analysis.goal}\n`; let prompt = `${promptContent}\n\nTask: ${analysis.goal}`;
if (state.execution_results.length > 0) { if (state.execution_results.length > 0) {
prompt += '\nPrevious results:\n'; prompt += '\n\nPrevious results:\n';
state.execution_results.forEach(r => { state.execution_results.forEach(r => {
if (r.session_id) { if (r.session_id) {
prompt += `- ${r.command}: ${r.session_id} (${r.artifacts?.join(', ') || 'completed'})\n`; prompt += `- ${r.command}: ${r.session_id} (${r.artifacts?.join(', ') || 'completed'})\n`;
} }
}); });
} }
prompt += `\n${promptContent}`;
// Record prompt used // Record prompt used
state.prompts_used.push({ state.prompts_used.push({
@@ -671,12 +670,12 @@ function parseOutput(output) {
{ {
"index": 0, "index": 0,
"command": "/workflow:plan", "command": "/workflow:plan",
"prompt": "Task: Implement user registration...\n\n/workflow:plan --yes \"Implement user registration...\"" "prompt": "/workflow:plan -y \"Implement user registration...\"\n\nTask: Implement user registration..."
}, },
{ {
"index": 1, "index": 1,
"command": "/workflow:execute", "command": "/workflow:execute",
"prompt": "Task: Implement user registration...\n\nPrevious results:\n- /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md)\n\n/workflow:execute --yes --resume-session=\"WFS-plan-20250124\"" "prompt": "/workflow:execute -y --resume-session=\"WFS-plan-20250124\"\n\nTask: Implement user registration\n\nPrevious results:\n- /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md)"
} }
] ]
} }
@@ -747,22 +746,22 @@ ccw cli -p "PROMPT_CONTENT" --tool <tool> --mode <mode>
### Prompt Content Template ### Prompt Content Template
``` ```
/workflow:<command> -y <command_parameters>
Task: <task_description> Task: <task_description>
<optional_previous_results> <optional_previous_results>
/workflow:<command> -y <command_parameters>
``` ```
### Template Variables ### Template Variables
| Variable | Description | Examples | | Variable | Description | Examples |
|----------|-------------|----------| |----------|-------------|----------|
| `<task_description>` | Brief task description | "Implement user authentication", "Fix memory leak" |
| `<optional_previous_results>` | Context from previous commands | "Previous results:\n- /workflow:plan: WFS-xxx" |
| `<command>` | Workflow command name | `plan`, `lite-execute`, `test-cycle-execute` | | `<command>` | Workflow command name | `plan`, `lite-execute`, `test-cycle-execute` |
| `-y` | Auto-confirm flag (inside prompt) | Always include for automation | | `-y` | Auto-confirm flag (inside prompt) | Always include for automation |
| `<command_parameters>` | Command-specific parameters | Task description, session ID, flags | | `<command_parameters>` | Command-specific parameters | Task description, session ID, flags |
| `<task_description>` | Brief task description | "Implement user authentication", "Fix memory leak" |
| `<optional_previous_results>` | Context from previous commands | "Previous results:\n- /workflow:plan: WFS-xxx" |
### Command Parameter Patterns ### Command Parameter Patterns
@@ -778,26 +777,26 @@ Task: <task_description>
**Planning Command**: **Planning Command**:
```bash ```bash
ccw cli -p 'Task: Implement user registration ccw cli -p '/workflow:plan -y "Implement user registration with email validation"
/workflow:plan -y "Implement user registration with email validation"' --tool claude --mode write Task: Implement user registration' --tool claude --mode write
``` ```
**Execution with Context**: **Execution with Context**:
```bash ```bash
ccw cli -p 'Task: Implement user registration ccw cli -p '/workflow:execute -y --resume-session="WFS-plan-20250124"
Task: Implement user registration
Previous results: Previous results:
- /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md) - /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md)' --tool claude --mode write
/workflow:execute -y --resume-session="WFS-plan-20250124"' --tool claude --mode write
``` ```
**Standalone Lite Execution**: **Standalone Lite Execution**:
```bash ```bash
ccw cli -p 'Task: Fix login timeout ccw cli -p '/workflow:lite-fix -y "Fix login timeout in auth module"
/workflow:lite-fix -y "Fix login timeout in auth module"' --tool claude --mode write Task: Fix login timeout' --tool claude --mode write
``` ```
## Execution Flow ## Execution Flow
@@ -850,31 +849,46 @@ ccw cli -p "PROMPT_CONTENT" --tool <tool> --mode <mode>
### Prompt Assembly ### Prompt Assembly
The prompt content should include the workflow command with `-y` for auto-confirm: The prompt content MUST start with the workflow command, followed by task context:
``` ```
/workflow:<command> -y "<task description or parameters>" /workflow:<command> -y <parameters>
Task: <description>
<optional_context>
``` ```
**Examples**: **Examples**:
```bash ```bash
# Planning command # Planning command
ccw cli -p "/workflow:plan -y \"Implement user registration feature\"" --tool claude --mode write ccw cli -p '/workflow:plan -y "Implement user registration feature"
Task: Implement user registration' --tool claude --mode write
# Execution command (with session reference) # Execution command (with session reference)
ccw cli -p "/workflow:execute -y --resume-session=\"WFS-plan-20250124\"" --tool claude --mode write ccw cli -p '/workflow:execute -y --resume-session="WFS-plan-20250124"
Task: Implement user registration
Previous results:
- /workflow:plan: WFS-plan-20250124' --tool claude --mode write
# Lite execution (in-memory from previous plan) # Lite execution (in-memory from previous plan)
ccw cli -p "/workflow:lite-execute -y --in-memory" --tool claude --mode write ccw cli -p '/workflow:lite-execute -y --in-memory
Task: Implement user registration' --tool claude --mode write
``` ```
### Serial Blocking ### Serial Blocking
Commands execute one-by-one. After launching CLI in background, orchestrator stops immediately and waits for hook callback. Commands execute one-by-one. After launching CLI in background, orchestrator stops immediately and waits for hook callback.
**Prompt Structure**: Command must be first in prompt content
```javascript ```javascript
// Example: Execute command and stop // Example: Execute command and stop
const prompt = '/workflow:plan -y "Implement user authentication"'; const prompt = '/workflow:plan -y "Implement user authentication"\n\nTask: Implement user auth system';
const taskId = Bash(`ccw cli -p "${prompt}" --tool claude --mode write`, { run_in_background: true }).task_id; const taskId = Bash(`ccw cli -p "${prompt}" --tool claude --mode write`, { run_in_background: true }).task_id;
state.execution_results.push({ status: 'in-progress', task_id: taskId, ... }); state.execution_results.push({ status: 'in-progress', task_id: taskId, ... });
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2)); Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));