feat: 更新问题执行和队列生成逻辑,支持解决方案格式并增强元数据管理

This commit is contained in:
catlog22
2025-12-28 20:35:29 +08:00
parent 35c7fe28bb
commit c24ad501b5
5 changed files with 404 additions and 117 deletions

View File

@@ -1,104 +1,114 @@
---
description: Execute issue queue tasks sequentially with git commit after each task
argument-hint: "[--dry-run]"
description: Execute solution from issue queue with git commit after each task
argument-hint: "<solution-id> [--dry-run]"
---
# Issue Execute (Codex Version)
## Core Principle
**Serial Execution**: Execute tasks ONE BY ONE from the issue queue. Complete each task fully (implement → test → commit) before moving to next. Continue autonomously until ALL tasks complete or queue is empty.
**Solution-Aware Execution**: Receive a complete solution with all its tasks, execute tasks sequentially within the solution (implement → test → commit per task), then report solution completion. This aligns with the Queue's Solution-Level design.
## Execution Flow
```
INIT: Fetch first task via ccw issue next
INIT: Receive solution ID (S-N) from orchestrator
WHILE task exists:
1. Receive task JSON from ccw issue next
2. Execute full lifecycle:
- IMPLEMENT: Follow task.implementation steps
- TEST: Run task.test commands
- VERIFY: Check task.acceptance criteria
- COMMIT: Stage files, commit with task.commit.message_template
3. Report completion via ccw issue complete <item_id>
4. Fetch next task via ccw issue next
FOR solution:
1. Fetch full solution via: ccw issue detail <solution-id>
2. Iterate through solution.tasks sequentially:
FOR each task in solution.tasks:
- IMPLEMENT: Follow task.implementation steps
- TEST: Run task.test commands
- VERIFY: Check task.acceptance criteria
- COMMIT: Stage files, commit with task.commit.message_template
3. Report solution completion: ccw issue done <solution-id>
WHEN queue empty:
Output final summary
OUTPUT: Final summary with all commits
```
## Step 1: Fetch First Task
## Step 1: Fetch Solution
Run this command to get your first task:
Run this command to get the full solution:
```bash
ccw issue next
ccw issue detail <solution-id>
```
This returns JSON with the full task definition:
- `item_id`: Unique task identifier in queue (e.g., "T-1")
- `issue_id`: Parent issue ID (e.g., "ISSUE-20251227-001")
- `task`: Full task definition with implementation steps
- `context`: Relevant files and patterns
This returns JSON with the complete solution definition:
- `item_id`: Solution identifier in queue (e.g., "S-1")
- `issue_id`: Parent issue ID (e.g., "ISS-20251227-001")
- `solution_id`: Solution ID (e.g., "SOL-20251227-001")
- `solution`: Full solution with all tasks
- `execution_hints`: Timing and executor hints
If response contains `{ "status": "empty" }`, all tasks are complete - skip to final summary.
## Step 2: Parse Solution Response
## Step 2: Parse Task Response
Expected task structure:
Expected solution structure:
```json
{
"item_id": "T-1",
"issue_id": "ISSUE-20251227-001",
"solution_id": "SOL-001",
"task": {
"id": "T1",
"title": "Task title",
"scope": "src/module/",
"action": "Create|Modify|Fix|Refactor",
"description": "What to do",
"modification_points": [
{ "file": "path/to/file.ts", "target": "function name", "change": "description" }
"item_id": "S-1",
"issue_id": "ISS-20251227-001",
"solution_id": "SOL-20251227-001",
"status": "pending",
"solution": {
"id": "SOL-20251227-001",
"approach": "Description of solution approach",
"tasks": [
{
"id": "T1",
"title": "Task title",
"scope": "src/module/",
"action": "Create|Modify|Fix|Refactor",
"description": "What to do",
"modification_points": [
{ "file": "path/to/file.ts", "target": "function name", "change": "description" }
],
"implementation": [
"Step 1: Do this",
"Step 2: Do that"
],
"test": {
"commands": ["npm test -- --filter=xxx"],
"unit": "Unit test requirements",
"integration": "Integration test requirements (optional)"
},
"acceptance": [
"Criterion 1: Must pass",
"Criterion 2: Must verify"
],
"commit": {
"message_template": "feat(scope): description"
}
}
],
"implementation": [
"Step 1: Do this",
"Step 2: Do that"
],
"test": {
"commands": ["npm test -- --filter=xxx"],
"unit": "Unit test requirements",
"integration": "Integration test requirements (optional)"
},
"acceptance": [
"Criterion 1: Must pass",
"Criterion 2: Must verify"
],
"commit": {
"message_template": "feat(scope): description"
"exploration_context": {
"relevant_files": ["path/to/reference.ts"],
"patterns": "Follow existing pattern in xxx"
}
},
"context": {
"relevant_files": ["path/to/reference.ts"],
"patterns": "Follow existing pattern in xxx"
"execution_hints": {
"executor": "codex",
"estimated_minutes": 180
}
}
```
## Step 3: Execute Task Lifecycle
## Step 3: Execute Tasks Sequentially
Iterate through `solution.tasks` array and execute each task:
### Phase A: IMPLEMENT
1. Read all `context.relevant_files` to understand existing patterns
1. Read all `exploration_context.relevant_files` to understand existing patterns
2. Follow `task.implementation` steps in order
3. Apply changes to `task.modification_points` files
4. Follow `context.patterns` for code style consistency
4. Follow `exploration_context.patterns` for code style consistency
**Output format:**
```
## Implementing: [task.title]
## Implementing: [task.title] (Task [N]/[Total])
**Scope**: [task.scope]
**Action**: [task.action]
@@ -149,7 +159,7 @@ All criteria met: YES
### Phase D: COMMIT
After all phases pass, commit the changes:
After all phases pass, commit the changes for this task:
```bash
# Stage all modified files
@@ -159,7 +169,7 @@ git add path/to/file1.ts path/to/file2.ts ...
git commit -m "$(cat <<'EOF'
[task.commit.message_template]
Item-ID: [item_id]
Solution-ID: [solution_id]
Issue-ID: [issue_id]
Task-ID: [task.id]
EOF
@@ -175,92 +185,91 @@ EOF
**Files**: N files changed
```
## Step 4: Report Completion
### Repeat for Next Task
After commit succeeds, report to queue system:
Continue to next task in `solution.tasks` array until all tasks are complete.
## Step 4: Report Solution Completion
After ALL tasks in the solution are complete, report to queue system:
```bash
ccw issue complete [item_id] --result '{
"files_modified": ["path1", "path2"],
"tests_passed": true,
"acceptance_passed": true,
"committed": true,
"commit_hash": "[actual hash]",
"summary": "[What was accomplished]"
ccw issue done <solution-id> --result '{
"summary": "[What was accomplished]",
"files_modified": ["path1", "path2", ...],
"tasks_completed": N,
"commits": [
{ "task_id": "T1", "hash": "abc123" },
{ "task_id": "T2", "hash": "def456" }
]
}'
```
**If task failed and cannot be fixed:**
**If any task failed and cannot be fixed:**
```bash
ccw issue fail [item_id] --reason "Phase [X] failed: [details]"
ccw issue done <solution-id> --fail --reason "Task [task.id] failed: [details]"
```
## Step 5: Continue to Next Task
Immediately fetch the next task:
```bash
ccw issue next
```
**Output progress:**
```
✓ [N/M] Completed: [item_id] - [task.title]
→ Fetching next task...
```
**DO NOT STOP.** Return to Step 2 and continue until queue is empty.
## Final Summary
When `ccw issue next` returns `{ "status": "empty" }`:
When all tasks in solution are complete:
```markdown
## Issue Queue Execution Complete
## Solution Execution Complete
**Solution**: [solution_id]
**Issue**: [issue_id]
**Tasks Executed**: N/N
**Total Tasks Executed**: N
**All Commits**:
| # | Item ID | Task | Commit |
|---|---------|------|--------|
| 1 | T-1 | Task title | abc123 |
| 2 | T-2 | Task title | def456 |
| # | Task ID | Task Title | Commit |
|---|---------|------------|--------|
| 1 | T1 | Task title | abc123 |
| 2 | T2 | Task title | def456 |
**Files Modified**:
- path/to/file1.ts
- path/to/file2.ts
**Summary**:
[Overall what was accomplished]
[Overall what was accomplished for this solution]
```
## Execution Rules
1. **Never stop mid-queue** - Continue until queue is empty
2. **One task at a time** - Fully complete (including commit) before moving on
1. **Solution-aware** - Receive complete solution, iterate tasks internally
2. **Sequential within solution** - Complete each task (including commit) before moving to next
3. **Tests MUST pass** - Do not proceed to commit if tests fail
4. **Commit after each task** - Each task gets its own commit
5. **Self-verify** - All acceptance criteria must pass before commit
6. **Report accurately** - Use ccw issue complete/fail after each task
7. **Handle failures gracefully** - If a task fails, report via ccw issue fail and continue to next
6. **Report accurately** - Use `ccw issue done` after all tasks complete
7. **Handle failures gracefully** - If a task fails, report via `ccw issue done --fail`
## Error Handling
| Situation | Action |
|-----------|--------|
| ccw issue next returns empty | All done - output final summary |
| Solution not found | Report error, abort |
| Tests fail | Fix code, re-run tests |
| Verification fails | Go back to implement phase |
| Git commit fails | Check staging, retry commit |
| ccw issue complete fails | Log error, continue to next task |
| Unrecoverable error | Call ccw issue fail, continue to next |
| Unrecoverable error | Call `ccw issue done --fail`, report details |
## CLI Command Reference
| Command | Purpose |
|---------|---------|
| `ccw issue detail <id>` | Fetch full solution (READ-ONLY) |
| `ccw issue done <id>` | Mark solution complete |
| `ccw issue done <id> --fail` | Mark solution failed |
## Start Execution
Begin by running:
When invoked by orchestrator with solution ID:
```bash
ccw issue next
ccw issue detail <solution-id>
```
Then follow the lifecycle for each task until queue is empty.
Then follow the task lifecycle for each task in `solution.tasks` until all complete.