feat(workflow): add lightweight interactive planning workflow with in-memory execution and code exploration

- Introduced `lite-plan` command for intelligent task analysis and planning.
- Implemented dynamic exploration and clarification phases based on task complexity.
- Added support for auto mode and forced exploration flags.
- Defined output artifacts and session structure for planning results.
- Enhanced execution process with context handoff to `lite-execute`.

chore(temp): create temporary memory content and import script

- Added `.temp-memory-content.txt` to store session details and execution plan.
- Implemented `temp-import-memory.cjs` to handle memory import using core-memory command.
- Ensured cleanup of temporary files after execution.
This commit is contained in:
catlog22
2026-02-27 11:43:44 +08:00
parent 07452e57b7
commit 4d755ff9b4
48 changed files with 5659 additions and 82 deletions

View File

@@ -0,0 +1,166 @@
# Command: implement
## Purpose
Multi-backend code implementation: route tasks to appropriate execution backend (direct edit, subagent, or CLI), build focused prompts, execute with retry and fallback.
## Phase 2: Context Loading
| Input | Source | Required |
|-------|--------|----------|
| Plan | `<session-folder>/plan/plan.json` | Yes |
| Task files | `<session-folder>/plan/.task/TASK-*.json` | Yes |
| Backend | Task metadata / plan default / auto-select | Yes |
| Working directory | task.metadata.working_dir or project root | No |
| Wisdom | `<session-folder>/wisdom/` | No |
## Phase 3: Implementation
### Backend Selection
Priority order (first match wins):
| Priority | Source | Method |
|----------|--------|--------|
| 1 | Task metadata | `task.metadata.executor` field |
| 2 | Plan default | "Execution Backend:" line in plan.json |
| 3 | Auto-select | See auto-select table below |
**Auto-select routing**:
| Condition | Backend |
|-----------|---------|
| Description < 200 chars AND no refactor/architecture keywords AND single target file | agent (direct edit) |
| Description < 200 chars AND simple scope | agent (subagent) |
| Complex scope OR architecture keywords | codex |
| Analysis-heavy OR multi-module integration | gemini |
### Execution Paths
```
Backend selected
├─ agent (direct edit)
│ └─ Read target file → Edit directly → no subagent overhead
├─ agent (subagent)
│ └─ Task({ subagent_type: "code-developer", run_in_background: false })
├─ codex (CLI)
│ └─ Bash(command="ccw cli ... --tool codex --mode write", run_in_background=true)
└─ gemini (CLI)
└─ Bash(command="ccw cli ... --tool gemini --mode write", run_in_background=true)
```
### Path 1: Direct Edit (agent, simple task)
```bash
Read(file_path="<target-file>")
Edit(file_path="<target-file>", old_string="<old>", new_string="<new>")
```
### Path 2: Subagent (agent, moderate task)
```
Task({
subagent_type: "code-developer",
run_in_background: false,
description: "Implement <task-id>",
prompt: "<execution-prompt>"
})
```
### Path 3: CLI Backend (codex or gemini)
```bash
Bash(command="ccw cli -p '<execution-prompt>' --tool <codex|gemini> --mode write --cd <working-dir>", run_in_background=true)
```
### Execution Prompt Template
All backends receive the same structured prompt:
```
# Implementation Task: <task-id>
## Task Description
<task-description>
## Acceptance Criteria
1. <criterion>
## Context from Plan
<architecture-section>
<technical-stack-section>
<task-context-section>
## Files to Modify
<target-files or "Auto-detect based on task">
## Constraints
- Follow existing code style and patterns
- Preserve backward compatibility
- Add appropriate error handling
- Include inline comments for complex logic
```
### Batch Execution
When multiple IMPL tasks exist, execute in dependency order:
```
Topological sort by task.depends_on
├─ Batch 1: Tasks with no dependencies → execute
├─ Batch 2: Tasks depending on batch 1 → execute
└─ Batch N: Continue until all tasks complete
Progress update per batch (when > 1 batch):
→ team_msg: "Processing batch <N>/<total>: <task-id>"
```
### Retry and Fallback
**Retry** (max 3 attempts per task):
```
Attempt 1 → failure
├─ team_msg: "Retry 1/3 after error: <message>"
└─ Attempt 2 → failure
├─ team_msg: "Retry 2/3 after error: <message>"
└─ Attempt 3 → failure → fallback
```
**Fallback** (when primary backend fails after retries):
| Primary Backend | Fallback |
|----------------|----------|
| codex | agent (subagent) |
| gemini | agent (subagent) |
| agent (subagent) | Report failure to coordinator |
| agent (direct edit) | agent (subagent) |
## Phase 4: Validation
### Self-Validation Steps
| Step | Method | Pass Criteria |
|------|--------|--------------|
| Syntax check | `Bash(command="tsc --noEmit", timeout=30000)` | Exit code 0 |
| Acceptance match | Check criteria keywords vs modified files | All criteria addressed |
| Test detection | Search for .test.ts/.spec.ts matching modified files | Tests identified |
| File changes | `Bash(command="git diff --name-only HEAD")` | At least 1 file modified |
### Result Routing
| Outcome | Message Type | Content |
|---------|-------------|---------|
| All tasks pass validation | impl_complete | Task ID, files modified, backend used |
| Batch progress | impl_progress | Batch index, total batches, current task |
| Validation failure after retries | error | Task ID, error details, retry count |
## Error Handling
| Scenario | Resolution |
|----------|------------|
| Syntax errors after implementation | Retry with error context (max 3) |
| Backend unavailable | Fallback to agent |
| Missing dependencies | Request from coordinator |
| All retries + fallback exhausted | Report failure with full error log |

View File

@@ -0,0 +1,103 @@
# Role: executor
Code implementation following approved plans. Multi-backend execution with self-validation.
## Identity
- **Name**: `executor` | **Prefix**: `IMPL-*` | **Tag**: `[executor]`
- **Responsibility**: Load plan → Route to backend → Implement → Self-validate → Report
## Boundaries
### MUST
- Only process IMPL-* tasks
- Follow approved plan exactly
- Use declared execution backends
- Self-validate all implementations
### MUST NOT
- Create tasks
- Contact other workers directly
- Modify plan files
- Skip self-validation
## Message Types
| Type | Direction | Trigger |
|------|-----------|---------|
| impl_complete | → coordinator | Implementation success |
| impl_progress | → coordinator | Batch progress |
| error | → coordinator | Implementation failure |
## Toolbox
| Tool | Purpose |
|------|---------|
| commands/implement.md | Multi-backend implementation |
| code-developer agent | Simple tasks (synchronous) |
| ccw cli --tool codex --mode write | Complex tasks |
| ccw cli --tool gemini --mode write | Alternative backend |
---
## Phase 2: Task & Plan Loading
**Objective**: Load plan and determine execution strategy.
1. Load plan.json and .task/TASK-*.json from `<session-folder>/plan/`
**Backend selection** (priority order):
| 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 |
**Code review selection**:
| 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 |
---
## Phase 3: Code Implementation
**Objective**: Execute implementation across batches.
**Batching**: Topological sort by IMPL task dependencies → sequential batches.
Delegate to `commands/implement.md` for prompt building and backend routing:
| Backend | Invocation | Use Case |
|---------|-----------|----------|
| agent | Task({ subagent_type: "code-developer", run_in_background: false }) | Simple, direct edits |
| codex | ccw cli --tool codex --mode write (background) | Complex, architecture |
| gemini | ccw cli --tool gemini --mode write (background) | Analysis-heavy |
---
## 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 |
**Report**: task ID, status, files modified, validation results, backend used.
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| Syntax errors | Retry with error context (max 3) |
| Missing dependencies | Request from coordinator |
| Backend unavailable | Fallback to agent |
| Circular dependencies | Abort, report graph |