Refactor workflow tools and user interaction methods

- Updated synthesis tool to enhance user interaction with multi-select options and improved question presentation in Chinese.
- Revised conflict resolution tool to allow batch processing of conflicts, increasing the limit from 4 to 10 per round and changing user interaction from AskUserQuestion to text output.
- Added context_package_path to task generation tools for better context management.
- Improved task generation schema to include context_package_path for enhanced context delivery.
- Updated CLI templates to reflect changes in task JSON schema, ensuring context_package_path is included.
This commit is contained in:
catlog22
2025-10-25 14:43:55 +08:00
parent 89f22ec3cf
commit 692a68da6f
9 changed files with 706 additions and 714 deletions

View File

@@ -207,48 +207,85 @@ Task(subagent_type="cli-execution-agent", prompt=`
8. Return execution log path
```
### Phase 3: User Confirmation via AskUserQuestion
### Phase 3: User Confirmation via Text Interaction
**Command parses agent JSON output and presents conflicts to user**:
**Command parses agent JSON output and presents conflicts to user via text**:
```javascript
// 1. Parse agent JSON output
const conflictData = JSON.parse(agentOutput);
const conflicts = conflictData.conflicts.slice(0, 4); // Max 4 (tool limit)
const conflicts = conflictData.conflicts; // No 4-conflict limit
// 2. Build AskUserQuestion with all conflicts
const questions = conflicts.map((conflict, idx) => ({
question: `${conflict.id}: ${conflict.brief} - 请选择解决方案`,
header: `冲突${idx + 1}`,
multiSelect: false,
options: [
...conflict.strategies.map(s => ({
label: s.name,
description: `${s.approach} | 复杂度: ${s.complexity} | 风险: ${s.risk} | 工作量: ${s.effort}`
})),
{
label: "跳过此冲突",
description: "稍后手动处理,不应用任何修改"
}
]
}));
// 2. Format conflicts as text output (max 10 per round)
const batchSize = 10;
const batches = chunkArray(conflicts, batchSize);
// 3. Call AskUserQuestion
AskUserQuestion({questions});
for (const [batchIdx, batch] of batches.entries()) {
const totalBatches = batches.length;
// 4. Parse user selections
const selectedStrategies = parseUserAnswers(answers, conflicts);
// Output batch header
console.log(`===== 冲突解决 (第 ${batchIdx + 1}/${totalBatches} 轮) =====\n`);
// Output each conflict in batch
batch.forEach((conflict, idx) => {
const questionNum = batchIdx * batchSize + idx + 1;
console.log(`【问题${questionNum} - ${conflict.category}${conflict.id}: ${conflict.brief}`);
conflict.strategies.forEach((strategy, sIdx) => {
const optionLetter = String.fromCharCode(97 + sIdx); // a, b, c, ...
console.log(`${optionLetter}) ${strategy.name}`);
console.log(` 说明:${strategy.approach}`);
console.log(` 复杂度: ${strategy.complexity} | 风险: ${strategy.risk} | 工作量: ${strategy.effort}`);
});
// Add skip option
const skipLetter = String.fromCharCode(97 + conflict.strategies.length);
console.log(`${skipLetter}) 跳过此冲突`);
console.log(` 说明:稍后手动处理,不应用任何修改\n`);
});
console.log(`请回答 (格式: 1a 2b 3c...)`);
// Wait for user input
const userInput = await readUserInput();
// Parse answers
const answers = parseUserAnswers(userInput, batch);
}
// 3. Build selected strategies
const selectedStrategies = answers.filter(a => !a.isSkip).map(a => a.strategy);
```
**User Selection Examples**:
```
Question: "CON-001: 现有认证系统与计划不兼容 - 请选择解决方案"
Options:
- "渐进式迁移" | 复杂度: Medium | 风险: Low | 工作量: 3-5天
- "完全重写" | 复杂度: High | 风险: Medium | 工作量: 7-10天
- "跳过此冲突"
**Text Output Example**:
```markdown
===== 冲突解决 (第 1/1 轮) =====
【问题1 - 认证系统】CON-001: 现有认证系统与计划不兼容
a) 渐进式迁移
说明:保留现有系统,逐步迁移到新方案
复杂度: Medium | 风险: Low | 工作量: 3-5天
b) 完全重写
说明:废弃旧系统,从零实现新认证
复杂度: High | 风险: Medium | 工作量: 7-10天
c) 跳过此冲突
说明:稍后手动处理,不应用任何修改
【问题2 - 数据库】CON-002: 数据库 schema 冲突
a) 添加迁移脚本
说明:创建数据库迁移脚本处理 schema 变更
复杂度: Low | 风险: Low | 工作量: 1-2天
b) 跳过此冲突
说明:稍后手动处理,不应用任何修改
请回答 (格式: 1a 2b)
```
**User Input Examples**:
- `1a 2a` → Conflict 1: 渐进式迁移, Conflict 2: 添加迁移脚本
- `1b 2b` → Conflict 1: 完全重写, Conflict 2: 跳过
- `1c 2c` → Both skipped
### Phase 4: Apply Modifications
```javascript
@@ -290,7 +327,7 @@ return {
**Validation**:
```
✓ Agent returns valid JSON structure
AskUserQuestion displays all conflicts (max 4)
Text output displays all conflicts (max 10 per round)
✓ User selections captured correctly
✓ Edit tool successfully applies modifications
✓ guidance-specification.md updated
@@ -310,7 +347,7 @@ return {
### Key Requirements
| Requirement | Details |
|------------|---------|
| **Conflict limit** | Max 4 conflicts (AskUserQuestion tool limit) |
| **Conflict batching** | Max 10 conflicts per round (no total limit) |
| **Strategy count** | 2-4 strategies per conflict |
| **Modifications** | Each strategy includes file paths, old_content, new_content |
| **User-facing text** | Chinese (brief, strategy names, pros/cons) |
@@ -338,7 +375,7 @@ return {
```
If Edit tool fails mid-application:
1. Log all successfully applied modifications
2. Offer rollback option via AskUserQuestion
2. Output rollback option via text interaction
3. If rollback selected: restore files from git or backups
4. If continue: mark partial resolution in context-package.json
```
@@ -359,15 +396,15 @@ If Edit tool fails mid-application:
- NO report file generation
**User Interaction**:
- AskUserQuestion for strategy selection (max 4 conflicts)
- Text-based strategy selection (max 10 conflicts per round)
- Each conflict: 2-4 strategy options + "跳过" option
### Success Criteria
```
✓ CLI analysis returns valid JSON structure
Max 4 conflicts presented (tool limit)
Conflicts presented in batches (max 10 per round)
✓ Min 2 strategies per conflict with modifications
AskUserQuestion displays all conflicts correctly
Text output displays all conflicts correctly
✓ User selections captured and processed
✓ Edit tool applies modifications successfully
✓ guidance-specification.md updated with resolved conflicts

View File

@@ -49,6 +49,7 @@ Autonomous task JSON and IMPL_PLAN.md generation using action-planning-agent wit
"synthesis_output": {"path": "...", "exists": true},
"conflict_resolution": {"path": "...", "exists": true} // if conflict_risk >= medium
},
"context_package_path": ".workflow/{session-id}/.process/context-package.json",
"context_package": {
// If in memory: use cached content
// Else: Load from .workflow/{session-id}/.process/context-package.json
@@ -336,9 +337,11 @@ const agentContext = {
? memory.get("workflow-session.json")
: Read(.workflow/WFS-[id]/workflow-session.json),
context_package_path: ".workflow/WFS-[id]/.process/context-package.json",
context_package: memory.has("context-package.json")
? memory.get("context-package.json")
: Read(.workflow/WFS-[id]/.process/context-package.json),
: Read(".workflow/WFS-[id]/.process/context-package.json"),
// Extract brainstorm artifacts from context package
brainstorm_artifacts: extractBrainstormArtifacts(context_package),

View File

@@ -134,6 +134,7 @@ For each feature, generate task(s) with ID format:
"id": "IMPL-N", // Task identifier
"title": "Feature description with TDD", // Human-readable title
"status": "pending", // pending | in_progress | completed | container
"context_package_path": ".workflow/{session-id}/.process/context-package.json", // Path to smart context package
"meta": {
"type": "feature", // Task type
"agent": "@code-developer", // Assigned agent
@@ -259,6 +260,7 @@ identifier: WFS-{session-id}
source: "User requirements" | "File: path"
conflict_resolution: .workflow/{session-id}/.process/CONFLICT_RESOLUTION.md # if exists
context_package: .workflow/{session-id}/.process/context-package.json
context_package_path: .workflow/{session-id}/.process/context-package.json
test_context: .workflow/{session-id}/.process/test-context-package.json # if exists
workflow_type: "tdd"
verification_history:
@@ -411,6 +413,7 @@ Update workflow-session.json with TDD metadata:
├── CONFLICT_RESOLUTION.md # Conflict resolution strategies (if conflict_risk ≥ medium)
├── test-context-package.json # Test coverage analysis
├── context-package.json # Input from context-gather
├── context_package_path # Path to smart context package
└── green-fix-iteration-*.md # Fix logs from Green phase test-fix cycles
```

View File

@@ -173,6 +173,7 @@ This enhanced 5-field schema embeds all necessary context, artifacts, and execut
"id": "IMPL-N[.M]",
"title": "Descriptive task name",
"status": "pending|active|completed|blocked|container",
"context_package_path": ".workflow/WFS-[session]/.process/context-package.json",
"meta": {
"type": "feature|bugfix|refactor|test-gen|test-fix|docs",
"agent": "@code-developer|@test-fix-agent|@universal-executor",
@@ -193,11 +194,6 @@ This enhanced 5-field schema embeds all necessary context, artifacts, and execut
"priority": "highest",
"usage": "Role-specific requirements, design specs, enhanced by synthesis. Paths loaded dynamically from context-package.json (supports multiple files per role: analysis.md, analysis-01.md, analysis-api.md, etc.). Common roles: product-manager, system-architect, ui-designer, data-architect, ux-expert."
},
{
"path": ".workflow/WFS-[session]/.process/context-package.json",
"priority": "critical",
"usage": "Smart context with focus paths, module structure, dependency graph, existing patterns, tech stack. Use for: environment setup, dependency resolution, pattern discovery, conflict detection results"
},
{
"path": ".workflow/WFS-[session]/.brainstorming/guidance-specification.md",
"priority": "high",
@@ -210,8 +206,9 @@ This enhanced 5-field schema embeds all necessary context, artifacts, and execut
{
"step": "load_context_package",
"action": "Load context package for artifact paths",
"note": "Context package path is now at top-level field: context_package_path",
"commands": [
"Read(.workflow/WFS-[session]/.process/context-package.json)"
"Read({{context_package_path}})"
],
"output_to": "context_package",
"on_error": "fail"
@@ -221,7 +218,7 @@ This enhanced 5-field schema embeds all necessary context, artifacts, and execut
"action": "Load role analyses from context-package.json (supports multiple files per role)",
"note": "Paths loaded from context-package.json → brainstorm_artifacts.role_analyses[]. Supports analysis*.md automatically.",
"commands": [
"Read(.workflow/WFS-[session]/.process/context-package.json)",
"Read({{context_package_path}})",
"Extract(brainstorm_artifacts.role_analyses[].files[].path)",
"Read(each extracted path)"
],
@@ -231,9 +228,9 @@ This enhanced 5-field schema embeds all necessary context, artifacts, and execut
{
"step": "load_planning_context",
"action": "Load plan-generated context intelligence with resolved conflicts",
"note": "CRITICAL: context-package.json provides smart context (focus paths, dependencies, patterns) and conflict resolution status. If conflict_risk was medium/high, conflicts have been resolved in guidance-specification.md and role analyses.",
"note": "CRITICAL: context-package.json (from context_package_path) provides smart context (focus paths, dependencies, patterns) and conflict resolution status. If conflict_risk was medium/high, conflicts have been resolved in guidance-specification.md and role analyses.",
"commands": [
"Read(.workflow/WFS-[session]/.process/context-package.json)",
"Read({{context_package_path}})",
"Read(.workflow/WFS-[session]/.brainstorming/guidance-specification.md)"
],
"output_to": "planning_context",
@@ -403,7 +400,7 @@ Role analyses provide specialized perspectives on the implementation:
- **topic-framework.md**: Role-specific discussion points and analysis framework
**Artifact Priority in Development**:
1. context-package.json (primary source: smart context AND brainstorm artifact catalog in `brainstorm_artifacts` + conflict_risk status)
1. {context_package_path} (primary source: smart context AND brainstorm artifact catalog in `brainstorm_artifacts` + conflict_risk status)
2. role/analysis*.md (paths from context-package.json: requirements, design specs, enhanced by synthesis, with resolved conflicts if any)
3. guidance-specification.md (path from context-package.json: finalized decisions with resolved conflicts if any)
@@ -592,8 +589,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
**Key Points**:
- **Sequential Steps**: Steps execute in order defined in `implementation_approach` array
- **Context Delivery**: Each codex command receives context via CONTEXT field: `@.workflow/WFS-session/.process/context-package.json` (role analyses loaded dynamically from context package)
- **Multi-Step Tasks**: First step provides full context, subsequent steps use `resume --last` to maintain session continuity
- **Context Delivery**: Each codex command receives context via CONTEXT field: `@{context_package_path}` (role analyses loaded dynamically from context package)- **Multi-Step Tasks**: First step provides full context, subsequent steps use `resume --last` to maintain session continuity
- **Step Dependencies**: Later steps reference outputs from earlier steps via `depends_on` field
### Example 1: Agent Mode - Simple Task (Default, No Command)
@@ -601,6 +597,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
{
"id": "IMPL-001",
"title": "Implement user authentication module",
"context_package_path": ".workflow/WFS-session/.process/context-package.json",
"context": {
"depends_on": [],
"focus_paths": ["src/auth"],
@@ -617,7 +614,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
"step": "load_role_analyses",
"action": "Load role analyses from context-package.json",
"commands": [
"Read(.workflow/WFS-session/.process/context-package.json)",
"Read({{context_package_path}})",
"Extract(brainstorm_artifacts.role_analyses[].files[].path)",
"Read(each extracted path)"
],
@@ -627,7 +624,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
{
"step": "load_context",
"action": "Load context package for project structure",
"commands": ["Read(.workflow/WFS-session/.process/context-package.json)"],
"commands": ["Read({{context_package_path}})"],
"output_to": "context_pkg",
"on_error": "fail"
}
@@ -662,6 +659,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
{
"id": "IMPL-002",
"title": "Implement user authentication module",
"context_package_path": ".workflow/WFS-session/.process/context-package.json",
"context": {
"depends_on": [],
"focus_paths": ["src/auth"],
@@ -674,7 +672,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
"step": "load_role_analyses",
"action": "Load role analyses from context-package.json",
"commands": [
"Read(.workflow/WFS-session/.process/context-package.json)",
"Read({{context_package_path}})",
"Extract(brainstorm_artifacts.role_analyses[].files[].path)",
"Read(each extracted path)"
],
@@ -687,7 +685,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
"step": 1,
"title": "Implement authentication with Codex",
"description": "Create JWT-based authentication module",
"command": "bash(codex -C src/auth --full-auto exec \"PURPOSE: Implement user authentication TASK: JWT-based auth with login/registration MODE: auto CONTEXT: @.workflow/WFS-session/.process/context-package.json EXPECTED: Complete auth module with tests RULES: Load role analyses from context-package.json → brainstorm_artifacts\" --skip-git-repo-check -s danger-full-access)",
"command": "bash(codex -C src/auth --full-auto exec \"PURPOSE: Implement user authentication TASK: JWT-based auth with login/registration MODE: auto CONTEXT: @{{context_package_path}} EXPECTED: Complete auth module with tests RULES: Load role analyses from context-package.json → brainstorm_artifacts\" --skip-git-repo-check -s danger-full-access)",
"modification_points": ["Create auth service", "Implement endpoints", "Add JWT middleware"],
"logic_flow": ["Validate credentials", "Generate JWT", "Return token"],
"depends_on": [],
@@ -704,6 +702,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
{
"id": "IMPL-003",
"title": "Implement role-based access control",
"context_package_path": ".workflow/WFS-session/.process/context-package.json",
"context": {
"depends_on": ["IMPL-002"],
"focus_paths": ["src/auth", "src/middleware"],
@@ -716,7 +715,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
"step": "load_context",
"action": "Load context and role analyses from context-package.json",
"commands": [
"Read(.workflow/WFS-session/.process/context-package.json)",
"Read({{context_package_path}})",
"Extract(brainstorm_artifacts.role_analyses[].files[].path)",
"Read(each extracted path)"
],
@@ -729,7 +728,7 @@ When using `--cli-execute`, each step in `implementation_approach` includes a `c
"step": 1,
"title": "Create RBAC models",
"description": "Define role and permission data models",
"command": "bash(codex -C src/auth --full-auto exec \"PURPOSE: Create RBAC models TASK: Role and permission models MODE: auto CONTEXT: @.workflow/WFS-session/.process/context-package.json EXPECTED: Models with migrations RULES: Load role analyses from context-package.json → brainstorm_artifacts\" --skip-git-repo-check -s danger-full-access)",
"command": "bash(codex -C src/auth --full-auto exec \"PURPOSE: Create RBAC models TASK: Role and permission models MODE: auto CONTEXT: @{{context_package_path}} EXPECTED: Models with migrations RULES: Load role analyses from context-package.json → brainstorm_artifacts\" --skip-git-repo-check -s danger-full-access)",
"modification_points": ["Define role model", "Define permission model", "Create migrations"],
"logic_flow": ["Design schema", "Implement models", "Generate migrations"],
"depends_on": [],