feat: add DDD scan, sync, and update commands for document indexing

- Implemented `/ddd:scan` command to analyze existing codebases and generate document indices without specifications. This includes phases for project structure analysis, component discovery, feature inference, and requirement extraction.
- Introduced `/ddd:sync` command for post-task synchronization, updating document indices, generating action logs, and refreshing feature/component documentation after development tasks.
- Added `/ddd:update` command for lightweight incremental updates to the document index, allowing for quick impact checks during development and pre-commit validation.
- Created `execute.md` for the coordinator role in the team lifecycle, detailing the spawning of executor team-workers for IMPL tasks.
- Added `useHasHydrated` hook to determine if the Zustand workflow store has been rehydrated from localStorage, improving state management reliability.
This commit is contained in:
catlog22
2026-03-07 00:00:18 +08:00
parent a9469a5e3b
commit 7ee9b579fa
18 changed files with 2739 additions and 155 deletions

View File

@@ -1,9 +1,9 @@
---
role: executor
prefix: IMPL
inner_loop: true
inner_loop: false
discuss_rounds: []
input_artifact_types: []
input_artifact_types: [plan, spec, architecture]
message_types:
success: impl_complete
progress: impl_progress
@@ -12,56 +12,160 @@ message_types:
# Executor — Phase 2-4
## Phase 2: Task & Plan Loading
**Role**: Implementation worker with team interaction protocol. Supports two execution modes: direct agent implementation or CLI delegation. Coordinator assigns mode per task via `Executor:` field.
**Objective**: Load plan and determine execution strategy.
## Phase 2: Parse Task & Resolve Execution Mode
1. Load plan.json and .task/TASK-*.json from `<session-folder>/plan/`
**Objective**: Load task JSON, execute pre-analysis, resolve execution mode.
**Backend selection** (priority order):
### 2.1 Extract from task description
| Priority | Source | Method |
|----------|--------|--------|
| 1 | Task metadata | task.metadata.executor field |
| 2 | Plan default | "Execution Backend:" in plan |
| 3 | Auto-select | Simple (< 200 chars, no refactor) → agent; Complex → codex |
- `Task file:``task_file` path
- `Session:``session` folder
- `Executor:``mode` (`agent` | `gemini` | `codex` | `qwen`)
**Code review selection**:
### 2.2 Load task JSON (read task_file)
| Priority | Source | Method |
|----------|--------|--------|
| 1 | Task metadata | task.metadata.code_review field |
| 2 | Plan default | "Code Review:" in plan |
| 3 | Auto-select | Critical keywords (auth, security, payment) → enabled |
```
Task JSON Fields:
├── id, title, scope, action
├── description → Implementation goal
├── files[] → Target files (path, target, change)
├── implementation[] → Step-by-step execution instructions
├── convergence.criteria[] → Done-when checklist
├── pre_analysis[] → Context gathering steps (optional)
│ └── { step, action, commands[], output_to, on_error }
├── reference → Pattern reference (pattern, files[], examples)
├── risks[] → Risk mitigations (optional)
├── rationale → Approach rationale (optional)
└── depends_on[] → (handled by coordinator, not executor)
```
## Phase 3: Code Implementation
### 2.3 Resolve execution mode (priority order)
**Objective**: Execute implementation across batches.
| Priority | Source | Resolution |
|----------|--------|------------|
| 1 | Task description `Executor:` | Coordinator assignment |
| 2 | task.meta.execution_config.method | Per-task config from planner |
| 3 | plan.json recommended_execution | Plan-level default |
| 4 | Auto-select | Low complexity → agent; Medium/High → codex |
**Batching**: Topological sort by IMPL task dependencies → sequential batches.
### 2.4 Execute pre_analysis (if exists, runs locally regardless of mode)
| Backend | Invocation | Use Case |
|---------|-----------|----------|
| gemini | `ccw cli --tool gemini --mode write` (foreground) | Simple, direct edits |
| codex | `ccw cli --tool codex --mode write` (foreground) | Complex, architecture |
| qwen | `ccw cli --tool qwen --mode write` (foreground) | Alternative backend |
```
For each step in task.pre_analysis[]:
→ Parse step.commands[] using command-to-tool mapping:
"Read(path)" → Read tool
"bash(command)" → Bash tool
"Search(pattern,path)" → Grep tool
"Glob(pattern)" → Glob tool
→ Store output in [step.output_to] variable
→ Handle errors per step.on_error (fail | continue | skip)
```
## Phase 3: Execute Implementation
Route by resolved execution mode:
### Mode: `agent` — Direct Implementation
Executor implements directly using Edit/Write/Bash tools. Follows code-developer patterns.
```
1. Read task.files[] as target files
2. Read task.implementation[] as step-by-step instructions
3. For each implementation step:
- Substitute [variable_name] placeholders with pre_analysis results
- For each file in step:
* New file → Write tool
* Modify file → Edit tool
- Follow task.reference (pattern, files) for consistency
4. Apply task.rationale.chosen_approach
5. Mitigate task.risks[] during implementation
```
**Quality rules** (same as code-developer):
- Verify module/package existence before referencing (use Grep/Glob)
- Incremental progress — small working changes
- Follow existing code patterns from task.reference
- No premature abstractions
- ASCII-only, GBK-compatible
### Mode: `gemini` / `codex` / `qwen` — CLI Delegation
Build structured prompt from task JSON, delegate to CLI tool.
**Build handoff prompt**:
```javascript
function buildCliHandoffPrompt(task, preAnalysisResults) {
const context = Object.entries(preAnalysisResults)
.map(([key, value]) => `### ${key}\n${value}`)
.join('\n\n')
return `
PURPOSE: ${task.title}
${task.description}
## TARGET FILES
${task.files?.map(f => `- **${f.path}** → ${f.change}`).join('\n')}
## IMPLEMENTATION STEPS
${task.implementation?.map((s, i) => `${i+1}. ${s}`).join('\n')}
${context ? `## PRE-ANALYSIS CONTEXT\n${context}` : ''}
${task.reference ? `## REFERENCE\n- Pattern: ${task.reference.pattern}\n- Files: ${task.reference.files?.join(', ')}` : ''}
${task.rationale ? `## APPROACH\n${task.rationale.chosen_approach}` : ''}
${task.risks?.length ? `## RISKS\n${task.risks.map(r => `- ${r.description} → **${r.mitigation}**`).join('\n')}` : ''}
## DONE WHEN
${task.convergence?.criteria?.map(c => `- [ ] ${c}`).join('\n')}
MODE: write
CONSTRAINTS: Only modify files listed above | Follow existing patterns
`.trim()
}
```
**CLI call**:
```
Bash({
command: `ccw cli -p "${buildCliHandoffPrompt(task, preAnalysisResults)}"
--tool <cli_tool> --mode write --rule development-implement-feature`,
run_in_background: false,
timeout: 3600000
})
```
**Resume strategy** (if task.cli_execution exists):
| Strategy | Command |
|----------|---------|
| new | `--id <session>-<task_id>` |
| resume | `--resume <parent_id>` |
| fork | `--resume <parent_id> --id <new_id>` |
| merge_fork | `--resume <id1>,<id2> --id <new_id>` |
## Phase 4: Self-Validation
| Step | Method | Pass Criteria |
|------|--------|--------------|
| Syntax check | `tsc --noEmit` (30s) | Exit code 0 |
| Acceptance criteria | Match criteria keywords vs implementation | All addressed |
| Test detection | Find .test.ts/.spec.ts for modified files | Tests identified |
| Code review (optional) | gemini analysis or codex review | No blocking issues |
| Convergence check | Match task.convergence.criteria vs output | All criteria addressed |
| Syntax check | `tsc --noEmit` or language-appropriate (30s) | Exit code 0 |
| Test detection | Find test files for modified files | Tests identified |
**Report**: task ID, status, files modified, validation results, backend used.
**Report**: task ID, status, mode used, files modified, convergence results.
## Error Handling
| Scenario | Resolution |
|----------|------------|
| Syntax errors | Retry with error context (max 3) |
| Missing dependencies | Request from coordinator |
| Backend unavailable | Fallback to alternative tool |
| Circular dependencies | Abort, report graph |
| Agent mode: syntax errors | Retry with error context (max 3) |
| CLI mode: execution failure | Retry, or resume with --resume |
| pre_analysis failure | Follow step.on_error (fail/continue/skip) |
| CLI tool unavailable | Fallback: gemini → qwen → codex |
| Max retries exceeded | Report failure to coordinator |